@zuttora/charts 0.1.0 → 0.3.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 (47) hide show
  1. package/README.md +16 -2
  2. package/dist/chart.js +24 -0
  3. package/dist/chartState.d.ts +6 -0
  4. package/dist/chartState.js +5 -0
  5. package/dist/core/drawings.d.ts +21 -0
  6. package/dist/core/drawings.js +46 -0
  7. package/dist/core/indicatorSet.d.ts +20 -0
  8. package/dist/core/indicatorSet.js +66 -0
  9. package/dist/core/indicators.d.ts +53 -0
  10. package/dist/core/indicators.js +187 -0
  11. package/dist/core/types.d.ts +21 -0
  12. package/dist/dom/indicatorReadings.d.ts +7 -0
  13. package/dist/dom/indicatorReadings.js +26 -0
  14. package/dist/dom/legend.d.ts +5 -0
  15. package/dist/dom/legend.js +10 -1
  16. package/dist/dom/legendSync.js +8 -1
  17. package/dist/draw/controller.d.ts +36 -0
  18. package/dist/draw/controller.js +151 -0
  19. package/dist/draw/geometry.d.ts +44 -0
  20. package/dist/draw/geometry.js +118 -0
  21. package/dist/draw/mapper.d.ts +30 -0
  22. package/dist/draw/mapper.js +32 -0
  23. package/dist/draw/pointer.d.ts +17 -0
  24. package/dist/draw/pointer.js +144 -0
  25. package/dist/draw/state.d.ts +61 -0
  26. package/dist/draw/state.js +8 -0
  27. package/dist/drawApi.d.ts +20 -0
  28. package/dist/drawApi.js +59 -0
  29. package/dist/host.d.ts +3 -0
  30. package/dist/host.js +1 -0
  31. package/dist/index.d.ts +2 -2
  32. package/dist/index.js +1 -1
  33. package/dist/interact/attach.js +33 -18
  34. package/dist/render/drawCrosshair.js +6 -3
  35. package/dist/render/drawDrawings.d.ts +10 -0
  36. package/dist/render/drawDrawings.js +146 -0
  37. package/dist/render/drawIndicators.d.ts +4 -0
  38. package/dist/render/drawIndicators.js +67 -0
  39. package/dist/render/drawMain.js +13 -0
  40. package/dist/render/drawSubPanes.d.ts +2 -0
  41. package/dist/render/drawSubPanes.js +104 -0
  42. package/dist/render/frame.d.ts +4 -0
  43. package/dist/render/frameBuilder.js +12 -2
  44. package/dist/render/indicatorFrame.d.ts +17 -0
  45. package/dist/render/indicatorFrame.js +55 -0
  46. package/dist/render/paintFrame.js +3 -0
  47. package/package.json +1 -1
@@ -0,0 +1,17 @@
1
+ import type { PriceRange } from '../core/priceScale.ts';
2
+ import type { IndicatorEntry } from '../core/indicatorSet.ts';
3
+ import type { Layout } from './frame.ts';
4
+ export declare const SUB_PAD = 6;
5
+ export declare const RSI_GUIDES: number[];
6
+ export interface SubPane {
7
+ entry: IndicatorEntry;
8
+ top: number;
9
+ height: number;
10
+ min: number;
11
+ max: number;
12
+ }
13
+ export declare function subY(p: SubPane, v: number): number;
14
+ export declare function subValueAt(p: SubPane, y: number): number;
15
+ export declare function mainExtremes(entries: readonly IndicatorEntry[], from: number, to: number): PriceRange | null;
16
+ export declare function buildSubPanes(entries: readonly IndicatorEntry[], layout: Layout, from: number, to: number): SubPane[];
17
+ export declare function subTicks(p: SubPane, decimals: number): number[];
@@ -0,0 +1,55 @@
1
+ import { axisTicks } from "../core/priceScale.js";
2
+ export const SUB_PAD = 6;
3
+ export const RSI_GUIDES = [30, 70];
4
+ export function subY(p, v) {
5
+ return p.top + SUB_PAD + ((p.max - v) / (p.max - p.min)) * Math.max(1, p.height - 2 * SUB_PAD);
6
+ }
7
+ export function subValueAt(p, y) {
8
+ return p.max - ((y - p.top - SUB_PAD) / Math.max(1, p.height - 2 * SUB_PAD)) * (p.max - p.min);
9
+ }
10
+ function scan(lists, from, to, into) {
11
+ for (const values of lists) {
12
+ for (let i = from; i <= to; i++) {
13
+ const v = values[i];
14
+ if (v === null || v === undefined)
15
+ continue;
16
+ if (v < into.min)
17
+ into.min = v;
18
+ if (v > into.max)
19
+ into.max = v;
20
+ }
21
+ }
22
+ }
23
+ export function mainExtremes(entries, from, to) {
24
+ const out = { min: Infinity, max: -Infinity };
25
+ for (const e of entries) {
26
+ const l = e.calc.lines;
27
+ scan(e.spec.type === 'bollinger' ? [l.upper, l.lower] : [l.main], from, to, out);
28
+ }
29
+ return out.min <= out.max ? out : null;
30
+ }
31
+ export function buildSubPanes(entries, layout, from, to) {
32
+ const panes = [];
33
+ entries.forEach((entry, i) => {
34
+ const slot = layout.subs[i];
35
+ if (!slot)
36
+ return;
37
+ let min = 0;
38
+ let max = 100;
39
+ if (entry.spec.type === 'macd') {
40
+ const l = entry.calc.lines;
41
+ const r = { min: 0, max: 0 };
42
+ scan([l.macd, l.signal, l.hist], from, to, r);
43
+ const pad = (r.max - r.min || 1) * 0.08;
44
+ min = r.min - pad;
45
+ max = r.max + pad;
46
+ }
47
+ panes.push({ entry, top: slot.top, height: slot.height, min, max });
48
+ });
49
+ return panes;
50
+ }
51
+ export function subTicks(p, decimals) {
52
+ if (p.entry.spec.type === 'rsi')
53
+ return RSI_GUIDES;
54
+ return axisTicks({ min: p.min, max: p.max }, p.height, 10 ** -(decimals + 2)).map((v) => v + 0);
55
+ }
@@ -1,5 +1,6 @@
1
1
  import { fitCanvas } from "./canvas.js";
2
2
  import { drawCrosshair } from "./drawCrosshair.js";
3
+ import { drawDrawings } from "./drawDrawings.js";
3
4
  import { drawLastPrice, PULSE_MS } from "./drawLastPrice.js";
4
5
  import { drawMain } from "./drawMain.js";
5
6
  import { buildFrame } from "./frameBuilder.js";
@@ -14,6 +15,8 @@ export function paintFrame(s, t, flags, now) {
14
15
  const overlayCtx = fitCanvas(t.overlayCanvas, s.width, s.height, t.dpr());
15
16
  overlayCtx.clearRect(0, 0, s.width, s.height);
16
17
  s.pulses = s.pulses.filter((p) => now - p < PULSE_MS);
18
+ if (s.series.count > 0)
19
+ drawDrawings(overlayCtx, built.frame, { drawings: s.drawings, state: s.draw });
17
20
  if (s.series.forming) {
18
21
  drawLastPrice(overlayCtx, built.frame, {
19
22
  close: s.closeTween.value(now),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuttora/charts",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Zuttora's own canvas charting package: candlesticks, square corners, no runtime dependencies.",
5
5
  "license": "MIT",
6
6
  "type": "module",