billboard.js 3.6.0 → 3.6.2

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.
Files changed (39) hide show
  1. package/README.md +13 -77
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +4531 -7081
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +2 -2
  6. package/dist/billboard.pkgd.js +7931 -11567
  7. package/dist/billboard.pkgd.min.js +2 -3
  8. package/dist/plugin/billboardjs-plugin-bubblecompare.js +27 -62
  9. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  10. package/dist/plugin/billboardjs-plugin-sparkline.js +303 -528
  11. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  12. package/dist/plugin/billboardjs-plugin-stanford.js +368 -648
  13. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  14. package/dist/plugin/billboardjs-plugin-tableview.js +305 -513
  15. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  16. package/dist/plugin/billboardjs-plugin-textoverlap.js +306 -500
  17. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  18. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +2121 -2265
  19. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +2892 -3502
  20. package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +3146 -4013
  21. package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +2921 -3514
  22. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +3037 -3835
  23. package/dist/theme/datalab.css +1 -1
  24. package/dist/theme/datalab.min.css +1 -1
  25. package/dist/theme/graph.css +1 -1
  26. package/dist/theme/graph.min.css +1 -1
  27. package/dist/theme/insight.css +1 -1
  28. package/dist/theme/insight.min.css +1 -1
  29. package/dist-esm/billboard.js +54 -38
  30. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +3 -8
  31. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +3 -12
  32. package/dist-esm/plugin/billboardjs-plugin-stanford.js +3 -12
  33. package/dist-esm/plugin/billboardjs-plugin-tableview.js +3 -12
  34. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +3 -8
  35. package/package.json +23 -23
  36. package/src/ChartInternal/data/IData.ts +8 -2
  37. package/src/ChartInternal/interactions/eventrect.ts +22 -13
  38. package/src/ChartInternal/interactions/interaction.ts +39 -26
  39. package/types/options.d.ts +7 -0
@@ -2,12 +2,18 @@
2
2
  * Copyright (c) 2017 ~ present NAVER Corp.
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
- export interface IDataRow {
6
- x: number;
5
+ type TDataRow = {
7
6
  value: number | null;
8
7
  id: string;
9
8
  index: number;
10
9
  name?: string;
10
+ };
11
+
12
+ export interface IDataRow extends TDataRow {
13
+ x: number;
14
+ }
15
+ export interface IArcDataRow extends TDataRow {
16
+ ratio: number;
11
17
  }
12
18
 
13
19
  export interface IData {
@@ -242,33 +242,42 @@ export default {
242
242
  rectW = (d): number => {
243
243
  const x = getPrevNextX(d);
244
244
  const xDomain = xScale.domain();
245
+ let val: number;
245
246
 
246
247
  // if there this is a single data point make the eventRect full width (or height)
247
248
  if (x.prev === null && x.next === null) {
248
- return isRotated ? state.height : state.width;
249
+ val = isRotated ? state.height : state.width;
250
+ } else if (x.prev === null) {
251
+ val = (xScale(x.next) + xScale(d.x)) / 2;
252
+ } else if (x.next === null) {
253
+ val = xScale(xDomain[1]) - (
254
+ (xScale(x.prev) + xScale(d.x)) / 2
255
+ );
256
+ } else {
257
+ Object.keys(x).forEach((key, i) => {
258
+ x[key] = x[key] ?? xDomain[i];
259
+ });
260
+
261
+ val = Math.max(0, (xScale(x.next) - xScale(x.prev)) / 2);
249
262
  }
250
263
 
251
- Object.keys(x).forEach((key, i) => {
252
- x[key] = x[key] ?? xDomain[i];
253
- });
254
-
255
- return Math.max(0, (xScale(x.next) - xScale(x.prev)) / 2);
264
+ return val;
256
265
  };
257
266
 
258
267
  rectX = (d): number => {
259
268
  const x = getPrevNextX(d);
260
- const thisX = d.x;
269
+ let val: number;
261
270
 
262
271
  // if there this is a single data point position the eventRect at 0
263
272
  if (x.prev === null && x.next === null) {
264
- return 0;
265
- }
266
-
267
- if (x.prev === null) {
268
- x.prev = xScale.domain()[0];
273
+ val = 0;
274
+ } else if (x.prev === null) {
275
+ val = xScale(xScale.domain()[0]);
276
+ } else {
277
+ val = (xScale(d.x) + xScale(x.prev)) / 2;
269
278
  }
270
279
 
271
- return (xScale(thisX) + xScale(x.prev)) / 2;
280
+ return val;
272
281
  };
273
282
  }
274
283
 
@@ -7,6 +7,7 @@ import {drag as d3Drag} from "d3-drag";
7
7
  import {$ARC, $AXIS, $COMMON, $SHAPE} from "../../config/classes";
8
8
  import {KEY} from "../../module/Cache";
9
9
  import {emulateEvent, getPointer, isNumber, isObject} from "../../module/util";
10
+ import type {IArcDataRow} from "../data/IData";
10
11
 
11
12
  export default {
12
13
  selectRectForSingle(context, eventRect, index: number): void {
@@ -27,24 +28,26 @@ export default {
27
28
  }
28
29
  }
29
30
 
30
- main.selectAll(`.${$SHAPE.shape}-${index}`)
31
+ const shapeAtIndex = main.selectAll(`.${$SHAPE.shape}-${index}`)
31
32
  .each(function() {
32
33
  d3Select(this).classed($COMMON.EXPANDED, true);
33
34
 
34
35
  if (isSelectionEnabled) {
35
36
  eventRect.style("cursor", isSelectionGrouped ? "pointer" : null);
36
37
  }
37
-
38
- if (!isTooltipGrouped) {
39
- $$.hideGridFocus?.();
40
- $$.hideTooltip();
41
-
42
- !isSelectionGrouped && $$.setExpand(index);
43
- }
44
38
  })
45
39
  .filter(function(d) {
46
40
  return $$.isWithinShape(this, d);
47
- })
41
+ });
42
+
43
+ if (shapeAtIndex.empty() && !isTooltipGrouped) {
44
+ $$.hideGridFocus?.();
45
+ $$.hideTooltip();
46
+
47
+ !isSelectionGrouped && $$.setExpand(index);
48
+ }
49
+
50
+ shapeAtIndex
48
51
  .call(selected => {
49
52
  const d = selected.data();
50
53
 
@@ -107,42 +110,52 @@ export default {
107
110
  * @param {number|object} d data object
108
111
  * @private
109
112
  */
110
- setOverOut(isOver: boolean, d): void {
113
+ setOverOut(isOver: boolean, d: number | IArcDataRow): void {
111
114
  const $$ = this;
112
115
  const {config, state: {hasRadar}, $el: {main}} = $$;
113
116
  const isArc = isObject(d);
114
117
 
115
118
  // Call event handler
116
119
  if (isArc || d !== -1) {
117
- let callback = config[isOver ? "data_onover" : "data_onout"].bind($$.api);
120
+ const callback = config[isOver ? "data_onover" : "data_onout"].bind($$.api);
118
121
 
119
122
  config.color_onover && $$.setOverColor(isOver, d, isArc);
120
123
 
121
- if (isArc) {
122
- callback(d, main.select(`.${$ARC.arc}${$$.getTargetSelectorSuffix(d.id)}`).node());
124
+ if (isArc && "id") {
125
+ callback(d, main.select(`.${$ARC.arc}${$$.getTargetSelectorSuffix((d as IArcDataRow).id)}`).node());
123
126
  } else if (!config.tooltip_grouped) {
124
- let last = $$.cache.get(KEY.setOverOut) || [];
127
+ const last = $$.cache.get(KEY.setOverOut) || [];
125
128
 
126
- const shape = main.selectAll(`.${$SHAPE.shape}-${d}`)
129
+ // select based on the index
130
+ const shapesAtIndex = main.selectAll(`.${$SHAPE.shape}-${d}`)
127
131
  .filter(function(d) {
128
132
  return $$.isWithinShape(this, d);
129
133
  });
130
134
 
131
- shape
132
- .each(function(d) {
133
- if (last.length === 0 || last.every(v => v !== this)) {
134
- callback(d, this);
135
- last.push(this);
136
- }
137
- });
135
+ // filter if has new selection
136
+ const shape = shapesAtIndex.filter(function() {
137
+ return last.every(v => v !== this);
138
+ });
138
139
 
139
- if (last.length > 0 && shape.empty()) {
140
- callback = config.data_onout.bind($$.api);
140
+ // call onout callback
141
+ if (!isOver || shapesAtIndex.empty() || (
142
+ last.length === shape.size() && shape.nodes().every(((v, i) => v !== last[i]))
143
+ )) {
144
+ while (last.length) {
145
+ const target = last.pop();
141
146
 
142
- last.forEach(v => callback(d3Select(v).datum(), v));
143
- last = [];
147
+ config.data_onout.bind($$.api)(d3Select(target).datum(), target);
148
+ }
144
149
  }
145
150
 
151
+ // call onover callback
152
+ shape.each(function() {
153
+ if (isOver) {
154
+ callback(d3Select(this).datum(), this);
155
+ last.push(this);
156
+ }
157
+ });
158
+
146
159
  $$.cache.add(KEY.setOverOut, last);
147
160
  } else {
148
161
  if (isOver) {
@@ -82,6 +82,13 @@ export interface ChartOptions {
82
82
  height?: number;
83
83
  };
84
84
 
85
+ svg?: {
86
+ /**
87
+ * Set svg element's class name
88
+ */
89
+ classname?: string;
90
+ };
91
+
85
92
  /**
86
93
  * Set padding of chart, and accepts object or boolean type.
87
94
  * - `Object`: Specify each side's padding.