@rokkit/chart 1.0.0-next.121 → 1.0.0-next.123
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 +43 -35
- package/package.json +3 -3
- package/src/Plot/Axis.svelte +87 -95
- package/src/Plot/Bar.svelte +86 -86
- package/src/Plot/Grid.svelte +57 -57
- package/src/Plot/Legend.svelte +120 -122
- package/src/Plot/Root.svelte +107 -105
- package/src/elements/ColorRamp.svelte +19 -19
- package/src/elements/ContinuousLegend.svelte +1 -1
- package/src/elements/DefinePatterns.svelte +1 -1
- package/src/elements/DiscreteLegend.svelte +1 -1
- package/src/elements/SymbolGrid.svelte +1 -1
- package/src/examples/BarChartExample.svelte +42 -42
- package/src/index.js +13 -13
- package/src/lib/brewing/axes.svelte.js +120 -122
- package/src/lib/brewing/bars.svelte.js +70 -70
- package/src/lib/brewing/dimensions.svelte.js +25 -23
- package/src/lib/brewing/index.svelte.js +192 -204
- package/src/lib/brewing/legends.svelte.js +51 -52
- package/src/lib/brewing/scales.svelte.js +59 -68
- package/src/lib/brewing/types.js +2 -2
- package/src/lib/context.js +117 -107
- package/src/lib/scales.svelte.js +80 -87
- package/src/lib/utils.js +70 -72
- package/src/old_lib/chart.js +4 -4
- package/src/patterns/Brick.svelte +1 -1
- package/src/patterns/Circles.svelte +1 -1
- package/src/patterns/CrossHatch.svelte +1 -1
- package/src/patterns/Dots.svelte +1 -1
- package/src/patterns/OutlineCircles.svelte +1 -1
- package/src/patterns/Tile.svelte +1 -1
- package/src/patterns/Triangles.svelte +1 -1
- package/src/symbols/RoundedSquare.svelte +0 -1
- package/src/template/shapes/Circles.svelte +1 -1
- package/src/template/shapes/Lines.svelte +1 -1
- package/src/template/shapes/Polygons.svelte +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {} from './types.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @typedef {import('./types').ChartMargin} ChartMargin
|
|
@@ -9,29 +9,29 @@ import { } from './types.js';
|
|
|
9
9
|
* Default chart margin
|
|
10
10
|
* @type {ChartMargin}
|
|
11
11
|
*/
|
|
12
|
-
export const DEFAULT_MARGIN = { top: 20, right: 30, bottom: 40, left: 50 }
|
|
12
|
+
export const DEFAULT_MARGIN = { top: 20, right: 30, bottom: 40, left: 50 }
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Creates chart dimensions based on width, height and margins
|
|
16
|
-
*
|
|
16
|
+
*
|
|
17
17
|
* @param {number} width - Total chart width
|
|
18
18
|
* @param {number} height - Total chart height
|
|
19
19
|
* @param {ChartMargin} margin - Chart margins
|
|
20
20
|
* @returns {ChartDimensions} Chart dimensions
|
|
21
21
|
*/
|
|
22
22
|
export function createDimensions(width = 600, height = 400, margin = DEFAULT_MARGIN) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
return {
|
|
24
|
+
width,
|
|
25
|
+
height,
|
|
26
|
+
margin: { ...margin },
|
|
27
|
+
innerWidth: width - margin.left - margin.right,
|
|
28
|
+
innerHeight: height - margin.top - margin.bottom
|
|
29
|
+
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Updates existing dimensions with new values
|
|
34
|
-
*
|
|
34
|
+
*
|
|
35
35
|
* @param {ChartDimensions} dimensions - Current dimensions
|
|
36
36
|
* @param {Object} updates - Values to update
|
|
37
37
|
* @param {number} [updates.width] - New width
|
|
@@ -40,15 +40,17 @@ export function createDimensions(width = 600, height = 400, margin = DEFAULT_MAR
|
|
|
40
40
|
* @returns {ChartDimensions} Updated dimensions
|
|
41
41
|
*/
|
|
42
42
|
export function updateDimensions(dimensions, updates = {}) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
const newDimensions = { ...dimensions }
|
|
44
|
+
|
|
45
|
+
if (updates.width !== undefined) newDimensions.width = updates.width
|
|
46
|
+
if (updates.height !== undefined) newDimensions.height = updates.height
|
|
47
|
+
if (updates.margin !== undefined) newDimensions.margin = { ...updates.margin }
|
|
48
|
+
|
|
49
|
+
// Recalculate inner dimensions
|
|
50
|
+
newDimensions.innerWidth =
|
|
51
|
+
newDimensions.width - newDimensions.margin.left - newDimensions.margin.right
|
|
52
|
+
newDimensions.innerHeight =
|
|
53
|
+
newDimensions.height - newDimensions.margin.top - newDimensions.margin.bottom
|
|
54
|
+
|
|
55
|
+
return newDimensions
|
|
56
|
+
}
|
|
@@ -1,214 +1,202 @@
|
|
|
1
|
-
import { createDimensions, updateDimensions } from './dimensions.svelte.js'
|
|
2
|
-
import { createScales, getOrigin } from './scales.svelte.js'
|
|
3
|
-
import { createBars, filterBars, createGroupedBars } from './bars.svelte.js'
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
createYAxis,
|
|
7
|
-
createGrid,
|
|
8
|
-
createTickAttributes
|
|
9
|
-
} from './axes.svelte.js';
|
|
10
|
-
import {
|
|
11
|
-
createLegend,
|
|
12
|
-
filterByLegend,
|
|
13
|
-
createLegendItemAttributes
|
|
14
|
-
} from './legends.svelte.js';
|
|
1
|
+
import { createDimensions, updateDimensions } from './dimensions.svelte.js'
|
|
2
|
+
import { createScales, getOrigin } from './scales.svelte.js'
|
|
3
|
+
import { createBars, filterBars, createGroupedBars } from './bars.svelte.js'
|
|
4
|
+
import { createXAxis, createYAxis, createGrid, createTickAttributes } from './axes.svelte.js'
|
|
5
|
+
import { createLegend, filterByLegend, createLegendItemAttributes } from './legends.svelte.js'
|
|
15
6
|
|
|
16
7
|
/**
|
|
17
8
|
* Chart Brewing - A collection of pure functions for chart data preparation
|
|
18
9
|
*/
|
|
19
10
|
export {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
11
|
+
// Dimensions
|
|
12
|
+
createDimensions,
|
|
13
|
+
updateDimensions,
|
|
14
|
+
|
|
15
|
+
// Scales
|
|
16
|
+
createScales,
|
|
17
|
+
getOrigin,
|
|
18
|
+
|
|
19
|
+
// Bars
|
|
20
|
+
createBars,
|
|
21
|
+
filterBars,
|
|
22
|
+
createGroupedBars,
|
|
23
|
+
|
|
24
|
+
// Axes
|
|
25
|
+
createXAxis,
|
|
26
|
+
createYAxis,
|
|
27
|
+
createGrid,
|
|
28
|
+
createTickAttributes,
|
|
29
|
+
|
|
30
|
+
// Legends
|
|
31
|
+
createLegend,
|
|
32
|
+
filterByLegend,
|
|
33
|
+
createLegendItemAttributes
|
|
34
|
+
}
|
|
44
35
|
|
|
45
36
|
/**
|
|
46
37
|
* Main class that manages chart state and provides access to all brewing functions
|
|
47
38
|
*/
|
|
48
39
|
export class ChartBrewer {
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
return { ...this.#fields };
|
|
213
|
-
}
|
|
214
|
-
}
|
|
40
|
+
#data = []
|
|
41
|
+
#dimensions = createDimensions()
|
|
42
|
+
#scales = { x: null, y: null, color: null }
|
|
43
|
+
#fields = { x: null, y: null, color: null }
|
|
44
|
+
#options = {
|
|
45
|
+
padding: 0.2,
|
|
46
|
+
animationDuration: 300
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new ChartBrewer instance
|
|
51
|
+
*
|
|
52
|
+
* @param {Object} options Configuration options
|
|
53
|
+
*/
|
|
54
|
+
constructor(options = {}) {
|
|
55
|
+
this.#dimensions = createDimensions(options.width, options.height, options.margin)
|
|
56
|
+
|
|
57
|
+
if (options.padding !== undefined) this.#options.padding = options.padding
|
|
58
|
+
if (options.animationDuration !== undefined)
|
|
59
|
+
this.#options.animationDuration = options.animationDuration
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Sets the data for the chart
|
|
64
|
+
*
|
|
65
|
+
* @param {Array} data Data array
|
|
66
|
+
* @returns {ChartBrewer} this for method chaining
|
|
67
|
+
*/
|
|
68
|
+
setData(data) {
|
|
69
|
+
this.#data = Array.isArray(data) ? data : []
|
|
70
|
+
return this
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Sets the field mappings for axes and color
|
|
75
|
+
*
|
|
76
|
+
* @param {Object} fields Field mappings
|
|
77
|
+
* @returns {ChartBrewer} this for method chaining
|
|
78
|
+
*/
|
|
79
|
+
setFields({ x, y, color }) {
|
|
80
|
+
if (x !== undefined) this.#fields.x = x
|
|
81
|
+
if (y !== undefined) this.#fields.y = y
|
|
82
|
+
if (color !== undefined) this.#fields.color = color
|
|
83
|
+
return this
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Sets the dimensions of the chart
|
|
88
|
+
*
|
|
89
|
+
* @param {Object} dimensions Chart dimensions
|
|
90
|
+
* @returns {ChartBrewer} this for method chaining
|
|
91
|
+
*/
|
|
92
|
+
setDimensions({ width, height, margin }) {
|
|
93
|
+
this.#dimensions = updateDimensions(this.#dimensions, { width, height, margin })
|
|
94
|
+
return this
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Creates scales based on data and dimensions
|
|
99
|
+
*
|
|
100
|
+
* @returns {ChartBrewer} this for method chaining
|
|
101
|
+
*/
|
|
102
|
+
createScales() {
|
|
103
|
+
this.#scales = createScales(this.#data, this.#fields, this.#dimensions, {
|
|
104
|
+
padding: this.#options.padding
|
|
105
|
+
})
|
|
106
|
+
return this
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Creates bar data for rendering
|
|
111
|
+
*
|
|
112
|
+
* @returns {Array} Data for rendering bars
|
|
113
|
+
*/
|
|
114
|
+
createBars() {
|
|
115
|
+
return createBars(this.#data, this.#fields, this.#scales, this.#dimensions)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Creates x-axis tick data for rendering
|
|
120
|
+
*
|
|
121
|
+
* @param {Object} options Axis options
|
|
122
|
+
* @returns {Object} Axis rendering data
|
|
123
|
+
*/
|
|
124
|
+
createXAxis(options = {}) {
|
|
125
|
+
return createXAxis(this.#scales, this.#dimensions, options)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Creates y-axis tick data for rendering
|
|
130
|
+
*
|
|
131
|
+
* @param {Object} options Axis options
|
|
132
|
+
* @returns {Object} Axis rendering data
|
|
133
|
+
*/
|
|
134
|
+
createYAxis(options = {}) {
|
|
135
|
+
return createYAxis(this.#scales, this.#dimensions, options)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Creates grid line data for rendering
|
|
140
|
+
*
|
|
141
|
+
* @param {Object} options Grid options
|
|
142
|
+
* @returns {Object} Grid rendering data
|
|
143
|
+
*/
|
|
144
|
+
createGrid(options = {}) {
|
|
145
|
+
return createGrid(this.#scales, this.#dimensions, options)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Creates legend data for rendering
|
|
150
|
+
*
|
|
151
|
+
* @param {Object} options Legend options
|
|
152
|
+
* @returns {Object} Legend rendering data
|
|
153
|
+
*/
|
|
154
|
+
createLegend(options = {}) {
|
|
155
|
+
return createLegend(this.#data, this.#fields, this.#scales, this.#dimensions, options)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Gets all chart dimensions
|
|
160
|
+
*
|
|
161
|
+
* @returns {Object} Chart dimensions
|
|
162
|
+
*/
|
|
163
|
+
getDimensions() {
|
|
164
|
+
return { ...this.#dimensions }
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Gets all chart scales
|
|
169
|
+
*
|
|
170
|
+
* @returns {Object} Chart scales
|
|
171
|
+
*/
|
|
172
|
+
getScales() {
|
|
173
|
+
return { ...this.#scales }
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Gets the animation duration
|
|
178
|
+
*
|
|
179
|
+
* @returns {number} Animation duration in ms
|
|
180
|
+
*/
|
|
181
|
+
getAnimationDuration() {
|
|
182
|
+
return this.#options.animationDuration
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Gets the data being used
|
|
187
|
+
*
|
|
188
|
+
* @returns {Array} Chart data
|
|
189
|
+
*/
|
|
190
|
+
getData() {
|
|
191
|
+
return [...this.#data]
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Gets the fields configuration
|
|
196
|
+
*
|
|
197
|
+
* @returns {Object} Fields configuration
|
|
198
|
+
*/
|
|
199
|
+
getFields() {
|
|
200
|
+
return { ...this.#fields }
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {} from './types.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @typedef {import('./types').LegendItem} LegendItem
|
|
@@ -10,7 +10,7 @@ import { } from './types.js';
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Creates legend data for rendering
|
|
13
|
-
*
|
|
13
|
+
*
|
|
14
14
|
* @param {Array} data - Chart data
|
|
15
15
|
* @param {Object} fields - Field mappings
|
|
16
16
|
* @param {string} fields.color - Color field
|
|
@@ -25,71 +25,70 @@ import { } from './types.js';
|
|
|
25
25
|
* @returns {LegendData} Legend rendering data
|
|
26
26
|
*/
|
|
27
27
|
export function createLegend(data, fields, scales, dimensions, options = {}) {
|
|
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
|
-
};
|
|
28
|
+
if (!data || !fields.color || !scales.color) {
|
|
29
|
+
return { items: [], title: '', transform: 'translate(0, 0)' }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const { title = '', align = 'right', shape = 'rect', markerSize = 10 } = options
|
|
33
|
+
|
|
34
|
+
// Get unique color values
|
|
35
|
+
const colorValues = [...new Set(data.map((d) => d[fields.color]))]
|
|
36
|
+
|
|
37
|
+
// Create legend items
|
|
38
|
+
const items = colorValues.map((value, index) => ({
|
|
39
|
+
value,
|
|
40
|
+
color: scales.color(value),
|
|
41
|
+
y: index * (markerSize + 5) + (title ? 15 : 0),
|
|
42
|
+
shape,
|
|
43
|
+
markerSize
|
|
44
|
+
}))
|
|
45
|
+
|
|
46
|
+
// Calculate approximate width for alignment
|
|
47
|
+
const approximateWidth =
|
|
48
|
+
Math.max(...colorValues.map((v) => v.toString().length)) * 8 + markerSize + 10
|
|
49
|
+
|
|
50
|
+
// Calculate position based on alignment
|
|
51
|
+
let x = 0
|
|
52
|
+
if (align === 'right') {
|
|
53
|
+
x = dimensions.innerWidth - approximateWidth
|
|
54
|
+
} else if (align === 'center') {
|
|
55
|
+
x = (dimensions.innerWidth - approximateWidth) / 2
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
items,
|
|
60
|
+
title,
|
|
61
|
+
transform: `translate(${x}, 0)`
|
|
62
|
+
}
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
/**
|
|
67
66
|
* Filter data based on legend selection
|
|
68
|
-
*
|
|
67
|
+
*
|
|
69
68
|
* @param {Array} data - Chart data
|
|
70
69
|
* @param {string} colorField - Field used for color mapping
|
|
71
70
|
* @param {Array} selectedValues - Selected legend values
|
|
72
71
|
* @returns {Array} Filtered data
|
|
73
72
|
*/
|
|
74
73
|
export function filterByLegend(data, colorField, selectedValues) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
if (!selectedValues || selectedValues.length === 0) {
|
|
75
|
+
return data
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return data.filter((d) => selectedValues.includes(d[colorField]))
|
|
80
79
|
}
|
|
81
80
|
|
|
82
81
|
/**
|
|
83
82
|
* Create attributes for legend items
|
|
84
|
-
*
|
|
83
|
+
*
|
|
85
84
|
* @param {LegendItem} item - Legend item
|
|
86
85
|
* @returns {Object} Attributes for the legend item
|
|
87
86
|
*/
|
|
88
87
|
export function createLegendItemAttributes(item) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
88
|
+
return {
|
|
89
|
+
'data-plot-legend-item': '',
|
|
90
|
+
transform: `translate(0, ${item.y})`,
|
|
91
|
+
role: 'img',
|
|
92
|
+
'aria-label': `Legend item for ${item.value}`
|
|
93
|
+
}
|
|
94
|
+
}
|