billboard.js 3.9.2 → 3.10.0-next.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/README.md +2 -2
- package/dist/billboard.css +2 -2
- package/dist/billboard.js +2705 -2529
- package/dist/billboard.min.css +2 -2
- package/dist/billboard.min.js +2 -2
- package/dist/billboard.pkgd.js +3516 -3329
- package/dist/billboard.pkgd.min.js +4 -4
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +15 -15
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +215 -196
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-stanford.js +244 -239
- package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.js +184 -164
- package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-textoverlap.js +170 -151
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/{billboardjs-plugin-bubblecompare.js → billboardjs-plugin-bubblecompare.pkgd.js} +667 -642
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +12 -0
- package/dist/plugin/pkgd/{billboardjs-plugin-sparkline.js → billboardjs-plugin-sparkline.pkgd.js} +864 -820
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +12 -0
- package/dist/plugin/pkgd/{billboardjs-plugin-stanford.js → billboardjs-plugin-stanford.pkgd.js} +929 -900
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +12 -0
- package/dist/plugin/pkgd/{billboardjs-plugin-tableview.js → billboardjs-plugin-tableview.pkgd.js} +833 -788
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +12 -0
- package/dist/plugin/pkgd/{billboardjs-plugin-textoverlap.js → billboardjs-plugin-textoverlap.pkgd.js} +932 -897
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +12 -0
- package/dist/theme/dark.css +5 -4
- package/dist/theme/dark.min.css +2 -2
- package/dist/theme/datalab.css +5 -4
- package/dist/theme/datalab.min.css +2 -2
- package/dist/theme/graph.css +5 -4
- package/dist/theme/graph.min.css +2 -2
- package/dist/theme/insight.css +5 -4
- package/dist/theme/insight.min.css +2 -2
- package/dist-esm/billboard.js +605 -468
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +3 -3
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +13 -7
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +21 -28
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +17 -11
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +13 -7
- package/package.json +31 -31
- package/src/Chart/api/axis.ts +4 -0
- package/src/Chart/api/category.ts +8 -4
- package/src/Chart/api/export.ts +1 -2
- package/src/Chart/api/subchart.ts +162 -89
- package/src/Chart/api/zoom.ts +69 -79
- package/src/ChartInternal/Axis/AxisRendererHelper.ts +0 -8
- package/src/ChartInternal/data/IData.ts +4 -1
- package/src/ChartInternal/data/convert.helper.ts +1 -15
- package/src/ChartInternal/data/data.ts +8 -2
- package/src/ChartInternal/interactions/eventrect.ts +0 -1
- package/src/ChartInternal/interactions/flow.ts +1 -7
- package/src/ChartInternal/interactions/interaction.ts +10 -4
- package/src/ChartInternal/interactions/subchart.ts +36 -30
- package/src/ChartInternal/interactions/zoom.ts +13 -3
- package/src/ChartInternal/internals/category.ts +2 -2
- package/src/ChartInternal/internals/clip.ts +4 -4
- package/src/ChartInternal/internals/domain.ts +46 -10
- package/src/ChartInternal/internals/grid.ts +57 -86
- package/src/ChartInternal/internals/redraw.ts +0 -5
- package/src/ChartInternal/internals/region.ts +35 -12
- package/src/ChartInternal/internals/text.ts +1 -26
- package/src/ChartInternal/internals/title.ts +10 -48
- package/src/ChartInternal/internals/tooltip.ts +47 -51
- package/src/ChartInternal/shape/arc.ts +16 -6
- package/src/ChartInternal/shape/candlestick.ts +2 -17
- package/src/ChartInternal/shape/shape.ts +50 -4
- package/src/ChartInternal/shape/treemap.ts +2 -2
- package/src/Plugin/bubblecompare/index.ts +1 -1
- package/src/Plugin/stanford/Elements.ts +10 -2
- package/src/Plugin/stanford/index.ts +1 -24
- package/src/Plugin/tableview/index.ts +2 -2
- package/src/config/Options/axis/x.ts +1 -0
- package/src/config/Options/common/main.ts +12 -2
- package/src/config/Options/common/tooltip.ts +10 -10
- package/src/config/Options/data/axis.ts +3 -1
- package/src/config/Options/data/data.ts +10 -2
- package/src/config/Store/State.ts +3 -0
- package/src/module/Cache.ts +7 -5
- package/src/module/browser.ts +34 -14
- package/src/module/util.ts +8 -4
- package/src/module/worker.ts +24 -13
- package/src/scss/billboard.scss +4 -2
- package/src/scss/theme/dark.scss +4 -2
- package/src/scss/theme/datalab.scss +4 -2
- package/src/scss/theme/graph.scss +4 -2
- package/src/scss/theme/insight.scss +4 -2
- package/types/chart.d.ts +11 -0
- package/types/options.d.ts +3 -3
- package/types/types.d.ts +15 -1
|
@@ -12,7 +12,7 @@ import {$TEXT} from "../../config/classes";
|
|
|
12
12
|
* @returns {string|number} text-anchor value or position in pixel
|
|
13
13
|
* @private
|
|
14
14
|
*/
|
|
15
|
-
function
|
|
15
|
+
function getTextXPos(pos = "left", width?: number | any): number | "start" | "middle" | "end" {
|
|
16
16
|
const isNum = isNumber(width);
|
|
17
17
|
let position;
|
|
18
18
|
|
|
@@ -41,7 +41,7 @@ export default {
|
|
|
41
41
|
|
|
42
42
|
const text = $el.title
|
|
43
43
|
.append("text")
|
|
44
|
-
.style("text-anchor",
|
|
44
|
+
.style("text-anchor", getTextXPos(config.title_position))
|
|
45
45
|
.attr("class", $TEXT.title);
|
|
46
46
|
|
|
47
47
|
setTextValue(text, config.title_text, [0.3, 1.5]);
|
|
@@ -57,55 +57,14 @@ export default {
|
|
|
57
57
|
const {config, state: {current}, $el: {title}} = $$;
|
|
58
58
|
|
|
59
59
|
if (title) {
|
|
60
|
-
const
|
|
60
|
+
const x = getTextXPos(config.title_position, current.width);
|
|
61
|
+
const y = (config.title_padding.top || 0) +
|
|
62
|
+
$$.getTextRect($$.$el.title, $TEXT.title).height;
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
title.attr("transform", `translate(${getTextPos(config.title_position, current.width)}, ${y})`);
|
|
64
|
-
} else {
|
|
65
|
-
title.attr("x", $$.xForTitle.call($$)).attr("y", y);
|
|
66
|
-
}
|
|
64
|
+
title.attr("transform", `translate(${x}, ${y})`);
|
|
67
65
|
}
|
|
68
66
|
},
|
|
69
67
|
|
|
70
|
-
/**
|
|
71
|
-
* Returns the x attribute value of the title
|
|
72
|
-
* @returns {number} x attribute value
|
|
73
|
-
* @private
|
|
74
|
-
*/
|
|
75
|
-
xForTitle(): number {
|
|
76
|
-
const $$ = this;
|
|
77
|
-
const {config, state: {current}} = $$;
|
|
78
|
-
const position = config.title_position || "left";
|
|
79
|
-
const textRectWidth = $$.getTextRect($$.$el.title, $TEXT.title).width;
|
|
80
|
-
let x;
|
|
81
|
-
|
|
82
|
-
if (/(right|center)/.test(position)) {
|
|
83
|
-
x = current.width - textRectWidth;
|
|
84
|
-
|
|
85
|
-
if (position.indexOf("right") >= 0) {
|
|
86
|
-
x = current.width - textRectWidth - config.title_padding.right;
|
|
87
|
-
} else if (position.indexOf("center") >= 0) {
|
|
88
|
-
x = (current.width - textRectWidth) / 2;
|
|
89
|
-
}
|
|
90
|
-
} else { // left
|
|
91
|
-
x = (config.title_padding.left || 0);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return x;
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Returns the y attribute value of the title
|
|
99
|
-
* @returns {number} y attribute value
|
|
100
|
-
* @private
|
|
101
|
-
*/
|
|
102
|
-
yForTitle(): number {
|
|
103
|
-
const $$ = this;
|
|
104
|
-
|
|
105
|
-
return ($$.config.title_padding.top || 0) +
|
|
106
|
-
$$.getTextRect($$.$el.title, $TEXT.title).height;
|
|
107
|
-
},
|
|
108
|
-
|
|
109
68
|
/**
|
|
110
69
|
* Get title padding
|
|
111
70
|
* @returns {number} padding value
|
|
@@ -113,7 +72,10 @@ export default {
|
|
|
113
72
|
*/
|
|
114
73
|
getTitlePadding(): number {
|
|
115
74
|
const $$ = this;
|
|
75
|
+
const {$el, config} = $$;
|
|
116
76
|
|
|
117
|
-
return
|
|
77
|
+
return (config.title_padding.top || 0) +
|
|
78
|
+
$$.getTextRect($el.title, $TEXT.title).height +
|
|
79
|
+
(config.title_padding.bottom || 0);
|
|
118
80
|
},
|
|
119
81
|
};
|
|
@@ -6,7 +6,7 @@ import {select as d3Select} from "d3-selection";
|
|
|
6
6
|
import {document} from "../../module/browser";
|
|
7
7
|
import {$ARC, $TOOLTIP} from "../../config/classes";
|
|
8
8
|
import type {IArcData, IDataRow} from "../data/IData";
|
|
9
|
-
import {getPointer, isFunction, isObject, isString, isValue, callFn,
|
|
9
|
+
import {getPointer, isEmpty, isFunction, isObject, isString, isValue, callFn, sanitize, tplProcess, isUndefined, parseDate} from "../../module/util";
|
|
10
10
|
|
|
11
11
|
export default {
|
|
12
12
|
/**
|
|
@@ -31,50 +31,36 @@ export default {
|
|
|
31
31
|
$$.bindTooltipResizePos();
|
|
32
32
|
},
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Show tooltip at initialization.
|
|
36
|
+
* Is called only when tooltip.init.show=true option is set
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
34
39
|
initShowTooltip(): void {
|
|
35
40
|
const $$ = this;
|
|
36
41
|
const {config, $el, state: {hasAxis, hasRadar}} = $$;
|
|
37
42
|
|
|
38
43
|
// Show tooltip if needed
|
|
39
44
|
if (config.tooltip_init_show) {
|
|
40
|
-
const isArc = !(hasAxis
|
|
45
|
+
const isArc = !(hasAxis || hasRadar);
|
|
41
46
|
|
|
42
47
|
if ($$.axis?.isTimeSeries() && isString(config.tooltip_init_x)) {
|
|
43
|
-
const targets = $$.data.targets[0];
|
|
44
|
-
let i;
|
|
45
|
-
let val;
|
|
46
|
-
|
|
47
48
|
config.tooltip_init_x = parseDate.call($$, config.tooltip_init_x);
|
|
48
|
-
|
|
49
|
-
for (i = 0; (val = targets.values[i]); i++) {
|
|
50
|
-
if ((val.x - config.tooltip_init_x) === 0) {
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
config.tooltip_init_x = i;
|
|
56
49
|
}
|
|
57
50
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
$$.api.tooltip.show({
|
|
52
|
+
data: {
|
|
53
|
+
[isArc ? "index" : "x"]: config.tooltip_init_x
|
|
54
|
+
}
|
|
62
55
|
});
|
|
63
56
|
|
|
64
|
-
|
|
65
|
-
data = [data[config.tooltip_init_x]];
|
|
66
|
-
}
|
|
57
|
+
const position = config.tooltip_init_position;
|
|
67
58
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
$$.axis?.getXAxisTickFormat(),
|
|
71
|
-
$$.getDefaultValueFormat(),
|
|
72
|
-
$$.color
|
|
73
|
-
));
|
|
59
|
+
if (!config.tooltip_contents.bindto && !isEmpty(position)) {
|
|
60
|
+
const {top = 0, left = 50} = position;
|
|
74
61
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
.style("left", config.tooltip_init_position.left)
|
|
62
|
+
$el.tooltip.style("top", isString(top) ? top : `${top}px`)
|
|
63
|
+
.style("left", isString(left) ? left : `${left}px`)
|
|
78
64
|
.style("display", null);
|
|
79
65
|
}
|
|
80
66
|
}
|
|
@@ -107,17 +93,23 @@ export default {
|
|
|
107
93
|
const $$ = this;
|
|
108
94
|
const {api, config, state, $el} = $$;
|
|
109
95
|
|
|
110
|
-
|
|
96
|
+
// get formatter function
|
|
97
|
+
const [titleFn, nameFn, valueFn] = ["title", "name", "value"].map(v => {
|
|
111
98
|
const fn = config[`tooltip_format_${v}`];
|
|
112
99
|
|
|
113
100
|
return isFunction(fn) ? fn.bind(api) : fn;
|
|
114
101
|
});
|
|
115
102
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
103
|
+
// determine fotmatter function with sanitization
|
|
104
|
+
const titleFormat = (...arg) => sanitize((titleFn || defaultTitleFormat)(...arg));
|
|
105
|
+
const nameFormat = (...arg) => sanitize((nameFn || (name => name))(...arg));
|
|
106
|
+
const valueFormat = (...arg) => {
|
|
107
|
+
const fn = valueFn || (
|
|
108
|
+
state.hasTreemap || $$.isStackNormalized() ? (v, ratio) => `${(ratio * 100).toFixed(2)}%` : defaultValueFormat
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
return sanitize(fn(...arg));
|
|
112
|
+
};
|
|
121
113
|
|
|
122
114
|
const order = config.tooltip_order;
|
|
123
115
|
const getRowValue = row => ($$.axis && $$.isBubbleZType(row) ? $$.getBubbleZData(row.value, "z") : $$.getBaseValue(row));
|
|
@@ -172,8 +164,7 @@ export default {
|
|
|
172
164
|
}
|
|
173
165
|
|
|
174
166
|
if (isUndefined(text)) {
|
|
175
|
-
const title = (state.hasAxis || state.hasRadar) &&
|
|
176
|
-
sanitise(titleFormat ? titleFormat(row.x) : row.x);
|
|
167
|
+
const title = (state.hasAxis || state.hasRadar) && titleFormat(row.x);
|
|
177
168
|
|
|
178
169
|
text = tplProcess(tpl[0], {
|
|
179
170
|
CLASS_TOOLTIP: $TOOLTIP.tooltip,
|
|
@@ -188,25 +179,30 @@ export default {
|
|
|
188
179
|
row.ratio = $$.getRatio(...param);
|
|
189
180
|
}
|
|
190
181
|
|
|
191
|
-
param
|
|
192
|
-
|
|
182
|
+
// arrange param to be passed to formatter
|
|
183
|
+
param = [row.ratio, row.id, row.index];
|
|
193
184
|
|
|
194
185
|
if ($$.isAreaRangeType(row)) {
|
|
195
|
-
const [high, low] = ["high", "low"].map(v =>
|
|
196
|
-
|
|
197
|
-
));
|
|
186
|
+
const [high, low] = ["high", "low"].map(v => valueFormat($$.getRangedData(row, v), ...param));
|
|
187
|
+
const mid = valueFormat(getRowValue(row), ...param);
|
|
198
188
|
|
|
199
|
-
value = `<b>Mid:</b> ${
|
|
189
|
+
value = `<b>Mid:</b> ${mid} <b>High:</b> ${high} <b>Low:</b> ${low}`;
|
|
200
190
|
} else if ($$.isCandlestickType(row)) {
|
|
201
|
-
const [open, high, low, close, volume] = ["open", "high", "low", "close", "volume"].map(v =>
|
|
202
|
-
|
|
203
|
-
|
|
191
|
+
const [open, high, low, close, volume] = ["open", "high", "low", "close", "volume"].map(v => {
|
|
192
|
+
const value = $$.getRangedData(row, v, "candlestick");
|
|
193
|
+
|
|
194
|
+
return value ? valueFormat(
|
|
195
|
+
$$.getRangedData(row, v, "candlestick"), ...param
|
|
196
|
+
) : undefined;
|
|
197
|
+
});
|
|
204
198
|
|
|
205
199
|
value = `<b>Open:</b> ${open} <b>High:</b> ${high} <b>Low:</b> ${low} <b>Close:</b> ${close}${volume ? ` <b>Volume:</b> ${volume}` : ""}`;
|
|
206
200
|
} else if ($$.isBarRangeType(row)) {
|
|
207
|
-
const [start, end] = row
|
|
201
|
+
const {value: [start, end], id, index} = row;
|
|
208
202
|
|
|
209
|
-
value = `${valueFormat(start)} ~ ${valueFormat(end)}`;
|
|
203
|
+
value = `${valueFormat(start, undefined, id, index)} ~ ${valueFormat(end, undefined, id, index)}`;
|
|
204
|
+
} else {
|
|
205
|
+
value = valueFormat(getRowValue(row), ...param);
|
|
210
206
|
}
|
|
211
207
|
|
|
212
208
|
if (value !== undefined) {
|
|
@@ -215,7 +211,7 @@ export default {
|
|
|
215
211
|
continue;
|
|
216
212
|
}
|
|
217
213
|
|
|
218
|
-
const name =
|
|
214
|
+
const name = nameFormat(row.name, ...param);
|
|
219
215
|
const color = getBgColor(row);
|
|
220
216
|
const contentValue = {
|
|
221
217
|
CLASS_TOOLTIP_NAME: $TOOLTIP.tooltipName + $$.getTargetSelectorSuffix(row.id),
|
|
@@ -368,7 +364,7 @@ export default {
|
|
|
368
364
|
* @param {SVGElement} eventTarget Event element
|
|
369
365
|
* @private
|
|
370
366
|
*/
|
|
371
|
-
showTooltip(selectedData: IDataRow[], eventTarget
|
|
367
|
+
showTooltip(selectedData: IDataRow[], eventTarget: SVGElement): void {
|
|
372
368
|
const $$ = this;
|
|
373
369
|
const {config, $el: {tooltip}} = $$;
|
|
374
370
|
const dataToShow = selectedData.filter(d => d && isValue($$.getBaseValue(d)));
|
|
@@ -114,14 +114,24 @@ function getRadiusFn(expandRate = 0) {
|
|
|
114
114
|
*/
|
|
115
115
|
function getAttrTweenFn(fn: (d: IArcData) => string) {
|
|
116
116
|
return function(d: IArcData): (t: number) => string {
|
|
117
|
-
const
|
|
117
|
+
const getAngleKeyValue = ({startAngle = 0, endAngle = 0, padAngle = 0}) => ({
|
|
118
|
+
startAngle, endAngle, padAngle
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// d3.interpolate interpolates id value, if id is given as color string(ex. gold, silver, etc)
|
|
122
|
+
// to avoid unexpected behavior, interpolate only angle values
|
|
123
|
+
// https://github.com/naver/billboard.js/issues/3321
|
|
124
|
+
const interpolate = d3Interpolate(
|
|
125
|
+
getAngleKeyValue(this._current), getAngleKeyValue(d)
|
|
126
|
+
);
|
|
118
127
|
|
|
119
128
|
this._current = d;
|
|
120
129
|
|
|
121
130
|
return function(t: number): string {
|
|
122
|
-
const interpolated = interpolate(t);
|
|
131
|
+
const interpolated = interpolate(t) as IArcData;
|
|
132
|
+
const {data, index, value} = d;
|
|
123
133
|
|
|
124
|
-
return fn(interpolated);
|
|
134
|
+
return fn({...interpolated, data, index, value});
|
|
125
135
|
};
|
|
126
136
|
};
|
|
127
137
|
}
|
|
@@ -310,7 +320,7 @@ export default {
|
|
|
310
320
|
.innerRadius(inner)
|
|
311
321
|
.outerRadius(outer);
|
|
312
322
|
|
|
313
|
-
const newArc = function(d, withoutUpdate) {
|
|
323
|
+
const newArc = function(d: IArcData, withoutUpdate) {
|
|
314
324
|
let path: string | null = "M 0 0";
|
|
315
325
|
|
|
316
326
|
if (d.value || d.data) {
|
|
@@ -1031,8 +1041,8 @@ export default {
|
|
|
1031
1041
|
// touch events
|
|
1032
1042
|
if (isTouch && $$.hasArcType() && !$$.radars) {
|
|
1033
1043
|
const getEventArc = event => {
|
|
1034
|
-
const
|
|
1035
|
-
const eventArc = d3Select(document.elementFromPoint(
|
|
1044
|
+
const {clientX, clientY} = event.changedTouches?.[0] ?? {clientX: 0, clientY: 0};
|
|
1045
|
+
const eventArc = d3Select(document.elementFromPoint(clientX, clientY));
|
|
1036
1046
|
|
|
1037
1047
|
return eventArc;
|
|
1038
1048
|
};
|
|
@@ -35,7 +35,6 @@ export default {
|
|
|
35
35
|
const $$ = this;
|
|
36
36
|
const {$el} = $$;
|
|
37
37
|
const classChart = $$.getChartClass("Candlestick");
|
|
38
|
-
const classFocus = $$.classFocus.bind($$);
|
|
39
38
|
|
|
40
39
|
if (!$el.candlestick) {
|
|
41
40
|
$$.initCandlestick();
|
|
@@ -43,8 +42,7 @@ export default {
|
|
|
43
42
|
|
|
44
43
|
const mainUpdate = $$.$el.main.select(`.${$CANDLESTICK.chartCandlesticks}`)
|
|
45
44
|
.selectAll(`.${$CANDLESTICK.chartCandlestick}`)
|
|
46
|
-
.data(targets)
|
|
47
|
-
.attr("class", d => classChart(d) + classFocus(d));
|
|
45
|
+
.data(targets);
|
|
48
46
|
|
|
49
47
|
mainUpdate.enter().append("g")
|
|
50
48
|
.attr("class", classChart)
|
|
@@ -80,10 +78,6 @@ export default {
|
|
|
80
78
|
candlestickEnter.append("line");
|
|
81
79
|
candlestickEnter.append("path");
|
|
82
80
|
|
|
83
|
-
if (!$root.candlestick) {
|
|
84
|
-
$root.candlestick = {};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
81
|
$root.candlestick = candlestick.merge(candlestickEnter)
|
|
88
82
|
.style("opacity", initialOpacity);
|
|
89
83
|
},
|
|
@@ -157,8 +151,6 @@ export default {
|
|
|
157
151
|
*/
|
|
158
152
|
generateGetCandlestickPoints(indices, isSub = false): (d, i) => number[][] {
|
|
159
153
|
const $$ = this;
|
|
160
|
-
const {config} = $$;
|
|
161
|
-
|
|
162
154
|
const axis = isSub ? $$.axis.subX : $$.axis.x;
|
|
163
155
|
const targetsNum = $$.getIndicesMax(indices) + 1;
|
|
164
156
|
const barW: IOffset = $$.getBarW("candlestick", axis, targetsNum);
|
|
@@ -174,7 +166,7 @@ export default {
|
|
|
174
166
|
const value = $$.getCandlestickData(d);
|
|
175
167
|
let points;
|
|
176
168
|
|
|
177
|
-
if (value) {
|
|
169
|
+
if (value && isNumber(value.open) && isNumber(value.close)) {
|
|
178
170
|
const posX = {
|
|
179
171
|
start: x(d),
|
|
180
172
|
end: 0
|
|
@@ -192,13 +184,6 @@ export default {
|
|
|
192
184
|
low: y(value.low)
|
|
193
185
|
};
|
|
194
186
|
|
|
195
|
-
// fix posY not to overflow opposite quadrant
|
|
196
|
-
if (config.axis_rotated && (
|
|
197
|
-
(d.value > 0 && posY.start < y0) || (d.value < 0 && y0 < posY.start)
|
|
198
|
-
)) {
|
|
199
|
-
posY.start = y0;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
187
|
posY.start -= (y0 - offset);
|
|
203
188
|
|
|
204
189
|
points = [
|
|
@@ -28,6 +28,26 @@ import CLASS from "../../config/classes";
|
|
|
28
28
|
import {capitalize, getPointer, getRectSegList, getUnique, isObjectType, isNumber, isValue, isUndefined, notEmpty} from "../../module/util";
|
|
29
29
|
import type {IDataRow, IDataIndice, TIndices} from "../data/IData";
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Get grouped data point function for y coordinate
|
|
33
|
+
* - Note: Grouped(stacking) works only for line and bar types
|
|
34
|
+
* @param {object} d data vlaue
|
|
35
|
+
* @returns {Function|undefined}
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
function getGroupedDataPointsFn(d) {
|
|
39
|
+
const $$ = this;
|
|
40
|
+
let fn;
|
|
41
|
+
|
|
42
|
+
if ($$.isLineType(d)) {
|
|
43
|
+
fn = $$.generateGetLinePoints($$.getShapeIndices($$.isLineType));
|
|
44
|
+
} else if ($$.isBarType(d)) {
|
|
45
|
+
fn = $$.generateGetBarPoints($$.getShapeIndices($$.isBarType));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return fn;
|
|
49
|
+
}
|
|
50
|
+
|
|
31
51
|
export interface IOffset {
|
|
32
52
|
_$width: number;
|
|
33
53
|
_$total: number[]
|
|
@@ -87,7 +107,7 @@ export default {
|
|
|
87
107
|
},
|
|
88
108
|
|
|
89
109
|
/**
|
|
90
|
-
* Get shape's indices according it's position
|
|
110
|
+
* Get shape's indices according it's position within each axis tick.
|
|
91
111
|
*
|
|
92
112
|
* From the below example, indices will be:
|
|
93
113
|
* ==> {data1: 0, data2: 0, data3: 1, data4: 1, __max__: 1}
|
|
@@ -125,11 +145,16 @@ export default {
|
|
|
125
145
|
continue;
|
|
126
146
|
}
|
|
127
147
|
|
|
128
|
-
for (let k = 0,
|
|
129
|
-
if (
|
|
130
|
-
ind[d.id] = ind[
|
|
148
|
+
for (let k = 0, key; (key = groups[k]); k++) {
|
|
149
|
+
if (key in ind) {
|
|
150
|
+
ind[d.id] = ind[key];
|
|
131
151
|
break;
|
|
132
152
|
}
|
|
153
|
+
|
|
154
|
+
// for same grouped data, add other data to same indices
|
|
155
|
+
if (d.id !== key && xKey) {
|
|
156
|
+
ind[key] = ind[d.id] ?? i[xKey];
|
|
157
|
+
}
|
|
133
158
|
}
|
|
134
159
|
}
|
|
135
160
|
|
|
@@ -371,6 +396,27 @@ export default {
|
|
|
371
396
|
};
|
|
372
397
|
},
|
|
373
398
|
|
|
399
|
+
/**
|
|
400
|
+
* Get data's y coordinate
|
|
401
|
+
* @param {object} d Target data
|
|
402
|
+
* @param {number} i Index number
|
|
403
|
+
* @returns {number} y coordinate
|
|
404
|
+
* @private
|
|
405
|
+
*/
|
|
406
|
+
circleY(d: IDataRow, i: number): number {
|
|
407
|
+
const $$ = this;
|
|
408
|
+
const id = d.id;
|
|
409
|
+
let points;
|
|
410
|
+
|
|
411
|
+
if ($$.isGrouped(id)) {
|
|
412
|
+
points = getGroupedDataPointsFn.bind($$)(d);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return points ?
|
|
416
|
+
points(d, i)[0][1] :
|
|
417
|
+
$$.getYScaleById(id)($$.getBaseValue(d));
|
|
418
|
+
},
|
|
419
|
+
|
|
374
420
|
getBarW(type, axis, targetsNum: number): number | IOffset {
|
|
375
421
|
const $$ = this;
|
|
376
422
|
const {config, org, scale} = $$;
|
|
@@ -122,12 +122,12 @@ export default {
|
|
|
122
122
|
const isTouch = state.inputType === "touch";
|
|
123
123
|
|
|
124
124
|
$el.treemap
|
|
125
|
-
.on(isTouch ? "touchstart" : "mousemove", event => {
|
|
125
|
+
.on(isTouch ? "touchstart" : "mouseover mousemove", event => {
|
|
126
126
|
const data = getTarget(event);
|
|
127
127
|
|
|
128
128
|
if (data) {
|
|
129
129
|
$$.showTooltip([data], event.currentTarget);
|
|
130
|
-
event.type
|
|
130
|
+
/^(touchstart|mouseover)$/.test(event.type) && $$.setOverOut(true, data);
|
|
131
131
|
}
|
|
132
132
|
})
|
|
133
133
|
.on(isTouch ? "touchend" : "mouseout", event => {
|
|
@@ -76,7 +76,7 @@ export default class BubbleCompare extends Plugin {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
changeCursorPoint(): void {
|
|
79
|
-
this.$$.$el.
|
|
79
|
+
this.$$.$el.eventRect.style("cursor", "pointer");
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
findClosest(values, pos): number {
|
|
@@ -58,9 +58,17 @@ export default class Elements {
|
|
|
58
58
|
.select("line")
|
|
59
59
|
.transition()
|
|
60
60
|
.duration(duration)
|
|
61
|
-
.attr("x1", d =>
|
|
61
|
+
.attr("x1", d => {
|
|
62
|
+
const v = isRotated ? yvCustom(d, "y1") : xvCustom(d, "x1");
|
|
63
|
+
|
|
64
|
+
return v;
|
|
65
|
+
})
|
|
62
66
|
.attr("x2", d => (isRotated ? yvCustom(d, "y2") : xvCustom(d, "x2")))
|
|
63
|
-
.attr("y1", d =>
|
|
67
|
+
.attr("y1", d => {
|
|
68
|
+
const v = isRotated ? xvCustom(d, "x1") : yvCustom(d, "y1");
|
|
69
|
+
|
|
70
|
+
return v;
|
|
71
|
+
})
|
|
64
72
|
.attr("y2", d => (isRotated ? xvCustom(d, "x2") : yvCustom(d, "y2")))
|
|
65
73
|
.transition()
|
|
66
74
|
.style("opacity", null);
|
|
@@ -12,7 +12,7 @@ import Plugin from "../Plugin";
|
|
|
12
12
|
import Options from "./Options";
|
|
13
13
|
import Elements from "./Elements";
|
|
14
14
|
import ColorScale from "./ColorScale";
|
|
15
|
-
import {compareEpochs, isEmpty, isFunction,
|
|
15
|
+
import {compareEpochs, isEmpty, isFunction, pointInRegion} from "./util";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Stanford diagram plugin
|
|
@@ -173,29 +173,6 @@ export default class Stanford extends Plugin {
|
|
|
173
173
|
});
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
xvCustom(d, xyValue): number {
|
|
177
|
-
const $$ = this;
|
|
178
|
-
const {axis, config} = $$;
|
|
179
|
-
let value = xyValue ? d[xyValue] : $$.getBaseValue(d);
|
|
180
|
-
|
|
181
|
-
if (axis.isTimeSeries()) {
|
|
182
|
-
value = parseDate.call($$, value);
|
|
183
|
-
} else if (axis.isCategorized() && isString(value)) {
|
|
184
|
-
value = config.axis_x_categories.indexOf(d.value);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return Math.ceil($$.scale.x(value));
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
yvCustom(d, xyValue): number {
|
|
191
|
-
const $$ = this;
|
|
192
|
-
const {scale} = $$;
|
|
193
|
-
const yScale = d.axis && d.axis === "y2" ? scale.y2 : scale.y;
|
|
194
|
-
const value = xyValue ? d[xyValue] : $$.getBaseValue(d);
|
|
195
|
-
|
|
196
|
-
return Math.ceil(yScale(value));
|
|
197
|
-
}
|
|
198
|
-
|
|
199
176
|
initStanfordData(): void {
|
|
200
177
|
const {config} = this;
|
|
201
178
|
const target = this.$$.data.targets[0];
|
|
@@ -139,7 +139,7 @@ export default class TableView extends Plugin {
|
|
|
139
139
|
}</tr>`;
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
-
const rx =
|
|
142
|
+
const rx = /(<\/?(script|img)[^>]*>|<[^>]+><\/[^>]+>)/ig;
|
|
143
143
|
const r = tplProcess(tpl.body, {
|
|
144
144
|
...config,
|
|
145
145
|
title: config.title || $$.config.title_text || "",
|
|
@@ -158,7 +158,7 @@ export default class TableView extends Plugin {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
$willDestroy(): void {
|
|
161
|
-
this.element.parentNode
|
|
161
|
+
this.element.parentNode?.removeChild(this.element);
|
|
162
162
|
|
|
163
163
|
// remove default css style when left one chart instance
|
|
164
164
|
if (this.$$.charts.length === 1) {
|
|
@@ -46,6 +46,7 @@ export default {
|
|
|
46
46
|
* - **log** type:
|
|
47
47
|
* - the x values specified by [`data.x`](#.data%25E2%2580%25A4x)(or by any equivalent option), must be exclusively-positive.
|
|
48
48
|
* - x axis min value should be >= 0.
|
|
49
|
+
* - for 'category' type, `data.xs` option isn't supported.
|
|
49
50
|
*
|
|
50
51
|
* @name axis․x․type
|
|
51
52
|
* @memberof Options
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
|
+
import type {RegionsType} from "../../../../types/types";
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* main config options
|
|
7
9
|
*/
|
|
@@ -395,15 +397,23 @@ export default {
|
|
|
395
397
|
* @memberof Options
|
|
396
398
|
* @type {Array}
|
|
397
399
|
* @default []
|
|
400
|
+
* @see [Demo](https://naver.github.io/billboard.js/demo/#Region.RegionLabel)
|
|
398
401
|
* @example
|
|
399
402
|
* regions: [
|
|
400
403
|
* {
|
|
401
404
|
* axis: "x",
|
|
402
405
|
* start: 1,
|
|
403
406
|
* end: 4,
|
|
404
|
-
* class: "region-1-4"
|
|
407
|
+
* class: "region-1-4",
|
|
408
|
+
* label: {
|
|
409
|
+
* text: "Region Text",
|
|
410
|
+
* x: 5, // position relative of the initial x coordinate
|
|
411
|
+
* y: 5, // position relative of the initial y coordinate
|
|
412
|
+
* color: "red", // color string
|
|
413
|
+
* rotated: true // make text to show in vertical or horizontal
|
|
414
|
+
* }
|
|
405
415
|
* }
|
|
406
416
|
* ]
|
|
407
417
|
*/
|
|
408
|
-
regions: <
|
|
418
|
+
regions: <RegionsType[]> []
|
|
409
419
|
};
|
|
@@ -22,9 +22,9 @@ export default {
|
|
|
22
22
|
* Specified function receives x of the data point to show.
|
|
23
23
|
* @property {Function} [tooltip.format.name] Set format for the name of each data in tooltip.<br>
|
|
24
24
|
* Specified function receives name, ratio, id and index of the data point to show. ratio will be undefined if the chart is not donut/pie/gauge.
|
|
25
|
-
* @property {Function} [tooltip.format.value] Set format for the value of each data in tooltip. If undefined returned, the row of that value will be skipped to be called.
|
|
25
|
+
* @property {Function} [tooltip.format.value] Set format for the value of each data value in tooltip. If undefined returned, the row of that value will be skipped to be called.
|
|
26
26
|
* - Will pass following arguments to the given function:
|
|
27
|
-
* - `value {string}`: Value of the data point
|
|
27
|
+
* - `value {string}`: Value of the data point. If data row contains multiple or ranged(ex. candlestick, area range, etc.) value, formatter will be called as value length.
|
|
28
28
|
* - `ratio {number}`: Ratio of the data point in the `pie/donut/gauge` and `area/bar` when contains grouped data. Otherwise is `undefined`.
|
|
29
29
|
* - `id {string}`: id of the data point
|
|
30
30
|
* - `index {number}`: Index of the data point
|
|
@@ -63,7 +63,7 @@ export default {
|
|
|
63
63
|
* - The value array length should match with the data length
|
|
64
64
|
* @property {boolean} [tooltip.init.show=false] Show tooltip at the initialization.
|
|
65
65
|
* @property {number} [tooltip.init.x=0] Set x Axis index(or index for Arc(donut, gauge, pie) types) to be shown at the initialization.
|
|
66
|
-
* @property {object} [tooltip.init.position
|
|
66
|
+
* @property {object} [tooltip.init.position] Set the position of tooltip at the initialization.
|
|
67
67
|
* @property {Function} [tooltip.onshow] Set a callback that will be invoked before the tooltip is shown.
|
|
68
68
|
* @property {Function} [tooltip.onhide] Set a callback that will be invoked before the tooltip is hidden.
|
|
69
69
|
* @property {Function} [tooltip.onshown] Set a callback that will be invoked after the tooltip is shown
|
|
@@ -89,6 +89,9 @@ export default {
|
|
|
89
89
|
* format: {
|
|
90
90
|
* title: function(x) { return "Data " + x; },
|
|
91
91
|
* name: function(name, ratio, id, index) { return name; },
|
|
92
|
+
*
|
|
93
|
+
* // If data row contains multiple or ranged(ex. candlestick, area range, etc.) value,
|
|
94
|
+
* // formatter will be called as value length times.
|
|
92
95
|
* value: function(value, ratio, id, index) { return ratio; }
|
|
93
96
|
* },
|
|
94
97
|
* position: function(data, width, height, element, pos) {
|
|
@@ -155,10 +158,10 @@ export default {
|
|
|
155
158
|
* // show at the initialization
|
|
156
159
|
* init: {
|
|
157
160
|
* show: true,
|
|
158
|
-
* x: 2, // x Axis index(or index for Arc(donut, gauge, pie) types)
|
|
161
|
+
* x: 2, // x Axis index (or index for Arc(donut, gauge, pie) types)
|
|
159
162
|
* position: {
|
|
160
|
-
* top: "150px",
|
|
161
|
-
* left:
|
|
163
|
+
* top: "150px", // specify as number or as string with 'px' unit string
|
|
164
|
+
* left: 250 // specify as number or as string with 'px' unit string
|
|
162
165
|
* }
|
|
163
166
|
* },
|
|
164
167
|
*
|
|
@@ -212,10 +215,7 @@ export default {
|
|
|
212
215
|
> {},
|
|
213
216
|
tooltip_init_show: false,
|
|
214
217
|
tooltip_init_x: 0,
|
|
215
|
-
tooltip_init_position:
|
|
216
|
-
top: "0px",
|
|
217
|
-
left: "50px"
|
|
218
|
-
},
|
|
218
|
+
tooltip_init_position: undefined,
|
|
219
219
|
tooltip_linked: false,
|
|
220
220
|
tooltip_linked_name: "",
|
|
221
221
|
tooltip_onshow: () => {},
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
|
+
import type {DataRegionsType} from "../../../../types/types";
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* Axis based chart data config options
|
|
7
9
|
*/
|
|
@@ -128,7 +130,7 @@ export default {
|
|
|
128
130
|
* }
|
|
129
131
|
* }
|
|
130
132
|
*/
|
|
131
|
-
data_regions: <
|
|
133
|
+
data_regions: <DataRegionsType> {},
|
|
132
134
|
|
|
133
135
|
/**
|
|
134
136
|
* Set the stacking to be normalized
|