billboard.js 3.4.1 → 3.5.0
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/README.md +4 -1
- package/dist/billboard.css +1 -1
- package/dist/billboard.js +3942 -1467
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +2 -2
- package/dist/billboard.pkgd.js +8372 -5306
- package/dist/billboard.pkgd.min.js +3 -2
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +29 -13
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +375 -91
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-stanford.js +445 -108
- package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.js +339 -73
- package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-textoverlap.js +335 -74
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +4236 -3792
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +4637 -3889
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +4804 -3931
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +4595 -3865
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +4607 -3873
- package/dist/theme/datalab.css +1 -1
- package/dist/theme/datalab.min.css +1 -1
- package/dist/theme/graph.css +1 -1
- package/dist/theme/graph.min.css +1 -1
- package/dist/theme/insight.css +1 -1
- package/dist/theme/insight.min.css +1 -1
- package/dist-esm/billboard.js +837 -403
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +47 -75
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +68 -86
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +52 -77
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +49 -76
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +49 -76
- package/package.json +39 -39
- package/src/Chart/api/chart.ts +4 -1
- package/src/Chart/api/data.ts +2 -2
- package/src/Chart/api/flow.ts +125 -115
- package/src/ChartInternal/Axis/AxisRenderer.ts +29 -3
- package/src/ChartInternal/ChartInternal.ts +46 -18
- package/src/ChartInternal/data/IData.ts +2 -2
- package/src/ChartInternal/data/convert.helper.ts +226 -0
- package/src/ChartInternal/data/convert.ts +43 -210
- package/src/ChartInternal/data/load.ts +5 -4
- package/src/ChartInternal/interactions/zoom.ts +17 -4
- package/src/ChartInternal/internals/class.ts +1 -1
- package/src/ChartInternal/internals/color.ts +41 -42
- package/src/ChartInternal/internals/grid.ts +5 -3
- package/src/ChartInternal/internals/legend.ts +21 -6
- package/src/ChartInternal/internals/redraw.ts +5 -2
- package/src/ChartInternal/internals/scale.ts +3 -1
- package/src/ChartInternal/internals/size.axis.ts +5 -2
- package/src/ChartInternal/internals/style.ts +54 -0
- package/src/ChartInternal/internals/text.ts +118 -18
- package/src/ChartInternal/shape/arc.ts +4 -3
- package/src/ChartInternal/shape/area.ts +14 -7
- package/src/ChartInternal/shape/bar.ts +22 -12
- package/src/ChartInternal/shape/line.ts +3 -2
- package/src/ChartInternal/shape/point.ts +15 -9
- package/src/ChartInternal/shape/polar.ts +1 -1
- package/src/Plugin/sparkline/index.ts +22 -11
- package/src/Plugin/stanford/index.ts +10 -7
- package/src/Plugin/textoverlap/index.ts +4 -1
- package/src/config/Options/Options.ts +2 -0
- package/src/config/Options/common/boost.ts +31 -0
- package/src/config/Options/common/main.ts +15 -1
- package/src/config/Options/common/tooltip.ts +1 -1
- package/src/config/Options/data/data.ts +11 -3
- package/src/config/Options/shape/area.ts +6 -1
- package/src/config/Store/State.ts +3 -0
- package/src/module/browser.ts +2 -1
- package/src/module/generator.ts +18 -16
- package/src/module/util.ts +113 -0
- package/types/chart.d.ts +2 -2
- package/types/options.d.ts +45 -8
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import {select as d3Select} from "d3-selection";
|
|
6
6
|
import {scaleOrdinal as d3ScaleOrdinal} from "d3-scale";
|
|
7
|
-
import {document
|
|
7
|
+
import {document} from "../../module/browser";
|
|
8
8
|
import {$ARC, $COLOR, $SHAPE} from "../../config/classes";
|
|
9
9
|
import {KEY} from "../../module/Cache";
|
|
10
10
|
import {notEmpty, isFunction, isObject, isString} from "../../module/util";
|
|
11
|
+
import {IArcData, IDataRow} from "../data/IData";
|
|
12
|
+
import {d3Selection} from "../../../types";
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Set pattern's background color
|
|
@@ -34,57 +36,54 @@ const colorizePattern = (pattern, color, id: string) => {
|
|
|
34
36
|
};
|
|
35
37
|
};
|
|
36
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Get color pattern from CSS file
|
|
41
|
+
* CSS should be defined as: background-image: url("#00c73c;#fa7171; ...");
|
|
42
|
+
* @param {d3Selection} element Chart element
|
|
43
|
+
* @returns {Array}
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
function getColorFromCss(element: d3Selection): string[] {
|
|
47
|
+
const cacheKey = KEY.colorPattern;
|
|
48
|
+
const {body} = document;
|
|
49
|
+
let pattern = body[cacheKey];
|
|
50
|
+
|
|
51
|
+
if (!pattern) {
|
|
52
|
+
const delimiter = ";";
|
|
53
|
+
const content = element
|
|
54
|
+
.classed($COLOR.colorPattern, true)
|
|
55
|
+
.style("background-image");
|
|
56
|
+
|
|
57
|
+
element.classed($COLOR.colorPattern, false);
|
|
58
|
+
|
|
59
|
+
if (content.indexOf(delimiter) > -1) {
|
|
60
|
+
pattern = content
|
|
61
|
+
.replace(/url[^#]*|["'()]|(\s|%20)/g, "")
|
|
62
|
+
.split(delimiter)
|
|
63
|
+
.map(v => v.trim().replace(/[\"'\s]/g, ""))
|
|
64
|
+
.filter(Boolean);
|
|
65
|
+
|
|
66
|
+
body[cacheKey] = pattern;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return pattern;
|
|
71
|
+
}
|
|
72
|
+
|
|
37
73
|
// Replacement of d3.schemeCategory10.
|
|
38
74
|
// Contained differently depend on d3 version: v4(d3-scale), v5(d3-scale-chromatic)
|
|
39
75
|
const schemeCategory10 = ["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf"];
|
|
40
76
|
|
|
41
77
|
export default {
|
|
42
|
-
/**
|
|
43
|
-
* Get color pattern from CSS file
|
|
44
|
-
* CSS should be defined as: background-image: url("#00c73c;#fa7171; ...");
|
|
45
|
-
* @returns {Array}
|
|
46
|
-
* @private
|
|
47
|
-
*/
|
|
48
|
-
getColorFromCss(): string[] {
|
|
49
|
-
const cacheKey = KEY.colorPattern;
|
|
50
|
-
const {body} = document;
|
|
51
|
-
let pattern = body[cacheKey];
|
|
52
|
-
|
|
53
|
-
if (!pattern) {
|
|
54
|
-
const delimiter = ";";
|
|
55
|
-
const span = document.createElement("span");
|
|
56
|
-
|
|
57
|
-
span.className = $COLOR.colorPattern;
|
|
58
|
-
span.style.display = "none";
|
|
59
|
-
body.appendChild(span);
|
|
60
|
-
|
|
61
|
-
const content = window.getComputedStyle(span).backgroundImage;
|
|
62
|
-
|
|
63
|
-
span.parentNode.removeChild(span);
|
|
64
|
-
|
|
65
|
-
if (content.indexOf(delimiter) > -1) {
|
|
66
|
-
pattern = content
|
|
67
|
-
.replace(/url[^#]*|["'()]|(\s|%20)/g, "")
|
|
68
|
-
.split(delimiter)
|
|
69
|
-
.map(v => v.trim().replace(/[\"'\s]/g, ""))
|
|
70
|
-
.filter(Boolean);
|
|
71
|
-
|
|
72
|
-
body[cacheKey] = pattern;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return pattern;
|
|
77
|
-
},
|
|
78
|
-
|
|
79
78
|
generateColor(): Function {
|
|
80
79
|
const $$ = this;
|
|
81
|
-
const {config} = $$;
|
|
80
|
+
const {$el, config} = $$;
|
|
82
81
|
const colors = config.data_colors;
|
|
83
82
|
const callback = config.data_color;
|
|
84
83
|
const ids: string[] = [];
|
|
85
84
|
|
|
86
85
|
let pattern = notEmpty(config.color_pattern) ? config.color_pattern :
|
|
87
|
-
d3ScaleOrdinal(
|
|
86
|
+
d3ScaleOrdinal(getColorFromCss($el.chart) || schemeCategory10).range();
|
|
88
87
|
|
|
89
88
|
const originalColorPattern = pattern;
|
|
90
89
|
|
|
@@ -103,8 +102,8 @@ export default {
|
|
|
103
102
|
$$.patterns = colorizedPatterns;
|
|
104
103
|
}
|
|
105
104
|
|
|
106
|
-
return function(d) {
|
|
107
|
-
const id: string = d.id || d.data?.id || d;
|
|
105
|
+
return function(d: IDataRow | IArcData | string): string {
|
|
106
|
+
const id: string = (d as IDataRow).id || (d as IArcData).data?.id || d as string;
|
|
108
107
|
const isLine = $$.isTypeOf(id, ["line", "spline", "step"]) || !config.data_types[id];
|
|
109
108
|
let color;
|
|
110
109
|
|
|
@@ -133,10 +133,12 @@ export default {
|
|
|
133
133
|
|
|
134
134
|
updateYGrid(): void {
|
|
135
135
|
const $$ = this;
|
|
136
|
-
const {config, state, $el: {grid, main}} = $$;
|
|
136
|
+
const {axis, config, scale, state, $el: {grid, main}} = $$;
|
|
137
137
|
const isRotated = config.axis_rotated;
|
|
138
|
-
const
|
|
139
|
-
|
|
138
|
+
const pos = d => Math.ceil(scale.y(d));
|
|
139
|
+
|
|
140
|
+
const gridValues =
|
|
141
|
+
axis.y.getGeneratedTicks(config.grid_y_ticks) || $$.scale.y.ticks(config.grid_y_ticks);
|
|
140
142
|
|
|
141
143
|
grid.y = main.select(`.${$GRID.ygrids}`)
|
|
142
144
|
.selectAll(`.${$GRID.ygrid}`)
|
|
@@ -370,9 +370,10 @@ export default {
|
|
|
370
370
|
*/
|
|
371
371
|
setLegendItem(item): void {
|
|
372
372
|
const $$ = this;
|
|
373
|
-
const {api, config, state} = $$;
|
|
373
|
+
const {$el, api, config, state} = $$;
|
|
374
374
|
const isTouch = state.inputType === "touch";
|
|
375
375
|
const hasGauge = $$.hasType("gauge");
|
|
376
|
+
const useCssRule = config.boost_useCssRule;
|
|
376
377
|
|
|
377
378
|
item
|
|
378
379
|
.attr("class", function(id) {
|
|
@@ -384,8 +385,22 @@ export default {
|
|
|
384
385
|
.style("visibility", id => ($$.isLegendToShow(id) ? null : "hidden"));
|
|
385
386
|
|
|
386
387
|
if (config.interaction_enabled) {
|
|
388
|
+
if (useCssRule) {
|
|
389
|
+
[
|
|
390
|
+
[`.${$LEGEND.legendItem}`, "cursor:pointer"],
|
|
391
|
+
[`.${$LEGEND.legendItem} text`, "pointer-events:none"],
|
|
392
|
+
[`.${$LEGEND.legendItemPoint} text`, "pointer-events:none"],
|
|
393
|
+
[`.${$LEGEND.legendItemTile}`, "pointer-events:none"],
|
|
394
|
+
[`.${$LEGEND.legendItemEvent}`, "fill-opacity:0"]
|
|
395
|
+
].forEach(v => {
|
|
396
|
+
const [selector, props] = v;
|
|
397
|
+
|
|
398
|
+
$$.setCssRule(false, selector, [props])($el.legend);
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
|
|
387
402
|
item
|
|
388
|
-
.style("cursor", "pointer")
|
|
403
|
+
.style("cursor", $$.getStylePropValue("pointer"))
|
|
389
404
|
.on("click", function(event, id) {
|
|
390
405
|
if (!callFn(config.legend_item_onclick, api, id)) {
|
|
391
406
|
if (event.altKey) {
|
|
@@ -579,13 +594,13 @@ export default {
|
|
|
579
594
|
.each(function(id, i) {
|
|
580
595
|
updatePositions(this, id, i);
|
|
581
596
|
})
|
|
582
|
-
.style("pointer-events", "none")
|
|
597
|
+
.style("pointer-events", $$.getStylePropValue("none"))
|
|
583
598
|
.attr("x", isLegendRightOrInset ? xForLegendText : pos)
|
|
584
599
|
.attr("y", isLegendRightOrInset ? pos : yForLegendText);
|
|
585
600
|
|
|
586
601
|
l.append("rect")
|
|
587
602
|
.attr("class", $LEGEND.legendItemEvent)
|
|
588
|
-
.style("fill-opacity", "0")
|
|
603
|
+
.style("fill-opacity", $$.getStylePropValue("0"))
|
|
589
604
|
.attr("x", isLegendRightOrInset ? xForLegendRect : pos)
|
|
590
605
|
.attr("y", isLegendRightOrInset ? pos : yForLegendRect);
|
|
591
606
|
|
|
@@ -618,7 +633,7 @@ export default {
|
|
|
618
633
|
})
|
|
619
634
|
.attr("class", $LEGEND.legendItemPoint)
|
|
620
635
|
.style("fill", getColor)
|
|
621
|
-
.style("pointer-events", "none")
|
|
636
|
+
.style("pointer-events", $$.getStylePropValue("none"))
|
|
622
637
|
.attr("href", (data, idx, selection) => {
|
|
623
638
|
const node = selection[idx];
|
|
624
639
|
const nodeName = node.nodeName.toLowerCase();
|
|
@@ -630,7 +645,7 @@ export default {
|
|
|
630
645
|
l.append("line")
|
|
631
646
|
.attr("class", $LEGEND.legendItemTile)
|
|
632
647
|
.style("stroke", getColor)
|
|
633
|
-
.style("pointer-events", "none")
|
|
648
|
+
.style("pointer-events", $$.getStylePropValue("none"))
|
|
634
649
|
.attr("x1", isLegendRightOrInset ? x1ForLegendTile : pos)
|
|
635
650
|
.attr("y1", isLegendRightOrInset ? pos : yForLegendTile)
|
|
636
651
|
.attr("x2", isLegendRightOrInset ? x2ForLegendTile : pos)
|
|
@@ -26,7 +26,6 @@ export default {
|
|
|
26
26
|
$$.updateSizes(initializing);
|
|
27
27
|
|
|
28
28
|
// update legend and transform each g
|
|
29
|
-
|
|
30
29
|
if (wth.Legend && config.legend_show) {
|
|
31
30
|
options.withTransition = !!duration;
|
|
32
31
|
$$.updateLegend($$.mapToIds($$.data.targets), options, transitions);
|
|
@@ -246,7 +245,11 @@ export default {
|
|
|
246
245
|
$$.redraw(options, transitions);
|
|
247
246
|
},
|
|
248
247
|
|
|
249
|
-
|
|
248
|
+
/**
|
|
249
|
+
* Redraw without rescale
|
|
250
|
+
* @private
|
|
251
|
+
*/
|
|
252
|
+
redrawWithoutRescale(): void {
|
|
250
253
|
this.redraw({
|
|
251
254
|
withY: false,
|
|
252
255
|
withDimension: false,
|
|
@@ -169,7 +169,9 @@ export default {
|
|
|
169
169
|
const xSubDomain = updateXDomain && org.xDomain;
|
|
170
170
|
|
|
171
171
|
scale.x = $$.getXScale(min.x, max.x, xDomain, () => axis.x.tickOffset());
|
|
172
|
-
scale.subX = $$.getXScale(min.x, max.x, xSubDomain, d => (
|
|
172
|
+
scale.subX = $$.getXScale(min.x, max.x, xSubDomain, d => (
|
|
173
|
+
d % 1 ? 0 : (axis.subX ?? axis.x).tickOffset())
|
|
174
|
+
);
|
|
173
175
|
|
|
174
176
|
format.xAxisTick = axis.getXAxisTickFormat();
|
|
175
177
|
format.subXAxisTick = axis.getXAxisTickFormat(true);
|
|
@@ -25,9 +25,12 @@ export default {
|
|
|
25
25
|
|
|
26
26
|
if ($$.axis) {
|
|
27
27
|
const position = $$.axis?.getLabelPositionById(id);
|
|
28
|
+
const width = $$.axis.getMaxTickWidth(id, withoutRecompute);
|
|
29
|
+
const gap = width === 0 ? 0.5 : 0;
|
|
28
30
|
|
|
29
|
-
return
|
|
30
|
-
|
|
31
|
+
return width + (
|
|
32
|
+
position.isInner ? (20 + gap) : 40
|
|
33
|
+
);
|
|
31
34
|
} else {
|
|
32
35
|
return 40;
|
|
33
36
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
|
+
* billboard.js project is licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import {$SHAPE} from "../../config/classes";
|
|
6
|
+
import {d3Selection} from "../../../types/types";
|
|
7
|
+
import {IDataRow} from "../data/IData";
|
|
8
|
+
import {addCssRules, isFunction, isString} from "../../module/util";
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
/**
|
|
12
|
+
* Add props color css rule to given selector
|
|
13
|
+
* @param {boolean} withShape Set shpes' prefix class
|
|
14
|
+
* @param {string} selector CSS selector
|
|
15
|
+
* @param {Array} props CSS props list
|
|
16
|
+
* @param {Function} propsFn Function to retrieve value or determine for props
|
|
17
|
+
* @returns {Function}
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
setCssRule(withShape: boolean, selector: string, props: string[], propsFn: Function): Function {
|
|
21
|
+
const $$ = this;
|
|
22
|
+
const {config, state: {cssRule, style}} = $$;
|
|
23
|
+
|
|
24
|
+
return config.boost_useCssRule ? (selection: d3Selection) => {
|
|
25
|
+
selection.each((d: IDataRow) => {
|
|
26
|
+
const res = propsFn && propsFn?.call($$, d);
|
|
27
|
+
const shapeSelector = `${
|
|
28
|
+
withShape ? `.${$SHAPE.shapes + $$.getTargetSelectorSuffix(d.id)}` : ""
|
|
29
|
+
}${selector}`;
|
|
30
|
+
|
|
31
|
+
(selector in cssRule) && style.sheet.deleteRule(cssRule[shapeSelector]);
|
|
32
|
+
$$.state.cssRule[shapeSelector] = addCssRules(
|
|
33
|
+
style,
|
|
34
|
+
shapeSelector,
|
|
35
|
+
props.filter(Boolean).map(v => (
|
|
36
|
+
isString(res) && v.indexOf(":") === -1 ? `${v}: ${res}` : (v || "")
|
|
37
|
+
))
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
} : () => {};
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get style prop value
|
|
45
|
+
* @param {Function|string} v Value
|
|
46
|
+
* @returns {string|null}
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
49
|
+
getStylePropValue(v: Function|string): string|null {
|
|
50
|
+
const {config: {boost_useCssRule: useCssRule}} = this;
|
|
51
|
+
|
|
52
|
+
return useCssRule ? null : isFunction(v) ? v.bind(this) : v;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
@@ -12,6 +12,83 @@ import {capitalize, getBoundingRect, getRandom, isFunction, isNumber, isObject,
|
|
|
12
12
|
import {IDataRow, IArcData} from "../data/IData";
|
|
13
13
|
import {AxisType} from "../../../types/types";
|
|
14
14
|
|
|
15
|
+
type Coord = {x: number, y: number};
|
|
16
|
+
type Anchor = "start" | "middle" | "end";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Get text-anchor according text.labels.rotate angle
|
|
20
|
+
* @param {number} angle Angle value
|
|
21
|
+
* @returns {string} Anchor string value
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
function getRotateAnchor(angle: number): Anchor {
|
|
25
|
+
let anchor: Anchor = "middle";
|
|
26
|
+
|
|
27
|
+
if (angle > 0 && angle <= 170) {
|
|
28
|
+
anchor = "end";
|
|
29
|
+
} else if (angle > 190 && angle <= 360) {
|
|
30
|
+
anchor = "start";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return anchor;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Set rotated position coordinate according text.labels.rotate angle
|
|
38
|
+
* @param {object} d Data object
|
|
39
|
+
* @param {object} pos Position object
|
|
40
|
+
* @param {object} pos.x x coordinate
|
|
41
|
+
* @param {object} pos.y y coordinate
|
|
42
|
+
* @param {string} anchor string value
|
|
43
|
+
* @param {boolean} isRotated If axis is rotated
|
|
44
|
+
* @param {boolean} isInverted If axis is inverted
|
|
45
|
+
* @returns {object} x, y coordinate
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
function setRotatePos(
|
|
49
|
+
d: IDataRow, pos: Coord, anchor: Anchor, isRotated: boolean, isInverted: boolean
|
|
50
|
+
): Coord {
|
|
51
|
+
const $$ = this;
|
|
52
|
+
const {value} = d;
|
|
53
|
+
const isCandlestickType = $$.isCandlestickType(d);
|
|
54
|
+
const isNegative = (isNumber(value) && value < 0) || (
|
|
55
|
+
isCandlestickType && !$$.getCandlestickData(d)?._isUp
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
let {x, y} = pos;
|
|
59
|
+
const gap = 4;
|
|
60
|
+
const doubleGap = gap * 2;
|
|
61
|
+
|
|
62
|
+
if (isRotated) {
|
|
63
|
+
if (anchor === "start") {
|
|
64
|
+
x += isNegative ? 0 : doubleGap;
|
|
65
|
+
y += gap;
|
|
66
|
+
} else if (anchor === "middle") {
|
|
67
|
+
x += doubleGap;
|
|
68
|
+
y -= doubleGap;
|
|
69
|
+
} else if (anchor === "end") {
|
|
70
|
+
isNegative && (x -= doubleGap);
|
|
71
|
+
y += gap;
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
if (anchor === "start") {
|
|
75
|
+
x += gap;
|
|
76
|
+
isNegative && (y += doubleGap * 2);
|
|
77
|
+
} else if (anchor === "middle") {
|
|
78
|
+
y -= doubleGap;
|
|
79
|
+
} else if (anchor === "end") {
|
|
80
|
+
x -= gap;
|
|
81
|
+
isNegative && (y += doubleGap * 2);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (isInverted) {
|
|
85
|
+
y += isNegative ? -17 : (isCandlestickType ? 13 : 7);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return {x, y};
|
|
90
|
+
}
|
|
91
|
+
|
|
15
92
|
export default {
|
|
16
93
|
opacityForText(d): null | "0" {
|
|
17
94
|
const $$ = this;
|
|
@@ -50,7 +127,7 @@ export default {
|
|
|
50
127
|
const mainTextEnter = mainTextUpdate.enter().append("g")
|
|
51
128
|
.style("opacity", "0")
|
|
52
129
|
.attr("class", classChartText)
|
|
53
|
-
.
|
|
130
|
+
.call($$.setCssRule(true, ` .${$TEXT.text}`, ["fill", "pointer-events:none"], $$.updateTextColor));
|
|
54
131
|
|
|
55
132
|
mainTextEnter.append("g")
|
|
56
133
|
.attr("class", classTexts);
|
|
@@ -89,7 +166,7 @@ export default {
|
|
|
89
166
|
|
|
90
167
|
return (config.axis_rotated ? (isEndAnchor ? "end" : "start") : "middle");
|
|
91
168
|
})
|
|
92
|
-
.style("fill", $$.updateTextColor
|
|
169
|
+
.style("fill", $$.getStylePropValue($$.updateTextColor))
|
|
93
170
|
.style("fill-opacity", "0")
|
|
94
171
|
.each(function(d, i, texts) {
|
|
95
172
|
const node = d3Select(this);
|
|
@@ -171,34 +248,46 @@ export default {
|
|
|
171
248
|
|
|
172
249
|
/**
|
|
173
250
|
* Redraw chartText
|
|
174
|
-
* @param {Function}
|
|
175
|
-
* @param {Function}
|
|
251
|
+
* @param {Function} getX Positioning function for x
|
|
252
|
+
* @param {Function} getY Positioning function for y
|
|
176
253
|
* @param {boolean} forFlow Weather is flow
|
|
177
254
|
* @param {boolean} withTransition transition is enabled
|
|
178
255
|
* @returns {Array}
|
|
179
256
|
* @private
|
|
180
257
|
*/
|
|
181
|
-
redrawText(
|
|
258
|
+
redrawText(getX, getY, forFlow?: boolean, withTransition?: boolean): true {
|
|
182
259
|
const $$ = this;
|
|
183
|
-
const {$T} = $$;
|
|
260
|
+
const {$T, axis, config} = $$;
|
|
184
261
|
const t = <string>getRandom(true);
|
|
262
|
+
const isRotated = config.axis_rotated;
|
|
263
|
+
const angle = config.data_labels.rotate;
|
|
264
|
+
|
|
265
|
+
const anchorString = getRotateAnchor(angle);
|
|
266
|
+
const rotateString = angle ? `rotate(${angle})` : "";
|
|
185
267
|
|
|
186
268
|
$$.$el.text
|
|
187
|
-
.style("fill", $$.updateTextColor
|
|
269
|
+
.style("fill", $$.getStylePropValue($$.updateTextColor))
|
|
188
270
|
.attr("filter", $$.updateTextBacgroundColor.bind($$))
|
|
189
271
|
.style("fill-opacity", forFlow ? 0 : $$.opacityForText.bind($$))
|
|
190
|
-
.each(function(d, i) {
|
|
272
|
+
.each(function(d: IDataRow, i: number) {
|
|
191
273
|
// do not apply transition for newly added text elements
|
|
192
274
|
const node = $T(this, !!(withTransition && this.getAttribute("x")), t);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
275
|
+
const isInverted = config[`axis_${axis?.getId(d.id)}_inverted`];
|
|
276
|
+
let pos = {
|
|
277
|
+
x: getX.bind(this)(d, i),
|
|
278
|
+
y: getY.bind(this)(d, i)
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
if (angle) {
|
|
282
|
+
pos = setRotatePos.bind($$)(d, pos, anchorString, isRotated, isInverted);
|
|
283
|
+
node.attr("text-anchor", anchorString);
|
|
284
|
+
}
|
|
196
285
|
|
|
197
286
|
// when is multiline
|
|
198
|
-
if (this.childElementCount) {
|
|
199
|
-
node.attr("transform", `translate(${
|
|
287
|
+
if (this.childElementCount || angle) {
|
|
288
|
+
node.attr("transform", `translate(${pos.x} ${pos.y}) ${rotateString}`);
|
|
200
289
|
} else {
|
|
201
|
-
node.attr("x",
|
|
290
|
+
node.attr("x", pos.x).attr("y", pos.y);
|
|
202
291
|
}
|
|
203
292
|
});
|
|
204
293
|
|
|
@@ -338,7 +427,6 @@ export default {
|
|
|
338
427
|
const isRotated = config.axis_rotated;
|
|
339
428
|
let xPos = points[0][0];
|
|
340
429
|
|
|
341
|
-
|
|
342
430
|
if ($$.isCandlestickType(d)) {
|
|
343
431
|
if (isRotated) {
|
|
344
432
|
xPos = $$.getCandlestickData(d)?._isUp ?
|
|
@@ -384,8 +472,10 @@ export default {
|
|
|
384
472
|
*/
|
|
385
473
|
getYForText(points, d, textElement): number {
|
|
386
474
|
const $$ = this;
|
|
387
|
-
const {config, state} = $$;
|
|
475
|
+
const {axis, config, state} = $$;
|
|
388
476
|
const isRotated = config.axis_rotated;
|
|
477
|
+
const isInverted = config[`axis_${axis?.getId(d.id)}_inverted`];
|
|
478
|
+
const isBarType = $$.isBarType(d);
|
|
389
479
|
const r = config.point_r;
|
|
390
480
|
const rect = getBoundingRect(textElement);
|
|
391
481
|
let {value} = d;
|
|
@@ -402,6 +492,10 @@ export default {
|
|
|
402
492
|
yPos = value && value._isUp ?
|
|
403
493
|
points[2][2] - baseY :
|
|
404
494
|
points[2][1] + (baseY * 4);
|
|
495
|
+
|
|
496
|
+
if (isInverted) {
|
|
497
|
+
yPos += 15 * (value._isUp ? 1 : -1);
|
|
498
|
+
}
|
|
405
499
|
}
|
|
406
500
|
} else {
|
|
407
501
|
if (isRotated) {
|
|
@@ -414,16 +508,22 @@ export default {
|
|
|
414
508
|
}
|
|
415
509
|
|
|
416
510
|
if (value < 0 || (value === 0 && !state.hasPositiveValue && state.hasNegativeValue)) {
|
|
417
|
-
yPos +=
|
|
511
|
+
yPos += isInverted ? (isBarType ? -3 : -5) : (
|
|
512
|
+
rect.height + (isBarType ? -baseY : baseY)
|
|
513
|
+
);
|
|
418
514
|
} else {
|
|
419
515
|
let diff = -baseY * 2;
|
|
420
516
|
|
|
421
|
-
if (
|
|
517
|
+
if (isBarType) {
|
|
422
518
|
diff = -baseY;
|
|
423
519
|
} else if ($$.isBubbleType(d)) {
|
|
424
520
|
diff = baseY;
|
|
425
521
|
}
|
|
426
522
|
|
|
523
|
+
if (isInverted) {
|
|
524
|
+
diff = isBarType ? 10 : 15;
|
|
525
|
+
}
|
|
526
|
+
|
|
427
527
|
yPos += diff;
|
|
428
528
|
}
|
|
429
529
|
}
|
|
@@ -515,7 +515,8 @@ export default {
|
|
|
515
515
|
.attr("class", d => classChartArc(d) + classFocus(d.data));
|
|
516
516
|
|
|
517
517
|
const mainPieEnter = mainPieUpdate.enter().append("g")
|
|
518
|
-
.attr("class", classChartArc)
|
|
518
|
+
.attr("class", classChartArc)
|
|
519
|
+
.call(this.setCssRule(false, `.${$ARC.chartArcs} text`, ["pointer-events:none", "text-anchor:middle"]));
|
|
519
520
|
|
|
520
521
|
mainPieEnter.append("g")
|
|
521
522
|
.attr("class", classArcs)
|
|
@@ -524,8 +525,8 @@ export default {
|
|
|
524
525
|
mainPieEnter.append("text")
|
|
525
526
|
.attr("dy", hasGauge && !$$.hasMultiTargets() ? "-.1em" : ".35em")
|
|
526
527
|
.style("opacity", "0")
|
|
527
|
-
.style("text-anchor", "middle")
|
|
528
|
-
.style("pointer-events", "none");
|
|
528
|
+
.style("text-anchor", $$.getStylePropValue("middle"))
|
|
529
|
+
.style("pointer-events", $$.getStylePropValue("none"));
|
|
529
530
|
|
|
530
531
|
$el.text = chartArcs.selectAll(`.${$COMMON.target} text`);
|
|
531
532
|
// MEMO: can not keep same color..., but not bad to update color in redraw
|
|
@@ -6,9 +6,13 @@ import {area as d3Area} from "d3-shape";
|
|
|
6
6
|
import {select as d3Select} from "d3-selection";
|
|
7
7
|
import {$AREA, $CIRCLE, $LINE} from "../../config/classes";
|
|
8
8
|
import {getRandom, isFunction} from "../../module/util";
|
|
9
|
+
import {IData, IDataRow} from "../data/IData";
|
|
10
|
+
import {d3Selection} from "../../../types";
|
|
11
|
+
|
|
12
|
+
type Indices = {[key: string | "__max__"]: number};
|
|
9
13
|
|
|
10
14
|
export default {
|
|
11
|
-
initArea(mainLine): void {
|
|
15
|
+
initArea(mainLine: d3Selection): void {
|
|
12
16
|
const $$ = this;
|
|
13
17
|
const {config} = $$;
|
|
14
18
|
|
|
@@ -51,7 +55,7 @@ export default {
|
|
|
51
55
|
});
|
|
52
56
|
},
|
|
53
57
|
|
|
54
|
-
updateAreaColor(d): string {
|
|
58
|
+
updateAreaColor(d: IDataRow): string {
|
|
55
59
|
const $$ = this;
|
|
56
60
|
|
|
57
61
|
return $$.config.area_linearGradient ?
|
|
@@ -99,7 +103,7 @@ export default {
|
|
|
99
103
|
* @param {boolean} isSub Subchart draw
|
|
100
104
|
* @returns {Array}
|
|
101
105
|
*/
|
|
102
|
-
redrawArea(drawFn, withTransition?: boolean, isSub = false) {
|
|
106
|
+
redrawArea(drawFn: Function, withTransition?: boolean, isSub = false): d3Selection[] {
|
|
103
107
|
const $$ = this;
|
|
104
108
|
const {area} = (isSub ? this.$el.subchart : this.$el);
|
|
105
109
|
const {orgAreaOpacity} = $$.state;
|
|
@@ -119,7 +123,7 @@ export default {
|
|
|
119
123
|
* @returns {Function}
|
|
120
124
|
* @private
|
|
121
125
|
*/
|
|
122
|
-
generateDrawArea(areaIndices, isSub?: boolean): (d) => string {
|
|
126
|
+
generateDrawArea(areaIndices: Indices, isSub?: boolean): (d: IData) => string {
|
|
123
127
|
const $$ = this;
|
|
124
128
|
const {config} = $$;
|
|
125
129
|
const lineConnectNull = config.line_connectNull;
|
|
@@ -156,8 +160,9 @@ export default {
|
|
|
156
160
|
.x0(value0)
|
|
157
161
|
.x1(value1) :
|
|
158
162
|
area.x(xValue)
|
|
159
|
-
|
|
160
|
-
|
|
163
|
+
.y0(config.area_above ? 0 : (
|
|
164
|
+
config.area_below ? $$.state.height : value0
|
|
165
|
+
))
|
|
161
166
|
.y1(value1);
|
|
162
167
|
|
|
163
168
|
if (!lineConnectNull) {
|
|
@@ -182,7 +187,9 @@ export default {
|
|
|
182
187
|
};
|
|
183
188
|
},
|
|
184
189
|
|
|
185
|
-
generateGetAreaPoints(
|
|
190
|
+
generateGetAreaPoints(
|
|
191
|
+
areaIndices: Indices, isSub?: boolean
|
|
192
|
+
): (d: IDataRow, i: number) => [number, number][] {
|
|
186
193
|
// partial duplication of generateGetBarPoints
|
|
187
194
|
const $$ = this;
|
|
188
195
|
const {config} = $$;
|