@dou-ui/chart 0.1.0-alpha.2 → 0.1.0-alpha.21
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/core/bar.js +69 -19
- package/dist/core/bar.js.map +1 -1
- package/dist/core/box.js +1 -1
- package/dist/core/box.js.map +1 -1
- package/dist/core/waterfall.js +2 -2
- package/dist/core/waterfall.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/core/bar.d.ts +8 -2
- package/dist/zoom-layer.js.map +1 -1
- package/dist/zoom-layer.vue_vue_type_script_setup_true_lang.js +58 -10
- package/dist/zoom-layer.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/package.json +2 -2
package/dist/core/bar.js
CHANGED
|
@@ -12,15 +12,24 @@ var GAP = 2;
|
|
|
12
12
|
/** Below this width (px), bars are drawn one column of pixels at a time. */
|
|
13
13
|
var DENSE = 1.5;
|
|
14
14
|
/**
|
|
15
|
+
* Bands narrower than this (px) are filled by their bars, edge to edge: a
|
|
16
|
+
* pixel of room now and then between them would show as stripes.
|
|
17
|
+
*/
|
|
18
|
+
var SOLID = 2;
|
|
19
|
+
/**
|
|
15
20
|
* Where a series' bars go in each x band: the offset of their near edge
|
|
16
|
-
* from the band's center,
|
|
21
|
+
* from the band's center, their width, and the room left between the
|
|
22
|
+
* bars of one band and the next, in px. The room grows with the band,
|
|
23
|
+
* from none below 2px to its full share from 12px, so zooming through
|
|
24
|
+
* never changes the look at once.
|
|
17
25
|
*/
|
|
18
26
|
function barPlacement(band, slot) {
|
|
19
27
|
const { index, count } = slot ?? {
|
|
20
28
|
index: 0,
|
|
21
29
|
count: 1
|
|
22
30
|
};
|
|
23
|
-
|
|
31
|
+
const spaced = Math.min(1, Math.max(0, (band - SOLID) / 10));
|
|
32
|
+
let group = band * (1 - (1 - (count > 1 ? GROUPED : SINGLE)) * spaced);
|
|
24
33
|
let gap = count > 1 && group / count >= 8 ? GAP : 0;
|
|
25
34
|
let width = (group - gap * (count - 1)) / count;
|
|
26
35
|
if (width > MAX_WIDTH) {
|
|
@@ -30,7 +39,8 @@ function barPlacement(band, slot) {
|
|
|
30
39
|
}
|
|
31
40
|
return {
|
|
32
41
|
offset: -group / 2 + index * (width + gap),
|
|
33
|
-
width
|
|
42
|
+
width,
|
|
43
|
+
room: band - group
|
|
34
44
|
};
|
|
35
45
|
}
|
|
36
46
|
/**
|
|
@@ -38,7 +48,9 @@ function barPlacement(band, slot) {
|
|
|
38
48
|
* The end away from 0 is rounded; in a stack, only the outermost slice's.
|
|
39
49
|
* Bars narrower than a pixel and a half are merged per pixel column into
|
|
40
50
|
* one bar from the lowest to the highest value there, which looks the
|
|
41
|
-
* same and keeps a million bars as cheap as a few hundred.
|
|
51
|
+
* same and keeps a million bars as cheap as a few hundred. The room between
|
|
52
|
+
* bars is a whole number of pixels, and narrows with the bands down to
|
|
53
|
+
* none (square, slices touching), so hundreds of days read as one even shape.
|
|
42
54
|
*/
|
|
43
55
|
function drawBars(painter, series, view, placement = barPlacement(view.band, series.slot)) {
|
|
44
56
|
const { x: sx, y: sy, dpr, horizontal } = view;
|
|
@@ -59,8 +71,35 @@ function drawBars(painter, series, view, placement = barPlacement(view.band, ser
|
|
|
59
71
|
let column = NaN;
|
|
60
72
|
let lo = 0;
|
|
61
73
|
let hi = 0;
|
|
74
|
+
let tallest = -1;
|
|
75
|
+
let row = -1;
|
|
62
76
|
const flush = () => {
|
|
63
|
-
if (column
|
|
77
|
+
if (column !== column) return;
|
|
78
|
+
if (ends && row >= 0) {
|
|
79
|
+
const v1 = sy.map(top[row]);
|
|
80
|
+
const v0 = base ? sy.map(base[row]) : zero;
|
|
81
|
+
lo = Math.min(v0, v1);
|
|
82
|
+
hi = Math.max(v0, v1);
|
|
83
|
+
}
|
|
84
|
+
if (hi > lo) rect(column, column + 1, lo, hi);
|
|
85
|
+
};
|
|
86
|
+
const add = (c, i, a, b) => {
|
|
87
|
+
const extent = ends ? ends.up[i] - ends.down[i] : 0;
|
|
88
|
+
if (c !== column) {
|
|
89
|
+
flush();
|
|
90
|
+
column = c;
|
|
91
|
+
lo = a;
|
|
92
|
+
hi = b;
|
|
93
|
+
tallest = extent;
|
|
94
|
+
row = i;
|
|
95
|
+
} else {
|
|
96
|
+
lo = Math.min(lo, a);
|
|
97
|
+
hi = Math.max(hi, b);
|
|
98
|
+
if (extent > tallest) {
|
|
99
|
+
tallest = extent;
|
|
100
|
+
row = i;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
64
103
|
};
|
|
65
104
|
for (let i = from; i < to; i++) {
|
|
66
105
|
const value = top[i];
|
|
@@ -68,23 +107,26 @@ function drawBars(painter, series, view, placement = barPlacement(view.band, ser
|
|
|
68
107
|
if (value !== value || x !== x || log && !(value > 0)) continue;
|
|
69
108
|
const v1 = sy.map(value);
|
|
70
109
|
const v0 = base ? sy.map(base[i]) : zero;
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
lo = Math.min(lo, v0, v1);
|
|
79
|
-
hi = Math.max(hi, v0, v1);
|
|
80
|
-
}
|
|
110
|
+
const a = Math.min(v0, v1);
|
|
111
|
+
const b = Math.max(v0, v1);
|
|
112
|
+
const left = sx.map(x) + offset;
|
|
113
|
+
const first = Math.ceil(left - .5) + 0;
|
|
114
|
+
const last = Math.ceil(left + width - .5);
|
|
115
|
+
if (last <= first) add(Math.floor(left + width / 2), i, a, b);
|
|
116
|
+
else for (let c = first; c < last; c++) add(c, i, a, b);
|
|
81
117
|
}
|
|
82
118
|
flush();
|
|
83
119
|
painter.fill();
|
|
84
120
|
painter.restore();
|
|
85
121
|
return;
|
|
86
122
|
}
|
|
87
|
-
const
|
|
123
|
+
const count = series.slot?.count ?? 1;
|
|
124
|
+
const room = Math.round(Math.max(0, view.band - placement.width * count) * dpr) / dpr;
|
|
125
|
+
const single = count === 1;
|
|
126
|
+
const radius = Math.min(Math.max(0, series.props.radius ?? 2), room * 2);
|
|
127
|
+
const parted = room >= 2;
|
|
128
|
+
const across = Math.max(1 / dpr, Math.round(width * dpr) / dpr);
|
|
129
|
+
const half = Math.floor(room * dpr / 2) / dpr;
|
|
88
130
|
const bar = (i) => {
|
|
89
131
|
const value = top[i];
|
|
90
132
|
const x = xs[i];
|
|
@@ -95,12 +137,20 @@ function drawBars(painter, series, view, placement = barPlacement(view.band, ser
|
|
|
95
137
|
}
|
|
96
138
|
const from0 = base ? base[i] : 0;
|
|
97
139
|
if (value === from0) return;
|
|
98
|
-
const
|
|
99
|
-
|
|
140
|
+
const center = sx.map(x);
|
|
141
|
+
let u0;
|
|
142
|
+
let u1;
|
|
143
|
+
if (single) {
|
|
144
|
+
u0 = snap(center - view.band / 2) + half;
|
|
145
|
+
u1 = Math.max(u0 + 1 / dpr, snap(center + view.band / 2) - (room - half));
|
|
146
|
+
} else {
|
|
147
|
+
u0 = snap(center + offset + (width - across) / 2);
|
|
148
|
+
u1 = u0 + across;
|
|
149
|
+
}
|
|
100
150
|
let v0 = base ? sy.map(from0) : zero;
|
|
101
151
|
const v1 = sy.map(value);
|
|
102
152
|
const length = Math.abs(v1 - v0);
|
|
103
|
-
if (base && from0 !== 0 && length > 2) v0 += v1 > v0 ? 1 : -1;
|
|
153
|
+
if (base && from0 !== 0 && length > 2 && parted) v0 += v1 > v0 ? 1 : -1;
|
|
104
154
|
const r = !ends || (value > from0 ? value === ends.up[i] : value === ends.down[i]) ? Math.min(radius, (u1 - u0) / 2, Math.abs(v1 - v0)) : 0;
|
|
105
155
|
if (r < .5) rect(u0, u1, v0, v1);
|
|
106
156
|
else roundedEnd(painter, u0, u1, v0, v1, r, horizontal);
|
package/dist/core/bar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar.js","names":[],"sources":["../../src/core/bar.ts"],"sourcesContent":["import { visibleRange } from './decimate'\nimport type { Painter } from './painter'\nimport { fillPattern } from './pattern'\nimport { baseline } from './scale'\nimport type { ChartLabelAnchor, ChartSeries, ChartSeriesKind, ChartView } from './series'\n\nexport interface BarStyle {\n /** Corner radius of the bar's end, in px. */\n radius?: number\n labelPosition?: 'outside' | 'inside'\n}\n\n/** The part of each x band that a group of bars takes, alone and side by side. */\nconst SINGLE = 0.6\nconst GROUPED = 0.76\n/** The widest a bar gets, in px. */\nconst MAX_WIDTH = 56\n/** The room between bars of a group, in px. */\nconst GAP = 2\n/** Below this width (px), bars are drawn one column of pixels at a time. */\nconst DENSE = 1.5\n\n/**\n * Where a series' bars go in each x band: the offset of their near edge\n * from the band's center, and their width, in px.\n */\nexport function barPlacement(\n band: number,\n slot: { index: number; count: number } | null,\n): { offset: number; width: number } {\n const { index, count } = slot ?? { index: 0, count: 1 }\n let group = band * (count > 1 ? GROUPED : SINGLE)\n let gap = count > 1 && group / count >= GAP * 4 ? GAP : 0\n let width = (group - gap * (count - 1)) / count\n if (width > MAX_WIDTH) {\n width = MAX_WIDTH\n gap = count > 1 ? GAP * 2 : 0\n group = width * count + gap * (count - 1)\n }\n return { offset: -group / 2 + index * (width + gap), width }\n}\n\n/**\n * Draws bars from 0 (or from the slice of the stack below) to each value.\n * The end away from 0 is rounded; in a stack, only the outermost slice's.\n * Bars narrower than a pixel and a half are merged per pixel column into\n * one bar from the lowest to the highest value there, which looks the\n * same and keeps a million bars as cheap as a few hundred.\n */\nexport function drawBars(\n painter: Painter,\n series: ChartSeries<BarStyle>,\n view: ChartView,\n placement = barPlacement(view.band, series.slot),\n) {\n const { x: sx, y: sy, dpr, horizontal } = view\n const xs = series.x.values\n const top = series.top\n const base = series.base\n const ends = series.stackEnds\n const [from, to] = visibleRange(xs, series.x.sorted, sx.domain[0], sx.domain[1])\n const { offset, width } = placement\n const zero = baseline(sy)\n const log = sy.kind === 'log'\n const snap = (v: number) => Math.round(v * dpr) / dpr\n\n // a bar is drawn along `u` (the x axis) and `v` (the value axis); swapped when horizontal\n const rect = (u0: number, u1: number, v0: number, v1: number) =>\n horizontal\n ? painter.rect(Math.min(v0, v1), u0, Math.abs(v1 - v0), u1 - u0)\n : painter.rect(u0, Math.min(v0, v1), u1 - u0, Math.abs(v1 - v0))\n\n painter.save()\n painter.fillStyle = series.color\n painter.beginPath()\n\n if (width < DENSE) {\n // one column per pixel: from the lowest to the highest end of the bars in it\n let column = Number.NaN\n let lo = 0\n let hi = 0\n const flush = () => {\n if (column === column && hi > lo) rect(column, column + 1, lo, hi)\n }\n for (let i = from; i < to; i++) {\n const value = top[i]!\n const x = xs[i]!\n if (value !== value || x !== x || (log && !(value > 0))) continue\n const v1 = sy.map(value)\n const v0 = base ? sy.map(base[i]!) : zero\n const c = Math.floor(sx.map(x) + offset + width / 2)\n if (c !== column) {\n flush()\n column = c\n lo = Math.min(v0, v1)\n hi = Math.max(v0, v1)\n } else {\n lo = Math.min(lo, v0, v1)\n hi = Math.max(hi, v0, v1)\n }\n }\n flush()\n painter.fill()\n painter.restore()\n return\n }\n\n const radius = Math.max(0, series.props.radius ?? 2)\n const bar = (i: number) => {\n const value = top[i]!\n const x = xs[i]!\n if (value !== value || x !== x) return\n // a log axis has no 0 to grow from, nor room for values at or below it\n if (log && !(value > 0)) {\n warnLog()\n return\n }\n const from0 = base ? base[i]! : 0\n if (value === from0) return\n const u0 = snap(sx.map(x) + offset)\n const u1 = Math.max(u0 + 1 / dpr, snap(sx.map(x) + offset + width))\n let v0 = base ? sy.map(from0) : zero\n const v1 = sy.map(value)\n const length = Math.abs(v1 - v0)\n // a slice on another one leaves a hairline of room between them\n if (base && from0 !== 0 && length > 2) v0 += v1 > v0 ? 1 : -1\n const outermost = !ends || (value > from0 ? value === ends.up[i] : value === ends.down[i])\n const r = outermost ? Math.min(radius, (u1 - u0) / 2, Math.abs(v1 - v0)) : 0\n if (r < 0.5) rect(u0, u1, v0, v1)\n else roundedEnd(painter, u0, u1, v0, v1, r, horizontal)\n }\n const own = series.colors\n if (own) {\n // bars of their own color: one shape per color\n const groups = new Map<string, number[]>()\n for (let i = from; i < to; i++) {\n const color = own[i] ?? series.color\n let group = groups.get(color)\n if (!group) groups.set(color, (group = []))\n group.push(i)\n }\n for (const [color, rows] of groups) {\n painter.fillStyle = color\n painter.beginPath()\n for (const i of rows) bar(i)\n painter.fill()\n if (series.pattern) fillPattern(painter, series.pattern, view.plot, view.colors.surface)\n }\n } else {\n for (let i = from; i < to; i++) bar(i)\n painter.fill()\n if (series.pattern) fillPattern(painter, series.pattern, view.plot, view.colors.surface)\n }\n painter.restore()\n}\n\n/** A bar from `v0` to `v1` with the corners at `v1` rounded. */\nfunction roundedEnd(\n painter: Painter,\n u0: number,\n u1: number,\n v0: number,\n v1: number,\n r: number,\n swap: boolean,\n) {\n const p = (u: number, v: number): [number, number] => (swap ? [v, u] : [u, v])\n // the side the corners curve away from: back towards v0\n const back = v1 < v0 ? r : -r\n painter.moveTo(...p(u0, v0))\n painter.lineTo(...p(u0, v1 + back))\n painter.arcTo(...p(u0, v1), ...p(u0 + r, v1), r)\n painter.lineTo(...p(u1 - r, v1))\n painter.arcTo(...p(u1, v1), ...p(u1, v1 + back), r)\n painter.lineTo(...p(u1, v0))\n painter.closePath()\n}\n\nlet logWarned = false\nfunction warnLog() {\n if (process.env.NODE_ENV === 'production' || logWarned) return\n logWarned = true\n console.warn(\n '[@dou-ui/chart] bars on a log axis grow from its start; values at or below 0 are left out.',\n )\n}\n\n/** Bars narrower than this (px) get no labels: they couldn't be told apart. */\nconst LABEL_WIDTH = 8\n\n/**\n * Where bars' labels go: past each bar's end, or in its middle (stacked\n * bars, by default), with the bar to fit in.\n */\nexport function barLabels(\n series: ChartSeries<BarStyle>,\n view: ChartView,\n placement = barPlacement(view.band, series.slot),\n): ChartLabelAnchor[] {\n const { x: sx, y: sy, horizontal } = view\n const { offset, width } = placement\n if (width < LABEL_WIDTH) return []\n const xs = series.x.values\n const top = series.top\n const base = series.base\n const [from, to] = visibleRange(xs, series.x.sorted, sx.domain[0], sx.domain[1])\n const inside =\n (series.props.labelPosition ?? (series.stackEnds ? 'inside' : 'outside')) === 'inside'\n const zero = baseline(sy)\n // past its end, a label may take its bar's share of the x band, no more\n const room = view.band / (series.slot?.count ?? 1)\n const out: ChartLabelAnchor[] = []\n for (let i = from; i < to; i++) {\n const value = top[i]!\n const x = xs[i]!\n if (value !== value || x !== x) continue\n const from0 = base ? base[i]! : 0\n if (value === from0 || (sy.kind === 'log' && !(value > 0))) continue\n const u = sx.map(x) + offset + width / 2\n const v1 = sy.map(value)\n const v0 = base ? sy.map(from0) : zero\n // which way the bar runs on screen: a reversed axis turns it round\n const up = horizontal ? v1 > v0 : v1 < v0\n if (inside) {\n const lo = Math.min(v0, v1)\n const length = Math.abs(v1 - v0)\n const box = horizontal\n ? { x: lo, y: u - width / 2, width: length, height: width }\n : { x: u - width / 2, y: lo, width, height: length }\n const middle = (v0 + v1) / 2\n out.push({\n index: i,\n at: horizontal ? [middle, u] : [u, middle],\n side: 'center',\n box: { ...box, color: series.colors?.[i] ?? series.color },\n })\n } else {\n // past the end away from 0: above a bar going up, below one going down\n const side = horizontal ? (up ? 'right' : 'left') : up ? 'top' : 'bottom'\n out.push({ index: i, at: horizontal ? [v1, u] : [u, v1], side, room })\n }\n }\n return out\n}\n\nexport const barKind: ChartSeriesKind<BarStyle> = {\n type: 'bar',\n zero: true,\n stackable: true,\n band: true,\n draw: drawBars,\n labels: barLabels,\n}\n"],"mappings":";;;;;AAaA,IAAM,SAAS;AACf,IAAM,UAAU;;AAEhB,IAAM,YAAY;;AAElB,IAAM,MAAM;;AAEZ,IAAM,QAAQ;;;;;AAMd,SAAgB,aACd,MACA,MACmC;CACnC,MAAM,EAAE,OAAO,UAAU,QAAQ;EAAE,OAAO;EAAG,OAAO;CAAE;CACtD,IAAI,QAAQ,QAAQ,QAAQ,IAAI,UAAU;CAC1C,IAAI,MAAM,QAAQ,KAAK,QAAQ,SAAS,IAAU,MAAM;CACxD,IAAI,SAAS,QAAQ,OAAO,QAAQ,MAAM;CAC1C,IAAI,QAAQ,WAAW;EACrB,QAAQ;EAC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,MAAM,KAAK,GAAG,IAAI,KAAK;EACvB,MAAM,KAAK,OAAO,GAAG,IAAI,KAAK,IAAI;EAElC,MAAM,KAAK,aAAa,KAAK,KAAK,KAAK;EACvC,IAAI,QAAQ;GACV,MAAM,KAAK,KAAK,IAAI,IAAI,EAAE;GAC1B,MAAM,SAAS,KAAK,IAAI,KAAK,EAAE;GAC/B,MAAM,MAAM,aACR;IAAE,GAAG;IAAI,GAAG,IAAI,QAAQ;IAAG,OAAO;IAAQ,QAAQ;GAAM,IACxD;IAAE,GAAG,IAAI,QAAQ;IAAG,GAAG;IAAI;IAAO,QAAQ;GAAO;GACrD,MAAM,UAAU,KAAK,MAAM;GAC3B,IAAI,KAAK;IACP,OAAO;IACP,IAAI,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,MAAM;IACzC,MAAM;IACN,KAAK;KAAE,GAAG;KAAK,OAAO,OAAO,SAAS,MAAM,OAAO;IAAM;GAC3D,CAAC;EACH,OAAO;GAEL,MAAM,OAAO,aAAc,KAAK,UAAU,SAAU,KAAK,QAAQ;GACjE,IAAI,KAAK;IAAE,OAAO;IAAG,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;IAAG;IAAM;GAAK,CAAC;EACvE;CACF;CACA,OAAO;AACT;AAEA,IAAa,UAAqC;CAChD,MAAM;CACN,MAAM;CACN,WAAW;CACX,MAAM;CACN,MAAM;CACN,QAAQ;AACV"}
|
|
1
|
+
{"version":3,"file":"bar.js","names":[],"sources":["../../src/core/bar.ts"],"sourcesContent":["import { visibleRange } from './decimate'\nimport type { Painter } from './painter'\nimport { fillPattern } from './pattern'\nimport { baseline } from './scale'\nimport type { ChartLabelAnchor, ChartSeries, ChartSeriesKind, ChartView } from './series'\n\nexport interface BarStyle {\n /** Corner radius of the bar's end, in px. */\n radius?: number\n labelPosition?: 'outside' | 'inside'\n}\n\n/** The part of each x band that a group of bars takes, alone and side by side. */\nconst SINGLE = 0.6\nconst GROUPED = 0.76\n/** The widest a bar gets, in px. */\nconst MAX_WIDTH = 56\n/** The room between bars of a group, in px. */\nconst GAP = 2\n/** Below this width (px), bars are drawn one column of pixels at a time. */\nconst DENSE = 1.5\n/**\n * Bands narrower than this (px) are filled by their bars, edge to edge: a\n * pixel of room now and then between them would show as stripes.\n */\nconst SOLID = 2\n/** From this band width (px) on, bars leave their full share of room between them. */\nconst SPACED = 12\n\n/**\n * Where a series' bars go in each x band: the offset of their near edge\n * from the band's center, their width, and the room left between the\n * bars of one band and the next, in px. The room grows with the band,\n * from none below 2px to its full share from 12px, so zooming through\n * never changes the look at once.\n */\nexport function barPlacement(\n band: number,\n slot: { index: number; count: number } | null,\n): { offset: number; width: number; room: number } {\n const { index, count } = slot ?? { index: 0, count: 1 }\n const spaced = Math.min(1, Math.max(0, (band - SOLID) / (SPACED - SOLID)))\n let group = band * (1 - (1 - (count > 1 ? GROUPED : SINGLE)) * spaced)\n let gap = count > 1 && group / count >= GAP * 4 ? GAP : 0\n let width = (group - gap * (count - 1)) / count\n if (width > MAX_WIDTH) {\n width = MAX_WIDTH\n gap = count > 1 ? GAP * 2 : 0\n group = width * count + gap * (count - 1)\n }\n return { offset: -group / 2 + index * (width + gap), width, room: band - group }\n}\n\n/**\n * Draws bars from 0 (or from the slice of the stack below) to each value.\n * The end away from 0 is rounded; in a stack, only the outermost slice's.\n * Bars narrower than a pixel and a half are merged per pixel column into\n * one bar from the lowest to the highest value there, which looks the\n * same and keeps a million bars as cheap as a few hundred. The room between\n * bars is a whole number of pixels, and narrows with the bands down to\n * none (square, slices touching), so hundreds of days read as one even shape.\n */\nexport function drawBars(\n painter: Painter,\n series: ChartSeries<BarStyle>,\n view: ChartView,\n placement: { offset: number; width: number } = barPlacement(view.band, series.slot),\n) {\n const { x: sx, y: sy, dpr, horizontal } = view\n const xs = series.x.values\n const top = series.top\n const base = series.base\n const ends = series.stackEnds\n const [from, to] = visibleRange(xs, series.x.sorted, sx.domain[0], sx.domain[1])\n const { offset, width } = placement\n const zero = baseline(sy)\n const log = sy.kind === 'log'\n const snap = (v: number) => Math.round(v * dpr) / dpr\n\n // a bar is drawn along `u` (the x axis) and `v` (the value axis); swapped when horizontal\n const rect = (u0: number, u1: number, v0: number, v1: number) =>\n horizontal\n ? painter.rect(Math.min(v0, v1), u0, Math.abs(v1 - v0), u1 - u0)\n : painter.rect(u0, Math.min(v0, v1), u1 - u0, Math.abs(v1 - v0))\n\n painter.save()\n painter.fillStyle = series.color\n painter.beginPath()\n\n if (width < DENSE) {\n // one column per pixel: from the lowest to the highest end of the bars in it;\n // a stack's slices all from the day its whole stack is tallest, so they still\n // sit on one another (each slice's own lowest to highest would cover the others)\n let column = Number.NaN\n let lo = 0\n let hi = 0\n let tallest = -1\n let row = -1\n const flush = () => {\n if (column !== column) return\n if (ends && row >= 0) {\n const v1 = sy.map(top[row]!)\n const v0 = base ? sy.map(base[row]!) : zero\n lo = Math.min(v0, v1)\n hi = Math.max(v0, v1)\n }\n if (hi > lo) rect(column, column + 1, lo, hi)\n }\n const add = (c: number, i: number, a: number, b: number) => {\n const extent = ends ? ends.up[i]! - ends.down[i]! : 0\n if (c !== column) {\n flush()\n column = c\n lo = a\n hi = b\n tallest = extent\n row = i\n } else {\n lo = Math.min(lo, a)\n hi = Math.max(hi, b)\n if (extent > tallest) {\n tallest = extent\n row = i\n }\n }\n }\n for (let i = from; i < to; i++) {\n const value = top[i]!\n const x = xs[i]!\n if (value !== value || x !== x || (log && !(value > 0))) continue\n const v1 = sy.map(value)\n const v0 = base ? sy.map(base[i]!) : zero\n const a = Math.min(v0, v1)\n const b = Math.max(v0, v1)\n // the columns whose middles the bar covers; at least the one its middle is in\n const left = sx.map(x) + offset\n // (+ 0: -0.4 rounds up to -0)\n const first = Math.ceil(left - 0.5) + 0\n const last = Math.ceil(left + width - 0.5)\n if (last <= first) add(Math.floor(left + width / 2), i, a, b)\n else for (let c = first; c < last; c++) add(c, i, a, b)\n }\n flush()\n painter.fill()\n painter.restore()\n return\n }\n\n // the room between one band's bars and the next, in whole device pixels: the\n // same everywhere, so it can't come and go in stripes\n const count = series.slot?.count ?? 1\n const room = Math.round(Math.max(0, view.band - placement.width * count) * dpr) / dpr\n const single = count === 1\n // corners round, and stacked slices part, only as the room between bars opens\n const radius = Math.min(Math.max(0, series.props.radius ?? 2), room * 2)\n const parted = room >= 2\n // grouped bars: each the same whole number of pixels wide\n const across = Math.max(1 / dpr, Math.round(width * dpr) / dpr)\n const half = Math.floor((room * dpr) / 2) / dpr\n const bar = (i: number) => {\n const value = top[i]!\n const x = xs[i]!\n if (value !== value || x !== x) return\n // a log axis has no 0 to grow from, nor room for values at or below it\n if (log && !(value > 0)) {\n warnLog()\n return\n }\n const from0 = base ? base[i]! : 0\n if (value === from0) return\n const center = sx.map(x)\n let u0: number\n let u1: number\n if (single) {\n // the band's edges, shared with the next band, less the room between them\n u0 = snap(center - view.band / 2) + half\n u1 = Math.max(u0 + 1 / dpr, snap(center + view.band / 2) - (room - half))\n } else {\n u0 = snap(center + offset + (width - across) / 2)\n u1 = u0 + across\n }\n let v0 = base ? sy.map(from0) : zero\n const v1 = sy.map(value)\n const length = Math.abs(v1 - v0)\n // a slice on another one leaves a hairline of room between them\n if (base && from0 !== 0 && length > 2 && parted) v0 += v1 > v0 ? 1 : -1\n const outermost = !ends || (value > from0 ? value === ends.up[i] : value === ends.down[i])\n const r = outermost ? Math.min(radius, (u1 - u0) / 2, Math.abs(v1 - v0)) : 0\n if (r < 0.5) rect(u0, u1, v0, v1)\n else roundedEnd(painter, u0, u1, v0, v1, r, horizontal)\n }\n const own = series.colors\n if (own) {\n // bars of their own color: one shape per color\n const groups = new Map<string, number[]>()\n for (let i = from; i < to; i++) {\n const color = own[i] ?? series.color\n let group = groups.get(color)\n if (!group) groups.set(color, (group = []))\n group.push(i)\n }\n for (const [color, rows] of groups) {\n painter.fillStyle = color\n painter.beginPath()\n for (const i of rows) bar(i)\n painter.fill()\n if (series.pattern) fillPattern(painter, series.pattern, view.plot, view.colors.surface)\n }\n } else {\n for (let i = from; i < to; i++) bar(i)\n painter.fill()\n if (series.pattern) fillPattern(painter, series.pattern, view.plot, view.colors.surface)\n }\n painter.restore()\n}\n\n/** A bar from `v0` to `v1` with the corners at `v1` rounded. */\nfunction roundedEnd(\n painter: Painter,\n u0: number,\n u1: number,\n v0: number,\n v1: number,\n r: number,\n swap: boolean,\n) {\n const p = (u: number, v: number): [number, number] => (swap ? [v, u] : [u, v])\n // the side the corners curve away from: back towards v0\n const back = v1 < v0 ? r : -r\n painter.moveTo(...p(u0, v0))\n painter.lineTo(...p(u0, v1 + back))\n painter.arcTo(...p(u0, v1), ...p(u0 + r, v1), r)\n painter.lineTo(...p(u1 - r, v1))\n painter.arcTo(...p(u1, v1), ...p(u1, v1 + back), r)\n painter.lineTo(...p(u1, v0))\n painter.closePath()\n}\n\nlet logWarned = false\nfunction warnLog() {\n if (process.env.NODE_ENV === 'production' || logWarned) return\n logWarned = true\n console.warn(\n '[@dou-ui/chart] bars on a log axis grow from its start; values at or below 0 are left out.',\n )\n}\n\n/** Bars narrower than this (px) get no labels: they couldn't be told apart. */\nconst LABEL_WIDTH = 8\n\n/**\n * Where bars' labels go: past each bar's end, or in its middle (stacked\n * bars, by default), with the bar to fit in.\n */\nexport function barLabels(\n series: ChartSeries<BarStyle>,\n view: ChartView,\n placement: { offset: number; width: number } = barPlacement(view.band, series.slot),\n): ChartLabelAnchor[] {\n const { x: sx, y: sy, horizontal } = view\n const { offset, width } = placement\n if (width < LABEL_WIDTH) return []\n const xs = series.x.values\n const top = series.top\n const base = series.base\n const [from, to] = visibleRange(xs, series.x.sorted, sx.domain[0], sx.domain[1])\n const inside =\n (series.props.labelPosition ?? (series.stackEnds ? 'inside' : 'outside')) === 'inside'\n const zero = baseline(sy)\n // past its end, a label may take its bar's share of the x band, no more\n const room = view.band / (series.slot?.count ?? 1)\n const out: ChartLabelAnchor[] = []\n for (let i = from; i < to; i++) {\n const value = top[i]!\n const x = xs[i]!\n if (value !== value || x !== x) continue\n const from0 = base ? base[i]! : 0\n if (value === from0 || (sy.kind === 'log' && !(value > 0))) continue\n const u = sx.map(x) + offset + width / 2\n const v1 = sy.map(value)\n const v0 = base ? sy.map(from0) : zero\n // which way the bar runs on screen: a reversed axis turns it round\n const up = horizontal ? v1 > v0 : v1 < v0\n if (inside) {\n const lo = Math.min(v0, v1)\n const length = Math.abs(v1 - v0)\n const box = horizontal\n ? { x: lo, y: u - width / 2, width: length, height: width }\n : { x: u - width / 2, y: lo, width, height: length }\n const middle = (v0 + v1) / 2\n out.push({\n index: i,\n at: horizontal ? [middle, u] : [u, middle],\n side: 'center',\n box: { ...box, color: series.colors?.[i] ?? series.color },\n })\n } else {\n // past the end away from 0: above a bar going up, below one going down\n const side = horizontal ? (up ? 'right' : 'left') : up ? 'top' : 'bottom'\n out.push({ index: i, at: horizontal ? [v1, u] : [u, v1], side, room })\n }\n }\n return out\n}\n\nexport const barKind: ChartSeriesKind<BarStyle> = {\n type: 'bar',\n zero: true,\n stackable: true,\n band: true,\n draw: drawBars,\n labels: barLabels,\n}\n"],"mappings":";;;;;AAaA,IAAM,SAAS;AACf,IAAM,UAAU;;AAEhB,IAAM,YAAY;;AAElB,IAAM,MAAM;;AAEZ,IAAM,QAAQ;;;;;AAKd,IAAM,QAAQ;;;;;;;;AAWd,SAAgB,aACd,MACA,MACiD;CACjD,MAAM,EAAE,OAAO,UAAU,QAAQ;EAAE,OAAO;EAAG,OAAO;CAAE;CACtD,MAAM,SAAS,KAAK,IAAI,GAAG,KAAK,IAAI,IAAI,OAAO,SAAU,EAAe,CAAC;CACzE,IAAI,QAAQ,QAAQ,KAAK,KAAK,QAAQ,IAAI,UAAU,WAAW;CAC/D,IAAI,MAAM,QAAQ,KAAK,QAAQ,SAAS,IAAU,MAAM;CACxD,IAAI,SAAS,QAAQ,OAAO,QAAQ,MAAM;CAC1C,IAAI,QAAQ,WAAW;EACrB,QAAQ;EACR,MAAM,QAAQ,IAAI,IAAU;EAC5B,QAAQ,QAA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AAG,IAAI,KAAK,IAAI;EAElC,MAAM,KAAK,aAAa,KAAK,KAAK,KAAK;EACvC,IAAI,QAAQ;GACV,MAAM,KAAK,KAAK,IAAI,IAAI,EAAE;GAC1B,MAAM,SAAS,KAAK,IAAI,KAAK,EAAE;GAC/B,MAAM,MAAM,aACR;IAAE,GAAG;IAAI,GAAG,IAAI,QAAQ;IAAG,OAAO;IAAQ,QAAQ;GAAM,IACxD;IAAE,GAAG,IAAI,QAAQ;IAAG,GAAG;IAAI;IAAO,QAAQ;GAAO;GACrD,MAAM,UAAU,KAAK,MAAM;GAC3B,IAAI,KAAK;IACP,OAAO;IACP,IAAI,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,MAAM;IACzC,MAAM;IACN,KAAK;KAAE,GAAG;KAAK,OAAO,OAAO,SAAS,MAAM,OAAO;IAAM;GAC3D,CAAC;EACH,OAAO;GAEL,MAAM,OAAO,aAAc,KAAK,UAAU,SAAU,KAAK,QAAQ;GACjE,IAAI,KAAK;IAAE,OAAO;IAAG,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;IAAG;IAAM;GAAK,CAAC;EACvE;CACF;CACA,OAAO;AACT;AAEA,IAAa,UAAqC;CAChD,MAAM;CACN,MAAM;CACN,WAAW;CACX,MAAM;CACN,MAAM;CACN,QAAQ;AACV"}
|
package/dist/core/box.js
CHANGED
|
@@ -86,7 +86,7 @@ function draw(painter, series, view) {
|
|
|
86
86
|
const u0 = snap(sx.map(x) + offset);
|
|
87
87
|
const u1 = Math.max(u0 + 1, snap(sx.map(x) + offset + width));
|
|
88
88
|
const mid = line((u0 + u1) / 2);
|
|
89
|
-
const cap = Math.max(4, (u1 - u0) / 2);
|
|
89
|
+
const cap = Math.min(Math.max(4, (u1 - u0) / 2), view.band);
|
|
90
90
|
const [q1, q3] = [snap(sy.map(box.q1)), snap(sy.map(box.q3))];
|
|
91
91
|
painter.strokeStyle = color;
|
|
92
92
|
painter.beginPath();
|
package/dist/core/box.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"box.js","names":[],"sources":["../../src/core/box.ts"],"sourcesContent":["import { barPlacement } from './bar'\nimport { read, rowCount, rowOf, type ChartAccessor, type ChartData } from './data'\nimport { visibleRange } from './decimate'\nimport { crisp, type Painter } from './painter'\nimport { warnOnce } from './warn'\nimport type { ChartSeries, ChartSeriesKind, ChartView } from './series'\n\n/*\n * A box plot: for each x, a group of values summed up in five numbers. The\n * box runs from the lower quartile to the upper one with a line at the\n * median; the whiskers reach the farthest values within 1.5 times the box's\n * length of it, and values past them are dots of their own.\n */\n\nexport interface BoxStyle {\n /** How far whiskers reach, in box lengths past the box: `1.5` by default, `Infinity` for all the values. */\n whisker?: number\n}\n\nexport interface BoxStats {\n /** The ends of the whiskers. */\n low: number\n high: number\n q1: number\n median: number\n q3: number\n /** The values past the whiskers. */\n outliers: number[]\n /** How many values there are. */\n count: number\n}\n\n/** The `p`th quantile (0 to 1) of sorted values, between the two nearest. */\nfunction quantile(sorted: number[], p: number): number {\n const at = (sorted.length - 1) * p\n const i = Math.floor(at)\n const next = sorted[Math.min(i + 1, sorted.length - 1)]!\n return sorted[i]! + (next - sorted[i]!) * (at - i)\n}\n\n/** Sums up a group of values; `null` when none is a number. */\nexport function boxStats(values: unknown, whisker = 1.5): BoxStats | null {\n if (!values || typeof (values as ArrayLike<unknown>).length !== 'number') return null\n const list: number[] = []\n for (const v of Array.from(values as ArrayLike<unknown>)) {\n const n = typeof v === 'number' ? v : Number(v)\n if (v != null && v !== '' && Number.isFinite(n)) list.push(n)\n }\n if (!list.length) return null\n list.sort((a, b) => a - b)\n const q1 = quantile(list, 0.25)\n const q3 = quantile(list, 0.75)\n const reach = (q3 - q1) * whisker\n let low = q1\n let high = q3\n const outliers: number[] = []\n for (const v of list) {\n if (v < q1 - reach || v > q3 + reach) outliers.push(v)\n else {\n if (v < low) low = v\n if (v > high) high = v\n }\n }\n return { low, high, q1, median: quantile(list, 0.5), q3, outliers, count: list.length }\n}\n\nconst cache = new WeakMap<object, Map<unknown, Array<BoxStats | null>>>()\n\n/** Each row's numbers, worked out once for the same rows, accessor and whisker. */\nexport function boxesOf(\n rows: ChartData,\n values: ChartAccessor,\n whisker = 1.5,\n): Array<BoxStats | null> {\n let byAccessor = cache.get(rows)\n if (!byAccessor) cache.set(rows, (byAccessor = new Map()))\n const key = `${whisker}`\n let byWhisker = byAccessor.get(values) as unknown as Map<string, Array<BoxStats | null>>\n if (!byWhisker) byAccessor.set(values, (byWhisker = new Map()) as never)\n let out = byWhisker.get(key)\n if (!out) {\n out = []\n const n = rowCount(rows)\n for (let i = 0; i < n; i++) {\n const group = read(rowOf(rows, i), values, i)\n if (group != null && typeof (group as ArrayLike<unknown>).length !== 'number')\n warnOnce(\n 'box-values',\n \"a box plot's `y` gives each row an array of values; other values are left out.\",\n )\n out.push(boxStats(group, whisker))\n }\n byWhisker.set(key, out)\n }\n return out\n}\n\n/** A box plot series' numbers by row. */\nexport const boxes = (series: Pick<ChartSeries<BoxStyle>, 'rows' | 'props'>) =>\n boxesOf(series.rows, series.props.y, series.props.whisker)\n\n/** The radius of an outlier's dot, in px. */\nconst DOT = 2.5\n\nfunction draw(painter: Painter, series: ChartSeries<BoxStyle>, view: ChartView) {\n const { x: sx, y: sy, dpr, horizontal } = view\n const xs = series.x.values\n const list = boxes(series)\n const [from, to] = visibleRange(xs, series.x.sorted, sx.domain[0], sx.domain[1])\n const { offset, width } = barPlacement(view.band, series.slot)\n const snap = (v: number) => Math.round(v * dpr) / dpr\n // a line 1 px wide on whole device pixels\n const line = (v: number) => crisp(v, dpr)\n const p = (u: number, v: number): [number, number] => (horizontal ? [v, u] : [u, v])\n const color = series.color\n\n painter.save()\n painter.lineWidth = 1\n for (let i = from; i < to; i++) {\n const box = list[i]\n const x = xs[i]!\n if (!box || x !== x) continue\n const u0 = snap(sx.map(x) + offset)\n const u1 = Math.max(u0 + 1, snap(sx.map(x) + offset + width))\n const mid = line((u0 + u1) / 2)\n const cap = Math.max(4, (u1 - u0) / 2)\n const [q1, q3] = [snap(sy.map(box.q1)), snap(sy.map(box.q3))]\n // whiskers and their caps\n painter.strokeStyle = color\n painter.beginPath()\n for (const [end, edge] of [\n [box.low, box.q1],\n [box.high, box.q3],\n ] as const) {\n const v = line(sy.map(end))\n painter.moveTo(...p(mid, snap(sy.map(edge))))\n painter.lineTo(...p(mid, v))\n painter.moveTo(...p(mid - cap / 2, v))\n painter.lineTo(...p(mid + cap / 2, v))\n }\n painter.stroke()\n // the box: a light fill, its outline, and the median across it\n const [x0, y0] = p(u0, Math.min(q1, q3))\n const [x1, y1] = p(u1, Math.max(q1, q3))\n const rect = [Math.min(x0, x1), Math.min(y0, y1), Math.abs(x1 - x0), Math.abs(y1 - y0)] as const\n painter.beginPath()\n painter.rect(...rect)\n painter.fillStyle = view.colors.surface\n painter.fill()\n painter.save()\n painter.globalAlpha *= 0.16\n painter.fillStyle = color\n painter.fill()\n painter.restore()\n painter.beginPath()\n painter.rect(rect[0] + 0.5, rect[1] + 0.5, Math.max(0, rect[2] - 1), Math.max(0, rect[3] - 1))\n painter.stroke()\n painter.lineWidth = 2\n painter.beginPath()\n const m = snap(sy.map(box.median))\n painter.moveTo(...p(u0, m))\n painter.lineTo(...p(u1, m))\n painter.stroke()\n painter.lineWidth = 1\n // the values past the whiskers: rings, so many on one spot still show\n if (box.outliers.length) {\n painter.beginPath()\n for (const v of box.outliers) {\n const [cx, cy] = p(mid, sy.map(v))\n painter.moveTo(cx + DOT, cy)\n painter.arc(cx, cy, DOT, 0, Math.PI * 2)\n }\n painter.fillStyle = view.colors.surface\n painter.fill()\n painter.stroke()\n }\n }\n painter.restore()\n}\n\nexport const boxKind: ChartSeriesKind<BoxStyle> = {\n type: 'box',\n box: true,\n band: true,\n draw,\n}\n"],"mappings":";;;;;;;AAiCA,SAAS,SAAS,QAAkB,GAAmB;CACrD,MAAM,MAAM,OAAO,SAAS,KAAK;CACjC,MAAM,IAAI,KA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AK;EACb,QAAQ,eAAe;EACvB,QAAQ,YAAY;EACpB,QAAQ,KAAK;EACb,QAAQ,QAAQ;EAChB,QAAQ,UAAU;EAClB,QAAQ,KAAK,KAAK,KAAK,IAAK,KAAK,KAAK,IAAK,KAAK,IAAI,GAAG,KAAK,KAAK,CAAC,GAAG,KAAK,IAAI,GAAG,KAAK,KAAK,CAAC,CAAC;EAC7F,QAAQ,OAAO;EACf,QAAQ,YAAY;EACpB,QAAQ,UAAU;EAClB,MAAM,IAAI,KAAK,GAAG,IAAI,IAAI,MAAM,CAAC;EACjC,QAAQ,OAAO,GAAG,EAAE,IAAI,CAAC,CAAC;EAC1B,QAAQ,OAAO,GAAG,EAAE,IAAI,CAAC,CAAC;EAC1B,QAAQ,OAAO;EACf,QAAQ,YAAY;EAEpB,IAAI,IAAI,SAAS,QAAQ;GACvB,QAAQ,UAAU;GAClB,KAAK,MAAM,KAAK,IAAI,UAAU;IAC5B,MAAM,CAAC,IAAI,MAAM,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC;IACjC,QAAQ,OAAO,KAAK,KAAK,EAAE;IAC3B,QAAQ,IAAI,IAAI,IAAI,KAAK,GAAG,KAAK,KAAK,CAAC;GACzC;GACA,QAAQ,YAAY,KAAK,OAAO;GAChC,QAAQ,KAAK;GACb,QAAQ,OAAO;EACjB;CACF;CACA,QAAQ,QAAQ;AAClB;AAEA,IAAa,UAAqC;CAChD,MAAM;CACN,KAAK;CACL,MAAM;CACN;AACF"}
|
|
1
|
+
{"version":3,"file":"box.js","names":[],"sources":["../../src/core/box.ts"],"sourcesContent":["import { barPlacement } from './bar'\nimport { read, rowCount, rowOf, type ChartAccessor, type ChartData } from './data'\nimport { visibleRange } from './decimate'\nimport { crisp, type Painter } from './painter'\nimport { warnOnce } from './warn'\nimport type { ChartSeries, ChartSeriesKind, ChartView } from './series'\n\n/*\n * A box plot: for each x, a group of values summed up in five numbers. The\n * box runs from the lower quartile to the upper one with a line at the\n * median; the whiskers reach the farthest values within 1.5 times the box's\n * length of it, and values past them are dots of their own.\n */\n\nexport interface BoxStyle {\n /** How far whiskers reach, in box lengths past the box: `1.5` by default, `Infinity` for all the values. */\n whisker?: number\n}\n\nexport interface BoxStats {\n /** The ends of the whiskers. */\n low: number\n high: number\n q1: number\n median: number\n q3: number\n /** The values past the whiskers. */\n outliers: number[]\n /** How many values there are. */\n count: number\n}\n\n/** The `p`th quantile (0 to 1) of sorted values, between the two nearest. */\nfunction quantile(sorted: number[], p: number): number {\n const at = (sorted.length - 1) * p\n const i = Math.floor(at)\n const next = sorted[Math.min(i + 1, sorted.length - 1)]!\n return sorted[i]! + (next - sorted[i]!) * (at - i)\n}\n\n/** Sums up a group of values; `null` when none is a number. */\nexport function boxStats(values: unknown, whisker = 1.5): BoxStats | null {\n if (!values || typeof (values as ArrayLike<unknown>).length !== 'number') return null\n const list: number[] = []\n for (const v of Array.from(values as ArrayLike<unknown>)) {\n const n = typeof v === 'number' ? v : Number(v)\n if (v != null && v !== '' && Number.isFinite(n)) list.push(n)\n }\n if (!list.length) return null\n list.sort((a, b) => a - b)\n const q1 = quantile(list, 0.25)\n const q3 = quantile(list, 0.75)\n const reach = (q3 - q1) * whisker\n let low = q1\n let high = q3\n const outliers: number[] = []\n for (const v of list) {\n if (v < q1 - reach || v > q3 + reach) outliers.push(v)\n else {\n if (v < low) low = v\n if (v > high) high = v\n }\n }\n return { low, high, q1, median: quantile(list, 0.5), q3, outliers, count: list.length }\n}\n\nconst cache = new WeakMap<object, Map<unknown, Array<BoxStats | null>>>()\n\n/** Each row's numbers, worked out once for the same rows, accessor and whisker. */\nexport function boxesOf(\n rows: ChartData,\n values: ChartAccessor,\n whisker = 1.5,\n): Array<BoxStats | null> {\n let byAccessor = cache.get(rows)\n if (!byAccessor) cache.set(rows, (byAccessor = new Map()))\n const key = `${whisker}`\n let byWhisker = byAccessor.get(values) as unknown as Map<string, Array<BoxStats | null>>\n if (!byWhisker) byAccessor.set(values, (byWhisker = new Map()) as never)\n let out = byWhisker.get(key)\n if (!out) {\n out = []\n const n = rowCount(rows)\n for (let i = 0; i < n; i++) {\n const group = read(rowOf(rows, i), values, i)\n if (group != null && typeof (group as ArrayLike<unknown>).length !== 'number')\n warnOnce(\n 'box-values',\n \"a box plot's `y` gives each row an array of values; other values are left out.\",\n )\n out.push(boxStats(group, whisker))\n }\n byWhisker.set(key, out)\n }\n return out\n}\n\n/** A box plot series' numbers by row. */\nexport const boxes = (series: Pick<ChartSeries<BoxStyle>, 'rows' | 'props'>) =>\n boxesOf(series.rows, series.props.y, series.props.whisker)\n\n/** The radius of an outlier's dot, in px. */\nconst DOT = 2.5\n\nfunction draw(painter: Painter, series: ChartSeries<BoxStyle>, view: ChartView) {\n const { x: sx, y: sy, dpr, horizontal } = view\n const xs = series.x.values\n const list = boxes(series)\n const [from, to] = visibleRange(xs, series.x.sorted, sx.domain[0], sx.domain[1])\n const { offset, width } = barPlacement(view.band, series.slot)\n const snap = (v: number) => Math.round(v * dpr) / dpr\n // a line 1 px wide on whole device pixels\n const line = (v: number) => crisp(v, dpr)\n const p = (u: number, v: number): [number, number] => (horizontal ? [v, u] : [u, v])\n const color = series.color\n\n painter.save()\n painter.lineWidth = 1\n for (let i = from; i < to; i++) {\n const box = list[i]\n const x = xs[i]!\n if (!box || x !== x) continue\n const u0 = snap(sx.map(x) + offset)\n const u1 = Math.max(u0 + 1, snap(sx.map(x) + offset + width))\n const mid = line((u0 + u1) / 2)\n // kept to its band, which may be narrower than 4px\n const cap = Math.min(Math.max(4, (u1 - u0) / 2), view.band)\n const [q1, q3] = [snap(sy.map(box.q1)), snap(sy.map(box.q3))]\n // whiskers and their caps\n painter.strokeStyle = color\n painter.beginPath()\n for (const [end, edge] of [\n [box.low, box.q1],\n [box.high, box.q3],\n ] as const) {\n const v = line(sy.map(end))\n painter.moveTo(...p(mid, snap(sy.map(edge))))\n painter.lineTo(...p(mid, v))\n painter.moveTo(...p(mid - cap / 2, v))\n painter.lineTo(...p(mid + cap / 2, v))\n }\n painter.stroke()\n // the box: a light fill, its outline, and the median across it\n const [x0, y0] = p(u0, Math.min(q1, q3))\n const [x1, y1] = p(u1, Math.max(q1, q3))\n const rect = [Math.min(x0, x1), Math.min(y0, y1), Math.abs(x1 - x0), Math.abs(y1 - y0)] as const\n painter.beginPath()\n painter.rect(...rect)\n painter.fillStyle = view.colors.surface\n painter.fill()\n painter.save()\n painter.globalAlpha *= 0.16\n painter.fillStyle = color\n painter.fill()\n painter.restore()\n painter.beginPath()\n painter.rect(rect[0] + 0.5, rect[1] + 0.5, Math.max(0, rect[2] - 1), Math.max(0, rect[3] - 1))\n painter.stroke()\n painter.lineWidth = 2\n painter.beginPath()\n const m = snap(sy.map(box.median))\n painter.moveTo(...p(u0, m))\n painter.lineTo(...p(u1, m))\n painter.stroke()\n painter.lineWidth = 1\n // the values past the whiskers: rings, so many on one spot still show\n if (box.outliers.length) {\n painter.beginPath()\n for (const v of box.outliers) {\n const [cx, cy] = p(mid, sy.map(v))\n painter.moveTo(cx + DOT, cy)\n painter.arc(cx, cy, DOT, 0, Math.PI * 2)\n }\n painter.fillStyle = view.colors.surface\n painter.fill()\n painter.stroke()\n }\n }\n painter.restore()\n}\n\nexport const boxKind: ChartSeriesKind<BoxStyle> = {\n type: 'box',\n box: true,\n band: true,\n draw,\n}\n"],"mappings":";;;;;;;AAiCA,SAAS,SAAS,QAAkB,GAAmB;CACrD,MAAM,MAAM,OAAO,SAAS,KAAK;CACjC,MAAM,IAAI,KAAK,MAAM,EAAE;CACvB,MAAM,OAAO,OAAO,KAAK,IAAI,IAAI,GAAG,OAAO,SAAS,CAAC;CACrD,OAAO,OAAO,MAAO,OAAO,OAAO,OAAQ,KAAK;AAClD;;AAGA,SAAgB,SAAS,QAAiB,UAAU,KAAsB;CACxE,IAAI,CAAC,UAAU,OAAQ,OAA8B,WAAW,UAAU,OAAO;CACjF,MAAM,OAAiB,CAAC;CACxB,KAAK,MAAM,KAAK,MAAM,KAAK,MAA4B,GAAG;EACxD,MAAM,I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AAU;EAClB,MAAM,IAAI,KAAK,GAAG,IAAI,IAAI,MAAM,CAAC;EACjC,QAAQ,OAAO,GAAG,EAAE,IAAI,CAAC,CAAC;EAC1B,QAAQ,OAAO,GAAG,EAAE,IAAI,CAAC,CAAC;EAC1B,QAAQ,OAAO;EACf,QAAQ,YAAY;EAEpB,IAAI,IAAI,SAAS,QAAQ;GACvB,QAAQ,UAAU;GAClB,KAAK,MAAM,KAAK,IAAI,UAAU;IAC5B,MAAM,CAAC,IAAI,MAAM,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC;IACjC,QAAQ,OAAO,KAAK,KAAK,EAAE;IAC3B,QAAQ,IAAI,IAAI,IAAI,KAAK,GAAG,KAAK,KAAK,CAAC;GACzC;GACA,QAAQ,YAAY,KAAK,OAAO;GAChC,QAAQ,KAAK;GACb,QAAQ,OAAO;EACjB;CACF;CACA,QAAQ,QAAQ;AAClB;AAEA,IAAa,UAAqC;CAChD,MAAM;CACN,KAAK;CACL,MAAM;CACN;AACF"}
|
package/dist/core/waterfall.js
CHANGED
|
@@ -46,9 +46,9 @@ function draw(painter, series, view) {
|
|
|
46
46
|
const { top, base } = series;
|
|
47
47
|
if (!base) return;
|
|
48
48
|
const [from, to] = visibleRange(xs, series.x.sorted, sx.domain[0], sx.domain[1]);
|
|
49
|
-
const { offset, width } = barPlacement(view.band, series.slot);
|
|
49
|
+
const { offset, width, room } = barPlacement(view.band, series.slot);
|
|
50
50
|
const snap = (v) => Math.round(v * dpr) / dpr;
|
|
51
|
-
const radius = Math.max(0, series.props.radius ?? 2);
|
|
51
|
+
const radius = Math.min(Math.max(0, series.props.radius ?? 2), Math.round(room * dpr) / dpr * 2);
|
|
52
52
|
const p = (u, v) => horizontal ? [v, u] : [u, v];
|
|
53
53
|
if (series.props.connectors ?? true) {
|
|
54
54
|
painter.save();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waterfall.js","names":[],"sources":["../../src/core/waterfall.ts"],"sourcesContent":["import { barLabels, barPlacement } from './bar'\nimport { read, rowOf, type ChartAccessor, type ChartData } from './data'\nimport { visibleRange } from './decimate'\nimport type { Painter } from './painter'\nimport type { ChartSeries, ChartSeriesKind } from './series'\n\n/*\n * A waterfall: each row a change, drawn as a bar floating from the running\n * total before it to the total after; a total row (`total`) is a bar from\n * 0 up to the running total so far. A thin line joins each bar's end to\n * the next bar, at the total they share.\n */\n\nexport interface WaterfallStyle {\n /** Whether a row is a total: a key of the row or a function of it. */\n total?: ChartAccessor\n /** Corner radius of the bars, in px. */\n radius?: number\n /** Lines from each bar to the next, at the total they share. */\n connectors?: boolean\n labelPosition?: 'outside' | 'inside'\n}\n\n/**\n * The bars of a waterfall: where each starts (`base`) and ends (`top`), and\n * its value (`y`): the change, or for a total row, the running total. A\n * row without a value is left out and changes nothing.\n */\nexport function waterfallSteps(\n rows: ChartData,\n changes: Float64Array,\n total: ChartAccessor | undefined,\n): { y: Float64Array; top: Float64Array; base: Float64Array } {\n const n = changes.length\n const y = new Float64Array(n)\n const top = new Float64Array(n)\n const base = new Float64Array(n)\n let sum = 0\n for (let i = 0; i < n; i++) {\n if (total !== undefined && read(rowOf(rows, i), total, i)) {\n y[i] = top[i] = sum\n base[i] = 0\n continue\n }\n const change = changes[i]!\n if (change !== change) {\n y[i] = top[i] = base[i] = Number.NaN\n continue\n }\n y[i] = change\n base[i] = sum\n sum += change\n top[i] = sum\n }\n return { y, top, base }\n}\n\n/** Whether row `i` of a waterfall is a total. */\nexport function isTotal(series: Pick<ChartSeries<WaterfallStyle>, 'props' | 'rows'>, i: number) {\n const total = series.props.total\n return total !== undefined && !!read(rowOf(series.rows, i), total, i)\n}\n\nfunction draw(\n painter: Painter,\n series: ChartSeries<WaterfallStyle>,\n view: Parameters<ChartSeriesKind['draw']>[2],\n) {\n const { x: sx, y: sy, dpr, horizontal } = view\n const xs = series.x.values\n const { top, base } = series\n if (!base) return\n const [from, to] = visibleRange(xs, series.x.sorted, sx.domain[0], sx.domain[1])\n const { offset, width } = barPlacement(view.band, series.slot)\n const snap = (v: number) => Math.round(v * dpr) / dpr\n const radius = Math.max(0, series.props.radius ?? 2)\n const p = (u: number, v: number): [number, number] => (horizontal ? [v, u] : [u, v])\n\n // the lines first, under the bars: from each bar's end to the next bar\n if (series.props.connectors ?? true) {\n painter.save()\n painter.strokeStyle = view.colors.baseline\n painter.lineWidth = 1\n painter.setLineDash([3, 3])\n painter.beginPath()\n let last = -1\n for (let i = from; i < to; i++) {\n if (top[i] !== top[i] || xs[i] !== xs[i]) continue\n if (last >= 0) {\n // the total after the last bar, where this one starts (or a total bar ends)\n const v = snap(sy.map(top[last]!)) + 0.5\n const u0 = snap(sx.map(xs[last]!) + offset + width)\n const u1 = snap(sx.map(xs[i]!) + offset)\n if (u1 > u0) {\n painter.moveTo(...p(u0, v))\n painter.lineTo(...p(u1, v))\n }\n }\n last = i\n }\n painter.stroke()\n painter.restore()\n }\n\n const bar = (i: number) => {\n const value = top[i]!\n const x = xs[i]!\n if (value !== value || x !== x) return\n const u0 = snap(sx.map(x) + offset)\n const u1 = Math.max(u0 + 1 / dpr, snap(sx.map(x) + offset + width))\n let v0 = snap(sy.map(base[i]!))\n let v1 = snap(sy.map(value))\n // no change still shows, as a hairline at the total\n if (Math.abs(v1 - v0) < 1) [v0, v1] = [v0 - 0.5, v0 + 0.5]\n const lo = Math.min(v0, v1)\n const hi = Math.max(v0, v1)\n const r = Math.min(radius, (u1 - u0) / 2, (hi - lo) / 2)\n // the corners round, but not at an end that stands on 0 (a total's foot)\n const zero = snap(sy.map(0))\n const rLo = Math.abs(lo - zero) < 1 ? 0 : r\n const rHi = Math.abs(hi - zero) < 1 ? 0 : r\n if (r < 0.5) {\n const [x0, y0] = p(u0, lo)\n const [x1, y1] = p(u1, hi)\n painter.rect(Math.min(x0, x1), Math.min(y0, y1), Math.abs(x1 - x0), Math.abs(y1 - y0))\n return\n }\n const corner = (u: number, v: number, nu: number, nv: number, cr: number) => {\n if (cr > 0) painter.arcTo(...p(u, v), ...p(nu, nv), cr)\n else painter.lineTo(...p(u, v))\n }\n painter.moveTo(...p((u0 + u1) / 2, lo))\n corner(u1, lo, u1, hi, rLo)\n corner(u1, hi, u0, hi, rHi)\n corner(u0, hi, u0, lo, rHi)\n corner(u0, lo, u1, lo, rLo)\n painter.closePath()\n }\n\n painter.save()\n const groups = new Map<string, number[]>()\n for (let i = from; i < to; i++) {\n const color = series.colors?.[i] ?? series.color\n let group = groups.get(color)\n if (!group) groups.set(color, (group = []))\n group.push(i)\n }\n for (const [color, rows] of groups) {\n painter.fillStyle = color\n painter.beginPath()\n for (const i of rows) bar(i)\n painter.fill()\n }\n painter.restore()\n}\n\nexport const waterfallKind: ChartSeriesKind<WaterfallStyle> = {\n type: 'bar',\n waterfall: true,\n zero: true,\n band: true,\n draw,\n labels: barLabels,\n}\n"],"mappings":";;;;;;;;;AA4BA,SAAgB,eACd,MACA,SACA,OAC4D;CAC5D,MAAM,IAAI,QAAQ;CAClB,MAAM,IAAI,IAAI,aAAa,CAAC;CAC5B,MAAM,MAAM,IAAI,aAAa,CAAC;CAC9B,MAAM,OAAO,IAAI,aAAa,CAAC;CAC/B,IAAI,MAAM;CACV,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;EAC1B,IAAI,UAAU,KAAA,KAAa,KAAK,MAAM,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG;GACzD,EAAE,KAAK,IAAI,KAAK;GAChB,KAAK,KAAK;GACV;EACF;EACA,MAAM,SAAS,QAAQ;EACvB,IAAI,WAAW,QAAQ;GACrB,EAAE,KAAK,IAAI,KAAK,KAAK,KAAK;GAC1B;EACF;EACA,EAAE,KAAK;EACP,KAAK,KAAK;EACV,OAAO;EACP,IAAI,KAAK;CACX;CACA,OAAO;EAAE;EAAG;EAAK;CAAK;AACxB;;AAGA,SAAgB,QAAQ,QAA6D,GAAW;CAC9F,MAAM,QAAQ,OAAO,MAAM;CAC3B,OAAO,UAAU,KAAA,KAAa,CAAC,CAAC,KAAK,MAAM,OAAO,MAAM,CAAC,GAAG,OAAO,CAAC;AACtE;AAEA,SAAS,KACP,SACA,QACA,MACA;CACA,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI,KAAK,eAAe;CAC1C,MAAM,KAAK,OAAO,EAAE;CACpB,MAAM,EAAE,KAAK,SAAS;CACtB,IAAI,CAAC,MAAM;CACX,MAAM,CAAC,MAAM,MAAM,aAAa,IAAI,OAAO,EAAE,QAAQ,GAAG,OAAO,IAAI,GAAG,OAAO,EAAE;CAC/E,MAAM,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"waterfall.js","names":[],"sources":["../../src/core/waterfall.ts"],"sourcesContent":["import { barLabels, barPlacement } from './bar'\nimport { read, rowOf, type ChartAccessor, type ChartData } from './data'\nimport { visibleRange } from './decimate'\nimport type { Painter } from './painter'\nimport type { ChartSeries, ChartSeriesKind } from './series'\n\n/*\n * A waterfall: each row a change, drawn as a bar floating from the running\n * total before it to the total after; a total row (`total`) is a bar from\n * 0 up to the running total so far. A thin line joins each bar's end to\n * the next bar, at the total they share.\n */\n\nexport interface WaterfallStyle {\n /** Whether a row is a total: a key of the row or a function of it. */\n total?: ChartAccessor\n /** Corner radius of the bars, in px. */\n radius?: number\n /** Lines from each bar to the next, at the total they share. */\n connectors?: boolean\n labelPosition?: 'outside' | 'inside'\n}\n\n/**\n * The bars of a waterfall: where each starts (`base`) and ends (`top`), and\n * its value (`y`): the change, or for a total row, the running total. A\n * row without a value is left out and changes nothing.\n */\nexport function waterfallSteps(\n rows: ChartData,\n changes: Float64Array,\n total: ChartAccessor | undefined,\n): { y: Float64Array; top: Float64Array; base: Float64Array } {\n const n = changes.length\n const y = new Float64Array(n)\n const top = new Float64Array(n)\n const base = new Float64Array(n)\n let sum = 0\n for (let i = 0; i < n; i++) {\n if (total !== undefined && read(rowOf(rows, i), total, i)) {\n y[i] = top[i] = sum\n base[i] = 0\n continue\n }\n const change = changes[i]!\n if (change !== change) {\n y[i] = top[i] = base[i] = Number.NaN\n continue\n }\n y[i] = change\n base[i] = sum\n sum += change\n top[i] = sum\n }\n return { y, top, base }\n}\n\n/** Whether row `i` of a waterfall is a total. */\nexport function isTotal(series: Pick<ChartSeries<WaterfallStyle>, 'props' | 'rows'>, i: number) {\n const total = series.props.total\n return total !== undefined && !!read(rowOf(series.rows, i), total, i)\n}\n\nfunction draw(\n painter: Painter,\n series: ChartSeries<WaterfallStyle>,\n view: Parameters<ChartSeriesKind['draw']>[2],\n) {\n const { x: sx, y: sy, dpr, horizontal } = view\n const xs = series.x.values\n const { top, base } = series\n if (!base) return\n const [from, to] = visibleRange(xs, series.x.sorted, sx.domain[0], sx.domain[1])\n const { offset, width, room } = barPlacement(view.band, series.slot)\n const snap = (v: number) => Math.round(v * dpr) / dpr\n // narrow bands leave little or no room between bars: no corners to round there either\n const radius = Math.min(Math.max(0, series.props.radius ?? 2), (Math.round(room * dpr) / dpr) * 2)\n const p = (u: number, v: number): [number, number] => (horizontal ? [v, u] : [u, v])\n\n // the lines first, under the bars: from each bar's end to the next bar\n if (series.props.connectors ?? true) {\n painter.save()\n painter.strokeStyle = view.colors.baseline\n painter.lineWidth = 1\n painter.setLineDash([3, 3])\n painter.beginPath()\n let last = -1\n for (let i = from; i < to; i++) {\n if (top[i] !== top[i] || xs[i] !== xs[i]) continue\n if (last >= 0) {\n // the total after the last bar, where this one starts (or a total bar ends)\n const v = snap(sy.map(top[last]!)) + 0.5\n const u0 = snap(sx.map(xs[last]!) + offset + width)\n const u1 = snap(sx.map(xs[i]!) + offset)\n if (u1 > u0) {\n painter.moveTo(...p(u0, v))\n painter.lineTo(...p(u1, v))\n }\n }\n last = i\n }\n painter.stroke()\n painter.restore()\n }\n\n const bar = (i: number) => {\n const value = top[i]!\n const x = xs[i]!\n if (value !== value || x !== x) return\n const u0 = snap(sx.map(x) + offset)\n const u1 = Math.max(u0 + 1 / dpr, snap(sx.map(x) + offset + width))\n let v0 = snap(sy.map(base[i]!))\n let v1 = snap(sy.map(value))\n // no change still shows, as a hairline at the total\n if (Math.abs(v1 - v0) < 1) [v0, v1] = [v0 - 0.5, v0 + 0.5]\n const lo = Math.min(v0, v1)\n const hi = Math.max(v0, v1)\n const r = Math.min(radius, (u1 - u0) / 2, (hi - lo) / 2)\n // the corners round, but not at an end that stands on 0 (a total's foot)\n const zero = snap(sy.map(0))\n const rLo = Math.abs(lo - zero) < 1 ? 0 : r\n const rHi = Math.abs(hi - zero) < 1 ? 0 : r\n if (r < 0.5) {\n const [x0, y0] = p(u0, lo)\n const [x1, y1] = p(u1, hi)\n painter.rect(Math.min(x0, x1), Math.min(y0, y1), Math.abs(x1 - x0), Math.abs(y1 - y0))\n return\n }\n const corner = (u: number, v: number, nu: number, nv: number, cr: number) => {\n if (cr > 0) painter.arcTo(...p(u, v), ...p(nu, nv), cr)\n else painter.lineTo(...p(u, v))\n }\n painter.moveTo(...p((u0 + u1) / 2, lo))\n corner(u1, lo, u1, hi, rLo)\n corner(u1, hi, u0, hi, rHi)\n corner(u0, hi, u0, lo, rHi)\n corner(u0, lo, u1, lo, rLo)\n painter.closePath()\n }\n\n painter.save()\n const groups = new Map<string, number[]>()\n for (let i = from; i < to; i++) {\n const color = series.colors?.[i] ?? series.color\n let group = groups.get(color)\n if (!group) groups.set(color, (group = []))\n group.push(i)\n }\n for (const [color, rows] of groups) {\n painter.fillStyle = color\n painter.beginPath()\n for (const i of rows) bar(i)\n painter.fill()\n }\n painter.restore()\n}\n\nexport const waterfallKind: ChartSeriesKind<WaterfallStyle> = {\n type: 'bar',\n waterfall: true,\n zero: true,\n band: true,\n draw,\n labels: barLabels,\n}\n"],"mappings":";;;;;;;;;AA4BA,SAAgB,eACd,MACA,SACA,OAC4D;CAC5D,MAAM,IAAI,QAAQ;CAClB,MAAM,IAAI,IAAI,aAAa,CAAC;CAC5B,MAAM,MAAM,IAAI,aAAa,CAAC;CAC9B,MAAM,OAAO,IAAI,aAAa,CAAC;CAC/B,IAAI,MAAM;CACV,KAAK,IAAI,IAAI,GAAG,IA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,UAAU;EAClB,KAAK,MAAM,KAAK,MAAM,IAAI,CAAC;EAC3B,QAAQ,KAAK;CACf;CACA,QAAQ,QAAQ;AAClB;AAEA,IAAa,gBAAiD;CAC5D,MAAM;CACN,WAAW;CACX,MAAM;CACN,MAAM;CACN;CACA,QAAQ;AACV"}
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
@layer dou.components{.dou-chart{--dou-chart-surface:var(--dou-color-bg-surface);--dou-chart-grid:var(--dou-color-border-subtle);--dou-chart-baseline:var(--dou-color-border-strong);--dou-chart-label:var(--dou-color-text-tertiary);--dou-chart-title:var(--dou-color-text-secondary);--dou-chart-range-ink:var(--dou-color-text-tertiary);--dou-chart-marker:color-mix(in oklab,var(--dou-color-text)45%,transparent);--dou-chart-track:color-mix(in oklab,var(--dou-color-text)10%,transparent);position:relative;box-sizing:border-box;overflow:hidden;color:var(--dou-color-text);font-family:var(--dou-font-family);font-variant-numeric:tabular-nums;width:100%;min-width:0;font-size:12px;line-height:16px}.dou-chart__canvas{position:absolute;display:block;top:0;left:0}.dou-chart__static{position:absolute;display:block;width:100%;height:100%;font-size:12px;inset:0}.dou-chart__canvas,.dou-chart__static,.dou-chart__labels,.dou-chart__legends{transition:opacity var(--dou-motion-duration-fast)var(--dou-motion-easing)}.dou-chart.is-loading>:is(.dou-chart__canvas,.dou-chart__static,.dou-chart__labels,.dou-chart__legends){opacity:.4}.dou-chart__loading{position:absolute;display:flex;color:var(--dou-color-text-secondary);justify-content:center;align-items: center;inset:0}.dou-chart__labels{position:absolute;pointer-events:none;inset:0}.dou-chart__tick,.dou-chart__title{position:absolute;display:flex;white-space:nowrap;align-items: center;height:16px}.dou-chart__text{text-box:trim-both cap alphabetic}.dou-chart__tick{color:var(--dou-chart-label);will-change:transform;top:0;left:0}.dou-chart__tick.is-value{color:var(--dou-color-text-secondary);font-variant-numeric:tabular-nums}.dou-chart__tick.is-rate{font-variant-numeric:tabular-nums}.dou-chart__tick.is-clipped{pointer-events:auto}.dou-chart__tick.is-clipped>.dou-chart__text{overflow:hidden;text-overflow:ellipsis;text-box:normal;min-width:0;line-height:16px}.dou-chart__value{position:absolute;display:flex;color:var(--dou-color-text-secondary);font-variant-numeric:tabular-nums;white-space:nowrap;transition:opacity var(--dou-motion-duration-fast)var(--dou-motion-easing);align-items: center;height:16px;top:0;left:0}.dou-chart__value.is-middle{translate:-50%}.dou-chart__value.is-end{translate:-100%}.dou-chart__value.is-inside{font-weight:var(--dou-font-weight-medium)}.dou-chart__value.is-faded{opacity:.24}.dou-chart__value.is-clipped{pointer-events:auto}.dou-chart__value.is-clipped>.dou-chart__text{overflow:hidden;text-overflow:ellipsis;text-box:normal;min-width:0;line-height:16px}.dou-chart__value.is-hidden{opacity:0;transition:none}.dou-chart__marker{position:absolute;display:flex;color:var(--dou-color-text-secondary);white-space:nowrap;align-items: center;height:16px;top:0;left:0}.dou-chart__marker.is-middle{translate:-50%}.dou-chart__marker.is-end{translate:-100%}.dou-chart__marker.is-backdrop{background-color:color-mix(in oklab,currentColor 10%,var(--dou-chart-surface));border-radius:4px;padding-inline-start:4px;padding-inline-end:4px}.dou-chart__marker.is-backdrop.is-start{margin-left:-4px}.dou-chart__marker.is-backdrop.is-end{margin-left:4px}.dou-chart__marker.is-primary{color:var(--dou-color-primary-text)}.dou-chart__marker.is-success{color:var(--dou-color-success-text)}.dou-chart__marker.is-warning{color:var(--dou-color-warning-text)}.dou-chart__marker.is-danger{color:var(--dou-color-danger-text)}.dou-chart__measure{visibility:hidden;contain:layout style}.dou-chart__title,.dou-chart__legend{top:0;left:0}.dou-chart.is-interactive:focus-visible{outline:2px solid var(--dou-color-focus);outline-offset:2px;border-radius:var(--dou-radius-control)}.dou-chart__legends{position:absolute;pointer-events:none}.dou-chart__legends.is-scroll{overflow-y:auto;overscroll-behavior:contain;pointer-events:auto;scrollbar-width:thin}.dou-chart__title{color:var(--dou-chart-title);font-weight:var(--dou-font-weight-medium)}.dou-chart__title.is-end{translate:-100%}.dou-chart__legend{position:absolute;display:flex;color:var(--dou-color-text-secondary);font:inherit;white-space:nowrap;cursor:pointer;pointer-events:auto;transition:color var(--dou-motion-duration-fast)var(--dou-motion-easing);-webkit-touch-callout:none;user-select:none;background:0 0;border:0;border-radius:2px;align-items: center;gap:6px;height:16px;padding:0}.dou-chart__legend:before{position:absolute;content:"";inset:-6px -4px}@media (pointer:coarse){.dou-chart__legend:before{inset:-12px -4px}}.dou-chart__legend:hover{color:var(--dou-color-text)}.dou-chart__legend:focus-visible{outline:2px solid var(--dou-color-focus);outline-offset:2px}.dou-chart__legend.is-clipped>.dou-chart__text{overflow:hidden;text-overflow:ellipsis;text-box:normal;min-width:0;line-height:16px}.dou-chart__legend.is-locked{cursor:default}.dou-chart__legend.is-locked:hover{color:var(--dou-color-text-secondary)}.dou-chart__legend.is-off{color:var(--dou-color-text-disabled)}.dou-chart__legend.is-off>.dou-chart__swatch{opacity:.32}.dou-chart__swatch{background-color:currentColor;border-radius:1px;flex-shrink:0;width:12px;height:2px}.is-area>.dou-chart__swatch{border-radius:2px;height:8px}.is-radar>.dou-chart__swatch{border-radius:2px;height:8px}.is-bar>.dou-chart__swatch{border-radius:2px;width:8px;height:8px;margin-inline-start:2px;margin-inline-end:2px}.is-pie>.dou-chart__swatch{border-radius:2px;width:8px;height:8px;margin-inline-start:2px;margin-inline-end:2px}.is-box>.dou-chart__swatch{box-sizing:border-box;background-color:color-mix(in srgb,currentColor 16%,transparent);border:1px solid;border-radius:1px;width:8px;height:10px;margin-inline-start:2px;margin-inline-end:2px}.is-scatter>.dou-chart__swatch{border-radius:50%;width:8px;height:8px;margin-inline-start:2px;margin-inline-end:2px}.is-heatmap>.dou-chart__swatch{box-shadow:inset 0 0 0 1px color-mix(in oklab,var(--dou-color-text)8%,transparent);border-radius:2px;height:8px}.is-dashed>.dou-chart__swatch{background:repeating-linear-gradient(90deg,currentColor 0 4px,#0000 4px 7px)}.dou-chart__center{position:absolute;display:flex;text-align:center;flex-direction:column;justify-content:center;align-items: center;translate:-50% -50%}.dou-chart__center.is-above{translate:-50% calc(-100% - 4px)}.dou-chart__gauge-value{color:var(--dou-color-text);font-size:var(--dou-chart-gauge-value-size,28px);font-weight:var(--dou-font-weight-bold);font-variant-numeric:tabular-nums;line-height:1.3}.dou-chart__gauge-name{color:var(--dou-color-text-tertiary);font-size:var(--dou-font-size-sm);line-height:20px}.dou-chart__empty{position:absolute;display:flex;color:var(--dou-color-text-tertiary);font-size:var(--dou-font-size-sm);justify-content:center;align-items: center;inset:0}.dou-chart.is-table>:not(:-webkit-any(.dou-chart__table,.dou-chart__parts)){visibility:hidden}.dou-chart.is-table>:not(:-moz-any(.dou-chart__table,.dou-chart__parts)){visibility:hidden}.dou-chart.is-table>:not(:is(.dou-chart__table,.dou-chart__parts)){visibility:hidden}.dou-chart__table{position:absolute;overflow:auto;border:1px solid var(--dou-color-border);border-radius:var(--dou-radius-container);background-color:var(--dou-chart-surface);color:var(--dou-color-text);font-size:var(--dou-font-size-sm);overscroll-behavior:contain;line-height:1.5;inset:0}.dou-chart__table:focus-visible{outline:2px solid var(--dou-color-focus);outline-offset:2px}.dou-chart__table table{border-collapse:separate;border-spacing:0;font-variant-numeric:tabular-nums;width:100%}.dou-chart__table caption{position:absolute;overflow:hidden;clip-path:inset(50%);white-space:nowrap;width:1px;height:1px}.dou-chart__table th{box-sizing:border-box;border-bottom:1px solid var(--dou-color-border-subtle);text-align:end;white-space:nowrap;height:36px;padding:6px 10px}.dou-chart__table td{box-sizing:border-box;border-bottom:1px solid var(--dou-color-border-subtle);text-align:end;white-space:nowrap;height:36px;padding:6px 10px}.dou-chart__table th[scope=row]{text-align:start}.dou-chart__table thead th:first-child{text-align:start}.dou-chart__table th[scope=row]{font-weight:var(--dou-font-weight-regular)}.dou-chart__table thead th{position:sticky;z-index:1;border-bottom-color:var(--dou-color-border);background-color:color-mix(in oklab,var(--dou-color-text)2.5%,var(--dou-chart-surface));color:var(--dou-color-text-secondary);font-weight:var(--dou-font-weight-medium);height:32px;top:0}.dou-chart__table tbody tr:last-child>*{border-bottom:0}.dou-chart__table-more{border-top:1px solid var(--dou-color-border-subtle);color:var(--dou-color-text-tertiary);margin:0;padding:8px 10px}.dou-chart__pointer{position:absolute;pointer-events:none;inset:0}.dou-chart__crosshair,.dou-chart__band,.dou-chart__cell,.dou-chart__mark,.dou-chart__tooltip{position:absolute;top:0;left:0}.dou-chart__crosshair{background-color:var(--dou-chart-baseline)}.dou-chart__band{background-color:color-mix(in oklab,var(--dou-color-text)5%,transparent)}.dou-chart__cell{box-sizing:border-box;border:2px solid var(--dou-color-text);box-shadow:inset 0 0 0 1px var(--dou-chart-surface);border-radius:4px}.dou-chart__mark{box-sizing:border-box;border:2px solid var(--dou-chart-surface);box-shadow:0 0 0 1px color-mix(in oklab,currentColor 24%,transparent);background-color:currentColor;border-radius:50%}.dou-chart__mark.is-faded{opacity:.32}.dou-chart__mark.is-ring{box-shadow:0 0 0 1px var(--dou-chart-surface);background:0 0;border-color:currentColor}.dou-chart__tooltip{--dou-chart-tooltip-bg:color-mix(in oklab,var(--dou-color-text)calc(4%*var(--dou-scheme-dark)),var(--dou-color-bg-surface));box-sizing:border-box;border:1px solid var(--dou-color-border);border-radius:var(--dou-radius-container);background-color:var(--dou-chart-tooltip-bg);box-shadow:var(--dou-shadow-md);color:var(--dou-color-text-secondary);will-change:transform;min-width:120px;max-width:min(280px,100% - 8px);padding:8px 10px}.dou-chart__tooltip-title{display:flex;color:var(--dou-color-text);font-weight:var(--dou-font-weight-medium);align-items: center;min-height:16px;margin-bottom:6px}.dou-chart__tooltip-item{display:flex;align-items: center;gap:6px;min-height:16px}.dou-chart__tooltip-item+.dou-chart__tooltip-item{margin-top:4px}.dou-chart__tooltip-item.is-muted{color:var(--dou-color-text-tertiary)}.dou-chart__tooltip-item.is-muted>.dou-chart__tooltip-value{color:var(--dou-color-text-secondary)}.dou-chart__tooltip-swatch{box-shadow:inset 0 0 0 1px color-mix(in oklab,var(--dou-color-text)8%,transparent);background-color:currentColor;border-radius:2px;flex-shrink:0;width:8px;height:8px}.dou-chart__tooltip-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-box:normal;flex:1;min-width:0;line-height:16px}.dou-chart__tooltip-value{color:var(--dou-color-text);font-weight:var(--dou-font-weight-medium);white-space:nowrap;margin-left:12px}.dou-chart__tooltip-note{color:var(--dou-color-text-tertiary);margin-top:6px;line-height:16px}.dou-chart__live{position:absolute;overflow:hidden;clip-path:inset(50%);white-space:nowrap;width:1px;height:1px}.dou-chart.is-zoomed{cursor:grab}.dou-chart.is-brushing{cursor:crosshair}.dou-chart__brush{position:absolute;box-sizing:border-box;border:1px solid color-mix(in oklab,var(--dou-color-text)28%,transparent);background-color:color-mix(in oklab,var(--dou-color-text)6%,transparent);pointer-events:none;top:0;left:0}.dou-chart__range{position:absolute;box-sizing:border-box;border-radius:var(--dou-radius-control);box-shadow:inset 0 0 0 1px var(--dou-color-border-subtle);cursor:pointer;touch-action:none;user-select:none;top:0;left:0}.dou-chart__range-canvas{position:absolute;display:block;opacity:.56;top:0;left:0}.dou-chart__range-shade,.dou-chart__range-window,.dou-chart__range-handle{position:absolute;top:0;left:0}.dou-chart__range-shade{background-color:color-mix(in oklab,var(--dou-chart-surface)72%,transparent)}.dou-chart__range-window{box-sizing:border-box;--dou-chart-range-edge:color-mix(in oklab,var(--dou-color-text)32%,transparent);border-block:1px solid var(--dou-chart-range-edge);background-color:color-mix(in oklab,var(--dou-color-text)6%,transparent);cursor:grab}.is-vertical>.dou-chart__range-window{border-block-start:none;border-block-end:none;border-inline:1px solid var(--dou-chart-range-edge)}.dou-chart__range-handle{box-sizing:border-box;border:1px solid var(--dou-color-border-strong);background-color:var(--dou-color-bg-surface);box-shadow:var(--dou-shadow-sm);outline:none;cursor:ew-resize;border-radius:4px;width:8px;height:20px;margin:6px 0 0 -4px}.dou-chart__range-handle:before{position:absolute;content:"";inset:-6px -8px}.dou-chart__range-handle:hover{border-color:var(--dou-color-text-tertiary)}.dou-chart__range-handle:focus-visible{outline:2px solid var(--dou-color-focus);outline-offset:2px}.is-vertical>.dou-chart__range-handle{cursor:ns-resize;width:20px;height:8px;margin:-4px 0 0 6px}.is-vertical>.dou-chart__range-handle:before{inset:-8px -6px}@media (pointer:coarse){.dou-chart__range-handle:before{inset:-10px -16px}.is-vertical>.dou-chart__range-handle:before{inset:-16px -10px}}}
|
|
1
|
+
@layer dou.components{.dou-chart{--dou-chart-surface:var(--dou-color-bg-surface);--dou-chart-grid:var(--dou-color-border-subtle);--dou-chart-baseline:var(--dou-color-border-strong);--dou-chart-label:var(--dou-color-text-tertiary);--dou-chart-title:var(--dou-color-text-secondary);--dou-chart-range-ink:var(--dou-color-text-tertiary);--dou-chart-marker:color-mix(in oklab,var(--dou-color-text)45%,transparent);--dou-chart-track:color-mix(in oklab,var(--dou-color-text)10%,transparent);position:relative;box-sizing:border-box;overflow:hidden;color:var(--dou-color-text);font-family:var(--dou-font-family);font-variant-numeric:tabular-nums;width:100%;min-width:0;font-size:12px;line-height:16px}.dou-chart__canvas{position:absolute;display:block;top:0;left:0}.dou-chart__static{position:absolute;display:block;width:100%;height:100%;font-size:12px;inset:0}.dou-chart__canvas,.dou-chart__static,.dou-chart__labels,.dou-chart__legends{transition:opacity var(--dou-motion-duration-fast)var(--dou-motion-easing)}.dou-chart.is-loading>:is(.dou-chart__canvas,.dou-chart__static,.dou-chart__labels,.dou-chart__legends){opacity:.4}.dou-chart__loading{position:absolute;display:flex;color:var(--dou-color-text-secondary);justify-content:center;align-items: center;inset:0}.dou-chart__labels{position:absolute;pointer-events:none;inset:0}.dou-chart__tick,.dou-chart__title{position:absolute;display:flex;white-space:nowrap;align-items: center;height:16px}.dou-chart__text{text-box:trim-both cap alphabetic}.dou-chart__tick{color:var(--dou-chart-label);will-change:transform;top:0;left:0}.dou-chart__tick.is-value{color:var(--dou-color-text-secondary);font-variant-numeric:tabular-nums}.dou-chart__tick.is-rate{font-variant-numeric:tabular-nums}.dou-chart__tick.is-clipped{pointer-events:auto}.dou-chart__tick.is-clipped>.dou-chart__text{overflow:hidden;text-overflow:ellipsis;text-box:normal;min-width:0;line-height:16px}.dou-chart__value{position:absolute;display:flex;color:var(--dou-color-text-secondary);font-variant-numeric:tabular-nums;white-space:nowrap;transition:opacity var(--dou-motion-duration-fast)var(--dou-motion-easing);align-items: center;height:16px;top:0;left:0}.dou-chart__value.is-middle{translate:-50%}.dou-chart__value.is-end{translate:-100%}.dou-chart__value.is-inside{font-weight:var(--dou-font-weight-medium)}.dou-chart__value.is-faded{opacity:.24}.dou-chart__value.is-clipped{pointer-events:auto}.dou-chart__value.is-clipped>.dou-chart__text{overflow:hidden;text-overflow:ellipsis;text-box:normal;min-width:0;line-height:16px}.dou-chart__value.is-hidden{opacity:0;transition:none}.dou-chart__marker{position:absolute;display:flex;color:var(--dou-color-text-secondary);white-space:nowrap;align-items: center;height:16px;top:0;left:0}.dou-chart__marker.is-middle{translate:-50%}.dou-chart__marker.is-end{translate:-100%}.dou-chart__marker.is-backdrop{background-color:color-mix(in oklab,currentColor 10%,var(--dou-chart-surface));border-radius:4px;padding-inline-start:4px;padding-inline-end:4px}.dou-chart__marker.is-backdrop.is-start{margin-left:-4px}.dou-chart__marker.is-backdrop.is-end{margin-left:4px}.dou-chart__marker.is-primary{color:var(--dou-color-primary-text)}.dou-chart__marker.is-success{color:var(--dou-color-success-text)}.dou-chart__marker.is-warning{color:var(--dou-color-warning-text)}.dou-chart__marker.is-danger{color:var(--dou-color-danger-text)}.dou-chart__measure{visibility:hidden;contain:layout style}.dou-chart__title,.dou-chart__legend{top:0;left:0}.dou-chart.is-interactive:focus-visible{outline:2px solid var(--dou-color-focus);outline-offset:2px;border-radius:var(--dou-radius-control)}.dou-chart__legends{position:absolute;pointer-events:none}.dou-chart__legends.is-scroll{overflow-y:auto;overscroll-behavior:contain;pointer-events:auto;scrollbar-width:thin}.dou-chart__title{color:var(--dou-chart-title);font-weight:var(--dou-font-weight-medium)}.dou-chart__title.is-end{translate:-100%}.dou-chart__legend{position:absolute;display:flex;color:var(--dou-color-text-secondary);font:inherit;white-space:nowrap;cursor:pointer;pointer-events:auto;transition:color var(--dou-motion-duration-fast)var(--dou-motion-easing);-webkit-touch-callout:none;user-select:none;background:0 0;border:0;border-radius:2px;align-items: center;gap:6px;height:16px;padding:0}.dou-chart__legend:before{position:absolute;content:"";inset:-6px -4px}@media (pointer:coarse){.dou-chart__legend:before{inset:-12px -4px}}.dou-chart__legend:hover{color:var(--dou-color-text)}.dou-chart__legend:focus-visible{outline:2px solid var(--dou-color-focus);outline-offset:2px}.dou-chart__legend.is-clipped>.dou-chart__text{overflow:hidden;text-overflow:ellipsis;text-box:normal;min-width:0;line-height:16px}.dou-chart__legend.is-locked{cursor:default}.dou-chart__legend.is-locked:hover{color:var(--dou-color-text-secondary)}.dou-chart__legend.is-off{color:var(--dou-color-text-disabled)}.dou-chart__legend.is-off>.dou-chart__swatch{opacity:.32}.dou-chart__swatch{background-color:currentColor;border-radius:1px;flex-shrink:0;width:12px;height:2px}.is-area>.dou-chart__swatch{border-radius:2px;height:8px}.is-radar>.dou-chart__swatch{border-radius:2px;height:8px}.is-bar>.dou-chart__swatch{border-radius:2px;width:8px;height:8px;margin-inline-start:2px;margin-inline-end:2px}.is-pie>.dou-chart__swatch{border-radius:2px;width:8px;height:8px;margin-inline-start:2px;margin-inline-end:2px}.is-box>.dou-chart__swatch{box-sizing:border-box;background-color:color-mix(in srgb,currentColor 16%,transparent);border:1px solid;border-radius:1px;width:8px;height:10px;margin-inline-start:2px;margin-inline-end:2px}.is-scatter>.dou-chart__swatch{border-radius:50%;width:8px;height:8px;margin-inline-start:2px;margin-inline-end:2px}.is-heatmap>.dou-chart__swatch{box-shadow:inset 0 0 0 1px color-mix(in oklab,var(--dou-color-text)8%,transparent);border-radius:2px;height:8px}.is-dashed>.dou-chart__swatch{background:repeating-linear-gradient(90deg,currentColor 0 4px,#0000 4px 7px)}.dou-chart__center{position:absolute;display:flex;text-align:center;flex-direction:column;justify-content:center;align-items: center;translate:-50% -50%}.dou-chart__center.is-above{translate:-50% calc(-100% - 4px)}.dou-chart__gauge-value{color:var(--dou-color-text);font-size:var(--dou-chart-gauge-value-size,28px);font-weight:var(--dou-font-weight-bold);font-variant-numeric:tabular-nums;line-height:1.3}.dou-chart__gauge-name{color:var(--dou-color-text-tertiary);font-size:var(--dou-font-size-sm);line-height:20px}.dou-chart__empty{position:absolute;display:flex;color:var(--dou-color-text-tertiary);font-size:var(--dou-font-size-sm);justify-content:center;align-items: center;inset:0}.dou-chart.is-table>:not(:-webkit-any(.dou-chart__table,.dou-chart__parts)){visibility:hidden}.dou-chart.is-table>:not(:-moz-any(.dou-chart__table,.dou-chart__parts)){visibility:hidden}.dou-chart.is-table>:not(:is(.dou-chart__table,.dou-chart__parts)){visibility:hidden}.dou-chart__table{position:absolute;overflow:auto;border:1px solid var(--dou-color-border);border-radius:var(--dou-radius-container);background-color:var(--dou-chart-surface);color:var(--dou-color-text);font-size:var(--dou-font-size-sm);overscroll-behavior:contain;line-height:1.5;inset:0}.dou-chart__table:focus-visible{outline:2px solid var(--dou-color-focus);outline-offset:2px}.dou-chart__table table{border-collapse:separate;border-spacing:0;font-variant-numeric:tabular-nums;width:100%}.dou-chart__table caption{position:absolute;overflow:hidden;clip-path:inset(50%);white-space:nowrap;width:1px;height:1px}.dou-chart__table th{box-sizing:border-box;border-bottom:1px solid var(--dou-color-border-subtle);text-align:end;white-space:nowrap;height:36px;padding:6px 10px}.dou-chart__table td{box-sizing:border-box;border-bottom:1px solid var(--dou-color-border-subtle);text-align:end;white-space:nowrap;height:36px;padding:6px 10px}.dou-chart__table th[scope=row]{text-align:start}.dou-chart__table thead th:first-child{text-align:start}.dou-chart__table th[scope=row]{font-weight:var(--dou-font-weight-regular)}.dou-chart__table thead th{position:sticky;z-index:1;border-bottom-color:var(--dou-color-border);background-color:color-mix(in oklab,var(--dou-color-text)2.5%,var(--dou-chart-surface));color:var(--dou-color-text-secondary);font-weight:var(--dou-font-weight-medium);height:32px;top:0}.dou-chart__table tbody tr:last-child>*{border-bottom:0}.dou-chart__table-more{border-top:1px solid var(--dou-color-border-subtle);color:var(--dou-color-text-tertiary);margin:0;padding:8px 10px}.dou-chart__pointer{position:absolute;pointer-events:none;inset:0}.dou-chart__crosshair,.dou-chart__band,.dou-chart__cell,.dou-chart__mark,.dou-chart__tooltip{position:absolute;top:0;left:0}.dou-chart__crosshair{background-color:var(--dou-chart-baseline)}.dou-chart__band{background-color:color-mix(in oklab,var(--dou-color-text)5%,transparent)}.dou-chart__cell{box-sizing:border-box;border:2px solid var(--dou-color-text);box-shadow:inset 0 0 0 1px var(--dou-chart-surface);border-radius:4px}.dou-chart__mark{box-sizing:border-box;border:2px solid var(--dou-chart-surface);box-shadow:0 0 0 1px color-mix(in oklab,currentColor 24%,transparent);background-color:currentColor;border-radius:50%}.dou-chart__mark.is-faded{opacity:.32}.dou-chart__mark.is-ring{box-shadow:0 0 0 1px var(--dou-chart-surface);background:0 0;border-color:currentColor}.dou-chart__tooltip{--dou-chart-tooltip-bg:color-mix(in oklab,var(--dou-color-text)calc(4%*var(--dou-scheme-dark)),var(--dou-color-bg-surface));box-sizing:border-box;border:1px solid var(--dou-color-border);border-radius:var(--dou-radius-container);background-color:var(--dou-chart-tooltip-bg);box-shadow:var(--dou-shadow-md);color:var(--dou-color-text-secondary);will-change:transform;min-width:120px;max-width:min(280px,100% - 8px);padding:8px 10px}.dou-chart__tooltip-title{display:flex;color:var(--dou-color-text);font-weight:var(--dou-font-weight-medium);align-items: center;min-height:16px;margin-bottom:6px}.dou-chart__tooltip-item{display:flex;align-items: center;gap:6px;min-height:16px}.dou-chart__tooltip-item+.dou-chart__tooltip-item{margin-top:4px}.dou-chart__tooltip-item.is-muted{color:var(--dou-color-text-tertiary)}.dou-chart__tooltip-item.is-muted>.dou-chart__tooltip-value{color:var(--dou-color-text-secondary)}.dou-chart__tooltip-swatch{box-shadow:inset 0 0 0 1px color-mix(in oklab,var(--dou-color-text)8%,transparent);background-color:currentColor;border-radius:2px;flex-shrink:0;width:8px;height:8px}.dou-chart__tooltip-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-box:normal;flex:1;min-width:0;line-height:16px}.dou-chart__tooltip-value{color:var(--dou-color-text);font-weight:var(--dou-font-weight-medium);white-space:nowrap;margin-left:12px}.dou-chart__tooltip-note{color:var(--dou-color-text-tertiary);margin-top:6px;line-height:16px}.dou-chart__live{position:absolute;overflow:hidden;clip-path:inset(50%);white-space:nowrap;width:1px;height:1px}.dou-chart.is-zoomed{cursor:grab}.dou-chart.is-brushing{cursor:crosshair}.dou-chart__brush{position:absolute;box-sizing:border-box;border:1px solid color-mix(in oklab,var(--dou-color-text)28%,transparent);background-color:color-mix(in oklab,var(--dou-color-text)6%,transparent);pointer-events:none;top:0;left:0}.dou-chart__range{position:absolute;box-sizing:border-box;border-radius:var(--dou-radius-control);box-shadow:inset 0 0 0 1px var(--dou-color-border-subtle);cursor:pointer;touch-action:none;user-select:none;top:0;left:0}.dou-chart__range-canvas{position:absolute;display:block;opacity:.56;top:0;left:0}.dou-chart__range-shade,.dou-chart__range-window,.dou-chart__range-handle{position:absolute;top:0;left:0}.dou-chart__range-shade{background-color:color-mix(in oklab,var(--dou-chart-surface)72%,transparent)}.dou-chart__range-window{box-sizing:border-box;--dou-chart-range-edge:color-mix(in oklab,var(--dou-color-text)32%,transparent);border-block:1px solid var(--dou-chart-range-edge);background-color:color-mix(in oklab,var(--dou-color-text)6%,transparent);cursor:inherit}.is-vertical>.dou-chart__range-window{border-block-start:none;border-block-end:none;border-inline:1px solid var(--dou-chart-range-edge)}.dou-chart__range-handle{box-sizing:border-box;border:1px solid var(--dou-color-border-strong);background-color:var(--dou-color-bg-surface);box-shadow:var(--dou-shadow-sm);outline:none;cursor:inherit;border-radius:4px;width:8px;height:20px;margin:6px 0 0 -4px}.dou-chart__range-handle:before{position:absolute;content:"";inset:-6px -4px}.dou-chart__range-handle:hover{border-color:var(--dou-color-text-tertiary)}.dou-chart__range-handle:focus-visible{outline:2px solid var(--dou-color-focus);outline-offset:2px}.is-vertical>.dou-chart__range-handle{width:20px;height:8px;margin:-4px 0 0 6px}.is-vertical>.dou-chart__range-handle:before{inset:-4px -6px}@media (pointer:coarse){.dou-chart__range-handle:before{inset:-10px -16px}.is-vertical>.dou-chart__range-handle:before{inset:-16px -10px}}}
|
package/dist/types/core/bar.d.ts
CHANGED
|
@@ -7,7 +7,10 @@ export interface BarStyle {
|
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Where a series' bars go in each x band: the offset of their near edge
|
|
10
|
-
* from the band's center,
|
|
10
|
+
* from the band's center, their width, and the room left between the
|
|
11
|
+
* bars of one band and the next, in px. The room grows with the band,
|
|
12
|
+
* from none below 2px to its full share from 12px, so zooming through
|
|
13
|
+
* never changes the look at once.
|
|
11
14
|
*/
|
|
12
15
|
export declare function barPlacement(band: number, slot: {
|
|
13
16
|
index: number;
|
|
@@ -15,13 +18,16 @@ export declare function barPlacement(band: number, slot: {
|
|
|
15
18
|
} | null): {
|
|
16
19
|
offset: number;
|
|
17
20
|
width: number;
|
|
21
|
+
room: number;
|
|
18
22
|
};
|
|
19
23
|
/**
|
|
20
24
|
* Draws bars from 0 (or from the slice of the stack below) to each value.
|
|
21
25
|
* The end away from 0 is rounded; in a stack, only the outermost slice's.
|
|
22
26
|
* Bars narrower than a pixel and a half are merged per pixel column into
|
|
23
27
|
* one bar from the lowest to the highest value there, which looks the
|
|
24
|
-
* same and keeps a million bars as cheap as a few hundred.
|
|
28
|
+
* same and keeps a million bars as cheap as a few hundred. The room between
|
|
29
|
+
* bars is a whole number of pixels, and narrows with the bands down to
|
|
30
|
+
* none (square, slices touching), so hundreds of days read as one even shape.
|
|
25
31
|
*/
|
|
26
32
|
export declare function drawBars(painter: Painter, series: ChartSeries<BarStyle>, view: ChartView, placement?: {
|
|
27
33
|
offset: number;
|
package/dist/zoom-layer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zoom-layer.js","names":["_sfc_main"],"sources":["../src/zoom-layer.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { holdPointer, useNamespace, type PointerHold } from 'dou-ui'\nimport { computed, useTemplateRef, watchPostEffect, type ComputedRef } from 'vue'\nimport type { Rect } from './core/painter'\n\n/**\n * What goes over the plot for zooming and selecting: the selection being\n * dragged or kept, and the range strip with its handles. Kept apart from\n * the chart, so a drag doesn't render the chart's slot again.\n */\nexport interface ZoomLayerState {\n /** The selection, in px from the chart's top left. */\n brush: ComputedRef<Rect | null>\n /** The strip, and the part of x shown (0 to 1 of the whole). */\n strip: ComputedRef<{ rect: Rect; horizontal: boolean; from: number; to: number } | null>\n /** The smallest part of x that can be shown, 0 to 1. */\n least: ComputedRef<number>\n /** How far a key moves a handle, 0 to 1. */\n step: ComputedRef<number>\n /** The x at each end, as the axis shows it. */\n texts: ComputedRef<[string, string]>\n labels: ComputedRef<[string, string]>\n /** Shows `from` to `to` (0 to 1); `settle` at the end of a drag. */\n show: (from: number, to: number, settle: boolean) => void\n /** Shows all of x. */\n reset: () => void\n /** A drag on the strip starts: the tooltip goes. */\n start: () => void\n /** What the strip's sketch is drawn from: a new value only when it has to be drawn again. */\n sketch: ComputedRef<unknown>\n /** Draws the series, small, on the strip's canvas. */\n paint: (canvas: HTMLCanvasElement) => void\n}\n\ndefineOptions({ name: 'DouChartZoomLayer' })\n\nconst { state } = defineProps<{ state: ZoomLayerState }>()\nconst ns = useNamespace('chart')\nconst { brush, strip } = state\nconst canvas = useTemplateRef<HTMLCanvasElement>('canvas')\n\nwatchPostEffect(() => {\n // not on `strip`: moving the shown part leaves the sketch as it is\n if (canvas.value && state.sketch.value) state.paint(canvas.value)\n})\n\nconst px = (r: Rect) => ({\n transform: `translate(${r.x}px, ${r.y}px)`,\n width: `${r.width}px`,\n height: `${r.height}px`,\n})\n\n/** The shown part and the dimmed parts on either side, in px. */\nconst parts = computed(() => {\n const s = strip.value\n if (!s) return null\n const { rect, horizontal } = s\n const length = horizontal ? rect.height : rect.width\n const start = horizontal ? rect.y : rect.x\n const a = start + s.from * length\n const b = start + s.to * length\n const stretch = (from: number, to: number): Rect =>\n horizontal\n ? { x: rect.x, y: from, width: rect.width, height: to - from }\n : { x: from, y: rect.y, width: to - from, height: rect.height }\n return {\n before: stretch(start, a),\n window: stretch(a, b),\n after: stretch(b, start + length),\n ends: [a, b] as const,\n }\n})\n\n/* dragging a handle, the shown part, or the strip around it */\n\ntype Grip = 'from' | 'to' | 'window'\nlet drag: {\n grip: Grip\n start: number\n from: number\n to: number\n hold: PointerHold\n id: number\n} | null = null\n\nfunction along(event: PointerEvent): number {\n const s = strip.value!\n const el = event.currentTarget as HTMLElement\n const box = el.closest(`.${ns.e('range')}`)!.getBoundingClientRect()\n return s.horizontal\n ? (event.clientY - box.top) / box.height\n : (event.clientX - box.left) / box.width\n}\n\nfunction onPointerDown(event: PointerEvent, grip: Grip | 'track') {\n if (event.button !== 0 || !strip.value) return\n event.stopPropagation()\n event.preventDefault()\n state.start()\n const s = strip.value\n let { from, to } = s\n const at = along(event)\n if (grip === 'track') {\n // a press beside the shown part moves it there, and drags it from there\n const span = to - from\n from = Math.min(Math.max(0, at - span / 2), 1 - span)\n to = from + span\n state.show(from, to, false)\n grip = 'window'\n }\n const el = event.currentTarget as HTMLElement\n const hold = holdPointer(event, el)\n hold.grab()\n try {\n el.setPointerCapture?.(event.pointerId)\n } catch {\n // the pointer is already gone\n }\n drag = { grip, start: at, from, to, hold, id: event.pointerId }\n}\n\nfunction onPointerMove(event: PointerEvent) {\n if (!drag || event.pointerId !== drag.id) return\n const d = along(event) - drag.start\n state.show(...moved(drag.grip, drag.from, drag.to, d), false)\n}\n\nfunction onPointerUp(event: PointerEvent) {\n if (!drag || event.pointerId !== drag.id) return\n const d = along(event) - drag.start\n const grip = drag.grip\n drag.hold.release()\n const { from, to } = drag\n drag = null\n state.show(...moved(grip, from, to, d), true)\n}\n\nfunction onPointerCancel() {\n drag?.hold.release()\n drag = null\n}\n\n/** `from` and `to` after `grip` moved by `d`, kept in the strip and apart by the least. */\nfunction moved(grip: Grip, from: number, to: number, d: number): [number, number] {\n const least = state.least.value\n if (grip === 'from') return [Math.min(Math.max(0, from + d), to - least), to]\n if (grip === 'to') return [from, Math.max(Math.min(1, to + d), from + least)]\n const shift = Math.min(Math.max(d, -from), 1 - to)\n return [from + shift, to + shift]\n}\n\n/* the keys on a handle */\n\nfunction onKeydown(event: KeyboardEvent, grip: 'from' | 'to') {\n const s = strip.value\n if (!s) return\n const step = state.step.value\n const keys: Record<string, number> = {\n ArrowLeft: -step,\n ArrowDown: s.horizontal ? step : -step,\n ArrowRight: step,\n ArrowUp: s.horizontal ? -step : step,\n PageDown: -step * 10,\n PageUp: step * 10,\n Home: -Infinity,\n End: Infinity,\n }\n // down a vertical strip is further along x\n if (s.horizontal) [keys.PageDown, keys.PageUp] = [step * 10, -step * 10]\n const d = keys[event.key]\n if (d === undefined) return\n event.preventDefault()\n const at = grip === 'from' ? s.from : s.to\n const next = Number.isFinite(d) ? at + d : d < 0 ? 0 : 1\n state.show(...moved(grip, s.from, s.to, next - at), true)\n}\n\nconst percent = (value: number) => Math.round(value * 1000) / 10\n</script>\n\n<template>\n <div v-if=\"brush\" :class=\"ns.e('brush')\" :style=\"px(brush)\" aria-hidden=\"true\" />\n <div\n v-if=\"strip && parts\"\n :class=\"[ns.e('range'), ns.is('vertical', strip.horizontal)]\"\n :style=\"px(strip.rect)\"\n @pointerdown=\"(e) => onPointerDown(e, 'track')\"\n @pointermove=\"onPointerMove\"\n @pointerup=\"onPointerUp\"\n @pointercancel=\"onPointerCancel\"\n @dblclick.stop=\"state.reset()\"\n @click.stop\n >\n <canvas ref=\"canvas\" :class=\"ns.e('range-canvas')\" aria-hidden=\"true\" />\n <div\n :class=\"ns.e('range-shade')\"\n :style=\"\n px({ ...parts.before, x: parts.before.x - strip.rect.x, y: parts.before.y - strip.rect.y })\n \"\n />\n <div\n :class=\"ns.e('range-shade')\"\n :style=\"\n px({ ...parts.after, x: parts.after.x - strip.rect.x, y: parts.after.y - strip.rect.y })\n \"\n />\n <div\n :class=\"ns.e('range-window')\"\n :style=\"\n px({ ...parts.window, x: parts.window.x - strip.rect.x, y: parts.window.y - strip.rect.y })\n \"\n @pointerdown=\"(e) => onPointerDown(e, 'window')\"\n />\n <div\n v-for=\"(grip, i) in ['from', 'to'] as const\"\n :key=\"grip\"\n :class=\"ns.e('range-handle')\"\n role=\"slider\"\n tabindex=\"0\"\n :aria-label=\"state.labels.value[i]\"\n :aria-orientation=\"strip.horizontal ? 'vertical' : 'horizontal'\"\n aria-valuemin=\"0\"\n aria-valuemax=\"100\"\n :aria-valuenow=\"percent(grip === 'from' ? strip.from : strip.to)\"\n :aria-valuetext=\"state.texts.value[i]\"\n :style=\"\n strip.horizontal\n ? { transform: `translate(0, ${parts.ends[i]! - strip.rect.y}px)` }\n : { transform: `translate(${parts.ends[i]! - strip.rect.x}px, 0)` }\n \"\n @pointerdown=\"(e) => onPointerDown(e, grip)\"\n @keydown=\"(e) => onKeydown(e, grip)\"\n />\n </div>\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"zoom-layer.js","names":["_sfc_main"],"sources":["../src/zoom-layer.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { holdPointer, useNamespace, type PointerHold } from 'dou-ui'\nimport { computed, useTemplateRef, watchPostEffect, type ComputedRef } from 'vue'\nimport type { Rect } from './core/painter'\n\n/**\n * What goes over the plot for zooming and selecting: the selection being\n * dragged or kept, and the range strip with its handles. Kept apart from\n * the chart, so a drag doesn't render the chart's slot again.\n */\nexport interface ZoomLayerState {\n /** The selection, in px from the chart's top left. */\n brush: ComputedRef<Rect | null>\n /** The strip, and the part of x shown (0 to 1 of the whole). */\n strip: ComputedRef<{ rect: Rect; horizontal: boolean; from: number; to: number } | null>\n /** The smallest part of x that can be shown, 0 to 1. */\n least: ComputedRef<number>\n /** How far a key moves a handle, 0 to 1. */\n step: ComputedRef<number>\n /** The x at each end, as the axis shows it. */\n texts: ComputedRef<[string, string]>\n labels: ComputedRef<[string, string]>\n /** Shows `from` to `to` (0 to 1); `settle` at the end of a drag. */\n show: (from: number, to: number, settle: boolean) => void\n /** Shows all of x. */\n reset: () => void\n /** A drag on the strip starts: the tooltip goes. */\n start: () => void\n /** What the strip's sketch is drawn from: a new value only when it has to be drawn again. */\n sketch: ComputedRef<unknown>\n /** Draws the series, small, on the strip's canvas. */\n paint: (canvas: HTMLCanvasElement) => void\n}\n\ndefineOptions({ name: 'DouChartZoomLayer' })\n\nconst { state } = defineProps<{ state: ZoomLayerState }>()\nconst ns = useNamespace('chart')\nconst { brush, strip } = state\nconst canvas = useTemplateRef<HTMLCanvasElement>('canvas')\nconst rangeEl = useTemplateRef<HTMLElement>('range')\n\nwatchPostEffect(() => {\n // not on `strip`: moving the shown part leaves the sketch as it is\n if (canvas.value && state.sketch.value) state.paint(canvas.value)\n})\n\nconst px = (r: Rect) => ({\n transform: `translate(${r.x}px, ${r.y}px)`,\n width: `${r.width}px`,\n height: `${r.height}px`,\n})\n\n/** The shown part and the dimmed parts on either side, in px. */\nconst parts = computed(() => {\n const s = strip.value\n if (!s) return null\n const { rect, horizontal } = s\n const length = horizontal ? rect.height : rect.width\n const start = horizontal ? rect.y : rect.x\n const a = start + s.from * length\n const b = start + s.to * length\n const stretch = (from: number, to: number): Rect =>\n horizontal\n ? { x: rect.x, y: from, width: rect.width, height: to - from }\n : { x: from, y: rect.y, width: to - from, height: rect.height }\n return {\n before: stretch(start, a),\n window: stretch(a, b),\n after: stretch(b, start + length),\n ends: [a, b] as const,\n }\n})\n\n/* dragging a handle, the shown part, or the strip around it */\n\ntype Grip = 'from' | 'to' | 'window'\nlet drag: {\n grip: Grip\n start: number\n from: number\n to: number\n hold: PointerHold\n id: number\n} | null = null\n\nfunction along(event: PointerEvent): number {\n const s = strip.value!\n const box = rangeEl.value!.getBoundingClientRect()\n return s.horizontal\n ? (event.clientY - box.top) / box.height\n : (event.clientX - box.left) / box.width\n}\n\n/** How near a handle (px) a press takes it, by a finger and by a mouse. */\nconst REACH = { touch: 20, mouse: 8 }\n/** What is kept in the middle of the shown part to pan it by, at the least (px). */\nconst MIDDLE = 6\n\n/**\n * What a press at `at` (0 to 1 along the strip) takes hold of: a handle\n * when near it, the shown part when on it, or else the strip. Inside the\n * shown part a handle takes only its outer quarter, so even a sliver of a\n * week in years can be dragged by its middle; outside, a handle reaches\n * as far as a finger. A handle at the chart's edge has no room outside\n * (the chart cuts it off), so it takes what it misses from inside instead.\n */\nfunction gripAt(event: PointerEvent, at: number): Grip | 'track' {\n const s = strip.value!\n const length = s.horizontal ? s.rect.height : s.rect.width\n const x = at * length\n const a = s.from * length\n const b = s.to * length\n const reach = event.pointerType === 'mouse' ? REACH.mouse : REACH.touch\n // the room past each end of the strip, to the chart's edges\n const box = rangeEl.value!.getBoundingClientRect()\n const chart = rangeEl.value!.closest(`.${ns.b()}`)?.getBoundingClientRect() ?? box\n const [startRoom, endRoom] = s.horizontal\n ? [box.top - chart.top, chart.bottom - box.bottom]\n : [box.left - chart.left, chart.right - box.right]\n const span = b - a\n const inner = (outside: number) => Math.max(Math.min(reach, span / 4), reach - outside)\n if (x > a && x < b) {\n let toFrom = inner(a + startRoom)\n let toTo = inner(length - b + endRoom)\n // more than the shown part leaves for its middle (6px to pan it by):\n // shared out as each asks\n const room = Math.max(0, span - MIDDLE)\n const over = (toFrom + toTo) / room\n if (over > 1) [toFrom, toTo] = [toFrom / over, toTo / over]\n if (x - a <= toFrom) return 'from'\n if (b - x <= toTo) return 'to'\n return 'window'\n }\n if (x <= a && a - x <= reach) return 'from'\n if (x >= b && x - b <= reach) return 'to'\n return 'track'\n}\n\n/** The pointer that `gripAt` would give for a mouse over the strip. */\nfunction cursorOf(grip: Grip | 'track'): string {\n if (grip === 'window') return 'grab'\n if (grip === 'track') return 'pointer'\n return strip.value?.horizontal ? 'ns-resize' : 'ew-resize'\n}\n\nfunction onPointerDown(event: PointerEvent) {\n if (event.button !== 0 || !strip.value) return\n event.stopPropagation()\n event.preventDefault()\n state.start()\n const s = strip.value\n let { from, to } = s\n const at = along(event)\n let grip = gripAt(event, at)\n if (grip === 'track') {\n // a press beside the shown part moves it there, and drags it from there\n const span = to - from\n from = Math.min(Math.max(0, at - span / 2), 1 - span)\n to = from + span\n state.show(from, to, false)\n grip = 'window'\n }\n const el = event.currentTarget as HTMLElement\n const hold = holdPointer(event, el)\n hold.grab()\n try {\n el.setPointerCapture?.(event.pointerId)\n } catch {\n // the pointer is already gone\n }\n drag = { grip, start: at, from, to, hold, id: event.pointerId }\n}\n\nfunction onPointerMove(event: PointerEvent) {\n // hovering: the pointer shows what a press here would take\n if (!drag && strip.value && event.pointerType === 'mouse')\n rangeEl.value!.style.cursor = cursorOf(gripAt(event, along(event)))\n if (!drag || event.pointerId !== drag.id) return\n const d = along(event) - drag.start\n state.show(...moved(drag.grip, drag.from, drag.to, d), false)\n}\n\nfunction onPointerUp(event: PointerEvent) {\n if (!drag || event.pointerId !== drag.id) return\n const d = along(event) - drag.start\n const grip = drag.grip\n drag.hold.release()\n const { from, to } = drag\n drag = null\n state.show(...moved(grip, from, to, d), true)\n}\n\nfunction onPointerCancel() {\n drag?.hold.release()\n drag = null\n}\n\n/** `from` and `to` after `grip` moved by `d`, kept in the strip and apart by the least. */\nfunction moved(grip: Grip, from: number, to: number, d: number): [number, number] {\n const least = state.least.value\n if (grip === 'from') return [Math.min(Math.max(0, from + d), to - least), to]\n if (grip === 'to') return [from, Math.max(Math.min(1, to + d), from + least)]\n const shift = Math.min(Math.max(d, -from), 1 - to)\n return [from + shift, to + shift]\n}\n\n/* the keys on a handle */\n\nfunction onKeydown(event: KeyboardEvent, grip: 'from' | 'to') {\n const s = strip.value\n if (!s) return\n const step = state.step.value\n const keys: Record<string, number> = {\n ArrowLeft: -step,\n ArrowDown: s.horizontal ? step : -step,\n ArrowRight: step,\n ArrowUp: s.horizontal ? -step : step,\n PageDown: -step * 10,\n PageUp: step * 10,\n Home: -Infinity,\n End: Infinity,\n }\n // down a vertical strip is further along x\n if (s.horizontal) [keys.PageDown, keys.PageUp] = [step * 10, -step * 10]\n const d = keys[event.key]\n if (d === undefined) return\n event.preventDefault()\n const at = grip === 'from' ? s.from : s.to\n const next = Number.isFinite(d) ? at + d : d < 0 ? 0 : 1\n state.show(...moved(grip, s.from, s.to, next - at), true)\n}\n\nconst percent = (value: number) => Math.round(value * 1000) / 10\n</script>\n\n<template>\n <div v-if=\"brush\" :class=\"ns.e('brush')\" :style=\"px(brush)\" aria-hidden=\"true\" />\n <div\n v-if=\"strip && parts\"\n :class=\"[ns.e('range'), ns.is('vertical', strip.horizontal)]\"\n ref=\"range\"\n :style=\"px(strip.rect)\"\n @pointerdown=\"onPointerDown\"\n @pointermove=\"onPointerMove\"\n @pointerup=\"onPointerUp\"\n @pointercancel=\"onPointerCancel\"\n @dblclick.stop=\"state.reset()\"\n @click.stop\n >\n <canvas ref=\"canvas\" :class=\"ns.e('range-canvas')\" aria-hidden=\"true\" />\n <div\n :class=\"ns.e('range-shade')\"\n :style=\"\n px({ ...parts.before, x: parts.before.x - strip.rect.x, y: parts.before.y - strip.rect.y })\n \"\n />\n <div\n :class=\"ns.e('range-shade')\"\n :style=\"\n px({ ...parts.after, x: parts.after.x - strip.rect.x, y: parts.after.y - strip.rect.y })\n \"\n />\n <div\n :class=\"ns.e('range-window')\"\n :style=\"\n px({ ...parts.window, x: parts.window.x - strip.rect.x, y: parts.window.y - strip.rect.y })\n \"\n />\n <div\n v-for=\"(grip, i) in ['from', 'to'] as const\"\n :key=\"grip\"\n :class=\"ns.e('range-handle')\"\n role=\"slider\"\n tabindex=\"0\"\n :aria-label=\"state.labels.value[i]\"\n :aria-orientation=\"strip.horizontal ? 'vertical' : 'horizontal'\"\n aria-valuemin=\"0\"\n aria-valuemax=\"100\"\n :aria-valuenow=\"percent(grip === 'from' ? strip.from : strip.to)\"\n :aria-valuetext=\"state.texts.value[i]\"\n :style=\"\n strip.horizontal\n ? { transform: `translate(0, ${parts.ends[i]! - strip.rect.y}px)` }\n : { transform: `translate(${parts.ends[i]! - strip.rect.x}px, 0)` }\n \"\n @keydown=\"(e) => onKeydown(e, grip)\"\n />\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -6,9 +6,17 @@ var _hoisted_1 = [
|
|
|
6
6
|
"aria-orientation",
|
|
7
7
|
"aria-valuenow",
|
|
8
8
|
"aria-valuetext",
|
|
9
|
-
"onPointerdown",
|
|
10
9
|
"onKeydown"
|
|
11
10
|
];
|
|
11
|
+
var MIDDLE = 6;
|
|
12
|
+
/**
|
|
13
|
+
* What a press at `at` (0 to 1 along the strip) takes hold of: a handle
|
|
14
|
+
* when near it, the shown part when on it, or else the strip. Inside the
|
|
15
|
+
* shown part a handle takes only its outer quarter, so even a sliver of a
|
|
16
|
+
* week in years can be dragged by its middle; outside, a handle reaches
|
|
17
|
+
* as far as a finger. A handle at the chart's edge has no room outside
|
|
18
|
+
* (the chart cuts it off), so it takes what it misses from inside instead.
|
|
19
|
+
*/
|
|
12
20
|
var zoom_layer_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
13
21
|
name: "DouChartZoomLayer",
|
|
14
22
|
__name: "zoom-layer",
|
|
@@ -17,6 +25,7 @@ var zoom_layer_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
17
25
|
const ns = useNamespace("chart");
|
|
18
26
|
const { brush, strip } = __props.state;
|
|
19
27
|
const canvas = useTemplateRef("canvas");
|
|
28
|
+
const rangeEl = useTemplateRef("range");
|
|
20
29
|
watchPostEffect(() => {
|
|
21
30
|
if (canvas.value && __props.state.sketch.value) __props.state.paint(canvas.value);
|
|
22
31
|
});
|
|
@@ -55,16 +64,55 @@ var zoom_layer_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
55
64
|
let drag = null;
|
|
56
65
|
function along(event) {
|
|
57
66
|
const s = strip.value;
|
|
58
|
-
const box =
|
|
67
|
+
const box = rangeEl.value.getBoundingClientRect();
|
|
59
68
|
return s.horizontal ? (event.clientY - box.top) / box.height : (event.clientX - box.left) / box.width;
|
|
60
69
|
}
|
|
61
|
-
|
|
70
|
+
/** How near a handle (px) a press takes it, by a finger and by a mouse. */
|
|
71
|
+
const REACH = {
|
|
72
|
+
touch: 20,
|
|
73
|
+
mouse: 8
|
|
74
|
+
};
|
|
75
|
+
/** What is kept in the middle of the shown part to pan it by, at the least (px). */
|
|
76
|
+
function gripAt(event, at) {
|
|
77
|
+
const s = strip.value;
|
|
78
|
+
const length = s.horizontal ? s.rect.height : s.rect.width;
|
|
79
|
+
const x = at * length;
|
|
80
|
+
const a = s.from * length;
|
|
81
|
+
const b = s.to * length;
|
|
82
|
+
const reach = event.pointerType === "mouse" ? REACH.mouse : REACH.touch;
|
|
83
|
+
const box = rangeEl.value.getBoundingClientRect();
|
|
84
|
+
const chart = rangeEl.value.closest(`.${ns.b()}`)?.getBoundingClientRect() ?? box;
|
|
85
|
+
const [startRoom, endRoom] = s.horizontal ? [box.top - chart.top, chart.bottom - box.bottom] : [box.left - chart.left, chart.right - box.right];
|
|
86
|
+
const span = b - a;
|
|
87
|
+
const inner = (outside) => Math.max(Math.min(reach, span / 4), reach - outside);
|
|
88
|
+
if (x > a && x < b) {
|
|
89
|
+
let toFrom = inner(a + startRoom);
|
|
90
|
+
let toTo = inner(length - b + endRoom);
|
|
91
|
+
const room = Math.max(0, span - MIDDLE);
|
|
92
|
+
const over = (toFrom + toTo) / room;
|
|
93
|
+
if (over > 1) [toFrom, toTo] = [toFrom / over, toTo / over];
|
|
94
|
+
if (x - a <= toFrom) return "from";
|
|
95
|
+
if (b - x <= toTo) return "to";
|
|
96
|
+
return "window";
|
|
97
|
+
}
|
|
98
|
+
if (x <= a && a - x <= reach) return "from";
|
|
99
|
+
if (x >= b && x - b <= reach) return "to";
|
|
100
|
+
return "track";
|
|
101
|
+
}
|
|
102
|
+
/** The pointer that `gripAt` would give for a mouse over the strip. */
|
|
103
|
+
function cursorOf(grip) {
|
|
104
|
+
if (grip === "window") return "grab";
|
|
105
|
+
if (grip === "track") return "pointer";
|
|
106
|
+
return strip.value?.horizontal ? "ns-resize" : "ew-resize";
|
|
107
|
+
}
|
|
108
|
+
function onPointerDown(event) {
|
|
62
109
|
if (event.button !== 0 || !strip.value) return;
|
|
63
110
|
event.stopPropagation();
|
|
64
111
|
event.preventDefault();
|
|
65
112
|
__props.state.start();
|
|
66
113
|
let { from, to } = strip.value;
|
|
67
114
|
const at = along(event);
|
|
115
|
+
let grip = gripAt(event, at);
|
|
68
116
|
if (grip === "track") {
|
|
69
117
|
const span = to - from;
|
|
70
118
|
from = Math.min(Math.max(0, at - span / 2), 1 - span);
|
|
@@ -88,6 +136,7 @@ var zoom_layer_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
88
136
|
};
|
|
89
137
|
}
|
|
90
138
|
function onPointerMove(event) {
|
|
139
|
+
if (!drag && strip.value && event.pointerType === "mouse") rangeEl.value.style.cursor = cursorOf(gripAt(event, along(event)));
|
|
91
140
|
if (!drag || event.pointerId !== drag.id) return;
|
|
92
141
|
const d = along(event) - drag.start;
|
|
93
142
|
__props.state.show(...moved(drag.grip, drag.from, drag.to, d), false);
|
|
@@ -145,13 +194,14 @@ var zoom_layer_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
145
194
|
}, null, 6)) : createCommentVNode("", true), unref(strip) && parts.value ? (openBlock(), createElementBlock("div", {
|
|
146
195
|
key: 1,
|
|
147
196
|
class: normalizeClass([unref(ns).e("range"), unref(ns).is("vertical", unref(strip).horizontal)]),
|
|
197
|
+
ref: "range",
|
|
148
198
|
style: normalizeStyle(px(unref(strip).rect)),
|
|
149
|
-
onPointerdown:
|
|
199
|
+
onPointerdown: onPointerDown,
|
|
150
200
|
onPointermove: onPointerMove,
|
|
151
201
|
onPointerup: onPointerUp,
|
|
152
202
|
onPointercancel: onPointerCancel,
|
|
153
|
-
onDblclick: _cache[
|
|
154
|
-
onClick: _cache[
|
|
203
|
+
onDblclick: _cache[0] || (_cache[0] = withModifiers(($event) => __props.state.reset(), ["stop"])),
|
|
204
|
+
onClick: _cache[1] || (_cache[1] = withModifiers(() => {}, ["stop"]))
|
|
155
205
|
}, [
|
|
156
206
|
createElementVNode("canvas", {
|
|
157
207
|
ref_key: "canvas",
|
|
@@ -181,9 +231,8 @@ var zoom_layer_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
181
231
|
...parts.value.window,
|
|
182
232
|
x: parts.value.window.x - unref(strip).rect.x,
|
|
183
233
|
y: parts.value.window.y - unref(strip).rect.y
|
|
184
|
-
}))
|
|
185
|
-
|
|
186
|
-
}, null, 38),
|
|
234
|
+
}))
|
|
235
|
+
}, null, 6),
|
|
187
236
|
(openBlock(), createElementBlock(Fragment, null, renderList(["from", "to"], (grip, i) => {
|
|
188
237
|
return createElementVNode("div", {
|
|
189
238
|
key: grip,
|
|
@@ -197,7 +246,6 @@ var zoom_layer_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
197
246
|
"aria-valuenow": percent(grip === "from" ? unref(strip).from : unref(strip).to),
|
|
198
247
|
"aria-valuetext": __props.state.texts.value[i],
|
|
199
248
|
style: normalizeStyle(unref(strip).horizontal ? { transform: `translate(0, ${parts.value.ends[i] - unref(strip).rect.y}px)` } : { transform: `translate(${parts.value.ends[i] - unref(strip).rect.x}px, 0)` }),
|
|
200
|
-
onPointerdown: (e) => onPointerDown(e, grip),
|
|
201
249
|
onKeydown: (e) => onKeydown(e, grip)
|
|
202
250
|
}, null, 46, _hoisted_1);
|
|
203
251
|
}), 64))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zoom-layer.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_Fragment","_unref","_normalizeClass","_normalizeStyle","_createCommentVNode","_withModifiers","_createElementVNode","_renderList"],"sources":["../src/zoom-layer.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { holdPointer, useNamespace, type PointerHold } from 'dou-ui'\nimport { computed, useTemplateRef, watchPostEffect, type ComputedRef } from 'vue'\nimport type { Rect } from './core/painter'\n\n/**\n * What goes over the plot for zooming and selecting: the selection being\n * dragged or kept, and the range strip with its handles. Kept apart from\n * the chart, so a drag doesn't render the chart's slot again.\n */\nexport interface ZoomLayerState {\n /** The selection, in px from the chart's top left. */\n brush: ComputedRef<Rect | null>\n /** The strip, and the part of x shown (0 to 1 of the whole). */\n strip: ComputedRef<{ rect: Rect; horizontal: boolean; from: number; to: number } | null>\n /** The smallest part of x that can be shown, 0 to 1. */\n least: ComputedRef<number>\n /** How far a key moves a handle, 0 to 1. */\n step: ComputedRef<number>\n /** The x at each end, as the axis shows it. */\n texts: ComputedRef<[string, string]>\n labels: ComputedRef<[string, string]>\n /** Shows `from` to `to` (0 to 1); `settle` at the end of a drag. */\n show: (from: number, to: number, settle: boolean) => void\n /** Shows all of x. */\n reset: () => void\n /** A drag on the strip starts: the tooltip goes. */\n start: () => void\n /** What the strip's sketch is drawn from: a new value only when it has to be drawn again. */\n sketch: ComputedRef<unknown>\n /** Draws the series, small, on the strip's canvas. */\n paint: (canvas: HTMLCanvasElement) => void\n}\n\ndefineOptions({ name: 'DouChartZoomLayer' })\n\nconst { state } = defineProps<{ state: ZoomLayerState }>()\nconst ns = useNamespace('chart')\nconst { brush, strip } = state\nconst canvas = useTemplateRef<HTMLCanvasElement>('canvas')\n\nwatchPostEffect(() => {\n // not on `strip`: moving the shown part leaves the sketch as it is\n if (canvas.value && state.sketch.value) state.paint(canvas.value)\n})\n\nconst px = (r: Rect) => ({\n transform: `translate(${r.x}px, ${r.y}px)`,\n width: `${r.width}px`,\n height: `${r.height}px`,\n})\n\n/** The shown part and the dimmed parts on either side, in px. */\nconst parts = computed(() => {\n const s = strip.value\n if (!s) return null\n const { rect, horizontal } = s\n const length = horizontal ? rect.height : rect.width\n const start = horizontal ? rect.y : rect.x\n const a = start + s.from * length\n const b = start + s.to * length\n const stretch = (from: number, to: number): Rect =>\n horizontal\n ? { x: rect.x, y: from, width: rect.width, height: to - from }\n : { x: from, y: rect.y, width: to - from, height: rect.height }\n return {\n before: stretch(start, a),\n window: stretch(a, b),\n after: stretch(b, start + length),\n ends: [a, b] as const,\n }\n})\n\n/* dragging a handle, the shown part, or the strip around it */\n\ntype Grip = 'from' | 'to' | 'window'\nlet drag: {\n grip: Grip\n start: number\n from: number\n to: number\n hold: PointerHold\n id: number\n} | null = null\n\nfunction along(event: PointerEvent): number {\n const s = strip.value!\n const el = event.currentTarget as HTMLElement\n const box = el.closest(`.${ns.e('range')}`)!.getBoundingClientRect()\n return s.horizontal\n ? (event.clientY - box.top) / box.height\n : (event.clientX - box.left) / box.width\n}\n\nfunction onPointerDown(event: PointerEvent, grip: Grip | 'track') {\n if (event.button !== 0 || !strip.value) return\n event.stopPropagation()\n event.preventDefault()\n state.start()\n const s = strip.value\n let { from, to } = s\n const at = along(event)\n if (grip === 'track') {\n // a press beside the shown part moves it there, and drags it from there\n const span = to - from\n from = Math.min(Math.max(0, at - span / 2), 1 - span)\n to = from + span\n state.show(from, to, false)\n grip = 'window'\n }\n const el = event.currentTarget as HTMLElement\n const hold = holdPointer(event, el)\n hold.grab()\n try {\n el.setPointerCapture?.(event.pointerId)\n } catch {\n // the pointer is already gone\n }\n drag = { grip, start: at, from, to, hold, id: event.pointerId }\n}\n\nfunction onPointerMove(event: PointerEvent) {\n if (!drag || event.pointerId !== drag.id) return\n const d = along(event) - drag.start\n state.show(...moved(drag.grip, drag.from, drag.to, d), false)\n}\n\nfunction onPointerUp(event: PointerEvent) {\n if (!drag || event.pointerId !== drag.id) return\n const d = along(event) - drag.start\n const grip = drag.grip\n drag.hold.release()\n const { from, to } = drag\n drag = null\n state.show(...moved(grip, from, to, d), true)\n}\n\nfunction onPointerCancel() {\n drag?.hold.release()\n drag = null\n}\n\n/** `from` and `to` after `grip` moved by `d`, kept in the strip and apart by the least. */\nfunction moved(grip: Grip, from: number, to: number, d: number): [number, number] {\n const least = state.least.value\n if (grip === 'from') return [Math.min(Math.max(0, from + d), to - least), to]\n if (grip === 'to') return [from, Math.max(Math.min(1, to + d), from + least)]\n const shift = Math.min(Math.max(d, -from), 1 - to)\n return [from + shift, to + shift]\n}\n\n/* the keys on a handle */\n\nfunction onKeydown(event: KeyboardEvent, grip: 'from' | 'to') {\n const s = strip.value\n if (!s) return\n const step = state.step.value\n const keys: Record<string, number> = {\n ArrowLeft: -step,\n ArrowDown: s.horizontal ? step : -step,\n ArrowRight: step,\n ArrowUp: s.horizontal ? -step : step,\n PageDown: -step * 10,\n PageUp: step * 10,\n Home: -Infinity,\n End: Infinity,\n }\n // down a vertical strip is further along x\n if (s.horizontal) [keys.PageDown, keys.PageUp] = [step * 10, -step * 10]\n const d = keys[event.key]\n if (d === undefined) return\n event.preventDefault()\n const at = grip === 'from' ? s.from : s.to\n const next = Number.isFinite(d) ? at + d : d < 0 ? 0 : 1\n state.show(...moved(grip, s.from, s.to, next - at), true)\n}\n\nconst percent = (value: number) => Math.round(value * 1000) / 10\n</script>\n\n<template>\n <div v-if=\"brush\" :class=\"ns.e('brush')\" :style=\"px(brush)\" aria-hidden=\"true\" />\n <div\n v-if=\"strip && parts\"\n :class=\"[ns.e('range'), ns.is('vertical', strip.horizontal)]\"\n :style=\"px(strip.rect)\"\n @pointerdown=\"(e) => onPointerDown(e, 'track')\"\n @pointermove=\"onPointerMove\"\n @pointerup=\"onPointerUp\"\n @pointercancel=\"onPointerCancel\"\n @dblclick.stop=\"state.reset()\"\n @click.stop\n >\n <canvas ref=\"canvas\" :class=\"ns.e('range-canvas')\" aria-hidden=\"true\" />\n <div\n :class=\"ns.e('range-shade')\"\n :style=\"\n px({ ...parts.before, x: parts.before.x - strip.rect.x, y: parts.before.y - strip.rect.y })\n \"\n />\n <div\n :class=\"ns.e('range-shade')\"\n :style=\"\n px({ ...parts.after, x: parts.after.x - strip.rect.x, y: parts.after.y - strip.rect.y })\n \"\n />\n <div\n :class=\"ns.e('range-window')\"\n :style=\"\n px({ ...parts.window, x: parts.window.x - strip.rect.x, y: parts.window.y - strip.rect.y })\n \"\n @pointerdown=\"(e) => onPointerDown(e, 'window')\"\n />\n <div\n v-for=\"(grip, i) in ['from', 'to'] as const\"\n :key=\"grip\"\n :class=\"ns.e('range-handle')\"\n role=\"slider\"\n tabindex=\"0\"\n :aria-label=\"state.labels.value[i]\"\n :aria-orientation=\"strip.horizontal ? 'vertical' : 'horizontal'\"\n aria-valuemin=\"0\"\n aria-valuemax=\"100\"\n :aria-valuenow=\"percent(grip === 'from' ? strip.from : strip.to)\"\n :aria-valuetext=\"state.texts.value[i]\"\n :style=\"\n strip.horizontal\n ? { transform: `translate(0, ${parts.ends[i]! - strip.rect.y}px)` }\n : { transform: `translate(${parts.ends[i]! - strip.rect.x}px, 0)` }\n \"\n @pointerdown=\"(e) => onPointerDown(e, grip)\"\n @keydown=\"(e) => onKeydown(e, grip)\"\n />\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;EAqCA,MAAM,KAAK,aAAa,OAAO;EAC/B,MAAM,EAAE,OAAO,UAAU,QAAA;EACzB,MAAM,SAAS,eAAkC,QAAQ;EAEzD,sBAAsB;GAEpB,IAAI,OAAO,SAAS,QAAA,MAAM,OAAO,OAAO,QAAA,MAAM,MAAM,OAAO,KAAK;EAClE,CAAC;EAED,MAAM,MAAM,OAAa;GACvB,WAAW,aAAa,EAAE,EAAE,MAAM,EAAE,EAAE;GACtC,OAAO,GAAG,EAAE,MAAM;GAClB,QAAQ,GAAG,EAAE,OAAO;EACtB;;EAGA,MAAM,QAAQ,eAAe;GAC3B,MAAM,IAAI,MAAM;GAChB,IAAI,CAAC,GAAG,OAAO;GACf,MAAM,EAAE,MAAM,eAAe;GAC7B,MAAM,SAAS,aAAa,KAAK,SAAS,KAAK;GAC/C,MAAM,QAAQ,aAAa,KAAK,IAAI,KAAK;GACzC,MAAM,IAAI,QAAQ,EAAE,OAAO;GAC3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,eAAED,MAAA,EAAA,CAAE,CAAC,EAAC,cAAA,CAAA;MACZ,MAAK;MACL,UAAS;MACR,cAAY,QAAA,MAAM,OAAO,MAAM;MAC/B,oBAAkBA,MAAA,KAAA,CAAK,CAAC,aAAU,aAAA;MACnC,iBAAc;MACd,iBAAc;MACb,iBAAe,QAAQ,SAAI,SAAcA,MAAA,KAAA,CAAK,CAAC,OAAOA,MAAA,KAAA,CAAK,CAAC,EAAE;MAC9D,kBAAgB,QAAA,MAAM,MAAM,MAAM;MAClC,OAAKE,eAAWF,MAAA,KAAA,CAAK,CAAC,aAAoD,EAAA,WAAA,gBAAA,MAAA,MAAM,KAAK,KAAMA,MAAA,KAAA,CAAK,CAAC,KAAK,EAAC,KAAA,IAA8C,EAAA,WAAA,aAAA,MAAA,MAAM,KAAK,KAAMA,MAAA,KAAA,CAAK,CAAC,KAAK,EAAC,QAAA,C;MAKlL,gBAAc,MAAM,cAAc,GAAG,IAAI;MACzC,YAAU,MAAM,UAAU,GAAG,IAAI"}
|
|
1
|
+
{"version":3,"file":"zoom-layer.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_Fragment","_unref","_normalizeClass","_normalizeStyle","_createCommentVNode","_withModifiers","_createElementVNode","_renderList"],"sources":["../src/zoom-layer.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { holdPointer, useNamespace, type PointerHold } from 'dou-ui'\nimport { computed, useTemplateRef, watchPostEffect, type ComputedRef } from 'vue'\nimport type { Rect } from './core/painter'\n\n/**\n * What goes over the plot for zooming and selecting: the selection being\n * dragged or kept, and the range strip with its handles. Kept apart from\n * the chart, so a drag doesn't render the chart's slot again.\n */\nexport interface ZoomLayerState {\n /** The selection, in px from the chart's top left. */\n brush: ComputedRef<Rect | null>\n /** The strip, and the part of x shown (0 to 1 of the whole). */\n strip: ComputedRef<{ rect: Rect; horizontal: boolean; from: number; to: number } | null>\n /** The smallest part of x that can be shown, 0 to 1. */\n least: ComputedRef<number>\n /** How far a key moves a handle, 0 to 1. */\n step: ComputedRef<number>\n /** The x at each end, as the axis shows it. */\n texts: ComputedRef<[string, string]>\n labels: ComputedRef<[string, string]>\n /** Shows `from` to `to` (0 to 1); `settle` at the end of a drag. */\n show: (from: number, to: number, settle: boolean) => void\n /** Shows all of x. */\n reset: () => void\n /** A drag on the strip starts: the tooltip goes. */\n start: () => void\n /** What the strip's sketch is drawn from: a new value only when it has to be drawn again. */\n sketch: ComputedRef<unknown>\n /** Draws the series, small, on the strip's canvas. */\n paint: (canvas: HTMLCanvasElement) => void\n}\n\ndefineOptions({ name: 'DouChartZoomLayer' })\n\nconst { state } = defineProps<{ state: ZoomLayerState }>()\nconst ns = useNamespace('chart')\nconst { brush, strip } = state\nconst canvas = useTemplateRef<HTMLCanvasElement>('canvas')\nconst rangeEl = useTemplateRef<HTMLElement>('range')\n\nwatchPostEffect(() => {\n // not on `strip`: moving the shown part leaves the sketch as it is\n if (canvas.value && state.sketch.value) state.paint(canvas.value)\n})\n\nconst px = (r: Rect) => ({\n transform: `translate(${r.x}px, ${r.y}px)`,\n width: `${r.width}px`,\n height: `${r.height}px`,\n})\n\n/** The shown part and the dimmed parts on either side, in px. */\nconst parts = computed(() => {\n const s = strip.value\n if (!s) return null\n const { rect, horizontal } = s\n const length = horizontal ? rect.height : rect.width\n const start = horizontal ? rect.y : rect.x\n const a = start + s.from * length\n const b = start + s.to * length\n const stretch = (from: number, to: number): Rect =>\n horizontal\n ? { x: rect.x, y: from, width: rect.width, height: to - from }\n : { x: from, y: rect.y, width: to - from, height: rect.height }\n return {\n before: stretch(start, a),\n window: stretch(a, b),\n after: stretch(b, start + length),\n ends: [a, b] as const,\n }\n})\n\n/* dragging a handle, the shown part, or the strip around it */\n\ntype Grip = 'from' | 'to' | 'window'\nlet drag: {\n grip: Grip\n start: number\n from: number\n to: number\n hold: PointerHold\n id: number\n} | null = null\n\nfunction along(event: PointerEvent): number {\n const s = strip.value!\n const box = rangeEl.value!.getBoundingClientRect()\n return s.horizontal\n ? (event.clientY - box.top) / box.height\n : (event.clientX - box.left) / box.width\n}\n\n/** How near a handle (px) a press takes it, by a finger and by a mouse. */\nconst REACH = { touch: 20, mouse: 8 }\n/** What is kept in the middle of the shown part to pan it by, at the least (px). */\nconst MIDDLE = 6\n\n/**\n * What a press at `at` (0 to 1 along the strip) takes hold of: a handle\n * when near it, the shown part when on it, or else the strip. Inside the\n * shown part a handle takes only its outer quarter, so even a sliver of a\n * week in years can be dragged by its middle; outside, a handle reaches\n * as far as a finger. A handle at the chart's edge has no room outside\n * (the chart cuts it off), so it takes what it misses from inside instead.\n */\nfunction gripAt(event: PointerEvent, at: number): Grip | 'track' {\n const s = strip.value!\n const length = s.horizontal ? s.rect.height : s.rect.width\n const x = at * length\n const a = s.from * length\n const b = s.to * length\n const reach = event.pointerType === 'mouse' ? REACH.mouse : REACH.touch\n // the room past each end of the strip, to the chart's edges\n const box = rangeEl.value!.getBoundingClientRect()\n const chart = rangeEl.value!.closest(`.${ns.b()}`)?.getBoundingClientRect() ?? box\n const [startRoom, endRoom] = s.horizontal\n ? [box.top - chart.top, chart.bottom - box.bottom]\n : [box.left - chart.left, chart.right - box.right]\n const span = b - a\n const inner = (outside: number) => Math.max(Math.min(reach, span / 4), reach - outside)\n if (x > a && x < b) {\n let toFrom = inner(a + startRoom)\n let toTo = inner(length - b + endRoom)\n // more than the shown part leaves for its middle (6px to pan it by):\n // shared out as each asks\n const room = Math.max(0, span - MIDDLE)\n const over = (toFrom + toTo) / room\n if (over > 1) [toFrom, toTo] = [toFrom / over, toTo / over]\n if (x - a <= toFrom) return 'from'\n if (b - x <= toTo) return 'to'\n return 'window'\n }\n if (x <= a && a - x <= reach) return 'from'\n if (x >= b && x - b <= reach) return 'to'\n return 'track'\n}\n\n/** The pointer that `gripAt` would give for a mouse over the strip. */\nfunction cursorOf(grip: Grip | 'track'): string {\n if (grip === 'window') return 'grab'\n if (grip === 'track') return 'pointer'\n return strip.value?.horizontal ? 'ns-resize' : 'ew-resize'\n}\n\nfunction onPointerDown(event: PointerEvent) {\n if (event.button !== 0 || !strip.value) return\n event.stopPropagation()\n event.preventDefault()\n state.start()\n const s = strip.value\n let { from, to } = s\n const at = along(event)\n let grip = gripAt(event, at)\n if (grip === 'track') {\n // a press beside the shown part moves it there, and drags it from there\n const span = to - from\n from = Math.min(Math.max(0, at - span / 2), 1 - span)\n to = from + span\n state.show(from, to, false)\n grip = 'window'\n }\n const el = event.currentTarget as HTMLElement\n const hold = holdPointer(event, el)\n hold.grab()\n try {\n el.setPointerCapture?.(event.pointerId)\n } catch {\n // the pointer is already gone\n }\n drag = { grip, start: at, from, to, hold, id: event.pointerId }\n}\n\nfunction onPointerMove(event: PointerEvent) {\n // hovering: the pointer shows what a press here would take\n if (!drag && strip.value && event.pointerType === 'mouse')\n rangeEl.value!.style.cursor = cursorOf(gripAt(event, along(event)))\n if (!drag || event.pointerId !== drag.id) return\n const d = along(event) - drag.start\n state.show(...moved(drag.grip, drag.from, drag.to, d), false)\n}\n\nfunction onPointerUp(event: PointerEvent) {\n if (!drag || event.pointerId !== drag.id) return\n const d = along(event) - drag.start\n const grip = drag.grip\n drag.hold.release()\n const { from, to } = drag\n drag = null\n state.show(...moved(grip, from, to, d), true)\n}\n\nfunction onPointerCancel() {\n drag?.hold.release()\n drag = null\n}\n\n/** `from` and `to` after `grip` moved by `d`, kept in the strip and apart by the least. */\nfunction moved(grip: Grip, from: number, to: number, d: number): [number, number] {\n const least = state.least.value\n if (grip === 'from') return [Math.min(Math.max(0, from + d), to - least), to]\n if (grip === 'to') return [from, Math.max(Math.min(1, to + d), from + least)]\n const shift = Math.min(Math.max(d, -from), 1 - to)\n return [from + shift, to + shift]\n}\n\n/* the keys on a handle */\n\nfunction onKeydown(event: KeyboardEvent, grip: 'from' | 'to') {\n const s = strip.value\n if (!s) return\n const step = state.step.value\n const keys: Record<string, number> = {\n ArrowLeft: -step,\n ArrowDown: s.horizontal ? step : -step,\n ArrowRight: step,\n ArrowUp: s.horizontal ? -step : step,\n PageDown: -step * 10,\n PageUp: step * 10,\n Home: -Infinity,\n End: Infinity,\n }\n // down a vertical strip is further along x\n if (s.horizontal) [keys.PageDown, keys.PageUp] = [step * 10, -step * 10]\n const d = keys[event.key]\n if (d === undefined) return\n event.preventDefault()\n const at = grip === 'from' ? s.from : s.to\n const next = Number.isFinite(d) ? at + d : d < 0 ? 0 : 1\n state.show(...moved(grip, s.from, s.to, next - at), true)\n}\n\nconst percent = (value: number) => Math.round(value * 1000) / 10\n</script>\n\n<template>\n <div v-if=\"brush\" :class=\"ns.e('brush')\" :style=\"px(brush)\" aria-hidden=\"true\" />\n <div\n v-if=\"strip && parts\"\n :class=\"[ns.e('range'), ns.is('vertical', strip.horizontal)]\"\n ref=\"range\"\n :style=\"px(strip.rect)\"\n @pointerdown=\"onPointerDown\"\n @pointermove=\"onPointerMove\"\n @pointerup=\"onPointerUp\"\n @pointercancel=\"onPointerCancel\"\n @dblclick.stop=\"state.reset()\"\n @click.stop\n >\n <canvas ref=\"canvas\" :class=\"ns.e('range-canvas')\" aria-hidden=\"true\" />\n <div\n :class=\"ns.e('range-shade')\"\n :style=\"\n px({ ...parts.before, x: parts.before.x - strip.rect.x, y: parts.before.y - strip.rect.y })\n \"\n />\n <div\n :class=\"ns.e('range-shade')\"\n :style=\"\n px({ ...parts.after, x: parts.after.x - strip.rect.x, y: parts.after.y - strip.rect.y })\n \"\n />\n <div\n :class=\"ns.e('range-window')\"\n :style=\"\n px({ ...parts.window, x: parts.window.x - strip.rect.x, y: parts.window.y - strip.rect.y })\n \"\n />\n <div\n v-for=\"(grip, i) in ['from', 'to'] as const\"\n :key=\"grip\"\n :class=\"ns.e('range-handle')\"\n role=\"slider\"\n tabindex=\"0\"\n :aria-label=\"state.labels.value[i]\"\n :aria-orientation=\"strip.horizontal ? 'vertical' : 'horizontal'\"\n aria-valuemin=\"0\"\n aria-valuemax=\"100\"\n :aria-valuenow=\"percent(grip === 'from' ? strip.from : strip.to)\"\n :aria-valuetext=\"state.texts.value[i]\"\n :style=\"\n strip.horizontal\n ? { transform: `translate(0, ${parts.ends[i]! - strip.rect.y}px)` }\n : { transform: `translate(${parts.ends[i]! - strip.rect.x}px, 0)` }\n \"\n @keydown=\"(e) => onKeydown(e, grip)\"\n />\n </div>\n</template>\n"],"mappings":";;;;;;;;;;AAiGA,IAAM,SAAS;;;;;;;;;;;;;;EA5Df,MAAM,KAAK,aAAa,OAAO;EAC/B,MAAM,EAAE,OAAO,UAAU,QAAA;EACzB,MAAM,SAAS,eAAkC,QAAQ;EACzD,MAAM,UAAU,eAA4B,OAAO;EAEnD,sBAAsB;GAEpB,IAAI,OAAO,SAAS,QAAA,MAAM,OAAO,OAAO,QAAA,MAAM,MAAM,OAAO,KAAK;EAClE,CAAC;EAED,MAAM,MAAM,OAAa;GACvB,WAAW,aAAa,EAAE,EAAE,MAAM,EAAE,EAAE;GACtC,OAAO,GAAG,EAAE,MAAM;GAClB,QAAQ,GAAG,EAAE,OAAO;EACtB;;EAGA,MAAM,QAAQ,eAAe;GAC3B,MAAM,IAAI,MAAM;GAChB,IAAI,CAAC,GAAG,OAAO;GACf,MAAM,EAAE,MAAM,eAAe;GAC7B,MAAM,SAAS,aAAa,KAAK,SAAS,KAAK;GAC/C,MAAM,QAAQ,aAAa,KAAK,IAAI,KAAK;GACzC,MAAM,IAAI,QAAQ,EAAE,OAAO;GAC3B,MAAM,IAAI,QAAQ,EAAE,KAAK;GACzB,MAAM,WAAW,MAAc,OAC7B,aACI;IAAE,GAAG,KAAK;IAAG,GAAG;IAAM,OAAO,KAAK;IAAO,QAAQ,KAAK;GAAK,IAC3D;IAAE,GAAG;IAAM,GAAG,KAAK;IAAG,OAAO,KAAK;IAAM,QAAQ,KAAK;GAAO;GAClE,OAAO;IACL,QAAQ,QAAQ,OAAO,CAAC;IACxB,QAAQ,QAAQ,GAAG,CAAC;IACpB,OAAO,QAAQ,GAAG,QAAQ,MAAM;IAChC,MAAM,CAAC,GAAG,CAAC;GACb;EACF,CAAC;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E;MAC9D,kBAAgB,QAAA,MAAM,MAAM,MAAM;MAClC,OAAKE,eAAWF,MAAA,KAAA,CAAK,CAAC,aAAoD,EAAA,WAAA,gBAAA,MAAA,MAAM,KAAK,KAAMA,MAAA,KAAA,CAAK,CAAC,KAAK,EAAC,KAAA,IAA8C,EAAA,WAAA,aAAA,MAAA,MAAM,KAAK,KAAMA,MAAA,KAAA,CAAK,CAAC,KAAK,EAAC,QAAA,C;MAKlL,YAAU,MAAM,UAAU,GAAG,IAAI"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dou-ui/chart",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.21",
|
|
4
4
|
"description": "DouUI 的图表:折线、面积、柱状、散点与饼图",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vue",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"build": "vite build && vue-tsc -p tsconfig.build.json && bun scripts/build-style.ts"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"dou-ui": "0.1.0-alpha.
|
|
49
|
+
"dou-ui": "0.1.0-alpha.21",
|
|
50
50
|
"vue": "^3.5.0"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|