mdt-charts 1.12.0 → 1.12.1
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.
- package/lib/config/config.d.ts +5 -0
- package/lib/engine/features/legend/legend.d.ts +10 -1
- package/lib/engine/features/legend/legend.js +10 -22
- package/lib/engine/features/legend/legendHelper.d.ts +4 -5
- package/lib/engine/features/legend/legendHelper.js +19 -23
- package/lib/engine/features/legend/legendHelperService.d.ts +12 -0
- package/lib/engine/features/legend/legendHelperService.js +30 -0
- package/lib/engine/polarNotation/extenders/polarRecordOverflowAlert.d.ts +0 -1
- package/lib/engine/polarNotation/extenders/polarRecordOverflowAlert.js +9 -17
- package/lib/model/dataManagerModel/dataManagerModel.d.ts +8 -0
- package/lib/model/dataManagerModel/dataManagerModel.js +25 -12
- package/lib/model/featuresModel/axisModel.d.ts +5 -4
- package/lib/model/featuresModel/axisModel.js +13 -11
- package/lib/model/featuresModel/axisModelService.d.ts +4 -0
- package/lib/model/featuresModel/axisModelService.js +11 -0
- package/lib/model/featuresModel/legendModel/legendCanvasModel.d.ts +4 -2
- package/lib/model/featuresModel/legendModel/legendCanvasModel.js +42 -29
- package/lib/model/featuresModel/legendModel/legendModel.d.ts +1 -2
- package/lib/model/featuresModel/legendModel/legendModel.js +14 -14
- package/lib/model/featuresModel/legendModel/polarMarginCalculator.d.ts +11 -0
- package/lib/model/featuresModel/legendModel/polarMarginCalculator.js +42 -0
- package/lib/model/featuresModel/titleModel.js +1 -1
- package/lib/model/marginModel.d.ts +3 -2
- package/lib/model/marginModel.js +5 -2
- package/lib/model/model.d.ts +1 -2
- package/lib/model/modelBuilder.js +2 -2
- package/lib/model/notations/polarModel.d.ts +3 -1
- package/lib/model/notations/polarModel.js +12 -1
- package/lib/model/notations/twoDimensionalModel.js +1 -1
- package/lib/style/charts-main.css +26 -7
- package/lib/style/charts-main.less +26 -7
- package/package.json +2 -2
- package/tsconfig.production.json +23 -0
- package/lib/engine/features/recordOverflowAlert/recordOverflowAlert.d.ts +0 -14
- package/lib/engine/features/recordOverflowAlert/recordOverflowAlert.js +0 -97
- package/lib/model/dataManagerModel.d.ts +0 -23
- package/lib/model/dataManagerModel.js +0 -139
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { AxisModel } from "./featuresModel/axisModel";
|
|
2
|
-
import { LegendCanvasModel } from "./featuresModel/legendModel/legendCanvasModel";
|
|
3
|
-
import { MIN_DONUT_BLOCK_SIZE } from "./featuresModel/legendModel/legendModel";
|
|
4
|
-
import { ModelHelper } from "./modelHelper";
|
|
5
|
-
export class DataManagerModel {
|
|
6
|
-
static getPreparedData(data, allowableKeys, config) {
|
|
7
|
-
const scopedData = this.getScopedData(data, allowableKeys, config);
|
|
8
|
-
this.setDataType(scopedData, config);
|
|
9
|
-
return scopedData;
|
|
10
|
-
}
|
|
11
|
-
static getDataScope(config, data, designerConfig, legendBlock, modelInstance) {
|
|
12
|
-
if (config.options.type === '2d' || config.options.type === 'interval') {
|
|
13
|
-
return this.getDataScopeFor2D(config.options, modelInstance, data, designerConfig);
|
|
14
|
-
}
|
|
15
|
-
else if (config.options.type === 'polar') {
|
|
16
|
-
return this.getDataScopeForPolar(config.options, modelInstance, data, legendBlock, designerConfig.canvas.legendBlock);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
static getDataValuesByKeyField(data, dataSourceName, keyFieldName) {
|
|
20
|
-
return data[dataSourceName].map(dataRow => dataRow[keyFieldName]);
|
|
21
|
-
}
|
|
22
|
-
static getDataScopeFor2D(configOptions, modelInstance, data, designerConfig) {
|
|
23
|
-
// Для interval всегда один элемент, так как там может быть только один столбик
|
|
24
|
-
let itemsLength = 1;
|
|
25
|
-
if (configOptions.type === '2d') {
|
|
26
|
-
itemsLength = (configOptions.charts)
|
|
27
|
-
.filter((chart) => chart.type === 'bar').length;
|
|
28
|
-
if (itemsLength === 0)
|
|
29
|
-
itemsLength = 1; // Если баров нет, то для одной записи выделяется столько же места, сколько для одного столбика
|
|
30
|
-
}
|
|
31
|
-
if (itemsLength !== 0) {
|
|
32
|
-
const axisLength = AxisModel.getAxisLength(configOptions.orientation, modelInstance.canvasModel);
|
|
33
|
-
const uniqueKeys = ModelHelper.getUniqueValues(data[configOptions.data.dataSource].map(d => d[configOptions.data.keyField.name]));
|
|
34
|
-
const dataLength = uniqueKeys.length;
|
|
35
|
-
const limit = this.getDataLimitByItemSize(this.getElementsInGroupAmount(configOptions, itemsLength), dataLength, axisLength, designerConfig.canvas.chartOptions.bar);
|
|
36
|
-
const allowableKeys = uniqueKeys.slice(0, limit);
|
|
37
|
-
return {
|
|
38
|
-
allowableKeys,
|
|
39
|
-
hidedRecordsAmount: dataLength - allowableKeys.length
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
allowableKeys: this.getDataValuesByKeyField(data, configOptions.data.dataSource, configOptions.data.keyField.name),
|
|
44
|
-
hidedRecordsAmount: 0
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
static getDataScopeForPolar(configOptions, modelInstance, data, legendBlock, legendCanvas) {
|
|
48
|
-
const canvas = modelInstance.canvasModel;
|
|
49
|
-
const dataset = data[configOptions.data.dataSource];
|
|
50
|
-
const keyFieldName = configOptions.data.keyField.name;
|
|
51
|
-
const keys = dataset.map(dataRow => dataRow[keyFieldName]);
|
|
52
|
-
if (!configOptions.legend.show) {
|
|
53
|
-
return {
|
|
54
|
-
allowableKeys: keys,
|
|
55
|
-
hidedRecordsAmount: 0
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
let position;
|
|
59
|
-
if (canvas.getChartBlockWidth() >= MIN_DONUT_BLOCK_SIZE)
|
|
60
|
-
position = 'right';
|
|
61
|
-
else
|
|
62
|
-
position = 'bottom';
|
|
63
|
-
let maxItemsNumber;
|
|
64
|
-
if (position === 'right') {
|
|
65
|
-
maxItemsNumber = LegendCanvasModel.findElementsAmountByLegendSize(keys, position, legendCanvas.maxWidth, canvas.getChartBlockHeight());
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
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);
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
allowableKeys: keys.slice(0, maxItemsNumber),
|
|
74
|
-
hidedRecordsAmount: keys.length - maxItemsNumber
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Выводит количество элементов (преимущественно баров) в одной группе. Группа - один ключ
|
|
79
|
-
* @param configOptions
|
|
80
|
-
* @param chartsLength
|
|
81
|
-
*/
|
|
82
|
-
static getElementsInGroupAmount(configOptions, chartsLength) {
|
|
83
|
-
if (configOptions.type === '2d')
|
|
84
|
-
return this.getBarChartsInGroupAmount(configOptions.charts);
|
|
85
|
-
return chartsLength;
|
|
86
|
-
}
|
|
87
|
-
static getBarChartsInGroupAmount(charts) {
|
|
88
|
-
let barsAmount = 0;
|
|
89
|
-
charts.forEach(chart => {
|
|
90
|
-
if (chart.type === 'bar' && chart.isSegmented)
|
|
91
|
-
barsAmount += 1; // в сегментированном баре все valueFields находятся внутри одного бара, поэтому бар всегда один.
|
|
92
|
-
else if (chart.type === 'bar')
|
|
93
|
-
barsAmount += chart.data.valueFields.length;
|
|
94
|
-
});
|
|
95
|
-
return barsAmount;
|
|
96
|
-
}
|
|
97
|
-
static getScopedData(data, allowableKeys, config) {
|
|
98
|
-
const newData = {};
|
|
99
|
-
newData[config.options.data.dataSource] = this.getScopedChartData(data[config.options.data.dataSource], allowableKeys, config.options.data.keyField.name);
|
|
100
|
-
return newData;
|
|
101
|
-
}
|
|
102
|
-
static getScopedChartData(data, allowableKeys, keyFieldName) {
|
|
103
|
-
return data.filter(d => allowableKeys.findIndex(key => key === d[keyFieldName]) !== -1);
|
|
104
|
-
}
|
|
105
|
-
static setDataType(data, config) {
|
|
106
|
-
if (config.options.type === 'polar' || config.options.type === '2d') {
|
|
107
|
-
// Форматиривание для оси ключей пока не совсем верно установлено
|
|
108
|
-
// if(config.options.data.keyField.format === 'date') {
|
|
109
|
-
// data[config.options.data.dataSource] = this.getTypedData(data[config.options.data.dataSource], config.options.data.keyField);
|
|
110
|
-
// }
|
|
111
|
-
}
|
|
112
|
-
else if (config.options.type === 'interval') {
|
|
113
|
-
const chart = config.options.chart;
|
|
114
|
-
if (chart.data.valueField1.format === 'date') {
|
|
115
|
-
data[config.options.data.dataSource] = this.getTypedData(data[config.options.data.dataSource], chart.data.valueField1);
|
|
116
|
-
}
|
|
117
|
-
if (chart.data.valueField2.format === 'date') {
|
|
118
|
-
data[config.options.data.dataSource] = this.getTypedData(data[config.options.data.dataSource], chart.data.valueField2);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
static getTypedData(data, field) {
|
|
123
|
-
if (field.format === 'date')
|
|
124
|
-
data.forEach(d => {
|
|
125
|
-
d[field.name] = new Date(d[field.name]);
|
|
126
|
-
});
|
|
127
|
-
return data;
|
|
128
|
-
}
|
|
129
|
-
static getDataLimitByItemSize(elementsInGroupAmount, dataLength, axisLength, barOptions) {
|
|
130
|
-
let sumSize = dataLength * (elementsInGroupAmount * barOptions.minBarWidth + (elementsInGroupAmount - 1) * barOptions.barDistance + barOptions.groupMinDistance);
|
|
131
|
-
while (dataLength !== 0 && axisLength < sumSize) {
|
|
132
|
-
dataLength--;
|
|
133
|
-
// find whole space for bars in group + distance between bars + group distance
|
|
134
|
-
sumSize = dataLength * (elementsInGroupAmount * barOptions.minBarWidth + (elementsInGroupAmount - 1)
|
|
135
|
-
* barOptions.barDistance + barOptions.groupMinDistance);
|
|
136
|
-
}
|
|
137
|
-
return dataLength;
|
|
138
|
-
}
|
|
139
|
-
}
|