Skip to content

Commit

Permalink
Fixed #413 - getCalculatedData() and getData() return different resul…
Browse files Browse the repository at this point in the history
…ts for all visualizer classes, except VisualizerBase - use getCalculatedData everywhere
  • Loading branch information
tsv2013 committed Mar 25, 2024
1 parent 5b1fc92 commit 4735f35
Show file tree
Hide file tree
Showing 23 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion examples/custom_matrix_2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Array<number>> = [];
Expand Down
4 changes: 2 additions & 2 deletions src/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Array<number>> = [];
Expand Down
2 changes: 1 addition & 1 deletion src/matrixDropdownGrouped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class NumberModel extends VisualizerBase {
return colors;
}

getData() {
public getCalculatedValues(): any {
if (
this._resultAverage === undefined ||
this._resultMin === undefined ||
Expand Down
4 changes: 2 additions & 2 deletions src/plotly/histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/plotly/ranking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class RankingPlotly extends SelectBasePlotly {
return data;
}

getData(): any[] {
public getCalculatedValues(): any[] {
const results = this.getQuestionResults();
const choices = this.getValues();

Expand Down
2 changes: 1 addition & 1 deletion src/plotly/rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (<QuestionRatingModel>question).visibleRateValues;
Expand Down
4 changes: 2 additions & 2 deletions src/plotly/selectBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/selectBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ export class SelectBase
}

getPercentages(): Array<Array<number>> {
var data: Array<Array<number>> = this.getData();
var data: Array<Array<number>> = this.getCalculatedValues();
var percentages: Array<Array<number>> = [];
var percentagePrecision = this._percentagePrecision;

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <HTMLElement>DocumentHelper.createElement("p", "", {
innerText: localization.getString("noResults"),
});
Expand Down Expand Up @@ -60,7 +60,7 @@ export class Text extends VisualizerBase {
this._textTableAdapter = new TextTableAdapter(this);
}

getData() {
public getCalculatedValues(): any {
let result: Array<Array<string>> = [];
let columnsCount = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/visualizerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/wordcloud/wordcloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <HTMLCanvasElement>(
DocumentHelper.createElement("canvas", "")
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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[] = [];
Expand Down
8 changes: 4 additions & 4 deletions tests/boolean.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand All @@ -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", () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/dataProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ test("getData for matrix dropdown inner visualizers", () => {
let visualizer = new VisualizationMatrixDropdown(<any>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(),
]);
Expand Down
20 changes: 10 additions & 10 deletions tests/histogram.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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]);
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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([]);
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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]]);
});
4 changes: 2 additions & 2 deletions tests/matrix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
4 changes: 2 additions & 2 deletions tests/matrixDropdownGrouped.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
8 changes: 4 additions & 4 deletions tests/number.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions tests/plotly/histogram.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
window.URL.createObjectURL = jest.fn();
import { HistogramPlotly } from "../../src/plotly/histogram";

test("getData", () => {
test("getCalculatedValues", () => {
const preparedData = [
{
"Column 1": 1,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]]);
});
Loading

0 comments on commit 4735f35

Please sign in to comment.