deno.land / x / billboardjs@3.6.0 / ChartInternal / internals / selection.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/** * Copyright (c) 2017 ~ present NAVER Corp. * billboard.js project is licensed under the MIT license */import {select as d3Select} from "d3-selection";import drag from "../interactions/drag";import {$SELECT, $SHAPE} from "../../config/classes";import {callFn} from "../../module/util";
export default { ...drag,
/** * Select a point * @param {object} target Target point * @param {object} d Data object * @param {number} i Index number * @private */ selectPoint(target, d, i: number): void { const $$ = this; const {config, $el: {main}, $T} = $$; const isRotated = config.axis_rotated; const cx = (isRotated ? $$.circleY : $$.circleX).bind($$); const cy = (isRotated ? $$.circleX : $$.circleY).bind($$); const r = $$.pointSelectR.bind($$);
callFn(config.data_onselected, $$.api, d, target.node());
// add selected-circle on low layer g $T(main.select(`.${$SELECT.selectedCircles}${$$.getTargetSelectorSuffix(d.id)}`) .selectAll(`.${$SELECT.selectedCircle}-${i}`) .data([d]) .enter() .append("circle") .attr("class", () => $$.generateClass($SELECT.selectedCircle, i)) .attr("cx", cx) .attr("cy", cy) .attr("stroke", $$.color) .attr("r", d2 => $$.pointSelectR(d2) * 1.4) ).attr("r", r); },
/** * Unelect a point * @param {object} target Target point * @param {object} d Data object * @param {number} i Index number * @private */ unselectPoint(target, d, i: number): void { const $$ = this; const {config, $el: {main}, $T} = $$;
callFn(config.data_onunselected, $$.api, d, target.node());
// remove selected-circle from low layer g $T(main.select(`.${$SELECT.selectedCircles}${$$.getTargetSelectorSuffix(d.id)}`) .selectAll(`.${$SELECT.selectedCircle}-${i}`) ) .attr("r", 0) .remove(); },
/** * Toggles the selection of points * @param {boolean} selected whether or not to select. * @param {object} target Target object * @param {object} d Data object * @param {number} i Index number * @private */ togglePoint(selected, target, d, i: number): void { const method = `${selected ? "" : "un"}selectPoint`;
this[method](target, d, i); },
/** * Select a path * @param {object} target Target path * @param {object} d Data object * @private */ selectPath(target, d): void { const $$ = this; const {config} = $$;
callFn(config.data_onselected, $$.api, d, target.node());
if (config.interaction_brighten) { target.style("filter", "brightness(1.25)"); } },
/** * Unelect a path * @private * @param {object} target Target path * @param {object} d Data object */ unselectPath(target, d): void { const $$ = this; const {config} = $$;
callFn(config.data_onunselected, $$.api, d, target.node());
if (config.interaction_brighten) { target.style("filter", null); } },
/** * Toggles the selection of lines * @param {boolean} selected whether or not to select. * @param {object} target Target object * @param {object} d Data object * @param {number} i Index number * @private */ togglePath(selected, target, d, i: number): void { this[ `${selected ? "" : "un"}selectPath` ](target, d, i); },
/** * Returns the toggle method of the target * @param {object} that shape * @param {object} d Data object * @returns {Function} toggle method * @private */ getToggle(that, d): Function { const $$ = this;
return that.nodeName === "path" ? $$.togglePath : ( $$.isStepType(d) ? () => {} : // circle is hidden in step chart, so treat as within the click area $$.togglePoint ); },
/** * Toggles the selection of shapes * @param {object} that shape * @param {object} d Data object * @param {number} i Index number * @private */ toggleShape(that, d, i: number): void { const $$ = this; const {config, $el: {main}} = $$;
if (config.data_selection_enabled && config.data_selection_isselectable.bind($$.api)(d)) { const shape = d3Select(that); const isSelected = shape.classed($SELECT.SELECTED); const toggle = $$.getToggle(that, d).bind($$); let toggledShape;
if (!config.data_selection_multiple) { let selector = `.${$SHAPE.shapes}`;
if (config.data_selection_grouped) { selector += $$.getTargetSelectorSuffix(d.id); }
main.selectAll(selector) .selectAll(`.${$SHAPE.shape}`) .each(function(d, i) { const shape = d3Select(this);
if (shape.classed($SELECT.SELECTED)) { toggledShape = shape; toggle(false, shape.classed($SELECT.SELECTED, false), d, i); } }); }
if (!toggledShape || toggledShape.node() !== shape.node()) { shape.classed($SELECT.SELECTED, !isSelected); toggle(!isSelected, shape, d, i); } } },};
billboardjs

Version Info

Tagged at
a year ago