@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/chart",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "type": "module",
5
5
  "description": "Data-driven chart components",
6
6
  "repository": {
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()
@@ -1,6 +1,8 @@
1
1
  import { getContext, setContext } from 'svelte'
2
2
  import { writable, derived } from 'svelte/store'
3
- import * as d3 from 'd3'
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 = d3
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 = d3
71
- .scaleLinear()
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 = d3.scaleOrdinal().domain(uniqueCategories).range(d3.schemeCategory10)
79
+ colorScale = scaleOrdinal().domain(uniqueCategories).range(schemeCategory10)
80
80
  }
81
81
 
82
82
  return { xScale, yScale, colorScale }
@@ -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) => /** @type {HTMLElement|SVGElement} */ (el).tabIndex >= 0
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
- /** @type {HTMLElement|SVGElement} */ (elements[nextIdx]).focus()
28
+ elements[nextIdx].focus()
29
29
  }
30
30
  }
31
31
  node.addEventListener('keydown', handleKeydown)