@funnest/charts 0.6.11 → 0.6.13

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/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export type { FormatPriceOptions } from './price';
13
13
  export { decimalsOf, formatCompact, formatPrice, krxTickSize, resolveTickSize, roundToTick } from './price';
14
14
  export { isIntradayResolution, resolutionToMs } from './resolution';
15
15
  export type { ChartType } from './render/renderer';
16
- export type { BuiltinDrawingType, Drawing, DrawingDefinition, DrawingGeometry, DrawingPoint, DrawingRenderContext, DrawingStyle, DrawingType, } from './objects/drawings';
16
+ export type { BuiltinDrawingType, Drawing, DrawingDefinition, DrawingGeometry, DrawingPoint, DrawingRenderContext, DrawingStyle, DrawingColorSlot, DrawingType, } from './objects/drawings';
17
17
  export { BUILTIN_DRAWINGS, distToSegment, FIB_LEVELS } from './objects/drawings';
18
18
  export type { ChartOverlay, ObjectRenderContext, PaneCoords } from './objects/types';
19
19
  export type { Painter } from './render/painter';
package/dist/index.js CHANGED
@@ -1265,6 +1265,7 @@ var BUILTIN_DRAWINGS = [
1265
1265
  group: "fib",
1266
1266
  section: { ko: "\uD53C\uBCF4\uB098\uCE58", en: "Fibonacci" },
1267
1267
  clicks: 2,
1268
+ colors: FIB_LEVELS.map((level, i) => ({ key: String(level), name: { ko: String(level), en: String(level) }, color: FIB_COLORS[i] })),
1268
1269
  distance: (g, x, y) => {
1269
1270
  const [x1, y1] = p0(g);
1270
1271
  const [x2, y2] = p1(g);
@@ -1285,7 +1286,7 @@ var BUILTIN_DRAWINGS = [
1285
1286
  FIB_LEVELS.forEach((level, i) => {
1286
1287
  const price = b + (a - b) * level;
1287
1288
  const y = c.priceToY(price);
1288
- const levelColor = d.color ?? FIB_COLORS[i];
1289
+ const levelColor = d.style?.colors?.[String(level)] ?? d.color ?? FIB_COLORS[i];
1289
1290
  if (i > 0) {
1290
1291
  const prevY = c.priceToY(b + (a - b) * FIB_LEVELS[i - 1]);
1291
1292
  ctx.save();
@@ -1490,6 +1491,7 @@ var DrawingManager = class {
1490
1491
  palette: rc.palette,
1491
1492
  color,
1492
1493
  style,
1494
+ colorOf: (key) => style.colors?.[key] ?? d.color ?? def.colors?.find((c2) => c2.key === key)?.color ?? color,
1493
1495
  width: (fallback) => Math.min(8, Math.max(0.5, style.width ?? fallback)),
1494
1496
  dash: (fallback = []) => style.dash ? DASHES[style.dash] : [...fallback],
1495
1497
  bars,
@@ -24,6 +24,18 @@ export interface DrawingStyle {
24
24
  fontSize?: number;
25
25
  /** Can't be dragged or edited until unlocked (still selectable). */
26
26
  locked?: boolean;
27
+ /** Colors of the tool's parts (`DrawingDefinition.colors` keys), where set apart from the rest. */
28
+ colors?: Record<string, string>;
29
+ }
30
+ /**
31
+ * A part of a tool with its own color (a Fibonacci level, a position's target zone…). Its color
32
+ * is `style.colors[key]`, else the drawing's color (picking one recolors every part), else `color`.
33
+ */
34
+ export interface DrawingColorSlot {
35
+ key: string;
36
+ name: Record<Locale, string>;
37
+ /** Default color. */
38
+ color: string;
27
39
  }
28
40
  export interface Drawing {
29
41
  id: string;
@@ -45,6 +57,8 @@ export interface DrawingRenderContext extends DrawingGeometry {
45
57
  color: string;
46
58
  /** `drawing.style` (empty object when none). */
47
59
  style: DrawingStyle;
60
+ /** A part's color (see `DrawingDefinition.colors`): its own, else the drawing's, else the default. */
61
+ colorOf(key: string): string;
48
62
  /** The main line width: the drawing's style, else the tool's default. */
49
63
  width(fallback: number): number;
50
64
  /** The main line dash pattern for canvas: the drawing's style, else the tool's default. */
@@ -93,6 +107,8 @@ export interface DrawingDefinition {
93
107
  freehand?: boolean;
94
108
  /** Has text (`style.text`): the widget offers a text field for it when selected. */
95
109
  text?: boolean;
110
+ /** Parts with their own colors: the widget lets each be recolored (read them with `rc.colorOf`). */
111
+ colors?: DrawingColorSlot[];
96
112
  /** Distance in px from (x, y) to the shape, for hit testing. */
97
113
  distance(geometry: DrawingGeometry, x: number, y: number): number;
98
114
  render(drawing: Drawing, rc: DrawingRenderContext): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnest/charts",
3
- "version": "0.6.11",
3
+ "version": "0.6.13",
4
4
  "description": "Canvas charting engine for financial charts",
5
5
  "keywords": [
6
6
  "chart",