billboard.js 3.5.0-next.2 → 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.
Files changed (45) hide show
  1. package/dist/billboard.css +1 -1
  2. package/dist/billboard.js +116 -91
  3. package/dist/billboard.min.css +1 -1
  4. package/dist/billboard.min.js +2 -2
  5. package/dist/billboard.pkgd.js +124 -96
  6. package/dist/billboard.pkgd.min.js +2 -2
  7. package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  8. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  9. package/dist/plugin/billboardjs-plugin-sparkline.js +2 -2
  10. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  11. package/dist/plugin/billboardjs-plugin-stanford.js +2 -2
  12. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-tableview.js +2 -2
  14. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  15. package/dist/plugin/billboardjs-plugin-textoverlap.js +2 -2
  16. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  17. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +10 -7
  18. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +10 -7
  19. package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +10 -7
  20. package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +10 -7
  21. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +10 -7
  22. package/dist/theme/datalab.css +1 -1
  23. package/dist/theme/datalab.min.css +1 -1
  24. package/dist/theme/graph.css +1 -1
  25. package/dist/theme/graph.min.css +1 -1
  26. package/dist/theme/insight.css +1 -1
  27. package/dist/theme/insight.min.css +1 -1
  28. package/dist-esm/billboard.js +86 -60
  29. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  30. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +2 -2
  31. package/dist-esm/plugin/billboardjs-plugin-stanford.js +2 -2
  32. package/dist-esm/plugin/billboardjs-plugin-tableview.js +2 -2
  33. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -2
  34. package/package.json +14 -14
  35. package/src/ChartInternal/ChartInternal.ts +2 -11
  36. package/src/ChartInternal/internals/class.ts +1 -1
  37. package/src/ChartInternal/internals/color.ts +1 -25
  38. package/src/ChartInternal/internals/legend.ts +21 -6
  39. package/src/ChartInternal/internals/style.ts +54 -0
  40. package/src/ChartInternal/internals/text.ts +3 -4
  41. package/src/ChartInternal/shape/arc.ts +4 -3
  42. package/src/ChartInternal/shape/bar.ts +6 -5
  43. package/src/ChartInternal/shape/line.ts +3 -2
  44. package/src/ChartInternal/shape/point.ts +8 -6
  45. package/src/config/Store/State.ts +1 -1
@@ -39,6 +39,7 @@ import redraw from "./internals/redraw";
39
39
  import scale from "./internals/scale";
40
40
  import shape from "./shape/shape";
41
41
  import size from "./internals/size";
42
+ import style from "./internals/style";
42
43
  import text from "./internals/text";
43
44
  import title from "./internals/title";
44
45
  import tooltip from "./internals/tooltip";
@@ -266,22 +267,11 @@ export default class ChartInternal {
266
267
  const $$ = <any> this;
267
268
  const {config, format, state} = $$;
268
269
  const isRotated = config.axis_rotated;
269
- const useCssRule = config.boost_useCssRule;
270
270
 
271
271
  // color settings
272
272
  $$.color = $$.generateColor();
273
- $$.colorByRule = $$.color;
274
- $$.colorTextByRule = $$.updateTextColor.bind($$);
275
273
  $$.levelColor = $$.generateLevelColor();
276
274
 
277
- if (useCssRule) {
278
- state.colorRule = {};
279
-
280
- // to not apply inline color setting
281
- $$.colorByRule = null;
282
- $$.colorTextByRule = null;
283
- }
284
-
285
275
  // when 'padding=false' is set, disable axes and subchart. Because they are useless.
286
276
  if (config.padding === false) {
287
277
  config.axis_x_show = false;
@@ -812,6 +802,7 @@ extend(ChartInternal.prototype, [
812
802
  scale,
813
803
  shape,
814
804
  size,
805
+ style,
815
806
  text,
816
807
  title,
817
808
  tooltip,
@@ -112,5 +112,5 @@ export default {
112
112
  selectorLegends(ids): string[] | null {
113
113
  return ids?.length ?
114
114
  ids.map(id => this.selectorLegend(id)) : null;
115
- },
115
+ }
116
116
  };
@@ -7,7 +7,7 @@ import {scaleOrdinal as d3ScaleOrdinal} from "d3-scale";
7
7
  import {document} from "../../module/browser";
8
8
  import {$ARC, $COLOR, $SHAPE} from "../../config/classes";
9
9
  import {KEY} from "../../module/Cache";
10
- import {addCssRules, notEmpty, isFunction, isObject, isString} from "../../module/util";
10
+ import {notEmpty, isFunction, isObject, isString} from "../../module/util";
11
11
  import {IArcData, IDataRow} from "../data/IData";
12
12
  import {d3Selection} from "../../../types";
13
13
 
@@ -75,30 +75,6 @@ function getColorFromCss(element: d3Selection): string[] {
75
75
  const schemeCategory10 = ["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf"];
76
76
 
77
77
  export default {
78
- /**
79
- * Add props color css rule to given selector
80
- * @param {Function} fn Color function
81
- * @param {string} selector CSS selector
82
- * @param {Array} props CSS props list
83
- * @returns {Function}
84
- * @private
85
- */
86
- setColorByRule(fn: Function, selector: string, props: string[]): Function {
87
- const $$ = this;
88
- const {config, state: {colorRule, style}} = $$;
89
- const colorFn = fn || $$.color;
90
-
91
- return config.boost_useCssRule ? (selection: d3Selection) => {
92
- selection.each((d: IDataRow) => {
93
- const color = colorFn.call($$, d);
94
- const shapeSelector = `${$SHAPE.shapes}${$$.getTargetSelectorSuffix(d.id)} .${selector}`;
95
-
96
- (shapeSelector in colorRule) && style.sheet.deleteRule(colorRule[shapeSelector]);
97
- $$.state.colorRule[shapeSelector] = addCssRules(style, shapeSelector, props.map(v => `${v}: ${color}`));
98
- });
99
- } : () => {};
100
- },
101
-
102
78
  generateColor(): Function {
103
79
  const $$ = this;
104
80
  const {$el, config} = $$;
@@ -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)
@@ -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
+ };
@@ -127,8 +127,7 @@ export default {
127
127
  const mainTextEnter = mainTextUpdate.enter().append("g")
128
128
  .style("opacity", "0")
129
129
  .attr("class", classChartText)
130
- .call($$.setColorByRule($$.updateTextColor, $TEXT.text, ["fill"]))
131
- .style("pointer-events", "none");
130
+ .call($$.setCssRule(true, ` .${$TEXT.text}`, ["fill", "pointer-events:none"], $$.updateTextColor));
132
131
 
133
132
  mainTextEnter.append("g")
134
133
  .attr("class", classTexts);
@@ -167,7 +166,7 @@ export default {
167
166
 
168
167
  return (config.axis_rotated ? (isEndAnchor ? "end" : "start") : "middle");
169
168
  })
170
- .style("fill", $$.colorTextByRule)
169
+ .style("fill", $$.getStylePropValue($$.updateTextColor))
171
170
  .style("fill-opacity", "0")
172
171
  .each(function(d, i, texts) {
173
172
  const node = d3Select(this);
@@ -267,7 +266,7 @@ export default {
267
266
  const rotateString = angle ? `rotate(${angle})` : "";
268
267
 
269
268
  $$.$el.text
270
- .style("fill", $$.colorTextByRule)
269
+ .style("fill", $$.getStylePropValue($$.updateTextColor))
271
270
  .attr("filter", $$.updateTextBacgroundColor.bind($$))
272
271
  .style("fill-opacity", forFlow ? 0 : $$.opacityForText.bind($$))
273
272
  .each(function(d: IDataRow, i: number) {
@@ -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
@@ -16,7 +16,8 @@ export default {
16
16
  $el.bar = $el.main.select(`.${$COMMON.chart}`)
17
17
  // should positioned at the beginning of the shape node to not overlap others
18
18
  .insert("g", ":first-child")
19
- .attr("class", $BAR.chartBars);
19
+ .attr("class", $BAR.chartBars)
20
+ .call(this.setCssRule(false, `.${$BAR.chartBars}`, ["pointer-events:none"]));
20
21
 
21
22
  // set clip-path attribute when condition meet
22
23
  // https://github.com/naver/billboard.js/issues/2421
@@ -52,13 +53,13 @@ export default {
52
53
  const mainBarEnter = mainBarUpdate.enter().append("g")
53
54
  .attr("class", classChartBar)
54
55
  .style("opacity", "0")
55
- .style("pointer-events", "none");
56
+ .style("pointer-events", $$.getStylePropValue("none"));
56
57
 
57
58
  // Bars for each data
58
59
  mainBarEnter.append("g")
59
60
  .attr("class", classBars)
60
61
  .style("cursor", d => (isSelectable?.bind?.($$.api)(d) ? "pointer" : null))
61
- .call($$.setColorByRule(null, $BAR.bar, ["fill"]));
62
+ .call($$.setCssRule(true, ` .${$BAR.bar}`, ["fill"], $$.color));
62
63
  },
63
64
 
64
65
  /**
@@ -84,7 +85,7 @@ export default {
84
85
 
85
86
  $root.bar = bar.enter().append("path")
86
87
  .attr("class", classBar)
87
- .style("fill", $$.colorByRule)
88
+ .style("fill", $$.getStylePropValue($$.color))
88
89
  .merge(bar)
89
90
  .style("opacity", initialOpacity);
90
91
  },
@@ -103,7 +104,7 @@ export default {
103
104
  return [
104
105
  $$.$T(bar, withTransition, getRandom())
105
106
  .attr("d", d => (isNumber(d.value) || $$.isBarRangeType(d)) && drawFn(d))
106
- .style("fill", $$.colorByRule)
107
+ .style("fill", $$.getStylePropValue($$.color))
107
108
  .style("opacity", null)
108
109
  ];
109
110
  },
@@ -12,7 +12,8 @@ export default {
12
12
  const {$el} = this;
13
13
 
14
14
  $el.line = $el.main.select(`.${$COMMON.chart}`).append("g")
15
- .attr("class", $LINE.chartLines);
15
+ .attr("class", $LINE.chartLines)
16
+ .call(this.setCssRule(false, `.${$LINE.chartLines}`, ["pointer-events:none"]));
16
17
  },
17
18
 
18
19
  updateTargetsForLine(t): void {
@@ -36,7 +37,7 @@ export default {
36
37
  const mainLineEnter = mainLineUpdate.enter().append("g")
37
38
  .attr("class", classChartLine)
38
39
  .style("opacity", "0")
39
- .style("pointer-events", "none");
40
+ .style("pointer-events", $$.getStylePropValue("none"));
40
41
 
41
42
  // Lines for each data
42
43
  mainLineEnter.append("g")
@@ -101,8 +101,10 @@ export default {
101
101
 
102
102
  enterNode.append("g")
103
103
  .attr("class", classCircles)
104
- .style("cursor", d => (isFunction(isSelectable) && isSelectable(d) ? "pointer" : null))
105
- .call($$.setColorByRule(null, $CIRCLE.circle, ["fill", "stroke"]))
104
+ .call(selection => {
105
+ $$.setCssRule(true, `.${$CIRCLE.circles}`, ["cursor:pointer"], isSelectable)(selection);
106
+ $$.setCssRule(true, ` .${$CIRCLE.circle}`, ["fill", "stroke"], $$.color)(selection);
107
+ })
106
108
  .style("opacity", function() {
107
109
  const parent = d3Select(this.parentNode);
108
110
 
@@ -139,10 +141,10 @@ export default {
139
141
 
140
142
  circles.enter()
141
143
  .filter(Boolean)
142
- .append($$.point("create", this, $$.pointR.bind($$), $$.colorByRule));
144
+ .append($$.point("create", this, $$.pointR.bind($$), $$.getStylePropValue($$.color)));
143
145
 
144
146
  $root.circle = $root.main.selectAll(`.${$CIRCLE.circles} .${$CIRCLE.circle}`)
145
- .style("stroke", $$.colorByRule)
147
+ .style("stroke", $$.getStylePropValue($$.color))
146
148
  .style("opacity", $$.initialOpacityForCircle.bind($$));
147
149
  }
148
150
  },
@@ -157,7 +159,7 @@ export default {
157
159
  return [];
158
160
  }
159
161
 
160
- const fn = $$.point("update", $$, cx, cy, $$.colorByRule, withTransition, flow, selectedCircles);
162
+ const fn = $$.point("update", $$, cx, cy, $$.getStylePropValue($$.color), withTransition, flow, selectedCircles);
161
163
  const posAttr = $$.isCirclePoint() ? "c" : "";
162
164
 
163
165
  const t = getRandom();
@@ -195,7 +197,7 @@ export default {
195
197
  const cx = (hasRadar ? $$.radarCircleX : $$.circleX).bind($$);
196
198
  const cy = (hasRadar ? $$.radarCircleY : $$.circleY).bind($$);
197
199
  const withTransition = toggling || isUndefined(d);
198
- const fn = $$.point("update", $$, cx, cy, $$.colorByRule, resizing ? false : withTransition);
200
+ const fn = $$.point("update", $$, cx, cy, $$.getStylePropValue($$.color), resizing ? false : withTransition);
199
201
 
200
202
  if (d) {
201
203
  circle = circle
@@ -42,7 +42,7 @@ export default class State {
42
42
  hasRadar: false,
43
43
 
44
44
  // for data CSS rule index (used when boost.useCssRule is true)
45
- colorRule: {},
45
+ cssRule: {},
46
46
 
47
47
  current: {
48
48
  // chart whole dimension