svelteplot 0.0.1-alpha.10 → 0.0.1-alpha.11

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/dist/Plot.svelte CHANGED
@@ -82,8 +82,8 @@ let hasLegend = $derived(color?.legend || symbol?.legend);
82
82
  onmousemove={onmousemove ? onMouseMove : null}
83
83
  >
84
84
  <!-- automatic grids -->
85
- {#if grid || x?.grid}<GridX automatic />{/if}
86
- {#if grid || y?.grid}<GridY automatic />{/if}
85
+ {#if (grid || x?.grid) && plot.hasChannelX}<GridX automatic />{/if}
86
+ {#if (grid || y?.grid) && plot.hasChannelY}<GridY automatic />{/if}
87
87
 
88
88
  {#if !plot.hasAxisXMark && plot.hasChannelX}
89
89
  <!-- automatic x axis -->
@@ -37,8 +37,8 @@ export class Plot {
37
37
  _height = $state(400);
38
38
  options = $state(DEFAULT_PLOT_OPTIONS);
39
39
  marks = $state([]);
40
- hasChannelX = $derived(!!this.marks.find((mark) => mark.channels.has('x')));
41
- hasChannelY = $derived(!!this.marks.find((mark) => mark.channels.has('y')));
40
+ hasChannelX = $derived(!!this.marks.find((mark) => !mark.automatic && mark.channels.has('x')));
41
+ hasChannelY = $derived(!!this.marks.find((mark) => !mark.automatic && mark.channels.has('y')));
42
42
  hasFilledDotMarks = $derived(!!this.marks.find((d) => d.type === 'dot' && d.props?.fill));
43
43
  manualMarks = $derived(this.marks.filter((mark) => !mark.automatic));
44
44
  singlePosChannelMark = $derived(this.manualMarks.length === 1 &&
@@ -90,7 +90,7 @@ export class Plot {
90
90
  // console.log('addMark: ' + mark);
91
91
  this.marks = [...this.marks, mark];
92
92
  // add mark to respective channels
93
- // console.log(this.x.domain);
93
+ console.log('y', this.hasChannelY, this.marks.filter(m => !m.automatic && m.channels.has('y')));
94
94
  }
95
95
  removeMark(removeMark) {
96
96
  this.marks = this.marks.filter((mark) => mark.id !== removeMark.id);
@@ -19,14 +19,14 @@ let {
19
19
  } = $props();
20
20
  let autoTickCount = $derived(plot.plotHeight / get(plot, "options.y.tickSpacing", 80));
21
21
  let autoTicks = $derived(
22
- ticks.length > 0 ? ticks : get(plot, "options.y.ticks", plot.yScale.ticks(autoTickCount))
22
+ ticks.length > 0 ? ticks : plot.options.y?.ticks || plot.yScale.ticks(autoTickCount)
23
23
  );
24
24
  let useTickFormat = $derived(
25
- typeof tickFormat === "function" ? tickFormat : plot.y.scaleType === "time" ? typeof tickFormat === "string" ? (d) => dayjs(d).format(tickFormat).split("\n") : autoTimeFormat(plot.y, plot.plotHeight) : (d) => String(d) + "x"
25
+ typeof tickFormat === "function" ? tickFormat : plot.y.scaleType === "time" ? typeof tickFormat === "string" ? (d) => dayjs(d).format(tickFormat).split("\n") : autoTimeFormat(plot.y, plot.plotHeight) : (d) => String(d)
26
26
  );
27
27
  let optionsLabel = $derived(plot.options.y?.label);
28
28
  let useTitle = $derived(
29
- title || (optionsLabel === null ? null : optionsLabel !== void 0 ? optionsLabel : `\u2191 ${plot.y.autoTitle}`)
29
+ title || (optionsLabel === null ? null : optionsLabel !== void 0 ? optionsLabel : plot.y.autoTitle ? `\u2191 ${plot.y.autoTitle}` : "")
30
30
  );
31
31
  </script>
32
32
 
@@ -6,7 +6,7 @@ const plot = getContext("svelteplot");
6
6
  let { ticks = [], automatic = false, ...styleProps } = $props();
7
7
  let autoTickCount = $derived(plot.plotHeight / get(plot, "options.y.tickSpacing", 80));
8
8
  let autoTicks = $derived(
9
- ticks.length > 0 ? ticks : get(plot, "options.y.ticks", plot.yScale.ticks(autoTickCount))
9
+ ticks.length > 0 ? ticks : plot.options.y?.ticks || plot.yScale.ticks(autoTickCount)
10
10
  );
11
11
  </script>
12
12
 
@@ -4,11 +4,11 @@ import getBaseStyles from "../helpers/getBaseStyles.js";
4
4
  import resolveChannel from "../helpers/resolveChannel.js";
5
5
  const BaseMark_RuleX = BaseMark;
6
6
  const plot = getContext("svelteplot");
7
- let { data = [], x, y1, y2, ...styleProps } = $props();
7
+ let { data = [], x, y1 = null, y2 = null, ...styleProps } = $props();
8
8
  let dataWrapped = $derived(x ? data : data.map((d) => ({ x: d, ___orig___: d })));
9
9
  </script>
10
10
 
11
- <BaseMark_RuleX type="rule-x" data={dataWrapped} channels={['x', 'y']} {x} {y1} {y2}>
11
+ <BaseMark_RuleX type="rule-x" data={dataWrapped} channels={y1 || y2 ? ['x', 'y'] : ['x']} x={x || 'x'} {y1} {y2}>
12
12
  <g class="rule-x">
13
13
  {#each data as datum}
14
14
  <line
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.0.1-alpha.10",
3
+ "version": "0.0.1-alpha.11",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build",
@@ -34,6 +34,7 @@
34
34
  "@sveltejs/kit": "^1.27.6",
35
35
  "@types/chroma-js": "^2.4.3",
36
36
  "@types/d3-interpolate": "^3.0.4",
37
+ "@types/d3-random": "^3.0.3",
37
38
  "@types/d3-scale-chromatic": "^3.0.3",
38
39
  "@types/d3-shape": "^3.1.6",
39
40
  "@typescript-eslint/eslint-plugin": "^6.13.2",
@@ -68,6 +69,7 @@
68
69
  "chroma-js": "^2.4.2",
69
70
  "d3-array": "^3.2.4",
70
71
  "d3-interpolate": "^3.0.1",
72
+ "d3-random": "^3.0.1",
71
73
  "d3-scale": "^4.0.2",
72
74
  "d3-scale-chromatic": "^3.0.0",
73
75
  "d3-shape": "^3.2.0",