mdt-charts 1.10.1 → 1.11.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 +12 -5
- package/lib/designer/designerConfig.d.ts +8 -2
- package/lib/engine/features/aggregator/aggregator.d.ts +4 -3
- package/lib/engine/features/aggregator/aggregator.js +14 -11
- package/lib/engine/features/title/title.js +2 -0
- package/lib/engine/features/tolltip/tooltip.js +1 -1
- package/lib/engine/filterManager/filterEventManager.d.ts +3 -3
- package/lib/engine/filterManager/filterEventManager.js +4 -4
- package/lib/engine/intervalNotation/intervalManager.js +2 -2
- package/lib/engine/polarNotation/donut/DonutHelper.d.ts +2 -0
- package/lib/engine/polarNotation/donut/DonutHelper.js +20 -3
- package/lib/engine/polarNotation/donut/donut.js +1 -1
- package/lib/engine/polarNotation/polarManager.js +6 -7
- package/lib/engine/twoDimensionalNotation/twoDimensionalManager.js +4 -4
- package/lib/model/chartStyleModel/TwoDimensionalChartStyleModel.d.ts +19 -0
- package/lib/model/chartStyleModel/TwoDimensionalChartStyleModel.js +61 -0
- package/lib/model/chartStyleModel/chartStyleModel.d.ts +9 -0
- package/lib/model/chartStyleModel/chartStyleModel.js +27 -0
- package/lib/model/dataManagerModel.d.ts +3 -2
- package/lib/model/dataManagerModel.js +12 -10
- package/lib/model/featuresModel/axisModel.d.ts +9 -8
- package/lib/model/featuresModel/axisModel.js +20 -20
- package/lib/model/featuresModel/legendModel/legendModel.d.ts +4 -3
- package/lib/model/featuresModel/legendModel/legendModel.js +5 -7
- package/lib/model/featuresModel/otherComponents.d.ts +9 -2
- package/lib/model/featuresModel/otherComponents.js +6 -4
- package/lib/model/featuresModel/scaleModel.d.ts +7 -6
- package/lib/model/featuresModel/scaleModel.js +9 -9
- package/lib/model/featuresModel/titleModel.d.ts +1 -1
- package/lib/model/featuresModel/titleModel.js +7 -5
- package/lib/model/marginModel.d.ts +5 -5
- package/lib/model/marginModel.js +37 -35
- package/lib/model/model.d.ts +24 -18
- package/lib/model/modelBuilder.js +23 -34
- package/lib/model/modelInstance/canvasModel/canvasModel.d.ts +22 -0
- package/lib/model/modelInstance/canvasModel/canvasModel.js +42 -0
- package/lib/model/modelInstance/canvasModel/titleCanvas.d.ts +9 -0
- package/lib/model/modelInstance/canvasModel/titleCanvas.js +11 -0
- package/lib/model/modelInstance/modelInstance.d.ts +7 -0
- package/lib/model/modelInstance/modelInstance.js +11 -0
- package/lib/model/notations/intervalModel.d.ts +2 -1
- package/lib/model/notations/intervalModel.js +16 -13
- package/lib/model/notations/polarModel.d.ts +5 -3
- package/lib/model/notations/polarModel.js +17 -7
- package/lib/model/notations/twoDimensionalModel.d.ts +7 -5
- package/lib/model/notations/twoDimensionalModel.js +19 -11
- package/lib/style/charts-main.css +2 -0
- package/lib/style/charts-main.less +2 -0
- package/package.json +3 -2
- package/.vscode/settings.json +0 -7
- package/lib/model/chartStyleModel.d.ts +0 -16
- package/lib/model/chartStyleModel.js +0 -67
package/lib/config/config.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface MdtChartsDataSource {
|
|
|
16
16
|
}
|
|
17
17
|
export interface MdtChartsConfig {
|
|
18
18
|
canvas: ChartBlockCanvas;
|
|
19
|
-
options:
|
|
19
|
+
options: MdtChartsPolarOptions | MdtChartsTwoDimensionalOptions | IntervalOptions;
|
|
20
20
|
}
|
|
21
21
|
export interface ChartBlockCanvas {
|
|
22
22
|
size: Size;
|
|
@@ -33,18 +33,18 @@ export interface NewSize {
|
|
|
33
33
|
interface Options {
|
|
34
34
|
legend: Legend;
|
|
35
35
|
data: DataOptions;
|
|
36
|
-
title
|
|
36
|
+
title?: string;
|
|
37
37
|
selectable: boolean;
|
|
38
38
|
tooltip?: TooltipOptions;
|
|
39
39
|
}
|
|
40
|
-
export interface
|
|
40
|
+
export interface MdtChartsTwoDimensionalOptions extends Options {
|
|
41
41
|
type: '2d';
|
|
42
42
|
axis: TwoDimensionalAxis;
|
|
43
43
|
additionalElements: AdditionalElements;
|
|
44
44
|
charts: TwoDimensionalChart[];
|
|
45
45
|
orientation: ChartOrientation;
|
|
46
46
|
}
|
|
47
|
-
export interface
|
|
47
|
+
export interface MdtChartsPolarOptions extends Options {
|
|
48
48
|
type: 'polar';
|
|
49
49
|
chart: PolarChart;
|
|
50
50
|
}
|
|
@@ -69,6 +69,9 @@ export interface MdtChartsField {
|
|
|
69
69
|
export interface ValueField extends MdtChartsField {
|
|
70
70
|
title: string;
|
|
71
71
|
}
|
|
72
|
+
export interface TwoDimValueField extends ValueField {
|
|
73
|
+
color?: string;
|
|
74
|
+
}
|
|
72
75
|
export interface TooltipOptions {
|
|
73
76
|
html: TooltipHtml;
|
|
74
77
|
}
|
|
@@ -125,13 +128,14 @@ export interface TwoDimensionalChart extends ChartSettings {
|
|
|
125
128
|
export interface PolarChart extends ChartSettings {
|
|
126
129
|
type: PolarChartType;
|
|
127
130
|
data: PolarChartData;
|
|
131
|
+
aggregator: MdtChartsPolarChartAggregator;
|
|
128
132
|
}
|
|
129
133
|
export interface IntervalChart extends ChartSettings {
|
|
130
134
|
type: IntervalChartType;
|
|
131
135
|
data: IntervalChartData;
|
|
132
136
|
}
|
|
133
137
|
export interface TwoDimensionalChartData {
|
|
134
|
-
valueFields:
|
|
138
|
+
valueFields: TwoDimValueField[];
|
|
135
139
|
}
|
|
136
140
|
interface MarkersOptions {
|
|
137
141
|
show: boolean;
|
|
@@ -141,6 +145,9 @@ export interface PolarChartData {
|
|
|
141
145
|
valueField: ValueField;
|
|
142
146
|
colorField?: MdtChartsColorField;
|
|
143
147
|
}
|
|
148
|
+
export interface MdtChartsPolarChartAggregator {
|
|
149
|
+
text: string;
|
|
150
|
+
}
|
|
144
151
|
interface IntervalChartData {
|
|
145
152
|
valueField1: ValueField;
|
|
146
153
|
valueField2: ValueField;
|
|
@@ -4,6 +4,7 @@ export declare type DataTypeOptions = {
|
|
|
4
4
|
};
|
|
5
5
|
export declare type Formatter = (value: any, options?: any) => string;
|
|
6
6
|
export declare type TooltipPosition = 'followCursor' | 'fixed';
|
|
7
|
+
export declare type MdtChartsDonutThicknessUnit = "px" | "%";
|
|
7
8
|
export interface DesignerConfig {
|
|
8
9
|
canvas: Canvas;
|
|
9
10
|
dataFormat: DataFormat;
|
|
@@ -45,9 +46,14 @@ export interface BarOptionsCanvas {
|
|
|
45
46
|
}
|
|
46
47
|
export interface DonutOptionsCanvas {
|
|
47
48
|
padAngle: number;
|
|
48
|
-
minThickness: number;
|
|
49
|
-
maxThickness: number;
|
|
50
49
|
aggregatorPad: number;
|
|
50
|
+
thickness: MdtChartsDonutThicknessOptions;
|
|
51
|
+
}
|
|
52
|
+
export interface MdtChartsDonutThicknessOptions {
|
|
53
|
+
min: number;
|
|
54
|
+
max: number;
|
|
55
|
+
value: number;
|
|
56
|
+
unit: MdtChartsDonutThicknessUnit;
|
|
51
57
|
}
|
|
52
58
|
interface DataFormat {
|
|
53
59
|
formatters: Formatter;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { MdtChartsDataRow } from '../../../config/config';
|
|
2
2
|
import { DataType } from '../../../designer/designerConfig';
|
|
3
|
-
import { Field } from "../../../model/model";
|
|
3
|
+
import { DonutChartAggreagorModel, Field } from "../../../model/model";
|
|
4
4
|
import { Block } from "../../block/block";
|
|
5
5
|
import { Translate } from "../../polarNotation/donut/donut";
|
|
6
6
|
export interface AggregatorInfo {
|
|
7
7
|
name: string;
|
|
8
8
|
value: number;
|
|
9
9
|
format: DataType;
|
|
10
|
+
margin: number;
|
|
10
11
|
}
|
|
11
12
|
export declare class Aggregator {
|
|
12
13
|
static readonly aggregatorValueClass = "aggregator-value";
|
|
13
14
|
private static readonly aggregatorNameClass;
|
|
14
15
|
private static readonly aggregatorObjectClass;
|
|
15
|
-
static render(block: Block, data: MdtChartsDataRow[], valueField: Field, innerRadius: number, translate: Translate, fontSize: number,
|
|
16
|
-
static update(block: Block, data: MdtChartsDataRow[], valueField: Field,
|
|
16
|
+
static render(block: Block, data: MdtChartsDataRow[], valueField: Field, innerRadius: number, translate: Translate, fontSize: number, settings: DonutChartAggreagorModel): void;
|
|
17
|
+
static update(block: Block, data: MdtChartsDataRow[], valueField: Field, settings: DonutChartAggreagorModel): void;
|
|
17
18
|
private static renderText;
|
|
18
19
|
private static updateText;
|
|
19
20
|
private static reCalculateAggregatorFontSize;
|
|
@@ -3,23 +3,25 @@ import { interpolateNumber } from 'd3-interpolate';
|
|
|
3
3
|
import { Helper } from '../../helpers/helper';
|
|
4
4
|
import { ValueFormatter } from '../../valueFormatter';
|
|
5
5
|
export class Aggregator {
|
|
6
|
-
static render(block, data, valueField, innerRadius, translate, fontSize,
|
|
6
|
+
static render(block, data, valueField, innerRadius, translate, fontSize, settings) {
|
|
7
7
|
const aggregator = {
|
|
8
|
-
name:
|
|
8
|
+
name: settings.text,
|
|
9
9
|
value: sum(data.map(d => d[valueField.name])),
|
|
10
|
-
format: valueField.format
|
|
10
|
+
format: valueField.format,
|
|
11
|
+
margin: settings.margin
|
|
11
12
|
};
|
|
12
|
-
this.renderText(block, innerRadius, aggregator, translate, fontSize
|
|
13
|
+
this.renderText(block, innerRadius, aggregator, translate, fontSize);
|
|
13
14
|
}
|
|
14
|
-
static update(block, data, valueField,
|
|
15
|
+
static update(block, data, valueField, settings) {
|
|
15
16
|
const aggregator = {
|
|
16
17
|
name: 'Сумма',
|
|
17
18
|
value: sum(data.map(d => d[valueField.name])),
|
|
18
|
-
format: valueField.format
|
|
19
|
+
format: valueField.format,
|
|
20
|
+
margin: settings.margin
|
|
19
21
|
};
|
|
20
|
-
this.updateText(block, aggregator
|
|
22
|
+
this.updateText(block, aggregator);
|
|
21
23
|
}
|
|
22
|
-
static renderText(block, innerRadius, aggregatorInfo, translate, fontSize
|
|
24
|
+
static renderText(block, innerRadius, aggregatorInfo, translate, fontSize) {
|
|
23
25
|
if (innerRadius > 50) {
|
|
24
26
|
const aggregatorObject = this.renderAggregatorObject(block, innerRadius, translate);
|
|
25
27
|
const wrapper = this.renderWrapper(aggregatorObject);
|
|
@@ -32,13 +34,14 @@ export class Aggregator {
|
|
|
32
34
|
wrapper
|
|
33
35
|
.append('div')
|
|
34
36
|
.attr('class', this.aggregatorNameClass)
|
|
37
|
+
.attr('title', aggregatorInfo.name)
|
|
35
38
|
.style('text-align', 'center')
|
|
36
39
|
.style('font-size', '18px')
|
|
37
40
|
.text(aggregatorInfo.name);
|
|
38
|
-
this.reCalculateAggregatorFontSize(aggregatorObject.node().getBoundingClientRect().width, block,
|
|
41
|
+
this.reCalculateAggregatorFontSize(aggregatorObject.node().getBoundingClientRect().width, block, aggregatorInfo.margin);
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
|
-
static updateText(block, newAggregator
|
|
44
|
+
static updateText(block, newAggregator) {
|
|
42
45
|
const aggregatorObject = block.getSvg()
|
|
43
46
|
.select(`.${this.aggregatorObjectClass}`);
|
|
44
47
|
const thisClass = this;
|
|
@@ -53,7 +56,7 @@ export class Aggregator {
|
|
|
53
56
|
const interpolateFunc = interpolateNumber(oldValue, newAggregator.value);
|
|
54
57
|
return t => {
|
|
55
58
|
this.textContent = ValueFormatter.formatField(newAggregator.format, (interpolateFunc(t)).toFixed(precision));
|
|
56
|
-
thisClass.reCalculateAggregatorFontSize(aggregatorObject.node().getBoundingClientRect().width, block,
|
|
59
|
+
thisClass.reCalculateAggregatorFontSize(aggregatorObject.node().getBoundingClientRect().width, block, newAggregator.margin);
|
|
57
60
|
};
|
|
58
61
|
});
|
|
59
62
|
}
|
|
@@ -19,7 +19,7 @@ export class Tooltip {
|
|
|
19
19
|
this.renderTooltipFor2DCharts(block, data, model.blockCanvas.size, model.chartBlock.margin, scales, model.options, tooltipOptions);
|
|
20
20
|
}
|
|
21
21
|
else if (model.options.type === 'polar') {
|
|
22
|
-
this.renderTooltipForPolar(block, model.options, data, model.blockCanvas.size, model.chartBlock.margin, DonutHelper.getThickness(model.
|
|
22
|
+
this.renderTooltipForPolar(block, model.options, data, model.blockCanvas.size, model.chartBlock.margin, DonutHelper.getThickness(model.options.chartCanvas, model.blockCanvas.size, model.chartBlock.margin), model.otherComponents.tooltipBlock);
|
|
23
23
|
}
|
|
24
24
|
else if (model.options.type === 'interval') {
|
|
25
25
|
this.renderTooltipForIntervalCharts(block, data, model.blockCanvas.size, model.chartBlock.margin, scales, model.options, tooltipOptions);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AxisScale } from "d3-axis";
|
|
2
2
|
import { MdtChartsDataRow, Size } from "../../config/config";
|
|
3
|
-
import { BlockMargin, TwoDimensionalOptionsModel, PolarOptionsModel
|
|
3
|
+
import { BlockMargin, TwoDimensionalOptionsModel, PolarOptionsModel } from "../../model/model";
|
|
4
4
|
import { Block } from "../block/block";
|
|
5
5
|
export declare type FilterCallback = (rows: MdtChartsDataRow[]) => void;
|
|
6
6
|
export interface SelectDetails {
|
|
@@ -19,12 +19,12 @@ export declare class FilterEventManager {
|
|
|
19
19
|
updateData(newDataset: MdtChartsDataRow[]): void;
|
|
20
20
|
isSelected(keyValue: string): boolean;
|
|
21
21
|
clearKeysFor2D(options: TwoDimensionalOptionsModel): void;
|
|
22
|
-
clearKeysForPolar(margin: BlockMargin, blockSize: Size, options: PolarOptionsModel
|
|
22
|
+
clearKeysForPolar(margin: BlockMargin, blockSize: Size, options: PolarOptionsModel): void;
|
|
23
23
|
private setKey;
|
|
24
24
|
private addId;
|
|
25
25
|
private removeId;
|
|
26
26
|
private processKey;
|
|
27
|
-
setListenerPolar(margin: BlockMargin, blockSize: Size, options: PolarOptionsModel
|
|
27
|
+
setListenerPolar(margin: BlockMargin, blockSize: Size, options: PolarOptionsModel): void;
|
|
28
28
|
event2DUpdate(options: TwoDimensionalOptionsModel): void;
|
|
29
29
|
registerEventFor2D(scaleKey: AxisScale<any>, margin: BlockMargin, blockSize: Size, options: TwoDimensionalOptionsModel): void;
|
|
30
30
|
private registerEventToDonut;
|
|
@@ -29,11 +29,11 @@ export class FilterEventManager {
|
|
|
29
29
|
this.callback([]);
|
|
30
30
|
SelectHighlighter.clear2D(this.block, options);
|
|
31
31
|
}
|
|
32
|
-
clearKeysForPolar(margin, blockSize, options
|
|
32
|
+
clearKeysForPolar(margin, blockSize, options) {
|
|
33
33
|
this.selectedKeys = [];
|
|
34
34
|
if (this.callback)
|
|
35
35
|
this.callback([]);
|
|
36
|
-
SelectHighlighter.clearPolar(margin, blockSize, this.block, options, Donut.getAllArcGroups(this.block),
|
|
36
|
+
SelectHighlighter.clearPolar(margin, blockSize, this.block, options, Donut.getAllArcGroups(this.block), options.chartCanvas);
|
|
37
37
|
}
|
|
38
38
|
setKey(key) {
|
|
39
39
|
this.selectedKeys = [key];
|
|
@@ -66,9 +66,9 @@ export class FilterEventManager {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
setListenerPolar(margin, blockSize, options
|
|
69
|
+
setListenerPolar(margin, blockSize, options) {
|
|
70
70
|
if (this.filterable) {
|
|
71
|
-
this.registerEventToDonut(margin, blockSize, options,
|
|
71
|
+
this.registerEventToDonut(margin, blockSize, options, options.chartCanvas);
|
|
72
72
|
const selectedElems = Donut.getAllArcGroups(this.block).filter(d => this.selectedKeys.findIndex(sid => sid === d.data[options.data.keyField.name]) !== -1);
|
|
73
73
|
this.selectedKeys = [];
|
|
74
74
|
selectedElems.dispatch('click', { bubbles: false, cancelable: true, detail: { multySelect: true } });
|
|
@@ -10,10 +10,10 @@ export class IntervalManager {
|
|
|
10
10
|
static render(block, model, data) {
|
|
11
11
|
const options = model.options;
|
|
12
12
|
block.renderSvg(model.blockCanvas.size);
|
|
13
|
-
const scales = Scale.getScales(options.scale.key, options.scale.value,
|
|
13
|
+
const scales = Scale.getScales(options.scale.key, options.scale.value, options.chartSettings.bar);
|
|
14
14
|
Axis.render(block, scales, options.scale, options.axis, model.blockCanvas.size);
|
|
15
15
|
GridLine.render(block, options.additionalElements.gridLine.flag, options.axis, model.blockCanvas.size, model.chartBlock.margin, options.scale.key);
|
|
16
|
-
this.renderCharts(block, options.charts, scales, data, options.data, model.chartBlock.margin, options.axis.key.orient,
|
|
16
|
+
this.renderCharts(block, options.charts, scales, data, options.data, model.chartBlock.margin, options.axis.key.orient, options.chartSettings);
|
|
17
17
|
Title.render(block, options.title, model.otherComponents.titleBlock, model.blockCanvas.size);
|
|
18
18
|
Legend.render(block, data, options, model);
|
|
19
19
|
Tooltip.render(block, model, data, model.otherComponents.tooltipBlock, scales);
|
|
@@ -12,4 +12,6 @@ export declare class DonutHelper {
|
|
|
12
12
|
static getArcGenerator(outerRadius: number, innerRadius: number): Arc<any, PieArcDatum<MdtChartsDataRow>>;
|
|
13
13
|
static getPieGenerator(valueField: string, padAngle: number): Pie<any, MdtChartsDataRow>;
|
|
14
14
|
static mergeDataWithZeros(firstDataset: MdtChartsDataRow[], secondDataset: MdtChartsDataRow[], keyField: string, colorField: MdtChartsColorField): MdtChartsDataRow[];
|
|
15
|
+
private static getThicknessByUnit;
|
|
16
|
+
private static getChartBlockSize;
|
|
15
17
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { merge } from "d3-array";
|
|
2
2
|
import { arc, pie } from "d3-shape";
|
|
3
|
+
const MIN_CHART_BLOCK_SIZE_FOR_MAX_THICKNESS = 400;
|
|
3
4
|
export class DonutHelper {
|
|
4
5
|
static getThickness(donutSettings, blockSize, margin) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const thicknessOpts = donutSettings.thickness;
|
|
7
|
+
const chartBlockSize = this.getChartBlockSize(blockSize, margin);
|
|
8
|
+
if (thicknessOpts.value)
|
|
9
|
+
return this.getThicknessByUnit(chartBlockSize, thicknessOpts.value, thicknessOpts.unit);
|
|
10
|
+
if (Math.min(chartBlockSize.width, chartBlockSize.height) > MIN_CHART_BLOCK_SIZE_FOR_MAX_THICKNESS)
|
|
11
|
+
return this.getThicknessByUnit(chartBlockSize, thicknessOpts.max, thicknessOpts.unit);
|
|
12
|
+
return this.getThicknessByUnit(chartBlockSize, thicknessOpts.min, thicknessOpts.unit);
|
|
8
13
|
}
|
|
9
14
|
static getArcCentroid(blockSize, margin, dataItem, donutThickness) {
|
|
10
15
|
const arc = this.getArcGeneratorObject(blockSize, margin, donutThickness);
|
|
@@ -57,4 +62,16 @@ export class DonutHelper {
|
|
|
57
62
|
const sortedMerge = merge([secondDataset, onlyNew]);
|
|
58
63
|
return sortedMerge;
|
|
59
64
|
}
|
|
65
|
+
static getThicknessByUnit(chartBlockSize, valueInPx, unit) {
|
|
66
|
+
if (unit === "px")
|
|
67
|
+
return valueInPx;
|
|
68
|
+
const minSideSize = Math.min(chartBlockSize.width, chartBlockSize.height);
|
|
69
|
+
return minSideSize / 2 * (valueInPx / 100);
|
|
70
|
+
}
|
|
71
|
+
static getChartBlockSize(blockSize, margin) {
|
|
72
|
+
return {
|
|
73
|
+
height: blockSize.height - margin.top - margin.bottom,
|
|
74
|
+
width: blockSize.width - margin.left - margin.right
|
|
75
|
+
};
|
|
76
|
+
}
|
|
60
77
|
}
|
|
@@ -11,6 +11,7 @@ export class Donut {
|
|
|
11
11
|
const arcGenerator = DonutHelper.getArcGenerator(outerRadius, innerRadius);
|
|
12
12
|
const pieGenerator = DonutHelper.getPieGenerator(chart.data.valueField.name, settings.padAngle);
|
|
13
13
|
const translateAttr = DonutHelper.getTranslate(margin, blockSize);
|
|
14
|
+
Aggregator.render(block, data, chart.data.valueField, innerRadius, translateAttr, thickness, settings.aggregator);
|
|
14
15
|
const donutBlock = block.getSvg()
|
|
15
16
|
.append('g')
|
|
16
17
|
.attr('class', this.donutBlockClass)
|
|
@@ -19,7 +20,6 @@ export class Donut {
|
|
|
19
20
|
.attr('transform', `translate(${translateAttr.x}, ${translateAttr.y})`);
|
|
20
21
|
this.renderNewArcItems(arcGenerator, pieGenerator, donutBlock, data, chart);
|
|
21
22
|
this.renderClonesG(donutBlock);
|
|
22
|
-
Aggregator.render(block, data, chart.data.valueField, innerRadius, translateAttr, thickness, settings.aggregatorPad);
|
|
23
23
|
}
|
|
24
24
|
static update(block, data, margin, chart, blockSize, donutSettings, keyField) {
|
|
25
25
|
const outerRadius = DonutHelper.getOuterRadius(margin, blockSize);
|
|
@@ -9,18 +9,17 @@ export class PolarManager {
|
|
|
9
9
|
static render(engine, model) {
|
|
10
10
|
const options = model.options;
|
|
11
11
|
engine.block.renderSvg(model.blockCanvas.size);
|
|
12
|
-
this.renderCharts(engine.block, options.charts, engine.data, options.data.dataSource, model.chartBlock.margin, model.blockCanvas.size,
|
|
12
|
+
this.renderCharts(engine.block, options.charts, engine.data, options.data.dataSource, model.chartBlock.margin, model.blockCanvas.size, options.chartCanvas);
|
|
13
13
|
Title.render(engine.block, options.title, model.otherComponents.titleBlock, model.blockCanvas.size);
|
|
14
14
|
Legend.render(engine.block, engine.data, options, model);
|
|
15
|
-
``;
|
|
16
15
|
Tooltip.render(engine.block, model, engine.data, model.otherComponents.tooltipBlock);
|
|
17
|
-
engine.block.filterEventManager.setListenerPolar(model.chartBlock.margin, model.blockCanvas.size, options
|
|
16
|
+
engine.block.filterEventManager.setListenerPolar(model.chartBlock.margin, model.blockCanvas.size, options);
|
|
18
17
|
if (model.dataSettings.scope.hidedRecordsAmount !== 0 && model.options.legend.position !== 'off')
|
|
19
18
|
RecordOverflowAlert.render(engine.block, model.dataSettings.scope.hidedRecordsAmount, model.options.legend.position);
|
|
20
19
|
engine.block.getSvg()
|
|
21
20
|
.on('click', (e) => {
|
|
22
21
|
if (e.target === engine.block.getSvg().node())
|
|
23
|
-
engine.block.filterEventManager.clearKeysForPolar(model.chartBlock.margin, model.blockCanvas.size, options
|
|
22
|
+
engine.block.filterEventManager.clearKeysForPolar(model.chartBlock.margin, model.blockCanvas.size, options);
|
|
24
23
|
});
|
|
25
24
|
}
|
|
26
25
|
static update(block, model, data) {
|
|
@@ -32,12 +31,12 @@ export class PolarManager {
|
|
|
32
31
|
ElementHighlighter.toggleActivityStyle(Donut.getAllArcGroups(block), true);
|
|
33
32
|
Tooltip.hide(block);
|
|
34
33
|
const options = model.options;
|
|
35
|
-
Donut.update(block, data[options.data.dataSource], model.chartBlock.margin, options.charts[0], model.blockCanvas.size,
|
|
34
|
+
Donut.update(block, data[options.data.dataSource], model.chartBlock.margin, options.charts[0], model.blockCanvas.size, options.chartCanvas, options.data.keyField.name)
|
|
36
35
|
.then(() => {
|
|
37
36
|
Tooltip.render(block, model, data, model.otherComponents.tooltipBlock);
|
|
38
|
-
block.filterEventManager.setListenerPolar(model.chartBlock.margin, model.blockCanvas.size, options
|
|
37
|
+
block.filterEventManager.setListenerPolar(model.chartBlock.margin, model.blockCanvas.size, options);
|
|
39
38
|
});
|
|
40
|
-
Aggregator.update(block, data[options.data.dataSource], options.charts[0].data.valueField,
|
|
39
|
+
Aggregator.update(block, data[options.data.dataSource], options.charts[0].data.valueField, options.chartCanvas.aggregator);
|
|
41
40
|
Legend.update(block, data, model);
|
|
42
41
|
if (model.options.legend.position !== 'off')
|
|
43
42
|
RecordOverflowAlert.update(block, model.dataSettings.scope.hidedRecordsAmount, model.options.legend.position);
|
|
@@ -16,12 +16,12 @@ import { Line } from "./line/line";
|
|
|
16
16
|
export class TwoDimensionalManager {
|
|
17
17
|
static render(engine, model) {
|
|
18
18
|
const options = model.options;
|
|
19
|
-
const scales = Scale.getScales(options.scale.key, options.scale.value,
|
|
19
|
+
const scales = Scale.getScales(options.scale.key, options.scale.value, options.chartSettings.bar);
|
|
20
20
|
engine.block.scales = scales;
|
|
21
21
|
engine.block.renderSvg(model.blockCanvas.size);
|
|
22
22
|
Axis.render(engine.block, scales, options.scale, options.axis, model.blockCanvas.size);
|
|
23
23
|
GridLine.render(engine.block, options.additionalElements.gridLine.flag, options.axis, model.blockCanvas.size, model.chartBlock.margin, options.scale.key);
|
|
24
|
-
this.renderCharts(engine.block, options.charts, scales, engine.data, options.data, model.chartBlock.margin, options.axis.key.orient,
|
|
24
|
+
this.renderCharts(engine.block, options.charts, scales, engine.data, options.data, model.chartBlock.margin, options.axis.key.orient, options.chartSettings.bar, model.blockCanvas.size);
|
|
25
25
|
engine.block.filterEventManager.registerEventFor2D(scales.key, model.chartBlock.margin, model.blockCanvas.size, options);
|
|
26
26
|
engine.block.filterEventManager.event2DUpdate(options);
|
|
27
27
|
Title.render(engine.block, options.title, model.otherComponents.titleBlock, model.blockCanvas.size);
|
|
@@ -42,12 +42,12 @@ export class TwoDimensionalManager {
|
|
|
42
42
|
Tooltip.hide(block);
|
|
43
43
|
const options = model.options;
|
|
44
44
|
ElementHighlighter.remove2DChartsFullHighlighting(block, options.charts);
|
|
45
|
-
const scales = Scale.getScales(options.scale.key, options.scale.value,
|
|
45
|
+
const scales = Scale.getScales(options.scale.key, options.scale.value, options.chartSettings.bar);
|
|
46
46
|
const keyDomainEquality = Helper.checkDomainsEquality(block.scales.key.domain(), scales.key.domain());
|
|
47
47
|
block.scales = scales;
|
|
48
48
|
Axis.update(block, scales, options.scale, options.axis, model.blockCanvas.size, keyDomainEquality);
|
|
49
49
|
GridLine.update(block, options.additionalElements.gridLine.flag, options.axis, model.blockCanvas.size, model.chartBlock.margin, options.scale.key);
|
|
50
|
-
const promises = this.updateCharts(block, options.charts, scales, data, model.options.data, model.chartBlock.margin, options.axis.key.orient, model.blockCanvas.size,
|
|
50
|
+
const promises = this.updateCharts(block, options.charts, scales, data, model.options.data, model.chartBlock.margin, options.axis.key.orient, model.blockCanvas.size, options.chartSettings.bar);
|
|
51
51
|
Promise.all(promises)
|
|
52
52
|
.then(() => {
|
|
53
53
|
block.filterEventManager.event2DUpdate(options);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TwoDimensionalChart, TwoDimensionalChartType } from "../../config/config";
|
|
2
|
+
import { ChartStyleConfig } from "../../designer/designerConfig";
|
|
3
|
+
import { ChartStyle } from "../model";
|
|
4
|
+
export declare class TwoDimensionalChartStyleModel {
|
|
5
|
+
private charts;
|
|
6
|
+
private chartStyleConfig;
|
|
7
|
+
private service;
|
|
8
|
+
constructor(charts: TwoDimensionalChart[], chartStyleConfig: ChartStyleConfig);
|
|
9
|
+
getChartStyle(chart: TwoDimensionalChart, chartIndex: number): ChartStyle;
|
|
10
|
+
private getChartsValueFieldsAmounts;
|
|
11
|
+
}
|
|
12
|
+
export declare class TwoDimensionalChartStyleService {
|
|
13
|
+
getChartColors(chart: TwoDimensionalChart, styleConfig: ChartStyleConfig, chartsFieldsAmounts: number[], chartIndex: number): string[];
|
|
14
|
+
getChartOpacity(chartsLength: number, chartType: TwoDimensionalChartType, chartsValueFieldAmount: number, isChartSegmented: boolean): number;
|
|
15
|
+
private generateNewChartColors;
|
|
16
|
+
private isMoreThanOneValueFieldOnCanvas;
|
|
17
|
+
private makeColorsBrighter;
|
|
18
|
+
private getStartIndex;
|
|
19
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as chroma from "chroma-js";
|
|
2
|
+
import { ModelHelper } from "../modelHelper";
|
|
3
|
+
import { ChartStyleModelService } from "./chartStyleModel";
|
|
4
|
+
export class TwoDimensionalChartStyleModel {
|
|
5
|
+
constructor(charts, chartStyleConfig) {
|
|
6
|
+
this.charts = charts;
|
|
7
|
+
this.chartStyleConfig = chartStyleConfig;
|
|
8
|
+
this.service = new TwoDimensionalChartStyleService();
|
|
9
|
+
}
|
|
10
|
+
getChartStyle(chart, chartIndex) {
|
|
11
|
+
const fieldsAmounts = this.getChartsValueFieldsAmounts();
|
|
12
|
+
return {
|
|
13
|
+
elementColors: this.service.getChartColors(chart, this.chartStyleConfig, fieldsAmounts, chartIndex),
|
|
14
|
+
opacity: this.service.getChartOpacity(this.charts.length, chart.type, fieldsAmounts[chartIndex], chart.isSegmented)
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
getChartsValueFieldsAmounts() {
|
|
18
|
+
return this.charts.map(chart => chart.data.valueFields.length);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class TwoDimensionalChartStyleService {
|
|
22
|
+
getChartColors(chart, styleConfig, chartsFieldsAmounts, chartIndex) {
|
|
23
|
+
const generatedColors = this.generateNewChartColors(chart.type, styleConfig, chartsFieldsAmounts, chartIndex);
|
|
24
|
+
chart.data.valueFields.forEach((field, fieldIndex) => {
|
|
25
|
+
if (field.color)
|
|
26
|
+
generatedColors[fieldIndex] = field.color;
|
|
27
|
+
});
|
|
28
|
+
return generatedColors;
|
|
29
|
+
}
|
|
30
|
+
getChartOpacity(chartsLength, chartType, chartsValueFieldAmount, isChartSegmented) {
|
|
31
|
+
if (chartType === 'area' && this.isMoreThanOneValueFieldOnCanvas(chartsLength, chartsValueFieldAmount) && !isChartSegmented)
|
|
32
|
+
return 0.5; // combined area with other charts has 0.5 opacity
|
|
33
|
+
return 1;
|
|
34
|
+
}
|
|
35
|
+
generateNewChartColors(chartType, styleConfig, chartsFieldsAmounts, chartIndex) {
|
|
36
|
+
const startIndex = this.getStartIndex(chartIndex, chartsFieldsAmounts);
|
|
37
|
+
const baseColors = ChartStyleModelService.checkAndGet(styleConfig.baseColors);
|
|
38
|
+
const palette = ChartStyleModelService.getColorSet(baseColors, ModelHelper.getSum(chartsFieldsAmounts));
|
|
39
|
+
const elementsAmount = chartsFieldsAmounts[chartIndex];
|
|
40
|
+
const selectedColors = palette.slice(startIndex, startIndex + elementsAmount);
|
|
41
|
+
if (chartType !== 'line')
|
|
42
|
+
return selectedColors;
|
|
43
|
+
this.makeColorsBrighter(selectedColors);
|
|
44
|
+
return selectedColors;
|
|
45
|
+
}
|
|
46
|
+
isMoreThanOneValueFieldOnCanvas(chartsLength, chartsValueFieldAmount) {
|
|
47
|
+
return (chartsLength > 1 || chartsValueFieldAmount > 1);
|
|
48
|
+
}
|
|
49
|
+
makeColorsBrighter(initialColors) {
|
|
50
|
+
for (let i = 0; i < initialColors.length; i++) {
|
|
51
|
+
initialColors[i] = chroma.mix(initialColors[i], 'white', 0.2).saturate(3).hex();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
getStartIndex(chartIndex, chartsFieldsAmounts) {
|
|
55
|
+
let startIndex = 0;
|
|
56
|
+
for (let i = 0; i < chartIndex; i++) {
|
|
57
|
+
startIndex += chartsFieldsAmounts[i];
|
|
58
|
+
}
|
|
59
|
+
return startIndex;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ChartStyleConfig } from "../../designer/designerConfig";
|
|
2
|
+
import { ChartStyle } from "../model";
|
|
3
|
+
export declare class ChartStyleModelService {
|
|
4
|
+
private static standartColors;
|
|
5
|
+
static getCssClasses(chartIndex: number): string[];
|
|
6
|
+
static getChartStyle(elementsAmount: number, styleConfig: ChartStyleConfig): ChartStyle;
|
|
7
|
+
static getColorSet(baseColors: string[], elementsAmount: number): string[];
|
|
8
|
+
static checkAndGet(baseColors: string[]): string[];
|
|
9
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as chroma from "chroma-js";
|
|
2
|
+
export class ChartStyleModelService {
|
|
3
|
+
static getCssClasses(chartIndex) {
|
|
4
|
+
const cssClasses = [`chart-${chartIndex}`];
|
|
5
|
+
return cssClasses;
|
|
6
|
+
}
|
|
7
|
+
static getChartStyle(elementsAmount, styleConfig) {
|
|
8
|
+
const baseColors = this.checkAndGet(styleConfig.baseColors);
|
|
9
|
+
return {
|
|
10
|
+
elementColors: this.getColorSet(baseColors, elementsAmount),
|
|
11
|
+
opacity: 1
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
static getColorSet(baseColors, elementsAmount) {
|
|
15
|
+
return chroma.scale(baseColors)
|
|
16
|
+
.mode('rgb')
|
|
17
|
+
.domain([0, 0.55, 0.75, 1])
|
|
18
|
+
.colors(elementsAmount <= 1 ? 2 : elementsAmount);
|
|
19
|
+
}
|
|
20
|
+
static checkAndGet(baseColors) {
|
|
21
|
+
if (baseColors.length === 0 || baseColors.filter(color => color === 'rgba(0, 0, 0, 0)' || !color).length > 0) {
|
|
22
|
+
return this.standartColors;
|
|
23
|
+
}
|
|
24
|
+
return baseColors;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
ChartStyleModelService.standartColors = ["#209DE3", "#FF3131", "#FFBA00", "#20B078"];
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { MdtChartsConfig, MdtChartsDataSource } from "../config/config";
|
|
2
2
|
import { DesignerConfig } from "../designer/designerConfig";
|
|
3
|
-
import {
|
|
3
|
+
import { DataScope, LegendBlockModel } from "./model";
|
|
4
|
+
import { ModelInstance } from "./modelInstance/modelInstance";
|
|
4
5
|
export declare class DataManagerModel {
|
|
5
6
|
static getPreparedData(data: MdtChartsDataSource, allowableKeys: string[], config: MdtChartsConfig): MdtChartsDataSource;
|
|
6
|
-
static getDataScope(config: MdtChartsConfig,
|
|
7
|
+
static getDataScope(config: MdtChartsConfig, data: MdtChartsDataSource, designerConfig: DesignerConfig, legendBlock: LegendBlockModel, modelInstance: ModelInstance): DataScope;
|
|
7
8
|
static getDataValuesByKeyField(data: MdtChartsDataSource, dataSourceName: string, keyFieldName: string): string[];
|
|
8
9
|
private static getDataScopeFor2D;
|
|
9
10
|
private static getDataScopeForPolar;
|
|
@@ -8,18 +8,18 @@ export class DataManagerModel {
|
|
|
8
8
|
this.setDataType(scopedData, config);
|
|
9
9
|
return scopedData;
|
|
10
10
|
}
|
|
11
|
-
static getDataScope(config,
|
|
11
|
+
static getDataScope(config, data, designerConfig, legendBlock, modelInstance) {
|
|
12
12
|
if (config.options.type === '2d' || config.options.type === 'interval') {
|
|
13
|
-
return this.getDataScopeFor2D(config.options,
|
|
13
|
+
return this.getDataScopeFor2D(config.options, modelInstance, data, designerConfig);
|
|
14
14
|
}
|
|
15
15
|
else if (config.options.type === 'polar') {
|
|
16
|
-
return this.getDataScopeForPolar(config.options,
|
|
16
|
+
return this.getDataScopeForPolar(config.options, modelInstance, data, legendBlock, designerConfig.canvas.legendBlock);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
static getDataValuesByKeyField(data, dataSourceName, keyFieldName) {
|
|
20
20
|
return data[dataSourceName].map(dataRow => dataRow[keyFieldName]);
|
|
21
21
|
}
|
|
22
|
-
static getDataScopeFor2D(configOptions,
|
|
22
|
+
static getDataScopeFor2D(configOptions, modelInstance, data, designerConfig) {
|
|
23
23
|
// Для interval всегда один элемент, так как там может быть только один столбик
|
|
24
24
|
let itemsLength = 1;
|
|
25
25
|
if (configOptions.type === '2d') {
|
|
@@ -29,7 +29,7 @@ export class DataManagerModel {
|
|
|
29
29
|
itemsLength = 1; // Если баров нет, то для одной записи выделяется столько же места, сколько для одного столбика
|
|
30
30
|
}
|
|
31
31
|
if (itemsLength !== 0) {
|
|
32
|
-
const axisLength = AxisModel.getAxisLength(configOptions.orientation,
|
|
32
|
+
const axisLength = AxisModel.getAxisLength(configOptions.orientation, modelInstance.canvasModel);
|
|
33
33
|
const uniqueKeys = ModelHelper.getUniqueValues(data[configOptions.data.dataSource].map(d => d[configOptions.data.keyField.name]));
|
|
34
34
|
const dataLength = uniqueKeys.length;
|
|
35
35
|
const limit = this.getDataLimitByItemSize(this.getElementsInGroupAmount(configOptions, itemsLength), dataLength, axisLength, designerConfig.canvas.chartOptions.bar);
|
|
@@ -44,7 +44,8 @@ export class DataManagerModel {
|
|
|
44
44
|
hidedRecordsAmount: 0
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
-
static getDataScopeForPolar(configOptions,
|
|
47
|
+
static getDataScopeForPolar(configOptions, modelInstance, data, legendBlock, legendCanvas) {
|
|
48
|
+
const canvas = modelInstance.canvasModel;
|
|
48
49
|
const dataset = data[configOptions.data.dataSource];
|
|
49
50
|
const keyFieldName = configOptions.data.keyField.name;
|
|
50
51
|
const keys = dataset.map(dataRow => dataRow[keyFieldName]);
|
|
@@ -55,17 +56,18 @@ export class DataManagerModel {
|
|
|
55
56
|
};
|
|
56
57
|
}
|
|
57
58
|
let position;
|
|
58
|
-
if (
|
|
59
|
+
if (canvas.getChartBlockWidth() >= MIN_DONUT_BLOCK_SIZE)
|
|
59
60
|
position = 'right';
|
|
60
61
|
else
|
|
61
62
|
position = 'bottom';
|
|
62
63
|
let maxItemsNumber;
|
|
63
64
|
if (position === 'right') {
|
|
64
|
-
maxItemsNumber = LegendCanvasModel.findElementsAmountByLegendSize(keys, position, legendCanvas.maxWidth,
|
|
65
|
+
maxItemsNumber = LegendCanvasModel.findElementsAmountByLegendSize(keys, position, legendCanvas.maxWidth, canvas.getChartBlockHeight());
|
|
65
66
|
}
|
|
66
67
|
else {
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
const margin = canvas.getMargin();
|
|
69
|
+
const marginBottomWithoutLegendBlock = margin.bottom - (legendBlock.coordinate.bottom.size === 0 ? legendBlock.coordinate.bottom.size : legendBlock.coordinate.bottom.size - legendBlock.coordinate.bottom.margin.bottom);
|
|
70
|
+
maxItemsNumber = LegendCanvasModel.findElementsAmountByLegendSize(keys, position, canvas.getChartBlockWidth(), canvas.getBlockSize().height - margin.top - marginBottomWithoutLegendBlock - legendBlock.coordinate.bottom.margin.bottom - MIN_DONUT_BLOCK_SIZE);
|
|
69
71
|
}
|
|
70
72
|
return {
|
|
71
73
|
allowableKeys: keys.slice(0, maxItemsNumber),
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { AxisPosition, ChartOrientation, DataOptions, MdtChartsDataSource, DiscreteAxisOptions, NumberAxisOptions,
|
|
2
|
-
import { AxisLabelPosition, AxisModelOptions,
|
|
1
|
+
import { AxisPosition, ChartOrientation, DataOptions, MdtChartsDataSource, DiscreteAxisOptions, NumberAxisOptions, TwoDimensionalChart } from "../../config/config";
|
|
2
|
+
import { AxisLabelPosition, AxisModelOptions, Orient } from "../model";
|
|
3
3
|
import { AxisType } from "../modelBuilder";
|
|
4
4
|
import { AxisLabelCanvas, TooltipSettings } from "../../designer/designerConfig";
|
|
5
|
+
import { CanvasModel } from "../modelInstance/canvasModel/canvasModel";
|
|
5
6
|
export interface LabelSize {
|
|
6
7
|
width: number;
|
|
7
8
|
height: number;
|
|
8
9
|
}
|
|
9
10
|
export declare class AxisModel {
|
|
10
|
-
static getKeyAxis(charts: TwoDimensionalChart[], data: MdtChartsDataSource, dataOptions: DataOptions, orient: ChartOrientation, axisConfig: DiscreteAxisOptions, labelConfig: AxisLabelCanvas,
|
|
11
|
-
static getValueAxis(orient: ChartOrientation, axisConfig: NumberAxisOptions, labelConfig: AxisLabelCanvas,
|
|
12
|
-
static getAxisLength(chartOrientation: ChartOrientation,
|
|
11
|
+
static getKeyAxis(charts: TwoDimensionalChart[], data: MdtChartsDataSource, dataOptions: DataOptions, orient: ChartOrientation, axisConfig: DiscreteAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel, tooltipSettings: TooltipSettings): AxisModelOptions;
|
|
12
|
+
static getValueAxis(orient: ChartOrientation, axisConfig: NumberAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel): AxisModelOptions;
|
|
13
|
+
static getAxisLength(chartOrientation: ChartOrientation, canvasModel: CanvasModel): number;
|
|
13
14
|
static getAxisOrient(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition): Orient;
|
|
14
|
-
static getAxisTranslateX(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition,
|
|
15
|
-
static getAxisTranslateY(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition,
|
|
16
|
-
static getKeyAxisLabelPosition(
|
|
15
|
+
static getAxisTranslateX(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition, canvasModel: CanvasModel): number;
|
|
16
|
+
static getAxisTranslateY(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition, canvasModel: CanvasModel): number;
|
|
17
|
+
static getKeyAxisLabelPosition(canvasModel: CanvasModel, scopedDataLength: number): AxisLabelPosition;
|
|
17
18
|
static getLabelSize(labelMaxWidth: number, labelTexts: any[]): LabelSize;
|
|
18
19
|
}
|