Skip to content

Commit

Permalink
Resolved #461 - Implement line charts, Resolved #464 - Make Vertical …
Browse files Browse the repository at this point in the history
…Bar for discrete data available for everyone, Resolved #465 - Remove the Scatter visualizer as it doesn't visualize data properly
  • Loading branch information
tsv2013 committed Aug 30, 2024
1 parent 7bbcaeb commit b65fb95
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/analytics-localization/english.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export var englishStrings = {
chartType_scatter: "Scatter",
chartType_gauge: "Gauge",
chartType_bullet: "Bullet",
chartType_line: "Line",
hideButton: "Hide",
makePrivateButton: "Make private",
makePublicButton: "Make public",
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface IVisualizerPanelElement {
*
* - `"bar"`
* - `"vbar"`
* - `"line"`
* - `"stackedbar"`
* - `"pie"`
* - `"doughnut"`
Expand Down
2 changes: 1 addition & 1 deletion src/plotly/histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DocumentHelper } from "../utils";

export class HistogramPlotly extends HistogramModel {
private _chartAdapter: PlotlyChartAdapter;
public static types = ["vbar", "bar", "scatter"];
public static types = ["vbar", "bar", "line"];

constructor(
question: Question,
Expand Down
4 changes: 2 additions & 2 deletions src/plotly/selectBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class PlotlyChartAdapter {

export class SelectBasePlotly extends SelectBase {
private _chartAdapter: PlotlyChartAdapter;
public static types = ["bar", "pie", "doughnut", "scatter"];
public static types = ["bar", "vbar", "pie", "doughnut", "line"];
public static displayModeBar: any = undefined;

constructor(
Expand All @@ -142,7 +142,7 @@ export class SelectBasePlotly extends SelectBase {
this.chartTypes.push("stackedbar");
}
if(options.allowExperimentalFeatures) {
this.chartTypes.splice(1, 0, "vbar");
// this.chartTypes.splice(1, 0, "vbar");
}
this._chartType = this.chartTypes[0];
if (this.chartTypes.indexOf(options.defaultChartType) !== -1) {
Expand Down
20 changes: 18 additions & 2 deletions src/plotly/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class PlotlySetup {
static setups: { [type: string]: (model: SelectBase, answersData: IAnswersData) => PlotlyOptions } = {
bar: PlotlySetup.setupBar,
vbar: PlotlySetup.setupVBar,
line: PlotlySetup.setupVBar,
stackedbar: PlotlySetup.setupBar,
doughnut: PlotlySetup.setupPie,
pie: PlotlySetup.setupPie,
Expand Down Expand Up @@ -282,6 +283,21 @@ export class PlotlySetup {
seriesLabels,
} = answersData;

if(model.type !== "histogram") {
labels = [].concat(labels).reverse();
colors = [].concat(colors.slice(0, labels.length)).reverse();
const ts = [];
texts.forEach(text => {
ts.push([].concat(text).reverse());
});
texts = ts;
const ds = [];
datasets.forEach(dataset => {
ds.push([].concat(dataset).reverse());
});
datasets = ds;
}

const traces: any = [];
const hasSeries = seriesLabels.length > 1 || model.question.getType() === "matrix";

Expand All @@ -305,10 +321,10 @@ export class PlotlySetup {
};

const traceConfig: any = {
type: "bar",
type: model.chartType === "line" ? "line" : "bar",
customdata: hasSeries ? seriesLabels : labels,
hoverinfo: "x+y",
mode: "markers",
mode: model.chartType === "line" ? "lines+markers" : "markers",
textposition: "none",
width: 0.5,
bargap: 0.5,
Expand Down
3 changes: 2 additions & 1 deletion src/selectBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class SelectBase
this.emptyAnswersBtn.innerText = this._hideEmptyAnswers
? localization.getString("showEmptyAnswers")
: localization.getString("hideEmptyAnswers");
if (this.chartType == "bar" || this.chartType == "vbar" || this.chartType == "scatter") {
if (this.chartType == "bar" || this.chartType == "vbar" || this.chartType == "line" || this.chartType == "scatter") {
this.emptyAnswersBtn.style.display = "inline";
} else {
this.emptyAnswersBtn.style.display = "none";
Expand All @@ -260,6 +260,7 @@ export class SelectBase
if (
this.chartType == "bar" ||
this.chartType == "vbar" ||
this.chartType == "line" ||
this.chartType == "scatter" ||
((this.chartType == "pie" || this.chartType == "doughnut") &&
this.topN > 0)
Expand Down
2 changes: 1 addition & 1 deletion src/visualizationPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export interface IVisualizationPanelOptions {
* - Date, Number: `"bar"` | `"scatter"`
* - Matrix: `"bar"` | `"pie"` | `"doughnut"` | `"stackedbar"`
* - Rating: `"bar"` | `"scatter"` | `"gauge"` | `"bullet"`
* - Radiogroup, Checkbox, Dropdown, Image Picker: `"bar"` | `"pie"` | `"doughnut"` | `"scatter"`
* - Radiogroup, Checkbox, Dropdown, Image Picker: `"bar"` | `"pie"` | `"doughnut"` | `"scatter"` | `"line"`
*
* To set a type for an individual chart, access this chart in the `visualizers` array and set its `chartType` property to one of the values described above:
*
Expand Down

0 comments on commit b65fb95

Please sign in to comment.