mdt-charts 1.19.0 → 1.20.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 +16 -0
- package/lib/engine/block/blockSvg.d.ts +1 -1
- package/lib/engine/block/blockSvg.js +1 -1
- package/lib/engine/elementHighlighter/elementHighlighter.d.ts +0 -1
- package/lib/engine/elementHighlighter/elementHighlighter.js +5 -8
- package/lib/engine/elementHighlighter/selectHighlighter.js +11 -10
- package/lib/engine/features/axis/axis.d.ts +3 -3
- package/lib/engine/features/axis/axis.js +6 -0
- package/lib/engine/features/legend/legendMarkerCreator.js +1 -1
- package/lib/engine/features/markDots/markDot.d.ts +11 -3
- package/lib/engine/features/markDots/markDot.js +21 -10
- package/lib/engine/features/scale/scale.js +1 -1
- package/lib/engine/features/tolltip/tooltip.js +5 -4
- package/lib/engine/features/valueLabels/valueLabels.d.ts +45 -0
- package/lib/engine/features/valueLabels/valueLabels.js +139 -0
- package/lib/engine/features/valueLabels/valueLabelsHelper.d.ts +6 -0
- package/lib/engine/features/valueLabels/valueLabelsHelper.js +21 -0
- package/lib/engine/features/valueLabelsCollision/valueLabelsCollision.d.ts +23 -0
- package/lib/engine/features/valueLabelsCollision/valueLabelsCollision.js +24 -0
- package/lib/engine/features/valueLabelsCollision/valueLabelsCollisionHelper.d.ts +5 -0
- package/lib/engine/features/valueLabelsCollision/valueLabelsCollisionHelper.js +47 -0
- package/lib/engine/twoDimensionalNotation/area/area.d.ts +18 -11
- package/lib/engine/twoDimensionalNotation/area/area.js +32 -22
- package/lib/engine/twoDimensionalNotation/area/areaGenerator.d.ts +14 -0
- package/lib/engine/twoDimensionalNotation/area/areaGenerator.js +22 -0
- package/lib/engine/twoDimensionalNotation/area/areaHelper.d.ts +7 -7
- package/lib/engine/twoDimensionalNotation/area/areaHelper.js +30 -31
- package/lib/engine/twoDimensionalNotation/bar/barHelper.js +1 -1
- package/lib/engine/twoDimensionalNotation/bar/stackedData/dataStacker.d.ts +4 -2
- package/lib/engine/twoDimensionalNotation/bar/stackedData/dataStacker.js +2 -5
- package/lib/engine/twoDimensionalNotation/line/line.d.ts +0 -6
- package/lib/engine/twoDimensionalNotation/line/line.js +4 -4
- package/lib/engine/twoDimensionalNotation/line/lineGenerator.d.ts +4 -7
- package/lib/engine/twoDimensionalNotation/line/lineGenerator.js +2 -16
- package/lib/engine/twoDimensionalNotation/line/lineHelper.d.ts +4 -13
- package/lib/engine/twoDimensionalNotation/line/lineHelper.js +22 -10
- package/lib/engine/twoDimensionalNotation/lineLike/generatorFactory/lineLikeGeneratorFactory.d.ts +12 -0
- package/lib/engine/twoDimensionalNotation/lineLike/generatorFactory/lineLikeGeneratorFactory.js +1 -0
- package/lib/engine/twoDimensionalNotation/lineLike/generatorMiddleware/lineLikeGeneratorCurveMiddleware.d.ts +14 -0
- package/lib/engine/twoDimensionalNotation/lineLike/generatorMiddleware/lineLikeGeneratorCurveMiddleware.js +21 -0
- package/lib/engine/twoDimensionalNotation/lineLike/generatorMiddleware/lineLikeGeneratorDefineMiddleware.d.ts +20 -0
- package/lib/engine/twoDimensionalNotation/lineLike/generatorMiddleware/lineLikeGeneratorDefineMiddleware.js +9 -0
- package/lib/engine/twoDimensionalNotation/lineLike/generatorMiddleware/lineLikeGeneratorMiddleware.d.ts +5 -0
- package/lib/engine/twoDimensionalNotation/lineLike/generatorMiddleware/lineLikeGeneratorMiddleware.js +1 -0
- package/lib/engine/twoDimensionalNotation/twoDimensionalManager.d.ts +1 -0
- package/lib/engine/twoDimensionalNotation/twoDimensionalManager.js +19 -3
- package/lib/model/featuresModel/axisModel.d.ts +4 -2
- package/lib/model/featuresModel/axisModel.js +14 -6
- package/lib/model/featuresModel/scaleModel/scaleModel.js +1 -1
- package/lib/model/featuresModel/valueLabelsModel/valueLabelsModel.d.ts +9 -0
- package/lib/model/featuresModel/valueLabelsModel/valueLabelsModel.js +33 -0
- package/lib/model/helpers/modelHelper.d.ts +1 -0
- package/lib/model/helpers/modelHelper.js +3 -2
- package/lib/model/helpers/twoDimensionalModelHelper.d.ts +5 -0
- package/lib/model/helpers/twoDimensionalModelHelper.js +16 -0
- package/lib/model/margin/twoDim/twoDimMarginModel.d.ts +2 -0
- package/lib/model/margin/twoDim/twoDimMarginModel.js +34 -1
- package/lib/model/model.d.ts +29 -5
- package/lib/model/modelInstance/configReader.d.ts +9 -3
- package/lib/model/modelInstance/configReader.js +46 -15
- package/lib/model/notations/twoDimensionalModel.js +31 -35
- package/package.json +1 -1
- /package/lib/engine/block/{defs.d.ts → defs/hatchPattern.d.ts} +0 -0
- /package/lib/engine/block/{defs.js → defs/hatchPattern.js} +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export class ValueLabelsCollisionHelper {
|
|
2
|
+
static calculateValueLabelsVisibility(elements) {
|
|
3
|
+
const sortedLabels = elements.sort((label1, label2) => label1.boundingClientRect.x - label2.boundingClientRect.x);
|
|
4
|
+
const activeLabels = [];
|
|
5
|
+
const labelsVisibility = new Map();
|
|
6
|
+
elements.forEach(label => {
|
|
7
|
+
labelsVisibility.set(label.index, { index: label.index, isVisible: true });
|
|
8
|
+
});
|
|
9
|
+
sortedLabels.forEach(currentLabel => {
|
|
10
|
+
for (let i = activeLabels.length - 1; i >= 0; i--) {
|
|
11
|
+
const activeLabel = activeLabels[i];
|
|
12
|
+
if (activeLabel.boundingClientRect.x + activeLabel.boundingClientRect.width < currentLabel.boundingClientRect.x) {
|
|
13
|
+
activeLabels.splice(i, 1);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
for (const activeLabel of activeLabels) {
|
|
17
|
+
if (this.isOverlapping(currentLabel.boundingClientRect, activeLabel.boundingClientRect)) {
|
|
18
|
+
if (currentLabel.boundingClientRect.x > activeLabel.boundingClientRect.x) {
|
|
19
|
+
labelsVisibility.get(currentLabel.index).isVisible = false;
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
else if (currentLabel.boundingClientRect.x === activeLabel.boundingClientRect.x) {
|
|
23
|
+
if (currentLabel.boundingClientRect.y > activeLabel.boundingClientRect.y) {
|
|
24
|
+
labelsVisibility.get(currentLabel.index).isVisible = false;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
else
|
|
28
|
+
labelsVisibility.get(activeLabel.index).isVisible = false;
|
|
29
|
+
}
|
|
30
|
+
else
|
|
31
|
+
labelsVisibility.get(activeLabel.index).isVisible = false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (labelsVisibility.get(currentLabel.index).isVisible) {
|
|
35
|
+
activeLabels.push(currentLabel);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return labelsVisibility;
|
|
39
|
+
}
|
|
40
|
+
static isOverlapping(rect1, rect2) {
|
|
41
|
+
return !(rect1.x + rect1.width < rect2.x ||
|
|
42
|
+
rect1.x > rect2.x + rect2.width ||
|
|
43
|
+
rect1.y + rect1.height < rect2.y ||
|
|
44
|
+
rect1.y > rect2.y + rect2.height);
|
|
45
|
+
}
|
|
46
|
+
;
|
|
47
|
+
}
|
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
import { BlockMargin, Field, Orient, TwoDimensionalChartModel } from "../../../model/model";
|
|
1
|
+
import { BlockMargin, Field, LineLikeChartSettings, Orient, TwoDimensionalChartModel } from "../../../model/model";
|
|
2
2
|
import { Scales } from "../../features/scale/scale";
|
|
3
3
|
import { Block } from "../../block/block";
|
|
4
4
|
import { MdtChartsDataRow, Size } from '../../../config/config';
|
|
5
|
+
interface AreaOptions {
|
|
6
|
+
staticSettings: LineLikeChartSettings;
|
|
7
|
+
}
|
|
5
8
|
export declare class Area {
|
|
9
|
+
private readonly options;
|
|
6
10
|
static readonly areaChartClass = "area";
|
|
7
|
-
static
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
private
|
|
11
|
+
static get(options: AreaOptions): Area;
|
|
12
|
+
constructor(options: AreaOptions);
|
|
13
|
+
render(block: Block, scales: Scales, data: MdtChartsDataRow[], keyField: Field, margin: BlockMargin, keyAxisOrient: Orient, chart: TwoDimensionalChartModel, blockSize: Size): void;
|
|
14
|
+
update(block: Block, scales: Scales, newData: MdtChartsDataRow[], keyField: Field, margin: BlockMargin, chart: TwoDimensionalChartModel, keyAxisOrient: Orient, blockSize: Size): Promise<any>[];
|
|
15
|
+
updateColors(block: Block, chart: TwoDimensionalChartModel): void;
|
|
16
|
+
private renderGrouped;
|
|
17
|
+
private renderSegmented;
|
|
18
|
+
private updateGrouped;
|
|
19
|
+
private updateSegmented;
|
|
20
|
+
private updateGroupedPath;
|
|
21
|
+
private updateSegmentedPath;
|
|
22
|
+
private setSegmentColor;
|
|
17
23
|
}
|
|
24
|
+
export {};
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { select } from 'd3-selection';
|
|
2
2
|
import { MarkDot } from "../../features/markDots/markDot";
|
|
3
|
-
import {
|
|
3
|
+
import { AreaGeneratorFactory } from './areaHelper';
|
|
4
4
|
import { DomHelper } from '../../helpers/domHelper';
|
|
5
5
|
import { Helper } from '../../helpers/helper';
|
|
6
6
|
import { getStackedDataWithOwn } from '../bar/stackedData/dataStacker';
|
|
7
7
|
export class Area {
|
|
8
|
-
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.options = options;
|
|
10
|
+
}
|
|
11
|
+
static get(options) {
|
|
12
|
+
return new Area(options);
|
|
13
|
+
}
|
|
14
|
+
render(block, scales, data, keyField, margin, keyAxisOrient, chart, blockSize) {
|
|
9
15
|
if (chart.isSegmented)
|
|
10
16
|
this.renderSegmented(block, scales, data, keyField, margin, keyAxisOrient, chart);
|
|
11
17
|
else
|
|
12
|
-
this.renderGrouped(block, scales, data, keyField, margin, keyAxisOrient, chart
|
|
18
|
+
this.renderGrouped(block, scales, data, keyField, margin, keyAxisOrient, chart);
|
|
13
19
|
}
|
|
14
|
-
|
|
20
|
+
update(block, scales, newData, keyField, margin, chart, keyAxisOrient, blockSize) {
|
|
15
21
|
let promises;
|
|
16
22
|
if (chart.isSegmented) {
|
|
17
23
|
promises = this.updateSegmented(block, scales, newData, keyField, margin, chart, keyAxisOrient);
|
|
@@ -21,21 +27,22 @@ export class Area {
|
|
|
21
27
|
}
|
|
22
28
|
return promises;
|
|
23
29
|
}
|
|
24
|
-
|
|
30
|
+
updateColors(block, chart) {
|
|
25
31
|
chart.data.valueFields.forEach((_vf, valueIndex) => {
|
|
26
32
|
const path = block.svg.getChartGroup(chart.index)
|
|
27
|
-
.select(`.${
|
|
33
|
+
.select(`.${Area.areaChartClass}${Helper.getCssClassesLine(chart.cssClasses)}.chart-element-${valueIndex}`);
|
|
28
34
|
DomHelper.setChartStyle(path, chart.style, valueIndex, 'fill');
|
|
29
35
|
MarkDot.updateColors(block, chart, valueIndex);
|
|
30
36
|
});
|
|
31
37
|
}
|
|
32
|
-
|
|
38
|
+
renderGrouped(block, scales, data, keyField, margin, keyAxisOrient, chart) {
|
|
39
|
+
const generatorFactory = new AreaGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, shouldRender: chart.lineLikeViewOptions.renderForKey, curve: this.options.staticSettings.shape.curve.type });
|
|
33
40
|
chart.data.valueFields.forEach((field, valueIndex) => {
|
|
34
|
-
const area =
|
|
41
|
+
const area = generatorFactory.getAreaGenerator(field.name);
|
|
35
42
|
const path = block.svg.getChartGroup(chart.index)
|
|
36
43
|
.append('path')
|
|
37
44
|
.attr('d', area(data))
|
|
38
|
-
.attr('class',
|
|
45
|
+
.attr('class', Area.areaChartClass)
|
|
39
46
|
.style('clip-path', `url(#${block.svg.getClipPathId()})`)
|
|
40
47
|
.style('pointer-events', 'none');
|
|
41
48
|
DomHelper.setCssClasses(path, Helper.getCssClassesWithElementIndex(chart.cssClasses, valueIndex));
|
|
@@ -43,16 +50,17 @@ export class Area {
|
|
|
43
50
|
MarkDot.render(block, data, keyAxisOrient, scales, margin, keyField.name, valueIndex, field.name, chart);
|
|
44
51
|
});
|
|
45
52
|
}
|
|
46
|
-
|
|
53
|
+
renderSegmented(block, scales, data, keyField, margin, keyAxisOrient, chart) {
|
|
47
54
|
const stackedData = getStackedDataWithOwn(data, chart.data.valueFields.map(field => field.name));
|
|
48
|
-
const
|
|
55
|
+
const generatorFactory = new AreaGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, shouldRender: chart.lineLikeViewOptions.renderForKey, curve: this.options.staticSettings.shape.curve.type });
|
|
56
|
+
const areaGenerator = generatorFactory.getSegmentedAreaGenerator();
|
|
49
57
|
const areas = block.svg.getChartGroup(chart.index)
|
|
50
|
-
.selectAll(`.${
|
|
58
|
+
.selectAll(`.${Area.areaChartClass}${Helper.getCssClassesLine(chart.cssClasses)}`)
|
|
51
59
|
.data(stackedData)
|
|
52
60
|
.enter()
|
|
53
61
|
.append('path')
|
|
54
62
|
.attr('d', d => areaGenerator(d))
|
|
55
|
-
.attr('class',
|
|
63
|
+
.attr('class', Area.areaChartClass)
|
|
56
64
|
.style('clip-path', `url(#${block.svg.getClipPathId()})`)
|
|
57
65
|
.style('pointer-events', 'none');
|
|
58
66
|
areas.each(function (d, i) {
|
|
@@ -63,23 +71,25 @@ export class Area {
|
|
|
63
71
|
MarkDot.render(block, dataset, keyAxisOrient, scales, margin, keyField.name, index, '1', chart);
|
|
64
72
|
});
|
|
65
73
|
}
|
|
66
|
-
|
|
74
|
+
updateGrouped(block, scales, newData, keyField, margin, chart, keyAxisOrient, blockSize) {
|
|
67
75
|
const promises = [];
|
|
76
|
+
const generatorFactory = new AreaGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, shouldRender: chart.lineLikeViewOptions.renderForKey, curve: this.options.staticSettings.shape.curve.type });
|
|
68
77
|
chart.data.valueFields.forEach((field, valueIndex) => {
|
|
69
|
-
const areaGenerator =
|
|
78
|
+
const areaGenerator = generatorFactory.getAreaGenerator(field.name);
|
|
70
79
|
const areaObject = block.svg.getChartGroup(chart.index)
|
|
71
|
-
.select(`.${
|
|
80
|
+
.select(`.${Area.areaChartClass}${Helper.getCssClassesLine(chart.cssClasses)}.chart-element-${valueIndex}`);
|
|
72
81
|
const prom = this.updateGroupedPath(block, areaObject, areaGenerator, newData);
|
|
73
82
|
promises.push(prom);
|
|
74
83
|
MarkDot.update(block, newData, keyAxisOrient, scales, margin, keyField.name, valueIndex, field.name, chart);
|
|
75
84
|
});
|
|
76
85
|
return promises;
|
|
77
86
|
}
|
|
78
|
-
|
|
87
|
+
updateSegmented(block, scales, newData, keyField, margin, chart, keyAxisOrient) {
|
|
79
88
|
const stackedData = getStackedDataWithOwn(newData, chart.data.valueFields.map(field => field.name));
|
|
80
|
-
const
|
|
89
|
+
const generatorFactory = new AreaGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, shouldRender: chart.lineLikeViewOptions.renderForKey, curve: this.options.staticSettings.shape.curve.type });
|
|
90
|
+
const areaGenerator = generatorFactory.getSegmentedAreaGenerator();
|
|
81
91
|
const areas = block.svg.getChartGroup(chart.index)
|
|
82
|
-
.selectAll(`path.${
|
|
92
|
+
.selectAll(`path.${Area.areaChartClass}${Helper.getCssClassesLine(chart.cssClasses)}`)
|
|
83
93
|
.data(stackedData);
|
|
84
94
|
const prom = this.updateSegmentedPath(block, areas, areaGenerator);
|
|
85
95
|
areas.each((dataset, index) => {
|
|
@@ -88,7 +98,7 @@ export class Area {
|
|
|
88
98
|
});
|
|
89
99
|
return [prom];
|
|
90
100
|
}
|
|
91
|
-
|
|
101
|
+
updateGroupedPath(block, areaObject, areaGenerator, newData) {
|
|
92
102
|
return new Promise(resolve => {
|
|
93
103
|
if (areaObject.size() === 0) {
|
|
94
104
|
resolve('');
|
|
@@ -106,7 +116,7 @@ export class Area {
|
|
|
106
116
|
resolve('');
|
|
107
117
|
});
|
|
108
118
|
}
|
|
109
|
-
|
|
119
|
+
updateSegmentedPath(block, areasObjects, areaGenerator) {
|
|
110
120
|
return new Promise(resolve => {
|
|
111
121
|
if (areasObjects.size() === 0) {
|
|
112
122
|
resolve('');
|
|
@@ -124,7 +134,7 @@ export class Area {
|
|
|
124
134
|
resolve('');
|
|
125
135
|
});
|
|
126
136
|
}
|
|
127
|
-
|
|
137
|
+
setSegmentColor(segments, colorPalette) {
|
|
128
138
|
segments.style('fill', (d, i) => colorPalette[i % colorPalette.length]);
|
|
129
139
|
}
|
|
130
140
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Area as IArea } from "d3-shape";
|
|
2
|
+
import { LineLikeGeneratorMiddleware } from "../lineLike/generatorMiddleware/lineLikeGeneratorMiddleware";
|
|
3
|
+
import { MdtChartsDataRow } from "../../../config/config";
|
|
4
|
+
import { CoordinateGetter } from "../lineLike/generatorFactory/lineLikeGeneratorFactory";
|
|
5
|
+
interface AreaGeneratorOptions {
|
|
6
|
+
middlewares: LineLikeGeneratorMiddleware[];
|
|
7
|
+
}
|
|
8
|
+
export declare class AreaGenerator {
|
|
9
|
+
private readonly options;
|
|
10
|
+
constructor(options: AreaGeneratorOptions);
|
|
11
|
+
getVertical(xValue: CoordinateGetter, y0Value: CoordinateGetter, y1Value: CoordinateGetter): IArea<MdtChartsDataRow>;
|
|
12
|
+
getHorizontal(x0Value: CoordinateGetter, x1Value: CoordinateGetter, yValue: CoordinateGetter): IArea<MdtChartsDataRow>;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { area } from "d3-shape";
|
|
2
|
+
export class AreaGenerator {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
this.options = options;
|
|
5
|
+
}
|
|
6
|
+
getVertical(xValue, y0Value, y1Value) {
|
|
7
|
+
const generator = area()
|
|
8
|
+
.x(xValue)
|
|
9
|
+
.y0(y0Value)
|
|
10
|
+
.y1(y1Value);
|
|
11
|
+
this.options.middlewares.forEach(middleware => middleware.handle(generator));
|
|
12
|
+
return generator;
|
|
13
|
+
}
|
|
14
|
+
getHorizontal(x0Value, x1Value, yValue) {
|
|
15
|
+
const generator = area()
|
|
16
|
+
.x0(x0Value)
|
|
17
|
+
.x1(x1Value)
|
|
18
|
+
.y(yValue);
|
|
19
|
+
this.options.middlewares.forEach(middleware => middleware.handle(generator));
|
|
20
|
+
return generator;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Area as IArea } from 'd3-shape';
|
|
2
|
-
import { MdtChartsDataRow
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { MdtChartsDataRow } from '../../../config/config';
|
|
3
|
+
import { LineLikeGeneratorFactoryOptions } from '../lineLike/generatorFactory/lineLikeGeneratorFactory';
|
|
4
|
+
export declare class AreaGeneratorFactory {
|
|
5
|
+
private readonly options;
|
|
6
|
+
constructor(options: LineLikeGeneratorFactoryOptions);
|
|
7
|
+
getAreaGenerator(valueFieldName: string): IArea<MdtChartsDataRow>;
|
|
8
|
+
getSegmentedAreaGenerator(): IArea<MdtChartsDataRow>;
|
|
9
9
|
}
|
|
@@ -1,40 +1,39 @@
|
|
|
1
|
-
import { area } from 'd3-shape';
|
|
2
1
|
import { Scale } from "../../features/scale/scale";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.y1(d => scales.value(d[valueFieldName]) + margin.top);
|
|
10
|
-
if (keyAxisOrient === 'left' || keyAxisOrient === 'right')
|
|
11
|
-
return area()
|
|
12
|
-
.x0(d => scales.value(0) + margin.left)
|
|
13
|
-
.x1(d => scales.value(d[valueFieldName]) + margin.left)
|
|
14
|
-
.y(d => Scale.getScaledValue(scales.key, d[keyFieldName]) + margin.top);
|
|
2
|
+
import { LineLikeGeneratorDefinedMiddleware } from '../lineLike/generatorMiddleware/lineLikeGeneratorDefineMiddleware';
|
|
3
|
+
import { AreaGenerator } from './areaGenerator';
|
|
4
|
+
import { LineLikeGeneratorCurveMiddleware } from '../lineLike/generatorMiddleware/lineLikeGeneratorCurveMiddleware';
|
|
5
|
+
export class AreaGeneratorFactory {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.options = options;
|
|
15
8
|
}
|
|
16
|
-
|
|
9
|
+
getAreaGenerator(valueFieldName) {
|
|
10
|
+
const { keyAxisOrient, scales, keyFieldName, margin, shouldRender } = this.options;
|
|
11
|
+
const generator = new AreaGenerator({
|
|
12
|
+
middlewares: [
|
|
13
|
+
new LineLikeGeneratorCurveMiddleware({ curve: this.options.curve }),
|
|
14
|
+
new LineLikeGeneratorDefinedMiddleware({ definedFn: shouldRender, valueFieldNameGetter: () => valueFieldName, dataRowGetter: (d) => d })
|
|
15
|
+
]
|
|
16
|
+
});
|
|
17
17
|
if (keyAxisOrient === 'bottom' || keyAxisOrient === 'top') {
|
|
18
|
-
return
|
|
19
|
-
.x(d => Scale.getScaledValue(scales.key, d.data[keyFieldName]) + margin.left)
|
|
20
|
-
.y0(d => scales.value(d[0]) + margin.top)
|
|
21
|
-
.y1(d => scales.value(d[1]) + margin.top);
|
|
18
|
+
return generator.getVertical(d => Scale.getScaledValue(scales.key, d[keyFieldName]) + margin.left, d => scales.value(0) + margin.top, d => scales.value(d[valueFieldName]) + margin.top);
|
|
22
19
|
}
|
|
23
20
|
if (keyAxisOrient === 'left' || keyAxisOrient === 'right') {
|
|
24
|
-
return
|
|
25
|
-
.x0(d => scales.value(d[0]) + margin.left)
|
|
26
|
-
.x1(d => scales.value(d[1]) + margin.left)
|
|
27
|
-
.y(d => Scale.getScaledValue(scales.key, d.data[keyFieldName]) + margin.top);
|
|
21
|
+
return generator.getHorizontal(d => scales.value(0) + margin.left, d => scales.value(d[valueFieldName]) + margin.left, d => Scale.getScaledValue(scales.key, d[keyFieldName]) + margin.top);
|
|
28
22
|
}
|
|
29
23
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
getSegmentedAreaGenerator() {
|
|
25
|
+
const { keyAxisOrient, scales, margin, keyFieldName, shouldRender } = this.options;
|
|
26
|
+
const generator = new AreaGenerator({
|
|
27
|
+
middlewares: [
|
|
28
|
+
new LineLikeGeneratorCurveMiddleware({ curve: this.options.curve }),
|
|
29
|
+
new LineLikeGeneratorDefinedMiddleware({ definedFn: shouldRender, valueFieldNameGetter: (d) => d.fieldName, dataRowGetter: (d) => d.data })
|
|
30
|
+
]
|
|
31
|
+
});
|
|
32
|
+
if (keyAxisOrient === 'bottom' || keyAxisOrient === 'top') {
|
|
33
|
+
return generator.getVertical(d => Scale.getScaledValue(scales.key, d.data[keyFieldName]) + margin.left, d => scales.value(d[0]) + margin.top, d => scales.value(d[1]) + margin.top);
|
|
34
|
+
}
|
|
35
|
+
if (keyAxisOrient === 'left' || keyAxisOrient === 'right') {
|
|
36
|
+
return generator.getHorizontal(d => scales.value(d[0]) + margin.left, d => scales.value(d[1]) + margin.left, d => Scale.getScaledValue(scales.key, d.data[keyFieldName]) + margin.top);
|
|
37
|
+
}
|
|
39
38
|
}
|
|
40
39
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Scale } from "../../features/scale/scale";
|
|
2
2
|
import { Helper } from "../../helpers/helper";
|
|
3
|
-
import { HatchPatternDef } from "../../block/defs";
|
|
3
|
+
import { HatchPatternDef } from "../../block/defs/hatchPattern";
|
|
4
4
|
export class BarHelper {
|
|
5
5
|
static getGroupedBarAttrs(keyAxisOrient, scales, margin, keyField, valueFieldName, blockSize, barIndex, barsAmount, barSettings) {
|
|
6
6
|
const attrs = {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { MdtChartsDataRow } from "../../../../config/config";
|
|
2
|
-
export interface
|
|
2
|
+
export interface SegmentWithFieldName {
|
|
3
|
+
fieldName: string;
|
|
4
|
+
}
|
|
5
|
+
export interface StackedDataRow extends SegmentWithFieldName {
|
|
3
6
|
0: number;
|
|
4
7
|
1: number;
|
|
5
8
|
data: MdtChartsDataRow;
|
|
@@ -10,4 +13,3 @@ export declare class DataStacker {
|
|
|
10
13
|
getStackedData(rawData: MdtChartsDataRow[], valueFields: string[]): StackedDataFull;
|
|
11
14
|
}
|
|
12
15
|
export declare function getStackedDataWithOwn(rawData: MdtChartsDataRow[], valueFields: string[]): StackedDataFull;
|
|
13
|
-
export declare function getStackedDataWithD3(rawData: MdtChartsDataRow[], valueFields: string[]): StackedDataFull;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { stack } from "d3-shape";
|
|
2
1
|
import { DataStackerService } from "./dataStackerService";
|
|
3
2
|
export class DataStacker {
|
|
4
3
|
constructor() {
|
|
@@ -15,7 +14,8 @@ export class DataStacker {
|
|
|
15
14
|
fieldStack.push({
|
|
16
15
|
"0": value0,
|
|
17
16
|
"1": value1,
|
|
18
|
-
data: dataRow
|
|
17
|
+
data: dataRow,
|
|
18
|
+
fieldName: vField
|
|
19
19
|
});
|
|
20
20
|
});
|
|
21
21
|
stackedData.push(fieldStack);
|
|
@@ -27,6 +27,3 @@ export function getStackedDataWithOwn(rawData, valueFields) {
|
|
|
27
27
|
const stacker = new DataStacker();
|
|
28
28
|
return stacker.getStackedData(rawData, valueFields);
|
|
29
29
|
}
|
|
30
|
-
export function getStackedDataWithD3(rawData, valueFields) {
|
|
31
|
-
return stack().keys(valueFields)(rawData);
|
|
32
|
-
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { SeriesPoint } from 'd3-shape';
|
|
2
1
|
import { BaseType, Selection } from 'd3-selection';
|
|
3
2
|
import { BlockMargin, Field, LineLikeChartSettings, Orient, TwoDimensionalChartModel } from "../../../model/model";
|
|
4
3
|
import { Scales } from "../../features/scale/scale";
|
|
@@ -8,11 +7,6 @@ import { Pipeline } from '../../helpers/pipeline/Pipeline';
|
|
|
8
7
|
interface LineChartOptions {
|
|
9
8
|
staticSettings: LineLikeChartSettings;
|
|
10
9
|
}
|
|
11
|
-
export interface Segment extends SeriesPoint<{
|
|
12
|
-
[p: string]: number;
|
|
13
|
-
}> {
|
|
14
|
-
fieldName: string;
|
|
15
|
-
}
|
|
16
10
|
export declare class Line {
|
|
17
11
|
private options;
|
|
18
12
|
static readonly lineChartClass = "line";
|
|
@@ -39,7 +39,7 @@ export class Line {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
renderGrouped(block, scales, data, keyField, margin, keyAxisOrient, chart) {
|
|
42
|
-
const generatorFactory = new LineGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, curve: this.options.staticSettings.shape.curve.type,
|
|
42
|
+
const generatorFactory = new LineGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, curve: this.options.staticSettings.shape.curve.type, shouldRender: chart.lineLikeViewOptions.renderForKey });
|
|
43
43
|
chart.data.valueFields.forEach((valueField, valueIndex) => {
|
|
44
44
|
const lineGenerator = generatorFactory.getLineGenerator(valueField.name);
|
|
45
45
|
let path = block.svg.getChartGroup(chart.index)
|
|
@@ -57,7 +57,7 @@ export class Line {
|
|
|
57
57
|
}
|
|
58
58
|
renderSegmented(block, scales, data, keyField, margin, keyAxisOrient, chart) {
|
|
59
59
|
let stackedData = getStackedData(data, chart);
|
|
60
|
-
const generatorFactory = new LineGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, curve: this.options.staticSettings.shape.curve.type,
|
|
60
|
+
const generatorFactory = new LineGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, curve: this.options.staticSettings.shape.curve.type, shouldRender: chart.lineLikeViewOptions.renderForKey });
|
|
61
61
|
const lineGenerator = generatorFactory.getSegmentedLineGenerator();
|
|
62
62
|
let lines = block.svg.getChartGroup(chart.index)
|
|
63
63
|
.selectAll(`.${this.lineChartClass}${Helper.getCssClassesLine(chart.cssClasses)}`)
|
|
@@ -80,7 +80,7 @@ export class Line {
|
|
|
80
80
|
}
|
|
81
81
|
updateGrouped(block, scales, newData, keyField, margin, keyAxisOrient, chart) {
|
|
82
82
|
const promises = [];
|
|
83
|
-
const generatorFactory = new LineGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, curve: this.options.staticSettings.shape.curve.type,
|
|
83
|
+
const generatorFactory = new LineGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, curve: this.options.staticSettings.shape.curve.type, shouldRender: chart.lineLikeViewOptions.renderForKey });
|
|
84
84
|
chart.data.valueFields.forEach((valueField, valueFieldIndex) => {
|
|
85
85
|
const lineGenerator = generatorFactory.getLineGenerator(valueField.name);
|
|
86
86
|
const lineObject = block.svg.getChartGroup(chart.index)
|
|
@@ -93,7 +93,7 @@ export class Line {
|
|
|
93
93
|
}
|
|
94
94
|
updateSegmented(block, scales, newData, keyField, margin, keyAxisOrient, chart) {
|
|
95
95
|
let stackedData = getStackedData(newData, chart);
|
|
96
|
-
const generatorFactory = new LineGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, curve: this.options.staticSettings.shape.curve.type,
|
|
96
|
+
const generatorFactory = new LineGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, curve: this.options.staticSettings.shape.curve.type, shouldRender: chart.lineLikeViewOptions.renderForKey });
|
|
97
97
|
const lineGenerator = generatorFactory.getSegmentedLineGenerator();
|
|
98
98
|
const lines = block.svg.getChartGroup(chart.index)
|
|
99
99
|
.selectAll(`path.${this.lineChartClass}${Helper.getCssClassesLine(chart.cssClasses)}`)
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import { Line as ILine } from "d3-shape";
|
|
2
1
|
import { MdtChartsDataRow } from "../../../config/config";
|
|
3
|
-
import {
|
|
2
|
+
import { LineLikeGeneratorMiddleware } from "../lineLike/generatorMiddleware/lineLikeGeneratorMiddleware";
|
|
3
|
+
import { CoordinateGetter } from "../lineLike/generatorFactory/lineLikeGeneratorFactory";
|
|
4
4
|
interface LineGeneratorOptions {
|
|
5
|
-
|
|
5
|
+
middlewares: LineLikeGeneratorMiddleware[];
|
|
6
6
|
}
|
|
7
|
-
declare type CoordinateGetter = (dataRow: MdtChartsDataRow) => number;
|
|
8
7
|
export declare class LineGenerator {
|
|
9
8
|
private options;
|
|
10
|
-
private readonly curvies;
|
|
11
9
|
constructor(options: LineGeneratorOptions);
|
|
12
|
-
get(xValue: CoordinateGetter, yValue: CoordinateGetter):
|
|
13
|
-
private setCurve;
|
|
10
|
+
get(xValue: CoordinateGetter, yValue: CoordinateGetter): import("d3-shape").Line<MdtChartsDataRow>;
|
|
14
11
|
}
|
|
15
12
|
export {};
|
|
@@ -1,27 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LineCurveType } from "../../../model/model";
|
|
1
|
+
import { line } from "d3-shape";
|
|
3
2
|
export class LineGenerator {
|
|
4
3
|
constructor(options) {
|
|
5
4
|
this.options = options;
|
|
6
|
-
this.curvies = {
|
|
7
|
-
[LineCurveType.monotoneX]: curveMonotoneX,
|
|
8
|
-
[LineCurveType.monotoneY]: curveMonotoneY,
|
|
9
|
-
[LineCurveType.basis]: curveBasis,
|
|
10
|
-
[LineCurveType.none]: undefined
|
|
11
|
-
};
|
|
12
5
|
}
|
|
13
6
|
get(xValue, yValue) {
|
|
14
7
|
const generator = line()
|
|
15
8
|
.x(xValue)
|
|
16
9
|
.y(yValue);
|
|
17
|
-
this.
|
|
10
|
+
this.options.middlewares.forEach(middleware => middleware.handle(generator));
|
|
18
11
|
return generator;
|
|
19
12
|
}
|
|
20
|
-
setCurve(generator) {
|
|
21
|
-
if (this.options.curve != null) {
|
|
22
|
-
const curve = this.curvies[this.options.curve];
|
|
23
|
-
if (curve)
|
|
24
|
-
generator.curve(curve);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
13
|
}
|
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
import { Line as ILine } from 'd3-shape';
|
|
2
2
|
import { MdtChartsDataRow } from '../../../config/config';
|
|
3
|
-
import {
|
|
4
|
-
import { Scales } from "../../features/scale/scale";
|
|
3
|
+
import { TwoDimensionalChartModel } from "../../../model/model";
|
|
5
4
|
import { Pipeline } from '../../helpers/pipeline/Pipeline';
|
|
6
5
|
import { BaseType, Selection } from 'd3-selection';
|
|
7
|
-
import { Segment } from '
|
|
8
|
-
|
|
9
|
-
keyAxisOrient: Orient;
|
|
10
|
-
scales: Scales;
|
|
11
|
-
keyFieldName: string;
|
|
12
|
-
margin: BlockMargin;
|
|
13
|
-
curve: LineCurveType;
|
|
14
|
-
shouldRenderLine: LineLikeChartRenderOptions;
|
|
15
|
-
}
|
|
6
|
+
import { Segment } from '../lineLike/generatorMiddleware/lineLikeGeneratorDefineMiddleware';
|
|
7
|
+
import { LineLikeGeneratorFactoryOptions } from '../lineLike/generatorFactory/lineLikeGeneratorFactory';
|
|
16
8
|
export declare class LineGeneratorFactory {
|
|
17
9
|
private options;
|
|
18
|
-
constructor(options:
|
|
10
|
+
constructor(options: LineLikeGeneratorFactoryOptions);
|
|
19
11
|
getLineGenerator(valueFieldName: string): ILine<MdtChartsDataRow>;
|
|
20
12
|
getSegmentedLineGenerator(): ILine<MdtChartsDataRow>;
|
|
21
13
|
}
|
|
22
14
|
export declare function onLineChartInit(creatingPipeline: Pipeline<Selection<SVGElement, any, BaseType, any>, TwoDimensionalChartModel>): void;
|
|
23
15
|
export declare function applyLineDash(lineSelection: Selection<SVGElement, any, BaseType, any>, dashSize: number, gapSize: number): Selection<SVGElement, any, BaseType, any>;
|
|
24
16
|
export declare function getStackedData(data: MdtChartsDataRow[], chart: TwoDimensionalChartModel): Segment[][];
|
|
25
|
-
export {};
|
|
@@ -1,35 +1,47 @@
|
|
|
1
1
|
import { stack } from 'd3-shape';
|
|
2
2
|
import { Scale } from "../../features/scale/scale";
|
|
3
3
|
import { LineGenerator } from './lineGenerator';
|
|
4
|
+
import { LineLikeGeneratorCurveMiddleware } from '../lineLike/generatorMiddleware/lineLikeGeneratorCurveMiddleware';
|
|
5
|
+
import { LineLikeGeneratorDefinedMiddleware } from '../lineLike/generatorMiddleware/lineLikeGeneratorDefineMiddleware';
|
|
4
6
|
export class LineGeneratorFactory {
|
|
5
7
|
constructor(options) {
|
|
6
8
|
this.options = options;
|
|
7
9
|
}
|
|
8
10
|
getLineGenerator(valueFieldName) {
|
|
9
|
-
const { keyAxisOrient, scales, keyFieldName, margin,
|
|
10
|
-
const generator = new LineGenerator({
|
|
11
|
+
const { keyAxisOrient, scales, keyFieldName, margin, shouldRender } = this.options;
|
|
12
|
+
const generator = new LineGenerator({
|
|
13
|
+
middlewares: [
|
|
14
|
+
new LineLikeGeneratorCurveMiddleware({ curve: this.options.curve }),
|
|
15
|
+
new LineLikeGeneratorDefinedMiddleware({ definedFn: shouldRender, valueFieldNameGetter: () => valueFieldName, dataRowGetter: (d) => d })
|
|
16
|
+
]
|
|
17
|
+
});
|
|
11
18
|
if (keyAxisOrient === 'bottom' || keyAxisOrient === 'top') {
|
|
12
|
-
return generator.get(d => Scale.getScaledValue(scales.key, d[keyFieldName]) + margin.left, d => scales.value(d[valueFieldName]) + margin.top)
|
|
19
|
+
return generator.get(d => Scale.getScaledValue(scales.key, d[keyFieldName]) + margin.left, d => scales.value(d[valueFieldName]) + margin.top);
|
|
13
20
|
}
|
|
14
21
|
if (keyAxisOrient === 'left' || keyAxisOrient === 'right') {
|
|
15
|
-
return generator.get(d => scales.value(d[valueFieldName]) + margin.left, d => Scale.getScaledValue(scales.key, d[keyFieldName]) + margin.top)
|
|
22
|
+
return generator.get(d => scales.value(d[valueFieldName]) + margin.left, d => Scale.getScaledValue(scales.key, d[keyFieldName]) + margin.top);
|
|
16
23
|
}
|
|
17
24
|
}
|
|
18
25
|
getSegmentedLineGenerator() {
|
|
19
|
-
const { keyAxisOrient, scales, keyFieldName, margin,
|
|
20
|
-
const generator = new LineGenerator({
|
|
26
|
+
const { keyAxisOrient, scales, keyFieldName, margin, shouldRender } = this.options;
|
|
27
|
+
const generator = new LineGenerator({
|
|
28
|
+
middlewares: [
|
|
29
|
+
new LineLikeGeneratorCurveMiddleware({ curve: this.options.curve }),
|
|
30
|
+
new LineLikeGeneratorDefinedMiddleware({ definedFn: shouldRender, valueFieldNameGetter: (d) => d.fieldName, dataRowGetter: (d) => d.data })
|
|
31
|
+
]
|
|
32
|
+
});
|
|
21
33
|
if (keyAxisOrient === 'bottom' || keyAxisOrient === 'top') {
|
|
22
|
-
return generator.get(d => Scale.getScaledValue(scales.key, d.data[keyFieldName]) + margin.left, d => scales.value(d[1]) + margin.top)
|
|
34
|
+
return generator.get(d => Scale.getScaledValue(scales.key, d.data[keyFieldName]) + margin.left, d => scales.value(d[1]) + margin.top);
|
|
23
35
|
}
|
|
24
36
|
if (keyAxisOrient === 'left' || keyAxisOrient === 'right') {
|
|
25
|
-
return generator.get(d => scales.value(d[1]) + margin.left, d => Scale.getScaledValue(scales.key, d.data[keyFieldName]) + margin.top)
|
|
37
|
+
return generator.get(d => scales.value(d[1]) + margin.left, d => Scale.getScaledValue(scales.key, d.data[keyFieldName]) + margin.top);
|
|
26
38
|
}
|
|
27
39
|
}
|
|
28
40
|
}
|
|
29
41
|
export function onLineChartInit(creatingPipeline) {
|
|
30
42
|
creatingPipeline.push((path, chart) => {
|
|
31
|
-
if (chart.
|
|
32
|
-
return applyLineDash(path, chart.
|
|
43
|
+
if (chart.lineLikeViewOptions.dashedStyles.on) {
|
|
44
|
+
return applyLineDash(path, chart.lineLikeViewOptions.dashedStyles.dashSize, chart.lineLikeViewOptions.dashedStyles.gapSize);
|
|
33
45
|
}
|
|
34
46
|
return path;
|
|
35
47
|
});
|
package/lib/engine/twoDimensionalNotation/lineLike/generatorFactory/lineLikeGeneratorFactory.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MdtChartsDataRow } from "../../../../config/config";
|
|
2
|
+
import { BlockMargin, LineCurveType, LineLikeChartRenderFn, Orient } from "../../../../model/model";
|
|
3
|
+
import { Scales } from "../../../features/scale/scale";
|
|
4
|
+
export declare type CoordinateGetter = (dataRow: MdtChartsDataRow) => number;
|
|
5
|
+
export interface LineLikeGeneratorFactoryOptions {
|
|
6
|
+
keyAxisOrient: Orient;
|
|
7
|
+
scales: Scales;
|
|
8
|
+
keyFieldName: string;
|
|
9
|
+
margin: BlockMargin;
|
|
10
|
+
curve: LineCurveType;
|
|
11
|
+
shouldRender: LineLikeChartRenderFn;
|
|
12
|
+
}
|
package/lib/engine/twoDimensionalNotation/lineLike/generatorFactory/lineLikeGeneratorFactory.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Area, Line } from "d3-shape";
|
|
2
|
+
import { LineCurveType } from "../../../../model/model";
|
|
3
|
+
import { LineLikeGeneratorMiddleware } from "./lineLikeGeneratorMiddleware";
|
|
4
|
+
import { MdtChartsDataRow } from "../../../../main";
|
|
5
|
+
interface LineLikeGeneratorCurveMiddlewareOptions {
|
|
6
|
+
curve?: LineCurveType;
|
|
7
|
+
}
|
|
8
|
+
export declare class LineLikeGeneratorCurveMiddleware implements LineLikeGeneratorMiddleware {
|
|
9
|
+
private options;
|
|
10
|
+
private readonly curvies;
|
|
11
|
+
constructor(options: LineLikeGeneratorCurveMiddlewareOptions);
|
|
12
|
+
handle(generator: Line<MdtChartsDataRow> | Area<MdtChartsDataRow>): Line<MdtChartsDataRow> | Area<MdtChartsDataRow>;
|
|
13
|
+
}
|
|
14
|
+
export {};
|