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
package/fesm/shared2.mjs CHANGED
@@ -1,11 +1,11 @@
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
- import { Event, QuestionCommentModel, settings, ItemValue, hasLicense, surveyLocalization, IsTouch, Helpers } from 'survey-core';
8
7
  import { D as DocumentHelper, l as localization, f as createLoadingIndicator, a as DataHelper, e as svgTemplate, d as createCommercialLicenseLink, t as toPrecision } from './shared.mjs';
8
+ import { Event, QuestionCommentModel, settings, ItemValue, hasLicense, surveyLocalization, IsTouch, Helpers } from 'survey-core';
9
9
 
10
10
  /******************************************************************************
11
11
  Copyright (c) Microsoft Corporation.
@@ -217,10 +217,10 @@ class VisualizationManager {
217
217
  static getVisualizersByType(questionType) {
218
218
  let vDescrs = VisualizationManager.vizualizers[questionType];
219
219
  if (!vDescrs) {
220
- if (VisualizerBase.suppressVisualizerStubRendering) {
220
+ if (VisualizationManager.defaultVisualizer.suppressVisualizerStubRendering) {
221
221
  return [];
222
222
  }
223
- return [VisualizerBase];
223
+ return [VisualizationManager.defaultVisualizer];
224
224
  }
225
225
  vDescrs = [].concat(vDescrs);
226
226
  vDescrs.sort((v1, v2) => v1.index - v2.index);
@@ -231,7 +231,7 @@ class VisualizationManager {
231
231
  * @see registerAltVisualizerSelector
232
232
  */
233
233
  static getAltVisualizerSelector() {
234
- return VisualizationManager.alternativesVisualizer || VisualizerBase;
234
+ return VisualizationManager.alternativesVisualizer || VisualizationManager.defaultVisualizer;
235
235
  }
236
236
  /**
237
237
  * Registers an alternative visualizer selector.
@@ -241,12 +241,13 @@ class VisualizationManager {
241
241
  VisualizationManager.alternativesVisualizer = constructor;
242
242
  }
243
243
  static getPivotVisualizerConstructor() {
244
- return VisualizationManager.pivotVisualizer || VisualizerBase;
244
+ return VisualizationManager.pivotVisualizer || VisualizationManager.defaultVisualizer;
245
245
  }
246
246
  static registerPivotVisualizer(constructor) {
247
247
  VisualizationManager.pivotVisualizer = constructor;
248
248
  }
249
249
  }
250
+ VisualizationManager.defaultVisualizer = undefined;
250
251
  VisualizationManager.alternativesVisualizer = undefined;
251
252
  VisualizationManager.pivotVisualizer = undefined;
252
253
  VisualizationManager.vizualizers = {};
@@ -294,6 +295,104 @@ class VisualizerFactory {
294
295
  }
295
296
  }
296
297
 
298
+ function defaultStatisticsCalculator(data, dataInfo) {
299
+ const dataNames = dataInfo.dataNames;
300
+ const statistics = [];
301
+ const values = dataInfo.getValues();
302
+ const valuesIndex = {};
303
+ values.forEach((val, index) => {
304
+ valuesIndex[val] = index;
305
+ });
306
+ const processMissingAnswers = values.indexOf(undefined) !== -1;
307
+ const series = dataInfo.getSeriesValues();
308
+ const seriesIndex = {};
309
+ series.forEach((val, index) => {
310
+ seriesIndex[val] = index;
311
+ });
312
+ const seriesLength = series.length || 1;
313
+ for (var i = 0; i < dataNames.length; ++i) {
314
+ const dataNameStatistics = new Array();
315
+ for (var j = 0; j < seriesLength; ++j) {
316
+ dataNameStatistics.push(new Array(values.length).fill(0));
317
+ }
318
+ statistics.push(dataNameStatistics);
319
+ }
320
+ data.forEach((row) => {
321
+ dataNames.forEach((dataName, index) => {
322
+ const rowValue = row[dataName];
323
+ if (rowValue !== undefined || processMissingAnswers) {
324
+ const rowValues = Array.isArray(rowValue) ? rowValue : [rowValue];
325
+ if (series.length > 0) {
326
+ if (row[DataProvider.seriesMarkerKey] !== undefined) {
327
+ // Series are labelled by seriesMarkerKey in row data
328
+ const seriesNo = seriesIndex[row[DataProvider.seriesMarkerKey]] || 0;
329
+ rowValues.forEach((val) => {
330
+ statistics[index][seriesNo][valuesIndex[val]]++;
331
+ });
332
+ }
333
+ else {
334
+ // Series are the keys in question value (matrix question)
335
+ // TODO: think about the de-normalization and combine with the previous case
336
+ rowValues.forEach((val) => {
337
+ series.forEach((seriesName) => {
338
+ if (val[seriesName] !== undefined) {
339
+ const seriesNo = seriesIndex[seriesName] || 0;
340
+ statistics[index][seriesNo][valuesIndex[val[seriesName]]]++;
341
+ }
342
+ });
343
+ });
344
+ }
345
+ }
346
+ else {
347
+ // No series
348
+ rowValues.forEach((val) => statistics[0][0][valuesIndex[val]]++);
349
+ }
350
+ }
351
+ });
352
+ });
353
+ return dataInfo.dataNames.length > 1 ? statistics : statistics[0];
354
+ }
355
+ function histogramStatisticsCalculator(data, intervals, seriesValues) {
356
+ const statistics = [];
357
+ if (seriesValues.length === 0) {
358
+ seriesValues.push("");
359
+ }
360
+ for (var i = 0; i < seriesValues.length; ++i) {
361
+ statistics.push(intervals.map(i => 0));
362
+ data[seriesValues[i]].forEach(dataValue => {
363
+ for (let j = 0; j < intervals.length; ++j) {
364
+ if (intervals[j].start <= dataValue && (dataValue < intervals[j].end || j == intervals.length - 1)) {
365
+ statistics[i][j]++;
366
+ break;
367
+ }
368
+ }
369
+ });
370
+ }
371
+ return statistics;
372
+ }
373
+ function mathStatisticsCalculator(data, dataName) {
374
+ let resultMin = Number.MAX_VALUE, resultMax = -Number.MAX_VALUE, resultAverage = 0;
375
+ let actualAnswerCount = 0;
376
+ data.forEach((rowData) => {
377
+ if (rowData[dataName] !== undefined) {
378
+ const questionValue = +rowData[dataName];
379
+ actualAnswerCount++;
380
+ resultAverage += questionValue;
381
+ if (resultMin > questionValue) {
382
+ resultMin = questionValue;
383
+ }
384
+ if (resultMax < questionValue) {
385
+ resultMax = questionValue;
386
+ }
387
+ }
388
+ });
389
+ if (actualAnswerCount > 0) {
390
+ resultAverage = resultAverage / actualAnswerCount;
391
+ }
392
+ resultAverage = Math.ceil(resultAverage * 100) / 100;
393
+ return [resultAverage, resultMin, resultMax];
394
+ }
395
+
297
396
  class PostponeHelper {
298
397
  static postpone(fn, timeout) {
299
398
  if (PostponeHelper.postponeFunction) {
@@ -356,6 +455,7 @@ class VisualizerBase {
356
455
  this.contentContainer = undefined;
357
456
  this.footerContainer = undefined;
358
457
  this._supportSelection = false;
458
+ this._chartAdapter = undefined;
359
459
  /**
360
460
  * An event that is raised after the visualizer's content is rendered.
361
461
  *
@@ -673,9 +773,10 @@ class VisualizerBase {
673
773
  if (!!this.options && typeof this.options.destroyContent === "function") {
674
774
  this.options.destroyContent(container, this);
675
775
  }
676
- else {
677
- container.innerHTML = "";
776
+ else if (this._chartAdapter) {
777
+ this._chartAdapter.destroy(container.children[0]);
678
778
  }
779
+ container.innerHTML = "";
679
780
  }
680
781
  renderHeader(container) {
681
782
  if (!!this.options && typeof this.options.renderHeader === "function") {
@@ -689,10 +790,16 @@ class VisualizerBase {
689
790
  }
690
791
  renderContentAsync(container) {
691
792
  return __awaiter(this, void 0, void 0, function* () {
692
- return new Promise((resolve, reject) => {
793
+ if (this._chartAdapter) {
794
+ const chartNode = DocumentHelper.createElement("div");
795
+ container.innerHTML = "";
796
+ container.appendChild(chartNode);
797
+ yield this._chartAdapter.create(chartNode);
798
+ }
799
+ else {
693
800
  container.innerText = localization.getString("noVisualizerForQuestion");
694
- resolve(container);
695
- });
801
+ }
802
+ return container;
696
803
  });
697
804
  }
698
805
  ensureQuestionIsReady() {
@@ -779,10 +886,23 @@ class VisualizerBase {
779
886
  });
780
887
  }
781
888
  }
782
- updateContent() {
889
+ isSupportSoftUpdateContent() {
890
+ return false;
891
+ }
892
+ softUpdateContent() {
893
+ }
894
+ hardUpdateContent() {
783
895
  this.destroyContent(this.contentContainer);
784
896
  this.renderContent(this.contentContainer);
785
897
  }
898
+ updateContent() {
899
+ if (!this.isSupportSoftUpdateContent()) {
900
+ this.hardUpdateContent();
901
+ }
902
+ else {
903
+ this.softUpdateContent();
904
+ }
905
+ }
786
906
  /**
787
907
  * Re-renders the visualizer and its content.
788
908
  */
@@ -973,6 +1093,7 @@ class VisualizerBase {
973
1093
  }
974
1094
  }
975
1095
  VisualizerBase.suppressVisualizerStubRendering = false;
1096
+ VisualizerBase.chartAdapterType = undefined;
976
1097
  // public static otherCommentQuestionType = "comment"; // TODO: make it configureable - allow choose what kind of question/visualizer will be used for comments/others
977
1098
  VisualizerBase.otherCommentCollapsed = true;
978
1099
  VisualizerBase.customColors = [];
@@ -988,63 +1109,112 @@ VisualizerBase.colors = [
988
1109
  "#cf37a6",
989
1110
  "#4e6198",
990
1111
  ];
991
- function defaultStatisticsCalculator(data, dataInfo) {
992
- const dataNames = dataInfo.dataNames;
993
- const statistics = [];
994
- const values = dataInfo.getValues();
995
- const valuesIndex = {};
996
- values.forEach((val, index) => {
997
- valuesIndex[val] = index;
998
- });
999
- const processMissingAnswers = values.indexOf(undefined) !== -1;
1000
- const series = dataInfo.getSeriesValues();
1001
- const seriesIndex = {};
1002
- series.forEach((val, index) => {
1003
- seriesIndex[val] = index;
1004
- });
1005
- const seriesLength = series.length || 1;
1006
- for (var i = 0; i < dataNames.length; ++i) {
1007
- const dataNameStatistics = new Array();
1008
- for (var j = 0; j < seriesLength; ++j) {
1009
- dataNameStatistics.push(new Array(values.length).fill(0));
1112
+ VisualizationManager.defaultVisualizer = VisualizerBase;
1113
+
1114
+ class NumberModel extends VisualizerBase {
1115
+ constructor(question, data, options = {}, name) {
1116
+ super(question, data, options, name || "number");
1117
+ if (VisualizerBase.chartAdapterType) {
1118
+ this._chartAdapter = new VisualizerBase.chartAdapterType(this);
1119
+ this.chartTypes = this._chartAdapter.getChartTypes();
1120
+ this.chartType = this.chartTypes[0];
1010
1121
  }
1011
- statistics.push(dataNameStatistics);
1012
- }
1013
- data.forEach((row) => {
1014
- dataNames.forEach((dataName, index) => {
1015
- const rowValue = row[dataName];
1016
- if (rowValue !== undefined || processMissingAnswers) {
1017
- const rowValues = Array.isArray(rowValue) ? rowValue : [rowValue];
1018
- if (series.length > 0) {
1019
- if (row[DataProvider.seriesMarkerKey] !== undefined) {
1020
- // Series are labelled by seriesMarkerKey in row data
1021
- const seriesNo = seriesIndex[row[DataProvider.seriesMarkerKey]] || 0;
1022
- rowValues.forEach((val) => {
1023
- statistics[index][seriesNo][valuesIndex[val]]++;
1024
- });
1025
- }
1026
- else {
1027
- // Series are the keys in question value (matrix question)
1028
- // TODO: think about the de-normalization and combine with the previous case
1029
- rowValues.forEach((val) => {
1030
- series.forEach((seriesName) => {
1031
- if (val[seriesName] !== undefined) {
1032
- const seriesNo = seriesIndex[seriesName] || 0;
1033
- statistics[index][seriesNo][valuesIndex[val[seriesName]]]++;
1034
- }
1035
- });
1036
- });
1037
- }
1038
- }
1039
- else {
1040
- // No series
1041
- rowValues.forEach((val) => statistics[0][0][valuesIndex[val]]++);
1042
- }
1122
+ this.registerToolbarItem("changeChartType", () => {
1123
+ if (this.chartTypes.length > 1) {
1124
+ return DocumentHelper.createSelector(this.chartTypes.map((chartType) => {
1125
+ return {
1126
+ value: chartType,
1127
+ text: localization.getString("chartType_" + chartType),
1128
+ };
1129
+ }), (option) => this.chartType === option.value, (e) => {
1130
+ this.setChartType(e.target.value);
1131
+ });
1043
1132
  }
1133
+ return null;
1044
1134
  });
1045
- });
1046
- return dataInfo.dataNames.length > 1 ? statistics : statistics[0];
1135
+ }
1136
+ onDataChanged() {
1137
+ this._resultAverage = undefined;
1138
+ this._resultMin = undefined;
1139
+ this._resultMax = undefined;
1140
+ super.onDataChanged();
1141
+ }
1142
+ onChartTypeChanged() { }
1143
+ setChartType(chartType) {
1144
+ if (this.chartTypes.indexOf(chartType) !== -1 &&
1145
+ this.chartType !== chartType) {
1146
+ this.chartType = chartType;
1147
+ this.onChartTypeChanged();
1148
+ if (!!this.contentContainer) {
1149
+ this.destroyContent(this.contentContainer);
1150
+ this.renderContent(this.contentContainer);
1151
+ }
1152
+ this.invokeOnUpdate();
1153
+ }
1154
+ }
1155
+ destroy() {
1156
+ this._resultAverage = undefined;
1157
+ this._resultMin = undefined;
1158
+ this._resultMax = undefined;
1159
+ super.destroy();
1160
+ }
1161
+ generateText(maxValue, minValue, stepsCount) {
1162
+ let texts = [];
1163
+ if (stepsCount === 5) {
1164
+ texts = [
1165
+ "very high (" + maxValue + ")",
1166
+ "high",
1167
+ "medium",
1168
+ "low",
1169
+ "very low (" + minValue + ")",
1170
+ ];
1171
+ }
1172
+ else {
1173
+ texts.push(maxValue);
1174
+ for (let i = 0; i < stepsCount - 2; i++) {
1175
+ texts.push("");
1176
+ }
1177
+ texts.push(minValue);
1178
+ }
1179
+ if (!!NumberModel.generateTextsCallback) {
1180
+ return NumberModel.generateTextsCallback(this.question, maxValue, minValue, stepsCount, texts);
1181
+ }
1182
+ return texts;
1183
+ }
1184
+ generateValues(maxValue, stepsCount) {
1185
+ const values = [];
1186
+ for (let i = 0; i < stepsCount; i++) {
1187
+ values.push(maxValue / stepsCount);
1188
+ }
1189
+ values.push(maxValue);
1190
+ return values;
1191
+ }
1192
+ generateColors(maxValue, minValue, stepsCount) {
1193
+ const palette = this.getColors();
1194
+ const colors = [];
1195
+ for (let i = 0; i < stepsCount; i++) {
1196
+ colors.push(palette[i]);
1197
+ }
1198
+ colors.push("rgba(255, 255, 255, 0)");
1199
+ return colors;
1200
+ }
1201
+ convertFromExternalData(externalCalculatedData) {
1202
+ return [externalCalculatedData.value || 0, externalCalculatedData.minValue || 0, externalCalculatedData.maxValue || 0];
1203
+ }
1204
+ getCalculatedValuesCore() {
1205
+ if (this._resultAverage === undefined ||
1206
+ this._resultMin === undefined ||
1207
+ this._resultMax === undefined) {
1208
+ [this._resultAverage, this._resultMin, this._resultMax] = mathStatisticsCalculator(this.surveyData, this.dataNames[0]);
1209
+ }
1210
+ return [this._resultAverage, this._resultMin, this._resultMax];
1211
+ }
1047
1212
  }
1213
+ NumberModel.stepsCount = 5;
1214
+ NumberModel.showAsPercentage = false;
1215
+ VisualizationManager.registerVisualizer("number", NumberModel, 200);
1216
+ VisualizationManager.registerVisualizer("rating", NumberModel, 200);
1217
+ VisualizationManager.registerVisualizer("expression", NumberModel);
1048
1218
 
1049
1219
  function hideEmptyAnswersInData(answersData) {
1050
1220
  const result = {
@@ -1150,6 +1320,18 @@ class SelectBase extends VisualizerBase {
1150
1320
  this._hideEmptyAnswers = this.options.hideEmptyAnswers === true;
1151
1321
  this._answersOrder = this.options.answersOrder || "default";
1152
1322
  this._showMissingAnswers = this.isSupportMissingAnswers() && this.options.showMissingAnswers === true;
1323
+ if (this.options.allowExperimentalFeatures) ;
1324
+ if (VisualizerBase.chartAdapterType) {
1325
+ this._chartAdapter = new VisualizerBase.chartAdapterType(this);
1326
+ this.chartTypes = this._chartAdapter.getChartTypes();
1327
+ if (this.getSeriesValues().length > 0 && this.chartTypes.indexOf("stackedbar") === -1) {
1328
+ this.chartTypes.push("stackedbar");
1329
+ }
1330
+ this._chartType = this.chartTypes[0];
1331
+ if (this.chartTypes.indexOf(this.options.defaultChartType) !== -1) {
1332
+ this._chartType = this.options.defaultChartType;
1333
+ }
1334
+ }
1153
1335
  this.registerToolbarItem("changeChartType", () => {
1154
1336
  if (this.chartTypes.length > 1) {
1155
1337
  return DocumentHelper.createSelector(this.chartTypes.map((chartType) => {
@@ -1327,6 +1509,16 @@ class SelectBase extends VisualizerBase {
1327
1509
  const selectBaseQuestion = this.question;
1328
1510
  return resultValues.map((value) => ItemValue.getTextOrHtmlByValue(selectBaseQuestion.choices, value)).join(", ");
1329
1511
  }
1512
+ isSupportSoftUpdateContent() {
1513
+ return true;
1514
+ }
1515
+ softUpdateContent() {
1516
+ var _a;
1517
+ const chartNode = (_a = this.contentContainer) === null || _a === void 0 ? void 0 : _a.children[0];
1518
+ if (chartNode) {
1519
+ this._chartAdapter.update(chartNode);
1520
+ }
1521
+ }
1330
1522
  getSelectedItemByText(itemText) {
1331
1523
  const selBase = this.question;
1332
1524
  if (this.question.hasOther && itemText == selBase.otherText) {
@@ -1637,87 +1829,11 @@ class SelectBase extends VisualizerBase {
1637
1829
  }
1638
1830
  SelectBase.topNValuesDefaults = [-1, 5, 10, 20];
1639
1831
  SelectBase._stateProperties = ["chartType", "answersOrder", "hideEmptyAnswers", "topN"];
1640
-
1641
- class Matrix extends SelectBase {
1642
- constructor(question, data, options, name) {
1643
- super(question, data, options, name || "matrix");
1644
- this._transposeData = true;
1645
- // this.getAnswersData();
1646
- }
1647
- get matrixQuestion() {
1648
- return this.question;
1649
- }
1650
- isSupportMissingAnswers() {
1651
- return false;
1652
- }
1653
- getSeriesValues() {
1654
- return this.matrixQuestion.rows.map((row) => "" + row.value);
1655
- }
1656
- getSeriesLabels() {
1657
- return this.matrixQuestion.rows.map((row) => ItemValue.getTextOrHtmlByValue(this.matrixQuestion.rows, row.value));
1658
- }
1659
- getSelectedItemByText(itemText) {
1660
- return this.matrixQuestion.columns.filter((column) => column.text === itemText)[0];
1661
- }
1662
- valuesSource() {
1663
- return this.matrixQuestion.columns;
1664
- }
1665
- getHasAnswersInAllSeriesArray(datasets) {
1666
- let result = Array();
1667
- for (let i = 0; i < datasets[0].length; i++) {
1668
- for (let j = 0; j < datasets.length; j++) {
1669
- if (datasets[j][i] != 0) {
1670
- result[i] = true;
1671
- }
1672
- }
1673
- }
1674
- return result;
1675
- }
1676
- getHasAnswersInSeries(dataset) {
1677
- for (let i = 0; i < dataset.length; i++) {
1678
- if (dataset[i] != 0) {
1679
- return true;
1680
- }
1681
- }
1682
- return false;
1683
- }
1684
- hideEmptyAnswersInData(answersData) {
1685
- const result = {
1686
- datasets: [],
1687
- labels: [],
1688
- colors: [],
1689
- texts: [],
1690
- seriesLabels: [],
1691
- };
1692
- const hasAnswersInAllSeriesArr = this.getHasAnswersInAllSeriesArray(answersData.datasets);
1693
- for (let i = 0; i < answersData.datasets.length; i++) {
1694
- const hasAnswersInSeries = this.getHasAnswersInSeries(answersData.datasets[i]);
1695
- if (hasAnswersInSeries) {
1696
- result.labels.push(answersData.labels[i]);
1697
- result.colors.push(answersData.colors[i]);
1698
- }
1699
- else {
1700
- continue;
1701
- }
1702
- const datasets = [];
1703
- const texts = [];
1704
- for (let j = 0; j < answersData.datasets[0].length; j++) {
1705
- if (hasAnswersInAllSeriesArr[j]) {
1706
- datasets.push(answersData.datasets[i][j]);
1707
- texts.push(answersData.texts[i][j]);
1708
- }
1709
- }
1710
- result.datasets.push(datasets);
1711
- result.texts.push(texts);
1712
- }
1713
- for (let i = 0; i < answersData.datasets[0].length; i++) {
1714
- if (hasAnswersInAllSeriesArr[i]) {
1715
- result.seriesLabels.push(answersData.seriesLabels[i]);
1716
- }
1717
- }
1718
- return result;
1719
- }
1720
- }
1832
+ VisualizationManager.registerVisualizer("checkbox", SelectBase);
1833
+ VisualizationManager.registerVisualizer("radiogroup", SelectBase);
1834
+ VisualizationManager.registerVisualizer("dropdown", SelectBase);
1835
+ VisualizationManager.registerVisualizer("imagepicker", SelectBase);
1836
+ VisualizationManager.registerVisualizer("tagbox", SelectBase);
1721
1837
 
1722
1838
  class BooleanModel extends SelectBase {
1723
1839
  constructor(question, data, options, name) {
@@ -1771,6 +1887,7 @@ class BooleanModel extends SelectBase {
1771
1887
  }
1772
1888
  BooleanModel.trueColor = "";
1773
1889
  BooleanModel.falseColor = "";
1890
+ VisualizationManager.registerVisualizer("boolean", BooleanModel);
1774
1891
 
1775
1892
  class HistogramModel extends SelectBase {
1776
1893
  constructor(question, data, options, name) {
@@ -1925,145 +2042,99 @@ class HistogramModel extends SelectBase {
1925
2042
  }
1926
2043
  getCalculatedValuesCore() {
1927
2044
  this.getContiniousValues();
1928
- const intervals = this.intervals;
1929
- const statistics = [];
1930
- const series = this.getSeriesValues();
1931
- if (series.length === 0) {
1932
- series.push("");
1933
- }
1934
- for (var i = 0; i < series.length; ++i) {
1935
- statistics.push(intervals.map(i => 0));
1936
- this._continiousData[series[i]].forEach(dataValue => {
1937
- for (let j = 0; j < intervals.length; ++j) {
1938
- if (intervals[j].start <= dataValue && (dataValue < intervals[j].end || j == intervals.length - 1)) {
1939
- statistics[i][j]++;
1940
- break;
1941
- }
1942
- }
1943
- });
1944
- }
1945
- return statistics;
2045
+ return histogramStatisticsCalculator(this._continiousData, this.intervals, this.getSeriesValues());
2046
+ }
2047
+ getValueType() {
2048
+ return this.valueType;
1946
2049
  }
1947
2050
  }
1948
2051
  HistogramModel.IntervalsCount = 10;
1949
2052
  HistogramModel.UseIntervalsFrom = 10;
2053
+ VisualizationManager.registerVisualizer("date", HistogramModel);
2054
+ VisualizationManager.registerVisualizer("number", HistogramModel, 100);
2055
+ VisualizationManager.registerVisualizer("rating", HistogramModel, 100);
1950
2056
 
1951
- class NumberModel extends VisualizerBase {
1952
- constructor(question, data, options = {}, name) {
1953
- super(question, data, options, name || "number");
1954
- this.registerToolbarItem("changeChartType", () => {
1955
- if (this.chartTypes.length > 1) {
1956
- return DocumentHelper.createSelector(this.chartTypes.map((chartType) => {
1957
- return {
1958
- value: chartType,
1959
- text: localization.getString("chartType_" + chartType),
1960
- };
1961
- }), (option) => this.chartType === option.value, (e) => {
1962
- this.setChartType(e.target.value);
1963
- });
1964
- }
1965
- return null;
1966
- });
2057
+ class Matrix extends SelectBase {
2058
+ constructor(question, data, options, name) {
2059
+ super(question, data, options, name || "matrix");
2060
+ this._transposeData = true;
2061
+ // this.getAnswersData();
1967
2062
  }
1968
- onDataChanged() {
1969
- this._resultAverage = undefined;
1970
- this._resultMin = undefined;
1971
- this._resultMax = undefined;
1972
- super.onDataChanged();
2063
+ get matrixQuestion() {
2064
+ return this.question;
1973
2065
  }
1974
- onChartTypeChanged() { }
1975
- setChartType(chartType) {
1976
- if (this.chartTypes.indexOf(chartType) !== -1 &&
1977
- this.chartType !== chartType) {
1978
- this.chartType = chartType;
1979
- this.onChartTypeChanged();
1980
- if (!!this.contentContainer) {
1981
- this.destroyContent(this.contentContainer);
1982
- this.renderContent(this.contentContainer);
1983
- }
1984
- this.invokeOnUpdate();
1985
- }
2066
+ isSupportMissingAnswers() {
2067
+ return false;
1986
2068
  }
1987
- destroy() {
1988
- this._resultAverage = undefined;
1989
- this._resultMin = undefined;
1990
- this._resultMax = undefined;
1991
- super.destroy();
2069
+ getSeriesValues() {
2070
+ return this.matrixQuestion.rows.map((row) => "" + row.value);
1992
2071
  }
1993
- generateText(maxValue, minValue, stepsCount) {
1994
- let texts = [];
1995
- if (stepsCount === 5) {
1996
- texts = [
1997
- "very high (" + maxValue + ")",
1998
- "high",
1999
- "medium",
2000
- "low",
2001
- "very low (" + minValue + ")",
2002
- ];
2003
- }
2004
- else {
2005
- texts.push(maxValue);
2006
- for (let i = 0; i < stepsCount - 2; i++) {
2007
- texts.push("");
2008
- }
2009
- texts.push(minValue);
2010
- }
2011
- if (!!NumberModel.generateTextsCallback) {
2012
- return NumberModel.generateTextsCallback(this.question, maxValue, minValue, stepsCount, texts);
2013
- }
2014
- return texts;
2072
+ getSeriesLabels() {
2073
+ return this.matrixQuestion.rows.map((row) => ItemValue.getTextOrHtmlByValue(this.matrixQuestion.rows, row.value));
2015
2074
  }
2016
- generateValues(maxValue, stepsCount) {
2017
- const values = [];
2018
- for (let i = 0; i < stepsCount; i++) {
2019
- values.push(maxValue / stepsCount);
2020
- }
2021
- values.push(maxValue);
2022
- return values;
2075
+ getSelectedItemByText(itemText) {
2076
+ return this.matrixQuestion.columns.filter((column) => column.text === itemText)[0];
2023
2077
  }
2024
- generateColors(maxValue, minValue, stepsCount) {
2025
- const palette = this.getColors();
2026
- const colors = [];
2027
- for (let i = 0; i < stepsCount; i++) {
2028
- colors.push(palette[i]);
2078
+ valuesSource() {
2079
+ return this.matrixQuestion.columns;
2080
+ }
2081
+ getHasAnswersInAllSeriesArray(datasets) {
2082
+ let result = Array();
2083
+ for (let i = 0; i < datasets[0].length; i++) {
2084
+ for (let j = 0; j < datasets.length; j++) {
2085
+ if (datasets[j][i] != 0) {
2086
+ result[i] = true;
2087
+ }
2088
+ }
2029
2089
  }
2030
- colors.push("rgba(255, 255, 255, 0)");
2031
- return colors;
2090
+ return result;
2032
2091
  }
2033
- convertFromExternalData(externalCalculatedData) {
2034
- return [externalCalculatedData.value || 0, externalCalculatedData.minValue || 0, externalCalculatedData.maxValue || 0];
2092
+ getHasAnswersInSeries(dataset) {
2093
+ for (let i = 0; i < dataset.length; i++) {
2094
+ if (dataset[i] != 0) {
2095
+ return true;
2096
+ }
2097
+ }
2098
+ return false;
2035
2099
  }
2036
- getCalculatedValuesCore() {
2037
- if (this._resultAverage === undefined ||
2038
- this._resultMin === undefined ||
2039
- this._resultMax === undefined) {
2040
- this._resultMin = Number.MAX_VALUE;
2041
- this._resultMax = -Number.MAX_VALUE;
2042
- this._resultAverage = 0;
2043
- let actualAnswerCount = 0;
2044
- this.data.forEach((rowData) => {
2045
- if (rowData[this.question.name] !== undefined) {
2046
- const questionValue = +rowData[this.question.name];
2047
- actualAnswerCount++;
2048
- this._resultAverage += questionValue;
2049
- if (this._resultMin > questionValue) {
2050
- this._resultMin = questionValue;
2051
- }
2052
- if (this._resultMax < questionValue) {
2053
- this._resultMax = questionValue;
2054
- }
2100
+ hideEmptyAnswersInData(answersData) {
2101
+ const result = {
2102
+ datasets: [],
2103
+ labels: [],
2104
+ colors: [],
2105
+ texts: [],
2106
+ seriesLabels: [],
2107
+ };
2108
+ const hasAnswersInAllSeriesArr = this.getHasAnswersInAllSeriesArray(answersData.datasets);
2109
+ for (let i = 0; i < answersData.datasets.length; i++) {
2110
+ const hasAnswersInSeries = this.getHasAnswersInSeries(answersData.datasets[i]);
2111
+ if (hasAnswersInSeries) {
2112
+ result.labels.push(answersData.labels[i]);
2113
+ result.colors.push(answersData.colors[i]);
2114
+ }
2115
+ else {
2116
+ continue;
2117
+ }
2118
+ const datasets = [];
2119
+ const texts = [];
2120
+ for (let j = 0; j < answersData.datasets[0].length; j++) {
2121
+ if (hasAnswersInAllSeriesArr[j]) {
2122
+ datasets.push(answersData.datasets[i][j]);
2123
+ texts.push(answersData.texts[i][j]);
2055
2124
  }
2056
- });
2057
- if (actualAnswerCount > 0) {
2058
- this._resultAverage = this._resultAverage / actualAnswerCount;
2059
2125
  }
2060
- this._resultAverage = Math.ceil(this._resultAverage * 100) / 100;
2126
+ result.datasets.push(datasets);
2127
+ result.texts.push(texts);
2128
+ }
2129
+ for (let i = 0; i < answersData.datasets[0].length; i++) {
2130
+ if (hasAnswersInAllSeriesArr[i]) {
2131
+ result.seriesLabels.push(answersData.seriesLabels[i]);
2132
+ }
2061
2133
  }
2062
- return [this._resultAverage, this._resultMin, this._resultMax];
2134
+ return result;
2063
2135
  }
2064
2136
  }
2065
- NumberModel.stepsCount = 5;
2066
- NumberModel.showAsPercentage = false;
2137
+ VisualizationManager.registerVisualizer("matrix", Matrix);
2067
2138
 
2068
2139
  class PivotModel extends SelectBase {
2069
2140
  constructor(questions, data, options, name) {
@@ -2236,7 +2307,7 @@ class PivotModel extends SelectBase {
2236
2307
  return this.question.getType() == "rating" && Array.isArray(this.question["rateValues"]) && this.question["rateValues"].length > 0;
2237
2308
  }
2238
2309
  getSeriesValues() {
2239
- if (this.questionsY.length === 0) {
2310
+ if (!this.questionsY || this.questionsY.length === 0) {
2240
2311
  return this.options.seriesValues || [];
2241
2312
  }
2242
2313
  const seriesValues = [];
@@ -2414,9 +2485,49 @@ class PivotModel extends SelectBase {
2414
2485
  }
2415
2486
  return statistics;
2416
2487
  }
2488
+ getValueType() {
2489
+ return this.valueType;
2490
+ }
2491
+ isSupportSoftUpdateContent() {
2492
+ return false;
2493
+ }
2417
2494
  }
2418
2495
  PivotModel.IntervalsCount = 10;
2419
2496
  PivotModel.UseIntervalsFrom = 10;
2497
+ VisualizationManager.registerPivotVisualizer(PivotModel);
2498
+
2499
+ class RankingModel extends SelectBase {
2500
+ getQuestionResults() {
2501
+ const name = this.question.name;
2502
+ return this.data.map((dataItem) => dataItem[name]);
2503
+ }
2504
+ getEmptyData() {
2505
+ const choices = this.getValues();
2506
+ let data = [];
2507
+ data.length = choices.length;
2508
+ data.fill(0);
2509
+ return data;
2510
+ }
2511
+ getCalculatedValuesCore() {
2512
+ const results = this.getQuestionResults();
2513
+ const choices = this.getValues();
2514
+ let plotlyData = this.getEmptyData();
2515
+ results.forEach((result) => {
2516
+ this.applyResultToPlotlyData(result, plotlyData, choices);
2517
+ });
2518
+ return [plotlyData];
2519
+ }
2520
+ applyResultToPlotlyData(result, plotlyData, choices) {
2521
+ if (!result || !plotlyData || !choices)
2522
+ return;
2523
+ result.forEach((resultValue, resultValueIndex, result) => {
2524
+ let index = choices.indexOf(resultValue);
2525
+ plotlyData[index] =
2526
+ +plotlyData[index] + (result.length - resultValueIndex);
2527
+ });
2528
+ }
2529
+ }
2530
+ VisualizationManager.registerVisualizer("ranking", RankingModel);
2420
2531
 
2421
2532
  class AlternativeVisualizersWrapper extends VisualizerBase {
2422
2533
  updateVisualizerSelector() {
@@ -12322,5 +12433,5 @@ NpsVisualizer.DetractorScore = 6;
12322
12433
  NpsVisualizer.PromoterScore = 9;
12323
12434
  // VisualizationManager.registerVisualizer("rating", NpsVisualizer);
12324
12435
 
12325
- export { AlternativeVisualizersWrapper as A, BooleanModel as B, DataProvider as D, HistogramModel as H, Matrix as M, NumberModel as N, PostponeHelper as P, SelectBase as S, TextTableAdapter as T, VisualizerFactory as V, WordCloudAdapter as W, __awaiter as _, VisualizerBase as a, VisualizationManager as b, VisualizationPanel as c, defaultStatisticsCalculator as d, VisualizationPanelDynamic as e, VisualizationMatrixDynamic as f, VisualizationMatrixDropdown as g, hideEmptyAnswersInData as h, WordCloud as i, Text as j, StatisticsTableAdapter as k, StatisticsTable as l, NpsVisualizerWidget as m, NpsAdapter as n, NpsVisualizer as o, PivotModel as p, textHelper as t };
12436
+ export { AlternativeVisualizersWrapper as A, BooleanModel as B, DataProvider as D, HistogramModel as H, Matrix as M, NumberModel as N, PostponeHelper as P, RankingModel as R, SelectBase as S, TextTableAdapter as T, VisualizerFactory as V, WordCloudAdapter as W, __awaiter as _, VisualizerBase as a, VisualizationManager as b, VisualizationPanel as c, VisualizationPanelDynamic as d, VisualizationMatrixDynamic as e, VisualizationMatrixDropdown as f, WordCloud as g, hideEmptyAnswersInData as h, Text as i, StatisticsTableAdapter as j, StatisticsTable as k, NpsVisualizerWidget as l, NpsAdapter as m, NpsVisualizer as n, PivotModel as o, defaultStatisticsCalculator as p, textHelper as t };
12326
12437
  //# sourceMappingURL=shared2.mjs.map