Skip to content

Commit

Permalink
Fixed #407 - Histogram - A Rating scale is visualized on a Date-Time …
Browse files Browse the repository at this point in the history
…scale by default
  • Loading branch information
tsv2013 committed Mar 19, 2024
1 parent 381d325 commit 65ce405
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/plotly/histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export class HistogramPlotly extends HistogramModel {
}
return statistics;
}

public getValueType(): "date" | "number" {
return this.valueType;
}
}

VisualizationManager.registerVisualizer("date", HistogramPlotly);
Expand Down
5 changes: 5 additions & 0 deletions src/plotly/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ export class PlotlySetup {
tickcolor: "transparent",
};
}
if((model as any).getValueType() != "date") {
layout.xaxis = {
type: "category",
};
}

return { traces, layout, hasSeries };
}
Expand Down
14 changes: 14 additions & 0 deletions tests/histogram.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ test("histogram original data keep number original values", () => {
rateStep: 1
};
const number = new HistogramModel(question, [{ "question2": "Yes", "question1": 3 }, { "question2": "It is going so well!!!", "question1": 5 }, { "question2": false, "question1": 5 }, { "question2": true, "question1": 1 }, { "question2": false, "question1": 5 }, { "question3": "item2", "question2": false, "question1": 5 }]);
expect(number["valueType"]).toBe("number");
expect(number.getValues()).toEqual([1, 2, 3, 4, 5]);
expect(number.getLabels()).toEqual(["1", "2", "3", "4", "5"]);

Expand All @@ -429,6 +430,19 @@ test("histogram original data keep number original values", () => {
expect(selectedItem.text).toBe("5");
});

test("histogram rating should be numeric", () => {
const question: any = {
getType: () => "rating",
type: "rating",
name: "question1",
rateMin: 0,
rateMax: 10,
rateStep: 1
};
const number = new HistogramModel(question, []);
expect(number["valueType"]).toBe("number");
});

test("histogram should use rate values", () => {
const json = {
questions: [
Expand Down

0 comments on commit 65ce405

Please sign in to comment.