layerchart 2.0.0-next.11 → 2.0.0-next.13
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/components/Axis.svelte +2 -2
- package/dist/components/Axis.svelte.d.ts +2 -2
- package/dist/components/Calendar.svelte +2 -2
- package/dist/components/Group.svelte +2 -2
- package/dist/components/Labels.svelte +3 -2
- package/dist/components/Labels.svelte.d.ts +2 -2
- package/dist/components/Legend.svelte +8 -5
- package/dist/components/Legend.svelte.d.ts +3 -3
- package/dist/components/charts/AreaChart.svelte +1 -3
- package/dist/components/charts/BarChart.svelte +2 -9
- package/dist/components/tooltip/TooltipHeader.svelte +5 -4
- package/dist/components/tooltip/TooltipHeader.svelte.d.ts +3 -3
- package/dist/components/tooltip/TooltipItem.svelte +5 -4
- package/dist/components/tooltip/TooltipItem.svelte.d.ts +3 -3
- package/dist/components/tooltip/tooltipMetaContext.d.ts +2 -2
- package/dist/utils/ticks.d.ts +2 -2
- package/dist/utils/ticks.js +21 -21
- package/package.json +5 -5
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
/**
|
|
72
72
|
* Format tick labels
|
|
73
73
|
*/
|
|
74
|
-
format?: FormatType;
|
|
74
|
+
format?: FormatType | FormatConfig;
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
77
|
* Props to apply to each tick label
|
|
@@ -126,7 +126,7 @@
|
|
|
126
126
|
import { extent } from 'd3-array';
|
|
127
127
|
import { pointRadial } from 'd3-shape';
|
|
128
128
|
|
|
129
|
-
import { type FormatType } from '@layerstack/utils';
|
|
129
|
+
import { type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
130
130
|
import { cls } from '@layerstack/tailwind';
|
|
131
131
|
|
|
132
132
|
import Group, { type GroupProps } from './Group.svelte';
|
|
@@ -60,7 +60,7 @@ export type AxisPropsWithoutHTML<In extends Transition = Transition> = {
|
|
|
60
60
|
/**
|
|
61
61
|
* Format tick labels
|
|
62
62
|
*/
|
|
63
|
-
format?: FormatType;
|
|
63
|
+
format?: FormatType | FormatConfig;
|
|
64
64
|
/**
|
|
65
65
|
* Props to apply to each tick label
|
|
66
66
|
*/
|
|
@@ -102,7 +102,7 @@ export type AxisPropsWithoutHTML<In extends Transition = Transition> = {
|
|
|
102
102
|
export type AxisProps<In extends Transition = Transition> = AxisPropsWithoutHTML<In> & Without<GroupProps, AxisPropsWithoutHTML<In>>;
|
|
103
103
|
import { type ComponentProps, type Snippet } from 'svelte';
|
|
104
104
|
import type { SVGAttributes } from 'svelte/elements';
|
|
105
|
-
import { type FormatType } from '@layerstack/utils';
|
|
105
|
+
import { type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
106
106
|
import { type GroupProps } from './Group.svelte';
|
|
107
107
|
import Rule from './Rule.svelte';
|
|
108
108
|
import Text from './Text.svelte';
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
import { type ComponentProps, type Snippet } from 'svelte';
|
|
58
58
|
import { timeDays, timeMonths, timeWeek, timeYear } from 'd3-time';
|
|
59
59
|
import { index } from 'd3-array';
|
|
60
|
-
import { format } from '
|
|
60
|
+
import { format } from '@layerstack/utils';
|
|
61
61
|
|
|
62
62
|
import Rect, { type RectPropsWithoutHTML } from './Rect.svelte';
|
|
63
63
|
import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
|
|
@@ -140,7 +140,7 @@
|
|
|
140
140
|
<Text
|
|
141
141
|
x={timeWeek.count(timeYear.floor(date), timeWeek.ceil(date)) * cellSize[0]}
|
|
142
142
|
y={-4}
|
|
143
|
-
value={format(date, '
|
|
143
|
+
value={format(date, 'month', { variant: 'short' })}
|
|
144
144
|
{...extractLayerProps(monthLabel, 'calendar-month-label', 'text-xs')}
|
|
145
145
|
/>
|
|
146
146
|
{/each}
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
initialY: initialYProp,
|
|
101
101
|
center = false,
|
|
102
102
|
preventTouchMove = false,
|
|
103
|
-
opacity =
|
|
103
|
+
opacity = undefined,
|
|
104
104
|
motion,
|
|
105
105
|
transitionIn: transitionInProp,
|
|
106
106
|
transitionInParams: transitionInParamsProp,
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
name: 'Group',
|
|
145
145
|
render: (ctx) => {
|
|
146
146
|
const currentGlobalAlpha = ctx.globalAlpha;
|
|
147
|
-
ctx.globalAlpha = opacity;
|
|
147
|
+
ctx.globalAlpha = opacity ?? 1;
|
|
148
148
|
|
|
149
149
|
ctx.translate(motionX.current ?? 0, motionY.current ?? 0);
|
|
150
150
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
2
|
import Text, { type TextProps } from './Text.svelte';
|
|
3
3
|
import { type ComponentProps, type Snippet } from 'svelte';
|
|
4
|
-
import { format as formatValue, type FormatType } from '@layerstack/utils';
|
|
4
|
+
import { format as formatValue, type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
5
5
|
import type { Without } from '../utils/types.js';
|
|
6
6
|
import Points, { type Point } from './Points.svelte';
|
|
7
7
|
import { accessor, type Accessor } from '../utils/common.js';
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
/**
|
|
52
52
|
* The format of the label
|
|
53
53
|
*/
|
|
54
|
-
format?: FormatType;
|
|
54
|
+
format?: FormatType | FormatConfig;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* Define unique value for {#each} `(key)` expressions to improve transitions.
|
|
@@ -109,6 +109,7 @@
|
|
|
109
109
|
|
|
110
110
|
const formattedValue = formatValue(
|
|
111
111
|
displayValue,
|
|
112
|
+
// @ts-expect-error - improve types
|
|
112
113
|
format ??
|
|
113
114
|
(value
|
|
114
115
|
? undefined
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Text, { type TextProps } from './Text.svelte';
|
|
2
2
|
import { type ComponentProps, type Snippet } from 'svelte';
|
|
3
|
-
import { type FormatType } from '@layerstack/utils';
|
|
3
|
+
import { type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
4
4
|
import type { Without } from '../utils/types.js';
|
|
5
5
|
import { type Point } from './Points.svelte';
|
|
6
6
|
import { type Accessor } from '../utils/common.js';
|
|
@@ -42,7 +42,7 @@ export type LabelsPropsWithoutHTML<T = any> = {
|
|
|
42
42
|
/**
|
|
43
43
|
* The format of the label
|
|
44
44
|
*/
|
|
45
|
-
format?: FormatType;
|
|
45
|
+
format?: FormatType | FormatConfig;
|
|
46
46
|
/**
|
|
47
47
|
* Define unique value for {#each} `(key)` expressions to improve transitions.
|
|
48
48
|
* `index` position used by default
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import type { Placement } from './types.js';
|
|
4
|
-
import type
|
|
4
|
+
import { asAny, type Without } from '../utils/types.js';
|
|
5
5
|
|
|
6
6
|
export type LegendItem = {
|
|
7
7
|
value: any;
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
* @default width / 64
|
|
38
38
|
*/
|
|
39
39
|
ticks?: number;
|
|
40
|
-
tickFormat?: FormatType;
|
|
40
|
+
tickFormat?: FormatType | FormatConfig;
|
|
41
41
|
tickValues?: any[];
|
|
42
42
|
/**
|
|
43
43
|
* The font size of the tick labels.
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
import { scaleBand, scaleLinear } from 'd3-scale';
|
|
111
111
|
import { quantize, interpolate, interpolateRound } from 'd3-interpolate';
|
|
112
112
|
import { quantile, range } from 'd3-array';
|
|
113
|
-
import { format, type FormatType } from '@layerstack/utils';
|
|
113
|
+
import { format, type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
114
114
|
|
|
115
115
|
import ColorRamp from './ColorRamp.svelte';
|
|
116
116
|
import { cls } from '@layerstack/tailwind';
|
|
@@ -245,6 +245,7 @@
|
|
|
245
245
|
const tickValues = range(thresholds.length);
|
|
246
246
|
const tickFormat = (i: number) => {
|
|
247
247
|
const value = thresholds[i];
|
|
248
|
+
// @ts-expect-error - improve types
|
|
248
249
|
return tickFormatProp ? format(value, tickFormatProp) : value;
|
|
249
250
|
};
|
|
250
251
|
|
|
@@ -360,7 +361,8 @@
|
|
|
360
361
|
classes.label
|
|
361
362
|
)}
|
|
362
363
|
>
|
|
363
|
-
|
|
364
|
+
<!-- @ts-expect-error - improve types -->
|
|
365
|
+
{tickFormatProp ? format(tick, asAny(tickFormatProp)) : tick}
|
|
364
366
|
</text>
|
|
365
367
|
|
|
366
368
|
{#if scaleConfig.tickLine}
|
|
@@ -409,7 +411,8 @@
|
|
|
409
411
|
classes.label
|
|
410
412
|
)}
|
|
411
413
|
>
|
|
412
|
-
|
|
414
|
+
<!-- @ts-expect-error - improve types -->
|
|
415
|
+
{tickFormatProp ? format(tick, asAny(tickFormatProp)) : tick}
|
|
413
416
|
</div>
|
|
414
417
|
</button>
|
|
415
418
|
{/each}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { Placement } from './types.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type Without } from '../utils/types.js';
|
|
4
4
|
export type LegendItem = {
|
|
5
5
|
value: any;
|
|
6
6
|
color: string;
|
|
@@ -30,7 +30,7 @@ export type LegendPropsWithoutHTML = {
|
|
|
30
30
|
* @default width / 64
|
|
31
31
|
*/
|
|
32
32
|
ticks?: number;
|
|
33
|
-
tickFormat?: FormatType;
|
|
33
|
+
tickFormat?: FormatType | FormatConfig;
|
|
34
34
|
tickValues?: any[];
|
|
35
35
|
/**
|
|
36
36
|
* The font size of the tick labels.
|
|
@@ -90,7 +90,7 @@ export type LegendPropsWithoutHTML = {
|
|
|
90
90
|
};
|
|
91
91
|
export type LegendProps = LegendPropsWithoutHTML & Without<HTMLAttributes<HTMLElement>, LegendPropsWithoutHTML>;
|
|
92
92
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
93
|
-
import { type FormatType } from '@layerstack/utils';
|
|
93
|
+
import { type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
94
94
|
import type { AnyScale } from '../utils/scales.svelte.js';
|
|
95
95
|
declare const Legend: import("svelte").Component<LegendProps, {}, "ref">;
|
|
96
96
|
type Legend = ReturnType<typeof Legend>;
|
|
@@ -69,7 +69,6 @@
|
|
|
69
69
|
import { onMount, type ComponentProps } from 'svelte';
|
|
70
70
|
import { scaleLinear, scaleTime } from 'd3-scale';
|
|
71
71
|
import { stack, stackOffsetDiverging, stackOffsetExpand, stackOffsetNone } from 'd3-shape';
|
|
72
|
-
import { format } from '@layerstack/utils';
|
|
73
72
|
import { cls } from '@layerstack/tailwind';
|
|
74
73
|
|
|
75
74
|
import Area from '../Area.svelte';
|
|
@@ -398,8 +397,7 @@
|
|
|
398
397
|
if (axisDirection === 'y') {
|
|
399
398
|
return {
|
|
400
399
|
placement: radial ? 'radius' : 'left',
|
|
401
|
-
format:
|
|
402
|
-
seriesLayout === 'stackExpand' ? (value) => format(value, 'percentRound') : undefined,
|
|
400
|
+
format: seriesLayout === 'stackExpand' ? 'percentRound' : undefined,
|
|
403
401
|
...(typeof axis === 'object' ? axis : null),
|
|
404
402
|
...props.yAxis,
|
|
405
403
|
};
|
|
@@ -86,7 +86,6 @@
|
|
|
86
86
|
import { onMount, type ComponentProps } from 'svelte';
|
|
87
87
|
import { scaleBand, scaleLinear, scaleTime } from 'd3-scale';
|
|
88
88
|
import { stack, stackOffsetDiverging, stackOffsetExpand, stackOffsetNone } from 'd3-shape';
|
|
89
|
-
import { format } from '@layerstack/utils';
|
|
90
89
|
import { cls } from '@layerstack/tailwind';
|
|
91
90
|
|
|
92
91
|
import Axis from '../Axis.svelte';
|
|
@@ -365,20 +364,14 @@
|
|
|
365
364
|
return {
|
|
366
365
|
placement: radial ? 'radius' : 'left',
|
|
367
366
|
|
|
368
|
-
format:
|
|
369
|
-
isVertical && seriesLayout === 'stackExpand'
|
|
370
|
-
? (value) => format(value, 'percentRound')
|
|
371
|
-
: undefined,
|
|
367
|
+
format: isVertical && seriesLayout === 'stackExpand' ? 'percentRound' : undefined,
|
|
372
368
|
...(typeof axis === 'object' ? axis : null),
|
|
373
369
|
...props.yAxis,
|
|
374
370
|
};
|
|
375
371
|
}
|
|
376
372
|
return {
|
|
377
373
|
placement: radial ? 'angle' : 'bottom',
|
|
378
|
-
format:
|
|
379
|
-
!isVertical && seriesLayout === 'stackExpand'
|
|
380
|
-
? (value) => format(value, 'percentRound')
|
|
381
|
-
: undefined,
|
|
374
|
+
format: !isVertical && seriesLayout === 'stackExpand' ? 'percentRound' : undefined,
|
|
382
375
|
...(typeof axis === 'object' ? axis : null),
|
|
383
376
|
...props.xAxis,
|
|
384
377
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
import type { Snippet } from 'svelte';
|
|
4
|
-
import type
|
|
4
|
+
import { asAny, type Without } from '../../utils/types.js';
|
|
5
5
|
|
|
6
6
|
export type TooltipHeaderPropsWithoutHTML = {
|
|
7
7
|
/**
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
/**
|
|
14
14
|
* The format to use when displaying the value.
|
|
15
15
|
*/
|
|
16
|
-
format?: FormatType;
|
|
16
|
+
format?: FormatType | FormatConfig;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* The color to use for the color dot.
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
</script>
|
|
55
55
|
|
|
56
56
|
<script lang="ts">
|
|
57
|
-
import { format as formatUtil, type FormatType } from '@layerstack/utils';
|
|
57
|
+
import { format as formatUtil, type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
58
58
|
import { cls } from '@layerstack/tailwind';
|
|
59
59
|
import { layerClass } from '../../utils/attributes.js';
|
|
60
60
|
|
|
@@ -114,6 +114,7 @@
|
|
|
114
114
|
{#if children}
|
|
115
115
|
{@render children?.()}
|
|
116
116
|
{:else}
|
|
117
|
-
|
|
117
|
+
<!-- @ts-expect-error - improve types -->
|
|
118
|
+
{format ? formatUtil(value, asAny(format)) : value}
|
|
118
119
|
{/if}
|
|
119
120
|
</div>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
|
-
import type
|
|
3
|
+
import { type Without } from '../../utils/types.js';
|
|
4
4
|
export type TooltipHeaderPropsWithoutHTML = {
|
|
5
5
|
/**
|
|
6
6
|
* The value to display in the tooltip header when the `children`
|
|
@@ -10,7 +10,7 @@ export type TooltipHeaderPropsWithoutHTML = {
|
|
|
10
10
|
/**
|
|
11
11
|
* The format to use when displaying the value.
|
|
12
12
|
*/
|
|
13
|
-
format?: FormatType;
|
|
13
|
+
format?: FormatType | FormatConfig;
|
|
14
14
|
/**
|
|
15
15
|
* The color to use for the color dot.
|
|
16
16
|
*/
|
|
@@ -40,7 +40,7 @@ export type TooltipHeaderPropsWithoutHTML = {
|
|
|
40
40
|
children?: Snippet;
|
|
41
41
|
};
|
|
42
42
|
export type TooltipHeaderProps = TooltipHeaderPropsWithoutHTML & Without<HTMLAttributes<HTMLElement>, TooltipHeaderPropsWithoutHTML>;
|
|
43
|
-
import { type FormatType } from '@layerstack/utils';
|
|
43
|
+
import { type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
44
44
|
declare const TooltipHeader: import("svelte").Component<TooltipHeaderProps, {}, "ref" | "colorRef">;
|
|
45
45
|
type TooltipHeader = ReturnType<typeof TooltipHeader>;
|
|
46
46
|
export default TooltipHeader;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
-
import type
|
|
3
|
+
import { asAny, type Without } from '../../utils/types.js';
|
|
4
4
|
|
|
5
5
|
export type TooltipItemPropsWithoutHTML = {
|
|
6
6
|
/**
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
/**
|
|
17
17
|
* Format to use when displaying the value.
|
|
18
18
|
*/
|
|
19
|
-
format?: FormatType;
|
|
19
|
+
format?: FormatType | FormatConfig;
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Alignment of the value.
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
</script>
|
|
76
76
|
|
|
77
77
|
<script lang="ts">
|
|
78
|
-
import { format as formatUtil, type FormatType } from '@layerstack/utils';
|
|
78
|
+
import { format as formatUtil, type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
79
79
|
import { cls } from '@layerstack/tailwind';
|
|
80
80
|
import type { Snippet } from 'svelte';
|
|
81
81
|
import { layerClass } from '../../utils/attributes.js';
|
|
@@ -189,7 +189,8 @@
|
|
|
189
189
|
{#if children}
|
|
190
190
|
{@render children()}
|
|
191
191
|
{:else}
|
|
192
|
-
|
|
192
|
+
<!-- @ts-expect-error - improve types -->
|
|
193
|
+
{format ? formatUtil(value, asAny(format)) : value}
|
|
193
194
|
{/if}
|
|
194
195
|
</div>
|
|
195
196
|
</div>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
|
-
import type
|
|
2
|
+
import { type Without } from '../../utils/types.js';
|
|
3
3
|
export type TooltipItemPropsWithoutHTML = {
|
|
4
4
|
/**
|
|
5
5
|
* The label to display in the tooltip item.
|
|
@@ -13,7 +13,7 @@ export type TooltipItemPropsWithoutHTML = {
|
|
|
13
13
|
/**
|
|
14
14
|
* Format to use when displaying the value.
|
|
15
15
|
*/
|
|
16
|
-
format?: FormatType;
|
|
16
|
+
format?: FormatType | FormatConfig;
|
|
17
17
|
/**
|
|
18
18
|
* Alignment of the value.
|
|
19
19
|
*
|
|
@@ -59,7 +59,7 @@ export type TooltipItemPropsWithoutHTML = {
|
|
|
59
59
|
colorRef?: HTMLElement;
|
|
60
60
|
};
|
|
61
61
|
export type TooltipItemProps = TooltipItemPropsWithoutHTML & Without<HTMLAttributes<HTMLElement>, TooltipItemPropsWithoutHTML>;
|
|
62
|
-
import { type FormatType } from '@layerstack/utils';
|
|
62
|
+
import { type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
63
63
|
import type { Snippet } from 'svelte';
|
|
64
64
|
declare const TooltipItem: import("svelte").Component<TooltipItemProps, {}, "ref" | "colorRef" | "labelRef" | "valueRef">;
|
|
65
65
|
type TooltipItem = ReturnType<typeof TooltipItem>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Accessor } from '../../utils/common.js';
|
|
2
2
|
import type { SeriesData } from '../charts/index.js';
|
|
3
3
|
import type { ChartContextValue } from '../Chart.svelte';
|
|
4
|
-
import { type FormatType } from '@layerstack/utils';
|
|
4
|
+
import { type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
5
5
|
export type SimplifiedChartType = 'bar' | 'area' | 'line' | 'pie' | 'scatter';
|
|
6
6
|
export type BarTooltipMetaContextValue = {
|
|
7
7
|
type: 'bar';
|
|
@@ -52,7 +52,7 @@ export type TooltipPayload = {
|
|
|
52
52
|
chartType?: SimplifiedChartType;
|
|
53
53
|
payload: any;
|
|
54
54
|
rawSeriesData?: SeriesData<any, any>;
|
|
55
|
-
formatter?: FormatType;
|
|
55
|
+
formatter?: FormatType | FormatConfig;
|
|
56
56
|
};
|
|
57
57
|
type BasePayloadHandlerProps = {
|
|
58
58
|
ctx: ChartContextValue;
|
package/dist/utils/ticks.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type TimeInterval } from 'd3-time';
|
|
2
|
-
import { Duration, type FormatType } from '@layerstack/utils';
|
|
2
|
+
import { Duration, type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
3
3
|
import { type AnyScale } from './scales.svelte.js';
|
|
4
4
|
export declare function getDurationFormat(duration: Duration, multiline?: boolean): (date: Date, i: number) => string;
|
|
5
5
|
export type TicksConfig = number | any[] | ((scale: AnyScale) => any[] | undefined) | {
|
|
6
6
|
interval: TimeInterval | null;
|
|
7
7
|
} | null;
|
|
8
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;
|
|
9
|
+
export declare function resolveTickFormat(scale: AnyScale, ticks?: TicksConfig, count?: number, formatType?: FormatType | FormatConfig, multiline?: boolean): (date: Date, i: number) => string;
|
package/dist/utils/ticks.js
CHANGED
|
@@ -1,69 +1,68 @@
|
|
|
1
1
|
import { timeYear, timeMonth, timeDay, timeTicks } from 'd3-time';
|
|
2
|
-
import { format,
|
|
2
|
+
import { format, Duration, isLiteralObject, DateToken, } from '@layerstack/utils';
|
|
3
3
|
import { isScaleBand, isScaleTime } from './scales.svelte.js';
|
|
4
4
|
export function getDurationFormat(duration, multiline = false) {
|
|
5
5
|
return function (date, i) {
|
|
6
6
|
if (+duration >= +new Duration({ duration: { years: 1 } })) {
|
|
7
7
|
// Year
|
|
8
|
-
return format(date,
|
|
8
|
+
return format(date, 'year');
|
|
9
9
|
}
|
|
10
10
|
else if (+duration >= +new Duration({ duration: { days: 28 } })) {
|
|
11
11
|
// Month
|
|
12
12
|
const isFirst = i === 0 || +timeYear.floor(date) === +date;
|
|
13
13
|
if (multiline) {
|
|
14
|
-
return (format(date,
|
|
15
|
-
(isFirst ? `\n${format(date, PeriodType.CalendarYear)}` : ''));
|
|
14
|
+
return (format(date, 'month', { variant: 'short' }) + (isFirst ? `\n${format(date, 'year')}` : ''));
|
|
16
15
|
}
|
|
17
16
|
else {
|
|
18
|
-
return (format(date,
|
|
19
|
-
(isFirst ? ` '${format(date,
|
|
17
|
+
return (format(date, 'month', { variant: 'short' }) +
|
|
18
|
+
(isFirst ? ` '${format(date, 'year', { variant: 'short' })}` : ''));
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
else if (+duration >= +new Duration({ duration: { days: 1 } })) {
|
|
23
22
|
// Day
|
|
24
|
-
const isFirst = i === 0 || date.getDate()
|
|
23
|
+
const isFirst = i === 0 || date.getDate() <= duration.days;
|
|
25
24
|
if (multiline) {
|
|
26
|
-
return (format(date,
|
|
27
|
-
(isFirst ? `\n${format(date,
|
|
25
|
+
return (format(date, 'custom', { custom: DateToken.DayOfMonth_numeric }) +
|
|
26
|
+
(isFirst ? `\n${format(date, 'month', { variant: 'short' })}` : ''));
|
|
28
27
|
}
|
|
29
28
|
else {
|
|
30
|
-
return format(date,
|
|
29
|
+
return format(date, 'day', { variant: 'short' });
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
else if (+duration >= +new Duration({ duration: { hours: 1 } })) {
|
|
34
33
|
// Hours
|
|
35
34
|
const isFirst = i === 0 || +timeDay.floor(date) === +date;
|
|
36
35
|
if (multiline) {
|
|
37
|
-
return (format(date,
|
|
38
|
-
(isFirst ? `\n${format(date,
|
|
36
|
+
return (format(date, 'custom', { custom: DateToken.Hour_numeric }) +
|
|
37
|
+
(isFirst ? `\n${format(date, 'day', { variant: 'short' })}` : ''));
|
|
39
38
|
}
|
|
40
39
|
else {
|
|
41
40
|
return isFirst
|
|
42
|
-
? format(date,
|
|
43
|
-
: format(date,
|
|
41
|
+
? format(date, 'day', { variant: 'short' })
|
|
42
|
+
: format(date, 'custom', { custom: DateToken.Hour_numeric });
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
45
|
else if (+duration >= +new Duration({ duration: { minutes: 1 } })) {
|
|
47
46
|
// Minutes
|
|
48
47
|
const isFirst = i === 0 || +timeDay.floor(date) === +date;
|
|
49
48
|
if (multiline) {
|
|
50
|
-
return (format(date,
|
|
51
|
-
(isFirst ? `\n${format(date,
|
|
49
|
+
return (format(date, 'time', { variant: 'short' }) +
|
|
50
|
+
(isFirst ? `\n${format(date, 'day', { variant: 'short' })}` : ''));
|
|
52
51
|
}
|
|
53
52
|
else {
|
|
54
|
-
return format(date,
|
|
53
|
+
return format(date, 'time', { variant: 'short' });
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
56
|
else if (+duration >= +new Duration({ duration: { seconds: 1 } })) {
|
|
58
57
|
// Seconds
|
|
59
58
|
const isFirst = i === 0 || +timeDay.floor(date) === +date;
|
|
60
|
-
return (format(date,
|
|
61
|
-
(multiline && isFirst ? `\n${format(date,
|
|
59
|
+
return (format(date, 'time') +
|
|
60
|
+
(multiline && isFirst ? `\n${format(date, 'day', { variant: 'short' })}` : ''));
|
|
62
61
|
}
|
|
63
62
|
else if (+duration >= +new Duration({ duration: { milliseconds: 1 } })) {
|
|
64
63
|
// Milliseconds
|
|
65
64
|
const isFirst = i === 0 || +timeDay.floor(date) === +date;
|
|
66
|
-
return (format(date,
|
|
65
|
+
return (format(date, 'custom', {
|
|
67
66
|
custom: [
|
|
68
67
|
DateToken.Hour_2Digit,
|
|
69
68
|
DateToken.Minute_2Digit,
|
|
@@ -71,7 +70,7 @@ export function getDurationFormat(duration, multiline = false) {
|
|
|
71
70
|
DateToken.MiliSecond_3,
|
|
72
71
|
DateToken.Hour_woAMPM,
|
|
73
72
|
],
|
|
74
|
-
}) + (multiline && isFirst ? `\n${format(date,
|
|
73
|
+
}) + (multiline && isFirst ? `\n${format(date, 'day', { variant: 'short' })}` : ''));
|
|
75
74
|
}
|
|
76
75
|
else {
|
|
77
76
|
return date.toString();
|
|
@@ -107,6 +106,7 @@ export function resolveTickVals(scale, ticks, count) {
|
|
|
107
106
|
export function resolveTickFormat(scale, ticks, count, formatType, multiline = false) {
|
|
108
107
|
// Explicit format
|
|
109
108
|
if (formatType) {
|
|
109
|
+
// @ts-expect-error - improve types
|
|
110
110
|
return (tick) => format(tick, formatType);
|
|
111
111
|
}
|
|
112
112
|
// Time scale
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"author": "Sean Lynch <techniq35@gmail.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "techniq/layerchart",
|
|
7
|
-
"version": "2.0.0-next.
|
|
7
|
+
"version": "2.0.0-next.13",
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@changesets/cli": "^2.29.4",
|
|
10
10
|
"@iconify-json/lucide": "^1.2.44",
|
|
@@ -72,10 +72,10 @@
|
|
|
72
72
|
"type": "module",
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@dagrejs/dagre": "^1.1.4",
|
|
75
|
-
"@layerstack/svelte-actions": "1.0.1-next.
|
|
76
|
-
"@layerstack/svelte-state": "0.1.0-next.
|
|
77
|
-
"@layerstack/tailwind": "2.0.0-next.
|
|
78
|
-
"@layerstack/utils": "2.0.0-next.
|
|
75
|
+
"@layerstack/svelte-actions": "1.0.1-next.4",
|
|
76
|
+
"@layerstack/svelte-state": "0.1.0-next.9",
|
|
77
|
+
"@layerstack/tailwind": "2.0.0-next.6",
|
|
78
|
+
"@layerstack/utils": "2.0.0-next.6",
|
|
79
79
|
"d3-array": "^3.2.4",
|
|
80
80
|
"d3-color": "^3.1.0",
|
|
81
81
|
"d3-delaunay": "^6.0.4",
|