mdt-charts 1.9.11 → 1.10.3
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 +148 -0
- package/lib/config/config.js +1 -0
- package/lib/designer/designerConfig.d.ts +71 -0
- package/lib/designer/designerConfig.js +1 -0
- package/lib/engine/block/block.d.ts +35 -0
- package/lib/engine/block/block.js +110 -0
- package/lib/engine/block/blockHelper.d.ts +12 -0
- package/lib/engine/block/blockHelper.js +19 -0
- package/lib/engine/colorReader/colorReader.d.ts +10 -0
- package/lib/engine/colorReader/colorReader.js +21 -0
- package/lib/engine/contentManager.d.ts +9 -0
- package/lib/engine/contentManager.js +29 -0
- package/lib/engine/elementHighlighter/elementHighlighter.d.ts +30 -0
- package/lib/engine/elementHighlighter/elementHighlighter.js +198 -0
- package/lib/engine/elementHighlighter/selectHighlighter.d.ts +11 -0
- package/lib/engine/elementHighlighter/selectHighlighter.js +95 -0
- package/lib/engine/engine.d.ts +20 -0
- package/lib/engine/engine.js +64 -0
- package/lib/engine/features/aggregator/aggregator.d.ts +22 -0
- package/lib/engine/features/aggregator/aggregator.js +95 -0
- package/lib/engine/features/axis/axis.d.ts +12 -0
- package/lib/engine/features/axis/axis.js +118 -0
- package/lib/engine/features/axis/axisDomHelper.d.ts +7 -0
- package/lib/engine/features/axis/axisDomHelper.js +24 -0
- package/lib/engine/features/axis/axisHelper.d.ts +9 -0
- package/lib/engine/features/axis/axisHelper.js +53 -0
- package/lib/engine/features/axis/axisLabelDomHelper.d.ts +17 -0
- package/lib/engine/features/axis/axisLabelDomHelper.js +143 -0
- package/lib/engine/features/axis/axisLabelsEventManager.d.ts +6 -0
- package/lib/engine/features/axis/axisLabelsEventManager.js +36 -0
- package/lib/engine/features/embeddedLabels/embeddedLabels.d.ts +23 -0
- package/lib/engine/features/embeddedLabels/embeddedLabels.js +147 -0
- package/lib/engine/features/embeddedLabels/embeddedLabelsDomHelper.d.ts +8 -0
- package/lib/engine/features/embeddedLabels/embeddedLabelsDomHelper.js +30 -0
- package/lib/engine/features/embeddedLabels/embeddedLabelsHelper.d.ts +27 -0
- package/lib/engine/features/embeddedLabels/embeddedLabelsHelper.js +65 -0
- package/lib/engine/features/gridLine/gidLineHelper.d.ts +13 -0
- package/lib/engine/features/gridLine/gidLineHelper.js +30 -0
- package/lib/engine/features/gridLine/gridLine.d.ts +11 -0
- package/lib/engine/features/gridLine/gridLine.js +67 -0
- package/lib/engine/features/legend/legend.d.ts +22 -0
- package/lib/engine/features/legend/legend.js +112 -0
- package/lib/engine/features/legend/legendDomHelper.d.ts +8 -0
- package/lib/engine/features/legend/legendDomHelper.js +48 -0
- package/lib/engine/features/legend/legendEventsManager.d.ts +12 -0
- package/lib/engine/features/legend/legendEventsManager.js +47 -0
- package/lib/engine/features/legend/legendHelper.d.ts +21 -0
- package/lib/engine/features/legend/legendHelper.js +99 -0
- package/lib/engine/features/markDots/markDot.d.ts +20 -0
- package/lib/engine/features/markDots/markDot.js +68 -0
- package/lib/engine/features/markDots/markDotsHelper.d.ts +6 -0
- package/lib/engine/features/markDots/markDotsHelper.js +16 -0
- package/lib/engine/features/recordOverflowAlert/recordOverflowAlert.d.ts +14 -0
- package/lib/engine/features/recordOverflowAlert/recordOverflowAlert.js +97 -0
- package/lib/engine/features/scale/scale.d.ts +16 -0
- package/lib/engine/features/scale/scale.js +74 -0
- package/lib/engine/features/tipBox/tipBox.d.ts +11 -0
- package/lib/engine/features/tipBox/tipBox.js +32 -0
- package/lib/engine/features/tipBox/tipBoxHelper.d.ts +16 -0
- package/lib/engine/features/tipBox/tipBoxHelper.js +48 -0
- package/lib/engine/features/title/title.d.ts +9 -0
- package/lib/engine/features/title/title.js +35 -0
- package/lib/engine/features/tolltip/newTooltip/newTooltip.d.ts +16 -0
- package/lib/engine/features/tolltip/newTooltip/newTooltip.js +26 -0
- package/lib/engine/features/tolltip/newTooltip/newTooltip.test.d.ts +1 -0
- package/lib/engine/features/tolltip/newTooltip/newTooltip.test.js +186 -0
- package/lib/engine/features/tolltip/newTooltip/newTooltipService.d.ts +17 -0
- package/lib/engine/features/tolltip/newTooltip/newTooltipService.js +26 -0
- package/lib/engine/features/tolltip/tooltip.d.ts +19 -0
- package/lib/engine/features/tolltip/tooltip.js +181 -0
- package/lib/engine/features/tolltip/tooltipComponentsManager.d.ts +17 -0
- package/lib/engine/features/tolltip/tooltipComponentsManager.js +125 -0
- package/lib/engine/features/tolltip/tooltipDomHelper.d.ts +30 -0
- package/lib/engine/features/tolltip/tooltipDomHelper.js +103 -0
- package/lib/engine/features/tolltip/tooltipHelper.d.ts +18 -0
- package/lib/engine/features/tolltip/tooltipHelper.js +93 -0
- package/lib/engine/filterManager/filterEventManager.d.ts +33 -0
- package/lib/engine/filterManager/filterEventManager.js +127 -0
- package/lib/engine/helpers/domHelper.d.ts +30 -0
- package/lib/engine/helpers/domHelper.js +68 -0
- package/lib/engine/helpers/helper.d.ts +30 -0
- package/lib/engine/helpers/helper.js +89 -0
- package/lib/engine/helpers/namesHelper.d.ts +5 -0
- package/lib/engine/helpers/namesHelper.js +9 -0
- package/lib/engine/intervalNotation/gantt.d.ts +10 -0
- package/lib/engine/intervalNotation/gantt.js +62 -0
- package/lib/engine/intervalNotation/intervalManager.d.ts +7 -0
- package/lib/engine/intervalNotation/intervalManager.js +30 -0
- package/lib/engine/polarNotation/donut/DonutHelper.d.ts +15 -0
- package/lib/engine/polarNotation/donut/DonutHelper.js +60 -0
- package/lib/engine/polarNotation/donut/donut.d.ts +32 -0
- package/lib/engine/polarNotation/donut/donut.js +125 -0
- package/lib/engine/polarNotation/polarManager.d.ts +10 -0
- package/lib/engine/polarNotation/polarManager.js +55 -0
- package/lib/engine/transitionManager.d.ts +19 -0
- package/lib/engine/transitionManager.js +64 -0
- package/lib/engine/twoDimensionalNotation/area/area.d.ts +17 -0
- package/lib/engine/twoDimensionalNotation/area/area.js +131 -0
- package/lib/engine/twoDimensionalNotation/area/areaHelper.d.ts +9 -0
- package/lib/engine/twoDimensionalNotation/area/areaHelper.js +40 -0
- package/lib/engine/twoDimensionalNotation/bar/bar.d.ts +34 -0
- package/lib/engine/twoDimensionalNotation/bar/bar.js +216 -0
- package/lib/engine/twoDimensionalNotation/bar/barHelper.d.ts +24 -0
- package/lib/engine/twoDimensionalNotation/bar/barHelper.js +103 -0
- package/lib/engine/twoDimensionalNotation/line/line.d.ts +17 -0
- package/lib/engine/twoDimensionalNotation/line/line.js +132 -0
- package/lib/engine/twoDimensionalNotation/line/lineHelper.d.ts +8 -0
- package/lib/engine/twoDimensionalNotation/line/lineHelper.js +28 -0
- package/lib/engine/twoDimensionalNotation/twoDimensionalManager.d.ts +11 -0
- package/lib/engine/twoDimensionalNotation/twoDimensionalManager.js +101 -0
- package/lib/engine/valueFormatter.d.ts +6 -0
- package/lib/engine/valueFormatter.js +8 -0
- package/lib/main.d.ts +79 -0
- package/lib/main.js +88 -0
- package/lib/model/chartStyleModel.d.ts +16 -0
- package/lib/model/chartStyleModel.js +67 -0
- package/lib/model/configsValidator/configValidator.d.ts +5 -0
- package/lib/model/configsValidator/configValidator.js +7 -0
- package/lib/model/dataManagerModel.d.ts +22 -0
- package/lib/model/dataManagerModel.js +137 -0
- package/lib/model/featuresModel/axisModel.d.ts +18 -0
- package/lib/model/featuresModel/axisModel.js +111 -0
- package/lib/model/featuresModel/legendModel/legendCanvasModel.d.ts +7 -0
- package/lib/model/featuresModel/legendModel/legendCanvasModel.js +86 -0
- package/lib/model/featuresModel/legendModel/legendModel.d.ts +13 -0
- package/lib/model/featuresModel/legendModel/legendModel.js +78 -0
- package/lib/model/featuresModel/otherComponents.d.ts +6 -0
- package/lib/model/featuresModel/otherComponents.js +12 -0
- package/lib/model/featuresModel/scaleModel.d.ts +17 -0
- package/lib/model/featuresModel/scaleModel.js +100 -0
- package/lib/model/featuresModel/titleModel.d.ts +4 -0
- package/lib/model/featuresModel/titleModel.js +14 -0
- package/lib/model/featuresModel/tooltipModel.d.ts +4 -0
- package/lib/model/featuresModel/tooltipModel.js +7 -0
- package/lib/model/marginModel.d.ts +19 -0
- package/lib/model/marginModel.js +126 -0
- package/lib/model/model.d.ts +221 -0
- package/lib/model/model.js +1 -0
- package/lib/model/modelBuilder.d.ts +16 -0
- package/lib/model/modelBuilder.js +128 -0
- package/lib/model/modelHelper.d.ts +7 -0
- package/lib/model/modelHelper.js +41 -0
- package/lib/model/notations/intervalModel.d.ts +8 -0
- package/lib/model/notations/intervalModel.js +93 -0
- package/lib/model/notations/polarModel.d.ts +7 -0
- package/lib/model/notations/polarModel.js +27 -0
- package/lib/model/notations/twoDimensionalModel.d.ts +19 -0
- package/lib/model/notations/twoDimensionalModel.js +85 -0
- package/lib/optionsServices/publicOptionsService.d.ts +6 -0
- package/lib/optionsServices/publicOptionsService.js +8 -0
- package/lib/optionsServices/validators/sizeValidator.d.ts +5 -0
- package/lib/optionsServices/validators/sizeValidator.js +13 -0
- package/lib/style/charts-main.css +243 -0
- package/lib/style/charts-main.less +243 -0
- package/package.json +1 -1
- package/dist/index.html +0 -363
- package/dist/listeners.89e1e272264c0e680de8.js +0 -278
- package/dist/main.f8b6bc6fee33cef1116c.js +0 -228
- package/dist/src_engine_engine_ts.ccee2a280374e0083541.js +0 -759
- package/dist/vendors-node_modules_chroma-js_chroma_js-node_modules_d3-array_src_max_js-node_modules_d3-arr-c3fc24.b32acc465b8557229277.js +0 -1869
package/lib/main.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { MdtChartsConfig, MdtChartsDataSource, NewSize, Size } from "./config/config";
|
|
2
|
+
import { DesignerConfig } from "./designer/designerConfig";
|
|
3
|
+
import { FilterCallback } from "./engine/filterManager/filterEventManager";
|
|
4
|
+
export interface IChart {
|
|
5
|
+
/**
|
|
6
|
+
* Рендер графика
|
|
7
|
+
* @param parentElement родительский элемент для графика
|
|
8
|
+
*/
|
|
9
|
+
render(parentElement: HTMLElement): void;
|
|
10
|
+
/**
|
|
11
|
+
* Удаление графика со страницы
|
|
12
|
+
*/
|
|
13
|
+
destroy(): void;
|
|
14
|
+
/**
|
|
15
|
+
* Обновление графика для новых данных
|
|
16
|
+
* @param data Новые данные
|
|
17
|
+
*/
|
|
18
|
+
updateData(data: MdtChartsDataSource): void;
|
|
19
|
+
/**
|
|
20
|
+
* Изменение размера блока с графиком
|
|
21
|
+
* @param newSize Новый размер
|
|
22
|
+
*/
|
|
23
|
+
updateSize(newSize: Size): void;
|
|
24
|
+
/**
|
|
25
|
+
* Обновление цветов графиков на основе новых базовых цветов
|
|
26
|
+
* @param newColors Новые базовые цвета
|
|
27
|
+
*/
|
|
28
|
+
updateColors(newColors: string[]): void;
|
|
29
|
+
}
|
|
30
|
+
export declare class Chart implements IChart {
|
|
31
|
+
static chartCounter: number;
|
|
32
|
+
private config;
|
|
33
|
+
private designerConfig;
|
|
34
|
+
private model;
|
|
35
|
+
private data;
|
|
36
|
+
private parentElement;
|
|
37
|
+
private isResizable;
|
|
38
|
+
private engine;
|
|
39
|
+
private resizeHandler;
|
|
40
|
+
/**
|
|
41
|
+
* @param config Объект конфигуратора
|
|
42
|
+
* @param designerConfig Объект конфигуратора дизайнера
|
|
43
|
+
* @param data Данные
|
|
44
|
+
* @param isResizable Флаг подстройки размера блока графика под родительский элемент
|
|
45
|
+
* @param filterCallback Функция коллбэк, вызываемая во время клика на элемент графика. Предназначена для обеспечения кросс-фильтрации
|
|
46
|
+
* @param selectedIds Id выделенных записей
|
|
47
|
+
*/
|
|
48
|
+
constructor(config: MdtChartsConfig, designerConfig: DesignerConfig, data: MdtChartsDataSource, isResizable?: boolean, filterCallback?: FilterCallback, selectedIds?: number[]);
|
|
49
|
+
/**
|
|
50
|
+
* Рендер графика
|
|
51
|
+
* @param parentElement родительский элемент для графика
|
|
52
|
+
*/
|
|
53
|
+
render(parentElement: HTMLElement): void;
|
|
54
|
+
/**
|
|
55
|
+
* Удаление графика со страницы
|
|
56
|
+
*/
|
|
57
|
+
destroy(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Обновление графика для новых данных
|
|
60
|
+
* @param data Новые данные
|
|
61
|
+
*/
|
|
62
|
+
updateData(data: MdtChartsDataSource): void;
|
|
63
|
+
/**
|
|
64
|
+
* Изменение размера блока с графиком
|
|
65
|
+
* @param newSize Новый размер
|
|
66
|
+
*/
|
|
67
|
+
updateSize(newSize: Partial<NewSize>): void;
|
|
68
|
+
/**
|
|
69
|
+
* Обновление цветов графиков на основе новых базовых цветов
|
|
70
|
+
* @param newColors Новые базовые цвета
|
|
71
|
+
*/
|
|
72
|
+
updateColors(newColors: string[]): void;
|
|
73
|
+
private registerResizeEvent;
|
|
74
|
+
private removeResizeEvent;
|
|
75
|
+
private resizeListener;
|
|
76
|
+
}
|
|
77
|
+
export * from "./config/config";
|
|
78
|
+
export * from "./designer/designerConfig";
|
|
79
|
+
export { FilterCallback } from "./engine/filterManager/filterEventManager";
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import Engine from "./engine/engine";
|
|
2
|
+
import { assembleModel, getPreparedData } from "./model/modelBuilder";
|
|
3
|
+
import { PublicOptionsService } from "./optionsServices/publicOptionsService";
|
|
4
|
+
export class Chart {
|
|
5
|
+
/**
|
|
6
|
+
* @param config Объект конфигуратора
|
|
7
|
+
* @param designerConfig Объект конфигуратора дизайнера
|
|
8
|
+
* @param data Данные
|
|
9
|
+
* @param isResizable Флаг подстройки размера блока графика под родительский элемент
|
|
10
|
+
* @param filterCallback Функция коллбэк, вызываемая во время клика на элемент графика. Предназначена для обеспечения кросс-фильтрации
|
|
11
|
+
* @param selectedIds Id выделенных записей
|
|
12
|
+
*/
|
|
13
|
+
constructor(config, designerConfig, data, isResizable = false, filterCallback = null, selectedIds = []) {
|
|
14
|
+
this.resizeHandler = this.resizeListener.bind(this);
|
|
15
|
+
Chart.chartCounter++;
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.designerConfig = designerConfig;
|
|
18
|
+
this.data = data;
|
|
19
|
+
this.isResizable = isResizable;
|
|
20
|
+
this.model = assembleModel(this.config, this.data, this.designerConfig);
|
|
21
|
+
this.engine = new Engine(Chart.chartCounter, filterCallback, selectedIds);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Рендер графика
|
|
25
|
+
* @param parentElement родительский элемент для графика
|
|
26
|
+
*/
|
|
27
|
+
render(parentElement) {
|
|
28
|
+
this.parentElement = parentElement;
|
|
29
|
+
this.engine.render(this.model, getPreparedData(this.model, this.data, this.config), this.parentElement);
|
|
30
|
+
if (this.isResizable)
|
|
31
|
+
this.registerResizeEvent();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Удаление графика со страницы
|
|
35
|
+
*/
|
|
36
|
+
destroy() {
|
|
37
|
+
this.engine.destroy();
|
|
38
|
+
if (this.isResizable)
|
|
39
|
+
this.removeResizeEvent();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Обновление графика для новых данных
|
|
43
|
+
* @param data Новые данные
|
|
44
|
+
*/
|
|
45
|
+
updateData(data) {
|
|
46
|
+
this.model = assembleModel(this.config, data, this.designerConfig);
|
|
47
|
+
this.data = data;
|
|
48
|
+
this.engine.updateData(this.model, getPreparedData(this.model, this.data, this.config));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Изменение размера блока с графиком
|
|
52
|
+
* @param newSize Новый размер
|
|
53
|
+
*/
|
|
54
|
+
updateSize(newSize) {
|
|
55
|
+
if (!PublicOptionsService.validateSize(newSize))
|
|
56
|
+
return;
|
|
57
|
+
if (newSize.height)
|
|
58
|
+
this.config.canvas.size.height = newSize.height;
|
|
59
|
+
if (newSize.width)
|
|
60
|
+
this.config.canvas.size.width = newSize.width;
|
|
61
|
+
this.model = assembleModel(this.config, this.data, this.designerConfig);
|
|
62
|
+
this.engine.updateFullBlock(this.model, getPreparedData(this.model, this.data, this.config));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Обновление цветов графиков на основе новых базовых цветов
|
|
66
|
+
* @param newColors Новые базовые цвета
|
|
67
|
+
*/
|
|
68
|
+
updateColors(newColors) {
|
|
69
|
+
this.designerConfig.chartStyle.baseColors = [...newColors];
|
|
70
|
+
this.model = assembleModel(this.config, this.data, this.designerConfig);
|
|
71
|
+
this.engine.updateColors(this.model);
|
|
72
|
+
}
|
|
73
|
+
registerResizeEvent() {
|
|
74
|
+
window.addEventListener('resize', this.resizeHandler);
|
|
75
|
+
}
|
|
76
|
+
removeResizeEvent() {
|
|
77
|
+
window.removeEventListener('resize', this.resizeHandler);
|
|
78
|
+
}
|
|
79
|
+
resizeListener() {
|
|
80
|
+
this.updateSize({
|
|
81
|
+
height: null,
|
|
82
|
+
width: this.parentElement.offsetWidth
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
Chart.chartCounter = 0;
|
|
87
|
+
export * from "./config/config";
|
|
88
|
+
export * from "./designer/designerConfig";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TwoDimensionalChartType } from "../config/config";
|
|
2
|
+
import { ChartStyleConfig } from "../designer/designerConfig";
|
|
3
|
+
import { ChartStyle } from "./model";
|
|
4
|
+
export declare class ChartStyleModel {
|
|
5
|
+
private static safeColorsAmount;
|
|
6
|
+
private static standartColors;
|
|
7
|
+
static getCssClasses(chartIndex: number): string[];
|
|
8
|
+
static get2DChartStyle(chartsAmount: number, chartType: TwoDimensionalChartType, chartsFieldsAmounts: number[], chartIndex: number, isSegmented: boolean, styleConfig: ChartStyleConfig): ChartStyle;
|
|
9
|
+
static getChartStyle(elementsAmount: number, styleConfig: ChartStyleConfig): ChartStyle;
|
|
10
|
+
private static getChartColors;
|
|
11
|
+
private static getChartOpacity;
|
|
12
|
+
private static getColorSet;
|
|
13
|
+
private static checkAndGet;
|
|
14
|
+
private static getStartIndex;
|
|
15
|
+
private static resetColor;
|
|
16
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as chroma from "chroma-js";
|
|
2
|
+
import { ModelHelper } from "./modelHelper";
|
|
3
|
+
export class ChartStyleModel {
|
|
4
|
+
static getCssClasses(chartIndex) {
|
|
5
|
+
const cssClasses = [`chart-${chartIndex}`];
|
|
6
|
+
return cssClasses;
|
|
7
|
+
}
|
|
8
|
+
static get2DChartStyle(chartsAmount, chartType, chartsFieldsAmounts, chartIndex, isSegmented, styleConfig) {
|
|
9
|
+
const startIndex = this.getStartIndex(chartIndex, chartsFieldsAmounts);
|
|
10
|
+
const baseColors = this.checkAndGet(styleConfig.baseColors);
|
|
11
|
+
const palette = this.getColorSet(baseColors, ModelHelper.getSum(chartsFieldsAmounts));
|
|
12
|
+
return {
|
|
13
|
+
elementColors: this.getChartColors(palette, chartsFieldsAmounts[chartIndex], startIndex, chartType),
|
|
14
|
+
opacity: this.getChartOpacity(chartsAmount, chartType, chartsFieldsAmounts[chartIndex], isSegmented)
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
static getChartStyle(elementsAmount, styleConfig) {
|
|
18
|
+
const baseColors = this.checkAndGet(styleConfig.baseColors);
|
|
19
|
+
return {
|
|
20
|
+
elementColors: this.getColorSet(baseColors, elementsAmount),
|
|
21
|
+
opacity: 1
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
static getChartColors(palette, elementsAmount, startIndex, chartType) {
|
|
25
|
+
const selectedColors = palette.slice(startIndex, startIndex + elementsAmount);
|
|
26
|
+
if (chartType !== 'line')
|
|
27
|
+
return selectedColors;
|
|
28
|
+
for (let i = 0; i < selectedColors.length; i++) {
|
|
29
|
+
selectedColors[i] = chroma.mix(selectedColors[i], 'white', 0.2).saturate(3).hex();
|
|
30
|
+
}
|
|
31
|
+
return selectedColors;
|
|
32
|
+
}
|
|
33
|
+
static getChartOpacity(chartsLength, chartType, chartsValueFieldAmount, isSegmented) {
|
|
34
|
+
if (chartType === 'area' && (chartsLength > 1 || chartsValueFieldAmount > 1) && !isSegmented)
|
|
35
|
+
return 0.5; // combined area with other charts has 0.5 opacity
|
|
36
|
+
return 1;
|
|
37
|
+
}
|
|
38
|
+
static getColorSet(baseColors, elementsAmount) {
|
|
39
|
+
return chroma.scale(baseColors)
|
|
40
|
+
.mode('rgb')
|
|
41
|
+
.domain([0, 0.55, 0.75, 1])
|
|
42
|
+
.colors(elementsAmount <= 1 ? 2 : elementsAmount);
|
|
43
|
+
}
|
|
44
|
+
static checkAndGet(baseColors) {
|
|
45
|
+
if (baseColors.length === 0 || baseColors.filter(color => color === 'rgba(0, 0, 0, 0)' || !color).length > 0) {
|
|
46
|
+
return this.standartColors;
|
|
47
|
+
}
|
|
48
|
+
return baseColors;
|
|
49
|
+
}
|
|
50
|
+
static getStartIndex(chartIndex, chartsFieldsAmounts) {
|
|
51
|
+
let startIndex = 0;
|
|
52
|
+
for (let i = 0; i < chartIndex; i++) {
|
|
53
|
+
startIndex += chartsFieldsAmounts[i];
|
|
54
|
+
}
|
|
55
|
+
return startIndex;
|
|
56
|
+
}
|
|
57
|
+
static resetColor(index, baseColor) {
|
|
58
|
+
let color = chroma(baseColor)
|
|
59
|
+
.luminance(0.5)
|
|
60
|
+
.saturate(1.5 + Math.floor(index / this.safeColorsAmount) * 0.5);
|
|
61
|
+
color = chroma(color)
|
|
62
|
+
.set('hsv.h', chroma(color).get('hsv.h') + Math.floor(index / this.safeColorsAmount) * 4);
|
|
63
|
+
return color.hex();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
ChartStyleModel.safeColorsAmount = 8;
|
|
67
|
+
ChartStyleModel.standartColors = ["#209DE3", "#FF3131", "#FFBA00", "#20B078"];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export class ConfigValidatorClass {
|
|
2
|
+
validateCanvasSize(size) {
|
|
3
|
+
const validateSide = (side) => typeof side === "number" && side >= 0;
|
|
4
|
+
return validateSide(size.width) && validateSide(size.height);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export const ConfigValidator = new ConfigValidatorClass();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { MdtChartsConfig, MdtChartsDataSource } from "../config/config";
|
|
2
|
+
import { DesignerConfig } from "../designer/designerConfig";
|
|
3
|
+
import { BlockMargin, DataScope, LegendBlockModel } from "./model";
|
|
4
|
+
export declare class DataManagerModel {
|
|
5
|
+
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 getDataValuesByKeyField(data: MdtChartsDataSource, dataSourceName: string, keyFieldName: string): string[];
|
|
8
|
+
private static getDataScopeFor2D;
|
|
9
|
+
private static getDataScopeForPolar;
|
|
10
|
+
/**
|
|
11
|
+
* Выводит количество элементов (преимущественно баров) в одной группе. Группа - один ключ
|
|
12
|
+
* @param configOptions
|
|
13
|
+
* @param chartsLength
|
|
14
|
+
*/
|
|
15
|
+
private static getElementsInGroupAmount;
|
|
16
|
+
private static getBarChartsInGroupAmount;
|
|
17
|
+
private static getScopedData;
|
|
18
|
+
private static getScopedChartData;
|
|
19
|
+
private static setDataType;
|
|
20
|
+
private static getTypedData;
|
|
21
|
+
private static getDataLimitByItemSize;
|
|
22
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
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, margin, data, designerConfig, legendBlock) {
|
|
12
|
+
if (config.options.type === '2d' || config.options.type === 'interval') {
|
|
13
|
+
return this.getDataScopeFor2D(config.options, config.canvas.size, margin, data, designerConfig);
|
|
14
|
+
}
|
|
15
|
+
else if (config.options.type === 'polar') {
|
|
16
|
+
return this.getDataScopeForPolar(config.options, config.canvas.size, margin, 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, blockSize, margin, 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, margin, blockSize);
|
|
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, blockSize, margin, data, legendBlock, legendCanvas) {
|
|
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
|
+
return {
|
|
53
|
+
allowableKeys: keys,
|
|
54
|
+
hidedRecordsAmount: 0
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
let position;
|
|
58
|
+
if (blockSize.width - margin.left - margin.right >= MIN_DONUT_BLOCK_SIZE)
|
|
59
|
+
position = 'right';
|
|
60
|
+
else
|
|
61
|
+
position = 'bottom';
|
|
62
|
+
let maxItemsNumber;
|
|
63
|
+
if (position === 'right') {
|
|
64
|
+
maxItemsNumber = LegendCanvasModel.findElementsAmountByLegendSize(keys, position, legendCanvas.maxWidth, blockSize.height - margin.top - margin.bottom);
|
|
65
|
+
}
|
|
66
|
+
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);
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
allowableKeys: keys.slice(0, maxItemsNumber),
|
|
72
|
+
hidedRecordsAmount: keys.length - maxItemsNumber
|
|
73
|
+
};
|
|
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 === 'polar' || config.options.type === '2d') {
|
|
105
|
+
// Форматиривание для оси ключей пока не совсем верно установлено
|
|
106
|
+
// if(config.options.data.keyField.format === 'date') {
|
|
107
|
+
// data[config.options.data.dataSource] = this.getTypedData(data[config.options.data.dataSource], config.options.data.keyField);
|
|
108
|
+
// }
|
|
109
|
+
}
|
|
110
|
+
else if (config.options.type === 'interval') {
|
|
111
|
+
const chart = config.options.chart;
|
|
112
|
+
if (chart.data.valueField1.format === 'date') {
|
|
113
|
+
data[config.options.data.dataSource] = this.getTypedData(data[config.options.data.dataSource], chart.data.valueField1);
|
|
114
|
+
}
|
|
115
|
+
if (chart.data.valueField2.format === 'date') {
|
|
116
|
+
data[config.options.data.dataSource] = this.getTypedData(data[config.options.data.dataSource], chart.data.valueField2);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
static getTypedData(data, field) {
|
|
121
|
+
if (field.format === 'date')
|
|
122
|
+
data.forEach(d => {
|
|
123
|
+
d[field.name] = new Date(d[field.name]);
|
|
124
|
+
});
|
|
125
|
+
return data;
|
|
126
|
+
}
|
|
127
|
+
static getDataLimitByItemSize(elementsInGroupAmount, dataLength, axisLength, barOptions) {
|
|
128
|
+
let sumSize = dataLength * (elementsInGroupAmount * barOptions.minBarWidth + (elementsInGroupAmount - 1) * barOptions.barDistance + barOptions.groupMinDistance);
|
|
129
|
+
while (dataLength !== 0 && axisLength < sumSize) {
|
|
130
|
+
dataLength--;
|
|
131
|
+
// find whole space for bars in group + distance between bars + group distance
|
|
132
|
+
sumSize = dataLength * (elementsInGroupAmount * barOptions.minBarWidth + (elementsInGroupAmount - 1)
|
|
133
|
+
* barOptions.barDistance + barOptions.groupMinDistance);
|
|
134
|
+
}
|
|
135
|
+
return dataLength;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AxisPosition, ChartOrientation, DataOptions, MdtChartsDataSource, DiscreteAxisOptions, NumberAxisOptions, Size, TwoDimensionalChart } from "../../config/config";
|
|
2
|
+
import { AxisLabelPosition, AxisModelOptions, BlockMargin, Orient } from "../model";
|
|
3
|
+
import { AxisType } from "../modelBuilder";
|
|
4
|
+
import { AxisLabelCanvas, TooltipSettings } from "../../designer/designerConfig";
|
|
5
|
+
export interface LabelSize {
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
}
|
|
9
|
+
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;
|
|
13
|
+
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;
|
|
17
|
+
static getLabelSize(labelMaxWidth: number, labelTexts: any[]): LabelSize;
|
|
18
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ModelHelper } from "../modelHelper";
|
|
2
|
+
import { AxisType, CLASSES } from "../modelBuilder";
|
|
3
|
+
import { DataManagerModel } from "../dataManagerModel";
|
|
4
|
+
import { TwoDimensionalModel } from "../notations/twoDimensionalModel";
|
|
5
|
+
export class AxisModel {
|
|
6
|
+
static getKeyAxis(charts, data, dataOptions, orient, axisConfig, labelConfig, margin, blockSize, tooltipSettings) {
|
|
7
|
+
return {
|
|
8
|
+
type: 'key',
|
|
9
|
+
orient: AxisModel.getAxisOrient(AxisType.Key, orient, axisConfig.position),
|
|
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)
|
|
13
|
+
},
|
|
14
|
+
cssClass: 'key-axis',
|
|
15
|
+
ticks: axisConfig.ticks,
|
|
16
|
+
labels: {
|
|
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),
|
|
19
|
+
visible: !TwoDimensionalModel.getChartsEmbeddedLabelsFlag(charts, orient),
|
|
20
|
+
defaultTooltip: tooltipSettings.position === 'fixed'
|
|
21
|
+
},
|
|
22
|
+
visibility: axisConfig.visibility
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
static getValueAxis(orient, axisConfig, labelConfig, margin, blockSize) {
|
|
26
|
+
return {
|
|
27
|
+
type: 'value',
|
|
28
|
+
orient: AxisModel.getAxisOrient(AxisType.Value, orient, axisConfig.position),
|
|
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)
|
|
32
|
+
},
|
|
33
|
+
cssClass: 'value-axis',
|
|
34
|
+
ticks: axisConfig.ticks,
|
|
35
|
+
labels: {
|
|
36
|
+
maxSize: labelConfig.maxSize.main,
|
|
37
|
+
position: 'straight',
|
|
38
|
+
visible: true,
|
|
39
|
+
defaultTooltip: true
|
|
40
|
+
},
|
|
41
|
+
visibility: axisConfig.visibility
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
static getAxisLength(chartOrientation, margin, blockSize) {
|
|
45
|
+
if (chartOrientation === 'horizontal') {
|
|
46
|
+
return blockSize.height - margin.top - margin.bottom;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return blockSize.width - margin.left - margin.right;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
static getAxisOrient(axisType, chartOrientation, axisPosition) {
|
|
53
|
+
if (chartOrientation === 'vertical') {
|
|
54
|
+
if (axisPosition === 'start')
|
|
55
|
+
return axisType === AxisType.Key ? 'top' : 'left';
|
|
56
|
+
return axisType === AxisType.Key ? 'bottom' : 'right';
|
|
57
|
+
}
|
|
58
|
+
if (axisPosition === 'start')
|
|
59
|
+
return axisType === AxisType.Key ? 'left' : 'top';
|
|
60
|
+
return axisType === AxisType.Key ? 'right' : 'bottom';
|
|
61
|
+
}
|
|
62
|
+
static getAxisTranslateX(axisType, chartOrientation, axisPosition, margin, blockWidth) {
|
|
63
|
+
const orient = AxisModel.getAxisOrient(axisType, chartOrientation, axisPosition);
|
|
64
|
+
if (orient === 'top' || orient === 'left')
|
|
65
|
+
return margin.left;
|
|
66
|
+
else if (orient === 'bottom')
|
|
67
|
+
return margin.left;
|
|
68
|
+
return blockWidth - margin.right;
|
|
69
|
+
}
|
|
70
|
+
static getAxisTranslateY(axisType, chartOrientation, axisPosition, margin, blockHeight) {
|
|
71
|
+
const orient = AxisModel.getAxisOrient(axisType, chartOrientation, axisPosition);
|
|
72
|
+
if (orient === 'top' || orient === 'left')
|
|
73
|
+
return margin.top;
|
|
74
|
+
else if (orient === 'bottom')
|
|
75
|
+
return blockHeight - margin.bottom;
|
|
76
|
+
return margin.top;
|
|
77
|
+
}
|
|
78
|
+
static getKeyAxisLabelPosition(margin, blockSize, scopedDataLength) {
|
|
79
|
+
const minBandSize = 50;
|
|
80
|
+
if ((blockSize.width - margin.left - margin.right) / scopedDataLength < minBandSize)
|
|
81
|
+
return 'rotated';
|
|
82
|
+
return 'straight';
|
|
83
|
+
}
|
|
84
|
+
static getLabelSize(labelMaxWidth, labelTexts) {
|
|
85
|
+
const labelSize = {
|
|
86
|
+
width: 0,
|
|
87
|
+
height: 0
|
|
88
|
+
};
|
|
89
|
+
const textBlock = document.createElement('span');
|
|
90
|
+
textBlock.style.opacity = '0';
|
|
91
|
+
textBlock.style.position = 'absolute';
|
|
92
|
+
textBlock.style.whiteSpace = 'nowrap';
|
|
93
|
+
textBlock.classList.add(CLASSES.dataLabel);
|
|
94
|
+
let maxLabel = '';
|
|
95
|
+
let biggestScore = 0;
|
|
96
|
+
let maxWidth = 0;
|
|
97
|
+
labelTexts.forEach((text) => {
|
|
98
|
+
if (ModelHelper.getStringScore(text) > biggestScore) {
|
|
99
|
+
maxLabel = text;
|
|
100
|
+
biggestScore = ModelHelper.getStringScore(text);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
textBlock.textContent = maxLabel === '0000' ? maxLabel : maxLabel + 'D';
|
|
104
|
+
document.body.append(textBlock);
|
|
105
|
+
maxWidth = Math.ceil(textBlock.getBoundingClientRect().width);
|
|
106
|
+
labelSize.height = textBlock.getBoundingClientRect().height;
|
|
107
|
+
labelSize.width = maxWidth > labelMaxWidth ? labelMaxWidth : maxWidth;
|
|
108
|
+
textBlock.remove();
|
|
109
|
+
return labelSize;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LegendPosition } from "../../model";
|
|
2
|
+
export declare type LegendItemsDirection = 'row' | 'column';
|
|
3
|
+
export declare class LegendCanvasModel {
|
|
4
|
+
static getLegendHeight(texts: string[], blockWidth: number, marginLeft: number, marginRight: number, itemsPosition: LegendItemsDirection, legendPosition: LegendPosition): number;
|
|
5
|
+
static getLegendItemWidth(text: string): number;
|
|
6
|
+
static findElementsAmountByLegendSize(texts: string[], position: LegendPosition, legendBlockWidth: number, legendBlockHeight: number): number;
|
|
7
|
+
}
|