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
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { select } from 'd3-selection';
|
|
2
|
+
import { easeLinear } from 'd3-ease';
|
|
3
|
+
import { interrupt } from 'd3-transition';
|
|
4
|
+
import { DonutHelper } from '../polarNotation/donut/DonutHelper';
|
|
5
|
+
import { DomHelper, SelectionCondition } from '../helpers/domHelper';
|
|
6
|
+
import { Donut } from '../polarNotation/donut/donut';
|
|
7
|
+
import { MarkDot } from '../features/markDots/markDot';
|
|
8
|
+
import { Helper } from '../helpers/helper';
|
|
9
|
+
import * as chroma from 'chroma-js';
|
|
10
|
+
export class ElementHighlighter {
|
|
11
|
+
static toggleActivityStyle(elementSelection, isActive) {
|
|
12
|
+
elementSelection.classed(this.inactiveElemClass, !isActive);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @param blurPercent процент от макс. размера блюра
|
|
16
|
+
*/
|
|
17
|
+
static setShadowFilter(elemSelection, blurPercent = 1) {
|
|
18
|
+
const maxBlurSize = 8;
|
|
19
|
+
elemSelection.each(function () {
|
|
20
|
+
const elemFill = select(this).style('fill') || 'rgb(0, 0, 0)';
|
|
21
|
+
const colorInRgb = chroma(elemFill).css();
|
|
22
|
+
const shadowColor = Helper.getRgbaFromRgb(colorInRgb, 0.6);
|
|
23
|
+
select(this).style('filter', `drop-shadow(0px 0px ${blurPercent * maxBlurSize}px ${shadowColor})`);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
static removeFilter(elemSelection) {
|
|
27
|
+
elemSelection.style('filter', null);
|
|
28
|
+
}
|
|
29
|
+
static removeShadowClone(block, keyFieldName, selectedSegment, margin, blockSize, donutThickness) {
|
|
30
|
+
const shadowClone = Donut.getAllArcShadows(block)
|
|
31
|
+
.filter((d) => d.data[keyFieldName] === selectedSegment.datum().data[keyFieldName]);
|
|
32
|
+
this.removeFilter(shadowClone.select('path'));
|
|
33
|
+
this.toggleDonutHighlightState(shadowClone, margin, blockSize, donutThickness, block.transitionManager.durations.higlightedScale, false)
|
|
34
|
+
.then(() => shadowClone.remove());
|
|
35
|
+
}
|
|
36
|
+
static removeCloneForElem(block, keyFieldName, selectedSegment) {
|
|
37
|
+
const clone = Donut.getAllArcClones(block)
|
|
38
|
+
.filter((d) => d.data[keyFieldName] === selectedSegment.datum().data[keyFieldName]);
|
|
39
|
+
clone.remove();
|
|
40
|
+
}
|
|
41
|
+
static removeDonutArcClones(block) {
|
|
42
|
+
Donut.getAllArcClones(block).remove();
|
|
43
|
+
Donut.getAllArcShadows(block).remove();
|
|
44
|
+
}
|
|
45
|
+
static renderArcCloneAndHighlight(block, margin, arcSelection, blockSize, donutThickness) {
|
|
46
|
+
const clone = this.makeArcClone(arcSelection, block);
|
|
47
|
+
const shadowClone = this.makeArcShadow(arcSelection, block);
|
|
48
|
+
this.toggleDonutHighlightState(arcSelection, margin, blockSize, donutThickness, block.transitionManager.durations.higlightedScale, true);
|
|
49
|
+
this.toggleDonutHighlightState(clone, margin, blockSize, donutThickness, block.transitionManager.durations.higlightedScale, true);
|
|
50
|
+
this.toggleDonutHighlightState(shadowClone, margin, blockSize, donutThickness, block.transitionManager.durations.higlightedScale, true);
|
|
51
|
+
this.setShadowFilter(shadowClone.select('path'), donutThickness / 60);
|
|
52
|
+
}
|
|
53
|
+
static toggleDonutHighlightState(segment, margin, blockSize, donutThickness, transitionDuration, on) {
|
|
54
|
+
return new Promise(resolve => {
|
|
55
|
+
let scaleSize = 0;
|
|
56
|
+
if (on)
|
|
57
|
+
scaleSize = 5; // Если нужно выделить сегмент, то scaleSize не равен нулю и отображается увеличенным
|
|
58
|
+
segment
|
|
59
|
+
.select('path')
|
|
60
|
+
.interrupt()
|
|
61
|
+
.transition()
|
|
62
|
+
.duration(transitionDuration)
|
|
63
|
+
.on('end', () => resolve(''))
|
|
64
|
+
.ease(easeLinear)
|
|
65
|
+
.attr('d', (d, i) => DonutHelper.getArcGeneratorObject(blockSize, margin, donutThickness)
|
|
66
|
+
.outerRadius(DonutHelper.getOuterRadius(margin, blockSize) + scaleSize)
|
|
67
|
+
.innerRadius(DonutHelper.getOuterRadius(margin, blockSize) - donutThickness - scaleSize)(d, i));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
static removeDonutHighlightingByKeys(arcSegments, keyFieldName, keyValues, margin, blockSize, donutThickness) {
|
|
71
|
+
const segments = DomHelper.getChartElementsByKeys(arcSegments, true, keyFieldName, keyValues, SelectionCondition.Exclude);
|
|
72
|
+
this.toggleDonutHighlightState(segments, margin, blockSize, donutThickness, 0, false);
|
|
73
|
+
}
|
|
74
|
+
static setInactiveFor2D(block, keyFieldName, charts) {
|
|
75
|
+
charts.forEach(chart => {
|
|
76
|
+
const elems = DomHelper.get2DChartElements(block, chart);
|
|
77
|
+
if (block.filterEventManager.getSelectedKeys().length === 0) {
|
|
78
|
+
this.toggleActivityStyle(elems, true);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const unselectedElems = DomHelper.getChartElementsByKeys(elems, chart.isSegmented, keyFieldName, block.filterEventManager.getSelectedKeys(), SelectionCondition.Exclude);
|
|
82
|
+
const selectedElems = DomHelper.getChartElementsByKeys(elems, chart.isSegmented, keyFieldName, block.filterEventManager.getSelectedKeys());
|
|
83
|
+
this.toggleActivityStyle(unselectedElems, false);
|
|
84
|
+
this.toggleActivityStyle(selectedElems, true);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
static toggleMarkDotVisible(markDots, isHighlight) {
|
|
89
|
+
markDots.classed(MarkDot.hiddenDotClass, !isHighlight);
|
|
90
|
+
}
|
|
91
|
+
static remove2DChartsFullHighlighting(block, charts, transitionDuration = 0) {
|
|
92
|
+
charts.forEach(chart => {
|
|
93
|
+
const elems = DomHelper.get2DChartElements(block, chart);
|
|
94
|
+
if (chart.type !== 'bar' && !chart.markersOptions.show)
|
|
95
|
+
elems.classed(MarkDot.hiddenDotClass, true);
|
|
96
|
+
this.toggle2DElements(elems, false, chart.type, transitionDuration);
|
|
97
|
+
this.toggleActivityStyle(elems, true);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
static removeUnselected2DHighlight(block, keyFieldName, charts, transitionDuration) {
|
|
101
|
+
charts.forEach(chart => {
|
|
102
|
+
const elems = DomHelper.get2DChartElements(block, chart);
|
|
103
|
+
const selectedElems = DomHelper.getChartElementsByKeys(elems, chart.isSegmented, keyFieldName, block.filterEventManager.getSelectedKeys(), SelectionCondition.Exclude);
|
|
104
|
+
if (chart.type !== 'bar' && !chart.markersOptions.show)
|
|
105
|
+
selectedElems.classed(MarkDot.hiddenDotClass, true);
|
|
106
|
+
this.toggle2DElements(selectedElems, false, chart.type, transitionDuration);
|
|
107
|
+
if (block.filterEventManager.getSelectedKeys().length > 0)
|
|
108
|
+
this.toggleActivityStyle(selectedElems, false);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
static toggle2DElements(elemSelection, isHighlight, chartType, transitionDuration) {
|
|
112
|
+
if (chartType === 'area' || chartType === 'line') {
|
|
113
|
+
elemSelection.call(this.toggleDot, isHighlight, transitionDuration);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
this.toggleBar(elemSelection, isHighlight);
|
|
117
|
+
if (isHighlight) {
|
|
118
|
+
elemSelection.each(function (d) {
|
|
119
|
+
const attrs = this.attrs;
|
|
120
|
+
const blurPercent = (attrs.orient === 'vertical' ? attrs.width : attrs.height) / 30; // 30px = max bar size, 13px - max blurSize
|
|
121
|
+
ElementHighlighter.setShadowFilter(select(this), blurPercent);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
this.removeFilter(elemSelection);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
static makeArcClone(segment, block) {
|
|
130
|
+
const clone = this.renderDonutSegmentClone(segment, `${Donut.arcCloneClass}`);
|
|
131
|
+
block.getSvg().select(`.${Donut.arcClonesGroupClass}`).append(function () { return clone.node(); });
|
|
132
|
+
return clone;
|
|
133
|
+
}
|
|
134
|
+
static makeArcShadow(segment, block) {
|
|
135
|
+
const shadowClone = this.renderDonutSegmentClone(segment, `${Donut.arcShadowClass}`);
|
|
136
|
+
block.getSvg().select(`.${Donut.arcShadowsGroupClass}`).append(function () { return shadowClone.node(); });
|
|
137
|
+
return shadowClone;
|
|
138
|
+
}
|
|
139
|
+
static renderDonutSegmentClone(segment, newClass) {
|
|
140
|
+
return segment
|
|
141
|
+
.clone(true)
|
|
142
|
+
.style('pointer-events', 'none')
|
|
143
|
+
.classed(`${Donut.arcCloneClass}`, false)
|
|
144
|
+
.classed(newClass, true)
|
|
145
|
+
.remove();
|
|
146
|
+
}
|
|
147
|
+
static toggleBar(elemSelection, isHighlight) {
|
|
148
|
+
const animationName = 'bar-highlight';
|
|
149
|
+
if (isHighlight) {
|
|
150
|
+
elemSelection.each(function () {
|
|
151
|
+
const attrs = this.attrs;
|
|
152
|
+
const handler = select(this).interrupt(animationName).transition(animationName).duration(200);
|
|
153
|
+
if (attrs.orient === 'vertical') {
|
|
154
|
+
handler
|
|
155
|
+
.attr('x', attrs.x - attrs.scaleSize)
|
|
156
|
+
.attr('width', attrs.width + attrs.scaleSize * 2);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
handler
|
|
160
|
+
.attr('y', attrs.y - attrs.scaleSize)
|
|
161
|
+
.attr('height', attrs.height + attrs.scaleSize * 2);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
elemSelection.each(function () {
|
|
167
|
+
const attrs = this.attrs;
|
|
168
|
+
const handler = select(this).interrupt(animationName).transition(animationName).duration(200);
|
|
169
|
+
handler
|
|
170
|
+
.attr('x', attrs.x)
|
|
171
|
+
.attr('width', attrs.width)
|
|
172
|
+
.attr('y', attrs.y)
|
|
173
|
+
.attr('height', attrs.height);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
static toggleDot(elementSelection, isScaled, transitionDuration = 0) {
|
|
178
|
+
const animationName = 'size-scale';
|
|
179
|
+
elementSelection.nodes().forEach(node => {
|
|
180
|
+
interrupt(node, animationName);
|
|
181
|
+
});
|
|
182
|
+
let elementsHandler = elementSelection;
|
|
183
|
+
if (transitionDuration > 0) {
|
|
184
|
+
elementsHandler = elementsHandler
|
|
185
|
+
.interrupt()
|
|
186
|
+
.transition(animationName)
|
|
187
|
+
.duration(transitionDuration)
|
|
188
|
+
.ease(easeLinear);
|
|
189
|
+
}
|
|
190
|
+
elementsHandler
|
|
191
|
+
.attr('r', isScaled ? 5 : 4)
|
|
192
|
+
.style('stroke-width', (isScaled ? 3.5 : 3) + 'px')
|
|
193
|
+
.each(function () {
|
|
194
|
+
select(this).style('fill', isScaled ? select(this).style('stroke') : 'white');
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
ElementHighlighter.inactiveElemClass = 'charts-opacity-inactive';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseType, Selection } from "d3-selection";
|
|
2
|
+
import { PieArcDatum } from "d3-shape";
|
|
3
|
+
import { MdtChartsDataRow, Size } from "../../config/config";
|
|
4
|
+
import { BlockMargin, DonutChartSettings, PolarOptionsModel, TwoDimensionalOptionsModel } from "../../model/model";
|
|
5
|
+
import { Block } from "../block/block";
|
|
6
|
+
export declare class SelectHighlighter {
|
|
7
|
+
static click2DHandler(multySelection: boolean, appendKey: boolean, keyValue: string, selectedKeys: string[], block: Block, options: TwoDimensionalOptionsModel): void;
|
|
8
|
+
static clickPolarHandler(multySelection: boolean, appendKey: boolean, selectedSegment: Selection<SVGGElement, PieArcDatum<MdtChartsDataRow>, BaseType, unknown>, selectedKeys: string[], margin: BlockMargin, blockSize: Size, block: Block, options: PolarOptionsModel, arcItems: Selection<SVGGElement, PieArcDatum<MdtChartsDataRow>, SVGGElement, unknown>, donutSettings: DonutChartSettings): void;
|
|
9
|
+
static clear2D(block: Block, options: TwoDimensionalOptionsModel): void;
|
|
10
|
+
static clearPolar(margin: BlockMargin, blockSize: Size, block: Block, options: PolarOptionsModel, arcItems: Selection<SVGGElement, PieArcDatum<MdtChartsDataRow>, SVGGElement, unknown>, donutSettings: DonutChartSettings): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { select } from "d3-selection";
|
|
2
|
+
import { Legend } from "../features/legend/legend";
|
|
3
|
+
import { DomHelper, SelectionCondition } from "../helpers/domHelper";
|
|
4
|
+
import { Donut } from "../polarNotation/donut/donut";
|
|
5
|
+
import { DonutHelper } from "../polarNotation/donut/DonutHelper";
|
|
6
|
+
import { ElementHighlighter } from "./elementHighlighter";
|
|
7
|
+
export class SelectHighlighter {
|
|
8
|
+
static click2DHandler(multySelection, appendKey, keyValue, selectedKeys, block, options) {
|
|
9
|
+
options.charts.forEach(chart => {
|
|
10
|
+
const selectedElements = DomHelper.getChartElementsByKeys(DomHelper.get2DChartElements(block, chart), chart.isSegmented, options.data.keyField.name, [keyValue]);
|
|
11
|
+
const elements = DomHelper.get2DChartElements(block, chart);
|
|
12
|
+
if (!appendKey) {
|
|
13
|
+
ElementHighlighter.toggle2DElements(selectedElements, false, chart.type, block.transitionManager.durations.markerHover);
|
|
14
|
+
if (chart.type !== 'bar' && !chart.markersOptions.show)
|
|
15
|
+
ElementHighlighter.toggleMarkDotVisible(selectedElements, false);
|
|
16
|
+
if (selectedKeys.length > 0) {
|
|
17
|
+
ElementHighlighter.toggleActivityStyle(selectedElements, false);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
ElementHighlighter.toggleActivityStyle(elements, true);
|
|
21
|
+
if (chart.type !== 'bar' && !chart.markersOptions.show)
|
|
22
|
+
ElementHighlighter.toggleMarkDotVisible(elements, false);
|
|
23
|
+
}
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (multySelection) {
|
|
27
|
+
ElementHighlighter.toggle2DElements(selectedElements, true, chart.type, block.transitionManager.durations.markerHover);
|
|
28
|
+
ElementHighlighter.toggleActivityStyle(selectedElements, true);
|
|
29
|
+
ElementHighlighter.toggleActivityStyle(DomHelper.getChartElementsByKeys(elements, chart.isSegmented, options.data.keyField.name, selectedKeys, SelectionCondition.Exclude), false);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
ElementHighlighter.toggle2DElements(DomHelper.getChartElementsByKeys(elements, chart.isSegmented, options.data.keyField.name, selectedKeys, SelectionCondition.Exclude), false, chart.type, block.transitionManager.durations.markerHover);
|
|
33
|
+
ElementHighlighter.toggleActivityStyle(elements, false);
|
|
34
|
+
if (chart.type !== 'bar' && !chart.markersOptions.show)
|
|
35
|
+
ElementHighlighter.toggleMarkDotVisible(elements, false);
|
|
36
|
+
ElementHighlighter.toggleActivityStyle(selectedElements, true);
|
|
37
|
+
ElementHighlighter.toggle2DElements(selectedElements, true, chart.type, block.transitionManager.durations.markerHover);
|
|
38
|
+
}
|
|
39
|
+
if (chart.type !== 'bar' && !chart.markersOptions.show)
|
|
40
|
+
ElementHighlighter.toggleMarkDotVisible(selectedElements, true);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
static clickPolarHandler(multySelection, appendKey, selectedSegment, selectedKeys, margin, blockSize, block, options, arcItems, donutSettings) {
|
|
44
|
+
const donutThickness = DonutHelper.getThickness(donutSettings, blockSize, margin);
|
|
45
|
+
if (!appendKey) {
|
|
46
|
+
ElementHighlighter.toggleDonutHighlightState(selectedSegment, margin, blockSize, donutThickness, block.transitionManager.durations.higlightedScale, false);
|
|
47
|
+
ElementHighlighter.removeCloneForElem(block, options.data.keyField.name, selectedSegment);
|
|
48
|
+
ElementHighlighter.removeShadowClone(block, options.data.keyField.name, selectedSegment, margin, blockSize, donutThickness);
|
|
49
|
+
if (selectedKeys.length > 0) {
|
|
50
|
+
ElementHighlighter.toggleActivityStyle(selectedSegment, false);
|
|
51
|
+
ElementHighlighter.toggleActivityStyle(Legend.getItemsByKeys(block, selectedKeys, SelectionCondition.Exclude), false);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
ElementHighlighter.toggleActivityStyle(Donut.getAllArcGroups(block), true);
|
|
55
|
+
ElementHighlighter.toggleActivityStyle(Legend.getItemsByKeys(block, [], SelectionCondition.Exclude), true);
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (multySelection) {
|
|
60
|
+
ElementHighlighter.removeCloneForElem(block, options.data.keyField.name, selectedSegment);
|
|
61
|
+
ElementHighlighter.removeShadowClone(block, options.data.keyField.name, selectedSegment, margin, blockSize, donutThickness);
|
|
62
|
+
ElementHighlighter.renderArcCloneAndHighlight(block, margin, selectedSegment, blockSize, donutThickness);
|
|
63
|
+
ElementHighlighter.toggleActivityStyle(selectedSegment, true);
|
|
64
|
+
ElementHighlighter.toggleActivityStyle(DomHelper.getChartElementsByKeys(Donut.getAllArcGroups(block), true, options.data.keyField.name, selectedKeys, SelectionCondition.Exclude), false);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
ElementHighlighter.removeDonutHighlightingByKeys(arcItems, options.data.keyField.name, selectedKeys, margin, blockSize, donutThickness);
|
|
68
|
+
ElementHighlighter.removeDonutArcClones(block);
|
|
69
|
+
ElementHighlighter.toggleActivityStyle(Donut.getAllArcGroups(block), false);
|
|
70
|
+
ElementHighlighter.toggleActivityStyle(selectedSegment, true);
|
|
71
|
+
ElementHighlighter.renderArcCloneAndHighlight(block, margin, selectedSegment, blockSize, donutThickness);
|
|
72
|
+
}
|
|
73
|
+
ElementHighlighter.toggleActivityStyle(Legend.getItemsByKeys(block, selectedKeys, SelectionCondition.Exclude), false);
|
|
74
|
+
ElementHighlighter.toggleActivityStyle(Legend.getItemsByKeys(block, selectedKeys), true);
|
|
75
|
+
}
|
|
76
|
+
static clear2D(block, options) {
|
|
77
|
+
options.charts.forEach(chart => {
|
|
78
|
+
const elements = DomHelper.get2DChartElements(block, chart);
|
|
79
|
+
ElementHighlighter.toggle2DElements(elements, false, chart.type, block.transitionManager.durations.markerHover);
|
|
80
|
+
ElementHighlighter.toggleActivityStyle(elements, true);
|
|
81
|
+
if (chart.type !== 'bar' && !chart.markersOptions.show)
|
|
82
|
+
ElementHighlighter.toggleMarkDotVisible(elements, false);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
static clearPolar(margin, blockSize, block, options, arcItems, donutSettings) {
|
|
86
|
+
const donutThickness = DonutHelper.getThickness(donutSettings, blockSize, margin);
|
|
87
|
+
ElementHighlighter.toggleDonutHighlightState(arcItems, margin, blockSize, donutThickness, block.transitionManager.durations.higlightedScale, false);
|
|
88
|
+
arcItems.each(function () {
|
|
89
|
+
ElementHighlighter.removeCloneForElem(block, options.data.keyField.name, select(this));
|
|
90
|
+
ElementHighlighter.removeShadowClone(block, options.data.keyField.name, select(this), margin, blockSize, donutThickness);
|
|
91
|
+
});
|
|
92
|
+
ElementHighlighter.toggleActivityStyle(Donut.getAllArcGroups(block), true);
|
|
93
|
+
ElementHighlighter.toggleActivityStyle(Legend.getItemsByKeys(block, [], SelectionCondition.Exclude), true);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Block } from './block/block';
|
|
2
|
+
import { Model } from '../model/model';
|
|
3
|
+
import { FilterCallback, FilterEventManager } from './filterManager/filterEventManager';
|
|
4
|
+
import { MdtChartsDataSource } from '../config/config';
|
|
5
|
+
export default class Engine {
|
|
6
|
+
private filterCallback;
|
|
7
|
+
private initializeSelected;
|
|
8
|
+
block: Block;
|
|
9
|
+
filterEventManager: FilterEventManager;
|
|
10
|
+
data: MdtChartsDataSource;
|
|
11
|
+
private chartId;
|
|
12
|
+
constructor(id: number, filterCallback: FilterCallback, initializeSelected: number[]);
|
|
13
|
+
render(model: Model, data: MdtChartsDataSource, parentElement: HTMLElement): void;
|
|
14
|
+
updateFullBlock(model: Model, data: MdtChartsDataSource): void;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
updateData(model: Model, newData: MdtChartsDataSource): void;
|
|
17
|
+
updateColors(model: Model): void;
|
|
18
|
+
private renderCharts;
|
|
19
|
+
private setFilterEventManager;
|
|
20
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Block } from './block/block';
|
|
2
|
+
import { ValueFormatter } from './valueFormatter';
|
|
3
|
+
import { ContentManager } from './contentManager';
|
|
4
|
+
import { FilterEventManager } from './filterManager/filterEventManager';
|
|
5
|
+
import { Helper } from './helpers/helper';
|
|
6
|
+
export default class Engine {
|
|
7
|
+
constructor(id, filterCallback, initializeSelected) {
|
|
8
|
+
this.filterCallback = filterCallback;
|
|
9
|
+
this.initializeSelected = initializeSelected;
|
|
10
|
+
this.chartId = id;
|
|
11
|
+
}
|
|
12
|
+
render(model, data, parentElement) {
|
|
13
|
+
this.data = data;
|
|
14
|
+
this.setFilterEventManager(model === null || model === void 0 ? void 0 : model.options);
|
|
15
|
+
this.block = new Block(model.blockCanvas.cssClass, parentElement, this.chartId, this.filterEventManager, model.transitions);
|
|
16
|
+
this.filterEventManager.setBlock(this.block);
|
|
17
|
+
this.block.renderWrapper(model.blockCanvas.size);
|
|
18
|
+
if (model.options) {
|
|
19
|
+
ValueFormatter.setFormatFunction(model.dataSettings.format.formatters);
|
|
20
|
+
this.renderCharts(model, this.data);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
updateFullBlock(model, data) {
|
|
24
|
+
this.destroy();
|
|
25
|
+
this.render(model, data, this.block.parentElement);
|
|
26
|
+
}
|
|
27
|
+
destroy() {
|
|
28
|
+
this.block.destroy();
|
|
29
|
+
}
|
|
30
|
+
updateData(model, newData) {
|
|
31
|
+
if (!newData) {
|
|
32
|
+
this.data = newData;
|
|
33
|
+
this.block.clearWrapper();
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
if (!this.data) {
|
|
37
|
+
this.data = newData;
|
|
38
|
+
this.updateFullBlock(model, this.data);
|
|
39
|
+
}
|
|
40
|
+
else if (!Helper.compareData(this.data, newData, model.options.data.dataSource)) {
|
|
41
|
+
for (let source in newData) {
|
|
42
|
+
this.data[source] = newData[source];
|
|
43
|
+
}
|
|
44
|
+
ContentManager.updateData(this.block, model, newData);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
updateColors(model) {
|
|
49
|
+
ContentManager.updateColors(this, model);
|
|
50
|
+
}
|
|
51
|
+
renderCharts(model, data) {
|
|
52
|
+
ContentManager.render(model, data, this);
|
|
53
|
+
}
|
|
54
|
+
setFilterEventManager(options) {
|
|
55
|
+
var _a, _b, _c;
|
|
56
|
+
let highlightIds = [];
|
|
57
|
+
if (this.initializeSelected instanceof Array && this.initializeSelected.length > 0)
|
|
58
|
+
highlightIds = [...this.initializeSelected];
|
|
59
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.data) === null || _a === void 0 ? void 0 : _a.dataSource)
|
|
60
|
+
this.filterEventManager = new FilterEventManager(this.filterCallback, this.data[options.data.dataSource], options.selectable, options.data.keyField.name, highlightIds);
|
|
61
|
+
else
|
|
62
|
+
this.filterEventManager = new FilterEventManager(this.filterCallback, [], options === null || options === void 0 ? void 0 : options.selectable, (_c = (_b = options === null || options === void 0 ? void 0 : options.data) === null || _b === void 0 ? void 0 : _b.keyField) === null || _c === void 0 ? void 0 : _c.name, highlightIds);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { MdtChartsDataRow } from '../../../config/config';
|
|
2
|
+
import { DataType } from '../../../designer/designerConfig';
|
|
3
|
+
import { Field } from "../../../model/model";
|
|
4
|
+
import { Block } from "../../block/block";
|
|
5
|
+
import { Translate } from "../../polarNotation/donut/donut";
|
|
6
|
+
export interface AggregatorInfo {
|
|
7
|
+
name: string;
|
|
8
|
+
value: number;
|
|
9
|
+
format: DataType;
|
|
10
|
+
}
|
|
11
|
+
export declare class Aggregator {
|
|
12
|
+
static readonly aggregatorValueClass = "aggregator-value";
|
|
13
|
+
private static readonly aggregatorNameClass;
|
|
14
|
+
private static readonly aggregatorObjectClass;
|
|
15
|
+
static render(block: Block, data: MdtChartsDataRow[], valueField: Field, innerRadius: number, translate: Translate, fontSize: number, pad: number): void;
|
|
16
|
+
static update(block: Block, data: MdtChartsDataRow[], valueField: Field, pad: number): void;
|
|
17
|
+
private static renderText;
|
|
18
|
+
private static updateText;
|
|
19
|
+
private static reCalculateAggregatorFontSize;
|
|
20
|
+
private static renderAggregatorObject;
|
|
21
|
+
private static renderWrapper;
|
|
22
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { sum } from 'd3-array';
|
|
2
|
+
import { interpolateNumber } from 'd3-interpolate';
|
|
3
|
+
import { Helper } from '../../helpers/helper';
|
|
4
|
+
import { ValueFormatter } from '../../valueFormatter';
|
|
5
|
+
export class Aggregator {
|
|
6
|
+
static render(block, data, valueField, innerRadius, translate, fontSize, pad) {
|
|
7
|
+
const aggregator = {
|
|
8
|
+
name: 'Сумма',
|
|
9
|
+
value: sum(data.map(d => d[valueField.name])),
|
|
10
|
+
format: valueField.format
|
|
11
|
+
};
|
|
12
|
+
this.renderText(block, innerRadius, aggregator, translate, fontSize, pad);
|
|
13
|
+
}
|
|
14
|
+
static update(block, data, valueField, pad) {
|
|
15
|
+
const aggregator = {
|
|
16
|
+
name: 'Сумма',
|
|
17
|
+
value: sum(data.map(d => d[valueField.name])),
|
|
18
|
+
format: valueField.format
|
|
19
|
+
};
|
|
20
|
+
this.updateText(block, aggregator, pad);
|
|
21
|
+
}
|
|
22
|
+
static renderText(block, innerRadius, aggregatorInfo, translate, fontSize, pad) {
|
|
23
|
+
if (innerRadius > 50) {
|
|
24
|
+
const aggregatorObject = this.renderAggregatorObject(block, innerRadius, translate);
|
|
25
|
+
const wrapper = this.renderWrapper(aggregatorObject);
|
|
26
|
+
wrapper
|
|
27
|
+
.append('div')
|
|
28
|
+
.attr('class', this.aggregatorValueClass)
|
|
29
|
+
.style('text-align', 'center')
|
|
30
|
+
.style('font-size', `${fontSize}px`)
|
|
31
|
+
.text(ValueFormatter.formatField(aggregatorInfo.format, aggregatorInfo.value));
|
|
32
|
+
wrapper
|
|
33
|
+
.append('div')
|
|
34
|
+
.attr('class', this.aggregatorNameClass)
|
|
35
|
+
.style('text-align', 'center')
|
|
36
|
+
.style('font-size', '18px')
|
|
37
|
+
.text(aggregatorInfo.name);
|
|
38
|
+
this.reCalculateAggregatorFontSize(aggregatorObject.node().getBoundingClientRect().width, block, pad);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
static updateText(block, newAggregator, pad) {
|
|
42
|
+
const aggregatorObject = block.getSvg()
|
|
43
|
+
.select(`.${this.aggregatorObjectClass}`);
|
|
44
|
+
const thisClass = this;
|
|
45
|
+
block.getSvg()
|
|
46
|
+
.select(`.${this.aggregatorValueClass}`)
|
|
47
|
+
.interrupt()
|
|
48
|
+
.transition()
|
|
49
|
+
.duration(block.transitionManager.durations.chartUpdate)
|
|
50
|
+
.tween("text", function () {
|
|
51
|
+
const oldValue = Helper.parseFormattedToNumber(this.textContent, ',');
|
|
52
|
+
const precision = Helper.calcDigitsAfterDot(newAggregator.value);
|
|
53
|
+
const interpolateFunc = interpolateNumber(oldValue, newAggregator.value);
|
|
54
|
+
return t => {
|
|
55
|
+
this.textContent = ValueFormatter.formatField(newAggregator.format, (interpolateFunc(t)).toFixed(precision));
|
|
56
|
+
thisClass.reCalculateAggregatorFontSize(aggregatorObject.node().getBoundingClientRect().width, block, pad);
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
static reCalculateAggregatorFontSize(wrapperSize, block, pad) {
|
|
61
|
+
const aggreggatorValue = block.getSvg()
|
|
62
|
+
.select(`.${this.aggregatorValueClass}`);
|
|
63
|
+
let fontSize = parseInt(aggreggatorValue.style('font-size'));
|
|
64
|
+
while (aggreggatorValue.node().getBoundingClientRect().width > wrapperSize - pad * 2 && fontSize > 15) {
|
|
65
|
+
aggreggatorValue.style('font-size', `${fontSize -= 2}px`);
|
|
66
|
+
}
|
|
67
|
+
while (aggreggatorValue.node().getBoundingClientRect().width < wrapperSize - pad * 2 && fontSize < 60) {
|
|
68
|
+
aggreggatorValue.style('font-size', `${fontSize += 2}px`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
static renderAggregatorObject(block, innerRadius, translate) {
|
|
72
|
+
return block.getSvg()
|
|
73
|
+
.append('foreignObject')
|
|
74
|
+
.attr('class', this.aggregatorObjectClass)
|
|
75
|
+
.attr('transform-origin', 'center')
|
|
76
|
+
.attr('width', innerRadius * 2)
|
|
77
|
+
.attr('height', innerRadius * 2)
|
|
78
|
+
.attr('transform', `translate(${translate.x - innerRadius}, ${translate.y - innerRadius})`)
|
|
79
|
+
.style('pointer-events', `none`);
|
|
80
|
+
}
|
|
81
|
+
static renderWrapper(aggregatorObject) {
|
|
82
|
+
return aggregatorObject
|
|
83
|
+
.append('xhtml:div')
|
|
84
|
+
.style('width', '100%')
|
|
85
|
+
.style('height', '100%')
|
|
86
|
+
.style('border-radius', '50%')
|
|
87
|
+
.style('display', 'flex')
|
|
88
|
+
.style('flex-direction', 'column')
|
|
89
|
+
.style('justify-content', 'center')
|
|
90
|
+
.style('align-items', 'center');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
Aggregator.aggregatorValueClass = 'aggregator-value';
|
|
94
|
+
Aggregator.aggregatorNameClass = 'aggregator-name';
|
|
95
|
+
Aggregator.aggregatorObjectClass = 'aggregator-object';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IAxisModel, IScaleModel } from "../../../model/model";
|
|
2
|
+
import { Block } from "../../block/block";
|
|
3
|
+
import { Scales } from "../scale/scale";
|
|
4
|
+
import { Size } from '../../../config/config';
|
|
5
|
+
export declare class Axis {
|
|
6
|
+
static axesClass: string;
|
|
7
|
+
static render(block: Block, scales: Scales, scaleModel: IScaleModel, axisModel: IAxisModel, blockSize: Size): void;
|
|
8
|
+
static update(block: Block, scales: Scales, scalesOptions: IScaleModel, axisModel: IAxisModel, blockSize: Size, keyDomainsEquality: boolean): void;
|
|
9
|
+
private static renderAxis;
|
|
10
|
+
private static updateValueAxis;
|
|
11
|
+
private static updateKeyAxis;
|
|
12
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Scale } from "../scale/scale";
|
|
2
|
+
import { AXIS_VERTICAL_LABEL_PADDING } from "../../../model/marginModel";
|
|
3
|
+
import { NamesHelper } from '../../helpers/namesHelper';
|
|
4
|
+
import { AxisHelper } from './axisHelper';
|
|
5
|
+
import { AxisLabelHelper } from './axisLabelDomHelper';
|
|
6
|
+
import { AxisDomHelper } from './axisDomHelper';
|
|
7
|
+
import { select } from 'd3-selection';
|
|
8
|
+
import { AxisLabelsEventManager } from './axisLabelsEventManager';
|
|
9
|
+
const MINIMAL_STEP_SIZE_FOR_WRAPPING = 38;
|
|
10
|
+
export class Axis {
|
|
11
|
+
static render(block, scales, scaleModel, axisModel, blockSize) {
|
|
12
|
+
if (axisModel.value.visibility)
|
|
13
|
+
this.renderAxis(block, scales.value, scaleModel.value, axisModel.value, blockSize);
|
|
14
|
+
if (axisModel.key.visibility)
|
|
15
|
+
this.renderAxis(block, scales.key, scaleModel.key, axisModel.key, blockSize);
|
|
16
|
+
}
|
|
17
|
+
static update(block, scales, scalesOptions, axisModel, blockSize, keyDomainsEquality) {
|
|
18
|
+
if (axisModel.value.visibility)
|
|
19
|
+
this.updateValueAxis(block, scales.value, scalesOptions.value, axisModel.value);
|
|
20
|
+
if (axisModel.key.visibility)
|
|
21
|
+
this.updateKeyAxis(block, scales.key, scalesOptions.key, axisModel.key, blockSize, keyDomainsEquality);
|
|
22
|
+
}
|
|
23
|
+
static renderAxis(block, scale, scaleOptions, axisOptions, blockSize) {
|
|
24
|
+
const axisGenerator = AxisHelper.getBaseAxisGenerator(axisOptions, scale, scaleOptions);
|
|
25
|
+
if (axisOptions.type === 'value' && (scaleOptions.type === 'linear' || scaleOptions.type === 'datetime'))
|
|
26
|
+
AxisHelper.setLabelsSettings(axisGenerator, scale.range(), scaleOptions);
|
|
27
|
+
const axisElement = block.getSvg()
|
|
28
|
+
.append('g')
|
|
29
|
+
.attr('class', `${this.axesClass} ${axisOptions.cssClass} data-label`);
|
|
30
|
+
AxisDomHelper.updateAxisElement(axisGenerator, axisElement, axisOptions.translate);
|
|
31
|
+
if (!axisOptions.labels.visible) {
|
|
32
|
+
AxisLabelHelper.hideLabels(axisElement);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (axisOptions.type === 'key') {
|
|
36
|
+
if (axisOptions.labels.position === 'rotated' && (axisOptions.orient === 'top' || axisOptions.orient === 'bottom'))
|
|
37
|
+
AxisLabelHelper.rotateLabels(axisElement, axisOptions.orient);
|
|
38
|
+
if ((axisOptions.orient === 'left' || axisOptions.orient === 'right') && Scale.getScaleStep(scale) >= MINIMAL_STEP_SIZE_FOR_WRAPPING)
|
|
39
|
+
axisElement.selectAll('.tick text').call(AxisLabelHelper.wrapHandler, axisOptions.labels.maxSize);
|
|
40
|
+
else
|
|
41
|
+
AxisLabelHelper.cropLabels(block, scale, scaleOptions, axisOptions, blockSize);
|
|
42
|
+
AxisLabelHelper.alignLabelsInKeyAxis(axisOptions, axisElement);
|
|
43
|
+
AxisLabelsEventManager.setHoverEvents(block, axisElement);
|
|
44
|
+
}
|
|
45
|
+
if (axisOptions.labels.defaultTooltip)
|
|
46
|
+
AxisLabelHelper.setTitles(axisElement);
|
|
47
|
+
}
|
|
48
|
+
static updateValueAxis(block, scaleValue, scaleOptions, axisOptions) {
|
|
49
|
+
const axisGenerator = AxisHelper.getBaseAxisGenerator(axisOptions, scaleValue, scaleOptions);
|
|
50
|
+
AxisHelper.setLabelsSettings(axisGenerator, scaleValue.range(), scaleOptions);
|
|
51
|
+
const axisElement = block.getSvg().select(`g.${axisOptions.cssClass}`);
|
|
52
|
+
AxisDomHelper.updateAxisElement(axisGenerator, axisElement, axisOptions.translate, block.transitionManager.durations.chartUpdate)
|
|
53
|
+
.then(() => {
|
|
54
|
+
if (axisOptions.labels.defaultTooltip)
|
|
55
|
+
AxisLabelHelper.setTitles(axisElement);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
static updateKeyAxis(block, scaleKey, scaleOptions, axisOptions, blockSize, domainNotUpdated) {
|
|
59
|
+
const axisGenerator = AxisHelper.getBaseAxisGenerator(axisOptions, scaleKey, scaleOptions);
|
|
60
|
+
if (axisOptions.labels.position === 'rotated') { // Задание координат для перевернутых лейблов (если до этого они не были перевернуты)
|
|
61
|
+
if (axisOptions.orient === 'bottom')
|
|
62
|
+
axisGenerator.tickPadding(-4);
|
|
63
|
+
else if (axisOptions.orient === 'top')
|
|
64
|
+
axisGenerator.tickPadding(-6);
|
|
65
|
+
}
|
|
66
|
+
const axisElement = block.getSvg()
|
|
67
|
+
.select(`g.${axisOptions.cssClass}`);
|
|
68
|
+
AxisLabelsEventManager.removeEvents(axisElement);
|
|
69
|
+
if (axisOptions.orient === 'left' || axisOptions.orient === 'right') {
|
|
70
|
+
axisElement.selectAll('.tick text').attr('y', null);
|
|
71
|
+
if (axisOptions.orient === 'left')
|
|
72
|
+
axisGenerator.tickPadding(axisOptions.labels.maxSize + AXIS_VERTICAL_LABEL_PADDING);
|
|
73
|
+
}
|
|
74
|
+
// Если ключи оси не меняются, то обновление происходит без анимации
|
|
75
|
+
AxisDomHelper.updateAxisElement(axisGenerator, axisElement, axisOptions.translate, domainNotUpdated ? 0 : block.transitionManager.durations.chartUpdate)
|
|
76
|
+
.then(() => {
|
|
77
|
+
if (axisOptions.orient === 'bottom' || axisOptions.orient === 'top') {
|
|
78
|
+
AxisLabelHelper.cropLabels(block, scaleKey, scaleOptions, axisOptions, blockSize);
|
|
79
|
+
}
|
|
80
|
+
AxisLabelsEventManager.setHoverEvents(block, axisElement);
|
|
81
|
+
if (axisOptions.labels.defaultTooltip)
|
|
82
|
+
AxisLabelHelper.setTitles(axisElement);
|
|
83
|
+
});
|
|
84
|
+
// Ведется отсчет нескольких кадров, чтобы получить уже 100%-отрендеренные лейблы оси.
|
|
85
|
+
let frame = 0;
|
|
86
|
+
const labelHandler = () => {
|
|
87
|
+
frame++;
|
|
88
|
+
if (frame < 10)
|
|
89
|
+
requestAnimationFrame(labelHandler);
|
|
90
|
+
if (frame === 2) {
|
|
91
|
+
axisElement.selectAll('.tick').each(function (d) {
|
|
92
|
+
if (scaleKey.domain().findIndex(key => key === d) === -1) {
|
|
93
|
+
select(this).style('opacity', 0);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
select(this).style('opacity', 1);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
if (axisOptions.orient === 'left' || axisOptions.orient === 'right') {
|
|
101
|
+
if (Scale.getScaleStep(scaleKey) >= MINIMAL_STEP_SIZE_FOR_WRAPPING)
|
|
102
|
+
axisElement.selectAll('.tick text').call(AxisLabelHelper.wrapHandler, axisOptions.labels.maxSize);
|
|
103
|
+
else
|
|
104
|
+
AxisLabelHelper.cropLabels(block, scaleKey, scaleOptions, axisOptions, blockSize);
|
|
105
|
+
AxisLabelHelper.alignLabelsInKeyAxis(axisOptions, axisElement);
|
|
106
|
+
}
|
|
107
|
+
if (axisOptions.orient === 'bottom' || axisOptions.orient === 'top') {
|
|
108
|
+
if (axisOptions.labels.position === 'rotated')
|
|
109
|
+
AxisLabelHelper.rotateLabels(axisElement, axisOptions.orient);
|
|
110
|
+
if (axisOptions.labels.position === 'straight') // Обратное выравнивание лейблов, если они были перевернуты, но теперь могут отображаться прямо
|
|
111
|
+
AxisDomHelper.rotateElementsBack(axisElement);
|
|
112
|
+
AxisLabelHelper.cropLabels(block, scaleKey, scaleOptions, axisOptions, blockSize);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
requestAnimationFrame(labelHandler);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
Axis.axesClass = NamesHelper.getClassName('axis');
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Selection, BaseType } from 'd3-selection';
|
|
2
|
+
import { Axis as IAxis } from 'd3-axis';
|
|
3
|
+
import { TranslateModel } from '../../../model/model';
|
|
4
|
+
export declare class AxisDomHelper {
|
|
5
|
+
static updateAxisElement(axisGenerator: IAxis<any>, axisElement: Selection<SVGGElement, any, BaseType, any>, translate: TranslateModel, transitionDuration?: number): Promise<string>;
|
|
6
|
+
static rotateElementsBack(axisElement: Selection<SVGGElement, unknown, HTMLElement, any>): void;
|
|
7
|
+
}
|