svelteplot 0.2.6-next.1 → 0.2.6-next.3

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.
@@ -1,8 +1,7 @@
1
1
  <script lang="ts">
2
2
  import { setContext, type Snippet } from 'svelte';
3
3
  import { resolveChannel } from '../helpers/resolve.js';
4
- import type { BaseMarkProps, DataRecord, PlotScale, RawValue } from '../types.js';
5
- import { identity } from '../helpers';
4
+ import type { BaseMarkProps, DataRecord, RawValue } from '../types.js';
6
5
 
7
6
  let {
8
7
  fx,
@@ -4,7 +4,7 @@
4
4
  marks for each facet domain value
5
5
  -->
6
6
  <script lang="ts">
7
- import { getContext, setContext, type Snippet } from 'svelte';
7
+ import { getContext, type Snippet } from 'svelte';
8
8
  import type { PlotContext, GenericMarkOptions, Mark } from '../types.js';
9
9
  import { scaleBand } from 'd3-scale';
10
10
  import Facet from './Facet.svelte';
@@ -62,6 +62,7 @@
62
62
  initialWidth: 500,
63
63
  inset: 0,
64
64
  colorScheme: 'turbo',
65
+ unknown: '#cccccc',
65
66
  dotRadius: 3,
66
67
  frame: false,
67
68
  axes: true,
@@ -160,7 +161,7 @@
160
161
  );
161
162
 
162
163
  // if the plot is showing filled dot marks we're using different defaults
163
- // for the symbol axis range, so we're passing on this info to the createScales
164
+ // for the symbol axis range, so we're passing on this info to the computeScales
164
165
  // function below
165
166
  const hasFilledDotMarks = $derived(
166
167
  !!explicitMarks.find((d) => d.type === 'dot' && d.options.fill)
@@ -5,6 +5,7 @@ import callWithProps from './callWithProps.js';
5
5
  import { interpolateLab, interpolateRound } from 'd3-interpolate';
6
6
  import { coalesce, maybeNumber } from './index.js';
7
7
  import { getLogTicks } from './getLogTicks.js';
8
+ import { isPlainObject } from 'es-toolkit';
8
9
  const Scales = {
9
10
  point: scalePoint,
10
11
  band: scaleBand,
@@ -102,10 +103,23 @@ export function autoScaleColor({ type, domain, scaleOptions, plotOptions, plotWi
102
103
  let fn;
103
104
  let range;
104
105
  // special treatment for color scales
105
- const { scheme, interpolate, pivot, n = type === 'threshold' ? domain.length + 1 : 9 } = scaleOptions;
106
+ const { scheme, interpolate, pivot, n = type === 'threshold' ? domain.length + 1 : 9, unknown = plotDefaults.unknown } = scaleOptions;
106
107
  if (type === 'categorical' || type === 'ordinal') {
107
108
  // categorical
108
- const scheme_ = scheme || plotDefaults.categoricalColorScheme;
109
+ let scheme_ = scheme || plotDefaults.categoricalColorScheme;
110
+ if (isPlainObject(scheme_)) {
111
+ const newScheme = Object.values(scheme_);
112
+ const newDomain = Object.keys(scheme_);
113
+ // for every value in domain that's not part of the scheme, map to unknown
114
+ for (const v of domain) {
115
+ if (scheme_[v] == null) {
116
+ newDomain.push(v);
117
+ newScheme.push(unknown);
118
+ }
119
+ }
120
+ domain = newDomain;
121
+ scheme_ = newScheme;
122
+ }
109
123
  // categorical scale
110
124
  range = Array.isArray(scheme_)
111
125
  ? scheme_
@@ -1,5 +1,5 @@
1
1
  import { geoClipRectangle, geoPath, geoTransform } from 'd3-geo';
2
- import { constant, isObject, isValid } from './index.js';
2
+ import { constant, isObject } from './index.js';
3
3
  const identity = constant({ stream: (stream) => stream });
4
4
  const defaultAspectRatio = 0.618;
5
5
  export function createProjection({ projOptions, inset: globalInset = 2, insetTop = globalInset, insetRight = globalInset, insetBottom = globalInset, insetLeft = globalInset } = {}, dimensions) {
@@ -1,4 +1,4 @@
1
- import { min, max, mode, sum, mean, median, variance, deviation, quantile, range } from 'd3-array';
1
+ import { min, max, mode, sum, mean, median, variance, deviation, quantile } from 'd3-array';
2
2
  import { resolveChannel } from './resolve.js';
3
3
  import { POSITION_CHANNELS } from './index.js';
4
4
  const niceReduceNames = {
@@ -2,7 +2,6 @@ import { CHANNEL_SCALE } from '../constants.js';
2
2
  import isDataRecord from './isDataRecord.js';
3
3
  import isRawValue from './isRawValue.js';
4
4
  import { isValid } from './isValid.js';
5
- import { pick } from 'es-toolkit';
6
5
  import { getBaseStylesObject } from './getBaseStyles.js';
7
6
  import { RAW_VALUE } from '../transforms/recordize.js';
8
7
  export function resolveProp(accessor, datum, _defaultValue = null) {
@@ -1,4 +1,4 @@
1
- import { extent, range as d3Range, ascending } from 'd3-array';
1
+ import { extent, ascending } from 'd3-array';
2
2
  import { isColorOrNull, isDateOrNull, isNumberOrNull, isNumberOrNullOrNaN, isStringOrNull } from './typeChecks.js';
3
3
  import { CHANNEL_SCALE, VALID_SCALE_TYPES } from '../constants.js';
4
4
  import { isSymbolOrNull } from './typeChecks.js';
@@ -9,7 +9,6 @@
9
9
  BaseMarkProps,
10
10
  ConstantAccessor,
11
11
  ChannelAccessor,
12
- FacetContext,
13
12
  RawValue
14
13
  } from '../types.js';
15
14
  import { resolveChannel, resolveProp, resolveStyles } from '../helpers/resolve.js';
@@ -6,11 +6,9 @@
6
6
  PlotContext,
7
7
  BaseMarkProps,
8
8
  RawValue,
9
- DataRecord,
10
9
  FacetContext,
11
10
  DefaultOptions
12
11
  } from '../types.js';
13
- import getBaseStyles from '../helpers/getBaseStyles.js';
14
12
  import autoTimeFormat from '../helpers/autoTimeFormat.js';
15
13
  import type { ConstantAccessor } from '../types.js';
16
14
  import { autoTicks } from '../helpers/autoTicks.js';
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import Cell from './Cell.svelte';
3
- import { recordizeX, recordizeY } from '../index.js';
3
+ import { recordizeY } from '../index.js';
4
4
  import type { BaseMarkProps, DataRow, RectMarkProps } from '../types.js';
5
5
  import type { ChannelAccessor } from '../types.js';
6
6
 
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import { getContext } from 'svelte';
3
3
  import { Plot, AxisX, Frame } from '../index.js';
4
- import { symbol as d3Symbol, symbol } from 'd3-shape';
4
+ import { symbol as d3Symbol } from 'd3-shape';
5
5
  import { range as d3Range, extent } from 'd3-array';
6
6
  import { maybeSymbol } from '../helpers/symbols.js';
7
7
 
@@ -2,7 +2,6 @@
2
2
  import type {
3
3
  BaseMarkProps,
4
4
  ChannelAccessor,
5
- ConstantAccessor,
6
5
  CurveName,
7
6
  DataRecord,
8
7
  PlotContext
@@ -15,7 +15,7 @@
15
15
  import { sort } from '../index.js';
16
16
  import Mark from '../Mark.svelte';
17
17
  import DotCanvas from './helpers/DotCanvas.svelte';
18
- import { maybeData, testFilter, isValid } from '../helpers/index.js';
18
+ import { maybeData, isValid } from '../helpers/index.js';
19
19
  import { recordizeXY } from '../transforms/recordize.js';
20
20
  import { addEventHandlers } from './helpers/events.js';
21
21
 
@@ -4,9 +4,7 @@
4
4
  DataRecord,
5
5
  PlotContext,
6
6
  BaseMarkProps,
7
- FacetContext,
8
- ConstantAccessor,
9
- UsedScales
7
+ ConstantAccessor
10
8
  } from '../types.js';
11
9
  import Mark from '../Mark.svelte';
12
10
  import { geoPath } from 'd3-geo';
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import { getContext } from 'svelte';
3
3
  import Mark from '../Mark.svelte';
4
- import type { PlotContext, BaseMarkProps, RawValue, DataRecord } from '../types.js';
4
+ import type { PlotContext, BaseMarkProps, RawValue } from '../types.js';
5
5
  import { resolveChannel, resolveStyles } from '../helpers/resolve.js';
6
6
  import { autoTicks } from '../helpers/autoTicks.js';
7
7
  import { testFilter } from '../helpers/index.js';
@@ -41,7 +41,7 @@
41
41
  import MarkerPath from './helpers/MarkerPath.svelte';
42
42
  import { getContext } from 'svelte';
43
43
  import { resolveProp, resolveStyles } from '../helpers/resolve.js';
44
- import { line, type CurveFactory, type Line } from 'd3-shape';
44
+ import { line, type CurveFactory, type Line as D3Line } from 'd3-shape';
45
45
  import { geoPath } from 'd3-geo';
46
46
  import callWithProps from '../helpers/callWithProps.js';
47
47
  import { maybeCurve } from '../helpers/curves.js';
@@ -100,7 +100,7 @@
100
100
  const { getPlotState } = getContext<PlotContext>('svelteplot');
101
101
  const plot = $derived(getPlotState());
102
102
 
103
- const linePath: Line<ScaledDataRecord> = $derived(
103
+ const linePath: D3Line<ScaledDataRecord> = $derived(
104
104
  plot.scales.projection && curve === 'auto'
105
105
  ? sphereLine(plot.scales.projection)
106
106
  : callWithProps(line, [], {
@@ -21,7 +21,7 @@ export type BaseLineMarkProps = {
21
21
  lineClass?: ConstantAccessor<string>;
22
22
  canvas?: boolean;
23
23
  } & MarkerOptions;
24
- import { type CurveFactory, type Line } from 'd3-shape';
24
+ import { type CurveFactory } from 'd3-shape';
25
25
  import type { RawValue } from '../types.js';
26
26
  type LineMarkProps = BaseMarkProps & {
27
27
  x?: ChannelAccessor;
@@ -6,8 +6,6 @@
6
6
  import Mark from '../Mark.svelte';
7
7
  import { getContext } from 'svelte';
8
8
  import { intervalX, intervalY } from '../index.js';
9
- import { resolveProp, resolveStyles } from '../helpers/resolve.js';
10
- import { coalesce, maybeNumber } from '../helpers/index.js';
11
9
  import type {
12
10
  PlotContext,
13
11
  DataRecord,
@@ -15,7 +13,6 @@
15
13
  BaseRectMarkProps,
16
14
  ChannelAccessor
17
15
  } from '../types.js';
18
- import { addEventHandlers } from './helpers/events.js';
19
16
  import GroupMultiple from './helpers/GroupMultiple.svelte';
20
17
  import RectPath from './helpers/RectPath.svelte';
21
18
 
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { getContext, tick, untrack } from 'svelte';
2
+ import { getContext, untrack } from 'svelte';
3
3
  import { randomId, testFilter } from '../../helpers/index.js';
4
4
  import { resolveProp, resolveStyles } from '../../helpers/resolve.js';
5
5
  import { max } from 'd3-array';
@@ -6,7 +6,6 @@
6
6
  ScaledDataRecord,
7
7
  PlotContext
8
8
  } from '../../types.js';
9
- import { CSS_VAR } from '../../constants.js';
10
9
  import { resolveProp } from '../../helpers/resolve.js';
11
10
  import { maybeSymbol } from '../../helpers/symbols.js';
12
11
  import { symbol as d3Symbol } from 'd3-shape';
@@ -8,7 +8,7 @@
8
8
  } from '../../types.js';
9
9
  import { CSS_VAR } from '../../constants.js';
10
10
  import { resolveProp, resolveScaledStyleProps } from '../../helpers/resolve.js';
11
- import { getContext, untrack } from 'svelte';
11
+ import { getContext } from 'svelte';
12
12
  import { type GeoPath } from 'd3-geo';
13
13
  import CanvasLayer from './CanvasLayer.svelte';
14
14
  import type { Attachment } from 'svelte/attachments';
@@ -1,4 +1,4 @@
1
- import { invert, pick } from 'es-toolkit';
1
+ import { pick } from 'es-toolkit';
2
2
  import { RAW_VALUE } from '../../transforms/recordize.js';
3
3
  import { INDEX } from '../../constants.js';
4
4
  /**
@@ -1,7 +1,7 @@
1
1
  import { resolveChannel } from '../helpers/resolve.js';
2
2
  import { maybeInterval } from '../helpers/autoTicks.js';
3
- import { bin as d3Bin, extent, groups as d3Groups, thresholdFreedmanDiaconis, thresholdScott, thresholdSturges } from 'd3-array';
4
- import { Reducer, reduceOutputs } from '../helpers/reduce.js';
3
+ import { bin as d3Bin, extent, thresholdFreedmanDiaconis, thresholdScott, thresholdSturges } from 'd3-array';
4
+ import { reduceOutputs } from '../helpers/reduce.js';
5
5
  import { groupFacetsAndZ } from '../helpers/group.js';
6
6
  import { isDate } from '../helpers/typeChecks.js';
7
7
  const ThresholdGenerators = {
@@ -1,6 +1,6 @@
1
1
  import { maybeInterval } from '../helpers/autoTicks.js';
2
2
  import { isValid } from '../helpers/index.js';
3
- import { Reducer, mayberReducer } from '../helpers/reduce.js';
3
+ import { mayberReducer } from '../helpers/reduce.js';
4
4
  import { resolveChannel } from '../helpers/resolve.js';
5
5
  import { groups as d3Groups } from 'd3-array';
6
6
  export function windowX(args, options) {
package/dist/types.d.ts CHANGED
@@ -339,6 +339,10 @@ export type PlotDefaults = {
339
339
  */
340
340
  numberFormat: Intl.NumberFormatOptions;
341
341
  markerDotRadius: number;
342
+ /**
343
+ * fallback color to be used for null/NA
344
+ */
345
+ unknown: string;
342
346
  css: (d: string) => string | undefined;
343
347
  };
344
348
  export type GenericMarkOptions = Record<string, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.2.6-next.1",
3
+ "version": "0.2.6-next.3",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",