layerchart 0.91.1 → 0.92.1
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 +16 -7
- package/dist/components/Brush.svelte +29 -11
- package/package.json +1 -1
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
import { cubicIn } from 'svelte/easing';
|
|
5
5
|
import type { SVGAttributes } from 'svelte/elements';
|
|
6
6
|
import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
|
|
7
|
+
import type { TimeInterval } from 'd3-time';
|
|
7
8
|
|
|
8
9
|
import { extent } from 'd3-array';
|
|
9
10
|
import { pointRadial } from 'd3-shape';
|
|
10
11
|
|
|
11
|
-
import { format as formatValue, type FormatType } from '@layerstack/utils';
|
|
12
|
+
import { format as formatValue, isLiteralObject, type FormatType } from '@layerstack/utils';
|
|
12
13
|
import { cls } from '@layerstack/tailwind';
|
|
13
14
|
import type { TransitionParams } from 'svelte-ux'; // TODO: Replace with `@layerstack/svelte-types` or similar
|
|
14
15
|
|
|
@@ -39,7 +40,13 @@
|
|
|
39
40
|
export let grid: boolean | Pick<SVGAttributes<SVGElement>, 'class' | 'style'> = false;
|
|
40
41
|
|
|
41
42
|
/** Control the number of ticks*/
|
|
42
|
-
export let ticks:
|
|
43
|
+
export let ticks:
|
|
44
|
+
| number
|
|
45
|
+
| any[]
|
|
46
|
+
| ((scale: AnyScale) => any)
|
|
47
|
+
| { interval: TimeInterval | null }
|
|
48
|
+
| null
|
|
49
|
+
| undefined = undefined;
|
|
43
50
|
|
|
44
51
|
/** Length of the tick line */
|
|
45
52
|
export let tickLength = 4;
|
|
@@ -87,11 +94,13 @@
|
|
|
87
94
|
? ticks
|
|
88
95
|
: typeof ticks === 'function'
|
|
89
96
|
? ticks(_scale)
|
|
90
|
-
:
|
|
91
|
-
? ticks
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
: isLiteralObject(ticks)
|
|
98
|
+
? _scale.ticks(ticks.interval) // d3-time interval such as `timeDay.every(1)`
|
|
99
|
+
: isScaleBand(_scale)
|
|
100
|
+
? ticks
|
|
101
|
+
? _scale.domain().filter((v: any, i: number) => i % ticks === 0)
|
|
102
|
+
: _scale.domain()
|
|
103
|
+
: _scale.ticks(ticks ?? (placement === 'left' || placement === 'right' ? 4 : undefined));
|
|
95
104
|
|
|
96
105
|
function getCoords(tick: any) {
|
|
97
106
|
switch (placement) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { extent, min, max } from 'd3-array';
|
|
4
4
|
import { clamp } from '@layerstack/utils';
|
|
5
5
|
import { cls } from '@layerstack/tailwind';
|
|
6
|
-
import { format as formatValue, type FormatType } from '@layerstack/utils';
|
|
6
|
+
import { format as formatValue, type FormatType, Logger } from '@layerstack/utils';
|
|
7
7
|
|
|
8
8
|
import { chartContext } from './ChartContext.svelte';
|
|
9
9
|
import Frame from './Frame.svelte';
|
|
@@ -74,6 +74,9 @@
|
|
|
74
74
|
|
|
75
75
|
let frameEl: SVGRectElement;
|
|
76
76
|
|
|
77
|
+
const logger = new Logger('Brush');
|
|
78
|
+
const RESET_THRESHOLD = 1; // size of pointer delta to ignore
|
|
79
|
+
|
|
77
80
|
function handler(
|
|
78
81
|
fn: (
|
|
79
82
|
start: {
|
|
@@ -85,35 +88,50 @@
|
|
|
85
88
|
) => void
|
|
86
89
|
) {
|
|
87
90
|
return (e: PointerEvent) => {
|
|
91
|
+
const startPoint = localPoint(frameEl, e);
|
|
88
92
|
const start = {
|
|
89
93
|
xDomain: [xDomain?.[0] ?? xDomainMin, xDomain?.[1] ?? xDomainMax] as [number, number],
|
|
90
94
|
yDomain: [yDomain?.[0] ?? yDomainMin, yDomain?.[1] ?? yDomainMax] as [number, number],
|
|
91
95
|
value: {
|
|
92
|
-
x: $xScale.invert?.((
|
|
93
|
-
y: $yScale.invert?.((
|
|
96
|
+
x: $xScale.invert?.((startPoint?.x ?? 0) - $padding.left),
|
|
97
|
+
y: $yScale.invert?.((startPoint?.y ?? 0) - $padding.top),
|
|
94
98
|
},
|
|
95
99
|
};
|
|
96
100
|
|
|
97
101
|
onbrushstart({ xDomain, yDomain });
|
|
98
102
|
|
|
99
103
|
const onPointerMove = (e: PointerEvent) => {
|
|
104
|
+
const currentPoint = localPoint(frameEl, e);
|
|
100
105
|
fn(start, {
|
|
101
|
-
x: $xScale.invert?.((
|
|
102
|
-
y: $yScale.invert?.((
|
|
106
|
+
x: $xScale.invert?.((currentPoint?.x ?? 0) - $padding.left),
|
|
107
|
+
y: $yScale.invert?.((currentPoint?.y ?? 0) - $padding.top),
|
|
103
108
|
});
|
|
104
109
|
|
|
105
|
-
// if (xDomain[0] === xDomain[1] || yDomain[0] === yDomain[1]) {
|
|
106
|
-
// // Ignore?
|
|
107
|
-
// // TODO: What about when using `x` or `y` axis?
|
|
108
|
-
// } else {
|
|
109
110
|
onchange({ xDomain, yDomain });
|
|
110
|
-
// }
|
|
111
111
|
};
|
|
112
112
|
|
|
113
113
|
const onPointerUp = (e: PointerEvent) => {
|
|
114
|
-
|
|
114
|
+
const currentPoint = localPoint(frameEl, e);
|
|
115
|
+
const xPointDelta = Math.abs((startPoint?.x ?? 0) - (currentPoint?.x ?? 0));
|
|
116
|
+
const yPointDelta = Math.abs((startPoint?.y ?? 0) - (currentPoint?.y ?? 0));
|
|
117
|
+
|
|
118
|
+
if (
|
|
119
|
+
(e.target == frameEl && xPointDelta < RESET_THRESHOLD && yPointDelta < RESET_THRESHOLD) ||
|
|
120
|
+
rangeWidth < RESET_THRESHOLD ||
|
|
121
|
+
rangeHeight < RESET_THRESHOLD
|
|
122
|
+
) {
|
|
123
|
+
// Clicked on frame, or pointer delta was <1
|
|
124
|
+
logger.info('resetting due to frame click');
|
|
115
125
|
reset();
|
|
116
126
|
onchange({ xDomain, yDomain });
|
|
127
|
+
} else {
|
|
128
|
+
logger.info('drag', {
|
|
129
|
+
target: e.target,
|
|
130
|
+
xPointDelta,
|
|
131
|
+
yPointDelta,
|
|
132
|
+
rangeWidth,
|
|
133
|
+
rangeHeight,
|
|
134
|
+
});
|
|
117
135
|
}
|
|
118
136
|
|
|
119
137
|
onbrushend({ xDomain, yDomain });
|