mdt-charts 1.12.0 → 1.12.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config/config.d.ts +24 -12
- package/lib/designer/designerConfig.d.ts +3 -5
- package/lib/engine/features/aggregator/aggregator.d.ts +9 -7
- package/lib/engine/features/aggregator/aggregator.js +51 -37
- 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/donut/donut.js +1 -1
- package/lib/engine/polarNotation/extenders/polarRecordOverflowAlert.d.ts +0 -1
- package/lib/engine/polarNotation/extenders/polarRecordOverflowAlert.js +9 -17
- package/lib/engine/polarNotation/polarManager.js +1 -1
- package/lib/model/chartStyleModel/TwoDimensionalChartStyleModel.d.ts +4 -4
- package/lib/model/dataManagerModel/dataManagerModel.d.ts +8 -0
- package/lib/model/dataManagerModel/dataManagerModel.js +26 -13
- 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 +15 -15
- package/lib/model/featuresModel/legendModel/polarMarginCalculator.d.ts +11 -0
- package/lib/model/featuresModel/legendModel/polarMarginCalculator.js +42 -0
- package/lib/model/featuresModel/scaleModel.d.ts +6 -6
- package/lib/model/featuresModel/titleModel.js +4 -4
- package/lib/model/marginModel.d.ts +3 -2
- package/lib/model/marginModel.js +6 -3
- package/lib/model/model.d.ts +19 -8
- package/lib/model/modelBuilder.js +8 -9
- package/lib/model/modelInstance/dataModel/dataModel.d.ts +14 -0
- package/lib/model/modelInstance/dataModel/dataModel.js +26 -0
- package/lib/model/modelInstance/dataModel/dataRepository.d.ts +12 -0
- package/lib/model/modelInstance/dataModel/dataRepository.js +20 -0
- package/lib/model/modelInstance/modelInstance.d.ts +3 -3
- package/lib/model/modelInstance/modelInstance.js +6 -4
- package/lib/model/notations/intervalModel.d.ts +2 -2
- package/lib/model/notations/polar/donut/donutAggregatorService.d.ts +12 -0
- package/lib/model/notations/polar/donut/donutAggregatorService.js +25 -0
- package/lib/model/notations/polar/donut/donutModel.d.ts +10 -0
- package/lib/model/notations/polar/donut/donutModel.js +32 -0
- package/lib/model/notations/polar/donut/donutThicknessService.d.ts +9 -0
- package/lib/model/notations/polar/donut/donutThicknessService.js +30 -0
- package/lib/model/notations/polar/polarModel.d.ts +15 -0
- package/lib/model/notations/polar/polarModel.js +53 -0
- package/lib/model/notations/polarModel.d.ts +3 -1
- package/lib/model/notations/polarModel.js +12 -1
- package/lib/model/notations/twoDimensionalModel.d.ts +6 -6
- package/lib/model/notations/twoDimensionalModel.js +3 -3
- package/lib/style/charts-main.css +29 -9
- package/lib/style/charts-main.less +29 -9
- 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
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "./lib/",
|
|
4
|
+
"noImplicitAny": true,
|
|
5
|
+
"target": "es6",
|
|
6
|
+
"lib": ["ES2017", "DOM"],
|
|
7
|
+
"jsx": "react",
|
|
8
|
+
"allowJs": true,
|
|
9
|
+
"types": [
|
|
10
|
+
"jest"
|
|
11
|
+
],
|
|
12
|
+
"declaration": true
|
|
13
|
+
},
|
|
14
|
+
"include": [
|
|
15
|
+
"src"
|
|
16
|
+
],
|
|
17
|
+
"exclude": [
|
|
18
|
+
"node_modules",
|
|
19
|
+
"**/__tests__/*",
|
|
20
|
+
"src/playground/*",
|
|
21
|
+
"**/*Example.ts"
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ChartOrientation } from "../../../config/config";
|
|
2
|
-
import { Block } from "../../block/block";
|
|
3
|
-
declare type AlertBlockPosition = 'top' | 'bottom' | 'right' | 'left';
|
|
4
|
-
export declare class RecordOverflowAlert {
|
|
5
|
-
private static readonly blockClass;
|
|
6
|
-
static render(block: Block, hidedRecordsAmount: number, position: AlertBlockPosition, chartOrientation?: ChartOrientation): void;
|
|
7
|
-
static update(block: Block, hidedRecordsAmount: number, position: AlertBlockPosition, chartOrientation?: ChartOrientation): void;
|
|
8
|
-
private static setAlertPosition;
|
|
9
|
-
private static getAlertText;
|
|
10
|
-
private static getWordTextEndingByAmount;
|
|
11
|
-
private static getBlockPositionAttrs;
|
|
12
|
-
private static getLeftAttrForRightBlock;
|
|
13
|
-
}
|
|
14
|
-
export {};
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { DomHelper } from '../../helpers/domHelper';
|
|
2
|
-
import { Legend } from '../legend/legend';
|
|
3
|
-
export class RecordOverflowAlert {
|
|
4
|
-
static render(block, hidedRecordsAmount, position, chartOrientation = null) {
|
|
5
|
-
const alertBlock = block.getWrapper()
|
|
6
|
-
.append('div')
|
|
7
|
-
.attr('class', this.blockClass)
|
|
8
|
-
.text(this.getAlertText(hidedRecordsAmount, chartOrientation));
|
|
9
|
-
const attrs = this.getBlockPositionAttrs(position, block);
|
|
10
|
-
this.setAlertPosition(alertBlock, attrs);
|
|
11
|
-
}
|
|
12
|
-
static update(block, hidedRecordsAmount, position, chartOrientation = null) {
|
|
13
|
-
let alertBlock = block.getWrapper()
|
|
14
|
-
.select(`div.${this.blockClass}`);
|
|
15
|
-
if (alertBlock.empty()) {
|
|
16
|
-
if (hidedRecordsAmount === 0)
|
|
17
|
-
return;
|
|
18
|
-
else
|
|
19
|
-
this.render(block, hidedRecordsAmount, position, chartOrientation);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
if (hidedRecordsAmount === 0)
|
|
23
|
-
alertBlock.remove();
|
|
24
|
-
else
|
|
25
|
-
alertBlock.text(this.getAlertText(hidedRecordsAmount, chartOrientation));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
static setAlertPosition(alertBlock, attrs) {
|
|
29
|
-
alertBlock
|
|
30
|
-
.style('position', 'absolute')
|
|
31
|
-
.style('left', attrs.left)
|
|
32
|
-
.style('right', attrs.right)
|
|
33
|
-
.style('top', attrs.top)
|
|
34
|
-
.style('bottom', attrs.bottom);
|
|
35
|
-
}
|
|
36
|
-
static getAlertText(hidedRecordsAmount, chartOrientation) {
|
|
37
|
-
return `+ ${hidedRecordsAmount} ${this.getWordTextEndingByAmount(hidedRecordsAmount, chartOrientation)}`;
|
|
38
|
-
}
|
|
39
|
-
static getWordTextEndingByAmount(hidedRecordsAmount, chartOrientation) {
|
|
40
|
-
const lastDigit = hidedRecordsAmount % 10;
|
|
41
|
-
if (chartOrientation === 'vertical') {
|
|
42
|
-
if (hidedRecordsAmount >= 10 && hidedRecordsAmount <= 20)
|
|
43
|
-
return 'столбцов';
|
|
44
|
-
if (lastDigit === 1)
|
|
45
|
-
return 'столбец';
|
|
46
|
-
if (lastDigit >= 2 && lastDigit <= 4)
|
|
47
|
-
return 'столбца';
|
|
48
|
-
return 'столбцов';
|
|
49
|
-
}
|
|
50
|
-
else if (chartOrientation === 'horizontal') {
|
|
51
|
-
if (hidedRecordsAmount >= 10 && hidedRecordsAmount <= 20)
|
|
52
|
-
return 'строк';
|
|
53
|
-
if (lastDigit === 1)
|
|
54
|
-
return 'строка';
|
|
55
|
-
if (lastDigit >= 2 && lastDigit <= 4)
|
|
56
|
-
return 'строки';
|
|
57
|
-
return 'строк';
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
if (hidedRecordsAmount >= 10 && hidedRecordsAmount <= 20)
|
|
61
|
-
return 'категорий';
|
|
62
|
-
if (lastDigit === 1)
|
|
63
|
-
return 'категория';
|
|
64
|
-
if (lastDigit >= 2 && lastDigit <= 4)
|
|
65
|
-
return 'категории';
|
|
66
|
-
return 'категорий';
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
static getBlockPositionAttrs(position, block) {
|
|
70
|
-
const attrs = {
|
|
71
|
-
bottom: null,
|
|
72
|
-
top: null,
|
|
73
|
-
right: null,
|
|
74
|
-
left: null
|
|
75
|
-
};
|
|
76
|
-
if (position === 'top') {
|
|
77
|
-
attrs.right = '17px';
|
|
78
|
-
attrs.top = '1rem';
|
|
79
|
-
}
|
|
80
|
-
if (position === 'right') {
|
|
81
|
-
attrs.bottom = '20px';
|
|
82
|
-
attrs.left = this.getLeftAttrForRightBlock(block) + 'px';
|
|
83
|
-
}
|
|
84
|
-
if (position === 'bottom') {
|
|
85
|
-
attrs.left = '20px';
|
|
86
|
-
attrs.bottom = '20px';
|
|
87
|
-
}
|
|
88
|
-
return attrs;
|
|
89
|
-
}
|
|
90
|
-
static getLeftAttrForRightBlock(block) {
|
|
91
|
-
const legendBlock = block.getSvg().select(`.${Legend.objectClass}`);
|
|
92
|
-
if (legendBlock.empty())
|
|
93
|
-
return null;
|
|
94
|
-
return DomHelper.getSelectionNumericAttr(legendBlock, 'x');
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
RecordOverflowAlert.blockClass = 'record-overflow-alert';
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { MdtChartsConfig, MdtChartsDataSource } from "../config/config";
|
|
2
|
-
import { DesignerConfig } from "../designer/designerConfig";
|
|
3
|
-
import { DataScope, LegendBlockModel } from "./model";
|
|
4
|
-
import { ModelInstance } from "./modelInstance/modelInstance";
|
|
5
|
-
export declare class DataManagerModel {
|
|
6
|
-
static getPreparedData(data: MdtChartsDataSource, allowableKeys: string[], config: MdtChartsConfig): MdtChartsDataSource;
|
|
7
|
-
static getDataScope(config: MdtChartsConfig, data: MdtChartsDataSource, designerConfig: DesignerConfig, legendBlock: LegendBlockModel, modelInstance: ModelInstance): DataScope;
|
|
8
|
-
static getDataValuesByKeyField(data: MdtChartsDataSource, dataSourceName: string, keyFieldName: string): string[];
|
|
9
|
-
private static getDataScopeFor2D;
|
|
10
|
-
private static getDataScopeForPolar;
|
|
11
|
-
/**
|
|
12
|
-
* Выводит количество элементов (преимущественно баров) в одной группе. Группа - один ключ
|
|
13
|
-
* @param configOptions
|
|
14
|
-
* @param chartsLength
|
|
15
|
-
*/
|
|
16
|
-
private static getElementsInGroupAmount;
|
|
17
|
-
private static getBarChartsInGroupAmount;
|
|
18
|
-
private static getScopedData;
|
|
19
|
-
private static getScopedChartData;
|
|
20
|
-
private static setDataType;
|
|
21
|
-
private static getTypedData;
|
|
22
|
-
private static getDataLimitByItemSize;
|
|
23
|
-
}
|
|
@@ -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
|
-
}
|