survey-analytics 2.2.3 → 2.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/fesm/shared.mjs +2 -1
  2. package/fesm/shared.mjs.map +1 -1
  3. package/fesm/shared2.mjs +379 -268
  4. package/fesm/shared2.mjs.map +1 -1
  5. package/fesm/survey.analytics.core.mjs +2 -2
  6. package/fesm/survey.analytics.mjs +177 -418
  7. package/fesm/survey.analytics.mjs.map +1 -1
  8. package/fesm/survey.analytics.tabulator.mjs +16 -4
  9. package/fesm/survey.analytics.tabulator.mjs.map +1 -1
  10. package/package.json +6 -5
  11. package/survey-analytics-tabulator.types/analytics-localization/english.d.ts +1 -0
  12. package/survey-analytics-tabulator.types/localizationManager.d.ts +1 -0
  13. package/survey-analytics-tabulator.types/tables/extensions/tableextensions.d.ts +1 -0
  14. package/survey-analytics.types/analytics-localization/english.d.ts +1 -0
  15. package/survey-analytics.types/boolean.d.ts +0 -1
  16. package/survey-analytics.types/entries/summary.core.d.ts +2 -1
  17. package/survey-analytics.types/histogram.d.ts +1 -1
  18. package/survey-analytics.types/localizationManager.d.ts +1 -0
  19. package/survey-analytics.types/pivot.d.ts +2 -0
  20. package/survey-analytics.types/plotly/chart-adapter.d.ts +22 -0
  21. package/survey-analytics.types/plotly/index.d.ts +2 -8
  22. package/survey-analytics.types/plotly/legacy.d.ts +33 -0
  23. package/survey-analytics.types/plotly/setup.d.ts +5 -3
  24. package/survey-analytics.types/{plotly/ranking.d.ts → ranking.d.ts} +2 -2
  25. package/survey-analytics.types/selectBase.d.ts +2 -0
  26. package/survey-analytics.types/statisticCalculators.d.ts +4 -0
  27. package/survey-analytics.types/visualizationManager.d.ts +1 -0
  28. package/survey-analytics.types/visualizerBase.d.ts +12 -3
  29. package/survey.analytics.core.css +1 -1
  30. package/survey.analytics.core.js +355 -151
  31. package/survey.analytics.core.js.map +1 -1
  32. package/survey.analytics.core.min.css +1 -1
  33. package/survey.analytics.core.min.js +1 -1
  34. package/survey.analytics.core.min.js.LICENSE.txt +1 -1
  35. package/survey.analytics.css +1 -1
  36. package/survey.analytics.js +679 -909
  37. package/survey.analytics.js.map +1 -1
  38. package/survey.analytics.min.css +1 -1
  39. package/survey.analytics.min.js +1 -1
  40. package/survey.analytics.min.js.LICENSE.txt +1 -1
  41. package/survey.analytics.tabulator.css +1 -1
  42. package/survey.analytics.tabulator.js +39 -5
  43. package/survey.analytics.tabulator.js.map +1 -1
  44. package/survey.analytics.tabulator.min.css +1 -1
  45. package/survey.analytics.tabulator.min.js +1 -1
  46. package/survey.analytics.tabulator.min.js.LICENSE.txt +1 -1
  47. package/survey-analytics.types/plotly/boolean.d.ts +0 -16
  48. package/survey-analytics.types/plotly/histogram.d.ts +0 -12
  49. package/survey-analytics.types/plotly/matrix.d.ts +0 -11
  50. package/survey-analytics.types/plotly/matrixdropdown-grouped.d.ts +0 -11
  51. package/survey-analytics.types/plotly/pivot.d.ts +0 -12
  52. package/survey-analytics.types/plotly/rating.d.ts +0 -20
  53. package/survey-analytics.types/plotly/selectBase.d.ts +0 -25
@@ -1,14 +1,14 @@
1
1
  /*!
2
- * surveyjs - SurveyJS Dashboard library v2.2.3
2
+ * surveyjs - SurveyJS Dashboard library v2.2.5
3
3
  * Copyright (c) 2015-2025 Devsoft Baltic OÜ - http://surveyjs.io/
4
4
  * License: MIT (http://www.opensource.org/licenses/mit-license.php)
5
5
  */
6
6
 
7
7
  import { Event, ItemValue } from 'survey-core';
8
- import { l as localization, D as DocumentHelper, a as DataHelper } from './shared.mjs';
9
- export { s as surveyStrings } from './shared.mjs';
10
- import { b as VisualizationManager, S as SelectBase, _ as __awaiter, M as Matrix, B as BooleanModel, d as defaultStatisticsCalculator, H as HistogramModel, N as NumberModel, p as PivotModel } from './shared2.mjs';
11
- export { A as AlternativeVisualizersWrapper, D as DataProvider, n as NpsAdapter, o as NpsVisualizer, m as NpsVisualizerWidget, P as PostponeHelper, l as StatisticsTable, k as StatisticsTableAdapter, j as Text, T as TextTableAdapter, g as VisualizationMatrixDropdown, f as VisualizationMatrixDynamic, c as VisualizationPanel, e as VisualizationPanelDynamic, a as VisualizerBase, V as VisualizerFactory, i as WordCloud, W as WordCloudAdapter, h as hideEmptyAnswersInData, t as textHelper } from './shared2.mjs';
8
+ import { l as localization, a as DataHelper } from './shared.mjs';
9
+ export { D as DocumentHelper, s as surveyStrings } from './shared.mjs';
10
+ import { N as NumberModel, b as VisualizationManager, S as SelectBase, p as defaultStatisticsCalculator, B as BooleanModel, H as HistogramModel, M as Matrix, o as PivotModel, R as RankingModel, a as VisualizerBase, _ as __awaiter } from './shared2.mjs';
11
+ export { A as AlternativeVisualizersWrapper, D as DataProvider, m as NpsAdapter, n as NpsVisualizer, l as NpsVisualizerWidget, P as PostponeHelper, k as StatisticsTable, j as StatisticsTableAdapter, i as Text, T as TextTableAdapter, f as VisualizationMatrixDropdown, e as VisualizationMatrixDynamic, c as VisualizationPanel, d as VisualizationPanelDynamic, V as VisualizerFactory, g as WordCloud, W as WordCloudAdapter, h as hideEmptyAnswersInData, t as textHelper } from './shared2.mjs';
12
12
  import Plotly from 'plotly.js-dist-min';
13
13
 
14
14
  class PlotlySetup {
@@ -372,6 +372,49 @@ class PlotlySetup {
372
372
  }
373
373
  return { traces, layout, hasSeries };
374
374
  }
375
+ static setupGauge(model, answersData) {
376
+ let [level, minValue, maxValue] = answersData;
377
+ if (model.question.getType() === "rating") {
378
+ const rateValues = model.question.visibleRateValues;
379
+ maxValue = rateValues[rateValues.length - 1].value;
380
+ minValue = rateValues[0].value;
381
+ }
382
+ const colors = model.generateColors(maxValue, minValue, NumberModel.stepsCount);
383
+ if (NumberModel.showAsPercentage) {
384
+ level = DataHelper.toPercentage(level, maxValue);
385
+ minValue = DataHelper.toPercentage(minValue, maxValue);
386
+ maxValue = DataHelper.toPercentage(maxValue, maxValue);
387
+ }
388
+ var traces = [
389
+ {
390
+ type: "indicator",
391
+ mode: "gauge+number",
392
+ gauge: {
393
+ axis: { range: [minValue, maxValue] },
394
+ shape: model.chartType,
395
+ bgcolor: "white",
396
+ bar: { color: colors[0] },
397
+ },
398
+ value: level,
399
+ text: model.name,
400
+ domain: { x: [0, 1], y: [0, 1] },
401
+ },
402
+ ];
403
+ const chartMargin = model.chartType === "bullet" ? 60 : 30;
404
+ var layout = {
405
+ height: 250,
406
+ margin: {
407
+ l: chartMargin,
408
+ r: chartMargin,
409
+ b: chartMargin,
410
+ t: chartMargin,
411
+ pad: 5
412
+ },
413
+ plot_bgcolor: model.backgroundColor,
414
+ paper_bgcolor: model.backgroundColor,
415
+ };
416
+ return { traces, layout, hasSeries: false };
417
+ }
375
418
  }
376
419
  PlotlySetup.imageExportFormat = "png";
377
420
  /**
@@ -391,6 +434,8 @@ PlotlySetup.setups = {
391
434
  doughnut: PlotlySetup.setupPie,
392
435
  pie: PlotlySetup.setupPie,
393
436
  scatter: PlotlySetup.setupScatter,
437
+ gauge: PlotlySetup.setupGauge,
438
+ bullet: PlotlySetup.setupGauge,
394
439
  };
395
440
  PlotlySetup.getTruncatedLabel = (label, labelTruncateLength) => {
396
441
  const truncateSymbols = "...";
@@ -404,262 +449,9 @@ PlotlySetup.getTruncatedLabel = (label, labelTruncateLength) => {
404
449
  return label.substring(0, labelTruncateLength) + truncateSymbols;
405
450
  };
406
451
 
407
- class PlotlyChartAdapter {
408
- constructor(model) {
409
- this.model = model;
410
- this._chart = undefined;
411
- }
412
- patchConfigParameters(chartNode, traces, layout, config) { }
413
- get chart() {
414
- return this._chart;
415
- }
416
- create(chartNode) {
417
- return __awaiter(this, void 0, void 0, function* () {
418
- const [plot, plotlyOptions] = yield this.update(chartNode);
419
- chartNode["on"]("plotly_click", (data) => {
420
- if (data.points.length > 0) {
421
- let itemText = "";
422
- if (!plotlyOptions.hasSeries) {
423
- itemText = Array.isArray(data.points[0].customdata)
424
- ? data.points[0].customdata[0]
425
- : data.points[0].customdata;
426
- const item = this.model.getSelectedItemByText(itemText);
427
- this.model.setSelection(item);
428
- }
429
- else {
430
- itemText = data.points[0].data.name;
431
- const propertyLabel = data.points[0].label;
432
- const seriesValues = this.model.getSeriesValues();
433
- const seriesLabels = this.model.getSeriesLabels();
434
- const propertyValue = seriesValues[seriesLabels.indexOf(propertyLabel)];
435
- const selectedItem = this.model.getSelectedItemByText(itemText);
436
- const item = new ItemValue({ [propertyValue]: selectedItem.value }, propertyLabel + ": " + selectedItem.text);
437
- this.model.setSelection(item);
438
- }
439
- // const itemText = plotlyOptions.hasSeries
440
- // ? data.points[0].data.name
441
- // : Array.isArray(data.points[0].customdata)
442
- // ? data.points[0].customdata[0]
443
- // : data.points[0].customdata;
444
- // const item: ItemValue = this.model.getSelectedItemByText(itemText);
445
- // this.model.setSelection(item);
446
- }
447
- });
448
- var getDragLayer = () => chartNode.getElementsByClassName("nsewdrag")[0];
449
- chartNode["on"]("plotly_hover", () => {
450
- const dragLayer = getDragLayer();
451
- dragLayer && (dragLayer.style.cursor = "pointer");
452
- });
453
- chartNode["on"]("plotly_unhover", () => {
454
- const dragLayer = getDragLayer();
455
- dragLayer && (dragLayer.style.cursor = "");
456
- });
457
- // setTimeout(() => Plotly.Plots.resize(chartNode), 10);
458
- this._chart = plot;
459
- return plot;
460
- });
461
- }
462
- update(chartNode) {
463
- return __awaiter(this, void 0, void 0, function* () {
464
- const answersData = yield this.model.getAnswersData();
465
- var plotlyOptions = PlotlySetup.setup(this.model.chartType, this.model, answersData);
466
- let config = {
467
- displaylogo: false,
468
- responsive: true,
469
- locale: localization.currentLocale,
470
- modeBarButtonsToRemove: ["toImage"],
471
- modeBarButtonsToAdd: [
472
- {
473
- name: "toImageSjs",
474
- title: localization.getString("saveDiagramAsPNG"),
475
- icon: Plotly.Icons.camera,
476
- click: (gd) => {
477
- let options = {
478
- format: PlotlySetup.imageExportFormat,
479
- // width: 800,
480
- // height: 600,
481
- filename: this.model.question.name,
482
- };
483
- PlotlySetup.onImageSaving.fire(this.model, options);
484
- Plotly.downloadImage(gd, options);
485
- },
486
- },
487
- ],
488
- };
489
- if (SelectBasePlotly.displayModeBar !== undefined) {
490
- config.displayModeBar = SelectBasePlotly.displayModeBar;
491
- }
492
- this.patchConfigParameters(chartNode, plotlyOptions.traces, plotlyOptions.layout, config);
493
- let options = {
494
- traces: plotlyOptions.traces,
495
- layout: plotlyOptions.layout,
496
- config: config,
497
- };
498
- PlotlySetup.onPlotCreating.fire(this.model, options);
499
- const plot = Plotly.react(chartNode, options.traces, options.layout, options.config);
500
- return [plot, plotlyOptions];
501
- });
502
- }
503
- destroy(node) {
504
- if (!!node) {
505
- Plotly.purge(node);
506
- }
507
- this._chart = undefined;
508
- }
509
- }
510
- class SelectBasePlotly extends SelectBase {
511
- constructor(question, data, options = {}, name) {
512
- super(question, data, options, name);
513
- this.chartTypes = [].concat(SelectBasePlotly.types);
514
- if (this.getSeriesValues().length > 0 && this.chartTypes.indexOf("stackedbar") === -1) {
515
- this.chartTypes.push("stackedbar");
516
- }
517
- if (options.allowExperimentalFeatures) ;
518
- this._chartType = this.chartTypes[0];
519
- if (this.chartTypes.indexOf(options.defaultChartType) !== -1) {
520
- this._chartType = options.defaultChartType;
521
- }
522
- this._chartAdapter = new PlotlyChartAdapter(this);
523
- }
524
- destroyContent(container) {
525
- this._chartAdapter.destroy(container.children[0]);
526
- super.destroyContent(container);
527
- }
528
- renderContentAsync(container) {
529
- return __awaiter(this, void 0, void 0, function* () {
530
- const chartNode = DocumentHelper.createElement("div");
531
- container.innerHTML = "";
532
- container.appendChild(chartNode);
533
- yield this._chartAdapter.create(chartNode);
534
- return container;
535
- });
536
- }
537
- updateContent() {
538
- var _a;
539
- const chartNode = (_a = this.contentContainer) === null || _a === void 0 ? void 0 : _a.children[0];
540
- if (chartNode) {
541
- this._chartAdapter.update(chartNode);
542
- }
543
- }
544
- }
545
- SelectBasePlotly.types = ["bar", "vbar", "pie", "doughnut"];
546
- SelectBasePlotly.displayModeBar = undefined;
547
- VisualizationManager.registerVisualizer("checkbox", SelectBasePlotly);
548
- VisualizationManager.registerVisualizer("radiogroup", SelectBasePlotly);
549
- VisualizationManager.registerVisualizer("dropdown", SelectBasePlotly);
550
- VisualizationManager.registerVisualizer("imagepicker", SelectBasePlotly);
551
- VisualizationManager.registerVisualizer("tagbox", SelectBasePlotly);
552
-
553
- class MatrixPlotly extends Matrix {
554
- constructor(question, data, options, name) {
555
- super(question, data, options, name);
556
- this.chartTypes = MatrixPlotly.types;
557
- this._chartType = this.chartTypes[0];
558
- this._chartAdapter = new PlotlyChartAdapter(this);
559
- }
560
- destroyContent(container) {
561
- this._chartAdapter.destroy(container.children[0]);
562
- super.destroyContent(container);
563
- }
564
- renderContentAsync(container) {
565
- return __awaiter(this, void 0, void 0, function* () {
566
- const chartNode = DocumentHelper.createElement("div");
567
- container.innerHTML = "";
568
- container.appendChild(chartNode);
569
- yield this._chartAdapter.create(chartNode);
570
- return container;
571
- });
572
- }
573
- }
574
- MatrixPlotly.types = ["bar", "stackedbar", "pie", "doughnut"];
575
- VisualizationManager.registerVisualizer("matrix", MatrixPlotly);
576
-
577
- class PlotlyBoolChartAdapter extends PlotlyChartAdapter {
578
- constructor(model) {
579
- super(model);
580
- }
581
- patchConfigParameters(chartNode, traces, layout, config) {
582
- const colors = this.model.getColors();
583
- const boolColors = [
584
- BooleanPlotly.trueColor || colors[0],
585
- BooleanPlotly.falseColor || colors[1],
586
- ];
587
- if (this.model.showMissingAnswers) {
588
- boolColors.push(colors[2]);
589
- }
590
- if (this.model.chartType === "pie" || this.model.chartType === "doughnut") {
591
- traces.forEach((trace) => {
592
- trace.marker.colors = boolColors;
593
- });
594
- }
595
- else if (this.model.chartType === "bar") {
596
- traces.forEach((trace) => {
597
- trace.marker.color = boolColors;
598
- });
599
- }
600
- }
601
- }
602
- class BooleanPlotly extends BooleanModel {
603
- constructor(question, data, options, name) {
604
- super(question, data, options, name);
605
- this.chartTypes = BooleanPlotly.types;
606
- this._chartType = this.chartTypes[0];
607
- this._chartAdapter = new PlotlyBoolChartAdapter(this);
608
- }
609
- destroyContent(container) {
610
- this._chartAdapter.destroy(container.children[0]);
611
- super.destroyContent(container);
612
- }
613
- renderContentAsync(container) {
614
- return __awaiter(this, void 0, void 0, function* () {
615
- const chartNode = DocumentHelper.createElement("div");
616
- yield this._chartAdapter.create(chartNode);
617
- container.innerHTML = "";
618
- container.appendChild(chartNode);
619
- return container;
620
- });
621
- }
622
- }
623
- BooleanPlotly.types = ["pie", "bar", "doughnut"];
624
- VisualizationManager.registerVisualizer("boolean", BooleanPlotly);
625
-
626
- class RankingPlotly extends SelectBasePlotly {
627
- getQuestionResults() {
628
- const name = this.question.name;
629
- return this.data.map((dataItem) => dataItem[name]);
630
- }
631
- getEmptyData() {
632
- const choices = this.getValues();
633
- let data = [];
634
- data.length = choices.length;
635
- data.fill(0);
636
- return data;
637
- }
638
- getCalculatedValuesCore() {
639
- const results = this.getQuestionResults();
640
- const choices = this.getValues();
641
- let plotlyData = this.getEmptyData();
642
- results.forEach((result) => {
643
- this.applyResultToPlotlyData(result, plotlyData, choices);
644
- });
645
- return [plotlyData];
646
- }
647
- applyResultToPlotlyData(result, plotlyData, choices) {
648
- if (!result || !plotlyData || !choices)
649
- return;
650
- result.forEach((resultValue, resultValueIndex, result) => {
651
- let index = choices.indexOf(resultValue);
652
- plotlyData[index] =
653
- +plotlyData[index] + (result.length - resultValueIndex);
654
- });
655
- }
656
- }
657
- VisualizationManager.registerVisualizer("ranking", RankingPlotly);
658
-
659
452
  class MatrixDropdownGrouped extends SelectBase {
660
453
  constructor(question, data, options, name) {
661
454
  super(question, data, options, name || "matrixDropdownGrouped");
662
- // this.getAnswersData();
663
455
  }
664
456
  get matrixQuestion() {
665
457
  return this.question;
@@ -696,124 +488,142 @@ class MatrixDropdownGrouped extends SelectBase {
696
488
  getSeriesValues: () => rows,
697
489
  getSeriesLabels: () => rows,
698
490
  });
699
- const preparedData = [];
700
- values.forEach((val, valueIndex) => {
701
- const seriesData = series.map((seriesName, seriesIndex) => statistics[seriesIndex][0][valueIndex]);
702
- preparedData.push(seriesData);
703
- });
704
- return preparedData;
491
+ return statistics.map(s => s[0]);
705
492
  }
706
493
  }
494
+ VisualizationManager.registerVisualizer("matrixdropdown-grouped", MatrixDropdownGrouped);
707
495
 
708
- class MatrixDropdownGroupedPlotly extends MatrixDropdownGrouped {
709
- constructor(question, data, options, name) {
710
- super(question, data, options, name);
711
- this.chartTypes = MatrixDropdownGroupedPlotly.types;
712
- this._chartType = this.chartTypes[0];
713
- this._chartAdapter = new PlotlyChartAdapter(this);
714
- }
715
- destroyContent(container) {
716
- this._chartAdapter.destroy(container.children[0]);
717
- super.destroyContent(container);
718
- }
719
- renderContentAsync(container) {
720
- return __awaiter(this, void 0, void 0, function* () {
721
- const chartNode = DocumentHelper.createElement("div");
722
- container.innerHTML = "";
723
- container.appendChild(chartNode);
724
- yield this._chartAdapter.create(chartNode);
725
- return container;
726
- });
727
- }
496
+ class SelectBasePlotly extends SelectBase {
728
497
  }
729
- MatrixDropdownGroupedPlotly.types = ["stackedbar", "bar", "pie", "doughnut"];
730
- VisualizationManager.registerVisualizer("matrixdropdown-grouped", MatrixDropdownGroupedPlotly);
731
-
498
+ SelectBasePlotly.types = ["bar", "vbar", "pie", "doughnut"];
499
+ SelectBasePlotly.displayModeBar = undefined;
500
+ class BooleanPlotly extends BooleanModel {
501
+ }
502
+ BooleanPlotly.types = ["pie", "bar", "doughnut"];
732
503
  class HistogramPlotly extends HistogramModel {
733
- constructor(question, data, options, name) {
734
- super(question, data, options, name);
735
- this.chartTypes = HistogramPlotly.types;
736
- this._chartType = this.chartTypes[0];
737
- this._chartAdapter = new PlotlyChartAdapter(this);
738
- }
739
- destroyContent(container) {
740
- this._chartAdapter.destroy(container.children[0]);
741
- super.destroyContent(container);
742
- }
743
- renderContentAsync(container) {
744
- return __awaiter(this, void 0, void 0, function* () {
745
- const chartNode = DocumentHelper.createElement("div");
746
- container.innerHTML = "";
747
- container.appendChild(chartNode);
748
- yield this._chartAdapter.create(chartNode);
749
- return container;
750
- });
751
- }
752
- getValueType() {
753
- return this.valueType;
754
- }
755
504
  }
756
505
  HistogramPlotly.types = ["vbar", "bar"];
757
- VisualizationManager.registerVisualizer("date", HistogramPlotly);
758
- VisualizationManager.registerVisualizer("number", HistogramPlotly);
759
- VisualizationManager.registerVisualizer("rating", HistogramPlotly);
506
+ class MatrixPlotly extends Matrix {
507
+ }
508
+ MatrixPlotly.types = ["bar", "stackedbar", "pie", "doughnut"];
509
+ class MatrixDropdownGroupedPlotly extends MatrixDropdownGrouped {
510
+ }
511
+ MatrixDropdownGroupedPlotly.types = ["stackedbar", "bar", "pie", "doughnut"];
512
+ class PivotPlotly extends PivotModel {
513
+ }
514
+ PivotPlotly.types = ["vbar", "bar", "line", "stackedbar", "pie", "doughnut"]; // ["vbar", "bar"];
515
+ class GaugePlotly extends NumberModel {
516
+ }
517
+ GaugePlotly.displayModeBar = undefined;
518
+ GaugePlotly.types = ["gauge", "bullet"];
519
+ class RankingPlotly extends RankingModel {
520
+ }
760
521
 
761
- class PlotlyGaugeAdapter {
522
+ const plotlyChartTypes = {
523
+ "boolean": BooleanPlotly.types,
524
+ "number": GaugePlotly.types,
525
+ "selectBase": SelectBasePlotly.types,
526
+ "histogram": HistogramPlotly.types,
527
+ "matrix": MatrixPlotly.types,
528
+ "matrixDropdownGrouped": MatrixDropdownGroupedPlotly.types,
529
+ "pivot": PivotPlotly.types,
530
+ };
531
+ class PlotlyChartAdapter {
762
532
  constructor(model) {
763
533
  this.model = model;
764
534
  this._chart = undefined;
765
535
  }
536
+ patchConfigParameters(chartNode, traces, layout, config) {
537
+ if (this.model.question.getType() === "boolean") {
538
+ const colors = this.model.getColors();
539
+ const boolColors = [
540
+ BooleanModel.trueColor || colors[0],
541
+ BooleanModel.falseColor || colors[1],
542
+ ];
543
+ if (this.model.showMissingAnswers) {
544
+ boolColors.push(colors[2]);
545
+ }
546
+ const chartType = this.model.chartType;
547
+ if (chartType === "pie" || chartType === "doughnut") {
548
+ traces.forEach((trace) => {
549
+ trace.marker.colors = boolColors;
550
+ });
551
+ }
552
+ else if (chartType === "bar") {
553
+ traces.forEach((trace) => {
554
+ trace.marker.color = boolColors;
555
+ });
556
+ }
557
+ }
558
+ if (this.model.type === "number") {
559
+ config.displayModeBar = true;
560
+ }
561
+ }
766
562
  get chart() {
767
563
  return this._chart;
768
564
  }
565
+ getChartTypes() {
566
+ const visualizerType = this.model.type;
567
+ const chartCtypes = plotlyChartTypes[visualizerType];
568
+ return chartCtypes || [];
569
+ }
769
570
  create(chartNode) {
770
571
  return __awaiter(this, void 0, void 0, function* () {
771
- const question = this.model.question;
772
- let [level, minValue, maxValue] = yield this.model.getCalculatedValues();
773
- if (question.getType() === "rating") {
774
- const rateValues = question.visibleRateValues;
775
- maxValue = rateValues[rateValues.length - 1].value;
776
- minValue = rateValues[0].value;
777
- }
778
- const colors = this.model.generateColors(maxValue, minValue, GaugePlotly.stepsCount);
779
- if (GaugePlotly.showAsPercentage) {
780
- level = DataHelper.toPercentage(level, maxValue);
781
- minValue = DataHelper.toPercentage(minValue, maxValue);
782
- maxValue = DataHelper.toPercentage(maxValue, maxValue);
572
+ const [plot, plotlyOptions] = yield this.update(chartNode);
573
+ if (this.model instanceof SelectBase) {
574
+ const _model = this.model;
575
+ chartNode["on"]("plotly_click", (data) => {
576
+ if (data.points.length > 0) {
577
+ let itemText = "";
578
+ if (!plotlyOptions.hasSeries) {
579
+ itemText = Array.isArray(data.points[0].customdata)
580
+ ? data.points[0].customdata[0]
581
+ : data.points[0].customdata;
582
+ const item = _model.getSelectedItemByText(itemText);
583
+ _model.setSelection(item);
584
+ }
585
+ else {
586
+ itemText = data.points[0].data.name;
587
+ const propertyLabel = data.points[0].label;
588
+ const seriesValues = this.model.getSeriesValues();
589
+ const seriesLabels = this.model.getSeriesLabels();
590
+ const propertyValue = seriesValues[seriesLabels.indexOf(propertyLabel)];
591
+ const selectedItem = _model.getSelectedItemByText(itemText);
592
+ const item = new ItemValue({ [propertyValue]: selectedItem.value }, propertyLabel + ": " + selectedItem.text);
593
+ _model.setSelection(item);
594
+ }
595
+ // const itemText = plotlyOptions.hasSeries
596
+ // ? data.points[0].data.name
597
+ // : Array.isArray(data.points[0].customdata)
598
+ // ? data.points[0].customdata[0]
599
+ // : data.points[0].customdata;
600
+ // const item: ItemValue = this.model.getSelectedItemByText(itemText);
601
+ // this.model.setSelection(item);
602
+ }
603
+ });
783
604
  }
784
- var data = [
785
- {
786
- type: "indicator",
787
- mode: "gauge+number",
788
- gauge: {
789
- axis: { range: [minValue, maxValue] },
790
- shape: this.model.chartType,
791
- bgcolor: "white",
792
- bar: { color: colors[0] },
793
- },
794
- value: level,
795
- text: question.name,
796
- domain: { x: [0, 1], y: [0, 1] },
797
- },
798
- ];
799
- const chartMargin = this.model.chartType === "bullet" ? 60 : 30;
800
- var layout = {
801
- height: 250,
802
- margin: {
803
- l: chartMargin,
804
- r: chartMargin,
805
- b: chartMargin,
806
- t: chartMargin,
807
- pad: 5
808
- },
809
- plot_bgcolor: this.model.backgroundColor,
810
- paper_bgcolor: this.model.backgroundColor,
811
- };
812
- const config = {
813
- displayModeBar: true,
814
- locale: localization.currentLocale,
815
- responsive: true,
605
+ var getDragLayer = () => chartNode.getElementsByClassName("nsewdrag")[0];
606
+ chartNode["on"]("plotly_hover", () => {
607
+ const dragLayer = getDragLayer();
608
+ dragLayer && (dragLayer.style.cursor = "pointer");
609
+ });
610
+ chartNode["on"]("plotly_unhover", () => {
611
+ const dragLayer = getDragLayer();
612
+ dragLayer && (dragLayer.style.cursor = "");
613
+ });
614
+ // setTimeout(() => Plotly.Plots.resize(chartNode), 10);
615
+ this._chart = plot;
616
+ return plot;
617
+ });
618
+ }
619
+ update(chartNode) {
620
+ return __awaiter(this, void 0, void 0, function* () {
621
+ const answersData = (this.model instanceof SelectBase) ? yield this.model.getAnswersData() : yield this.model.getCalculatedValues();
622
+ var plotlyOptions = PlotlySetup.setup(this.model.chartType, this.model, answersData);
623
+ let config = {
816
624
  displaylogo: false,
625
+ responsive: true,
626
+ locale: localization.currentLocale,
817
627
  modeBarButtonsToRemove: ["toImage"],
818
628
  modeBarButtonsToAdd: [
819
629
  {
@@ -833,18 +643,19 @@ class PlotlyGaugeAdapter {
833
643
  },
834
644
  ],
835
645
  };
836
- if (GaugePlotly.displayModeBar !== undefined) {
837
- config.displayModeBar = GaugePlotly.displayModeBar;
646
+ if (SelectBasePlotly.displayModeBar !== undefined) {
647
+ config.displayModeBar = SelectBasePlotly.displayModeBar;
838
648
  }
649
+ this.patchConfigParameters(chartNode, plotlyOptions.traces, plotlyOptions.layout, config);
839
650
  let options = {
840
- data: data,
841
- layout: layout,
651
+ traces: plotlyOptions.traces,
652
+ layout: plotlyOptions.layout,
653
+ data: answersData,
842
654
  config: config,
843
655
  };
844
656
  PlotlySetup.onPlotCreating.fire(this.model, options);
845
- const plot = Plotly.newPlot(chartNode, options.data, options.layout, options.config);
846
- // setTimeout(() => Plotly.Plots.resize(chartNode), 10);
847
- return plot;
657
+ const plot = Plotly.react(chartNode, options.traces, options.layout, options.config);
658
+ return [plot, plotlyOptions];
848
659
  });
849
660
  }
850
661
  destroy(node) {
@@ -854,59 +665,7 @@ class PlotlyGaugeAdapter {
854
665
  this._chart = undefined;
855
666
  }
856
667
  }
857
- class GaugePlotly extends NumberModel {
858
- constructor(question, data, options, name) {
859
- super(question, data, options, name);
860
- this.chartTypes = GaugePlotly.types;
861
- this.chartType = this.chartTypes[0];
862
- this._chartAdapter = new PlotlyGaugeAdapter(this);
863
- }
864
- destroyContent(container) {
865
- this._chartAdapter.destroy(container.children[0]);
866
- super.destroyContent(container);
867
- }
868
- renderContentAsync(container) {
869
- return __awaiter(this, void 0, void 0, function* () {
870
- const chartNode = DocumentHelper.createElement("div");
871
- container.innerHTML = "";
872
- container.appendChild(chartNode);
873
- yield this._chartAdapter.create(chartNode);
874
- return container;
875
- });
876
- }
877
- }
878
- GaugePlotly.displayModeBar = undefined;
879
- GaugePlotly.types = ["gauge", "bullet"];
880
- VisualizationManager.registerVisualizer("number", GaugePlotly);
881
- VisualizationManager.registerVisualizer("rating", GaugePlotly);
882
- VisualizationManager.registerVisualizer("expression", GaugePlotly);
883
-
884
- class PivotPlotly extends PivotModel {
885
- constructor(questions, data, options, name) {
886
- super(questions, data, options, name);
887
- this.chartTypes = PivotPlotly.types;
888
- this._chartType = this.chartTypes[0];
889
- this._chartAdapter = new PlotlyChartAdapter(this);
890
- }
891
- destroyContent(container) {
892
- this._chartAdapter.destroy(container.children[0]);
893
- super.destroyContent(container);
894
- }
895
- renderContentAsync(container) {
896
- return __awaiter(this, void 0, void 0, function* () {
897
- const chartNode = DocumentHelper.createElement("div");
898
- container.innerHTML = "";
899
- container.appendChild(chartNode);
900
- yield this._chartAdapter.create(chartNode);
901
- return container;
902
- });
903
- }
904
- getValueType() {
905
- return this.valueType;
906
- }
907
- }
908
- PivotPlotly.types = ["vbar", "bar", "line", "stackedbar", "pie", "doughnut"]; // ["vbar", "bar"];
909
- VisualizationManager.registerPivotVisualizer(PivotPlotly);
668
+ VisualizerBase.chartAdapterType = PlotlyChartAdapter;
910
669
 
911
- export { BooleanModel, BooleanPlotly, DocumentHelper, GaugePlotly, HistogramModel, HistogramPlotly, Matrix, MatrixDropdownGroupedPlotly, MatrixPlotly, NumberModel, PivotModel, PivotPlotly, PlotlyBoolChartAdapter, PlotlyChartAdapter, PlotlyGaugeAdapter, PlotlySetup, RankingPlotly, SelectBase, SelectBasePlotly, VisualizationManager, defaultStatisticsCalculator, localization };
670
+ export { BooleanModel, BooleanPlotly, GaugePlotly, HistogramModel, HistogramPlotly, Matrix, MatrixDropdownGroupedPlotly, MatrixPlotly, NumberModel, PivotModel, PivotPlotly, PlotlyChartAdapter, PlotlySetup, RankingModel, RankingPlotly, SelectBase, SelectBasePlotly, VisualizationManager, VisualizerBase, localization, plotlyChartTypes };
912
671
  //# sourceMappingURL=survey.analytics.mjs.map