layerchart 2.0.0-next.1 → 2.0.0-next.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/actions/movable.d.ts +28 -0
- package/dist/actions/movable.js +91 -0
- package/dist/components/AnnotationLine.svelte +143 -0
- package/dist/components/AnnotationLine.svelte.d.ts +30 -0
- package/dist/components/AnnotationPoint.svelte +119 -0
- package/dist/components/AnnotationPoint.svelte.d.ts +34 -0
- package/dist/components/AnnotationRange.svelte +147 -0
- package/dist/components/AnnotationRange.svelte.d.ts +40 -0
- package/dist/components/Arc.svelte +344 -151
- package/dist/components/Arc.svelte.d.ts +138 -0
- package/dist/components/Area.svelte +165 -149
- package/dist/components/Area.svelte.d.ts +45 -0
- package/dist/components/Axis.svelte +320 -179
- package/dist/components/Axis.svelte.d.ts +127 -0
- package/dist/components/Bar.svelte +166 -107
- package/dist/components/Bar.svelte.d.ts +51 -0
- package/dist/components/Bars.svelte +56 -67
- package/dist/components/Bars.svelte.d.ts +27 -0
- package/dist/components/Blur.svelte +42 -12
- package/dist/components/Blur.svelte.d.ts +23 -21
- package/dist/components/Bounds.svelte +49 -19
- package/dist/components/Bounds.svelte.d.ts +24 -50
- package/dist/components/BrushContext.svelte +296 -168
- package/dist/components/BrushContext.svelte.d.ts +97 -65
- package/dist/components/Calendar.svelte +116 -59
- package/dist/components/Calendar.svelte.d.ts +50 -31
- package/dist/components/Chart.svelte +1289 -398
- package/dist/components/Chart.svelte.d.ts +535 -410
- package/dist/components/ChartClipPath.svelte +37 -15
- package/dist/components/ChartClipPath.svelte.d.ts +21 -19
- package/dist/components/Circle.svelte +124 -85
- package/dist/components/Circle.svelte.d.ts +52 -0
- package/dist/components/CircleClipPath.svelte +76 -16
- package/dist/components/CircleClipPath.svelte.d.ts +46 -0
- package/dist/components/ClipPath.svelte +71 -21
- package/dist/components/ClipPath.svelte.d.ts +40 -27
- package/dist/components/ColorRamp.svelte +75 -9
- package/dist/components/ColorRamp.svelte.d.ts +37 -19
- package/dist/components/ComputedStyles.svelte +17 -5
- package/dist/components/ComputedStyles.svelte.d.ts +11 -19
- package/dist/components/Connector.svelte +149 -0
- package/dist/components/Connector.svelte.d.ts +51 -0
- package/dist/components/Dagre.svelte +211 -122
- package/dist/components/Dagre.svelte.d.ts +119 -56
- package/dist/components/ForceSimulation.svelte +215 -90
- package/dist/components/ForceSimulation.svelte.d.ts +82 -35
- package/dist/components/Frame.svelte +33 -13
- package/dist/components/Frame.svelte.d.ts +13 -17
- package/dist/components/GeoCircle.svelte +29 -16
- package/dist/components/GeoCircle.svelte.d.ts +22 -24
- package/dist/components/GeoContext.svelte +113 -72
- package/dist/components/GeoContext.svelte.d.ts +49 -41
- package/dist/components/GeoEdgeFade.svelte +49 -13
- package/dist/components/GeoEdgeFade.svelte.d.ts +17 -19
- package/dist/components/GeoPath.svelte +157 -127
- package/dist/components/GeoPath.svelte.d.ts +48 -36
- package/dist/components/GeoPoint.svelte +52 -20
- package/dist/components/GeoPoint.svelte.d.ts +25 -22
- package/dist/components/GeoSpline.svelte +75 -26
- package/dist/components/GeoSpline.svelte.d.ts +29 -20
- package/dist/components/GeoTile.svelte +100 -49
- package/dist/components/GeoTile.svelte.d.ts +38 -23
- package/dist/components/GeoVisible.svelte +17 -9
- package/dist/components/GeoVisible.svelte.d.ts +10 -18
- package/dist/components/Graticule.svelte +30 -14
- package/dist/components/Graticule.svelte.d.ts +11 -52
- package/dist/components/Grid.svelte +230 -117
- package/dist/components/Grid.svelte.d.ts +71 -0
- package/dist/components/Group.svelte +173 -106
- package/dist/components/Group.svelte.d.ts +81 -0
- package/dist/components/Highlight.svelte +410 -308
- package/dist/components/Highlight.svelte.d.ts +107 -0
- package/dist/components/Hull.svelte +97 -46
- package/dist/components/Hull.svelte.d.ts +40 -30
- package/dist/components/Labels.svelte +127 -47
- package/dist/components/Labels.svelte.d.ts +70 -27
- package/dist/components/Legend.svelte +374 -190
- package/dist/components/Legend.svelte.d.ts +95 -44
- package/dist/components/Line.svelte +163 -125
- package/dist/components/Line.svelte.d.ts +75 -0
- package/dist/components/LinearGradient.svelte +153 -78
- package/dist/components/LinearGradient.svelte.d.ts +66 -31
- package/dist/components/Link.svelte +160 -104
- package/dist/components/Link.svelte.d.ts +54 -0
- package/dist/components/Marker.svelte +100 -39
- package/dist/components/Marker.svelte.d.ts +59 -27
- package/dist/components/MarkerWrapper.svelte +35 -0
- package/dist/components/MarkerWrapper.svelte.d.ts +18 -0
- package/dist/components/MonthPath.svelte +65 -20
- package/dist/components/MonthPath.svelte.d.ts +23 -17
- package/dist/components/MotionPath.svelte +80 -24
- package/dist/components/MotionPath.svelte.d.ts +46 -27
- package/dist/components/Pack.svelte +53 -17
- package/dist/components/Pack.svelte.d.ts +42 -21
- package/dist/components/Partition.svelte +64 -22
- package/dist/components/Partition.svelte.d.ts +49 -26
- package/dist/components/Pattern.svelte +297 -11
- package/dist/components/Pattern.svelte.d.ts +103 -19
- package/dist/components/Pie.svelte +122 -76
- package/dist/components/Pie.svelte.d.ts +65 -51
- package/dist/components/Point.svelte +20 -9
- package/dist/components/Point.svelte.d.ts +16 -20
- package/dist/components/Points.svelte +148 -137
- package/dist/components/Points.svelte.d.ts +45 -34
- package/dist/components/RadialGradient.svelte +148 -77
- package/dist/components/RadialGradient.svelte.d.ts +69 -31
- package/dist/components/Rect.svelte +121 -102
- package/dist/components/Rect.svelte.d.ts +36 -0
- package/dist/components/RectClipPath.svelte +82 -18
- package/dist/components/RectClipPath.svelte.d.ts +55 -0
- package/dist/components/Rule.svelte +107 -63
- package/dist/components/Rule.svelte.d.ts +40 -19
- package/dist/components/Sankey.svelte +132 -55
- package/dist/components/Sankey.svelte.d.ts +61 -31
- package/dist/components/Spline.svelte +281 -218
- package/dist/components/Spline.svelte.d.ts +95 -0
- package/dist/components/Text.svelte +463 -197
- package/dist/components/Text.svelte.d.ts +136 -0
- package/dist/components/Threshold.svelte +48 -16
- package/dist/components/Threshold.svelte.d.ts +29 -31
- package/dist/components/TileImage.svelte +103 -30
- package/dist/components/TileImage.svelte.d.ts +48 -23
- package/dist/components/TransformContext.svelte +365 -171
- package/dist/components/TransformControls.svelte +50 -26
- package/dist/components/TransformControls.svelte.d.ts +27 -19
- package/dist/components/Tree.svelte +74 -33
- package/dist/components/Tree.svelte.d.ts +42 -30
- package/dist/components/Treemap.svelte +119 -42
- package/dist/components/Treemap.svelte.d.ts +75 -27
- package/dist/components/Voronoi.svelte +153 -103
- package/dist/components/Voronoi.svelte.d.ts +42 -41
- package/dist/components/charts/ArcChart.svelte +464 -0
- package/dist/components/charts/ArcChart.svelte.d.ts +90 -0
- package/dist/components/charts/AreaChart.svelte +444 -393
- package/dist/components/charts/AreaChart.svelte.d.ts +61 -0
- package/dist/components/charts/BarChart.svelte +463 -389
- package/dist/components/charts/BarChart.svelte.d.ts +76 -0
- package/dist/components/charts/ChartAnnotations.svelte +37 -0
- package/dist/components/charts/ChartAnnotations.svelte.d.ts +10 -0
- package/dist/components/charts/DefaultTooltip.svelte +60 -0
- package/dist/components/charts/DefaultTooltip.svelte.d.ts +10 -0
- package/dist/components/charts/LineChart.svelte +366 -315
- package/dist/components/charts/LineChart.svelte.d.ts +53 -0
- package/dist/components/charts/PieChart.svelte +458 -316
- package/dist/components/charts/PieChart.svelte.d.ts +137 -353
- package/dist/components/charts/ScatterChart.svelte +332 -296
- package/dist/components/charts/ScatterChart.svelte.d.ts +39 -0
- package/dist/components/charts/index.d.ts +8 -0
- package/dist/components/charts/index.js +7 -0
- package/dist/components/charts/types.d.ts +253 -0
- package/dist/components/charts/utils.svelte.d.ts +30 -0
- package/dist/components/charts/utils.svelte.js +59 -0
- package/dist/components/index.d.ts +76 -4
- package/dist/components/index.js +76 -5
- package/dist/components/layout/Canvas.svelte +347 -171
- package/dist/components/layout/Canvas.svelte.d.ts +110 -55
- package/dist/components/layout/Html.svelte +82 -42
- package/dist/components/layout/Html.svelte.d.ts +39 -28
- package/dist/components/layout/Layer.svelte +39 -0
- package/dist/components/layout/Layer.svelte.d.ts +17 -0
- package/dist/components/layout/Svg.svelte +122 -70
- package/dist/components/layout/Svg.svelte.d.ts +53 -34
- package/dist/components/layout/WebGL.svelte +135 -0
- package/dist/components/layout/WebGL.svelte.d.ts +50 -0
- package/dist/components/tooltip/Tooltip.svelte +253 -78
- package/dist/components/tooltip/Tooltip.svelte.d.ts +149 -31
- package/dist/components/tooltip/TooltipContext.svelte +426 -271
- package/dist/components/tooltip/TooltipContext.svelte.d.ts +86 -55
- package/dist/components/tooltip/TooltipHeader.svelte +100 -11
- package/dist/components/tooltip/TooltipHeader.svelte.d.ts +43 -23
- package/dist/components/tooltip/TooltipItem.svelte +167 -27
- package/dist/components/tooltip/TooltipItem.svelte.d.ts +63 -31
- package/dist/components/tooltip/TooltipList.svelte +22 -3
- package/dist/components/tooltip/TooltipList.svelte.d.ts +6 -17
- package/dist/components/tooltip/TooltipSeparator.svelte +27 -1
- package/dist/components/tooltip/TooltipSeparator.svelte.d.ts +6 -15
- package/dist/components/tooltip/index.d.ts +6 -0
- package/dist/components/tooltip/index.js +6 -0
- package/dist/components/tooltip/tooltipMetaContext.d.ts +79 -0
- package/dist/components/tooltip/tooltipMetaContext.js +139 -0
- package/dist/components/types.d.ts +1 -0
- package/dist/components/types.js +1 -0
- package/dist/docs/Blockquote.svelte +3 -1
- package/dist/docs/Blockquote.svelte.d.ts +5 -16
- package/dist/docs/Code.svelte +20 -12
- package/dist/docs/Code.svelte.d.ts +12 -22
- package/dist/docs/ConnectorSweepMenuField.svelte +17 -0
- package/dist/docs/ConnectorSweepMenuField.svelte.d.ts +7 -0
- package/dist/docs/ConnectorTypeMenuField.svelte +17 -0
- package/dist/docs/ConnectorTypeMenuField.svelte.d.ts +7 -0
- package/dist/docs/CurveMenuField.svelte +14 -3
- package/dist/docs/CurveMenuField.svelte.d.ts +9 -18
- package/dist/docs/GeoDebug.svelte +47 -42
- package/dist/docs/GeoDebug.svelte.d.ts +4 -16
- package/dist/docs/Header1.svelte +4 -2
- package/dist/docs/Header1.svelte.d.ts +5 -18
- package/dist/docs/Json.svelte +11 -3
- package/dist/docs/Json.svelte.d.ts +9 -17
- package/dist/docs/Layout.svelte +10 -7
- package/dist/docs/Layout.svelte.d.ts +5 -15
- package/dist/docs/Link.svelte +7 -3
- package/dist/docs/Link.svelte.d.ts +5 -27
- package/dist/docs/PathDataMenuField.svelte +14 -10
- package/dist/docs/PathDataMenuField.svelte.d.ts +8 -18
- package/dist/docs/Preview.svelte +20 -7
- package/dist/docs/Preview.svelte.d.ts +12 -22
- package/dist/docs/TilesetField.svelte +20 -19
- package/dist/docs/TilesetField.svelte.d.ts +6 -19
- package/dist/docs/TransformDebug.svelte +5 -6
- package/dist/docs/TransformDebug.svelte.d.ts +18 -14
- package/dist/docs/ViewSourceButton.svelte +7 -4
- package/dist/docs/ViewSourceButton.svelte.d.ts +8 -18
- package/dist/types/d3-shape-extentions.d.ts +7 -0
- package/dist/utils/afterTick.d.ts +5 -0
- package/dist/utils/afterTick.js +8 -0
- package/dist/utils/arcText.svelte.d.ts +57 -0
- package/dist/utils/arcText.svelte.js +262 -0
- package/dist/utils/array.d.ts +9 -1
- package/dist/utils/array.js +13 -0
- package/dist/utils/attributes.d.ts +29 -0
- package/dist/utils/attributes.js +40 -0
- package/dist/utils/canvas.js +47 -10
- package/dist/utils/chart.d.ts +78 -0
- package/dist/utils/chart.js +512 -0
- package/dist/utils/color.d.ts +1 -0
- package/dist/utils/color.js +8 -0
- package/dist/utils/common.d.ts +3 -5
- package/dist/utils/common.js +3 -2
- package/dist/utils/connectorUtils.d.ts +21 -0
- package/dist/utils/connectorUtils.js +111 -0
- package/dist/utils/createId.d.ts +7 -0
- package/dist/utils/createId.js +9 -0
- package/dist/utils/debug.d.ts +1 -0
- package/dist/utils/debug.js +84 -0
- package/dist/utils/filterObject.d.ts +9 -0
- package/dist/utils/filterObject.js +12 -0
- package/dist/utils/graph/dagre.d.ts +34 -0
- package/dist/utils/graph/dagre.js +78 -0
- package/dist/utils/graph/dagre.test.d.ts +1 -0
- package/dist/utils/{graph.test.js → graph/dagre.test.js} +19 -33
- package/dist/utils/graph/sankey.d.ts +28 -0
- package/dist/utils/{graph.js → graph/sankey.js} +13 -41
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/key.svelte.d.ts +3 -0
- package/dist/utils/key.svelte.js +11 -0
- package/dist/utils/legendPayload.d.ts +7 -0
- package/dist/utils/legendPayload.js +8 -0
- package/dist/utils/motion.svelte.d.ts +140 -0
- package/dist/utils/motion.svelte.js +180 -0
- package/dist/utils/motion.test.d.ts +1 -0
- package/dist/utils/motion.test.js +213 -0
- package/dist/utils/{rect.d.ts → rect.svelte.d.ts} +7 -4
- package/dist/utils/rect.svelte.js +105 -0
- package/dist/utils/scales.svelte.d.ts +91 -0
- package/dist/utils/scales.svelte.js +201 -0
- package/dist/utils/stack.d.ts +2 -3
- package/dist/utils/stack.js +1 -1
- package/dist/utils/string.js +87 -0
- package/dist/utils/ticks.d.ts +9 -3
- package/dist/utils/ticks.js +122 -147
- package/dist/utils/ticks.test.d.ts +1 -0
- package/dist/utils/ticks.test.js +57 -0
- package/dist/utils/types.d.ts +81 -0
- package/package.json +28 -24
- package/dist/components/ChartContext.svelte +0 -295
- package/dist/components/ChartContext.svelte.d.ts +0 -139
- package/dist/components/TransformContext.svelte.d.ts +0 -158
- package/dist/stores/motionStore.d.ts +0 -30
- package/dist/stores/motionStore.js +0 -62
- package/dist/utils/graph.d.ts +0 -37
- package/dist/utils/rect.js +0 -107
- package/dist/utils/scales.d.ts +0 -66
- package/dist/utils/scales.js +0 -136
- /package/dist/{utils/graph.test.d.ts → components/charts/types.js} +0 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type ScaleBand, type ScaleTime } from 'd3-scale';
|
|
2
|
+
import { type MotionProp, type MotionOptions, type SpringOptions, type TweenOptions } from './motion.svelte.js';
|
|
3
|
+
import type { Accessor } from './common.js';
|
|
4
|
+
import type { OnlyObjects } from './types.js';
|
|
5
|
+
export type AnyScale<TInput extends SingleDomainType = any, TOutput extends SingleDomainType = any, TScaleArgs extends any[] | readonly any[] = any[]> = {
|
|
6
|
+
(value: TInput): TOutput;
|
|
7
|
+
domain(domain: TInput[] | readonly TInput[]): AnyScale<TInput, TOutput, TScaleArgs>;
|
|
8
|
+
domain(): TInput[];
|
|
9
|
+
range(range: TOutput[] | readonly TOutput[]): AnyScale<TInput, TOutput, TScaleArgs>;
|
|
10
|
+
range(): TOutput[];
|
|
11
|
+
rangeRound?: (range: TOutput[] | readonly TOutput[]) => AnyScale<TInput, TOutput, TScaleArgs>;
|
|
12
|
+
copy: () => AnyScale<TInput, TOutput, TScaleArgs>;
|
|
13
|
+
invert?: (value: TOutput) => TInput;
|
|
14
|
+
invertExtent?: (value: TOutput) => [TInput, TInput];
|
|
15
|
+
bandwidth?: () => number;
|
|
16
|
+
ticks?: (count?: number) => TInput[];
|
|
17
|
+
tickFormat?: (count?: number) => (value: TInput) => string;
|
|
18
|
+
clamp?: (clamp: boolean) => AnyScale<TInput, TOutput, TScaleArgs>;
|
|
19
|
+
interpolate?: (interpolate: (a: TOutput, b: TOutput) => (t: number) => TOutput) => AnyScale<TInput, TOutput, TScaleArgs>;
|
|
20
|
+
nice?: (count?: number) => AnyScale<TInput, TOutput, TScaleArgs>;
|
|
21
|
+
interpolator?(interpolator: (t: number) => TOutput): AnyScale<TInput, TOutput, TScaleArgs>;
|
|
22
|
+
interpolator?(): (t: number) => TOutput;
|
|
23
|
+
thresholds?: () => TInput[];
|
|
24
|
+
quantiles?: () => TInput[];
|
|
25
|
+
};
|
|
26
|
+
export declare function isScaleBand(scale: AnyScale<any, any>): scale is ScaleBand<any>;
|
|
27
|
+
export declare function isScaleTime(scale: AnyScale<any, any>): scale is ScaleTime<any, any>;
|
|
28
|
+
export declare function getRange(scale: any): any[];
|
|
29
|
+
export type SingleDomainType = number | string | Date | null | undefined;
|
|
30
|
+
export type DomainType = (number | string | Date | null | undefined)[] | null | undefined;
|
|
31
|
+
export declare function createMotionScale<Domain, Range>(scale: AnyScale, motion: MotionProp | undefined, options: {
|
|
32
|
+
defaultDomain?: Domain;
|
|
33
|
+
defaultRange?: Range;
|
|
34
|
+
}): {
|
|
35
|
+
readonly current: any;
|
|
36
|
+
domain: (values: Domain) => Promise<void>;
|
|
37
|
+
range: (values: Range) => Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Implementation for missing `scaleBand().invert()`
|
|
41
|
+
*
|
|
42
|
+
* See: https://stackoverflow.com/questions/38633082/d3-getting-invert-value-of-band-scales
|
|
43
|
+
* https://github.com/d3/d3-scale/pull/64
|
|
44
|
+
* https://github.com/vega/vega-scale/blob/master/src/scaleBand.js#L118
|
|
45
|
+
* https://observablehq.com/@d3/ordinal-brushing
|
|
46
|
+
* https://github.com/d3/d3-scale/blob/11777dac7d4b0b3e229d658aee3257ea67bd5ffa/src/band.js#L32
|
|
47
|
+
* https://gist.github.com/LuisSevillano/d53a1dc529eef518780c6df99613e2fd
|
|
48
|
+
*/
|
|
49
|
+
export declare function scaleBandInvert(scale: ScaleBand<any>): (value: number) => any;
|
|
50
|
+
/**
|
|
51
|
+
* Generic way to invert a scale value, handling scaleBand and continuous scales (linear, time, etc).
|
|
52
|
+
* Useful to map mouse event location (x,y) to domain value
|
|
53
|
+
*/
|
|
54
|
+
export declare function scaleInvert(scale: AnyScale<any, any>, value: number): any;
|
|
55
|
+
/** Create new copy of scale with domain and range */
|
|
56
|
+
export declare function createScale(scale: AnyScale, domain: DomainType, range: any[] | readonly any[] | Function, context?: Record<any, any>): AnyScale<any, any, any[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Create a `scaleBand()` within another scaleBand()'s bandwidth
|
|
59
|
+
* (typically a x1 of an x0 scale, used for grouping)
|
|
60
|
+
*/
|
|
61
|
+
export declare function groupScaleBand<Domain extends {
|
|
62
|
+
toString(): string;
|
|
63
|
+
}>(scale: ScaleBand<Domain>, flatData: any[], groupBy: string, padding?: {
|
|
64
|
+
inner?: number;
|
|
65
|
+
outer?: number;
|
|
66
|
+
}): ScaleBand<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Animate d3-scale as domain and/or range are updated using tweened store
|
|
69
|
+
*/
|
|
70
|
+
export declare function tweenedScale<Domain, Range>(scale: any, tweenedOptions?: TweenOptions): {
|
|
71
|
+
readonly current: any;
|
|
72
|
+
domain: (values: Domain) => Promise<void>;
|
|
73
|
+
range: (values: Range) => Promise<void>;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Animate d3-scale as domain and/or range are updated using spring store
|
|
77
|
+
*/
|
|
78
|
+
export declare function springScale<Domain, Range>(scale: AnyScale, springOptions?: SpringOptions): {
|
|
79
|
+
readonly current: any;
|
|
80
|
+
domain: (values: Domain) => Promise<void>;
|
|
81
|
+
range: (values: Range) => Promise<void>;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Create a store wrapper around a d3-scale which interpolates the domain and/or range using `tweened()` or `spring()` stores. Fallbacks to `writable()` store if not interpolating
|
|
85
|
+
*/
|
|
86
|
+
export declare function motionScale<Domain, Range>(scale: AnyScale, options: OnlyObjects<MotionOptions>): {
|
|
87
|
+
readonly current: any;
|
|
88
|
+
domain: (values: Domain) => Promise<void>;
|
|
89
|
+
range: (values: Range) => Promise<void>;
|
|
90
|
+
};
|
|
91
|
+
export declare function makeAccessor<TData>(acc: Accessor<TData>): (d: TData) => any;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { unique } from '@layerstack/utils';
|
|
2
|
+
import { scaleBand } from 'd3-scale';
|
|
3
|
+
import { createControlledMotion, } from './motion.svelte.js';
|
|
4
|
+
import { Spring, Tween } from 'svelte/motion';
|
|
5
|
+
function isAnyScale(scale) {
|
|
6
|
+
return typeof scale === 'function' && typeof scale.range === 'function';
|
|
7
|
+
}
|
|
8
|
+
export function isScaleBand(scale) {
|
|
9
|
+
return typeof scale.bandwidth === 'function';
|
|
10
|
+
}
|
|
11
|
+
export function isScaleTime(scale) {
|
|
12
|
+
const domain = scale.domain();
|
|
13
|
+
return domain[0] instanceof Date || domain[1] instanceof Date;
|
|
14
|
+
}
|
|
15
|
+
export function getRange(scale) {
|
|
16
|
+
if (isAnyScale(scale)) {
|
|
17
|
+
return scale.range();
|
|
18
|
+
}
|
|
19
|
+
console.error("[LayerChart] Your scale doesn't have a `.range` method?");
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
// this may need to become a getter for options so we can reactively update after mount
|
|
23
|
+
export function createMotionScale(scale, motion, options) {
|
|
24
|
+
const domain = createControlledMotion(options.defaultDomain, motion);
|
|
25
|
+
const range = createControlledMotion(options.defaultRange, motion);
|
|
26
|
+
const motionScale = $derived.by(() => {
|
|
27
|
+
// @ts-expect-error
|
|
28
|
+
const scaleInstance = scale.domain ? scale : scale(); // support `scaleLinear` or `scaleLinear()` (which could have `.interpolate()` and others set)
|
|
29
|
+
if (domain.current) {
|
|
30
|
+
scaleInstance.domain(domain.current);
|
|
31
|
+
}
|
|
32
|
+
if (range.current) {
|
|
33
|
+
scaleInstance.range(range.current);
|
|
34
|
+
}
|
|
35
|
+
return scaleInstance;
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
get current() {
|
|
39
|
+
return motionScale;
|
|
40
|
+
},
|
|
41
|
+
domain: (values) => domain.set(values),
|
|
42
|
+
range: (values) => range.set(values),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Implementation for missing `scaleBand().invert()`
|
|
47
|
+
*
|
|
48
|
+
* See: https://stackoverflow.com/questions/38633082/d3-getting-invert-value-of-band-scales
|
|
49
|
+
* https://github.com/d3/d3-scale/pull/64
|
|
50
|
+
* https://github.com/vega/vega-scale/blob/master/src/scaleBand.js#L118
|
|
51
|
+
* https://observablehq.com/@d3/ordinal-brushing
|
|
52
|
+
* https://github.com/d3/d3-scale/blob/11777dac7d4b0b3e229d658aee3257ea67bd5ffa/src/band.js#L32
|
|
53
|
+
* https://gist.github.com/LuisSevillano/d53a1dc529eef518780c6df99613e2fd
|
|
54
|
+
*/
|
|
55
|
+
export function scaleBandInvert(scale) {
|
|
56
|
+
const domain = scale.domain();
|
|
57
|
+
const eachBand = scale.step();
|
|
58
|
+
const paddingOuter = eachBand * (scale.paddingOuter?.() ?? scale.padding()); // `scaleBand` uses paddingOuter(), while `scalePoint` uses padding() for outer paddding - https://github.com/d3/d3-scale#point_padding
|
|
59
|
+
return function (value) {
|
|
60
|
+
const index = Math.floor((value - paddingOuter / 2) / eachBand);
|
|
61
|
+
return domain[Math.max(0, Math.min(index, domain.length - 1))];
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Generic way to invert a scale value, handling scaleBand and continuous scales (linear, time, etc).
|
|
66
|
+
* Useful to map mouse event location (x,y) to domain value
|
|
67
|
+
*/
|
|
68
|
+
export function scaleInvert(scale, value) {
|
|
69
|
+
if (isScaleBand(scale)) {
|
|
70
|
+
return scaleBandInvert(scale)(value);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return scale.invert?.(value);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** Create new copy of scale with domain and range */
|
|
77
|
+
export function createScale(scale, domain, range, context) {
|
|
78
|
+
const scaleCopy = scale.copy();
|
|
79
|
+
if (domain) {
|
|
80
|
+
scaleCopy.domain(domain);
|
|
81
|
+
}
|
|
82
|
+
if (typeof range === 'function') {
|
|
83
|
+
scaleCopy.range(range(context));
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
scaleCopy.range(range);
|
|
87
|
+
}
|
|
88
|
+
return scaleCopy;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Create a `scaleBand()` within another scaleBand()'s bandwidth
|
|
92
|
+
* (typically a x1 of an x0 scale, used for grouping)
|
|
93
|
+
*/
|
|
94
|
+
export function groupScaleBand(scale, flatData, groupBy, padding) {
|
|
95
|
+
//
|
|
96
|
+
const groupKeys = unique(flatData.map((d) => d[groupBy]));
|
|
97
|
+
let newScale = scaleBand().domain(groupKeys).range([0, scale.bandwidth()]);
|
|
98
|
+
if (padding) {
|
|
99
|
+
if (padding.inner) {
|
|
100
|
+
newScale = newScale.paddingInner(padding.inner);
|
|
101
|
+
}
|
|
102
|
+
if (padding.outer) {
|
|
103
|
+
newScale = newScale.paddingOuter(padding.outer);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return newScale;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Animate d3-scale as domain and/or range are updated using tweened store
|
|
110
|
+
*/
|
|
111
|
+
export function tweenedScale(scale, tweenedOptions = {}) {
|
|
112
|
+
const tweenedDomain = new Tween(undefined, tweenedOptions);
|
|
113
|
+
const tweenedRange = new Tween(undefined, tweenedOptions);
|
|
114
|
+
const tweenedScale = $derived.by(() => {
|
|
115
|
+
const scaledInstance = scale.domain ? scale : scale();
|
|
116
|
+
if (tweenedDomain.current) {
|
|
117
|
+
scaledInstance.domain(tweenedDomain.current);
|
|
118
|
+
}
|
|
119
|
+
if (tweenedRange.current) {
|
|
120
|
+
scaledInstance.range(tweenedRange.current);
|
|
121
|
+
}
|
|
122
|
+
return scaledInstance;
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
get current() {
|
|
126
|
+
return tweenedScale;
|
|
127
|
+
},
|
|
128
|
+
domain: (values) => tweenedDomain.set(values),
|
|
129
|
+
range: (values) => tweenedRange.set(values),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Animate d3-scale as domain and/or range are updated using spring store
|
|
134
|
+
*/
|
|
135
|
+
export function springScale(scale, springOptions = {}) {
|
|
136
|
+
const domainState = new Spring(undefined, springOptions);
|
|
137
|
+
const rangeState = new Spring(undefined, springOptions);
|
|
138
|
+
const sprungScale = $derived.by(() => {
|
|
139
|
+
// @ts-expect-error - TODO: investigate/fix
|
|
140
|
+
const scaledInstance = scale.domain ? scale : scale();
|
|
141
|
+
if (domainState.current) {
|
|
142
|
+
scaledInstance.domain(domainState.current);
|
|
143
|
+
}
|
|
144
|
+
if (rangeState.current) {
|
|
145
|
+
scaledInstance.range(rangeState.current);
|
|
146
|
+
}
|
|
147
|
+
return scaledInstance;
|
|
148
|
+
});
|
|
149
|
+
return {
|
|
150
|
+
get current() {
|
|
151
|
+
return sprungScale;
|
|
152
|
+
},
|
|
153
|
+
domain: (values) => domainState.set(values),
|
|
154
|
+
range: (values) => rangeState.set(values),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Create a store wrapper around a d3-scale which interpolates the domain and/or range using `tweened()` or `spring()` stores. Fallbacks to `writable()` store if not interpolating
|
|
159
|
+
*/
|
|
160
|
+
export function motionScale(scale, options) {
|
|
161
|
+
const domainState = createControlledMotion(undefined, options);
|
|
162
|
+
const rangeState = createControlledMotion(undefined, options);
|
|
163
|
+
const tweenedScale = $derived.by(() => {
|
|
164
|
+
// @ts-expect-error
|
|
165
|
+
const scaleInstance = scale.domain ? scale : scale(); // support `scaleLinear` or `scaleLinear()` (which could have `.interpolate()` and others set)
|
|
166
|
+
if (domainState.current) {
|
|
167
|
+
scaleInstance.domain(domainState.current);
|
|
168
|
+
}
|
|
169
|
+
if (rangeState.current) {
|
|
170
|
+
scaleInstance.range(rangeState.current);
|
|
171
|
+
}
|
|
172
|
+
return scaleInstance;
|
|
173
|
+
});
|
|
174
|
+
return {
|
|
175
|
+
get current() {
|
|
176
|
+
return tweenedScale;
|
|
177
|
+
},
|
|
178
|
+
domain: (values) => domainState.set(values),
|
|
179
|
+
range: (values) => rangeState.set(values),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function canBeZero(val) {
|
|
183
|
+
if (val === 0)
|
|
184
|
+
return true;
|
|
185
|
+
return val;
|
|
186
|
+
}
|
|
187
|
+
export function makeAccessor(acc) {
|
|
188
|
+
if (!canBeZero(acc))
|
|
189
|
+
return null;
|
|
190
|
+
if (Array.isArray(acc)) {
|
|
191
|
+
return (d) => acc.map((k) => {
|
|
192
|
+
// @ts-expect-error - TODO: Fix these types
|
|
193
|
+
return typeof k !== 'function' ? d[k] : k(d);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
else if (typeof acc !== 'function') {
|
|
197
|
+
// @ts-expect-error - TODO: Fix these types
|
|
198
|
+
return (d) => d[acc];
|
|
199
|
+
}
|
|
200
|
+
return acc;
|
|
201
|
+
}
|
package/dist/utils/stack.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
type
|
|
3
|
-
type OffsetType = typeof stackOffsetNone;
|
|
1
|
+
type OrderType = typeof import('d3-shape').stackOrderNone;
|
|
2
|
+
type OffsetType = typeof import('d3-shape').stackOffsetNone;
|
|
4
3
|
export declare function groupStackData<TData>(data: TData[], options: {
|
|
5
4
|
xKey: string;
|
|
6
5
|
groupBy?: string;
|
package/dist/utils/stack.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { flatGroup, group, max, rollup, sum } from 'd3-array';
|
|
2
|
-
import { stack
|
|
2
|
+
import { stack } from 'd3-shape';
|
|
3
3
|
import { pivotWider } from './pivot.js';
|
|
4
4
|
export function groupStackData(data, options) {
|
|
5
5
|
const dataByKey = group(data, (d) => d[options.xKey]);
|
package/dist/utils/string.js
CHANGED
|
@@ -66,3 +66,90 @@ function getPixel(imageData, x, y) {
|
|
|
66
66
|
var d = imageData.data;
|
|
67
67
|
return [d[i], d[i + 1], d[i + 2], d[i + 3]];
|
|
68
68
|
}
|
|
69
|
+
export function toTitleCase(str) {
|
|
70
|
+
return str.replace(/^\w/, (d) => d.toUpperCase());
|
|
71
|
+
}
|
|
72
|
+
const DEFAULT_ELLIPSIS = '…';
|
|
73
|
+
/**
|
|
74
|
+
* Truncates a string to fit within a specified pixel width or character count.
|
|
75
|
+
* If the string's width exceeds the maxWidth, it will be truncated. If the character
|
|
76
|
+
* count exceeds maxChars, it will also be truncated.
|
|
77
|
+
*
|
|
78
|
+
* The ellipsis can be placed at the start, middle, or end of the string.
|
|
79
|
+
*/
|
|
80
|
+
export function truncateText(text, { position = 'end', ellipsis = DEFAULT_ELLIPSIS, maxWidth, style, maxChars }) {
|
|
81
|
+
if (!text)
|
|
82
|
+
return '';
|
|
83
|
+
// no constraints, return original text
|
|
84
|
+
if (maxWidth === undefined && maxChars === undefined)
|
|
85
|
+
return text;
|
|
86
|
+
// apply maxChars constraint first (if provided)
|
|
87
|
+
let workingText = text;
|
|
88
|
+
if (maxChars !== undefined && text.length > maxChars) {
|
|
89
|
+
if (position === 'start') {
|
|
90
|
+
workingText = ellipsis + text.slice(-maxChars);
|
|
91
|
+
}
|
|
92
|
+
else if (position === 'middle') {
|
|
93
|
+
const half = Math.floor(maxChars / 2);
|
|
94
|
+
workingText = text.slice(0, half) + ellipsis + text.slice(-half);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
workingText = text.slice(0, maxChars) + ellipsis;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// apply maxWidth constraint (if provided)
|
|
101
|
+
if (maxWidth !== undefined) {
|
|
102
|
+
const fullWidth = getStringWidth(workingText, style);
|
|
103
|
+
// if width measurement fails or text fits, return current text
|
|
104
|
+
if (fullWidth === null || fullWidth <= maxWidth)
|
|
105
|
+
return workingText;
|
|
106
|
+
const ellipsisWidth = getStringWidth(ellipsis, style) ?? 0;
|
|
107
|
+
let availableWidth = maxWidth - ellipsisWidth;
|
|
108
|
+
if (position === 'start') {
|
|
109
|
+
let truncated = workingText.slice(ellipsis.length); // remove initial ellipsis if present
|
|
110
|
+
let truncatedWidth = getStringWidth(truncated, style);
|
|
111
|
+
while (truncatedWidth !== null && truncatedWidth > availableWidth && truncated.length > 0) {
|
|
112
|
+
truncated = truncated.slice(1);
|
|
113
|
+
truncatedWidth = getStringWidth(truncated, style);
|
|
114
|
+
}
|
|
115
|
+
return ellipsis + truncated;
|
|
116
|
+
}
|
|
117
|
+
else if (position === 'middle') {
|
|
118
|
+
const halfWidth = availableWidth / 2;
|
|
119
|
+
let left = '';
|
|
120
|
+
let right = '';
|
|
121
|
+
let bestLeft = '';
|
|
122
|
+
let bestRight = '';
|
|
123
|
+
for (let i = 0, j = workingText.length - 1; i < workingText.length && j >= 0; i++, j--) {
|
|
124
|
+
const leftTest = workingText.slice(0, i + 1);
|
|
125
|
+
const rightTest = workingText.slice(j);
|
|
126
|
+
const leftWidth = getStringWidth(leftTest, style);
|
|
127
|
+
const rightWidth = getStringWidth(rightTest, style);
|
|
128
|
+
if (leftWidth !== null && leftWidth <= halfWidth)
|
|
129
|
+
left = leftTest;
|
|
130
|
+
if (rightWidth !== null && rightWidth <= halfWidth)
|
|
131
|
+
right = rightTest;
|
|
132
|
+
const combinedWidth = getStringWidth(left + ellipsis + right, style);
|
|
133
|
+
if (combinedWidth !== null && combinedWidth <= maxWidth) {
|
|
134
|
+
bestLeft = left; // longest valid left
|
|
135
|
+
bestRight = right; // longest valid right
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
// we've exceed maxWidth, so break out
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return bestLeft + ellipsis + bestRight;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
let truncated = workingText.slice(0, -ellipsis.length);
|
|
146
|
+
let truncatedWidth = getStringWidth(truncated + ellipsis, style);
|
|
147
|
+
while (truncatedWidth !== null && truncatedWidth > maxWidth && truncated.length > 0) {
|
|
148
|
+
truncated = truncated.slice(0, -1);
|
|
149
|
+
truncatedWidth = getStringWidth(truncated + ellipsis, style);
|
|
150
|
+
}
|
|
151
|
+
return truncated + ellipsis;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return workingText;
|
|
155
|
+
}
|
package/dist/utils/ticks.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { type TimeInterval } from 'd3-time';
|
|
2
|
+
import { Duration, type FormatType } from '@layerstack/utils';
|
|
3
|
+
import { type AnyScale } from './scales.svelte.js';
|
|
4
|
+
export declare function getDurationFormat(duration: Duration, multiline?: boolean): (date: Date, i: number) => string;
|
|
5
|
+
export type TicksConfig = number | any[] | ((scale: AnyScale) => any[] | undefined) | {
|
|
6
|
+
interval: TimeInterval | null;
|
|
7
|
+
} | null;
|
|
8
|
+
export declare function resolveTickVals(scale: AnyScale, ticks?: TicksConfig, count?: number): any[];
|
|
9
|
+
export declare function resolveTickFormat(scale: AnyScale, ticks?: TicksConfig, count?: number, formatType?: FormatType, multiline?: boolean): (date: Date, i: number) => string;
|