@rokkit/chart 1.3.0 → 1.3.1
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/package.json +1 -1
- package/src/lib/chart.js +2 -0
- package/src/lib/context.js +7 -7
- package/src/lib/keyboard-nav.js +2 -2
package/package.json
CHANGED
package/src/lib/chart.js
CHANGED
|
@@ -97,11 +97,13 @@ class Chart {
|
|
|
97
97
|
this.refresh()
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/* v8 ignore next 4 -- this.padding (number) set in #initFields shadows this prototype method */
|
|
100
101
|
padding(value) {
|
|
101
102
|
this.padding = value
|
|
102
103
|
return this.refresh()
|
|
103
104
|
}
|
|
104
105
|
|
|
106
|
+
/* v8 ignore next 4 -- this.margin (object) set in #initFields shadows this prototype method */
|
|
105
107
|
margin(value) {
|
|
106
108
|
this.margin = value
|
|
107
109
|
return this.refresh()
|
package/src/lib/context.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { getContext, setContext } from 'svelte'
|
|
2
2
|
import { writable, derived } from 'svelte/store'
|
|
3
|
-
import
|
|
3
|
+
import { scaleBand, scaleLinear, scaleOrdinal } from 'd3-scale'
|
|
4
|
+
import { schemeCategory10 } from 'd3-scale-chromatic'
|
|
5
|
+
import { max } from 'd3-array'
|
|
4
6
|
|
|
5
7
|
const CHART_CONTEXT = 'chart-context'
|
|
6
8
|
|
|
@@ -61,22 +63,20 @@ function makeUpdateScales(data, innerDimensions) {
|
|
|
61
63
|
return derived([data, innerDimensions], ([$data, $innerDimensions]) => {
|
|
62
64
|
if (!$data || $data.length === 0) return null
|
|
63
65
|
|
|
64
|
-
const xScale =
|
|
65
|
-
.scaleBand()
|
|
66
|
+
const xScale = scaleBand()
|
|
66
67
|
.domain($data.map((d) => d[xKey]))
|
|
67
68
|
.range([0, $innerDimensions.width])
|
|
68
69
|
.padding(0.2)
|
|
69
70
|
|
|
70
|
-
const yScale =
|
|
71
|
-
.
|
|
72
|
-
.domain([0, d3.max($data, (d) => d[yKey])])
|
|
71
|
+
const yScale = scaleLinear()
|
|
72
|
+
.domain([0, max($data, (d) => d[yKey])])
|
|
73
73
|
.nice()
|
|
74
74
|
.range([$innerDimensions.height, 0])
|
|
75
75
|
|
|
76
76
|
let colorScale = null
|
|
77
77
|
if (colorKey) {
|
|
78
78
|
const uniqueCategories = [...new Set($data.map((d) => d[colorKey]))]
|
|
79
|
-
colorScale =
|
|
79
|
+
colorScale = scaleOrdinal().domain(uniqueCategories).range(schemeCategory10)
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
return { xScale, yScale, colorScale }
|
package/src/lib/keyboard-nav.js
CHANGED
|
@@ -17,7 +17,7 @@ export function keyboardNav(node, enabled) {
|
|
|
17
17
|
const container = node.closest('[data-plot-geom]')
|
|
18
18
|
if (!container) return
|
|
19
19
|
const elements = [...container.querySelectorAll('[data-plot-element]')].filter(
|
|
20
|
-
(el) =>
|
|
20
|
+
(el) => el.tabIndex >= 0
|
|
21
21
|
)
|
|
22
22
|
const idx = elements.indexOf(node)
|
|
23
23
|
if (idx === -1) return
|
|
@@ -25,7 +25,7 @@ export function keyboardNav(node, enabled) {
|
|
|
25
25
|
e.key === 'ArrowRight' ? Math.min(idx + 1, elements.length - 1) : Math.max(idx - 1, 0)
|
|
26
26
|
if (nextIdx !== idx) {
|
|
27
27
|
e.preventDefault()
|
|
28
|
-
|
|
28
|
+
elements[nextIdx].focus()
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
node.addEventListener('keydown', handleKeydown)
|