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
package/src/module/util.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {d3Selection} from "../../types/types";
|
|
|
9
9
|
import {document, window} from "./browser";
|
|
10
10
|
|
|
11
11
|
export {
|
|
12
|
+
addCssRules,
|
|
12
13
|
asHalfPixel,
|
|
13
14
|
brushEmpty,
|
|
14
15
|
callFn,
|
|
@@ -51,6 +52,8 @@ export {
|
|
|
51
52
|
mergeObj,
|
|
52
53
|
notEmpty,
|
|
53
54
|
parseDate,
|
|
55
|
+
runUntil,
|
|
56
|
+
runWorker,
|
|
54
57
|
sanitise,
|
|
55
58
|
setTextValue,
|
|
56
59
|
sortValue,
|
|
@@ -254,6 +257,7 @@ function getPathBox(
|
|
|
254
257
|
};
|
|
255
258
|
}
|
|
256
259
|
|
|
260
|
+
|
|
257
261
|
/**
|
|
258
262
|
* Get event's current position coordinates
|
|
259
263
|
* @param {object} event Event object
|
|
@@ -457,6 +461,28 @@ function camelize(str: string, separator = "-"): string {
|
|
|
457
461
|
*/
|
|
458
462
|
const toArray = (v: CSSStyleDeclaration | any): any => [].slice.call(v);
|
|
459
463
|
|
|
464
|
+
/**
|
|
465
|
+
* Add CSS rules
|
|
466
|
+
* @param {object} style Style object
|
|
467
|
+
* @param {string} selector Selector string
|
|
468
|
+
* @param {Array} prop Prps arrary
|
|
469
|
+
* @returns {number} Newely added rule index
|
|
470
|
+
* @private
|
|
471
|
+
*/
|
|
472
|
+
function addCssRules(style, selector: string, prop: string[]): number {
|
|
473
|
+
const {rootSelctor, sheet} = style;
|
|
474
|
+
const getSelector = s => s
|
|
475
|
+
.replace(/\s?(bb-)/g, ".$1")
|
|
476
|
+
.replace(/\.+/g, ".");
|
|
477
|
+
|
|
478
|
+
const rule = `${rootSelctor} ${getSelector(selector)} {${prop.join(";")}}`;
|
|
479
|
+
|
|
480
|
+
return sheet[sheet.insertRule ? "insertRule" : "addRule"](
|
|
481
|
+
rule,
|
|
482
|
+
sheet.cssRules.length
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
|
|
460
486
|
/**
|
|
461
487
|
* Get css rules for specified stylesheets
|
|
462
488
|
* @param {Array} styleSheets The stylesheets to get the rules from
|
|
@@ -771,3 +797,90 @@ function convertInputType(mouse: boolean, touch: boolean): "mouse" | "touch" | n
|
|
|
771
797
|
// fallback to 'mouse' if no input type is detected.
|
|
772
798
|
return (hasMouse && "mouse") || (hasTouch && "touch") || "mouse";
|
|
773
799
|
}
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* Create and run on Web Worker
|
|
803
|
+
* @param {boolean} useWorker Use Web Worker
|
|
804
|
+
* @param {Function} fn Function to be executed in worker
|
|
805
|
+
* @param {Function} callback Callback function to receive result from worker
|
|
806
|
+
* @param {Array} depsFn Dependency functions to run given function(fn).
|
|
807
|
+
* @returns {object}
|
|
808
|
+
* @example
|
|
809
|
+
* const worker = runWorker(function(arg) {
|
|
810
|
+
* // do some tasks...
|
|
811
|
+
* console.log("param:", A(arg));
|
|
812
|
+
*
|
|
813
|
+
* return 1234;
|
|
814
|
+
* }, function(data) {
|
|
815
|
+
* // callback after worker is done
|
|
816
|
+
* console.log("result:", data);
|
|
817
|
+
* },
|
|
818
|
+
* [function A(){}]
|
|
819
|
+
* );
|
|
820
|
+
*
|
|
821
|
+
* worker(11111);
|
|
822
|
+
* @private
|
|
823
|
+
*/
|
|
824
|
+
function runWorker(
|
|
825
|
+
useWorker = true, fn: Function, callback: Function, depsFn?: Function[]
|
|
826
|
+
): Function {
|
|
827
|
+
let runFn;
|
|
828
|
+
|
|
829
|
+
if (window.Worker && useWorker) {
|
|
830
|
+
// Web Worker body
|
|
831
|
+
const blob = new Blob([
|
|
832
|
+
`${depsFn?.map(String).join(";") ?? ""}
|
|
833
|
+
|
|
834
|
+
self.onmessage=function({data}) {
|
|
835
|
+
const result = (${fn.toString()}).apply(null, data);
|
|
836
|
+
self.postMessage(result);
|
|
837
|
+
};`
|
|
838
|
+
], {
|
|
839
|
+
type: "text/javascript"
|
|
840
|
+
});
|
|
841
|
+
const worker = new Worker(URL.createObjectURL(blob));
|
|
842
|
+
|
|
843
|
+
runFn = function(...args) {
|
|
844
|
+
// trigger worker
|
|
845
|
+
worker.postMessage(args);
|
|
846
|
+
|
|
847
|
+
// listen worker
|
|
848
|
+
worker.onmessage = function(e) {
|
|
849
|
+
return callback(e.data);
|
|
850
|
+
};
|
|
851
|
+
|
|
852
|
+
// handle error
|
|
853
|
+
worker.onerror = function(e) {
|
|
854
|
+
console.error(e);
|
|
855
|
+
};
|
|
856
|
+
|
|
857
|
+
// return new Promise((resolve, reject) => {
|
|
858
|
+
// worker.onmessage = ({data}) => resolve(data);
|
|
859
|
+
// worker.onerror = reject;
|
|
860
|
+
// });
|
|
861
|
+
};
|
|
862
|
+
} else {
|
|
863
|
+
runFn = function(...args) {
|
|
864
|
+
const res = fn(...args);
|
|
865
|
+
|
|
866
|
+
callback(res);
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
return runFn;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* Run function until given condition function return true
|
|
875
|
+
* @param {Function} fn Function to be executed when condition is true
|
|
876
|
+
* @param {Function} conditionFn Condition function to check if condition is true
|
|
877
|
+
* @private
|
|
878
|
+
*/
|
|
879
|
+
function runUntil(fn: Function, conditionFn: Function): void {
|
|
880
|
+
if (conditionFn() === false) {
|
|
881
|
+
window.requestAnimationFrame(() => runUntil(fn, conditionFn));
|
|
882
|
+
} else {
|
|
883
|
+
fn();
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
|
package/types/chart.d.ts
CHANGED
|
@@ -347,7 +347,7 @@ export interface Chart {
|
|
|
347
347
|
load(this: Chart, args: {
|
|
348
348
|
append?: boolean;
|
|
349
349
|
url?: string;
|
|
350
|
-
json?:
|
|
350
|
+
json?: Array<{[key: string]: string | number }> | {[key: string]: Array<string | number>};
|
|
351
351
|
rows?: PrimitiveArray[];
|
|
352
352
|
columns?: PrimitiveArray[];
|
|
353
353
|
data?: Array<{ [key: string]: number }>;
|
|
@@ -358,7 +358,7 @@ export interface Chart {
|
|
|
358
358
|
axes?: { [key: string]: string | string[] };
|
|
359
359
|
colors?: { [key: string]: string };
|
|
360
360
|
headers?: { [key: string]: string };
|
|
361
|
-
keys?: { [key: string]: string };
|
|
361
|
+
keys?: { [key: string]: string | string[] };
|
|
362
362
|
mimeType?: string;
|
|
363
363
|
type?: string;
|
|
364
364
|
types?: { [key: string]: string };
|
package/types/options.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import Bubblecompare from "./plugin/bubblecompare/index";
|
|
|
8
8
|
import Stanford from "./plugin/stanford/index";
|
|
9
9
|
import TextOverlap from "./plugin/textoverlap/index";
|
|
10
10
|
import {Chart} from "./chart";
|
|
11
|
-
import {IData} from "../src/ChartInternal/data/IData";
|
|
11
|
+
import {IArcData, IData, IDataRow} from "../src/ChartInternal/data/IData";
|
|
12
12
|
|
|
13
13
|
export interface ChartOptions {
|
|
14
14
|
/**
|
|
@@ -49,6 +49,24 @@ export interface ChartOptions {
|
|
|
49
49
|
imgUrl?: string;
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
+
boost?: {
|
|
53
|
+
/**
|
|
54
|
+
* Avoid setting inline styles for each shape elements.
|
|
55
|
+
* - **NOTE:**
|
|
56
|
+
* - Will append <style> to the head tag and will add shpes' CSS rules dynamically.
|
|
57
|
+
* - For now, covers colors related properties (fill, stroke, etc.) only.
|
|
58
|
+
*/
|
|
59
|
+
useCssRule?: boolean;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Use Web Worker as possible for processing.
|
|
63
|
+
* - **NOTE:**
|
|
64
|
+
* - For now, only applies for data conversion at the initial time.
|
|
65
|
+
* - As of Web Worker's async nature, handling chart instance synchrously is not recommended.
|
|
66
|
+
*/
|
|
67
|
+
useWorker?: boolean;
|
|
68
|
+
};
|
|
69
|
+
|
|
52
70
|
size?: {
|
|
53
71
|
/**
|
|
54
72
|
* The desired width of the chart element.
|
|
@@ -99,6 +117,14 @@ export interface ChartOptions {
|
|
|
99
117
|
* Indicate if the chart should automatically get resized when the window gets resized.
|
|
100
118
|
*/
|
|
101
119
|
auto?: boolean;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Set resize timer option.
|
|
123
|
+
* - **NOTE:**
|
|
124
|
+
* - The resize function will be called using: true - `setTimeout()`, false - `requestIdleCallback()`.
|
|
125
|
+
* - Given number(delay in ms) value, resize function will be triggered using `setTimer()` with given delay.
|
|
126
|
+
*/
|
|
127
|
+
timer?: boolean | number;
|
|
102
128
|
};
|
|
103
129
|
|
|
104
130
|
color?: {
|
|
@@ -254,6 +280,12 @@ export interface ChartOptions {
|
|
|
254
280
|
*/
|
|
255
281
|
above?: boolean;
|
|
256
282
|
|
|
283
|
+
/**
|
|
284
|
+
* Set background area `below` the data chart line.
|
|
285
|
+
* - **NOTE**: Can't be used along with `above` option. When above & below options are set to true, `above` will be prioritized.
|
|
286
|
+
*/
|
|
287
|
+
below?: boolean;
|
|
288
|
+
|
|
257
289
|
/**
|
|
258
290
|
* Set area node to be positioned over line node.
|
|
259
291
|
*/
|
|
@@ -1082,10 +1114,10 @@ export interface TooltipOptions {
|
|
|
1082
1114
|
*/
|
|
1083
1115
|
contents?: ((
|
|
1084
1116
|
this: Chart,
|
|
1085
|
-
data:
|
|
1086
|
-
defaultTitleFormat: string,
|
|
1087
|
-
defaultValueFormat: string,
|
|
1088
|
-
color:
|
|
1117
|
+
data: IDataRow[],
|
|
1118
|
+
defaultTitleFormat: (x: Date|number|string) => number|string,
|
|
1119
|
+
defaultValueFormat: (value: number, ratio: number|undefined, id: string) => number|string,
|
|
1120
|
+
color: (d: IDataRow|IArcData|string) => string
|
|
1089
1121
|
) => string) | {
|
|
1090
1122
|
/**
|
|
1091
1123
|
* Set CSS selector or element reference to bind tooltip.
|
|
@@ -1193,7 +1225,7 @@ export interface SubchartOptions {
|
|
|
1193
1225
|
* Use custom format for x axis ticks - see 'axis.x.tick.format' option for details.
|
|
1194
1226
|
*/
|
|
1195
1227
|
format?: string
|
|
1196
|
-
| ((this: Chart, x:
|
|
1228
|
+
| ((this: Chart, x: Date) => string | number)
|
|
1197
1229
|
| ((this: Chart, index: number, categoryName: string) => string);
|
|
1198
1230
|
/**
|
|
1199
1231
|
* Show or hide x axis tick line.
|
|
@@ -1520,7 +1552,7 @@ export interface Data {
|
|
|
1520
1552
|
/**
|
|
1521
1553
|
* Set custom data name.
|
|
1522
1554
|
*/
|
|
1523
|
-
names?: { [key: string]: string };
|
|
1555
|
+
names?: { [key: string]: string|null };
|
|
1524
1556
|
/**
|
|
1525
1557
|
* Set custom data class.
|
|
1526
1558
|
* If this option is specified, the element g for the data has an additional class that has the prefix billboard-target- (e.g. billboard-target-additional-data1-class).
|
|
@@ -1613,7 +1645,12 @@ export interface Data {
|
|
|
1613
1645
|
*/
|
|
1614
1646
|
y?: number;
|
|
1615
1647
|
};
|
|
1616
|
-
}
|
|
1648
|
+
};
|
|
1649
|
+
|
|
1650
|
+
/**
|
|
1651
|
+
* Rotate label text. Specify degree value in a range of `0 ~ 360`.
|
|
1652
|
+
*/
|
|
1653
|
+
rotate?: number;
|
|
1617
1654
|
};
|
|
1618
1655
|
|
|
1619
1656
|
/**
|