deno.land / x / billboardjs@3.6.0 / ChartInternal / internals / region.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/** * Copyright (c) 2017 ~ present NAVER Corp. * billboard.js project is licensed under the MIT license */import {select as d3Select} from "d3-selection"; // selectionimport {$REGION} from "../../config/classes";import {isValue, parseDate} from "../../module/util";import type {AxisType} from "../../../types/types";
export default { initRegion() { const $$ = this; const {$el} = $$;
$el.region.main = $el.main .insert("g", ":first-child") .attr("clip-path", $$.state.clip.path) .attr("class", $REGION.regions); },
updateRegion(): void { const $$ = this; const {config, $el: {region}, $T} = $$;
if (!region.main) { $$.initRegion(); }
// hide if arc type region.main.style("visibility", $$.hasArcType() ? "hidden" : null); // select <g> element
let list = region.main .selectAll(`.${$REGION.region}`) .data(config.regions);
$T(list.exit()) .style("opacity", "0") .remove();
list = list.enter() .append("g") .merge(list) .attr("class", $$.classRegion.bind($$));
list .append("rect") .style("fill-opacity", "0");
region.list = list; },
redrawRegion(withTransition) { const $$ = this; const {$el: {region}, $T} = $$; let regions = region.list.select("rect");
regions = $T(regions, withTransition) .attr("x", $$.regionX.bind($$)) .attr("y", $$.regionY.bind($$)) .attr("width", $$.regionWidth.bind($$)) .attr("height", $$.regionHeight.bind($$));
return [ regions .style("fill-opacity", d => (isValue(d.opacity) ? d.opacity : null)) .on("end", function() { // remove unnecessary rect after transition d3Select(this.parentNode) .selectAll("rect:not([x])") .remove(); }) ]; },
getRegionXY(type: AxisType, d): number { const $$ = this; const {config, scale} = $$; const isRotated = config.axis_rotated; const isX = type === "x"; let key = "start"; let currScale; let pos = 0;
if (d.axis === "y" || d.axis === "y2") { if (!isX) { key = "end"; }
if ((isX ? isRotated : !isRotated) && key in d) { currScale = scale[d.axis]; pos = currScale(d[key]); } } else if ((isX ? !isRotated : isRotated) && key in d) { currScale = scale.zoom || scale.x; pos = currScale($$.axis.isTimeSeries() ? parseDate.call($$, d[key]) : d[key]); }
return pos; },
regionX(d): number { return this.getRegionXY("x", d); },
regionY(d): number { return this.getRegionXY("y", d); },
getRegionSize(type, d): number { const $$ = this; const {config, scale, state} = $$; const isRotated = config.axis_rotated; const isWidth = type === "width"; const start = $$[isWidth ? "regionX" : "regionY"](d); let currScale; let key = "end"; let end = state[type];
if (d.axis === "y" || d.axis === "y2") { if (!isWidth) { key = "start"; }
if ((isWidth ? isRotated : !isRotated) && key in d) { currScale = scale[d.axis]; end = currScale(d[key]); } } else if ((isWidth ? !isRotated : isRotated) && key in d) { currScale = scale.zoom || scale.x; end = currScale($$.axis.isTimeSeries() ? parseDate.call($$, d[key]) : d[key]); }
return end < start ? 0 : end - start; },
regionWidth(d): number { return this.getRegionSize("width", d); },
regionHeight(d): number { return this.getRegionSize("height", d); },
isRegionOnX(d): boolean { return !d.axis || d.axis === "x"; },};
billboardjs

Version Info

Tagged at
a year ago