svelteplot 0.1.3-next.4 → 0.1.3-next.5

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.
@@ -41,6 +41,7 @@
41
41
  facet,
42
42
  class: className = '',
43
43
  css,
44
+ width: fixedWidth,
44
45
  ...initialOpts
45
46
  }: Partial<PlotOptions> = $props();
46
47
 
@@ -176,7 +177,7 @@
176
177
 
177
178
  const hasProjection = $derived(!!preScales.projection);
178
179
 
179
- const plotWidth = $derived(width - plotOptions.marginLeft - plotOptions.marginRight);
180
+ const plotWidth = $derived((fixedWidth || width) - plotOptions.marginLeft - plotOptions.marginRight);
180
181
 
181
182
  // the facet and y domain counts are used for computing the automatic height
182
183
  const xFacetCount = $derived(Math.max(1, preScales.fx.domain.length));
@@ -476,7 +477,7 @@
476
477
  <div class="plot-body" bind:this={plotBody}>
477
478
  {#if underlay}<div class="plot-underlay">{@render underlay(plotOptions)}</div>{/if}
478
479
  <svg
479
- {width}
480
+ width={fixedWidth || width}
480
481
  {height}
481
482
  fill="currentColor"
482
483
  viewBox="0 0 {width} {height}"
@@ -13,5 +13,5 @@ export declare function toChannelOption(name: ScaledChannelName, channel: Channe
13
13
  export declare function resolveChannel(channel: ChannelName, datum: DataRow, channels: Partial<Record<ChannelName, ChannelAccessor | ChannelAlias>>): RawValue;
14
14
  export declare function resolveScaledStyleProps(datum: DataRecord, channels: Partial<Record<ScaledChannelName, ChannelAccessor>>, useScale: Record<ScaledChannelName, boolean>, plot: PlotState, defaultColorProp?: 'fill' | 'stroke' | null): any;
15
15
  export declare function resolveScaledStyles(datum: DataRecord, channels: Partial<Record<ScaledChannelName, ChannelAccessor>>, useScale: Record<ScaledChannelName, boolean>, plot: PlotState, defaultColorProp?: 'fill' | 'stroke' | null): string;
16
- export declare function resolveStyles(plot: PlotState, datum: ScaledDataRecord, channels: Partial<Record<ChannelName & MarkStyleProps, ChannelAccessor>>, defaultColorProp: "fill" | "stroke" | null | undefined, useScale: Record<ScaledChannelName, boolean>): [string | null, string | null];
16
+ export declare function resolveStyles(plot: PlotState, datum: ScaledDataRecord, channels: Partial<Record<ChannelName & MarkStyleProps, ChannelAccessor>>, defaultColorProp: "fill" | "stroke" | null | undefined, useScale: Record<ScaledChannelName, boolean>, recomputeChannels?: boolean): [string | null, string | null];
17
17
  export {};
@@ -120,7 +120,7 @@ function stylePropsToCSS(props) {
120
120
  .map(([key, value]) => `${key}: ${value}`)
121
121
  .join(';')}`;
122
122
  }
123
- export function resolveStyles(plot, datum, channels, defaultColorProp = null, useScale) {
123
+ export function resolveStyles(plot, datum, channels, defaultColorProp = null, useScale, recomputeChannels = false) {
124
124
  const styleProps = {
125
125
  ...getBaseStylesObject(datum.datum, channels),
126
126
  fill: 'none',
@@ -130,7 +130,7 @@ export function resolveStyles(plot, datum, channels, defaultColorProp = null, us
130
130
  : {}),
131
131
  ...Object.fromEntries(Object.entries(scaledStyleProps)
132
132
  .filter(([key]) => channels[key] != null)
133
- .map(([key, cssAttr]) => [key, cssAttr, datum[key]])
133
+ .map(([key, cssAttr]) => [key, cssAttr, recomputeChannels ? resolveChannel(key, datum.datum, channels) : datum[key]])
134
134
  .filter(([key, , value]) => isValid(value) || key === 'fill' || key === 'stroke')
135
135
  .map(([key, cssAttr, value]) => {
136
136
  if (useScale[key]) {
@@ -11,8 +11,6 @@
11
11
  ConstantAccessor,
12
12
  ChannelAccessor,
13
13
  MarkerOptions,
14
- FacetContext,
15
- PlotState,
16
14
  ScaledDataRecord
17
15
  } from '../types.js';
18
16
 
@@ -40,7 +38,7 @@
40
38
  import Mark from '../Mark.svelte';
41
39
  import MarkerPath from './helpers/MarkerPath.svelte';
42
40
  import { getContext } from 'svelte';
43
- import { resolveChannel, resolveProp, resolveStyles } from '../helpers/resolve.js';
41
+ import { resolveProp, resolveStyles } from '../helpers/resolve.js';
44
42
  import { line, type CurveFactory } from 'd3-shape';
45
43
  import { geoPath } from 'd3-geo';
46
44
  import callWithProps from '../helpers/callWithProps.js';
@@ -95,10 +93,6 @@
95
93
 
96
94
  const groupByKey = $derived(args.z || args.stroke);
97
95
 
98
- const groups = $derived(
99
- groupByKey && args.data.length > 0 ? groupIndex(args.data, groupByKey) : [args.data]
100
- );
101
-
102
96
  const { getPlotState } = getContext<PlotContext>('svelteplot');
103
97
  const plot = $derived(getPlotState());
104
98
 
@@ -189,12 +183,17 @@
189
183
  'fontStyle',
190
184
  'textAnchor'
191
185
  ]),
192
- fill: args.textFill || args.stroke,
193
- stroke: args.textStroke,
194
186
  strokeWidth: args.textStrokeWidth
187
+ ? args.textStrokeWidth
188
+ : args.textStroke
189
+ ? 2
190
+ : 0,
191
+ fill: args.textFill || args.stroke,
192
+ stroke: args.textStroke
195
193
  },
196
194
  'fill',
197
- usedScales
195
+ usedScales,
196
+ true
198
197
  )}
199
198
  <MarkerPath
200
199
  {mark}
@@ -206,6 +205,7 @@
206
205
  strokeWidth={args.strokeWidth}
207
206
  datum={lineData[0]}
208
207
  d={pathString}
208
+ dInv={text ? linePath(lineData.toReversed()) : null}
209
209
  color={lineData[0].stroke || 'currentColor'}
210
210
  {style}
211
211
  class={styleClass}
@@ -9,13 +9,10 @@
9
9
  CurveName,
10
10
  MarkerOptions,
11
11
  RawValue,
12
- FacetContext,
13
- DataRow,
14
12
  ScaledDataRecord
15
13
  } from '../types.js';
16
14
  import { resolveChannel, resolveProp, resolveStyles } from '../helpers/resolve.js';
17
- import { maybeData, testFilter } from '../helpers/index.js';
18
- import { getUsedScales, projectXY } from '../helpers/scales.js';
15
+ import { maybeData } from '../helpers/index.js';
19
16
  import Mark from '../Mark.svelte';
20
17
  import MarkerPath from './helpers/MarkerPath.svelte';
21
18
  import { replaceChannels } from '../transforms/rename.js';
@@ -72,30 +69,39 @@
72
69
 
73
70
  const sphericalLine = $derived(plot.scales.projection && curve === 'auto');
74
71
 
75
- const linePath: (d: ScaledDataRecord) => string = $derived.by(() => {
72
+ const linePath: (d: ScaledDataRecord, reversed: boolean) => string = $derived.by(() => {
76
73
  const fn = callWithProps(line, [], {
77
74
  curve: maybeCurve(curve === 'auto' ? 'linear' : curve, tension),
78
75
  x: (d) => d[0],
79
76
  y: (d) => d[1]
80
77
  });
81
78
 
82
- return (d: ScaledDataRecord) =>
83
- fn([
84
- [d.x1, d.y1],
85
- [d.x2, d.y2]
86
- ]);
79
+ return (d: ScaledDataRecord, reversed = false) =>
80
+ fn(
81
+ reversed
82
+ ? [
83
+ [d.x2, d.y2],
84
+ [d.x1, d.y1]
85
+ ]
86
+ : [
87
+ [d.x1, d.y1],
88
+ [d.x2, d.y2]
89
+ ]
90
+ );
87
91
  });
88
92
 
89
- const sphericalLinePath: (d: ScaledDataRecord) => string = $derived.by(() => {
90
- const fn = sphereLine(plot.scales.projection);
91
- return (d: ScaledDataRecord) => {
92
- const x1 = resolveChannel('x1', d.datum, args);
93
- const y1 = resolveChannel('y1', d.datum, args);
94
- const x2 = resolveChannel('x2', d.datum, args);
95
- const y2 = resolveChannel('y2', d.datum, args);
96
- return fn(x1, y1, x2, y2);
97
- };
98
- });
93
+ const sphericalLinePath: (d: ScaledDataRecord, reversed: boolean) => string = $derived.by(
94
+ () => {
95
+ const fn = sphereLine(plot.scales.projection);
96
+ return (d: ScaledDataRecord, reversed = false) => {
97
+ const x1 = resolveChannel('x1', d.datum, args);
98
+ const y1 = resolveChannel('y1', d.datum, args);
99
+ const x2 = resolveChannel('x2', d.datum, args);
100
+ const y2 = resolveChannel('y2', d.datum, args);
101
+ return reversed ? fn(x2, y2, x1, y1) : fn(x1, y1, x2, y2);
102
+ };
103
+ }
104
+ );
99
105
  // sphericalLine
100
106
  // ?
101
107
 
@@ -160,6 +166,7 @@
160
166
  datum={d.datum}
161
167
  color={d.stroke}
162
168
  d={sphericalLine ? sphericalLinePath(d) : linePath(d)}
169
+ dInv={sphericalLine ? sphericalLinePath(d, true) : linePath(d, true)}
163
170
  {style}
164
171
  text={text ? resolveProp(text, d.datum) : null}
165
172
  startOffset={resolveProp(args.textStartOffset, d.datum, '50%')}
@@ -63,6 +63,7 @@
63
63
  markerEnd,
64
64
  marker,
65
65
  d,
66
+ dInv,
66
67
  style,
67
68
  class: className = null,
68
69
  textStyleClass = null,
@@ -84,33 +85,9 @@
84
85
  const firstPt = $derived(text && hasPath ? points.at(0).split(',').map(Number) : []);
85
86
  const lastPt = $derived(text && hasPath ? points.at(-1).split(',').map(Number) : []);
86
87
  const leftToRight = $derived(text && hasPath ? firstPt[0] < lastPt.at(-2) : true);
87
- const pathIsCurve = $derived(text && hasPath ? d.includes('C') : false);
88
- // this rather complicated code "reverses" the path to ensure that the text
89
- // is not turned upside down
90
- const textPath = $derived(
91
- !text || leftToRight
92
- ? hasPath
93
- : pathIsCurve
94
- ? [
95
- 'M',
96
- points.at(-1).split(',').slice(-2).join(','),
97
- 'C',
98
- points.at(-1).split(',').slice(2, 4).join(','),
99
- ',',
100
- points.at(-1).split(',').slice(0, 2).join(','),
101
- ',',
102
- points[0]
103
- ].join('')
104
- : [
105
- 'M',
106
- points.at(-1),
107
- ...points
108
- .toReversed()
109
- .slice(1)
110
- .map((pt) => `L${pt}`)
111
- ].join('')
112
- );
113
88
 
89
+ // use reversed path if the path is not left to right
90
+ const textPath = $derived(!text || leftToRight ? d : dInv);
114
91
  const strokeWidth_ = $derived(resolveProp(strokeWidth, datum, 1.4));
115
92
  </script>
116
93
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.1.3-next.4",
3
+ "version": "0.1.3-next.5",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",
@@ -10,12 +10,11 @@
10
10
  "dev": "vite dev",
11
11
  "build": "vite build",
12
12
  "preview": "vite preview",
13
- "test": "npm run test:integration && npm run test:unit",
13
+ "test": "npm run test:unit",
14
14
  "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
15
15
  "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
16
16
  "lint": "prettier --check src && eslint src",
17
17
  "format": "prettier --write .",
18
- "test:integration": "playwright test",
19
18
  "test:unit": "vitest",
20
19
  "prepack": "npx svelte-package",
21
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",
@@ -48,7 +47,6 @@
48
47
  "devDependencies": {
49
48
  "@aitodotai/json-stringify-pretty-compact": "^1.3.0",
50
49
  "@emotion/css": "^11.13.5",
51
- "@playwright/test": "^1.52.0",
52
50
  "@sveltejs/adapter-auto": "^6.0.0",
53
51
  "@sveltejs/adapter-static": "^3.0.8",
54
52
  "@sveltejs/eslint-config": "^8.2.0",
@@ -58,6 +56,7 @@
58
56
  "@sveltepress/theme-default": "^6.0.2",
59
57
  "@sveltepress/twoslash": "^1.2.1",
60
58
  "@sveltepress/vite": "^1.2.1",
59
+ "@testing-library/svelte": "^5.2.7",
61
60
  "@types/d3-array": "^3.2.1",
62
61
  "@types/d3-color": "^3.1.3",
63
62
  "@types/d3-dsv": "^3.0.7",
@@ -81,6 +80,7 @@
81
80
  "prettier-plugin-svelte": "^3.3.3",
82
81
  "remark-code-extra": "^1.0.1",
83
82
  "remark-code-frontmatter": "^1.0.0",
83
+ "resize-observer-polyfill": "^1.5.1",
84
84
  "sass": "^1.86.3",
85
85
  "svelte-check": "^4.1.6",
86
86
  "svelte-eslint-parser": "1.1.3",