From b1d143c631ad8447fdd9cfd38e0d7b8d5bcab5fa Mon Sep 17 00:00:00 2001 From: tsv2013 Date: Mon, 25 Mar 2024 15:37:48 +0300 Subject: [PATCH] Fixed #413 - getCalculatedData() and getData() return different results for all visualizer classes, except VisualizerBase - use getCalculatedData everywhere (#414) Co-authored-by: tsv2013 --- examples/custom_matrix_2.js | 2 +- src/histogram.ts | 2 +- src/matrix.ts | 4 ++-- src/matrixDropdownGrouped.ts | 2 +- src/number.ts | 2 +- src/plotly/histogram.ts | 4 ++-- src/plotly/ranking.ts | 2 +- src/plotly/rating.ts | 2 +- src/plotly/selectBase.ts | 4 ++-- src/selectBase.ts | 4 ++-- src/text.ts | 4 ++-- src/visualizerBase.ts | 2 +- src/wordcloud/wordcloud.ts | 6 +++--- tests/boolean.test.ts | 8 ++++---- tests/dataProvider.test.ts | 4 ++-- tests/histogram.test.ts | 20 ++++++++++---------- tests/matrix.test.ts | 4 ++-- tests/matrixDropdownGrouped.test.ts | 4 ++-- tests/number.test.ts | 8 ++++---- tests/plotly/histogram.test.ts | 8 ++++---- tests/selectBase.test.ts | 12 ++++++------ tests/visualizationPanel.test.ts | 6 +++--- tests/wordcloud.test.ts | 2 +- 23 files changed, 58 insertions(+), 58 deletions(-) diff --git a/examples/custom_matrix_2.js b/examples/custom_matrix_2.js index 316b1cd6f..5a26dc8e4 100644 --- a/examples/custom_matrix_2.js +++ b/examples/custom_matrix_2.js @@ -11,7 +11,7 @@ function CustomVisualizer(question, data) { } function renderRows(table, visualizer) { - var data = visualizer.getData(); + var data = visualizer.getCalculatedValues(); var values = visualizer.getValues(); var series = visualizer.getSeriesValues(); if(series.length > 1) { diff --git a/src/histogram.ts b/src/histogram.ts index 0dc4aada6..fd688b7f5 100644 --- a/src/histogram.ts +++ b/src/histogram.ts @@ -173,7 +173,7 @@ export class HistogramModel extends SelectBase { return this._cachedIntervals; } - public getData() { + public getCalculatedValues(): any { const continiousValues = this.getContiniousValues(); const intervals = this.intervals; const statistics: Array> = []; diff --git a/src/matrix.ts b/src/matrix.ts index 70a9761a5..772e062cb 100644 --- a/src/matrix.ts +++ b/src/matrix.ts @@ -104,8 +104,8 @@ export class Matrix extends SelectBase { return result; } - getData(): any[] { - const statistics = super.getData(); + public getCalculatedValues(): any[] { + const statistics = super.getCalculatedValues(); const series = this.getSeriesValues(); const values = this.getValues(); const preparedData: Array> = []; diff --git a/src/matrixDropdownGrouped.ts b/src/matrixDropdownGrouped.ts index 2d1b92d84..90181249c 100644 --- a/src/matrixDropdownGrouped.ts +++ b/src/matrixDropdownGrouped.ts @@ -42,7 +42,7 @@ export class MatrixDropdownGrouped extends SelectBase { return false; } - getData(): any[] { + public getCalculatedValues(): any[] { const values = this.getValues(); const series = this.getSeriesValues(); const rows = this.matrixQuestion.rows.map(row => row.value); diff --git a/src/number.ts b/src/number.ts index 64e58abc1..41aa66f36 100644 --- a/src/number.ts +++ b/src/number.ts @@ -136,7 +136,7 @@ export class NumberModel extends VisualizerBase { return colors; } - getData() { + public getCalculatedValues(): any { if ( this._resultAverage === undefined || this._resultMin === undefined || diff --git a/src/plotly/histogram.ts b/src/plotly/histogram.ts index e7cba0c0b..4ce70fc1a 100644 --- a/src/plotly/histogram.ts +++ b/src/plotly/histogram.ts @@ -35,8 +35,8 @@ export class HistogramPlotly extends HistogramModel { }); } - getData(): any[] { - const statistics = super.getData(); + public getCalculatedValues(): any[] { + const statistics = super.getCalculatedValues(); const series = this.getSeriesValues(); const values = this.getValues(); if (series.length > 1) { diff --git a/src/plotly/ranking.ts b/src/plotly/ranking.ts index adff2252a..3b48fab0a 100644 --- a/src/plotly/ranking.ts +++ b/src/plotly/ranking.ts @@ -17,7 +17,7 @@ export class RankingPlotly extends SelectBasePlotly { return data; } - getData(): any[] { + public getCalculatedValues(): any[] { const results = this.getQuestionResults(); const choices = this.getValues(); diff --git a/src/plotly/rating.ts b/src/plotly/rating.ts index e07750c34..b593682e7 100644 --- a/src/plotly/rating.ts +++ b/src/plotly/rating.ts @@ -17,7 +17,7 @@ export class PlotlyGaugeAdapter { public create(chartNode: HTMLElement) { const question = this.model.question; - let [level, minValue, maxValue] = this.model.getData(); + let [level, minValue, maxValue] = this.model.getCalculatedValues(); if (question.getType() === "rating") { const rateValues = (question).visibleRateValues; diff --git a/src/plotly/selectBase.ts b/src/plotly/selectBase.ts index b6e0476b7..60f02777a 100644 --- a/src/plotly/selectBase.ts +++ b/src/plotly/selectBase.ts @@ -163,8 +163,8 @@ export class SelectBasePlotly extends SelectBase { }); } - getData(): any[] { - const statistics = super.getData(); + public getCalculatedValues(): any[] { + const statistics = super.getCalculatedValues(); const series = this.getSeriesValues(); const values = this.getValues(); if (series.length > 1) { diff --git a/src/selectBase.ts b/src/selectBase.ts index 8353be6f3..1a8f9cc0d 100644 --- a/src/selectBase.ts +++ b/src/selectBase.ts @@ -527,7 +527,7 @@ export class SelectBase } getPercentages(): Array> { - var data: Array> = this.getData(); + var data: Array> = this.getCalculatedValues(); var percentages: Array> = []; var percentagePrecision = this._percentagePrecision; @@ -587,7 +587,7 @@ export class SelectBase */ public getAnswersData(): IAnswersData { let seriesLabels = this.getSeriesLabels(); - let datasets = this.getData(); + let datasets = this.getCalculatedValues(); let labels = this.getLabels(); let colors = this.getColors(); var texts = this.showPercentages ? this.getPercentages() : datasets; diff --git a/src/text.ts b/src/text.ts index 055e72c5d..fd3bc1e38 100644 --- a/src/text.ts +++ b/src/text.ts @@ -10,7 +10,7 @@ export class TextTableAdapter { constructor(private model: Text) {} public create(container: HTMLElement) { - const { columnsCount, data } = this.model.getData(); + const { columnsCount, data } = this.model.getCalculatedValues(); const emptyTextNode = DocumentHelper.createElement("p", "", { innerText: localization.getString("noResults"), }); @@ -60,7 +60,7 @@ export class Text extends VisualizerBase { this._textTableAdapter = new TextTableAdapter(this); } - getData() { + public getCalculatedValues(): any { let result: Array> = []; let columnsCount = 0; diff --git a/src/visualizerBase.ts b/src/visualizerBase.ts index 9318618a2..81cca9b2f 100644 --- a/src/visualizerBase.ts +++ b/src/visualizerBase.ts @@ -621,7 +621,7 @@ export class VisualizerBase implements IDataInfo { * Obsolete. Use [`getCalculatedValues()`](https://surveyjs.io/dashboard/documentation/api-reference/visualizationpanel#getCalculatedValues) instead. */ getData(): any { - return this.dataProvider.getData(this); + return this.getCalculatedValues(); } /** diff --git a/src/wordcloud/wordcloud.ts b/src/wordcloud/wordcloud.ts index 217673b98..584b3fc78 100644 --- a/src/wordcloud/wordcloud.ts +++ b/src/wordcloud/wordcloud.ts @@ -28,7 +28,7 @@ export class WordCloudAdapter { } private createWordCloud2(node: HTMLElement) { - const data = this.model.getData(); + const data = this.model.getCalculatedValues(); const colors = this.model.getColors(); const canvasNode = ( DocumentHelper.createElement("canvas", "") @@ -73,7 +73,7 @@ export class WordCloudAdapter { } public create(element: HTMLElement): any { - const data = this.model.getData(); + const data = this.model.getCalculatedValues(); const colors = this.model.getColors(); if (data.length === 0) { @@ -116,7 +116,7 @@ export class WordCloud extends VisualizerBase { this._wordcloudAdapter = new WordCloudAdapter(this); } - getData() { + public getCalculatedValues(): any { let result: { [key: string]: number } = {}; let stopWords: string[] = []; diff --git a/tests/boolean.test.ts b/tests/boolean.test.ts index 9f229952f..e765c776e 100644 --- a/tests/boolean.test.ts +++ b/tests/boolean.test.ts @@ -33,11 +33,11 @@ test("getLabels method", () => { expect(boolean.getLabels()).toEqual(labels); }); -test("getData method", () => { - expect(boolean.getData()).toEqual([[3, 1]]); +test("getCalculatedValues method", () => { + expect(boolean.getCalculatedValues()).toEqual([[3, 1]]); }); -test("getData localized", () => { +test("getCalculatedValues localized", () => { var survey = new SurveyModel({ "pages": [ { @@ -60,7 +60,7 @@ test("getData localized", () => { var secondResult = { "bool": false, "organization_type": "In-house" }; var test = [firstResult, secondResult]; boolean = new BooleanModel(survey.getQuestionByName("bool"), test); - expect(boolean.getData()).toEqual([[1, 1]]); + expect(boolean.getCalculatedValues()).toEqual([[1, 1]]); }); test("hasHeader and correct answer text", () => { diff --git a/tests/dataProvider.test.ts b/tests/dataProvider.test.ts index 9fa368e96..521361bf2 100644 --- a/tests/dataProvider.test.ts +++ b/tests/dataProvider.test.ts @@ -256,11 +256,11 @@ test("getData for matrix dropdown inner visualizers", () => { let visualizer = new VisualizationMatrixDropdown(question, data); const innerPanelVisualizer: any = visualizer["_matrixDropdownVisualizer"]; - expect(innerPanelVisualizer["visualizers"][0].getData()).toEqual([ + expect(innerPanelVisualizer["visualizers"][0].getCalculatedValues()).toEqual([ [0, 2, 1].reverse(), [1, 1, 1].reverse(), ]); - expect(innerPanelVisualizer["visualizers"][1].getData()).toEqual([ + expect(innerPanelVisualizer["visualizers"][1].getCalculatedValues()).toEqual([ [1, 0, 2, 0, 0].reverse(), [0, 0, 0, 2, 1].reverse(), ]); diff --git a/tests/histogram.test.ts b/tests/histogram.test.ts index 7dcd6237a..d9a1ebeeb 100644 --- a/tests/histogram.test.ts +++ b/tests/histogram.test.ts @@ -47,7 +47,7 @@ test("number default histogram", () => { const histValues = number.getValues(); const histLabels = number.getLabels(); - const histData = number.getData(); + const histData = number.getCalculatedValues(); expect(number["valueType"]).toBe("number"); expect(histValues).toMatchObject([17, 19.3, 21.6, 23.9, 26.2, 28.5, 30.8, 33.1, 35.4, 37.7]); @@ -69,7 +69,7 @@ test("date default histogram", () => { const histValues = date.getValues(); const histLabels = date.getLabels(); - const histData = date.getData(); + const histData = date.getCalculatedValues(); expect(date["valueType"]).toBe("date"); expect(histValues).toMatchObject([1097625600000, 1151271360000, 1204917120000, 1258562880000, 1312208640000, 1365854400000, 1419500160000, 1473145920000, 1526791680000, 1580437440000]); @@ -108,7 +108,7 @@ test("date default intervals", () => { const histValues = date.getValues(); const histLabels = date.getLabels(); const histIntervals = date.intervals; - const histData = date.getData(); + const histData = date.getCalculatedValues(); expect(histIntervals.length).toBe(10); expect(histValues).toMatchObject([ @@ -150,7 +150,7 @@ test("date empty data", () => { const histValues = date.getValues(); const histIntervals = date.intervals; - const histData = date.getData(); + const histData = date.getCalculatedValues(); expect(histIntervals.length).toBe(0); expect(histValues).toMatchObject([]); @@ -205,7 +205,7 @@ test("number custom intervals", () => { const histValues = date.getValues(); const histIntervals = date.intervals; - const histData = date.getData(); + const histData = date.getCalculatedValues(); expect(histIntervals.length).toBe(5); expect(histValues).toMatchObject([ @@ -245,7 +245,7 @@ test("number custom intervals for small result sets", () => { const histValues = date.getValues(); const histIntervals = date.intervals; - const histData = date.getData(); + const histData = date.getCalculatedValues(); expect(histIntervals.length).toBe(5); expect(histValues).toMatchObject([ @@ -302,7 +302,7 @@ test("histogram series default algorithm data", () => { expect(number.getSeriesValues()).toMatchObject(series); expect(number.getSeriesLabels()).toMatchObject(series); - const chartData = number.getData(); + const chartData = number.getCalculatedValues(); expect(chartData).toMatchObject([ [1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0], @@ -391,7 +391,7 @@ test("histogram series intervals data", () => { seriesLabels: series, }); - const chartData = number.getData(); + const chartData = number.getCalculatedValues(); expect(chartData).toMatchObject([ [1, 0, 0, 1, 0, 0, 1, 0, 0, 0], [1, 0, 0, 0, 1, 0, 0, 1, 0, 0], @@ -470,7 +470,7 @@ test("histogram should use rate values", () => { ]); expect(rating.getValues()).toEqual([1, 2, 3]); expect(rating.getLabels()).toEqual(["15 minutes", "30 minutes", "1 hour"]); - expect(rating.getData()).toEqual([[0, 0, 1]]); + expect(rating.getCalculatedValues()).toEqual([[0, 0, 1]]); }); test("histogram intervals alignment and rounding", () => { @@ -683,6 +683,6 @@ test("number histogram answers order", () => { expect(histValues).toMatchObject([11.14, 14.43, 17.71, 21, 24.29, 27.57, 30.86, 34.14, 37.43, 40.71]); expect(histLabels).toMatchObject(["11.14-14.43", "14.43-17.71", "17.71-21", "21-24.29", "24.29-27.57", "27.57-30.86", "30.86-34.14", "34.14-37.43", "37.43-40.71", "40.71-44"]); - const histData = number.getData(); + const histData = number.getCalculatedValues(); expect(histData).toMatchObject([[5, 3, 0, 0, 0, 0, 1, 0, 0, 1]]); }); diff --git a/tests/matrix.test.ts b/tests/matrix.test.ts index 64de9b7c8..ae8f2debb 100644 --- a/tests/matrix.test.ts +++ b/tests/matrix.test.ts @@ -56,8 +56,8 @@ test("getSeriesLabels method", () => { expect(matrix.getSeriesLabels()).toEqual(matrixJson.rows); }); -test("getData method", () => { - expect(matrix.getData()).toEqual([ +test("getCalculatedValues method", () => { + expect(matrix.getCalculatedValues()).toEqual([ [1, 1], [2, 1], [0, 1], diff --git a/tests/matrixDropdownGrouped.test.ts b/tests/matrixDropdownGrouped.test.ts index cf41498a3..861b0c922 100644 --- a/tests/matrixDropdownGrouped.test.ts +++ b/tests/matrixDropdownGrouped.test.ts @@ -76,8 +76,8 @@ test("name property", () => { expect(matrix.name).toEqual(columns); }); -test("getData method", () => { - expect(matrix.getData()).toEqual([ +test("getCalculatedValues method", () => { + expect(matrix.getCalculatedValues()).toEqual([ [1, 1, 0], [1, 1, 0], [1, 1, 1], diff --git a/tests/number.test.ts b/tests/number.test.ts index 7c3f50d9e..376112bea 100644 --- a/tests/number.test.ts +++ b/tests/number.test.ts @@ -5,7 +5,7 @@ test("result resultMin resultMax", () => { const data = [{ test: 0 }, { test: 50 }, { test: 100 }]; const number = new NumberModel(question, data); - let [level, minValue, maxValue] = number.getData(); + let [level, minValue, maxValue] = number.getCalculatedValues(); expect(level).toBe(50); expect(minValue).toBe(0); @@ -17,7 +17,7 @@ test("result resultMin resultMax for negatives", () => { const data = [{ test: -10 }, { test: -50 }, { test: -100 }]; const number = new NumberModel(question, data); - let [level, minValue, maxValue] = number.getData(); + let [level, minValue, maxValue] = number.getCalculatedValues(); expect(level).toBe(-53.33); expect(minValue).toBe(-100); @@ -29,7 +29,7 @@ test("result average", () => { const data = [{ }, { test: 2 }, { test: 4 }]; const number = new NumberModel(question, data); - let [level, minValue, maxValue] = number.getData(); + let [level, minValue, maxValue] = number.getCalculatedValues(); expect(level).toBe(3); expect(minValue).toBe(2); @@ -41,7 +41,7 @@ test("result average for strings", () => { const data = [{ }, { test: "2" }, { test: "4" }]; const number = new NumberModel(question, data); - let [level, minValue, maxValue] = number.getData(); + let [level, minValue, maxValue] = number.getCalculatedValues(); expect(level).toBe(3); expect(minValue).toBe(2); diff --git a/tests/plotly/histogram.test.ts b/tests/plotly/histogram.test.ts index 50c4e0707..14c8e0309 100644 --- a/tests/plotly/histogram.test.ts +++ b/tests/plotly/histogram.test.ts @@ -1,7 +1,7 @@ window.URL.createObjectURL = jest.fn(); import { HistogramPlotly } from "../../src/plotly/histogram"; -test("getData", () => { +test("getCalculatedValues", () => { const preparedData = [ { "Column 1": 1, @@ -41,13 +41,13 @@ test("getData", () => { seriesLabels: series, }); - const chartData = number.getData(); + const chartData = number.getCalculatedValues(); expect(chartData).toMatchObject([ [1, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1], ]); }); -test("getData - 2 rows", () => { +test("getCalculatedValues - 2 rows", () => { const preparedData = [ { "Column 1": 1, @@ -87,6 +87,6 @@ test("getData - 2 rows", () => { seriesLabels: series, }); - const chartData = number.getData(); + const chartData = number.getCalculatedValues(); expect(chartData).toMatchObject([[2, 0], [0, 0], [0, 1], [0, 0], [0, 0], [0, 0], [0, 0], [0, 1], [0, 0], [1, 0]]); }); diff --git a/tests/selectBase.test.ts b/tests/selectBase.test.ts index dab87b26b..12bd3d2aa 100644 --- a/tests/selectBase.test.ts +++ b/tests/selectBase.test.ts @@ -51,8 +51,8 @@ test("getLabels method", () => { selectBase["options"].useValuesAsLabels = false; }); -test("getData method", () => { - expect(selectBase.getData()).toEqual([[2, 1, 0, 1, 0, 0].reverse()]); +test("getCalculatedValues method", () => { + expect(selectBase.getCalculatedValues()).toEqual([[2, 1, 0, 1, 0, 0].reverse()]); }); test("createToolbarItems", () => { @@ -233,14 +233,14 @@ test("showMissingAnswers", () => { expect(selectBase.showMissingAnswers).toBeFalsy(); expect(selectBase.getValues()).toEqual(["father", "mother", "brother", "sister", "son", "daughter"].reverse()); expect(selectBase.getLabels()).toEqual(["father_text", "mother_text", "brother_text", "sister_text", "son_text", "daughter_text"].reverse()); - expect(selectBase.getData()).toEqual([[2, 1, 0, 1, 0, 0].reverse()]); + expect(selectBase.getCalculatedValues()).toEqual([[2, 1, 0, 1, 0, 0].reverse()]); selectBase.showMissingAnswers = true; expect(selectBase.getValues()).toEqual([undefined, "father", "mother", "brother", "sister", "son", "daughter"].reverse()); expect(selectBase.getLabels()).toEqual(["Missing answers", "father_text", "mother_text", "brother_text", "sister_text", "son_text", "daughter_text"].reverse()); - expect(selectBase.getData()).toEqual([[1, 2, 1, 0, 1, 0, 0].reverse()]); + expect(selectBase.getCalculatedValues()).toEqual([[1, 2, 1, 0, 1, 0, 0].reverse()]); }); -test("valueName used for getData https://surveyjs.answerdesk.io/internal/ticket/details/T9071", () => { +test("valueName used for getCalculatedValues https://surveyjs.answerdesk.io/internal/ticket/details/T9071", () => { var question = new QuestionDropdownModel("q1"); question.choices = choices; question.valueName = "q1value"; @@ -262,7 +262,7 @@ test("valueName used for getData https://surveyjs.answerdesk.io/internal/ticket/ } ]; selectBase = new SelectBase(question, data, {}); - expect(selectBase.getData()).toEqual([[2, 1, 0, 1, 0, 0].reverse()]); + expect(selectBase.getCalculatedValues()).toEqual([[2, 1, 0, 1, 0, 0].reverse()]); }); test("hasHeader and correct answer text", () => { diff --git a/tests/visualizationPanel.test.ts b/tests/visualizationPanel.test.ts index 41cc3dc5a..1c6278201 100644 --- a/tests/visualizationPanel.test.ts +++ b/tests/visualizationPanel.test.ts @@ -631,14 +631,14 @@ test("updateData should be called in order to update data - #269", () => { let visPanel = new VisualizationPanel(survey.getAllQuestions(), data); const questionVisualizer = visPanel.visualizers[0]; - expect(questionVisualizer.getData()).toEqual([[0, 1, 2, 0, 2]]); + expect(questionVisualizer.getCalculatedValues()).toEqual([[0, 1, 2, 0, 2]]); const newAnswer = { "satisfaction-score": 4, "nps-score": 9 }; data.push(newAnswer); - expect(questionVisualizer.getData()).toEqual([[0, 1, 2, 0, 2]]); + expect(questionVisualizer.getCalculatedValues()).toEqual([[0, 1, 2, 0, 2]]); visPanel.updateData(data); - expect(questionVisualizer.getData()).toEqual([[0, 1, 2, 1, 2]]); + expect(questionVisualizer.getCalculatedValues()).toEqual([[0, 1, 2, 1, 2]]); }); test("hide/show all elements", () => { diff --git a/tests/wordcloud.test.ts b/tests/wordcloud.test.ts index 73896e61b..268a58d91 100644 --- a/tests/wordcloud.test.ts +++ b/tests/wordcloud.test.ts @@ -7,7 +7,7 @@ test("remove stopwords and clean punktuation", () => { { q1: "The Thimes!" }, { q1: "mega mega Super answer" }, ]); - var data = wc.getData(); + var data = wc.getCalculatedValues(); expect(Object.keys(data).length).toEqual(4); expect(data.filter((d) => d[0] === "The").length).toEqual(0); expect(data.filter((d) => d[0] === "mega").length).toEqual(1);