billboard.js 3.2.1 → 3.3.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/dist/billboard.css +2 -3
- package/dist/billboard.js +424 -114
- package/dist/billboard.min.css +2 -2
- package/dist/billboard.min.js +2 -2
- package/dist/billboard.pkgd.js +5415 -3250
- package/dist/billboard.pkgd.min.js +4 -4
- package/dist/plugin/billboardjs-plugin-bubblecompare.d.ts +7 -0
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.d.ts +7 -0
- package/dist/plugin/billboardjs-plugin-sparkline.js +19 -14
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-stanford.d.ts +7 -0
- package/dist/plugin/billboardjs-plugin-stanford.js +17 -12
- package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.d.ts +7 -0
- package/dist/plugin/billboardjs-plugin-tableview.js +19 -14
- package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-textoverlap.d.ts +7 -0
- package/dist/plugin/billboardjs-plugin-textoverlap.js +17 -12
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +5056 -3201
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +5082 -3222
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +5081 -3221
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +5075 -3215
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +5074 -3214
- package/dist/theme/datalab.css +2 -2
- package/dist/theme/datalab.min.css +2 -2
- package/dist/theme/graph.css +2 -2
- package/dist/theme/graph.min.css +2 -2
- package/dist/theme/insight.css +2 -2
- package/dist/theme/insight.min.css +2 -2
- package/dist-esm/billboard.js +737 -456
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.d.ts +7 -0
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-sparkline.d.ts +7 -0
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +8 -8
- package/dist-esm/plugin/billboardjs-plugin-stanford.d.ts +7 -0
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +15 -15
- package/dist-esm/plugin/billboardjs-plugin-tableview.d.ts +7 -0
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +6 -6
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.d.ts +7 -0
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +4 -4
- package/package.json +52 -52
- package/src/Chart/api/chart.ts +7 -1
- package/src/Chart/api/data.ts +3 -4
- package/src/ChartInternal/Axis/Axis.ts +15 -9
- package/src/ChartInternal/ChartInternal.ts +13 -2
- package/src/ChartInternal/data/IData.ts +9 -0
- package/src/ChartInternal/data/convert.ts +1 -1
- package/src/ChartInternal/data/data.ts +28 -11
- package/src/ChartInternal/interactions/interaction.ts +36 -4
- package/src/ChartInternal/internals/domain.ts +4 -2
- package/src/ChartInternal/internals/legend.ts +2 -1
- package/src/ChartInternal/internals/redraw.ts +2 -2
- package/src/ChartInternal/internals/scale.ts +3 -2
- package/src/ChartInternal/internals/size.ts +32 -1
- package/src/ChartInternal/internals/text.ts +2 -2
- package/src/ChartInternal/internals/tooltip.ts +4 -1
- package/src/ChartInternal/shape/arc.ts +3 -5
- package/src/ChartInternal/shape/bar.ts +89 -34
- package/src/ChartInternal/shape/radar.ts +2 -0
- package/src/ChartInternal/shape/shape.ts +72 -11
- package/src/Plugin/sparkline/index.ts +2 -2
- package/src/Plugin/tableview/index.ts +1 -1
- package/src/config/Options/axis/x.ts +27 -7
- package/src/config/Options/axis/y.ts +24 -3
- package/src/config/Options/axis/y2.ts +24 -3
- package/src/config/Options/common/main.ts +11 -1
- package/src/config/Options/data/data.ts +22 -0
- package/src/config/Options/shape/bar.ts +9 -2
- package/src/module/util.ts +19 -20
- package/src/scss/billboard.scss +1 -13
- package/src/scss/theme/datalab.scss +1 -7
- package/src/scss/theme/graph.scss +1 -2
- package/src/scss/theme/insight.scss +1 -2
- package/types/axis.d.ts +22 -8
- package/types/chart.d.ts +1 -1
- package/types/options.d.ts +40 -33
- package/types/plugin/tableview/index.d.ts +3 -3
- package/types/plugin/tableview/options.d.ts +1 -1
- package/types/types.d.ts +9 -6
|
@@ -82,7 +82,7 @@ export default {
|
|
|
82
82
|
* @returns {number} index number
|
|
83
83
|
* @private
|
|
84
84
|
*/
|
|
85
|
-
getIndexByX(x, basedX: (string
|
|
85
|
+
getIndexByX(x: Date|number|string, basedX: (Date|number|string)[]): number {
|
|
86
86
|
const $$ = this;
|
|
87
87
|
|
|
88
88
|
return basedX ?
|
|
@@ -154,7 +154,7 @@ export default {
|
|
|
154
154
|
.map(t => $$.addName($$.getValueOnIndex(t.values, index)));
|
|
155
155
|
|
|
156
156
|
if (filterNull) {
|
|
157
|
-
value = value.filter(v => isValue(v.value));
|
|
157
|
+
value = value.filter(v => v && "value" in v && isValue(v.value));
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
return value;
|
|
@@ -586,6 +586,7 @@ export default {
|
|
|
586
586
|
|
|
587
587
|
/**
|
|
588
588
|
* Sort targets data
|
|
589
|
+
* Note: For stacked bar, will sort from the total sum of data series, not for each stacked bar
|
|
589
590
|
* @param {Array} targetsValue Target value
|
|
590
591
|
* @returns {Array}
|
|
591
592
|
* @private
|
|
@@ -617,9 +618,9 @@ export default {
|
|
|
617
618
|
if (orderAsc || orderDesc) {
|
|
618
619
|
const reducer = (p, c) => p + Math.abs(c.value);
|
|
619
620
|
|
|
620
|
-
fn = (t1, t2) => {
|
|
621
|
-
const t1Sum = t1.values.reduce(reducer, 0);
|
|
622
|
-
const t2Sum = t2.values.reduce(reducer, 0);
|
|
621
|
+
fn = (t1: IData | IDataRow, t2: IData | IDataRow) => {
|
|
622
|
+
const t1Sum = "values" in t1 ? t1.values.reduce(reducer, 0) : t1.value;
|
|
623
|
+
const t2Sum = "values" in t2 ? t2.values.reduce(reducer, 0) : t2.value;
|
|
623
624
|
|
|
624
625
|
return isArc ?
|
|
625
626
|
(orderAsc ? t1Sum - t2Sum : t2Sum - t1Sum) :
|
|
@@ -743,20 +744,23 @@ export default {
|
|
|
743
744
|
let minDist = config.point_sensitivity;
|
|
744
745
|
let closest;
|
|
745
746
|
|
|
746
|
-
// find mouseovering bar
|
|
747
|
+
// find mouseovering bar/candlestick
|
|
748
|
+
// https://github.com/naver/billboard.js/issues/2434
|
|
747
749
|
data
|
|
748
|
-
.filter(v => $$.isBarType(v.id))
|
|
750
|
+
.filter(v => $$.isBarType(v.id) || $$.isCandlestickType(v.id))
|
|
749
751
|
.forEach(v => {
|
|
750
|
-
const
|
|
752
|
+
const selector = $$.isBarType(v.id) ?
|
|
753
|
+
`.${CLASS.chartBar}.${CLASS.target}${$$.getTargetSelectorSuffix(v.id)} .${CLASS.bar}-${v.index}` :
|
|
754
|
+
`.${CLASS.chartCandlestick}.${CLASS.target}${$$.getTargetSelectorSuffix(v.id)} .${CLASS.candlestick}-${v.index} path`;
|
|
751
755
|
|
|
752
|
-
if (!closest && $$.isWithinBar(
|
|
756
|
+
if (!closest && $$.isWithinBar(main.select(selector).node())) {
|
|
753
757
|
closest = v;
|
|
754
758
|
}
|
|
755
759
|
});
|
|
756
760
|
|
|
757
|
-
// find closest point from non-bar
|
|
761
|
+
// find closest point from non-bar/candlestick
|
|
758
762
|
data
|
|
759
|
-
.filter(v => !$$.isBarType(v.id))
|
|
763
|
+
.filter(v => !$$.isBarType(v.id) && !$$.isCandlestickType(v.id))
|
|
760
764
|
.forEach(v => {
|
|
761
765
|
const d = $$.dist(v, pos);
|
|
762
766
|
|
|
@@ -983,6 +987,19 @@ export default {
|
|
|
983
987
|
);
|
|
984
988
|
},
|
|
985
989
|
|
|
990
|
+
/**
|
|
991
|
+
* Determine if bar has ranged data
|
|
992
|
+
* @param {Array} d data value
|
|
993
|
+
* @returns {boolean}
|
|
994
|
+
* @private
|
|
995
|
+
*/
|
|
996
|
+
isBarRangeType(d): boolean {
|
|
997
|
+
const $$ = this;
|
|
998
|
+
const {value} = d;
|
|
999
|
+
|
|
1000
|
+
return $$.isBarType(d) && isArray(value) && value.length === 2 && value.every(v => isNumber(v));
|
|
1001
|
+
},
|
|
1002
|
+
|
|
986
1003
|
/**
|
|
987
1004
|
* Get data object by id
|
|
988
1005
|
* @param {string} id data id
|
|
@@ -254,10 +254,42 @@ export default {
|
|
|
254
254
|
const $$ = this;
|
|
255
255
|
const {$el: {eventRect, zoomResetBtn}} = $$;
|
|
256
256
|
|
|
257
|
-
eventRect
|
|
258
|
-
.on(".zoom", null)
|
|
259
|
-
.on(".drag", null);
|
|
257
|
+
eventRect?.on(".zoom wheel.zoom .drag", null);
|
|
260
258
|
|
|
261
|
-
zoomResetBtn?.
|
|
259
|
+
zoomResetBtn?.on("click", null)
|
|
260
|
+
.style("display", "none");
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Unbind all attached events
|
|
265
|
+
* @private
|
|
266
|
+
*/
|
|
267
|
+
unbindAllEvents(): void {
|
|
268
|
+
const $$ = this;
|
|
269
|
+
const {$el: {arcs, eventRect, legend, region, svg}, brush} = $$;
|
|
270
|
+
const list = [
|
|
271
|
+
"wheel",
|
|
272
|
+
"click",
|
|
273
|
+
"mouseover",
|
|
274
|
+
"mousemove",
|
|
275
|
+
"mouseout",
|
|
276
|
+
"touchstart",
|
|
277
|
+
"touchmove",
|
|
278
|
+
"touchend",
|
|
279
|
+
"touchstart.eventRect",
|
|
280
|
+
"touchmove.eventRect",
|
|
281
|
+
"touchend.eventRect",
|
|
282
|
+
".brush",
|
|
283
|
+
".drag",
|
|
284
|
+
".zoom",
|
|
285
|
+
"wheel.zoom",
|
|
286
|
+
"dblclick.zoom"
|
|
287
|
+
].join(" ");
|
|
288
|
+
|
|
289
|
+
// detach all possible event types
|
|
290
|
+
[svg, eventRect, region?.list, brush?.getSelection(), arcs?.selectAll("path"), legend?.selectAll("g")]
|
|
291
|
+
.forEach(v => v?.on(list, null));
|
|
292
|
+
|
|
293
|
+
$$.unbindZoomEvent?.();
|
|
262
294
|
}
|
|
263
295
|
};
|
|
@@ -145,7 +145,7 @@ export default {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
const domainLength = Math.abs(yDomainMax - yDomainMin);
|
|
148
|
-
|
|
148
|
+
let padding = {top: domainLength * 0.1, bottom: domainLength * 0.1};
|
|
149
149
|
|
|
150
150
|
if (isDefined(center)) {
|
|
151
151
|
const yDomainAbs = Math.max(Math.abs(yDomainMin), Math.abs(yDomainMax));
|
|
@@ -171,6 +171,8 @@ export default {
|
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
padding = $$.getResettedPadding(padding);
|
|
175
|
+
|
|
174
176
|
// if padding is set, the domain will be updated relative the current domain value
|
|
175
177
|
// ex) $$.height=300, padding.top=150, domainLength=4 --> domain=6
|
|
176
178
|
const p = config[`${pfx}_padding`];
|
|
@@ -233,7 +235,7 @@ export default {
|
|
|
233
235
|
|
|
234
236
|
defaultValue = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5;
|
|
235
237
|
} else {
|
|
236
|
-
defaultValue = diff * 0.01;
|
|
238
|
+
defaultValue = $$.getResettedPadding(diff * 0.01);
|
|
237
239
|
}
|
|
238
240
|
|
|
239
241
|
let {left = defaultValue, right = defaultValue} = isNumber(padding) ?
|
|
@@ -622,8 +622,9 @@ export default {
|
|
|
622
622
|
.attr("href", (data, idx, selection) => {
|
|
623
623
|
const node = selection[idx];
|
|
624
624
|
const nodeName = node.nodeName.toLowerCase();
|
|
625
|
+
const id = $$.getTargetSelectorSuffix(data);
|
|
625
626
|
|
|
626
|
-
return nodeName === "use" ? `#${state.datetimeId}-point
|
|
627
|
+
return nodeName === "use" ? `#${state.datetimeId}-point${id}` : undefined;
|
|
627
628
|
});
|
|
628
629
|
} else {
|
|
629
630
|
l.append("line")
|
|
@@ -16,8 +16,7 @@ export default {
|
|
|
16
16
|
state.redrawing = true;
|
|
17
17
|
|
|
18
18
|
const targetsToShow = $$.filterTargetsToShow($$.data.targets);
|
|
19
|
-
const initializing = options
|
|
20
|
-
const flow = options.flow;
|
|
19
|
+
const {flow, initializing} = options;
|
|
21
20
|
const wth = $$.getWithOption(options);
|
|
22
21
|
const duration = wth.Transition ? config.transition_duration : 0;
|
|
23
22
|
const durationForExit = wth.TransitionForExit ? duration : 0;
|
|
@@ -247,6 +246,7 @@ export default {
|
|
|
247
246
|
redrawWithoutRescale() {
|
|
248
247
|
this.redraw({
|
|
249
248
|
withY: false,
|
|
249
|
+
withLegend: true,
|
|
250
250
|
withSubchart: false,
|
|
251
251
|
withEventRect: false,
|
|
252
252
|
withTransitionForAxis: false
|
|
@@ -146,10 +146,11 @@ export default {
|
|
|
146
146
|
|
|
147
147
|
if (hasAxis) {
|
|
148
148
|
const isRotated = config.axis_rotated;
|
|
149
|
+
const resettedPadding = $$.getResettedPadding(1);
|
|
149
150
|
|
|
150
151
|
// update edges
|
|
151
152
|
const min = {
|
|
152
|
-
x: isRotated ?
|
|
153
|
+
x: isRotated ? resettedPadding : 0,
|
|
153
154
|
y: isRotated ? 0 : height,
|
|
154
155
|
subX: isRotated ? 1 : 0,
|
|
155
156
|
subY: isRotated ? 0 : height2
|
|
@@ -157,7 +158,7 @@ export default {
|
|
|
157
158
|
|
|
158
159
|
const max = {
|
|
159
160
|
x: isRotated ? height : width,
|
|
160
|
-
y: isRotated ? width :
|
|
161
|
+
y: isRotated ? width : resettedPadding,
|
|
161
162
|
subX: isRotated ? height : width,
|
|
162
163
|
subY: isRotated ? width2 : 1
|
|
163
164
|
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import {document} from "../../module/browser";
|
|
6
6
|
import CLASS from "../../config/classes";
|
|
7
|
-
import {isValue, ceil10, capitalize} from "../../module/util";
|
|
7
|
+
import {isValue, ceil10, capitalize, isNumber, isEmpty} from "../../module/util";
|
|
8
8
|
|
|
9
9
|
export default {
|
|
10
10
|
/**
|
|
@@ -232,6 +232,35 @@ export default {
|
|
|
232
232
|
}
|
|
233
233
|
},
|
|
234
234
|
|
|
235
|
+
/**
|
|
236
|
+
* Get resetted padding values when 'padding=false' option is set
|
|
237
|
+
* https://github.com/naver/billboard.js/issues/2367
|
|
238
|
+
* @param {number|object} v Padding values to be resetted
|
|
239
|
+
* @returns {number|object} Padding value
|
|
240
|
+
* @private
|
|
241
|
+
*/
|
|
242
|
+
getResettedPadding<T = number | {[key: string]: string;}>(v: T): T {
|
|
243
|
+
const $$ = this;
|
|
244
|
+
const {config} = $$;
|
|
245
|
+
const isNum = isNumber(v);
|
|
246
|
+
let p = isNum ? 0 : {};
|
|
247
|
+
|
|
248
|
+
if (config.padding === false) {
|
|
249
|
+
!isNum && Object.keys(v).forEach(key => {
|
|
250
|
+
// when data.lables=true, do not reset top padding
|
|
251
|
+
p[key] = (
|
|
252
|
+
!isEmpty(config.data_labels) &&
|
|
253
|
+
config.data_labels !== false &&
|
|
254
|
+
key === "top"
|
|
255
|
+
) ? v[key] : 0;
|
|
256
|
+
});
|
|
257
|
+
} else {
|
|
258
|
+
p = v;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return p as T;
|
|
262
|
+
},
|
|
263
|
+
|
|
235
264
|
/**
|
|
236
265
|
* Update size values
|
|
237
266
|
* @param {boolean} isInit If is called at initialization
|
|
@@ -275,6 +304,8 @@ export default {
|
|
|
275
304
|
left: hasArc ? 0 : $$.getCurrentPaddingLeft()
|
|
276
305
|
};
|
|
277
306
|
|
|
307
|
+
state.margin = $$.getResettedPadding(state.margin);
|
|
308
|
+
|
|
278
309
|
// for subchart
|
|
279
310
|
state.margin2 = isRotated ? {
|
|
280
311
|
top: state.margin.top,
|
|
@@ -339,9 +339,9 @@ export default {
|
|
|
339
339
|
let xPos = points[0][0];
|
|
340
340
|
|
|
341
341
|
|
|
342
|
-
if ($$.
|
|
342
|
+
if ($$.isCandlestickType(d)) {
|
|
343
343
|
if (isRotated) {
|
|
344
|
-
xPos = $$.getCandlestickData(d)
|
|
344
|
+
xPos = $$.getCandlestickData(d)?._isUp ?
|
|
345
345
|
points[2][2] + 4 : points[2][1] - 4;
|
|
346
346
|
} else {
|
|
347
347
|
xPos += (points[1][0] - xPos) / 2;
|
|
@@ -21,7 +21,6 @@ export default {
|
|
|
21
21
|
|
|
22
22
|
if ($el.tooltip.empty()) {
|
|
23
23
|
$el.tooltip = $el.chart
|
|
24
|
-
.style("position", "relative")
|
|
25
24
|
.append("div")
|
|
26
25
|
.attr("class", CLASS.tooltipContainer)
|
|
27
26
|
.style("position", "absolute")
|
|
@@ -203,6 +202,10 @@ export default {
|
|
|
203
202
|
));
|
|
204
203
|
|
|
205
204
|
value = `<b>Open:</b> ${open} <b>High:</b> ${high} <b>Low:</b> ${low} <b>Close:</b> ${close}${volume ? ` <b>Volume:</b> ${volume}` : ""}`;
|
|
205
|
+
} else if ($$.isBarRangeType(row)) {
|
|
206
|
+
const [start, end] = row.value;
|
|
207
|
+
|
|
208
|
+
value = `${valueFormat(start)} ~ ${valueFormat(end)}`;
|
|
206
209
|
}
|
|
207
210
|
|
|
208
211
|
if (value !== undefined) {
|
|
@@ -536,11 +536,7 @@ export default {
|
|
|
536
536
|
.attr("class", CLASS[hasGauge ? "chartArcsGaugeTitle" : "chartArcsTitle"])
|
|
537
537
|
.style("text-anchor", "middle");
|
|
538
538
|
|
|
539
|
-
|
|
540
|
-
text
|
|
541
|
-
.attr("dy", "-0.3em")
|
|
542
|
-
.style("font-size", "27px");
|
|
543
|
-
}
|
|
539
|
+
hasGauge && text.attr("dy", "-0.3em");
|
|
544
540
|
|
|
545
541
|
setTextValue(text, title, hasGauge ? undefined : [-0.6, 1.35], true);
|
|
546
542
|
}
|
|
@@ -799,6 +795,8 @@ export default {
|
|
|
799
795
|
return;
|
|
800
796
|
}
|
|
801
797
|
|
|
798
|
+
state.event = event;
|
|
799
|
+
|
|
802
800
|
const eventArc = getEventArc(event);
|
|
803
801
|
const datum: any = eventArc.datum();
|
|
804
802
|
const updated = (datum?.data && datum.data.id) ? $$.updateAngle(datum) : null;
|
|
@@ -2,20 +2,32 @@
|
|
|
2
2
|
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
|
+
import {DataRow} from "../../../types/types";
|
|
5
6
|
import CLASS from "../../config/classes";
|
|
6
|
-
import {
|
|
7
|
+
import {getRandom, isNumber} from "../../module/util";
|
|
8
|
+
import {IDataRow} from "../data/IData";
|
|
9
|
+
|
|
10
|
+
type BarTypeDataRow = DataRow<number | number[]>;
|
|
7
11
|
|
|
8
12
|
export default {
|
|
9
13
|
initBar(): void {
|
|
10
|
-
const {$el} = this;
|
|
14
|
+
const {$el, config, state: {clip}} = this;
|
|
11
15
|
|
|
12
16
|
$el.bar = $el.main.select(`.${CLASS.chart}`)
|
|
13
17
|
// should positioned at the beginning of the shape node to not overlap others
|
|
14
18
|
.insert("g", ":first-child")
|
|
15
19
|
.attr("class", CLASS.chartBars);
|
|
20
|
+
|
|
21
|
+
// set clip-path attribute when condition meet
|
|
22
|
+
// https://github.com/naver/billboard.js/issues/2421
|
|
23
|
+
if (config.clipPath === false && (
|
|
24
|
+
config.bar_radius || config.bar_radius_ratio
|
|
25
|
+
)) {
|
|
26
|
+
$el.bar.attr("clip-path", clip.pathXAxis.replace(/#[^)]*/, `#${clip.id}`));
|
|
27
|
+
}
|
|
16
28
|
},
|
|
17
29
|
|
|
18
|
-
updateTargetsForBar(targets): void {
|
|
30
|
+
updateTargetsForBar(targets: BarTypeDataRow[]): void {
|
|
19
31
|
const $$ = this;
|
|
20
32
|
const {config, $el} = $$;
|
|
21
33
|
const classChartBar = $$.getChartClass("Bar");
|
|
@@ -32,7 +44,7 @@ export default {
|
|
|
32
44
|
.data(
|
|
33
45
|
// remove
|
|
34
46
|
targets.filter(
|
|
35
|
-
v =>
|
|
47
|
+
v => v.values.some(d => (isNumber(d.value) || $$.isBarRangeType(d)))
|
|
36
48
|
)
|
|
37
49
|
)
|
|
38
50
|
.attr("class", d => classChartBar(d) + classFocus(d));
|
|
@@ -78,7 +90,7 @@ export default {
|
|
|
78
90
|
|
|
79
91
|
/**
|
|
80
92
|
* Redraw function
|
|
81
|
-
* @param {Function} drawFn Retuned
|
|
93
|
+
* @param {Function} drawFn Retuned function from .getDrawShape() => .generateDrawBar()
|
|
82
94
|
* @param {boolean} withTransition With or without transition
|
|
83
95
|
* @param {boolean} isSub Subchart draw
|
|
84
96
|
* @returns {Array}
|
|
@@ -89,18 +101,37 @@ export default {
|
|
|
89
101
|
|
|
90
102
|
return [
|
|
91
103
|
$$.$T(bar, withTransition, getRandom())
|
|
92
|
-
.attr("d", d => isNumber(d.value) && drawFn(d))
|
|
104
|
+
.attr("d", d => (isNumber(d.value) || $$.isBarRangeType(d)) && drawFn(d))
|
|
93
105
|
.style("fill", this.color)
|
|
94
106
|
.style("opacity", null)
|
|
95
107
|
];
|
|
96
108
|
},
|
|
97
109
|
|
|
98
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Generate draw function
|
|
112
|
+
* @param {object} barIndices data order within x axis.
|
|
113
|
+
* barIndices ==> {data1: 0, data2: 0, data3: 1, data4: 1, __max__: 1}
|
|
114
|
+
*
|
|
115
|
+
* When gropus given as:
|
|
116
|
+
* groups: [
|
|
117
|
+
* ["data1", "data2"],
|
|
118
|
+
* ["data3", "data4"]
|
|
119
|
+
* ],
|
|
120
|
+
*
|
|
121
|
+
* Will be rendered as:
|
|
122
|
+
* data1 data3 data1 data3
|
|
123
|
+
* data2 data4 data2 data4
|
|
124
|
+
* -------------------------
|
|
125
|
+
* 0 1
|
|
126
|
+
* @param {boolean} isSub If is for subchart
|
|
127
|
+
* @returns {Function}
|
|
128
|
+
* @private
|
|
129
|
+
*/
|
|
130
|
+
generateDrawBar(barIndices, isSub?: boolean): (d: IDataRow, i: number) => string {
|
|
99
131
|
const $$ = this;
|
|
100
132
|
const {config} = $$;
|
|
101
133
|
const getPoints = $$.generateGetBarPoints(barIndices, isSub);
|
|
102
134
|
const isRotated = config.axis_rotated;
|
|
103
|
-
const isGrouped = config.data_groups.length;
|
|
104
135
|
const barRadius = config.bar_radius;
|
|
105
136
|
const barRadiusRatio = config.bar_radius_ratio;
|
|
106
137
|
|
|
@@ -110,7 +141,7 @@ export default {
|
|
|
110
141
|
isNumber(barRadiusRatio) ? w => w * barRadiusRatio : null
|
|
111
142
|
);
|
|
112
143
|
|
|
113
|
-
return (d, i) => {
|
|
144
|
+
return (d: IDataRow, i: number) => {
|
|
114
145
|
// 4 points that make a bar
|
|
115
146
|
const points = getPoints(d, i);
|
|
116
147
|
|
|
@@ -122,7 +153,11 @@ export default {
|
|
|
122
153
|
const pathRadius = ["", ""];
|
|
123
154
|
let radius = 0;
|
|
124
155
|
|
|
125
|
-
|
|
156
|
+
const isGrouped = $$.isGrouped(d.id);
|
|
157
|
+
const hasRadius = d.value !== 0 && getRadius;
|
|
158
|
+
const isRadiusData = hasRadius && isGrouped ? $$.isStackingRadiusData(d) : false;
|
|
159
|
+
|
|
160
|
+
if (hasRadius && (!isGrouped || isRadiusData)) {
|
|
126
161
|
const index = isRotated ? indexY : indexX;
|
|
127
162
|
const barW = points[2][index] - points[0][index];
|
|
128
163
|
|
|
@@ -146,7 +181,46 @@ export default {
|
|
|
146
181
|
};
|
|
147
182
|
},
|
|
148
183
|
|
|
149
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Determine if given stacking bar data is radius type
|
|
186
|
+
* @param {Object} d Data row
|
|
187
|
+
* @returns {boolean}
|
|
188
|
+
*/
|
|
189
|
+
isStackingRadiusData(d: IDataRow): boolean {
|
|
190
|
+
const $$ = this;
|
|
191
|
+
const {config, data} = $$;
|
|
192
|
+
const {id, index, value} = d;
|
|
193
|
+
|
|
194
|
+
// Find same grouped ids
|
|
195
|
+
const keys = config.data_groups.find(v => v.indexOf(id) > -1);
|
|
196
|
+
|
|
197
|
+
// Get sorted list
|
|
198
|
+
const sortedList = $$.orderTargets(
|
|
199
|
+
$$.filterTargetsToShow(data.targets.filter($$.isBarType, $$))
|
|
200
|
+
).filter(v => keys.indexOf(v.id) > -1);
|
|
201
|
+
|
|
202
|
+
// Get sorted Ids. Filter positive or negative values Ids from given value
|
|
203
|
+
const sortedIds = sortedList
|
|
204
|
+
.map(v => v.values.filter(
|
|
205
|
+
v2 => v2.index === index && (
|
|
206
|
+
value > 0 ? v2.value > 0 : v2.value < 0
|
|
207
|
+
))[0]
|
|
208
|
+
)
|
|
209
|
+
.filter(Boolean)
|
|
210
|
+
.map(v => v.id);
|
|
211
|
+
|
|
212
|
+
// If the given id stays in the last position, then radius should be applied.
|
|
213
|
+
return value !== 0 && (sortedIds.indexOf(id) === sortedIds.length - 1);
|
|
214
|
+
},
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Generate bar coordinate points data
|
|
218
|
+
* @param {object} barIndices Data order within x axis.
|
|
219
|
+
* @param {boolean} isSub If is for subchart
|
|
220
|
+
* @returns {Array} Array of coordinate points
|
|
221
|
+
* @private
|
|
222
|
+
*/
|
|
223
|
+
generateGetBarPoints(barIndices, isSub?: boolean): (d: IDataRow, i: number) => [number, number][] {
|
|
150
224
|
const $$ = this;
|
|
151
225
|
const {config} = $$;
|
|
152
226
|
const axis = isSub ? $$.axis.subX : $$.axis.x;
|
|
@@ -157,7 +231,7 @@ export default {
|
|
|
157
231
|
const barOffset = $$.getShapeOffset($$.isBarType, barIndices, !!isSub);
|
|
158
232
|
const yScale = $$.getYScaleById.bind($$);
|
|
159
233
|
|
|
160
|
-
return (d, i) => {
|
|
234
|
+
return (d: IDataRow, i: number) => {
|
|
161
235
|
const y0 = yScale.call($$, d.id, isSub)($$.getShapeYMin(d.id));
|
|
162
236
|
const offset = barOffset(d, i) || y0; // offset is for stacked bar chart
|
|
163
237
|
const width = isNumber(barW) ? barW : barW[d.id] || barW._$width;
|
|
@@ -171,7 +245,9 @@ export default {
|
|
|
171
245
|
posY = y0;
|
|
172
246
|
}
|
|
173
247
|
|
|
174
|
-
|
|
248
|
+
if (!$$.isBarRangeType(d)) {
|
|
249
|
+
posY -= (y0 - offset);
|
|
250
|
+
}
|
|
175
251
|
|
|
176
252
|
const startPosX = posX + width;
|
|
177
253
|
|
|
@@ -183,26 +259,5 @@ export default {
|
|
|
183
259
|
[startPosX, offset]
|
|
184
260
|
];
|
|
185
261
|
};
|
|
186
|
-
},
|
|
187
|
-
|
|
188
|
-
isWithinBar(that): boolean {
|
|
189
|
-
const mouse = getPointer(this.state.event, that);
|
|
190
|
-
const list = getRectSegList(that);
|
|
191
|
-
const [seg0, seg1] = list;
|
|
192
|
-
const x = Math.min(seg0.x, seg1.x);
|
|
193
|
-
const y = Math.min(seg0.y, seg1.y);
|
|
194
|
-
const offset = this.config.bar_sensitivity;
|
|
195
|
-
const {width, height} = that.getBBox();
|
|
196
|
-
const sx = x - offset;
|
|
197
|
-
const ex = x + width + offset;
|
|
198
|
-
const sy = y + height + offset;
|
|
199
|
-
const ey = y - offset;
|
|
200
|
-
|
|
201
|
-
const isWithin = sx < mouse[0] &&
|
|
202
|
-
mouse[0] < ex &&
|
|
203
|
-
ey < mouse[1] &&
|
|
204
|
-
mouse[1] < sy;
|
|
205
|
-
|
|
206
|
-
return isWithin;
|
|
207
262
|
}
|
|
208
263
|
};
|