@blotch/dolan 22.2.2 → 22.2.4

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 (259) hide show
  1. package/dist/commands/add.d.ts +6 -2
  2. package/dist/commands/add.js +41 -11
  3. package/dist/commands/add.js.map +1 -1
  4. package/dist/commands/add.test.js +162 -9
  5. package/dist/commands/add.test.js.map +1 -1
  6. package/dist/commands/diff.d.ts +2 -1
  7. package/dist/commands/diff.js +38 -25
  8. package/dist/commands/diff.js.map +1 -1
  9. package/dist/commands/diff.test.js +72 -11
  10. package/dist/commands/diff.test.js.map +1 -1
  11. package/dist/commands/doctor.js +228 -34
  12. package/dist/commands/doctor.js.map +1 -1
  13. package/dist/commands/doctor.test.js +367 -10
  14. package/dist/commands/doctor.test.js.map +1 -1
  15. package/dist/commands/eject.js +7 -0
  16. package/dist/commands/eject.js.map +1 -1
  17. package/dist/commands/eject.test.js +39 -0
  18. package/dist/commands/eject.test.js.map +1 -1
  19. package/dist/commands/info.js +3 -2
  20. package/dist/commands/info.js.map +1 -1
  21. package/dist/commands/init.d.ts +37 -1
  22. package/dist/commands/init.js +169 -40
  23. package/dist/commands/init.js.map +1 -1
  24. package/dist/commands/init.test.js +392 -27
  25. package/dist/commands/init.test.js.map +1 -1
  26. package/dist/commands/install-packages.d.ts +6 -0
  27. package/dist/commands/install-packages.js +20 -0
  28. package/dist/commands/install-packages.js.map +1 -0
  29. package/dist/commands/install-packages.test.d.ts +1 -0
  30. package/dist/commands/install-packages.test.js +55 -0
  31. package/dist/commands/install-packages.test.js.map +1 -0
  32. package/dist/commands/list.js +21 -14
  33. package/dist/commands/list.js.map +1 -1
  34. package/dist/commands/list.test.js +62 -5
  35. package/dist/commands/list.test.js.map +1 -1
  36. package/dist/commands/outdated.js +11 -10
  37. package/dist/commands/outdated.js.map +1 -1
  38. package/dist/commands/outdated.test.js +20 -5
  39. package/dist/commands/outdated.test.js.map +1 -1
  40. package/dist/commands/remove.d.ts +4 -0
  41. package/dist/commands/remove.js +17 -4
  42. package/dist/commands/remove.js.map +1 -1
  43. package/dist/commands/remove.test.js +53 -2
  44. package/dist/commands/remove.test.js.map +1 -1
  45. package/dist/commands/theme.js +1 -1
  46. package/dist/commands/theme.js.map +1 -1
  47. package/dist/commands/update.d.ts +11 -0
  48. package/dist/commands/update.js +174 -58
  49. package/dist/commands/update.js.map +1 -1
  50. package/dist/commands/update.test.js +587 -33
  51. package/dist/commands/update.test.js.map +1 -1
  52. package/dist/index.js +7 -0
  53. package/dist/index.js.map +1 -1
  54. package/dist/lockfile.d.ts +7 -0
  55. package/dist/lockfile.js +36 -0
  56. package/dist/lockfile.js.map +1 -1
  57. package/dist/lockfile.test.d.ts +1 -0
  58. package/dist/lockfile.test.js +25 -0
  59. package/dist/lockfile.test.js.map +1 -0
  60. package/dist/registry.d.ts +14 -0
  61. package/dist/registry.js +78 -24
  62. package/dist/registry.js.map +1 -1
  63. package/dist/registry.test.js +119 -38
  64. package/dist/registry.test.js.map +1 -1
  65. package/dist/test-utils.d.ts +5 -0
  66. package/dist/test-utils.js +6 -1
  67. package/dist/test-utils.js.map +1 -1
  68. package/dist/testing/fire-lynx-event.d.ts +14 -0
  69. package/dist/testing/fire-lynx-event.js +19 -0
  70. package/dist/testing/fire-lynx-event.js.map +1 -0
  71. package/dist/testing/fire-lynx-event.test.d.ts +1 -0
  72. package/dist/testing/fire-lynx-event.test.js +44 -0
  73. package/dist/testing/fire-lynx-event.test.js.map +1 -0
  74. package/dist/testing/lynx-main-thread.d.ts +22 -0
  75. package/dist/testing/lynx-main-thread.js +11 -0
  76. package/dist/testing/lynx-main-thread.js.map +1 -0
  77. package/dist/testing/lynx-main-thread.test.d.ts +1 -0
  78. package/dist/testing/lynx-main-thread.test.js +24 -0
  79. package/dist/testing/lynx-main-thread.test.js.map +1 -0
  80. package/dist/testing/set-input-signal.d.ts +14 -0
  81. package/dist/testing/set-input-signal.js +21 -0
  82. package/dist/testing/set-input-signal.js.map +1 -0
  83. package/dist/testing/set-input-signal.test.d.ts +1 -0
  84. package/dist/testing/set-input-signal.test.js +20 -0
  85. package/dist/testing/set-input-signal.test.js.map +1 -0
  86. package/dist/ui/components/accordion/accordion.test.ts +158 -144
  87. package/dist/ui/components/accordion/accordion.ts +19 -14
  88. package/dist/ui/components/action-sheet/action-sheet.test.ts +283 -151
  89. package/dist/ui/components/action-sheet/action-sheet.ts +77 -43
  90. package/dist/ui/components/alert/alert.test.ts +67 -19
  91. package/dist/ui/components/alert/alert.ts +14 -16
  92. package/dist/ui/components/alert-dialog/alert-dialog.test.ts +208 -94
  93. package/dist/ui/components/alert-dialog/alert-dialog.ts +75 -38
  94. package/dist/ui/components/area-chart/area-chart.test.ts +134 -119
  95. package/dist/ui/components/area-chart/area-chart.ts +100 -315
  96. package/dist/ui/components/area-chart/index.ts +2 -3
  97. package/dist/ui/components/avatar/avatar.test.ts +89 -45
  98. package/dist/ui/components/badge/badge.test.ts +57 -23
  99. package/dist/ui/components/badge/badge.ts +12 -14
  100. package/dist/ui/components/bar-chart/bar-chart.test.ts +172 -45
  101. package/dist/ui/components/bar-chart/bar-chart.ts +140 -294
  102. package/dist/ui/components/bar-chart/index.ts +3 -3
  103. package/dist/ui/components/bottom-sheet/bottom-sheet.test.ts +386 -128
  104. package/dist/ui/components/bottom-sheet/bottom-sheet.ts +170 -53
  105. package/dist/ui/components/button/button.test.ts +611 -2
  106. package/dist/ui/components/button/button.ts +434 -49
  107. package/dist/ui/components/button/index.ts +2 -0
  108. package/dist/ui/components/button-group/button-group.test.ts +484 -2
  109. package/dist/ui/components/button-group/button-group.ts +380 -68
  110. package/dist/ui/components/button-group/index.ts +3 -0
  111. package/dist/ui/components/candlestick-chart/candlestick-chart.test.ts +183 -58
  112. package/dist/ui/components/candlestick-chart/candlestick-chart.ts +150 -323
  113. package/dist/ui/components/candlestick-chart/index.ts +3 -4
  114. package/dist/ui/components/card/card.test.ts +82 -62
  115. package/dist/ui/components/chart/chart-focus.test.ts +132 -0
  116. package/dist/ui/components/chart/chart-focus.ts +115 -0
  117. package/dist/ui/components/chart/chart-presets.test.ts +335 -0
  118. package/dist/ui/components/chart/chart-presets.ts +278 -0
  119. package/dist/ui/components/chart/chart-scene.test.ts +589 -0
  120. package/dist/ui/components/chart/chart-scene.ts +483 -0
  121. package/dist/ui/components/chart/chart-theme.test.ts +85 -0
  122. package/dist/ui/components/chart/chart-theme.ts +210 -0
  123. package/dist/ui/components/chart/chart-zoom.test.ts +159 -0
  124. package/dist/ui/components/chart/chart-zoom.ts +162 -0
  125. package/dist/ui/components/chart/chart.test.ts +1017 -0
  126. package/dist/ui/components/chart/chart.ts +934 -0
  127. package/dist/ui/components/chart/index.ts +24 -0
  128. package/dist/ui/components/checkbox/checkbox.test.ts +124 -42
  129. package/dist/ui/components/checkbox/checkbox.ts +23 -23
  130. package/dist/ui/components/collapsible/collapsible.test.ts +158 -81
  131. package/dist/ui/components/collapsible/collapsible.ts +19 -14
  132. package/dist/ui/components/context-menu/context-menu.test.ts +224 -0
  133. package/dist/ui/components/context-menu/context-menu.ts +110 -0
  134. package/dist/ui/components/context-menu/index.ts +1 -0
  135. package/dist/ui/components/dialog/dialog.test.ts +213 -108
  136. package/dist/ui/components/dialog/dialog.ts +72 -35
  137. package/dist/ui/components/dock/dock-scroll.test.ts +130 -0
  138. package/dist/ui/components/dock/dock-scroll.ts +133 -0
  139. package/dist/ui/components/dock/dock.test.ts +749 -0
  140. package/dist/ui/components/dock/dock.ts +960 -0
  141. package/dist/ui/components/dock/index.ts +2 -0
  142. package/dist/ui/components/empty-state/empty-state.test.ts +28 -39
  143. package/dist/ui/components/glass/concentric-radius.test.ts +13 -0
  144. package/dist/ui/components/glass/concentric-radius.ts +17 -0
  145. package/dist/ui/components/glass/glass-design.test.ts +78 -0
  146. package/dist/ui/components/glass/glass-design.ts +119 -0
  147. package/dist/ui/components/glass/glass.test.ts +338 -0
  148. package/dist/ui/components/glass/glass.ts +360 -0
  149. package/dist/ui/components/glass/index.ts +18 -0
  150. package/dist/ui/components/icon/icon-theme.test.ts +169 -0
  151. package/dist/ui/components/icon/icon-theme.ts +227 -0
  152. package/dist/ui/components/icon/icon.test.ts +85 -25
  153. package/dist/ui/components/icon/icon.ts +38 -21
  154. package/dist/ui/components/input/input.test.ts +178 -101
  155. package/dist/ui/components/input/input.ts +15 -12
  156. package/dist/ui/components/label/label.test.ts +11 -24
  157. package/dist/ui/components/line-chart/index.ts +2 -3
  158. package/dist/ui/components/line-chart/line-chart.test.ts +149 -56
  159. package/dist/ui/components/line-chart/line-chart.ts +83 -241
  160. package/dist/ui/components/list/list.test.ts +119 -21
  161. package/dist/ui/components/list/list.ts +21 -15
  162. package/dist/ui/components/menu/index.ts +25 -0
  163. package/dist/ui/components/menu/menu-placement.test.ts +153 -0
  164. package/dist/ui/components/menu/menu-placement.ts +159 -0
  165. package/dist/ui/components/menu/menu-popup.test.ts +632 -0
  166. package/dist/ui/components/menu/menu-popup.ts +544 -0
  167. package/dist/ui/components/menu/menu.test.ts +429 -0
  168. package/dist/ui/components/menu/menu.ts +415 -0
  169. package/dist/ui/components/nav-drawer/nav-drawer.test.ts +435 -191
  170. package/dist/ui/components/nav-drawer/nav-drawer.ts +127 -56
  171. package/dist/ui/components/pagination/pagination.test.ts +177 -65
  172. package/dist/ui/components/pagination/pagination.ts +55 -8
  173. package/dist/ui/components/progress/progress.test.ts +102 -46
  174. package/dist/ui/components/progress/progress.ts +52 -54
  175. package/dist/ui/components/radio-group/radio-group.test.ts +128 -83
  176. package/dist/ui/components/radio-group/radio-group.ts +24 -24
  177. package/dist/ui/components/scatter-chart/index.ts +2 -3
  178. package/dist/ui/components/scatter-chart/scatter-chart.test.ts +131 -26
  179. package/dist/ui/components/scatter-chart/scatter-chart.ts +104 -250
  180. package/dist/ui/components/scroll-area/scroll-area.test.ts +95 -24
  181. package/dist/ui/components/scroll-area/scroll-area.ts +8 -8
  182. package/dist/ui/components/select/select.test.ts +138 -78
  183. package/dist/ui/components/select/select.ts +17 -11
  184. package/dist/ui/components/separator/separator.test.ts +18 -17
  185. package/dist/ui/components/sheet/sheet.test.ts +64 -11
  186. package/dist/ui/components/sheet/sheet.ts +9 -1
  187. package/dist/ui/components/skeleton/skeleton.test.ts +24 -7
  188. package/dist/ui/components/skeleton/skeleton.ts +10 -16
  189. package/dist/ui/components/spinner/spinner.test.ts +67 -22
  190. package/dist/ui/components/spinner/spinner.ts +48 -41
  191. package/dist/ui/components/switch/switch.test.ts +116 -46
  192. package/dist/ui/components/switch/switch.ts +8 -13
  193. package/dist/ui/components/tab-bar/index.ts +1 -0
  194. package/dist/ui/components/tab-bar/tab-bar.test.ts +280 -0
  195. package/dist/ui/components/tab-bar/tab-bar.ts +230 -0
  196. package/dist/ui/components/tabs/tabs.test.ts +215 -157
  197. package/dist/ui/components/tabs/tabs.ts +110 -118
  198. package/dist/ui/components/textarea/textarea.test.ts +206 -100
  199. package/dist/ui/components/textarea/textarea.ts +14 -12
  200. package/dist/ui/components/toast/toast.test.ts +436 -315
  201. package/dist/ui/components/toast/toast.ts +62 -55
  202. package/dist/ui/components/toggle/toggle.test.ts +247 -140
  203. package/dist/ui/theme/chart-colors.test.ts +35 -0
  204. package/dist/ui/theme/dark.css +46 -2
  205. package/dist/ui/theme/default.css +63 -7
  206. package/dist/ui/theme/icon-colors.test.ts +35 -0
  207. package/dist/ui/theme/rgb-channels.test.ts +84 -0
  208. package/dist/ui/theme/tailwind-build.test.ts +114 -0
  209. package/dist/ui/theme/tailwind-css.test.ts +83 -0
  210. package/dist/ui/theme/tailwind-plugin.test.ts +42 -2
  211. package/dist/ui/theme/tailwind-plugin.ts +98 -25
  212. package/dist/ui/theme/tailwind.css +113 -0
  213. package/dist/ui/utils/animate.test.ts +13 -1
  214. package/dist/utils/analyze.d.ts +14 -0
  215. package/dist/utils/analyze.js +15 -0
  216. package/dist/utils/analyze.js.map +1 -1
  217. package/dist/utils/analyze.test.js +14 -1
  218. package/dist/utils/analyze.test.js.map +1 -1
  219. package/dist/utils/installed.d.ts +29 -0
  220. package/dist/utils/installed.js +43 -0
  221. package/dist/utils/installed.js.map +1 -0
  222. package/dist/utils/installed.test.d.ts +1 -0
  223. package/dist/utils/installed.test.js +57 -0
  224. package/dist/utils/installed.test.js.map +1 -0
  225. package/dist/utils/interactive.d.ts +9 -0
  226. package/dist/utils/interactive.js +10 -0
  227. package/dist/utils/interactive.js.map +1 -0
  228. package/dist/utils/interactive.test.d.ts +1 -0
  229. package/dist/utils/interactive.test.js +24 -0
  230. package/dist/utils/interactive.test.js.map +1 -0
  231. package/dist/utils/packages.d.ts +36 -0
  232. package/dist/utils/packages.js +70 -0
  233. package/dist/utils/packages.js.map +1 -0
  234. package/dist/utils/packages.test.d.ts +1 -0
  235. package/dist/utils/packages.test.js +89 -0
  236. package/dist/utils/packages.test.js.map +1 -0
  237. package/dist/utils/resolve-paths.d.ts +17 -1
  238. package/dist/utils/resolve-paths.js +21 -3
  239. package/dist/utils/resolve-paths.js.map +1 -1
  240. package/dist/utils/resolve-paths.test.js +38 -2
  241. package/dist/utils/resolve-paths.test.js.map +1 -1
  242. package/dist/utils/tailwind.d.ts +25 -0
  243. package/dist/utils/tailwind.js +51 -0
  244. package/dist/utils/tailwind.js.map +1 -0
  245. package/dist/utils/tailwind.test.d.ts +1 -0
  246. package/dist/utils/tailwind.test.js +71 -0
  247. package/dist/utils/tailwind.test.js.map +1 -0
  248. package/package.json +13 -1
  249. package/dist/ui/components/area-chart/area-chart-render.test.ts +0 -121
  250. package/dist/ui/components/bar-chart/bar-chart-render.test.ts +0 -174
  251. package/dist/ui/components/button/button-render.test.ts +0 -113
  252. package/dist/ui/components/button-group/button-group-render.test.ts +0 -146
  253. package/dist/ui/components/candlestick-chart/candlestick-chart-render.test.ts +0 -174
  254. package/dist/ui/components/cartesian-chart/cartesian-chart-render.test.ts +0 -188
  255. package/dist/ui/components/cartesian-chart/cartesian-chart.test.ts +0 -525
  256. package/dist/ui/components/cartesian-chart/cartesian-chart.ts +0 -1140
  257. package/dist/ui/components/cartesian-chart/index.ts +0 -18
  258. package/dist/ui/components/line-chart/line-chart-render.test.ts +0 -121
  259. package/dist/ui/components/scatter-chart/scatter-chart-render.test.ts +0 -157
@@ -1,74 +1,199 @@
1
+ import { Component, signal } from '@angular/core';
2
+ import {
3
+ fireEvent,
4
+ render,
5
+ waitForUpdate,
6
+ } from '@blotch/angular-lynx-testing-library';
7
+ import { createChartRuntime } from '@tanstack/charts/runtime';
8
+ import { createChartTooltipContent } from '@tanstack/charts/tooltip/model';
9
+ import type {
10
+ ChartDefinition,
11
+ ChartTooltipOptions,
12
+ SceneNode,
13
+ } from '@tanstack/charts/types';
1
14
  import { describe, expect, it } from 'vitest';
2
- import { computeCandles } from './candlestick-chart';
15
+ import {
16
+ type CandlestickDatum,
17
+ UiCandlestickChart,
18
+ candlestickChartDefinition,
19
+ } from './candlestick-chart';
3
20
 
4
- // A rising candle centered at cx=50. Screen y grows downward, so the projected
5
- // highY (top of the wick) is the smallest pixel value and lowY the largest.
6
- // close is above open (up), so closeY < openY in pixels.
7
- const upCandle = {
8
- cx: 50,
9
- highY: 10, // high price → top of plot
10
- lowY: 90, // low price → bottom of plot
11
- openY: 70,
12
- closeY: 30,
13
- up: true,
14
- };
21
+ const data = [
22
+ { x: 0, open: 100, high: 104, low: 98, close: 102 },
23
+ { x: 1, open: 102, high: 103, low: 97, close: 99 },
24
+ ];
15
25
 
16
- describe('computeCandles', () => {
17
- it('draws the wick spanning high to low, centered on cx', () => {
18
- const [shape] = computeCandles([upCandle], 12);
19
- expect(shape.wick.top).toBe(10); // min(highY, lowY)
20
- expect(shape.wick.height).toBe(80); // |lowY - highY|
21
- expect(shape.wick.width).toBe(1); // default wickWidth
22
- // Centered: left = cx - wickWidth/2.
23
- expect(shape.wick.left).toBe(50 - 0.5);
26
+ const render2 = (definition: ChartDefinition<any, any, any>) => {
27
+ const scene = createChartRuntime().render(definition, {
28
+ width: 300,
29
+ height: 200,
24
30
  });
31
+ const found: SceneNode[] = [];
32
+ const walk = (nodes: readonly SceneNode[]) => {
33
+ for (const node of nodes) {
34
+ if (node.kind === 'group') {
35
+ if (!node.focus) walk(node.children);
36
+ } else if (node.kind !== 'label') found.push(node);
37
+ }
38
+ };
39
+ walk(scene.nodes);
40
+ return { scene, found };
41
+ };
25
42
 
26
- it('draws the body between open and close, centered on cx', () => {
27
- const [shape] = computeCandles([upCandle], 12);
28
- expect(shape.body.top).toBe(30); // min(openY, closeY) — the higher price
29
- expect(shape.body.height).toBe(40); // |closeY - openY|
30
- expect(shape.body.width).toBe(12);
31
- expect(shape.body.left).toBe(50 - 6); // cx - bodyWidth/2
32
- expect(shape.up).toBe(true);
43
+ describe('candlestickChartDefinition', () => {
44
+ it('draws a wick and a body per candle, colored by direction', () => {
45
+ const { scene, found } = render2(candlestickChartDefinition({ data }));
46
+ const bodies = found.filter((n) => n.kind === 'rect');
47
+ expect(bodies.map((body) => body.style?.fill)).toEqual([
48
+ 'rgba(34, 197, 94, 1)',
49
+ 'rgba(239, 68, 68, 1)',
50
+ ]);
51
+ // The y axis spans the lows and highs.
52
+ expect(scene.scales['y']!.domain[0]).toBeLessThanOrEqual(97);
53
+ expect(scene.scales['y']!.domain[1]).toBeGreaterThanOrEqual(104);
54
+ expect(found.some((n) => n.kind === 'rule' || n.kind === 'polyline')).toBe(
55
+ true,
56
+ );
33
57
  });
34
58
 
35
- it('marks a falling candle as down and still tops the body at the higher price', () => {
36
- // close below open: closeY (pixels) is BELOW openY, i.e. larger.
37
- const downCandle = {
38
- cx: 20,
39
- highY: 5,
40
- lowY: 95,
41
- openY: 30,
42
- closeY: 60,
43
- up: false,
59
+ it('lists all four prices in the tooltip', () => {
60
+ const definition = candlestickChartDefinition({
61
+ data,
62
+ upColor: 'green',
63
+ downColor: 'red',
64
+ });
65
+ const { scene } = render2(definition);
66
+ const point = scene.points.find((p) => (p.datum as { x: number }).x === 1)!;
67
+ const content = createChartTooltipContent(
68
+ [point],
69
+ scene,
70
+ false,
71
+ definition.tooltip as unknown as ChartTooltipOptions,
72
+ point,
73
+ );
74
+ expect(content).toEqual({
75
+ title: '1',
76
+ color: 'red',
77
+ rows: [
78
+ { label: 'Open', value: '102' },
79
+ { label: 'High', value: '103' },
80
+ { label: 'Low', value: '97' },
81
+ { label: 'Close', value: '99' },
82
+ ],
83
+ });
84
+ const custom = (
85
+ definition.tooltip as unknown as Required<ChartTooltipOptions>
86
+ ).content;
87
+ const context = {
88
+ pinned: false,
89
+ xLabel: 'x',
90
+ yLabel: 'y',
91
+ formatX: (v: unknown) => `x${v}`,
92
+ formatY: (v: unknown) => `y${v}`,
44
93
  };
45
- const [shape] = computeCandles([downCandle], 10);
46
- expect(shape.up).toBe(false);
47
- expect(shape.body.top).toBe(30); // min(openY, closeY) = openY here
48
- expect(shape.body.height).toBe(30);
94
+ expect(custom([], context)).toEqual({ title: undefined, rows: [] });
95
+ // Points of other marks (say, a moving average added on top) get x/y rows.
96
+ expect(
97
+ custom(
98
+ [{ datum: { x: 1, y: 2 }, xValue: 1, yValue: 2 } as never],
99
+ context,
100
+ ),
101
+ ).toEqual({ title: 'x1', rows: [{ label: 'y', value: 'y2' }] });
102
+ expect(
103
+ custom([{ datum: null, xValue: 3, yValue: 4 } as never], context),
104
+ ).toMatchObject({
105
+ title: 'x3',
106
+ });
107
+ const up = scene.points.find((p) => (p.datum as { x: number }).x === 0)!;
108
+ expect(
109
+ createChartTooltipContent(
110
+ [up],
111
+ scene,
112
+ false,
113
+ definition.tooltip as unknown as ChartTooltipOptions,
114
+ up,
115
+ ),
116
+ ).toMatchObject({ color: 'green' });
49
117
  });
50
118
 
51
- it('clamps a doji (open === close) to the minimum body height', () => {
52
- const doji = {
53
- cx: 0,
54
- highY: 0,
55
- lowY: 100,
56
- openY: 50,
57
- closeY: 50,
58
- up: true,
59
- };
60
- // Zero-height body would be invisible; the floor keeps it a thin line.
61
- expect(computeCandles([doji], 12)[0].body.height).toBe(1);
62
- expect(computeCandles([doji], 12, 1, 3)[0].body.height).toBe(3);
119
+ it('can drop the tooltip, and clamps the body ratio', () => {
120
+ const definition = candlestickChartDefinition({
121
+ data,
122
+ tooltip: false,
123
+ bodyWidthRatio: 5,
124
+ });
125
+ expect(definition.tooltip).toBe(false);
126
+ expect(render2(definition).found.length).toBeGreaterThan(0);
63
127
  });
128
+ });
129
+
130
+ @Component({
131
+ imports: [UiCandlestickChart],
132
+ template: `
133
+ <ui-candlestick-chart
134
+ [data]="data"
135
+ [width]="300"
136
+ [upColor]="upColor()"
137
+ downColor="red"
138
+ (candleTap)="tapped.push($event)"
139
+ />
140
+ `,
141
+ })
142
+ class CandlestickChartHost {
143
+ readonly data = data;
144
+ readonly upColor = signal('green');
145
+ /** Every `candleTap`, in order. */
146
+ readonly tapped: CandlestickDatum[] = [];
147
+ }
148
+
149
+ /**
150
+ * The SVG the chart's marks layer draws.
151
+ */
152
+ const marksSvg = (container: Element) =>
153
+ container.querySelectorAll('svg')[1]!.getAttribute('content')!;
64
154
 
65
- it('honors a custom wick width', () => {
66
- const [shape] = computeCandles([upCandle], 12, 3);
67
- expect(shape.wick.width).toBe(3);
68
- expect(shape.wick.left).toBe(50 - 1.5);
155
+ /**
156
+ * The middle of each candle body the chart drew.
157
+ */
158
+ const bodiesDrawn = (container: Element) =>
159
+ [
160
+ ...marksSvg(container).matchAll(
161
+ /<rect x="([\d.-]+)" y="([\d.-]+)" width="([\d.-]+)" height="([\d.-]+)"[^>]*fill=/g,
162
+ ),
163
+ ].map(([, x, y, width, height]) => ({
164
+ x: Number(x) + Number(width) / 2,
165
+ y: Number(y) + Number(height) / 2,
166
+ }));
167
+
168
+ /**
169
+ * Touches a spot of the chart and lifts the finger right there: a tap.
170
+ */
171
+ const tap = async (container: Element, at: { x: number; y: number }) => {
172
+ const root = container.querySelector('[accessibility-label]')!;
173
+ fireEvent.touchstart(root, { touches: [at] });
174
+ fireEvent.touchend(root, { touches: [at] });
175
+ await waitForUpdate();
176
+ };
177
+
178
+ describe('UiCandlestickChart', () => {
179
+ it('colors each candle by direction with its inputs', async () => {
180
+ const { componentRef, container } = await render(CandlestickChartHost);
181
+ expect(bodiesDrawn(container)).toHaveLength(2);
182
+ expect(marksSvg(container)).toContain('fill="green"');
183
+ expect(marksSvg(container)).toContain('fill="red"');
184
+
185
+ (componentRef.instance as CandlestickChartHost).upColor.set('blue');
186
+ await waitForUpdate();
187
+ expect(marksSvg(container)).toContain('fill="blue"');
69
188
  });
70
189
 
71
- it('returns an empty array for no candles', () => {
72
- expect(computeCandles([], 12)).toEqual([]);
190
+ it("emits a tapped candle's datum, and nothing for a tap off the candles", async () => {
191
+ const { componentRef, container } = await render(CandlestickChartHost);
192
+ const host = componentRef.instance as CandlestickChartHost;
193
+ await tap(container, bodiesDrawn(container)[0]!);
194
+ expect(host.tapped).toEqual([data[0]]);
195
+
196
+ await tap(container, { x: -100, y: -100 });
197
+ expect(host.tapped).toEqual([data[0]]);
73
198
  });
74
199
  });