survey-analytics 2.2.3 → 2.2.4

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 (42) hide show
  1. package/fesm/shared.mjs +1 -1
  2. package/fesm/shared2.mjs +298 -193
  3. package/fesm/shared2.mjs.map +1 -1
  4. package/fesm/survey.analytics.core.mjs +2 -2
  5. package/fesm/survey.analytics.mjs +187 -418
  6. package/fesm/survey.analytics.mjs.map +1 -1
  7. package/fesm/survey.analytics.tabulator.mjs +1 -1
  8. package/package.json +2 -2
  9. package/survey-analytics.types/boolean.d.ts +0 -1
  10. package/survey-analytics.types/entries/summary.core.d.ts +2 -1
  11. package/survey-analytics.types/histogram.d.ts +1 -1
  12. package/survey-analytics.types/pivot.d.ts +2 -0
  13. package/survey-analytics.types/plotly/chart-adapter.d.ts +13 -0
  14. package/survey-analytics.types/plotly/index.d.ts +2 -8
  15. package/survey-analytics.types/plotly/legacy.d.ts +33 -0
  16. package/survey-analytics.types/plotly/setup.d.ts +5 -3
  17. package/survey-analytics.types/{plotly/ranking.d.ts → ranking.d.ts} +2 -2
  18. package/survey-analytics.types/selectBase.d.ts +2 -0
  19. package/survey-analytics.types/visualizerBase.d.ts +11 -0
  20. package/survey.analytics.core.css +1 -1
  21. package/survey.analytics.core.js +178 -23
  22. package/survey.analytics.core.js.map +1 -1
  23. package/survey.analytics.core.min.css +1 -1
  24. package/survey.analytics.core.min.js +1 -1
  25. package/survey.analytics.core.min.js.LICENSE.txt +1 -1
  26. package/survey.analytics.css +1 -1
  27. package/survey.analytics.js +491 -762
  28. package/survey.analytics.js.map +1 -1
  29. package/survey.analytics.min.css +1 -1
  30. package/survey.analytics.min.js +1 -1
  31. package/survey.analytics.min.js.LICENSE.txt +1 -1
  32. package/survey.analytics.tabulator.css +1 -1
  33. package/survey.analytics.tabulator.js +1 -1
  34. package/survey.analytics.tabulator.min.css +1 -1
  35. package/survey.analytics.tabulator.min.js.LICENSE.txt +1 -1
  36. package/survey-analytics.types/plotly/boolean.d.ts +0 -16
  37. package/survey-analytics.types/plotly/histogram.d.ts +0 -12
  38. package/survey-analytics.types/plotly/matrix.d.ts +0 -11
  39. package/survey-analytics.types/plotly/matrixdropdown-grouped.d.ts +0 -11
  40. package/survey-analytics.types/plotly/pivot.d.ts +0 -12
  41. package/survey-analytics.types/plotly/rating.d.ts +0 -20
  42. 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.4
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, d as defaultStatisticsCalculator, B as BooleanModel, H as HistogramModel, M as Matrix, p as PivotModel, R as RankingModel, a as VisualizerBase, _ as __awaiter } 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, V as VisualizerFactory, i 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,153 @@ 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
+ class PlotlyChartAdapter {
762
523
  constructor(model) {
763
524
  this.model = model;
764
525
  this._chart = undefined;
765
526
  }
527
+ patchConfigParameters(chartNode, traces, layout, config) {
528
+ if (this.model.question.getType() === "boolean") {
529
+ const colors = this.model.getColors();
530
+ const boolColors = [
531
+ BooleanModel.trueColor || colors[0],
532
+ BooleanModel.falseColor || colors[1],
533
+ ];
534
+ if (this.model.showMissingAnswers) {
535
+ boolColors.push(colors[2]);
536
+ }
537
+ const chartType = this.model.chartType;
538
+ if (chartType === "pie" || chartType === "doughnut") {
539
+ traces.forEach((trace) => {
540
+ trace.marker.colors = boolColors;
541
+ });
542
+ }
543
+ else if (chartType === "bar") {
544
+ traces.forEach((trace) => {
545
+ trace.marker.color = boolColors;
546
+ });
547
+ }
548
+ }
549
+ if (this.model.type === "number") {
550
+ config.displayModeBar = true;
551
+ }
552
+ }
766
553
  get chart() {
767
554
  return this._chart;
768
555
  }
556
+ getChartTypes() {
557
+ const visualizerType = this.model.type;
558
+ if (visualizerType === "boolean") {
559
+ return BooleanPlotly.types;
560
+ }
561
+ else if (visualizerType === "number") {
562
+ return GaugePlotly.types;
563
+ }
564
+ else if (visualizerType === "selectBase") {
565
+ return SelectBasePlotly.types;
566
+ }
567
+ else if (visualizerType === "histogram") {
568
+ return HistogramPlotly.types;
569
+ }
570
+ else if (visualizerType === "matrix") {
571
+ return MatrixPlotly.types;
572
+ }
573
+ else if (visualizerType === "matrixDropdownGrouped") {
574
+ return MatrixDropdownGroupedPlotly.types;
575
+ }
576
+ else if (visualizerType === "pivot") {
577
+ return PivotPlotly.types;
578
+ }
579
+ return [];
580
+ }
769
581
  create(chartNode) {
770
582
  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);
583
+ const [plot, plotlyOptions] = yield this.update(chartNode);
584
+ if (this.model instanceof SelectBase) {
585
+ const _model = this.model;
586
+ chartNode["on"]("plotly_click", (data) => {
587
+ if (data.points.length > 0) {
588
+ let itemText = "";
589
+ if (!plotlyOptions.hasSeries) {
590
+ itemText = Array.isArray(data.points[0].customdata)
591
+ ? data.points[0].customdata[0]
592
+ : data.points[0].customdata;
593
+ const item = _model.getSelectedItemByText(itemText);
594
+ _model.setSelection(item);
595
+ }
596
+ else {
597
+ itemText = data.points[0].data.name;
598
+ const propertyLabel = data.points[0].label;
599
+ const seriesValues = this.model.getSeriesValues();
600
+ const seriesLabels = this.model.getSeriesLabels();
601
+ const propertyValue = seriesValues[seriesLabels.indexOf(propertyLabel)];
602
+ const selectedItem = _model.getSelectedItemByText(itemText);
603
+ const item = new ItemValue({ [propertyValue]: selectedItem.value }, propertyLabel + ": " + selectedItem.text);
604
+ _model.setSelection(item);
605
+ }
606
+ // const itemText = plotlyOptions.hasSeries
607
+ // ? data.points[0].data.name
608
+ // : Array.isArray(data.points[0].customdata)
609
+ // ? data.points[0].customdata[0]
610
+ // : data.points[0].customdata;
611
+ // const item: ItemValue = this.model.getSelectedItemByText(itemText);
612
+ // this.model.setSelection(item);
613
+ }
614
+ });
783
615
  }
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,
616
+ var getDragLayer = () => chartNode.getElementsByClassName("nsewdrag")[0];
617
+ chartNode["on"]("plotly_hover", () => {
618
+ const dragLayer = getDragLayer();
619
+ dragLayer && (dragLayer.style.cursor = "pointer");
620
+ });
621
+ chartNode["on"]("plotly_unhover", () => {
622
+ const dragLayer = getDragLayer();
623
+ dragLayer && (dragLayer.style.cursor = "");
624
+ });
625
+ // setTimeout(() => Plotly.Plots.resize(chartNode), 10);
626
+ this._chart = plot;
627
+ return plot;
628
+ });
629
+ }
630
+ update(chartNode) {
631
+ return __awaiter(this, void 0, void 0, function* () {
632
+ const answersData = (this.model instanceof SelectBase) ? yield this.model.getAnswersData() : yield this.model.getCalculatedValues();
633
+ var plotlyOptions = PlotlySetup.setup(this.model.chartType, this.model, answersData);
634
+ let config = {
816
635
  displaylogo: false,
636
+ responsive: true,
637
+ locale: localization.currentLocale,
817
638
  modeBarButtonsToRemove: ["toImage"],
818
639
  modeBarButtonsToAdd: [
819
640
  {
@@ -833,18 +654,18 @@ class PlotlyGaugeAdapter {
833
654
  },
834
655
  ],
835
656
  };
836
- if (GaugePlotly.displayModeBar !== undefined) {
837
- config.displayModeBar = GaugePlotly.displayModeBar;
657
+ if (SelectBasePlotly.displayModeBar !== undefined) {
658
+ config.displayModeBar = SelectBasePlotly.displayModeBar;
838
659
  }
660
+ this.patchConfigParameters(chartNode, plotlyOptions.traces, plotlyOptions.layout, config);
839
661
  let options = {
840
- data: data,
841
- layout: layout,
662
+ traces: plotlyOptions.traces,
663
+ layout: plotlyOptions.layout,
842
664
  config: config,
843
665
  };
844
666
  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;
667
+ const plot = Plotly.react(chartNode, options.traces, options.layout, options.config);
668
+ return [plot, plotlyOptions];
848
669
  });
849
670
  }
850
671
  destroy(node) {
@@ -854,59 +675,7 @@ class PlotlyGaugeAdapter {
854
675
  this._chart = undefined;
855
676
  }
856
677
  }
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);
678
+ VisualizerBase.chartAdapterType = PlotlyChartAdapter;
910
679
 
911
- export { BooleanModel, BooleanPlotly, DocumentHelper, GaugePlotly, HistogramModel, HistogramPlotly, Matrix, MatrixDropdownGroupedPlotly, MatrixPlotly, NumberModel, PivotModel, PivotPlotly, PlotlyBoolChartAdapter, PlotlyChartAdapter, PlotlyGaugeAdapter, PlotlySetup, RankingPlotly, SelectBase, SelectBasePlotly, VisualizationManager, defaultStatisticsCalculator, localization };
680
+ export { BooleanModel, BooleanPlotly, GaugePlotly, HistogramModel, HistogramPlotly, Matrix, MatrixDropdownGroupedPlotly, MatrixPlotly, NumberModel, PivotModel, PivotPlotly, PlotlyChartAdapter, PlotlySetup, RankingModel, RankingPlotly, SelectBase, SelectBasePlotly, VisualizationManager, VisualizerBase, defaultStatisticsCalculator, localization };
912
681
  //# sourceMappingURL=survey.analytics.mjs.map