@dou-ui/chart 0.0.0-stage → 0.1.0-alpha.0

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.
Files changed (237) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -2
  3. package/dist/chart.js +6 -0
  4. package/dist/chart.js.map +1 -0
  5. package/dist/chart.vue_vue_type_script_setup_true_lang.js +4245 -0
  6. package/dist/chart.vue_vue_type_script_setup_true_lang.js.map +1 -0
  7. package/dist/components/area.js +6 -0
  8. package/dist/components/area.js.map +1 -0
  9. package/dist/components/area.vue_vue_type_script_setup_true_lang.js +55 -0
  10. package/dist/components/area.vue_vue_type_script_setup_true_lang.js.map +1 -0
  11. package/dist/components/axis.js +6 -0
  12. package/dist/components/axis.js.map +1 -0
  13. package/dist/components/axis.vue_vue_type_script_setup_true_lang.js +46 -0
  14. package/dist/components/axis.vue_vue_type_script_setup_true_lang.js.map +1 -0
  15. package/dist/components/bar.js +6 -0
  16. package/dist/components/bar.js.map +1 -0
  17. package/dist/components/bar.vue_vue_type_script_setup_true_lang.js +46 -0
  18. package/dist/components/bar.vue_vue_type_script_setup_true_lang.js.map +1 -0
  19. package/dist/components/boxplot.js +6 -0
  20. package/dist/components/boxplot.js.map +1 -0
  21. package/dist/components/boxplot.vue_vue_type_script_setup_true_lang.js +42 -0
  22. package/dist/components/boxplot.vue_vue_type_script_setup_true_lang.js.map +1 -0
  23. package/dist/components/brush.js +6 -0
  24. package/dist/components/brush.js.map +1 -0
  25. package/dist/components/brush.vue_vue_type_script_setup_true_lang.js +42 -0
  26. package/dist/components/brush.vue_vue_type_script_setup_true_lang.js.map +1 -0
  27. package/dist/components/funnel.js +6 -0
  28. package/dist/components/funnel.js.map +1 -0
  29. package/dist/components/funnel.vue_vue_type_script_setup_true_lang.js +41 -0
  30. package/dist/components/funnel.vue_vue_type_script_setup_true_lang.js.map +1 -0
  31. package/dist/components/gauge.js +6 -0
  32. package/dist/components/gauge.js.map +1 -0
  33. package/dist/components/gauge.vue_vue_type_script_setup_true_lang.js +91 -0
  34. package/dist/components/gauge.vue_vue_type_script_setup_true_lang.js.map +1 -0
  35. package/dist/components/heatmap.js +6 -0
  36. package/dist/components/heatmap.js.map +1 -0
  37. package/dist/components/heatmap.vue_vue_type_script_setup_true_lang.js +45 -0
  38. package/dist/components/heatmap.vue_vue_type_script_setup_true_lang.js.map +1 -0
  39. package/dist/components/histogram.js +6 -0
  40. package/dist/components/histogram.js.map +1 -0
  41. package/dist/components/histogram.vue_vue_type_script_setup_true_lang.js +61 -0
  42. package/dist/components/histogram.vue_vue_type_script_setup_true_lang.js.map +1 -0
  43. package/dist/components/line.js +6 -0
  44. package/dist/components/line.js.map +1 -0
  45. package/dist/components/line.vue_vue_type_script_setup_true_lang.js +52 -0
  46. package/dist/components/line.vue_vue_type_script_setup_true_lang.js.map +1 -0
  47. package/dist/components/marker.js +6 -0
  48. package/dist/components/marker.js.map +1 -0
  49. package/dist/components/marker.vue_vue_type_script_setup_true_lang.js +31 -0
  50. package/dist/components/marker.vue_vue_type_script_setup_true_lang.js.map +1 -0
  51. package/dist/components/pie.js +6 -0
  52. package/dist/components/pie.js.map +1 -0
  53. package/dist/components/pie.vue_vue_type_script_setup_true_lang.js +42 -0
  54. package/dist/components/pie.vue_vue_type_script_setup_true_lang.js.map +1 -0
  55. package/dist/components/radar.js +6 -0
  56. package/dist/components/radar.js.map +1 -0
  57. package/dist/components/radar.vue_vue_type_script_setup_true_lang.js +45 -0
  58. package/dist/components/radar.vue_vue_type_script_setup_true_lang.js.map +1 -0
  59. package/dist/components/range.js +6 -0
  60. package/dist/components/range.js.map +1 -0
  61. package/dist/components/range.vue_vue_type_script_setup_true_lang.js +27 -0
  62. package/dist/components/range.vue_vue_type_script_setup_true_lang.js.map +1 -0
  63. package/dist/components/scatter.js +6 -0
  64. package/dist/components/scatter.js.map +1 -0
  65. package/dist/components/scatter.vue_vue_type_script_setup_true_lang.js +45 -0
  66. package/dist/components/scatter.vue_vue_type_script_setup_true_lang.js.map +1 -0
  67. package/dist/components/sunburst.js +6 -0
  68. package/dist/components/sunburst.js.map +1 -0
  69. package/dist/components/sunburst.vue_vue_type_script_setup_true_lang.js +36 -0
  70. package/dist/components/sunburst.vue_vue_type_script_setup_true_lang.js.map +1 -0
  71. package/dist/components/tooltip.js +6 -0
  72. package/dist/components/tooltip.js.map +1 -0
  73. package/dist/components/tooltip.vue_vue_type_script_setup_true_lang.js +31 -0
  74. package/dist/components/tooltip.vue_vue_type_script_setup_true_lang.js.map +1 -0
  75. package/dist/components/treemap.js +6 -0
  76. package/dist/components/treemap.js.map +1 -0
  77. package/dist/components/treemap.vue_vue_type_script_setup_true_lang.js +33 -0
  78. package/dist/components/treemap.vue_vue_type_script_setup_true_lang.js.map +1 -0
  79. package/dist/components/waterfall.js +6 -0
  80. package/dist/components/waterfall.js.map +1 -0
  81. package/dist/components/waterfall.vue_vue_type_script_setup_true_lang.js +49 -0
  82. package/dist/components/waterfall.vue_vue_type_script_setup_true_lang.js.map +1 -0
  83. package/dist/components/zoom.js +6 -0
  84. package/dist/components/zoom.js.map +1 -0
  85. package/dist/components/zoom.vue_vue_type_script_setup_true_lang.js +37 -0
  86. package/dist/components/zoom.vue_vue_type_script_setup_true_lang.js.map +1 -0
  87. package/dist/context.js +30 -0
  88. package/dist/context.js.map +1 -0
  89. package/dist/core/bar.js +223 -0
  90. package/dist/core/bar.js.map +1 -0
  91. package/dist/core/box.js +150 -0
  92. package/dist/core/box.js.map +1 -0
  93. package/dist/core/colors.js +58 -0
  94. package/dist/core/colors.js.map +1 -0
  95. package/dist/core/data.js +257 -0
  96. package/dist/core/data.js.map +1 -0
  97. package/dist/core/decimate.js +211 -0
  98. package/dist/core/decimate.js.map +1 -0
  99. package/dist/core/format.js +151 -0
  100. package/dist/core/format.js.map +1 -0
  101. package/dist/core/funnel.js +68 -0
  102. package/dist/core/funnel.js.map +1 -0
  103. package/dist/core/grid.js +87 -0
  104. package/dist/core/grid.js.map +1 -0
  105. package/dist/core/heatmap.js +187 -0
  106. package/dist/core/heatmap.js.map +1 -0
  107. package/dist/core/histogram.js +81 -0
  108. package/dist/core/histogram.js.map +1 -0
  109. package/dist/core/hit.js +115 -0
  110. package/dist/core/hit.js.map +1 -0
  111. package/dist/core/labels.js +141 -0
  112. package/dist/core/labels.js.map +1 -0
  113. package/dist/core/layout.js +1002 -0
  114. package/dist/core/layout.js.map +1 -0
  115. package/dist/core/line.js +230 -0
  116. package/dist/core/line.js.map +1 -0
  117. package/dist/core/marker.js +205 -0
  118. package/dist/core/marker.js.map +1 -0
  119. package/dist/core/model.js +391 -0
  120. package/dist/core/model.js.map +1 -0
  121. package/dist/core/painter.js +79 -0
  122. package/dist/core/painter.js.map +1 -0
  123. package/dist/core/pattern.js +102 -0
  124. package/dist/core/pattern.js.map +1 -0
  125. package/dist/core/pie.js +119 -0
  126. package/dist/core/pie.js.map +1 -0
  127. package/dist/core/radar.js +83 -0
  128. package/dist/core/radar.js.map +1 -0
  129. package/dist/core/scale.js +149 -0
  130. package/dist/core/scale.js.map +1 -0
  131. package/dist/core/scatter.js +263 -0
  132. package/dist/core/scatter.js.map +1 -0
  133. package/dist/core/svg.js +209 -0
  134. package/dist/core/svg.js.map +1 -0
  135. package/dist/core/sync.js +21 -0
  136. package/dist/core/sync.js.map +1 -0
  137. package/dist/core/time.js +217 -0
  138. package/dist/core/time.js.map +1 -0
  139. package/dist/core/tree.js +348 -0
  140. package/dist/core/tree.js.map +1 -0
  141. package/dist/core/warn.js +11 -0
  142. package/dist/core/warn.js.map +1 -0
  143. package/dist/core/waterfall.js +134 -0
  144. package/dist/core/waterfall.js.map +1 -0
  145. package/dist/core/window.js +94 -0
  146. package/dist/core/window.js.map +1 -0
  147. package/dist/define.js +62 -0
  148. package/dist/define.js.map +1 -0
  149. package/dist/index.js +49 -0
  150. package/dist/index.js.map +1 -0
  151. package/dist/locale.js +170 -0
  152. package/dist/locale.js.map +1 -0
  153. package/dist/overlay.js +6 -0
  154. package/dist/overlay.js.map +1 -0
  155. package/dist/overlay.vue_vue_type_script_setup_true_lang.js +207 -0
  156. package/dist/overlay.vue_vue_type_script_setup_true_lang.js.map +1 -0
  157. package/dist/pointer.js +6 -0
  158. package/dist/pointer.js.map +1 -0
  159. package/dist/pointer.vue_vue_type_script_setup_true_lang.js +136 -0
  160. package/dist/pointer.vue_vue_type_script_setup_true_lang.js.map +1 -0
  161. package/dist/static.js +6 -0
  162. package/dist/static.js.map +1 -0
  163. package/dist/static.vue_vue_type_script_setup_true_lang.js +34 -0
  164. package/dist/static.vue_vue_type_script_setup_true_lang.js.map +1 -0
  165. package/dist/style.css +1 -0
  166. package/dist/style.d.ts +1 -0
  167. package/dist/style.js +3 -0
  168. package/dist/table.js +6 -0
  169. package/dist/table.js.map +1 -0
  170. package/dist/table.vue_vue_type_script_setup_true_lang.js +52 -0
  171. package/dist/table.vue_vue_type_script_setup_true_lang.js.map +1 -0
  172. package/dist/types/chart.vue.d.ts +24 -0
  173. package/dist/types/components/area.vue.d.ts +16 -0
  174. package/dist/types/components/axis.vue.d.ts +8 -0
  175. package/dist/types/components/bar.vue.d.ts +14 -0
  176. package/dist/types/components/boxplot.vue.d.ts +14 -0
  177. package/dist/types/components/brush.vue.d.ts +22 -0
  178. package/dist/types/components/funnel.vue.d.ts +14 -0
  179. package/dist/types/components/gauge.vue.d.ts +17 -0
  180. package/dist/types/components/heatmap.vue.d.ts +14 -0
  181. package/dist/types/components/histogram.vue.d.ts +14 -0
  182. package/dist/types/components/line.vue.d.ts +16 -0
  183. package/dist/types/components/marker.vue.d.ts +6 -0
  184. package/dist/types/components/pie.vue.d.ts +23 -0
  185. package/dist/types/components/radar.vue.d.ts +16 -0
  186. package/dist/types/components/range.vue.d.ts +12 -0
  187. package/dist/types/components/scatter.vue.d.ts +14 -0
  188. package/dist/types/components/sunburst.vue.d.ts +17 -0
  189. package/dist/types/components/tooltip.vue.d.ts +13 -0
  190. package/dist/types/components/treemap.vue.d.ts +8 -0
  191. package/dist/types/components/waterfall.vue.d.ts +16 -0
  192. package/dist/types/components/zoom.vue.d.ts +18 -0
  193. package/dist/types/context.d.ts +87 -0
  194. package/dist/types/core/bar.d.ts +38 -0
  195. package/dist/types/core/box.d.ts +25 -0
  196. package/dist/types/core/colors.d.ts +16 -0
  197. package/dist/types/core/data.d.ts +72 -0
  198. package/dist/types/core/decimate.d.ts +39 -0
  199. package/dist/types/core/format.d.ts +33 -0
  200. package/dist/types/core/funnel.d.ts +15 -0
  201. package/dist/types/core/grid.d.ts +18 -0
  202. package/dist/types/core/heatmap.d.ts +17 -0
  203. package/dist/types/core/histogram.d.ts +23 -0
  204. package/dist/types/core/hit.d.ts +31 -0
  205. package/dist/types/core/labels.d.ts +45 -0
  206. package/dist/types/core/layout.d.ts +259 -0
  207. package/dist/types/core/line.d.ts +36 -0
  208. package/dist/types/core/marker.d.ts +67 -0
  209. package/dist/types/core/model.d.ts +86 -0
  210. package/dist/types/core/painter.d.ts +34 -0
  211. package/dist/types/core/pattern.d.ts +14 -0
  212. package/dist/types/core/pie.d.ts +66 -0
  213. package/dist/types/core/radar.d.ts +12 -0
  214. package/dist/types/core/scale.d.ts +60 -0
  215. package/dist/types/core/scatter.d.ts +16 -0
  216. package/dist/types/core/series.d.ts +228 -0
  217. package/dist/types/core/svg.d.ts +63 -0
  218. package/dist/types/core/sync.d.ts +8 -0
  219. package/dist/types/core/time.d.ts +20 -0
  220. package/dist/types/core/tree.d.ts +84 -0
  221. package/dist/types/core/warn.d.ts +4 -0
  222. package/dist/types/core/waterfall.d.ts +24 -0
  223. package/dist/types/core/window.d.ts +36 -0
  224. package/dist/types/define.d.ts +115 -0
  225. package/dist/types/index.d.ts +363 -0
  226. package/dist/types/locale.d.ts +100 -0
  227. package/dist/types/overlay.vue.d.ts +95 -0
  228. package/dist/types/pointer.vue.d.ts +53 -0
  229. package/dist/types/static.vue.d.ts +24 -0
  230. package/dist/types/table.vue.d.ts +19 -0
  231. package/dist/types/types.d.ts +555 -0
  232. package/dist/types/zoom-layer.vue.d.ts +41 -0
  233. package/dist/zoom-layer.js +6 -0
  234. package/dist/zoom-layer.js.map +1 -0
  235. package/dist/zoom-layer.vue_vue_type_script_setup_true_lang.js +210 -0
  236. package/dist/zoom-layer.vue_vue_type_script_setup_true_lang.js.map +1 -0
  237. package/package.json +53 -4
@@ -0,0 +1,210 @@
1
+ import { holdPointer, useNamespace } from "dou-ui";
2
+ import { Fragment, computed, createCommentVNode, createElementBlock, createElementVNode, defineComponent, normalizeClass, normalizeStyle, openBlock, renderList, unref, useTemplateRef, watchPostEffect, withModifiers } from "vue";
3
+ // src/zoom-layer.vue?vue&type=script&setup=true&lang.ts
4
+ var _hoisted_1 = [
5
+ "aria-label",
6
+ "aria-orientation",
7
+ "aria-valuenow",
8
+ "aria-valuetext",
9
+ "onPointerdown",
10
+ "onKeydown"
11
+ ];
12
+ var zoom_layer_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
13
+ name: "DouChartZoomLayer",
14
+ __name: "zoom-layer",
15
+ props: { state: {} },
16
+ setup(__props) {
17
+ const ns = useNamespace("chart");
18
+ const { brush, strip } = __props.state;
19
+ const canvas = useTemplateRef("canvas");
20
+ watchPostEffect(() => {
21
+ if (canvas.value && __props.state.sketch.value) __props.state.paint(canvas.value);
22
+ });
23
+ const px = (r) => ({
24
+ transform: `translate(${r.x}px, ${r.y}px)`,
25
+ width: `${r.width}px`,
26
+ height: `${r.height}px`
27
+ });
28
+ /** The shown part and the dimmed parts on either side, in px. */
29
+ const parts = computed(() => {
30
+ const s = strip.value;
31
+ if (!s) return null;
32
+ const { rect, horizontal } = s;
33
+ const length = horizontal ? rect.height : rect.width;
34
+ const start = horizontal ? rect.y : rect.x;
35
+ const a = start + s.from * length;
36
+ const b = start + s.to * length;
37
+ const stretch = (from, to) => horizontal ? {
38
+ x: rect.x,
39
+ y: from,
40
+ width: rect.width,
41
+ height: to - from
42
+ } : {
43
+ x: from,
44
+ y: rect.y,
45
+ width: to - from,
46
+ height: rect.height
47
+ };
48
+ return {
49
+ before: stretch(start, a),
50
+ window: stretch(a, b),
51
+ after: stretch(b, start + length),
52
+ ends: [a, b]
53
+ };
54
+ });
55
+ let drag = null;
56
+ function along(event) {
57
+ const s = strip.value;
58
+ const box = event.currentTarget.closest(`.${ns.e("range")}`).getBoundingClientRect();
59
+ return s.horizontal ? (event.clientY - box.top) / box.height : (event.clientX - box.left) / box.width;
60
+ }
61
+ function onPointerDown(event, grip) {
62
+ if (event.button !== 0 || !strip.value) return;
63
+ event.stopPropagation();
64
+ event.preventDefault();
65
+ __props.state.start();
66
+ let { from, to } = strip.value;
67
+ const at = along(event);
68
+ if (grip === "track") {
69
+ const span = to - from;
70
+ from = Math.min(Math.max(0, at - span / 2), 1 - span);
71
+ to = from + span;
72
+ __props.state.show(from, to, false);
73
+ grip = "window";
74
+ }
75
+ const el = event.currentTarget;
76
+ const hold = holdPointer(event, el);
77
+ hold.grab();
78
+ try {
79
+ el.setPointerCapture?.(event.pointerId);
80
+ } catch {}
81
+ drag = {
82
+ grip,
83
+ start: at,
84
+ from,
85
+ to,
86
+ hold,
87
+ id: event.pointerId
88
+ };
89
+ }
90
+ function onPointerMove(event) {
91
+ if (!drag || event.pointerId !== drag.id) return;
92
+ const d = along(event) - drag.start;
93
+ __props.state.show(...moved(drag.grip, drag.from, drag.to, d), false);
94
+ }
95
+ function onPointerUp(event) {
96
+ if (!drag || event.pointerId !== drag.id) return;
97
+ const d = along(event) - drag.start;
98
+ const grip = drag.grip;
99
+ drag.hold.release();
100
+ const { from, to } = drag;
101
+ drag = null;
102
+ __props.state.show(...moved(grip, from, to, d), true);
103
+ }
104
+ function onPointerCancel() {
105
+ drag?.hold.release();
106
+ drag = null;
107
+ }
108
+ /** `from` and `to` after `grip` moved by `d`, kept in the strip and apart by the least. */
109
+ function moved(grip, from, to, d) {
110
+ const least = __props.state.least.value;
111
+ if (grip === "from") return [Math.min(Math.max(0, from + d), to - least), to];
112
+ if (grip === "to") return [from, Math.max(Math.min(1, to + d), from + least)];
113
+ const shift = Math.min(Math.max(d, -from), 1 - to);
114
+ return [from + shift, to + shift];
115
+ }
116
+ function onKeydown(event, grip) {
117
+ const s = strip.value;
118
+ if (!s) return;
119
+ const step = __props.state.step.value;
120
+ const keys = {
121
+ ArrowLeft: -step,
122
+ ArrowDown: s.horizontal ? step : -step,
123
+ ArrowRight: step,
124
+ ArrowUp: s.horizontal ? -step : step,
125
+ PageDown: -step * 10,
126
+ PageUp: step * 10,
127
+ Home: -Infinity,
128
+ End: Infinity
129
+ };
130
+ if (s.horizontal) [keys.PageDown, keys.PageUp] = [step * 10, -step * 10];
131
+ const d = keys[event.key];
132
+ if (d === void 0) return;
133
+ event.preventDefault();
134
+ const at = grip === "from" ? s.from : s.to;
135
+ const next = Number.isFinite(d) ? at + d : d < 0 ? 0 : 1;
136
+ __props.state.show(...moved(grip, s.from, s.to, next - at), true);
137
+ }
138
+ const percent = (value) => Math.round(value * 1e3) / 10;
139
+ return (_ctx, _cache) => {
140
+ return openBlock(), createElementBlock(Fragment, null, [unref(brush) ? (openBlock(), createElementBlock("div", {
141
+ key: 0,
142
+ class: normalizeClass(unref(ns).e("brush")),
143
+ style: normalizeStyle(px(unref(brush))),
144
+ "aria-hidden": "true"
145
+ }, null, 6)) : createCommentVNode("", true), unref(strip) && parts.value ? (openBlock(), createElementBlock("div", {
146
+ key: 1,
147
+ class: normalizeClass([unref(ns).e("range"), unref(ns).is("vertical", unref(strip).horizontal)]),
148
+ style: normalizeStyle(px(unref(strip).rect)),
149
+ onPointerdown: _cache[1] || (_cache[1] = (e) => onPointerDown(e, "track")),
150
+ onPointermove: onPointerMove,
151
+ onPointerup: onPointerUp,
152
+ onPointercancel: onPointerCancel,
153
+ onDblclick: _cache[2] || (_cache[2] = withModifiers(($event) => __props.state.reset(), ["stop"])),
154
+ onClick: _cache[3] || (_cache[3] = withModifiers(() => {}, ["stop"]))
155
+ }, [
156
+ createElementVNode("canvas", {
157
+ ref_key: "canvas",
158
+ ref: canvas,
159
+ class: normalizeClass(unref(ns).e("range-canvas")),
160
+ "aria-hidden": "true"
161
+ }, null, 2),
162
+ createElementVNode("div", {
163
+ class: normalizeClass(unref(ns).e("range-shade")),
164
+ style: normalizeStyle(px({
165
+ ...parts.value.before,
166
+ x: parts.value.before.x - unref(strip).rect.x,
167
+ y: parts.value.before.y - unref(strip).rect.y
168
+ }))
169
+ }, null, 6),
170
+ createElementVNode("div", {
171
+ class: normalizeClass(unref(ns).e("range-shade")),
172
+ style: normalizeStyle(px({
173
+ ...parts.value.after,
174
+ x: parts.value.after.x - unref(strip).rect.x,
175
+ y: parts.value.after.y - unref(strip).rect.y
176
+ }))
177
+ }, null, 6),
178
+ createElementVNode("div", {
179
+ class: normalizeClass(unref(ns).e("range-window")),
180
+ style: normalizeStyle(px({
181
+ ...parts.value.window,
182
+ x: parts.value.window.x - unref(strip).rect.x,
183
+ y: parts.value.window.y - unref(strip).rect.y
184
+ })),
185
+ onPointerdown: _cache[0] || (_cache[0] = (e) => onPointerDown(e, "window"))
186
+ }, null, 38),
187
+ (openBlock(), createElementBlock(Fragment, null, renderList(["from", "to"], (grip, i) => {
188
+ return createElementVNode("div", {
189
+ key: grip,
190
+ class: normalizeClass(unref(ns).e("range-handle")),
191
+ role: "slider",
192
+ tabindex: "0",
193
+ "aria-label": __props.state.labels.value[i],
194
+ "aria-orientation": unref(strip).horizontal ? "vertical" : "horizontal",
195
+ "aria-valuemin": "0",
196
+ "aria-valuemax": "100",
197
+ "aria-valuenow": percent(grip === "from" ? unref(strip).from : unref(strip).to),
198
+ "aria-valuetext": __props.state.texts.value[i],
199
+ 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
+ onKeydown: (e) => onKeydown(e, grip)
202
+ }, null, 46, _hoisted_1);
203
+ }), 64))
204
+ ], 38)) : createCommentVNode("", true)], 64);
205
+ };
206
+ }
207
+ });
208
+ export { zoom_layer_vue_vue_type_script_setup_true_lang_default as default };
209
+
210
+ //# sourceMappingURL=zoom-layer.vue_vue_type_script_setup_true_lang.js.map
@@ -0,0 +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,WAA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AAK,MAAA,MAAM,OAAO,IAAIF,MAAA,KAAA,CAAK,CAAC,KAAK;MAAC,GAAK,MAAA,MAAM,OAAO,IAAIA,MAAA,KAAA,CAAK,CAAC,KAAK;KAAC,CAAA,C;KAGxG,eAAW,OAAA,OAAA,OAAA,MAAG,MAAM,cAAc,GAAC,QAAA;;KAEtCH,UAAA,GAAAC,mBAmBEC,UAAA,MAAAO,WAlBoB,CAAA,QAAA,IAAA,IAAZ,MAAM,MAAC;KADjB,OAAAD,mBAmBE,OAAA;MAjBC,KAAK;MACL,OAAKJ,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"}
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "@dou-ui/chart",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-alpha.0",
4
+ "description": "DouUI 的图表:折线、面积、柱状、散点与饼图",
5
+ "keywords": [
6
+ "vue",
7
+ "vue3",
8
+ "chart",
9
+ "canvas",
10
+ "data-visualization",
11
+ "graph"
12
+ ],
13
+ "license": "MIT",
14
+ "author": "daidr <daidr@daidr.me>",
15
+ "homepage": "https://github.com/daidr/dou-ui#readme",
16
+ "bugs": "https://github.com/daidr/dou-ui/issues",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/daidr/dou-ui.git",
20
+ "directory": "packages/chart"
21
+ },
22
+ "type": "module",
23
+ "sideEffects": [
24
+ "*.css",
25
+ "./dist/style.js"
26
+ ],
27
+ "main": "./dist/index.js",
28
+ "module": "./dist/index.js",
29
+ "types": "./dist/types/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/types/index.d.ts",
33
+ "import": "./dist/index.js"
34
+ },
35
+ "./style": {
36
+ "types": "./dist/style.d.ts",
37
+ "import": "./dist/style.js"
38
+ },
39
+ "./style.css": "./dist/style.css",
40
+ "./package.json": "./package.json"
41
+ },
42
+ "files": [
43
+ "dist"
44
+ ],
45
+ "scripts": {
46
+ "build": "vite build && vue-tsc -p tsconfig.build.json && bun scripts/build-style.ts"
47
+ },
48
+ "peerDependencies": {
49
+ "dou-ui": "0.1.0-alpha.0",
50
+ "vue": "^3.5.0"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ }
55
+ }