mdt-charts 1.12.10 → 1.12.14

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 (58) hide show
  1. package/lib/config/config.d.ts +2 -2
  2. package/lib/designer/designerConfig.d.ts +1 -1
  3. package/lib/engine/features/axis/axis.js +1 -1
  4. package/lib/engine/features/axis/axisLabelDomHelper.js +1 -1
  5. package/lib/model/chartStyleModel/TwoDimensionalChartStyleModel.js +1 -1
  6. package/lib/model/dataManagerModel/dataManagerModel.d.ts +2 -0
  7. package/lib/model/dataManagerModel/dataManagerModel.js +10 -5
  8. package/lib/model/featuresModel/axisModel.js +1 -1
  9. package/lib/model/featuresModel/legendModel/legendCanvasModel.d.ts +0 -1
  10. package/lib/model/featuresModel/legendModel/legendCanvasModel.js +0 -25
  11. package/lib/model/featuresModel/legendModel/legendModel.d.ts +2 -6
  12. package/lib/model/featuresModel/legendModel/legendModel.js +4 -47
  13. package/lib/model/featuresModel/legendModel/polarMarginCalculator.d.ts +2 -5
  14. package/lib/model/featuresModel/legendModel/polarMarginCalculator.js +12 -29
  15. package/lib/model/featuresModel/legendModel/twoDimLegendModel.d.ts +7 -0
  16. package/lib/model/featuresModel/legendModel/twoDimLegendModel.js +24 -0
  17. package/lib/model/featuresModel/otherComponents.d.ts +0 -2
  18. package/lib/model/featuresModel/otherComponents.js +1 -1
  19. package/lib/model/featuresModel/scaleModel/scaleAxisRecalcer.js +3 -1
  20. package/lib/model/featuresModel/scaleModel/scaleModel.d.ts +2 -2
  21. package/lib/model/featuresModel/scaleModel/scaleModel.js +6 -6
  22. package/lib/model/{modelHelper.d.ts → helpers/modelHelper.d.ts} +1 -1
  23. package/lib/model/{modelHelper.js → helpers/modelHelper.js} +0 -0
  24. package/lib/model/helpers/unitsFromConfigReader.d.ts +2 -0
  25. package/lib/model/helpers/unitsFromConfigReader.js +7 -0
  26. package/lib/model/helpers/unitsReader.d.ts +5 -0
  27. package/lib/model/helpers/unitsReader.js +15 -0
  28. package/lib/model/margin/marginModel.d.ts +11 -0
  29. package/lib/model/margin/marginModel.js +26 -0
  30. package/lib/model/margin/twoDim/twoDimMarginModel.d.ts +14 -0
  31. package/lib/model/margin/twoDim/twoDimMarginModel.js +69 -0
  32. package/lib/model/model.d.ts +2 -2
  33. package/lib/model/modelBuilder.d.ts +0 -1
  34. package/lib/model/modelBuilder.js +7 -12
  35. package/lib/model/notations/intervalModel.d.ts +3 -3
  36. package/lib/model/notations/intervalModel.js +6 -6
  37. package/lib/model/notations/polar/donut/donutAggregatorService.d.ts +1 -0
  38. package/lib/model/notations/polar/donut/donutAggregatorService.js +19 -4
  39. package/lib/model/notations/polar/donut/donutThicknessService.d.ts +0 -2
  40. package/lib/model/notations/polar/donut/donutThicknessService.js +4 -16
  41. package/lib/model/notations/twoDimensionalModel.d.ts +2 -2
  42. package/lib/model/notations/twoDimensionalModel.js +4 -3
  43. package/lib/style/charts-main.css +2 -0
  44. package/lib/style/charts-main.less +2 -0
  45. package/package.json +1 -1
  46. package/tsconfig.production.json +2 -1
  47. package/lib/engine/features/tolltip/newTooltip/newTooltip.test.d.ts +0 -1
  48. package/lib/engine/features/tolltip/newTooltip/newTooltip.test.js +0 -186
  49. package/lib/engine/twoDimensionalNotation/bar/stackedData/dataStacker.test.d.ts +0 -1
  50. package/lib/engine/twoDimensionalNotation/bar/stackedData/dataStacker.test.js +0 -199
  51. package/lib/model/featuresModel/scaleModel.d.ts +0 -19
  52. package/lib/model/featuresModel/scaleModel.js +0 -115
  53. package/lib/model/marginModel.d.ts +0 -18
  54. package/lib/model/marginModel.js +0 -110
  55. package/lib/model/modelInstance/dataModel.d.ts +0 -11
  56. package/lib/model/modelInstance/dataModel.js +0 -23
  57. package/lib/model/notations/polarModel.d.ts +0 -15
  58. package/lib/model/notations/polarModel.js +0 -59
@@ -1,199 +0,0 @@
1
- import { DataStacker } from "./dataStacker";
2
- import { DataStackerService } from "./dataStackerService";
3
- describe('DataStacker', () => {
4
- const stacker = new DataStacker();
5
- describe('getStackedData', () => {
6
- describe('for positive values', () => {
7
- let dataRows = [
8
- { price: 12, count: 30 },
9
- { price: 30, count: 12 },
10
- { price: 0, count: 100 },
11
- { price: 10, count: 0 }
12
- ];
13
- const valueFields = ["price", "count"];
14
- test('should return right stack', () => {
15
- const res = stacker.getStackedData(dataRows, valueFields);
16
- expect(res).toEqual([
17
- [
18
- { "0": 0, "1": 12, data: dataRows[0] },
19
- { "0": 0, "1": 30, data: dataRows[1] },
20
- { "0": 0, "1": 0, data: dataRows[2] },
21
- { "0": 0, "1": 10, data: dataRows[3] },
22
- ],
23
- [
24
- { "0": 12, "1": 42, data: dataRows[0] },
25
- { "0": 30, "1": 42, data: dataRows[1] },
26
- { "0": 0, "1": 100, data: dataRows[2] },
27
- { "0": 10, "1": 10, data: dataRows[3] },
28
- ]
29
- ]);
30
- });
31
- });
32
- describe('for negative values', () => {
33
- let dataRows = [
34
- { price: -12, count: -30 },
35
- { price: -30, count: -12 },
36
- { price: 0, count: -100 },
37
- { price: -10, count: 0 }
38
- ];
39
- const valueFields = ["price", "count"];
40
- test('should return right stack', () => {
41
- const res = stacker.getStackedData(dataRows, valueFields);
42
- expect(res).toEqual([
43
- [
44
- { "0": 0, "1": -12, data: dataRows[0] },
45
- { "0": 0, "1": -30, data: dataRows[1] },
46
- { "0": 0, "1": 0, data: dataRows[2] },
47
- { "0": 0, "1": -10, data: dataRows[3] },
48
- ],
49
- [
50
- { "0": -12, "1": -42, data: dataRows[0] },
51
- { "0": -30, "1": -42, data: dataRows[1] },
52
- { "0": 0, "1": -100, data: dataRows[2] },
53
- { "0": -10, "1": -10, data: dataRows[3] },
54
- ]
55
- ]);
56
- });
57
- });
58
- });
59
- });
60
- describe('DataStackerService', () => {
61
- const service = new DataStackerService();
62
- let data = [
63
- [
64
- { "0": 0, "1": 42, data: {} },
65
- { "0": 0, "1": -123, data: {} }
66
- ]
67
- ];
68
- describe('getLastValue', () => {
69
- test('should return 0 if vfIndex is 0', () => {
70
- const res = service.getValue0(data, 0, 0, 0);
71
- expect(res).toBe(0);
72
- });
73
- test('should return last positive values if positive value exists and need positive', () => {
74
- const res = service.getValue0(data, 1, 0, 12);
75
- expect(res).toBe(42);
76
- });
77
- test('should return 0 if positive value not exists and need positive', () => {
78
- const res = service.getValue0(data, 1, 1, 12);
79
- expect(res).toBe(0);
80
- });
81
- test('should return last negative value if negative value exists and need negative', () => {
82
- const res = service.getValue0(data, 1, 1, -12);
83
- expect(res).toBe(-123);
84
- });
85
- test('should return 0 if negative value not exists and need negative', () => {
86
- const res = service.getValue0(data, 1, 0, -12);
87
- expect(res).toBe(0);
88
- });
89
- });
90
- describe('getValue1', () => {
91
- test('should return sum of value0 + value from data', () => {
92
- let res = service.getValue1(0, 12);
93
- expect(res).toBe(12);
94
- res = service.getValue1(-12, -30);
95
- expect(res).toBe(-42);
96
- res = service.getValue1(0, 30);
97
- expect(res).toBe(30);
98
- res = service.getValue1(0, -30);
99
- expect(res).toBe(-30);
100
- });
101
- });
102
- });
103
- describe('real example (positive only)', () => {
104
- const stacker = new DataStacker();
105
- const data = [
106
- {
107
- $id: 1,
108
- brand: "BMW BMW",
109
- price: 100000,
110
- count: 12000,
111
- color: "red"
112
- },
113
- {
114
- $id: 2,
115
- brand: "LADA",
116
- price: 0,
117
- count: 1000,
118
- color: "green"
119
- },
120
- {
121
- $id: 3,
122
- brand: "MERCEDES",
123
- price: 15000,
124
- count: 1200,
125
- color: "blue"
126
- },
127
- {
128
- $id: 4,
129
- brand: "AUDI",
130
- price: 20000,
131
- count: 500,
132
- color: "yellow"
133
- },
134
- {
135
- $id: 5,
136
- brand: "VOLKSWAGEN",
137
- price: 115000,
138
- count: 6000,
139
- color: "cyan"
140
- },
141
- {
142
- $id: 6,
143
- brand: "DODGE",
144
- price: 115000,
145
- count: 4000,
146
- color: "red"
147
- },
148
- {
149
- $id: 7,
150
- brand: "SAAB",
151
- price: 50000,
152
- count: 11000,
153
- color: "orange"
154
- },
155
- {
156
- $id: 8,
157
- brand: "HONDA",
158
- price: 20000,
159
- count: 2000,
160
- color: "brown"
161
- },
162
- {
163
- $id: 9,
164
- brand: "TOYOTA",
165
- price: 40000,
166
- count: 15000,
167
- color: "pink"
168
- }
169
- ];
170
- const valueFields = ["price", "count"];
171
- const stackedData = [
172
- [
173
- { "0": 0, "1": 100000, data: data[0] },
174
- { "0": 0, "1": 0, data: data[1] },
175
- { "0": 0, "1": 15000, data: data[2] },
176
- { "0": 0, "1": 20000, data: data[3] },
177
- { "0": 0, "1": 115000, data: data[4] },
178
- { "0": 0, "1": 115000, data: data[5] },
179
- { "0": 0, "1": 50000, data: data[6] },
180
- { "0": 0, "1": 20000, data: data[7] },
181
- { "0": 0, "1": 40000, data: data[8] }
182
- ],
183
- [
184
- { "0": 100000, "1": 112000, data: data[0] },
185
- { "0": 0, "1": 1000, data: data[1] },
186
- { "0": 15000, "1": 16200, data: data[2] },
187
- { "0": 20000, "1": 20500, data: data[3] },
188
- { "0": 115000, "1": 121000, data: data[4] },
189
- { "0": 115000, "1": 119000, data: data[5] },
190
- { "0": 50000, "1": 61000, data: data[6] },
191
- { "0": 20000, "1": 22000, data: data[7] },
192
- { "0": 40000, "1": 55000, data: data[8] }
193
- ]
194
- ];
195
- test('check on real example', () => {
196
- const res = stacker.getStackedData(data, valueFields);
197
- expect(res).toEqual(stackedData);
198
- });
199
- });
@@ -1,19 +0,0 @@
1
- import { ScaleKeyModel, ScaleKeyType, ScaleValueModel, ScaleValueType } from "../model";
2
- import { AxisPosition, NumberDomain, IntervalChart, MdtChartsTwoDimensionalChart, MdtChartsTwoDimensionalOptions, ChartOrientation, MdtChartsDataSource, MdtChartsDataRow } from "../../config/config";
3
- import { CanvasModel } from "../modelInstance/canvasModel/canvasModel";
4
- export declare enum ScaleType {
5
- Key = 0,
6
- Value = 1
7
- }
8
- export declare class ScaleModel {
9
- static getScaleKey(allowableKeys: string[], orient: ChartOrientation, canvasModel: CanvasModel, charts: MdtChartsTwoDimensionalChart[], barCharts: MdtChartsTwoDimensionalChart[]): ScaleKeyModel;
10
- static getScaleLinear(options: MdtChartsTwoDimensionalOptions, data: MdtChartsDataSource, canvasModel: CanvasModel): ScaleValueModel;
11
- static getRangePeek(scaleType: ScaleType, chartOrientation: string, canvasModel: CanvasModel): number;
12
- static getDateValueDomain(data: MdtChartsDataSource, chart: IntervalChart, keyAxisPosition: AxisPosition, dataSource: string): [Date, Date];
13
- static getLinearDomain(configDomain: NumberDomain, data: MdtChartsDataSource, configOptions: MdtChartsTwoDimensionalOptions): [number, number];
14
- static getScaleKeyType(charts: MdtChartsTwoDimensionalChart[]): ScaleKeyType;
15
- static getScaleValueType(charts: MdtChartsTwoDimensionalChart[] | IntervalChart[]): ScaleValueType;
16
- static getElementsAmount(barCharts: MdtChartsTwoDimensionalChart[]): number;
17
- static getScaleMaxValue(charts: MdtChartsTwoDimensionalChart[], dataRows: MdtChartsDataRow[]): number;
18
- static getScaleMinValue(charts: MdtChartsTwoDimensionalChart[], dataRows: MdtChartsDataRow[]): number;
19
- }
@@ -1,115 +0,0 @@
1
- import { ModelHelper } from "../modelHelper";
2
- export var ScaleType;
3
- (function (ScaleType) {
4
- ScaleType[ScaleType["Key"] = 0] = "Key";
5
- ScaleType[ScaleType["Value"] = 1] = "Value";
6
- })(ScaleType || (ScaleType = {}));
7
- export class ScaleModel {
8
- static getScaleKey(allowableKeys, orient, canvasModel, charts, barCharts) {
9
- return {
10
- domain: allowableKeys,
11
- range: {
12
- start: 0,
13
- end: ScaleModel.getRangePeek(ScaleType.Key, orient, canvasModel)
14
- },
15
- type: ScaleModel.getScaleKeyType(charts),
16
- elementsAmount: this.getElementsAmount(barCharts)
17
- };
18
- }
19
- static getScaleLinear(options, data, canvasModel) {
20
- return {
21
- domain: ScaleModel.getLinearDomain(options.axis.value.domain, data, options),
22
- range: {
23
- start: 0,
24
- end: ScaleModel.getRangePeek(ScaleType.Value, options.orientation, canvasModel)
25
- },
26
- type: ScaleModel.getScaleValueType(options.charts)
27
- };
28
- }
29
- static getRangePeek(scaleType, chartOrientation, canvasModel) {
30
- if (chartOrientation === 'vertical')
31
- return scaleType === ScaleType.Key
32
- ? canvasModel.getChartBlockWidth()
33
- : canvasModel.getChartBlockHeight();
34
- return scaleType === ScaleType.Key
35
- ? canvasModel.getChartBlockHeight()
36
- : canvasModel.getChartBlockWidth();
37
- }
38
- static getDateValueDomain(data, chart, keyAxisPosition, dataSource) {
39
- const minMax = ModelHelper.getMinAndMaxOfIntervalData(data, dataSource, chart);
40
- let domainPeekMin = minMax[0];
41
- let domainPeekMax = minMax[1];
42
- if (keyAxisPosition === 'start')
43
- return [domainPeekMin, domainPeekMax];
44
- return [domainPeekMax, domainPeekMin];
45
- }
46
- static getLinearDomain(configDomain, data, configOptions) {
47
- let domainPeekMin;
48
- let domainPeekMax;
49
- if (configDomain.start === -1)
50
- domainPeekMin = this.getScaleMinValue(configOptions.charts, data[configOptions.data.dataSource]);
51
- else
52
- domainPeekMin = configDomain.start;
53
- if (configDomain.end === -1)
54
- domainPeekMax = this.getScaleMaxValue(configOptions.charts, data[configOptions.data.dataSource]);
55
- else
56
- domainPeekMax = configDomain.end;
57
- if (configOptions.axis.key.position === 'start')
58
- return [domainPeekMin, domainPeekMax];
59
- return [domainPeekMax, domainPeekMin];
60
- }
61
- static getScaleKeyType(charts) {
62
- if (charts.findIndex((chart) => chart.type === 'bar') === -1)
63
- return 'point';
64
- return 'band';
65
- }
66
- static getScaleValueType(charts) {
67
- if (charts.findIndex((chart) => chart.type === 'gantt') !== -1)
68
- return 'datetime';
69
- return 'linear';
70
- }
71
- static getElementsAmount(barCharts) {
72
- if (barCharts.length === 0)
73
- return 1;
74
- let barsAmount = 0;
75
- barCharts.forEach(chart => {
76
- if (chart.isSegmented)
77
- barsAmount += 1; // Если бар сегментированный, то все valueFields являются частями одного бара
78
- else
79
- barsAmount += chart.data.valueFields.length;
80
- });
81
- return barsAmount;
82
- }
83
- static getScaleMaxValue(charts, dataRows) {
84
- let max = 0;
85
- charts.forEach(chart => {
86
- dataRows.forEach(dataRow => {
87
- let sumInRow = 0;
88
- chart.data.valueFields.forEach(field => {
89
- if (chart.isSegmented)
90
- sumInRow += dataRow[field.name];
91
- else if (dataRow[field.name] > sumInRow)
92
- sumInRow = dataRow[field.name];
93
- });
94
- if (max < sumInRow)
95
- max = sumInRow;
96
- });
97
- });
98
- return max;
99
- }
100
- static getScaleMinValue(charts, dataRows) {
101
- let min = 0;
102
- charts.forEach(chart => {
103
- dataRows.forEach(dataRow => {
104
- let sumInRow = 0;
105
- chart.data.valueFields.forEach(field => {
106
- if (dataRow[field.name] < sumInRow)
107
- sumInRow = dataRow[field.name];
108
- });
109
- if (min > sumInRow)
110
- min = sumInRow;
111
- });
112
- });
113
- return min;
114
- }
115
- }
@@ -1,18 +0,0 @@
1
- import { MdtChartsConfig, MdtChartsDataSource } from "../config/config";
2
- import { DesignerConfig } from "../designer/designerConfig";
3
- import { DataScope, LegendBlockModel, Orient, OtherCommonComponents } from "./model";
4
- import { ModelInstance } from "./modelInstance/modelInstance";
5
- import { CanvasModel } from "./modelInstance/canvasModel/canvasModel";
6
- export declare const AXIS_HORIZONTAL_LABEL_PADDING = 15;
7
- export declare const AXIS_VERTICAL_LABEL_PADDING = 10;
8
- export declare class MarginModel {
9
- static initMargin(designerConfig: DesignerConfig, config: MdtChartsConfig, otherComponents: OtherCommonComponents, data: MdtChartsDataSource, modelInstance: ModelInstance): void;
10
- static recalcMarginByVerticalAxisLabel(modelInstance: ModelInstance, config: MdtChartsConfig, designerConfig: DesignerConfig, dataScope: DataScope): void;
11
- private static getHorizontalMarginByAxisLabels;
12
- private static recalcVerticalMarginByAxisLabelHeight;
13
- private static recalcHorizontalMarginByAxisLabelWidth;
14
- private static recalcMarginWithLegend;
15
- private static getLegendItemsContent;
16
- static appendToGlobalMarginValuesLegendMargin(canvasModel: CanvasModel, position: Orient, legendBlockModel: LegendBlockModel): void;
17
- private static recalcMarginByTitle;
18
- }
@@ -1,110 +0,0 @@
1
- import { AxisModel } from "./featuresModel/axisModel";
2
- import { DataManagerModel } from "./dataManagerModel/dataManagerModel";
3
- import { LegendModel } from "./featuresModel/legendModel/legendModel";
4
- import { AxisType } from "./modelBuilder";
5
- import { TwoDimensionalModel } from "./notations/twoDimensionalModel";
6
- import { keyAxisLabelHorizontalLog, keyAxisLabelVerticalLog } from "./featuresModel/scaleModel/scaleAxisRecalcer";
7
- export const AXIS_HORIZONTAL_LABEL_PADDING = 15;
8
- export const AXIS_VERTICAL_LABEL_PADDING = 10;
9
- export class MarginModel {
10
- static initMargin(designerConfig, config, otherComponents, data, modelInstance) {
11
- const canvasModel = modelInstance.canvasModel;
12
- canvasModel.initMargin(Object.assign({}, designerConfig.canvas.chartBlockMargin));
13
- this.recalcMarginWithLegend(modelInstance, config, designerConfig.canvas.legendBlock.maxWidth, otherComponents.legendBlock, data);
14
- this.recalcMarginByTitle(canvasModel, otherComponents.titleBlock);
15
- if (config.options.type === '2d' || config.options.type === 'interval') {
16
- const labelSize = this.getHorizontalMarginByAxisLabels(designerConfig.canvas.axisLabel.maxSize.main, config.options.axis, data, config.options);
17
- this.recalcVerticalMarginByAxisLabelHeight(labelSize, canvasModel, config.options.orientation, config.options.axis);
18
- // Если встроенный лейбл показывает ключи, то лейблы оси ключей не показываются
19
- // При этом все графики должны иметь: embeddedLabels = 'key'
20
- // И все графики должны быть типа bar.
21
- const showingFlag = config.options.type === '2d'
22
- ? !TwoDimensionalModel.getChartsEmbeddedLabelsFlag(config.options.charts, config.options.orientation)
23
- : true;
24
- this.recalcHorizontalMarginByAxisLabelWidth(labelSize, canvasModel, config.options.orientation, config.options.axis, showingFlag);
25
- }
26
- }
27
- static recalcMarginByVerticalAxisLabel(modelInstance, config, designerConfig, dataScope) {
28
- if ((config.options.type === '2d' || config.options.type === 'interval') && config.options.orientation === 'vertical') {
29
- const axisLabelSize = AxisModel.getLabelSize(designerConfig.canvas.axisLabel.maxSize.main, dataScope.allowableKeys);
30
- const axisConfig = AxisModel.getKeyAxisLabelPosition(modelInstance.canvasModel, dataScope.allowableKeys.length, config.options.axis.key);
31
- const marginOrient = config.options.axis.key.position === 'end' ? 'bottom' : 'top';
32
- if (axisConfig === 'rotated') {
33
- modelInstance.canvasModel.decreaseMarginSide(marginOrient, axisLabelSize.height);
34
- modelInstance.canvasModel.increaseMarginSide(marginOrient, axisLabelSize.width, keyAxisLabelVerticalLog);
35
- }
36
- }
37
- }
38
- static getHorizontalMarginByAxisLabels(labelsMaxWidth, axis, data, options) {
39
- const keyAxisOrient = AxisModel.getAxisOrient(AxisType.Key, options.orientation, axis.key.position);
40
- let labelsTexts;
41
- if (keyAxisOrient === 'left' || keyAxisOrient === 'right') {
42
- labelsTexts = DataManagerModel.getDataValuesByKeyField(data, options.data.dataSource, options.data.keyField.name);
43
- }
44
- else {
45
- labelsTexts = ['0000'];
46
- }
47
- return AxisModel.getLabelSize(labelsMaxWidth, labelsTexts);
48
- }
49
- static recalcVerticalMarginByAxisLabelHeight(labelSize, canvasModel, orientation, axis) {
50
- const keyAxisOrient = AxisModel.getAxisOrient(AxisType.Key, orientation, axis.key.position);
51
- const valueAxisOrient = AxisModel.getAxisOrient(AxisType.Value, orientation, axis.value.position);
52
- if ((keyAxisOrient === 'bottom' || keyAxisOrient === 'top')) {
53
- if (axis.key.visibility)
54
- canvasModel.increaseMarginSide(keyAxisOrient, labelSize.height + AXIS_HORIZONTAL_LABEL_PADDING, keyAxisLabelVerticalLog);
55
- }
56
- else if (axis.value.visibility)
57
- canvasModel.increaseMarginSide(valueAxisOrient, labelSize.height + AXIS_HORIZONTAL_LABEL_PADDING);
58
- }
59
- static recalcHorizontalMarginByAxisLabelWidth(labelSize, canvasModel, orientation, axis, isShow) {
60
- const keyAxisOrient = AxisModel.getAxisOrient(AxisType.Key, orientation, axis.key.position);
61
- const valueAxisOrient = AxisModel.getAxisOrient(AxisType.Value, orientation, axis.value.position);
62
- if ((keyAxisOrient === 'left' || keyAxisOrient === 'right') && isShow && axis.key.visibility) {
63
- canvasModel.increaseMarginSide(keyAxisOrient, labelSize.width + AXIS_VERTICAL_LABEL_PADDING, keyAxisLabelHorizontalLog);
64
- }
65
- else if ((valueAxisOrient === 'left' || valueAxisOrient === 'right') && axis.value.visibility) {
66
- canvasModel.increaseMarginSide(valueAxisOrient, labelSize.width + AXIS_VERTICAL_LABEL_PADDING);
67
- }
68
- }
69
- static recalcMarginWithLegend(modelInstance, config, legendMaxWidth, legendBlockModel, data) {
70
- if (config.options.type === "polar") {
71
- return;
72
- }
73
- const canvasModel = modelInstance.canvasModel;
74
- const legendPosition = LegendModel.getLegendModel(config.options.type, config.options.legend.show, modelInstance.canvasModel).position;
75
- modelInstance.canvasModel.legendCanvas.setPosition(legendPosition);
76
- if (legendPosition !== 'off') {
77
- const legendItemsContent = this.getLegendItemsContent(config.options, data);
78
- const legendSize = LegendModel.getLegendSize(config.options.type, legendPosition, legendItemsContent, legendMaxWidth, canvasModel.getBlockSize(), legendBlockModel);
79
- canvasModel.increaseMarginSide(legendPosition, legendSize);
80
- if (legendSize !== 0)
81
- this.appendToGlobalMarginValuesLegendMargin(canvasModel, legendPosition, legendBlockModel);
82
- legendBlockModel.coordinate[legendPosition].size = legendSize;
83
- }
84
- }
85
- static getLegendItemsContent(options, data) {
86
- if (options.type === '2d') {
87
- let texts = [];
88
- options.charts.forEach(chart => {
89
- texts = texts.concat(chart.data.valueFields.map(field => field.title));
90
- });
91
- return texts;
92
- }
93
- else if (options.type === 'polar') {
94
- return DataManagerModel.getDataValuesByKeyField(data, options.data.dataSource, options.data.keyField.name);
95
- }
96
- else if (options.type === 'interval') {
97
- return [options.chart.data.valueField1.name];
98
- }
99
- }
100
- static appendToGlobalMarginValuesLegendMargin(canvasModel, position, legendBlockModel) {
101
- const legendCoordinate = legendBlockModel.coordinate;
102
- if (position === 'left' || position === 'right')
103
- canvasModel.increaseMarginSide(position, legendCoordinate[position].margin.left + legendCoordinate[position].margin.right);
104
- else
105
- canvasModel.increaseMarginSide(position, legendCoordinate[position].margin.top + legendCoordinate[position].margin.bottom);
106
- }
107
- static recalcMarginByTitle(canvasModel, titleBlockModel) {
108
- canvasModel.increaseMarginSide("top", titleBlockModel.margin.top + titleBlockModel.size + titleBlockModel.margin.bottom);
109
- }
110
- }
@@ -1,11 +0,0 @@
1
- import { DataScope } from "../model";
2
- export declare const DEFAULT_MAX_RECORDS_AMOUNT = 50;
3
- export declare class DataModelInstance {
4
- private maxRecordsAmount;
5
- private scope;
6
- initMaxRecordsAmount(amount: number): void;
7
- getMaxRecordsAmount(): number;
8
- initScope(scope: DataScope): void;
9
- getScope(): DataScope;
10
- getAllowableKeys(): string[];
11
- }
@@ -1,23 +0,0 @@
1
- export const DEFAULT_MAX_RECORDS_AMOUNT = 50;
2
- export class DataModelInstance {
3
- constructor() {
4
- this.maxRecordsAmount = DEFAULT_MAX_RECORDS_AMOUNT;
5
- }
6
- initMaxRecordsAmount(amount) {
7
- if (typeof amount === "number" && amount > 0) {
8
- this.maxRecordsAmount = amount;
9
- }
10
- }
11
- getMaxRecordsAmount() {
12
- return this.maxRecordsAmount;
13
- }
14
- initScope(scope) {
15
- this.scope = scope;
16
- }
17
- getScope() {
18
- return this.scope;
19
- }
20
- getAllowableKeys() {
21
- return this.getScope().allowableKeys;
22
- }
23
- }
@@ -1,15 +0,0 @@
1
- import { MdtChartsDataSource, MdtChartsPolarOptions } from "../../config/config";
2
- import { DesignerConfig } from "../../designer/designerConfig";
3
- import { PolarOptionsModel, LegendCoordinate } from "../model";
4
- import { CanvasModel } from "../modelInstance/canvasModel/canvasModel";
5
- import { ModelInstance } from "../modelInstance/modelInstance";
6
- /** If donut block has width less than this const, legend change postion from "right" to "bottom" */
7
- export declare const MIN_DONUT_BLOCK_SIZE = 120;
8
- export declare class PolarModel {
9
- static getOptions(options: MdtChartsPolarOptions, data: MdtChartsDataSource, designerConfig: DesignerConfig, modelInstance: ModelInstance): PolarOptionsModel;
10
- static getLegendPositionByBlockSize(canvasModel: CanvasModel): "bottom" | "right";
11
- static doesChartBlockHasEnoughWidthForContainsLegend(chartBlockWidth: number, legendWidth: number, legendCoordinate: LegendCoordinate): boolean;
12
- static doesChartBlockHasEnoughHeightForContainsLegend(chartBlockHeight: number, legendCoordinate: LegendCoordinate): boolean;
13
- private static getDonutSettings;
14
- private static getChartsModel;
15
- }
@@ -1,59 +0,0 @@
1
- import { ChartStyleModelService } from "../chartStyleModel/chartStyleModel";
2
- /** If donut block has width less than this const, legend change postion from "right" to "bottom" */
3
- export const MIN_DONUT_BLOCK_SIZE = 120;
4
- export class PolarModel {
5
- static getOptions(options, data, designerConfig, modelInstance) {
6
- return {
7
- type: options.type,
8
- selectable: !!options.selectable,
9
- title: options.title,
10
- data: Object.assign({}, options.data),
11
- charts: this.getChartsModel(options.chart, data[options.data.dataSource].length, designerConfig.chartStyle),
12
- legend: modelInstance.canvasModel.legendCanvas.getModel(),
13
- tooltip: options.tooltip,
14
- chartCanvas: this.getDonutSettings(designerConfig.canvas.chartOptions.donut, options.chart)
15
- };
16
- }
17
- //TODO: type for returned value
18
- static getLegendPositionByBlockSize(canvasModel) {
19
- const widthCoefficientWhenLegendShouldInBottom = 1.5;
20
- const avgLegendWidth = 100;
21
- const blockWidth = canvasModel.getBlockSize().width;
22
- const blockHeight = canvasModel.getBlockSize().height;
23
- return canvasModel.getChartBlockWidth() < MIN_DONUT_BLOCK_SIZE + avgLegendWidth
24
- && blockWidth * widthCoefficientWhenLegendShouldInBottom < blockHeight
25
- ? 'bottom'
26
- : 'right';
27
- }
28
- static doesChartBlockHasEnoughWidthForContainsLegend(chartBlockWidth, legendWidth, legendCoordinate) {
29
- const rightLegendMargin = legendCoordinate.right.margin;
30
- return chartBlockWidth - legendWidth - rightLegendMargin.left - rightLegendMargin.right >= MIN_DONUT_BLOCK_SIZE;
31
- }
32
- static doesChartBlockHasEnoughHeightForContainsLegend(chartBlockHeight, legendCoordinate) {
33
- const minHeightForLegend = 30;
34
- const bottomLegendMargin = legendCoordinate.bottom.margin;
35
- const heightForLegend = chartBlockHeight - bottomLegendMargin.bottom - bottomLegendMargin.top - MIN_DONUT_BLOCK_SIZE;
36
- return heightForLegend >= minHeightForLegend;
37
- }
38
- static getDonutSettings(settings, chartOptions) {
39
- return {
40
- padAngle: settings.padAngle,
41
- thickness: Object.assign({}, settings.thickness),
42
- aggregator: {
43
- margin: settings.aggregatorPad,
44
- text: chartOptions.aggregator.text
45
- }
46
- };
47
- }
48
- static getChartsModel(chart, dataLength, chartStyleConfig) {
49
- const chartsModel = [];
50
- chartsModel.push({
51
- type: chart.type,
52
- data: Object.assign({}, chart.data),
53
- tooltip: chart.tooltip,
54
- cssClasses: ChartStyleModelService.getCssClasses(0),
55
- style: ChartStyleModelService.getChartStyle(dataLength, chartStyleConfig)
56
- });
57
- return chartsModel;
58
- }
59
- }