mdt-charts 1.10.2 → 1.12.0

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 (65) hide show
  1. package/lib/config/config.d.ts +13 -5
  2. package/lib/designer/designerConfig.d.ts +8 -2
  3. package/lib/engine/features/aggregator/aggregator.d.ts +4 -3
  4. package/lib/engine/features/aggregator/aggregator.js +14 -11
  5. package/lib/engine/features/recordOverflowAlert/recordOverflowAlertCore.d.ts +28 -0
  6. package/lib/engine/features/recordOverflowAlert/recordOverflowAlertCore.js +50 -0
  7. package/lib/engine/features/title/title.js +2 -0
  8. package/lib/engine/features/tolltip/tooltip.js +1 -1
  9. package/lib/engine/filterManager/filterEventManager.d.ts +3 -3
  10. package/lib/engine/filterManager/filterEventManager.js +4 -4
  11. package/lib/engine/intervalNotation/intervalManager.js +2 -5
  12. package/lib/engine/polarNotation/donut/DonutHelper.d.ts +2 -0
  13. package/lib/engine/polarNotation/donut/DonutHelper.js +20 -3
  14. package/lib/engine/polarNotation/donut/donut.js +1 -1
  15. package/lib/engine/polarNotation/extenders/polarRecordOverflowAlert.d.ts +16 -0
  16. package/lib/engine/polarNotation/extenders/polarRecordOverflowAlert.js +48 -0
  17. package/lib/engine/polarNotation/polarManager.js +16 -12
  18. package/lib/engine/twoDimensionalNotation/extenders/twoDimRecordOverflowAlert.d.ts +15 -0
  19. package/lib/engine/twoDimensionalNotation/extenders/twoDimRecordOverflowAlert.js +32 -0
  20. package/lib/engine/twoDimensionalNotation/twoDimensionalManager.js +13 -7
  21. package/lib/model/chartStyleModel/TwoDimensionalChartStyleModel.d.ts +19 -0
  22. package/lib/model/chartStyleModel/TwoDimensionalChartStyleModel.js +61 -0
  23. package/lib/model/chartStyleModel/chartStyleModel.d.ts +9 -0
  24. package/lib/model/chartStyleModel/chartStyleModel.js +27 -0
  25. package/lib/model/dataManagerModel/dataManagerModel.d.ts +26 -0
  26. package/lib/model/dataManagerModel/dataManagerModel.js +132 -0
  27. package/lib/model/dataManagerModel/dataManagerModelService.d.ts +5 -0
  28. package/lib/model/dataManagerModel/dataManagerModelService.js +28 -0
  29. package/lib/model/dataManagerModel.d.ts +3 -2
  30. package/lib/model/dataManagerModel.js +12 -10
  31. package/lib/model/featuresModel/axisModel.d.ts +9 -8
  32. package/lib/model/featuresModel/axisModel.js +21 -21
  33. package/lib/model/featuresModel/legendModel/legendModel.d.ts +4 -5
  34. package/lib/model/featuresModel/legendModel/legendModel.js +6 -9
  35. package/lib/model/featuresModel/otherComponents.d.ts +9 -2
  36. package/lib/model/featuresModel/otherComponents.js +6 -4
  37. package/lib/model/featuresModel/scaleModel.d.ts +7 -6
  38. package/lib/model/featuresModel/scaleModel.js +9 -9
  39. package/lib/model/featuresModel/titleModel.d.ts +1 -1
  40. package/lib/model/featuresModel/titleModel.js +7 -5
  41. package/lib/model/marginModel.d.ts +5 -5
  42. package/lib/model/marginModel.js +41 -38
  43. package/lib/model/model.d.ts +24 -18
  44. package/lib/model/modelBuilder.js +26 -37
  45. package/lib/model/modelInstance/canvasModel/canvasModel.d.ts +24 -0
  46. package/lib/model/modelInstance/canvasModel/canvasModel.js +44 -0
  47. package/lib/model/modelInstance/canvasModel/legendCanvasModel.d.ts +7 -0
  48. package/lib/model/modelInstance/canvasModel/legendCanvasModel.js +13 -0
  49. package/lib/model/modelInstance/canvasModel/titleCanvas.d.ts +9 -0
  50. package/lib/model/modelInstance/canvasModel/titleCanvas.js +11 -0
  51. package/lib/model/modelInstance/dataModel.d.ts +11 -0
  52. package/lib/model/modelInstance/dataModel.js +23 -0
  53. package/lib/model/modelInstance/modelInstance.d.ts +10 -0
  54. package/lib/model/modelInstance/modelInstance.js +17 -0
  55. package/lib/model/notations/intervalModel.d.ts +2 -1
  56. package/lib/model/notations/intervalModel.js +17 -15
  57. package/lib/model/notations/polarModel.d.ts +9 -3
  58. package/lib/model/notations/polarModel.js +29 -8
  59. package/lib/model/notations/twoDimensionalModel.d.ts +7 -5
  60. package/lib/model/notations/twoDimensionalModel.js +19 -12
  61. package/lib/style/charts-main.css +2 -0
  62. package/lib/style/charts-main.less +2 -0
  63. package/package.json +3 -2
  64. package/lib/model/chartStyleModel.d.ts +0 -16
  65. package/lib/model/chartStyleModel.js +0 -67
@@ -3,7 +3,6 @@ import { Axis } from "../features/axis/axis";
3
3
  import { EmbeddedLabels } from "../features/embeddedLabels/embeddedLabels";
4
4
  import { GridLine } from "../features/gridLine/gridLine";
5
5
  import { Legend } from "../features/legend/legend";
6
- import { RecordOverflowAlert } from "../features/recordOverflowAlert/recordOverflowAlert";
7
6
  import { Scale } from "../features/scale/scale";
8
7
  import { TipBox } from "../features/tipBox/tipBox";
9
8
  import { Title } from "../features/title/title";
@@ -12,23 +11,27 @@ import { Helper } from "../helpers/helper";
12
11
  import { Area } from "./area/area";
13
12
  import { Bar } from "./bar/bar";
14
13
  import { BarHelper } from "./bar/barHelper";
14
+ import { TwoDimRecordOverflowAlert } from "./extenders/twoDimRecordOverflowAlert";
15
15
  import { Line } from "./line/line";
16
16
  export class TwoDimensionalManager {
17
17
  static render(engine, model) {
18
18
  const options = model.options;
19
- const scales = Scale.getScales(options.scale.key, options.scale.value, model.chartSettings.bar);
19
+ const scales = Scale.getScales(options.scale.key, options.scale.value, options.chartSettings.bar);
20
20
  engine.block.scales = scales;
21
21
  engine.block.renderSvg(model.blockCanvas.size);
22
22
  Axis.render(engine.block, scales, options.scale, options.axis, model.blockCanvas.size);
23
23
  GridLine.render(engine.block, options.additionalElements.gridLine.flag, options.axis, model.blockCanvas.size, model.chartBlock.margin, options.scale.key);
24
- this.renderCharts(engine.block, options.charts, scales, engine.data, options.data, model.chartBlock.margin, options.axis.key.orient, model.chartSettings.bar, model.blockCanvas.size);
24
+ this.renderCharts(engine.block, options.charts, scales, engine.data, options.data, model.chartBlock.margin, options.axis.key.orient, options.chartSettings.bar, model.blockCanvas.size);
25
25
  engine.block.filterEventManager.registerEventFor2D(scales.key, model.chartBlock.margin, model.blockCanvas.size, options);
26
26
  engine.block.filterEventManager.event2DUpdate(options);
27
27
  Title.render(engine.block, options.title, model.otherComponents.titleBlock, model.blockCanvas.size);
28
28
  Legend.render(engine.block, engine.data, options, model);
29
29
  Tooltip.render(engine.block, model, engine.data, model.otherComponents.tooltipBlock, scales);
30
30
  if (model.dataSettings.scope.hidedRecordsAmount !== 0)
31
- RecordOverflowAlert.render(engine.block, model.dataSettings.scope.hidedRecordsAmount, 'top', options.orient);
31
+ TwoDimRecordOverflowAlert.render(engine.block, {
32
+ hidedRecordsAmount: model.dataSettings.scope.hidedRecordsAmount,
33
+ chartOrientation: options.orient
34
+ });
32
35
  engine.block.getSvg()
33
36
  .on('click', (e) => {
34
37
  if (e.target === engine.block.getSvg().node())
@@ -42,19 +45,22 @@ export class TwoDimensionalManager {
42
45
  Tooltip.hide(block);
43
46
  const options = model.options;
44
47
  ElementHighlighter.remove2DChartsFullHighlighting(block, options.charts);
45
- const scales = Scale.getScales(options.scale.key, options.scale.value, model.chartSettings.bar);
48
+ const scales = Scale.getScales(options.scale.key, options.scale.value, options.chartSettings.bar);
46
49
  const keyDomainEquality = Helper.checkDomainsEquality(block.scales.key.domain(), scales.key.domain());
47
50
  block.scales = scales;
48
51
  Axis.update(block, scales, options.scale, options.axis, model.blockCanvas.size, keyDomainEquality);
49
52
  GridLine.update(block, options.additionalElements.gridLine.flag, options.axis, model.blockCanvas.size, model.chartBlock.margin, options.scale.key);
50
- const promises = this.updateCharts(block, options.charts, scales, data, model.options.data, model.chartBlock.margin, options.axis.key.orient, model.blockCanvas.size, model.chartSettings.bar);
53
+ const promises = this.updateCharts(block, options.charts, scales, data, model.options.data, model.chartBlock.margin, options.axis.key.orient, model.blockCanvas.size, options.chartSettings.bar);
51
54
  Promise.all(promises)
52
55
  .then(() => {
53
56
  block.filterEventManager.event2DUpdate(options);
54
57
  block.filterEventManager.registerEventFor2D(scales.key, model.chartBlock.margin, model.blockCanvas.size, options);
55
58
  Tooltip.render(block, model, data, model.otherComponents.tooltipBlock, scales);
56
59
  });
57
- RecordOverflowAlert.update(block, model.dataSettings.scope.hidedRecordsAmount, 'top', options.orient);
60
+ TwoDimRecordOverflowAlert.update(block, {
61
+ hidedRecordsAmount: model.dataSettings.scope.hidedRecordsAmount,
62
+ chartOrientation: options.orient
63
+ });
58
64
  }
59
65
  static updateColors(block, model) {
60
66
  Legend.updateColors(block, model.options);
@@ -0,0 +1,19 @@
1
+ import { TwoDimensionalChart, TwoDimensionalChartType } from "../../config/config";
2
+ import { ChartStyleConfig } from "../../designer/designerConfig";
3
+ import { ChartStyle } from "../model";
4
+ export declare class TwoDimensionalChartStyleModel {
5
+ private charts;
6
+ private chartStyleConfig;
7
+ private service;
8
+ constructor(charts: TwoDimensionalChart[], chartStyleConfig: ChartStyleConfig);
9
+ getChartStyle(chart: TwoDimensionalChart, chartIndex: number): ChartStyle;
10
+ private getChartsValueFieldsAmounts;
11
+ }
12
+ export declare class TwoDimensionalChartStyleService {
13
+ getChartColors(chart: TwoDimensionalChart, styleConfig: ChartStyleConfig, chartsFieldsAmounts: number[], chartIndex: number): string[];
14
+ getChartOpacity(chartsLength: number, chartType: TwoDimensionalChartType, chartsValueFieldAmount: number, isChartSegmented: boolean): number;
15
+ private generateNewChartColors;
16
+ private isMoreThanOneValueFieldOnCanvas;
17
+ private makeColorsBrighter;
18
+ private getStartIndex;
19
+ }
@@ -0,0 +1,61 @@
1
+ import * as chroma from "chroma-js";
2
+ import { ModelHelper } from "../modelHelper";
3
+ import { ChartStyleModelService } from "./chartStyleModel";
4
+ export class TwoDimensionalChartStyleModel {
5
+ constructor(charts, chartStyleConfig) {
6
+ this.charts = charts;
7
+ this.chartStyleConfig = chartStyleConfig;
8
+ this.service = new TwoDimensionalChartStyleService();
9
+ }
10
+ getChartStyle(chart, chartIndex) {
11
+ const fieldsAmounts = this.getChartsValueFieldsAmounts();
12
+ return {
13
+ elementColors: this.service.getChartColors(chart, this.chartStyleConfig, fieldsAmounts, chartIndex),
14
+ opacity: this.service.getChartOpacity(this.charts.length, chart.type, fieldsAmounts[chartIndex], chart.isSegmented)
15
+ };
16
+ }
17
+ getChartsValueFieldsAmounts() {
18
+ return this.charts.map(chart => chart.data.valueFields.length);
19
+ }
20
+ }
21
+ export class TwoDimensionalChartStyleService {
22
+ getChartColors(chart, styleConfig, chartsFieldsAmounts, chartIndex) {
23
+ const generatedColors = this.generateNewChartColors(chart.type, styleConfig, chartsFieldsAmounts, chartIndex);
24
+ chart.data.valueFields.forEach((field, fieldIndex) => {
25
+ if (field.color)
26
+ generatedColors[fieldIndex] = field.color;
27
+ });
28
+ return generatedColors;
29
+ }
30
+ getChartOpacity(chartsLength, chartType, chartsValueFieldAmount, isChartSegmented) {
31
+ if (chartType === 'area' && this.isMoreThanOneValueFieldOnCanvas(chartsLength, chartsValueFieldAmount) && !isChartSegmented)
32
+ return 0.5; // combined area with other charts has 0.5 opacity
33
+ return 1;
34
+ }
35
+ generateNewChartColors(chartType, styleConfig, chartsFieldsAmounts, chartIndex) {
36
+ const startIndex = this.getStartIndex(chartIndex, chartsFieldsAmounts);
37
+ const baseColors = ChartStyleModelService.checkAndGet(styleConfig.baseColors);
38
+ const palette = ChartStyleModelService.getColorSet(baseColors, ModelHelper.getSum(chartsFieldsAmounts));
39
+ const elementsAmount = chartsFieldsAmounts[chartIndex];
40
+ const selectedColors = palette.slice(startIndex, startIndex + elementsAmount);
41
+ if (chartType !== 'line')
42
+ return selectedColors;
43
+ this.makeColorsBrighter(selectedColors);
44
+ return selectedColors;
45
+ }
46
+ isMoreThanOneValueFieldOnCanvas(chartsLength, chartsValueFieldAmount) {
47
+ return (chartsLength > 1 || chartsValueFieldAmount > 1);
48
+ }
49
+ makeColorsBrighter(initialColors) {
50
+ for (let i = 0; i < initialColors.length; i++) {
51
+ initialColors[i] = chroma.mix(initialColors[i], 'white', 0.2).saturate(3).hex();
52
+ }
53
+ }
54
+ getStartIndex(chartIndex, chartsFieldsAmounts) {
55
+ let startIndex = 0;
56
+ for (let i = 0; i < chartIndex; i++) {
57
+ startIndex += chartsFieldsAmounts[i];
58
+ }
59
+ return startIndex;
60
+ }
61
+ }
@@ -0,0 +1,9 @@
1
+ import { ChartStyleConfig } from "../../designer/designerConfig";
2
+ import { ChartStyle } from "../model";
3
+ export declare class ChartStyleModelService {
4
+ private static standartColors;
5
+ static getCssClasses(chartIndex: number): string[];
6
+ static getChartStyle(elementsAmount: number, styleConfig: ChartStyleConfig): ChartStyle;
7
+ static getColorSet(baseColors: string[], elementsAmount: number): string[];
8
+ static checkAndGet(baseColors: string[]): string[];
9
+ }
@@ -0,0 +1,27 @@
1
+ import * as chroma from "chroma-js";
2
+ export class ChartStyleModelService {
3
+ static getCssClasses(chartIndex) {
4
+ const cssClasses = [`chart-${chartIndex}`];
5
+ return cssClasses;
6
+ }
7
+ static getChartStyle(elementsAmount, styleConfig) {
8
+ const baseColors = this.checkAndGet(styleConfig.baseColors);
9
+ return {
10
+ elementColors: this.getColorSet(baseColors, elementsAmount),
11
+ opacity: 1
12
+ };
13
+ }
14
+ static getColorSet(baseColors, elementsAmount) {
15
+ return chroma.scale(baseColors)
16
+ .mode('rgb')
17
+ .domain([0, 0.55, 0.75, 1])
18
+ .colors(elementsAmount <= 1 ? 2 : elementsAmount);
19
+ }
20
+ static checkAndGet(baseColors) {
21
+ if (baseColors.length === 0 || baseColors.filter(color => color === 'rgba(0, 0, 0, 0)' || !color).length > 0) {
22
+ return this.standartColors;
23
+ }
24
+ return baseColors;
25
+ }
26
+ }
27
+ ChartStyleModelService.standartColors = ["#209DE3", "#FF3131", "#FFBA00", "#20B078"];
@@ -0,0 +1,26 @@
1
+ import { MdtChartsConfig, MdtChartsDataSource } from "../../config/config";
2
+ import { DesignerConfig } from "../../designer/designerConfig";
3
+ import { LegendBlockModel } from "../model";
4
+ import { ModelInstance } from "../modelInstance/modelInstance";
5
+ export declare class DataManagerModel {
6
+ private static service;
7
+ static getPreparedData(data: MdtChartsDataSource, allowableKeys: string[], config: MdtChartsConfig): MdtChartsDataSource;
8
+ static initDataScope(config: MdtChartsConfig, data: MdtChartsDataSource, designerConfig: DesignerConfig, legendBlock: LegendBlockModel, modelInstance: ModelInstance): void;
9
+ static getDataValuesByKeyField(data: MdtChartsDataSource, dataSourceName: string, keyFieldName: string): string[];
10
+ private static initDataScopeFor2D;
11
+ private static initDataScopeForPolar;
12
+ private static getMaximumPossibleScope;
13
+ private static limitAllowableKeys;
14
+ /**
15
+ * Выводит количество элементов (преимущественно баров) в одной группе. Группа - один ключ
16
+ * @param configOptions
17
+ * @param chartsLength
18
+ */
19
+ private static getElementsInGroupAmount;
20
+ private static getBarChartsInGroupAmount;
21
+ private static getScopedData;
22
+ private static getScopedChartData;
23
+ private static setDataType;
24
+ private static getTypedData;
25
+ private static getDataLimitByItemSize;
26
+ }
@@ -0,0 +1,132 @@
1
+ import { AxisModel } from "../featuresModel/axisModel";
2
+ import { LegendCanvasModel } from "../featuresModel/legendModel/legendCanvasModel";
3
+ import { ModelHelper } from "../modelHelper";
4
+ import { MIN_DONUT_BLOCK_SIZE, PolarModel } from "../notations/polarModel";
5
+ import { DataManagerModelService } from "./dataManagerModelService";
6
+ export class DataManagerModel {
7
+ static getPreparedData(data, allowableKeys, config) {
8
+ const scopedData = this.getScopedData(data, allowableKeys, config);
9
+ this.setDataType(scopedData, config);
10
+ return scopedData;
11
+ }
12
+ static initDataScope(config, data, designerConfig, legendBlock, modelInstance) {
13
+ if (config.options.type === '2d' || config.options.type === 'interval') {
14
+ this.initDataScopeFor2D(config.options, modelInstance, data, designerConfig);
15
+ }
16
+ else if (config.options.type === 'polar') {
17
+ this.initDataScopeForPolar(config.options, modelInstance, data, legendBlock, designerConfig.canvas.legendBlock);
18
+ }
19
+ }
20
+ static getDataValuesByKeyField(data, dataSourceName, keyFieldName) {
21
+ return data[dataSourceName].map(dataRow => dataRow[keyFieldName]);
22
+ }
23
+ static initDataScopeFor2D(configOptions, modelInstance, data, designerConfig) {
24
+ // Для interval всегда один элемент, так как там может быть только один столбик
25
+ let itemsLength = 1;
26
+ if (configOptions.type === '2d') {
27
+ itemsLength = (configOptions.charts)
28
+ .filter((chart) => chart.type === 'bar').length;
29
+ if (itemsLength === 0)
30
+ itemsLength = 1; // Если баров нет, то для одной записи выделяется столько же места, сколько для одного столбика
31
+ }
32
+ if (itemsLength !== 0) {
33
+ const axisLength = AxisModel.getAxisLength(configOptions.orientation, modelInstance.canvasModel);
34
+ const uniqueKeys = ModelHelper.getUniqueValues(data[configOptions.data.dataSource].map(d => d[configOptions.data.keyField.name]));
35
+ const dataLength = uniqueKeys.length;
36
+ const limit = this.getDataLimitByItemSize(this.getElementsInGroupAmount(configOptions, itemsLength), dataLength, axisLength, designerConfig.canvas.chartOptions.bar);
37
+ const allowableKeys = uniqueKeys.slice(0, limit);
38
+ const hidedRecordsAmount = dataLength - allowableKeys.length;
39
+ modelInstance.dataModel.initScope(this.limitAllowableKeys(allowableKeys, hidedRecordsAmount, modelInstance.dataModel));
40
+ }
41
+ else {
42
+ const allKeys = this.getDataValuesByKeyField(data, configOptions.data.dataSource, configOptions.data.keyField.name);
43
+ modelInstance.dataModel.initScope(this.getMaximumPossibleScope(allKeys, modelInstance.dataModel));
44
+ }
45
+ }
46
+ static initDataScopeForPolar(configOptions, modelInstance, data, legendBlock, legendCanvas) {
47
+ const canvas = modelInstance.canvasModel;
48
+ const dataset = data[configOptions.data.dataSource];
49
+ const keyFieldName = configOptions.data.keyField.name;
50
+ const keys = dataset.map(dataRow => dataRow[keyFieldName]);
51
+ if (!configOptions.legend.show) {
52
+ modelInstance.dataModel.initScope(this.getMaximumPossibleScope(keys, modelInstance.dataModel));
53
+ return;
54
+ }
55
+ const position = PolarModel.getLegendPositionByBlockSize(modelInstance.canvasModel);
56
+ let maxItemsNumber;
57
+ if (position === 'right') {
58
+ maxItemsNumber = LegendCanvasModel.findElementsAmountByLegendSize(keys, position, legendCanvas.maxWidth, canvas.getChartBlockHeight());
59
+ }
60
+ else {
61
+ const margin = canvas.getMargin();
62
+ const marginBottomWithoutLegendBlock = margin.bottom - (legendBlock.coordinate.bottom.size === 0 ? legendBlock.coordinate.bottom.size : legendBlock.coordinate.bottom.size - legendBlock.coordinate.bottom.margin.bottom);
63
+ maxItemsNumber = LegendCanvasModel.findElementsAmountByLegendSize(keys, position, canvas.getChartBlockWidth(), canvas.getBlockSize().height - margin.top - marginBottomWithoutLegendBlock - legendBlock.coordinate.bottom.margin.bottom - MIN_DONUT_BLOCK_SIZE);
64
+ }
65
+ const allowableKeys = keys.slice(0, maxItemsNumber);
66
+ const hidedRecordsAmount = keys.length - maxItemsNumber;
67
+ modelInstance.dataModel.initScope(this.limitAllowableKeys(allowableKeys, hidedRecordsAmount, modelInstance.dataModel));
68
+ }
69
+ static getMaximumPossibleScope(keys, dataModel) {
70
+ return this.service.getMaximumPossibleAmount(keys, dataModel.getMaxRecordsAmount());
71
+ }
72
+ static limitAllowableKeys(allowableKeys, hidedRecordsAmount, dataModel) {
73
+ return this.service.limitAllowableKeys(allowableKeys, hidedRecordsAmount, dataModel.getMaxRecordsAmount());
74
+ }
75
+ /**
76
+ * Выводит количество элементов (преимущественно баров) в одной группе. Группа - один ключ
77
+ * @param configOptions
78
+ * @param chartsLength
79
+ */
80
+ static getElementsInGroupAmount(configOptions, chartsLength) {
81
+ if (configOptions.type === '2d')
82
+ return this.getBarChartsInGroupAmount(configOptions.charts);
83
+ return chartsLength;
84
+ }
85
+ static getBarChartsInGroupAmount(charts) {
86
+ let barsAmount = 0;
87
+ charts.forEach(chart => {
88
+ if (chart.type === 'bar' && chart.isSegmented)
89
+ barsAmount += 1; // в сегментированном баре все valueFields находятся внутри одного бара, поэтому бар всегда один.
90
+ else if (chart.type === 'bar')
91
+ barsAmount += chart.data.valueFields.length;
92
+ });
93
+ return barsAmount;
94
+ }
95
+ static getScopedData(data, allowableKeys, config) {
96
+ const newData = {};
97
+ newData[config.options.data.dataSource] = this.getScopedChartData(data[config.options.data.dataSource], allowableKeys, config.options.data.keyField.name);
98
+ return newData;
99
+ }
100
+ static getScopedChartData(data, allowableKeys, keyFieldName) {
101
+ return data.filter(d => allowableKeys.findIndex(key => key === d[keyFieldName]) !== -1);
102
+ }
103
+ static setDataType(data, config) {
104
+ if (config.options.type === 'interval') {
105
+ const chart = config.options.chart;
106
+ if (chart.data.valueField1.format === 'date') {
107
+ data[config.options.data.dataSource] = this.getTypedData(data[config.options.data.dataSource], chart.data.valueField1);
108
+ }
109
+ if (chart.data.valueField2.format === 'date') {
110
+ data[config.options.data.dataSource] = this.getTypedData(data[config.options.data.dataSource], chart.data.valueField2);
111
+ }
112
+ }
113
+ }
114
+ static getTypedData(data, field) {
115
+ if (field.format === 'date')
116
+ data.forEach(d => {
117
+ d[field.name] = new Date(d[field.name]);
118
+ });
119
+ return data;
120
+ }
121
+ static getDataLimitByItemSize(elementsInGroupAmount, dataLength, axisLength, barOptions) {
122
+ let sumSize = dataLength * (elementsInGroupAmount * barOptions.minBarWidth + (elementsInGroupAmount - 1) * barOptions.barDistance + barOptions.groupMinDistance);
123
+ while (dataLength !== 0 && axisLength < sumSize) {
124
+ dataLength--;
125
+ // find whole space for bars in group + distance between bars + group distance
126
+ sumSize = dataLength * (elementsInGroupAmount * barOptions.minBarWidth + (elementsInGroupAmount - 1)
127
+ * barOptions.barDistance + barOptions.groupMinDistance);
128
+ }
129
+ return dataLength;
130
+ }
131
+ }
132
+ DataManagerModel.service = new DataManagerModelService();
@@ -0,0 +1,5 @@
1
+ import { DataScope } from "../model";
2
+ export declare class DataManagerModelService {
3
+ getMaximumPossibleAmount(keys: string[], maxPossibleAmount: number): DataScope;
4
+ limitAllowableKeys(allowableKeys: string[], hidedRecordsAmount: number, globalRecordsMaxAmount: number): DataScope;
5
+ }
@@ -0,0 +1,28 @@
1
+ export class DataManagerModelService {
2
+ getMaximumPossibleAmount(keys, maxPossibleAmount) {
3
+ if (maxPossibleAmount >= keys.length) {
4
+ return {
5
+ allowableKeys: keys,
6
+ hidedRecordsAmount: 0
7
+ };
8
+ }
9
+ else {
10
+ return {
11
+ allowableKeys: keys.slice(0, maxPossibleAmount),
12
+ hidedRecordsAmount: keys.length - maxPossibleAmount
13
+ };
14
+ }
15
+ }
16
+ limitAllowableKeys(allowableKeys, hidedRecordsAmount, globalRecordsMaxAmount) {
17
+ if (allowableKeys.length <= globalRecordsMaxAmount) {
18
+ return {
19
+ allowableKeys,
20
+ hidedRecordsAmount
21
+ };
22
+ }
23
+ return {
24
+ allowableKeys: allowableKeys.slice(0, globalRecordsMaxAmount),
25
+ hidedRecordsAmount: hidedRecordsAmount + allowableKeys.length - globalRecordsMaxAmount
26
+ };
27
+ }
28
+ }
@@ -1,9 +1,10 @@
1
1
  import { MdtChartsConfig, MdtChartsDataSource } from "../config/config";
2
2
  import { DesignerConfig } from "../designer/designerConfig";
3
- import { BlockMargin, DataScope, LegendBlockModel } from "./model";
3
+ import { DataScope, LegendBlockModel } from "./model";
4
+ import { ModelInstance } from "./modelInstance/modelInstance";
4
5
  export declare class DataManagerModel {
5
6
  static getPreparedData(data: MdtChartsDataSource, allowableKeys: string[], config: MdtChartsConfig): MdtChartsDataSource;
6
- static getDataScope(config: MdtChartsConfig, margin: BlockMargin, data: MdtChartsDataSource, designerConfig: DesignerConfig, legendBlock: LegendBlockModel): DataScope;
7
+ static getDataScope(config: MdtChartsConfig, data: MdtChartsDataSource, designerConfig: DesignerConfig, legendBlock: LegendBlockModel, modelInstance: ModelInstance): DataScope;
7
8
  static getDataValuesByKeyField(data: MdtChartsDataSource, dataSourceName: string, keyFieldName: string): string[];
8
9
  private static getDataScopeFor2D;
9
10
  private static getDataScopeForPolar;
@@ -8,18 +8,18 @@ export class DataManagerModel {
8
8
  this.setDataType(scopedData, config);
9
9
  return scopedData;
10
10
  }
11
- static getDataScope(config, margin, data, designerConfig, legendBlock) {
11
+ static getDataScope(config, data, designerConfig, legendBlock, modelInstance) {
12
12
  if (config.options.type === '2d' || config.options.type === 'interval') {
13
- return this.getDataScopeFor2D(config.options, config.canvas.size, margin, data, designerConfig);
13
+ return this.getDataScopeFor2D(config.options, modelInstance, data, designerConfig);
14
14
  }
15
15
  else if (config.options.type === 'polar') {
16
- return this.getDataScopeForPolar(config.options, config.canvas.size, margin, data, legendBlock, designerConfig.canvas.legendBlock);
16
+ return this.getDataScopeForPolar(config.options, modelInstance, data, legendBlock, designerConfig.canvas.legendBlock);
17
17
  }
18
18
  }
19
19
  static getDataValuesByKeyField(data, dataSourceName, keyFieldName) {
20
20
  return data[dataSourceName].map(dataRow => dataRow[keyFieldName]);
21
21
  }
22
- static getDataScopeFor2D(configOptions, blockSize, margin, data, designerConfig) {
22
+ static getDataScopeFor2D(configOptions, modelInstance, data, designerConfig) {
23
23
  // Для interval всегда один элемент, так как там может быть только один столбик
24
24
  let itemsLength = 1;
25
25
  if (configOptions.type === '2d') {
@@ -29,7 +29,7 @@ export class DataManagerModel {
29
29
  itemsLength = 1; // Если баров нет, то для одной записи выделяется столько же места, сколько для одного столбика
30
30
  }
31
31
  if (itemsLength !== 0) {
32
- const axisLength = AxisModel.getAxisLength(configOptions.orientation, margin, blockSize);
32
+ const axisLength = AxisModel.getAxisLength(configOptions.orientation, modelInstance.canvasModel);
33
33
  const uniqueKeys = ModelHelper.getUniqueValues(data[configOptions.data.dataSource].map(d => d[configOptions.data.keyField.name]));
34
34
  const dataLength = uniqueKeys.length;
35
35
  const limit = this.getDataLimitByItemSize(this.getElementsInGroupAmount(configOptions, itemsLength), dataLength, axisLength, designerConfig.canvas.chartOptions.bar);
@@ -44,7 +44,8 @@ export class DataManagerModel {
44
44
  hidedRecordsAmount: 0
45
45
  };
46
46
  }
47
- static getDataScopeForPolar(configOptions, blockSize, margin, data, legendBlock, legendCanvas) {
47
+ static getDataScopeForPolar(configOptions, modelInstance, data, legendBlock, legendCanvas) {
48
+ const canvas = modelInstance.canvasModel;
48
49
  const dataset = data[configOptions.data.dataSource];
49
50
  const keyFieldName = configOptions.data.keyField.name;
50
51
  const keys = dataset.map(dataRow => dataRow[keyFieldName]);
@@ -55,17 +56,18 @@ export class DataManagerModel {
55
56
  };
56
57
  }
57
58
  let position;
58
- if (blockSize.width - margin.left - margin.right >= MIN_DONUT_BLOCK_SIZE)
59
+ if (canvas.getChartBlockWidth() >= MIN_DONUT_BLOCK_SIZE)
59
60
  position = 'right';
60
61
  else
61
62
  position = 'bottom';
62
63
  let maxItemsNumber;
63
64
  if (position === 'right') {
64
- maxItemsNumber = LegendCanvasModel.findElementsAmountByLegendSize(keys, position, legendCanvas.maxWidth, blockSize.height - margin.top - margin.bottom);
65
+ maxItemsNumber = LegendCanvasModel.findElementsAmountByLegendSize(keys, position, legendCanvas.maxWidth, canvas.getChartBlockHeight());
65
66
  }
66
67
  else {
67
- let marginBottom = margin.bottom - (legendBlock.coordinate.bottom.size === 0 ? legendBlock.coordinate.bottom.size : legendBlock.coordinate.bottom.size - legendBlock.coordinate.bottom.margin.bottom);
68
- maxItemsNumber = LegendCanvasModel.findElementsAmountByLegendSize(keys, position, blockSize.width - margin.left - margin.right, blockSize.height - margin.top - marginBottom - legendBlock.coordinate.bottom.margin.bottom - MIN_DONUT_BLOCK_SIZE);
68
+ const margin = canvas.getMargin();
69
+ const marginBottomWithoutLegendBlock = margin.bottom - (legendBlock.coordinate.bottom.size === 0 ? legendBlock.coordinate.bottom.size : legendBlock.coordinate.bottom.size - legendBlock.coordinate.bottom.margin.bottom);
70
+ maxItemsNumber = LegendCanvasModel.findElementsAmountByLegendSize(keys, position, canvas.getChartBlockWidth(), canvas.getBlockSize().height - margin.top - marginBottomWithoutLegendBlock - legendBlock.coordinate.bottom.margin.bottom - MIN_DONUT_BLOCK_SIZE);
69
71
  }
70
72
  return {
71
73
  allowableKeys: keys.slice(0, maxItemsNumber),
@@ -1,18 +1,19 @@
1
- import { AxisPosition, ChartOrientation, DataOptions, MdtChartsDataSource, DiscreteAxisOptions, NumberAxisOptions, Size, TwoDimensionalChart } from "../../config/config";
2
- import { AxisLabelPosition, AxisModelOptions, BlockMargin, Orient } from "../model";
1
+ import { AxisPosition, ChartOrientation, DataOptions, MdtChartsDataSource, DiscreteAxisOptions, NumberAxisOptions, TwoDimensionalChart } from "../../config/config";
2
+ import { AxisLabelPosition, AxisModelOptions, Orient } from "../model";
3
3
  import { AxisType } from "../modelBuilder";
4
4
  import { AxisLabelCanvas, TooltipSettings } from "../../designer/designerConfig";
5
+ import { CanvasModel } from "../modelInstance/canvasModel/canvasModel";
5
6
  export interface LabelSize {
6
7
  width: number;
7
8
  height: number;
8
9
  }
9
10
  export declare class AxisModel {
10
- static getKeyAxis(charts: TwoDimensionalChart[], data: MdtChartsDataSource, dataOptions: DataOptions, orient: ChartOrientation, axisConfig: DiscreteAxisOptions, labelConfig: AxisLabelCanvas, margin: BlockMargin, blockSize: Size, tooltipSettings: TooltipSettings): AxisModelOptions;
11
- static getValueAxis(orient: ChartOrientation, axisConfig: NumberAxisOptions, labelConfig: AxisLabelCanvas, margin: BlockMargin, blockSize: Size): AxisModelOptions;
12
- static getAxisLength(chartOrientation: ChartOrientation, margin: BlockMargin, blockSize: Size): number;
11
+ static getKeyAxis(charts: TwoDimensionalChart[], data: MdtChartsDataSource, dataOptions: DataOptions, orient: ChartOrientation, axisConfig: DiscreteAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel, tooltipSettings: TooltipSettings): AxisModelOptions;
12
+ static getValueAxis(orient: ChartOrientation, axisConfig: NumberAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel): AxisModelOptions;
13
+ static getAxisLength(chartOrientation: ChartOrientation, canvasModel: CanvasModel): number;
13
14
  static getAxisOrient(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition): Orient;
14
- static getAxisTranslateX(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition, margin: BlockMargin, blockWidth: number): number;
15
- static getAxisTranslateY(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition, margin: BlockMargin, blockHeight: number): number;
16
- static getKeyAxisLabelPosition(margin: BlockMargin, blockSize: Size, scopedDataLength: number): AxisLabelPosition;
15
+ static getAxisTranslateX(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition, canvasModel: CanvasModel): number;
16
+ static getAxisTranslateY(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition, canvasModel: CanvasModel): number;
17
+ static getKeyAxisLabelPosition(canvasModel: CanvasModel, scopedDataLength: number): AxisLabelPosition;
17
18
  static getLabelSize(labelMaxWidth: number, labelTexts: any[]): LabelSize;
18
19
  }
@@ -1,34 +1,34 @@
1
1
  import { ModelHelper } from "../modelHelper";
2
2
  import { AxisType, CLASSES } from "../modelBuilder";
3
- import { DataManagerModel } from "../dataManagerModel";
3
+ import { DataManagerModel } from "../dataManagerModel/dataManagerModel";
4
4
  import { TwoDimensionalModel } from "../notations/twoDimensionalModel";
5
5
  export class AxisModel {
6
- static getKeyAxis(charts, data, dataOptions, orient, axisConfig, labelConfig, margin, blockSize, tooltipSettings) {
6
+ static getKeyAxis(charts, data, dataOptions, orient, axisConfig, labelConfig, canvasModel, tooltipSettings) {
7
7
  return {
8
8
  type: 'key',
9
9
  orient: AxisModel.getAxisOrient(AxisType.Key, orient, axisConfig.position),
10
10
  translate: {
11
- translateX: AxisModel.getAxisTranslateX(AxisType.Key, orient, axisConfig.position, margin, blockSize.width),
12
- translateY: AxisModel.getAxisTranslateY(AxisType.Key, orient, axisConfig.position, margin, blockSize.height)
11
+ translateX: AxisModel.getAxisTranslateX(AxisType.Key, orient, axisConfig.position, canvasModel),
12
+ translateY: AxisModel.getAxisTranslateY(AxisType.Key, orient, axisConfig.position, canvasModel)
13
13
  },
14
14
  cssClass: 'key-axis',
15
15
  ticks: axisConfig.ticks,
16
16
  labels: {
17
17
  maxSize: AxisModel.getLabelSize(labelConfig.maxSize.main, data[dataOptions.dataSource].map(d => d[dataOptions.keyField.name])).width,
18
- position: AxisModel.getKeyAxisLabelPosition(margin, blockSize, DataManagerModel.getDataValuesByKeyField(data, dataOptions.dataSource, dataOptions.keyField.name).length),
18
+ position: AxisModel.getKeyAxisLabelPosition(canvasModel, DataManagerModel.getDataValuesByKeyField(data, dataOptions.dataSource, dataOptions.keyField.name).length),
19
19
  visible: !TwoDimensionalModel.getChartsEmbeddedLabelsFlag(charts, orient),
20
20
  defaultTooltip: tooltipSettings.position === 'fixed'
21
21
  },
22
22
  visibility: axisConfig.visibility
23
23
  };
24
24
  }
25
- static getValueAxis(orient, axisConfig, labelConfig, margin, blockSize) {
25
+ static getValueAxis(orient, axisConfig, labelConfig, canvasModel) {
26
26
  return {
27
27
  type: 'value',
28
28
  orient: AxisModel.getAxisOrient(AxisType.Value, orient, axisConfig.position),
29
29
  translate: {
30
- translateX: AxisModel.getAxisTranslateX(AxisType.Value, orient, axisConfig.position, margin, blockSize.width),
31
- translateY: AxisModel.getAxisTranslateY(AxisType.Value, orient, axisConfig.position, margin, blockSize.height)
30
+ translateX: AxisModel.getAxisTranslateX(AxisType.Value, orient, axisConfig.position, canvasModel),
31
+ translateY: AxisModel.getAxisTranslateY(AxisType.Value, orient, axisConfig.position, canvasModel)
32
32
  },
33
33
  cssClass: 'value-axis',
34
34
  ticks: axisConfig.ticks,
@@ -41,12 +41,12 @@ export class AxisModel {
41
41
  visibility: axisConfig.visibility
42
42
  };
43
43
  }
44
- static getAxisLength(chartOrientation, margin, blockSize) {
44
+ static getAxisLength(chartOrientation, canvasModel) {
45
45
  if (chartOrientation === 'horizontal') {
46
- return blockSize.height - margin.top - margin.bottom;
46
+ return canvasModel.getChartBlockHeight();
47
47
  }
48
48
  else {
49
- return blockSize.width - margin.left - margin.right;
49
+ return canvasModel.getChartBlockWidth();
50
50
  }
51
51
  }
52
52
  static getAxisOrient(axisType, chartOrientation, axisPosition) {
@@ -59,25 +59,25 @@ export class AxisModel {
59
59
  return axisType === AxisType.Key ? 'left' : 'top';
60
60
  return axisType === AxisType.Key ? 'right' : 'bottom';
61
61
  }
62
- static getAxisTranslateX(axisType, chartOrientation, axisPosition, margin, blockWidth) {
62
+ static getAxisTranslateX(axisType, chartOrientation, axisPosition, canvasModel) {
63
63
  const orient = AxisModel.getAxisOrient(axisType, chartOrientation, axisPosition);
64
64
  if (orient === 'top' || orient === 'left')
65
- return margin.left;
65
+ return canvasModel.getMarginSide("left");
66
66
  else if (orient === 'bottom')
67
- return margin.left;
68
- return blockWidth - margin.right;
67
+ return canvasModel.getMarginSide("left");
68
+ return canvasModel.getBlockSize().width - canvasModel.getMarginSide("right");
69
69
  }
70
- static getAxisTranslateY(axisType, chartOrientation, axisPosition, margin, blockHeight) {
70
+ static getAxisTranslateY(axisType, chartOrientation, axisPosition, canvasModel) {
71
71
  const orient = AxisModel.getAxisOrient(axisType, chartOrientation, axisPosition);
72
72
  if (orient === 'top' || orient === 'left')
73
- return margin.top;
73
+ return canvasModel.getMarginSide("top");
74
74
  else if (orient === 'bottom')
75
- return blockHeight - margin.bottom;
76
- return margin.top;
75
+ return canvasModel.getBlockSize().height - canvasModel.getMarginSide("bottom");
76
+ return canvasModel.getMarginSide("top");
77
77
  }
78
- static getKeyAxisLabelPosition(margin, blockSize, scopedDataLength) {
78
+ static getKeyAxisLabelPosition(canvasModel, scopedDataLength) {
79
79
  const minBandSize = 50;
80
- if ((blockSize.width - margin.left - margin.right) / scopedDataLength < minBandSize)
80
+ if (canvasModel.getChartBlockWidth() / scopedDataLength < minBandSize)
81
81
  return 'rotated';
82
82
  return 'straight';
83
83
  }
@@ -1,12 +1,11 @@
1
1
  import { ChartNotation, Size } from "../../../config/config";
2
- import { BlockMargin, ILegendModel, LegendBlockModel, LegendPosition, Orient } from "../../model";
2
+ import { ILegendModel, LegendBlockModel, LegendPosition, Orient } from "../../model";
3
+ import { CanvasModel } from "../../modelInstance/canvasModel/canvasModel";
3
4
  import { LegendItemsDirection } from "./legendCanvasModel";
4
- /** If donut block has width less than this const, legend change postion from "right" to "bottom" */
5
- export declare const MIN_DONUT_BLOCK_SIZE = 260;
6
5
  export declare class LegendModel {
7
6
  static getLegendSize(chartNotation: ChartNotation, position: Orient, texts: string[], legendMaxWidth: number, blockSize: Size, legendBlockModel: LegendBlockModel): number;
8
- static getBaseLegendBlockModel(notation: ChartNotation): LegendBlockModel;
9
- static getLegendModel(chartNotation: ChartNotation, legendShow: boolean, blockSize: Size, margin: BlockMargin): ILegendModel;
7
+ static getBaseLegendBlockModel(notation: ChartNotation, canvasModel: CanvasModel): LegendBlockModel;
8
+ static getLegendModel(chartNotation: ChartNotation, legendShow: boolean, canvasModel: CanvasModel): ILegendModel;
10
9
  static getLegendItemClass(itemsPosition: LegendItemsDirection): string;
11
10
  static getMarginClass(legendPosition: LegendPosition): string;
12
11
  private static getLegendWidth;