deno.land / x / billboardjs@3.6.0 / Chart / api / regions.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/** * Copyright (c) 2017 ~ present NAVER Corp. * billboard.js project is licensed under the MIT license */import {$REGION} from "../../config/classes";import {getOption, extend} from "../../module/util";
type RegionsParam = {axis?: string, class?: string, start?: number, end?: number}[];
/** * Update regions. * @function regions * @instance * @memberof Chart * @param {Array} regions Regions will be replaced with this argument. The format of this argument is the same as regions. * @returns {Array} regions * @example * // Show 2 regions * chart.regions([ * {axis: "x", start: 5, class: "regionX"}, * {axis: "y", end: 50, class: "regionY"} * ]); */function regions(regions: RegionsParam): RegionsParam { const $$ = this.internal; const {config} = $$;
if (!regions) { return config.regions; }
config.regions = regions; $$.redrawWithoutRescale();
return regions;}
extend(regions, { /** * Add new region.<br><br> * This API adds new region instead of replacing like regions. * @function regions․add * @instance * @memberof Chart * @param {Array|object} regions New region will be added. The format of this argument is the same as regions and it's possible to give an Object if only one region will be added. * @returns {Array} regions * @example * // Add a new region * chart.regions.add( * {axis: "x", start: 5, class: "regionX"} * ); * * // Add new regions * chart.regions.add([ * {axis: "x", start: 5, class: "regionX"}, * {axis: "y", end: 50, class: "regionY"} *]); */ add: function(regions: RegionsParam): RegionsParam { const $$ = this.internal; const {config} = $$;
if (!regions) { return config.regions; }
config.regions = config.regions.concat(regions); $$.redrawWithoutRescale();
return config.regions; },
/** * Remove regions.<br><br> * This API removes regions. * @function regions․remove * @instance * @memberof Chart * @param {object} optionsValue This argument should include classes. If classes is given, the regions that have one of the specified classes will be removed. If args is not given, all of regions will be removed. * @returns {Array} regions Removed regions * @example * // regions that have 'region-A' or 'region-B' will be removed. * chart.regions.remove({ * classes: [ * "region-A", "region-B" * ] * }); * * // all of regions will be removed. * chart.regions.remove(); */ remove: function(optionsValue: RegionsParam): RegionsParam { const $$ = this.internal; const {config, $T} = $$;
const options = optionsValue || {}; const classes = getOption(options, "classes", [$REGION.region]); let regions = $$.$el.main.select(`.${$REGION.regions}`) .selectAll(classes.map(c => `.${c}`));
$T(regions) .style("opacity", "0") .remove();
regions = config.regions;
if (Object.keys(options).length) { regions = regions.filter(region => { let found = false;
if (!region.class) { return true; }
region.class.split(" ").forEach(c => { if (classes.indexOf(c) >= 0) { found = true; } });
return !found; });
config.regions = regions; } else { config.regions = []; }
return regions; }});
export default {regions};
billboardjs

Version Info

Tagged at
2 years ago