svelteplot 0.2.5 → 0.2.6-next.0

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.
@@ -28,22 +28,6 @@
28
28
  import mergeDeep from '../helpers/mergeDeep.js';
29
29
  import { computeScales, projectXY } from '../helpers/scales.js';
30
30
  import { CHANNEL_SCALE, SCALES } from '../constants.js';
31
- import { scale } from 'svelte/transition';
32
-
33
- let {
34
- header,
35
- footer,
36
- overlay,
37
- underlay,
38
- children,
39
- facetAxes,
40
- testid,
41
- facet,
42
- class: className = '',
43
- css,
44
- width: fixedWidth,
45
- ...initialOpts
46
- }: Partial<PlotOptions> = $props();
47
31
 
48
32
  // automatic margins can be applied by the marks, registered
49
33
  // with their respective unique identifier as keys
@@ -95,6 +79,21 @@
95
79
  ...getContext<Partial<PlotDefaults>>('svelteplot/defaults')
96
80
  };
97
81
 
82
+ let {
83
+ header,
84
+ footer,
85
+ overlay,
86
+ underlay,
87
+ children,
88
+ facetAxes,
89
+ testid,
90
+ facet,
91
+ class: className = '',
92
+ css = DEFAULTS.css,
93
+ width: fixedWidth,
94
+ ...initialOpts
95
+ }: Partial<PlotOptions> = $props();
96
+
98
97
  let width = $state(DEFAULTS.initialWidth);
99
98
 
100
99
  setContext('svelteplot/_defaults', DEFAULTS);
@@ -454,7 +453,8 @@
454
453
  symbol: { type: 'ordinal' },
455
454
  fx: { type: 'band', axis: 'top' },
456
455
  fy: { type: 'band', axis: 'right' },
457
- locale: DEFAULTS.locale
456
+ locale: DEFAULTS.locale,
457
+ css: DEFAULTS.css
458
458
  };
459
459
  }
460
460
 
@@ -15,6 +15,7 @@ const styleProps = {
15
15
  fontWeight: 'font-weight',
16
16
  fontStyle: 'font-style',
17
17
  textAnchor: 'text-anchor',
18
+ fontVariant: 'font-variant',
18
19
  cursor: 'cursor',
19
20
  pointerEvents: 'pointer-events'
20
21
  };
@@ -11,7 +11,7 @@
11
11
  RawValue,
12
12
  ScaleType
13
13
  } from '../../types.js';
14
- import { resolveScaledStyles, resolveProp } from '../../helpers/resolve.js';
14
+ import { resolveProp, resolveStyles } from '../../helpers/resolve.js';
15
15
  import { max } from 'd3-array';
16
16
  import { randomId, testFilter } from '../../helpers/index.js';
17
17
 
@@ -142,7 +142,7 @@
142
142
  </script>
143
143
 
144
144
  <g class="axis-x">
145
- {#each positionedTicks as tick, t}
145
+ {#each positionedTicks as tick, t (t)}
146
146
  {#if testFilter(tick.value, options) && !tick.hidden}
147
147
  {@const textLines = tick.text}
148
148
  {@const prevTextLines = t && positionedTicks[t - 1].text}
@@ -152,27 +152,41 @@
152
152
  {@const moveDown =
153
153
  (tickSize + tickPadding + (tickRotate !== 0 ? tickFontSize * 0.35 : 0)) *
154
154
  (anchor === 'bottom' ? 1 : -1)}
155
+ {@const [textStyle, textClass] = resolveStyles(
156
+ plot,
157
+ tick,
158
+ {
159
+ fontVariant: isQuantitative ? 'tabular-nums' : 'normal',
160
+ ...options,
161
+ fontSize: tickFontSize,
162
+ stroke: null
163
+ },
164
+ 'fill',
165
+ { x: true }
166
+ )}
155
167
  <g
156
168
  class="tick {tickClass_ || ''}"
157
169
  transform="translate({tick.x + tick.dx}, {tickY + tick.dy})"
158
170
  text-anchor={tickRotate < 0 ? 'end' : tickRotate > 0 ? 'start' : 'middle'}>
159
171
  {#if tickSize}
172
+ {@const [tickLineStyle, tickLineClass] = resolveStyles(
173
+ plot,
174
+ tick,
175
+ options,
176
+ 'stroke',
177
+ { x: true }
178
+ )}
160
179
  <line
161
- style={resolveScaledStyles(tick, options, {}, plot, 'stroke')}
180
+ style={tickLineStyle}
181
+ class={tickLineClass}
162
182
  y2={anchor === 'bottom' ? tickSize : -tickSize} />
163
183
  {/if}
164
184
 
165
185
  <text
166
186
  bind:this={tickTextElements[t]}
167
187
  transform="translate(0, {moveDown}) rotate({tickRotate})"
168
- style:font-variant={isQuantitative ? 'tabular-nums' : 'normal'}
169
- style={resolveScaledStyles(
170
- tick,
171
- { ...options, fontSize: tickFontSize, stroke: null },
172
- {},
173
- plot,
174
- 'fill'
175
- )}
188
+ style={textStyle}
189
+ class={textClass}
176
190
  x={0}
177
191
  y={0}
178
192
  dominant-baseline={tickRotate !== 0
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
- import { getContext, untrack } from 'svelte';
2
+ import { getContext, tick, untrack } from 'svelte';
3
3
  import { randomId, testFilter } from '../../helpers/index.js';
4
- import { resolveProp, resolveScaledStyles } from '../../helpers/resolve.js';
4
+ import { resolveProp, resolveStyles } from '../../helpers/resolve.js';
5
5
  import { max } from 'd3-array';
6
6
  import type {
7
7
  AutoMarginStores,
@@ -84,6 +84,8 @@
84
84
 
85
85
  let tickTexts = $state([] as SVGTextElement[]);
86
86
 
87
+ const isQuantitative = $derived(scaleType !== 'point' && scaleType !== 'band');
88
+
87
89
  // generate id used for registering margins
88
90
  const id = randomId();
89
91
 
@@ -141,29 +143,43 @@
141
143
  </script>
142
144
 
143
145
  <g class="axis-y">
144
- {#each positionedTicks as tick, t}
146
+ {#each positionedTicks as tick, t (t)}
145
147
  {#if testFilter(tick.value, options) && !tick.hidden}
146
148
  {@const tickClass_ = resolveProp(tickClass, tick.value)}
149
+ {@const [textStyle, textClass] = resolveStyles(
150
+ plot,
151
+ tick,
152
+ {
153
+ fontVariant: isQuantitative ? 'tabular-nums' : 'normal',
154
+ ...options,
155
+ fontSize: tickFontSize,
156
+ stroke: null
157
+ },
158
+ 'fill',
159
+ { y: true }
160
+ )}
147
161
  <g
148
162
  class="tick {tickClass_ || ''}"
149
163
  transform="translate({tick.dx +
150
164
  marginLeft +
151
165
  (anchor === 'left' ? 0 : width)},{tick.y + tick.dy})">
152
166
  {#if tickSize}
167
+ {@const [tickLineStyle, tickLineClass] = resolveStyles(
168
+ plot,
169
+ tick,
170
+ options,
171
+ 'stroke',
172
+ { y: true }
173
+ )}
153
174
  <line
154
- style={resolveScaledStyles(tick.value, options, {}, plot, 'stroke')}
175
+ style={tickLineStyle}
176
+ class={tickLineClass}
155
177
  x2={anchor === 'left' ? -tickSize : tickSize} />
156
178
  {/if}
157
179
  <text
158
180
  bind:this={tickTexts[t]}
159
- class={{ 'is-left': anchor === 'left' }}
160
- style={resolveScaledStyles(
161
- tick.value,
162
- { ...options, fontSize: tickFontSize, stroke: null },
163
- {},
164
- plot,
165
- 'fill'
166
- )}
181
+ class={[textClass, { 'is-left': anchor === 'left' }]}
182
+ style={textStyle}
167
183
  x={(tickSize + tickPadding) * (anchor === 'left' ? -1 : 1)}
168
184
  dominant-baseline={LINE_ANCHOR[lineAnchor]}
169
185
  >{Array.isArray(tick.text) ? tick.text.join(' ') : tick.text}</text>
package/dist/types.d.ts CHANGED
@@ -296,9 +296,9 @@ export type PlotOptions = {
296
296
  */
297
297
  locale: string;
298
298
  /**
299
- *
299
+ * pass a @emotion/css function to style plot using dynamic classes
300
300
  */
301
- css: (d: string) => string;
301
+ css: (d: string) => string | undefined;
302
302
  };
303
303
  export type PlotDefaults = {
304
304
  axisXAnchor: AxisXAnchor;
@@ -339,6 +339,7 @@ export type PlotDefaults = {
339
339
  */
340
340
  numberFormat: Intl.NumberFormatOptions;
341
341
  markerDotRadius: number;
342
+ css: (d: string) => string | undefined;
342
343
  };
343
344
  export type GenericMarkOptions = Record<string, any>;
344
345
  export type DataRecord = Record<string | symbol, RawValue> & {
@@ -583,7 +584,7 @@ export type TransformArgsRecord = Partial<Channels> & {
583
584
  data: DataRecord[];
584
585
  };
585
586
  export type ColorScheme = 'brbg' | 'prgn' | 'piyg' | 'puor' | 'rdbu' | 'rdgy' | 'rdylbu' | 'rdylgn' | 'spectral' | 'burd' | 'buylrd' | 'blues' | 'greens' | 'grays' | 'greys' | 'oranges' | 'purples' | 'reds' | 'turbo' | 'viridis' | 'magma' | 'inferno' | 'plasma' | 'cividis' | 'cubehelix' | 'warm' | 'cool' | 'bugn' | 'bupu' | 'gnbu' | 'orrd' | 'pubu' | 'pubugn' | 'purd' | 'rdpu' | 'ylgn' | 'ylgnbu' | 'ylorbr' | 'ylorrd' | 'rainbow' | 'sinebow' | 'accent' | 'category10' | 'dark2' | 'paired' | 'pastel1' | 'pastel2' | 'set1' | 'set2' | 'set3' | 'tableau10' | 'observable10';
586
- export type MarkStyleProps = 'strokeDasharray' | 'strokeLinejoin' | 'strokeLinecap' | 'opacity' | 'cursor' | 'pointerEvents' | 'blend' | 'fill' | 'fillOpacity' | 'fontWeight' | 'fontSize' | 'fontStyle' | 'stroke' | 'strokeWidth' | 'strokeOpacity' | 'x' | 'y' | 'clipPath' | 'mask' | 'filter' | 'angle' | 'radius' | 'symbol' | 'textAnchor' | 'width';
587
+ export type MarkStyleProps = 'strokeDasharray' | 'strokeLinejoin' | 'strokeLinecap' | 'opacity' | 'cursor' | 'pointerEvents' | 'blend' | 'fill' | 'fillOpacity' | 'fontWeight' | 'fontVariant' | 'fontSize' | 'fontStyle' | 'stroke' | 'strokeWidth' | 'strokeOpacity' | 'x' | 'y' | 'clipPath' | 'mask' | 'filter' | 'angle' | 'radius' | 'symbol' | 'textAnchor' | 'width';
587
588
  export type AutoMarginStores = {
588
589
  autoMarginTop: Writable<Map<string, number>>;
589
590
  autoMarginLeft: Writable<Map<string, number>>;
package/package.json CHANGED
@@ -1,123 +1,124 @@
1
1
  {
2
- "name": "svelteplot",
3
- "version": "0.2.5",
4
- "license": "ISC",
5
- "author": {
6
- "name": "Gregor Aisch",
7
- "email": "gka@users.noreply.github.com"
8
- },
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "svelte": "./dist/index.js"
2
+ "name": "svelteplot",
3
+ "version": "0.2.6-next.0",
4
+ "license": "ISC",
5
+ "author": {
6
+ "name": "Gregor Aisch",
7
+ "email": "gka@users.noreply.github.com"
13
8
  },
14
- "./*.js": {
15
- "import": "./dist/*.js"
9
+ "scripts": {
10
+ "dev": "vite dev",
11
+ "build": "vite build",
12
+ "preview": "vite preview",
13
+ "test": "npm run test:unit",
14
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
15
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
16
+ "lint": "prettier --check src && eslint src",
17
+ "format": "prettier --write .",
18
+ "test:unit": "vitest",
19
+ "prepack": "npx svelte-package",
20
+ "release-next": "npm version prerelease --preid next && npm publish && git push && git push --tags && sleep 1 && npm dist-tag add svelteplot@$(npm view . version) next",
21
+ "docs": "npm run build && cd build && rsync --recursive . vis4.net:svelteplot/alpha0/"
16
22
  },
17
- "./*.svelte": {
18
- "import": "./dist/*.svelte"
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "svelte": "./dist/index.js"
27
+ },
28
+ "./*.js": {
29
+ "import": "./dist/*.js"
30
+ },
31
+ "./*.svelte": {
32
+ "import": "./dist/*.svelte"
33
+ },
34
+ "./core/*.svelte": {
35
+ "import": "./dist/core/*.svelte"
36
+ },
37
+ "./marks/*.svelte": {
38
+ "import": "./dist/marks/*.svelte"
39
+ },
40
+ "./transforms": {
41
+ "import": "./dist/transforms/index.js"
42
+ }
19
43
  },
20
- "./core/*.svelte": {
21
- "import": "./dist/core/*.svelte"
44
+ "main": "./dist/index.js",
45
+ "files": [
46
+ "dist",
47
+ "!dist/**/*.test.*",
48
+ "!dist/**/*.spec.*"
49
+ ],
50
+ "devDependencies": {
51
+ "@aitodotai/json-stringify-pretty-compact": "^1.3.0",
52
+ "@emotion/css": "^11.13.5",
53
+ "@sveltejs/adapter-auto": "^6.0.1",
54
+ "@sveltejs/adapter-static": "^3.0.8",
55
+ "@sveltejs/eslint-config": "^8.2.0",
56
+ "@sveltejs/kit": "^2.21.0",
57
+ "@sveltejs/package": "^2.3.11",
58
+ "@sveltejs/vite-plugin-svelte": "5.0.3",
59
+ "@sveltepress/theme-default": "^6.0.3",
60
+ "@sveltepress/twoslash": "^1.2.2",
61
+ "@sveltepress/vite": "^1.2.2",
62
+ "@testing-library/svelte": "^5.2.7",
63
+ "@testing-library/user-event": "^14.6.1",
64
+ "@types/d3-array": "^3.2.1",
65
+ "@types/d3-color": "^3.1.3",
66
+ "@types/d3-dsv": "^3.0.7",
67
+ "@types/d3-geo": "^3.1.0",
68
+ "@types/d3-interpolate": "^3.0.4",
69
+ "@types/d3-path": "^3.1.1",
70
+ "@types/d3-random": "^3.0.3",
71
+ "@types/d3-scale": "^4.0.9",
72
+ "@types/d3-scale-chromatic": "^3.1.0",
73
+ "@types/d3-shape": "^3.1.7",
74
+ "@typescript-eslint/eslint-plugin": "^8.32.1",
75
+ "@typescript-eslint/parser": "^8.32.1",
76
+ "csstype": "^3.1.3",
77
+ "d3-dsv": "^3.0.1",
78
+ "d3-fetch": "^3.0.1",
79
+ "d3-force": "^3.0.0",
80
+ "eslint": "^9.26.0",
81
+ "eslint-config-prettier": "^10.1.5",
82
+ "eslint-plugin-svelte": "3.7.0",
83
+ "jsdom": "^26.1.0",
84
+ "prettier": "^3.5.3",
85
+ "prettier-plugin-svelte": "^3.4.0",
86
+ "remark-code-extra": "^1.0.1",
87
+ "remark-code-frontmatter": "^1.0.0",
88
+ "resize-observer-polyfill": "^1.5.1",
89
+ "sass": "^1.89.0",
90
+ "svelte-check": "^4.2.1",
91
+ "svelte-eslint-parser": "1.2.0",
92
+ "svelte-highlight": "^7.8.3",
93
+ "svg-path-parser": "^1.1.0",
94
+ "topojson-client": "^3.1.0",
95
+ "tslib": "^2.8.1",
96
+ "typedoc": "^0.28.4",
97
+ "typedoc-plugin-markdown": "^4.6.3",
98
+ "typescript": "^5.8.3",
99
+ "vite": "^6.3.5",
100
+ "vitest": "^3.1.3",
101
+ "vitest-matchmedia-mock": "^2.0.3"
22
102
  },
23
- "./marks/*.svelte": {
24
- "import": "./dist/marks/*.svelte"
25
- },
26
- "./transforms": {
27
- "import": "./dist/transforms/index.js"
103
+ "types": "./dist/index.d.ts",
104
+ "type": "module",
105
+ "dependencies": {
106
+ "d3-array": "^3.2.4",
107
+ "d3-color": "^3.1.0",
108
+ "d3-format": "^3.1.0",
109
+ "d3-geo": "^3.1.1",
110
+ "d3-interpolate": "^3.0.1",
111
+ "d3-path": "^3.1.0",
112
+ "d3-quadtree": "^3.0.1",
113
+ "d3-random": "^3.0.1",
114
+ "d3-regression": "^1.3.10",
115
+ "d3-scale": "^4.0.2",
116
+ "d3-scale-chromatic": "^3.1.0",
117
+ "d3-shape": "^3.2.0",
118
+ "d3-time": "^3.1.0",
119
+ "es-toolkit": "^1.37.2",
120
+ "fast-equals": "^5.2.2",
121
+ "merge-deep": "^3.0.3",
122
+ "svelte": "5.30.1"
28
123
  }
29
- },
30
- "main": "./dist/index.js",
31
- "files": [
32
- "dist",
33
- "!dist/**/*.test.*",
34
- "!dist/**/*.spec.*"
35
- ],
36
- "devDependencies": {
37
- "@aitodotai/json-stringify-pretty-compact": "^1.3.0",
38
- "@emotion/css": "^11.13.5",
39
- "@sveltejs/adapter-auto": "^6.0.1",
40
- "@sveltejs/adapter-static": "^3.0.8",
41
- "@sveltejs/eslint-config": "^8.2.0",
42
- "@sveltejs/kit": "^2.21.0",
43
- "@sveltejs/package": "^2.3.11",
44
- "@sveltejs/vite-plugin-svelte": "5.0.3",
45
- "@sveltepress/theme-default": "^6.0.3",
46
- "@sveltepress/twoslash": "^1.2.2",
47
- "@sveltepress/vite": "^1.2.2",
48
- "@testing-library/svelte": "^5.2.7",
49
- "@testing-library/user-event": "^14.6.1",
50
- "@types/d3-array": "^3.2.1",
51
- "@types/d3-color": "^3.1.3",
52
- "@types/d3-dsv": "^3.0.7",
53
- "@types/d3-geo": "^3.1.0",
54
- "@types/d3-interpolate": "^3.0.4",
55
- "@types/d3-path": "^3.1.1",
56
- "@types/d3-random": "^3.0.3",
57
- "@types/d3-scale": "^4.0.9",
58
- "@types/d3-scale-chromatic": "^3.1.0",
59
- "@types/d3-shape": "^3.1.7",
60
- "@typescript-eslint/eslint-plugin": "^8.32.1",
61
- "@typescript-eslint/parser": "^8.32.1",
62
- "csstype": "^3.1.3",
63
- "d3-dsv": "^3.0.1",
64
- "d3-fetch": "^3.0.1",
65
- "d3-force": "^3.0.0",
66
- "eslint": "^9.26.0",
67
- "eslint-config-prettier": "^10.1.5",
68
- "eslint-plugin-svelte": "3.7.0",
69
- "jsdom": "^26.1.0",
70
- "prettier": "^3.5.3",
71
- "prettier-plugin-svelte": "^3.4.0",
72
- "remark-code-extra": "^1.0.1",
73
- "remark-code-frontmatter": "^1.0.0",
74
- "resize-observer-polyfill": "^1.5.1",
75
- "sass": "^1.89.0",
76
- "svelte-check": "^4.2.1",
77
- "svelte-eslint-parser": "1.2.0",
78
- "svelte-highlight": "^7.8.3",
79
- "svg-path-parser": "^1.1.0",
80
- "topojson-client": "^3.1.0",
81
- "tslib": "^2.8.1",
82
- "typedoc": "^0.28.4",
83
- "typedoc-plugin-markdown": "^4.6.3",
84
- "typescript": "^5.8.3",
85
- "vite": "^6.3.5",
86
- "vitest": "^3.1.3",
87
- "vitest-matchmedia-mock": "^2.0.3"
88
- },
89
- "types": "./dist/index.d.ts",
90
- "type": "module",
91
- "dependencies": {
92
- "d3-array": "^3.2.4",
93
- "d3-color": "^3.1.0",
94
- "d3-format": "^3.1.0",
95
- "d3-geo": "^3.1.1",
96
- "d3-interpolate": "^3.0.1",
97
- "d3-path": "^3.1.0",
98
- "d3-quadtree": "^3.0.1",
99
- "d3-random": "^3.0.1",
100
- "d3-regression": "^1.3.10",
101
- "d3-scale": "^4.0.2",
102
- "d3-scale-chromatic": "^3.1.0",
103
- "d3-shape": "^3.2.0",
104
- "d3-time": "^3.1.0",
105
- "es-toolkit": "^1.37.2",
106
- "fast-equals": "^5.2.2",
107
- "merge-deep": "^3.0.3",
108
- "svelte": "5.30.1"
109
- },
110
- "scripts": {
111
- "dev": "vite dev",
112
- "build": "vite build",
113
- "preview": "vite preview",
114
- "test": "npm run test:unit",
115
- "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
116
- "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
117
- "lint": "prettier --check src && eslint src",
118
- "format": "prettier --write .",
119
- "test:unit": "vitest",
120
- "release-next": "npm version prerelease --preid next && npm publish && git push && git push --tags && sleep 1 && npm dist-tag add svelteplot@$(npm view . version) next",
121
- "docs": "npm run build && cd build && rsync --recursive . vis4.net:svelteplot/alpha0/"
122
- }
123
- }
124
+ }