hyperprop-charting-library 0.1.69 → 0.1.70
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/hyperprop-charting-library.cjs +24 -8
- package/dist/hyperprop-charting-library.d.ts +10 -2
- package/dist/hyperprop-charting-library.js +23 -8
- package/dist/index.cjs +24 -8
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +23 -8
- package/docs/API.md +1 -0
- package/package.json +1 -1
|
@@ -20,9 +20,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
FIB_DEFAULT_PALETTE: () => FIB_DEFAULT_PALETTE,
|
|
23
24
|
createChart: () => createChart
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var FIB_DEFAULT_PALETTE = [
|
|
28
|
+
"#787b86",
|
|
29
|
+
"#f23645",
|
|
30
|
+
"#ff9800",
|
|
31
|
+
"#4caf50",
|
|
32
|
+
"#089981",
|
|
33
|
+
"#00bcd4",
|
|
34
|
+
"#2962ff",
|
|
35
|
+
"#9c27b0"
|
|
36
|
+
];
|
|
26
37
|
var DEFAULT_GRID_OPTIONS = {
|
|
27
38
|
color: "#2b2f38",
|
|
28
39
|
opacity: 0.38,
|
|
@@ -944,6 +955,7 @@ function createChart(element, options = {}) {
|
|
|
944
955
|
})),
|
|
945
956
|
visible: drawing.visible ?? true,
|
|
946
957
|
color: drawing.color ?? "#94a3b8",
|
|
958
|
+
colors: Array.isArray(drawing.colors) ? drawing.colors.filter((value) => typeof value === "string") : [],
|
|
947
959
|
style: drawing.style ?? "dotted",
|
|
948
960
|
width: Math.max(1, Number(drawing.width) || 1),
|
|
949
961
|
locked: drawing.locked ?? false,
|
|
@@ -955,6 +967,7 @@ function createChart(element, options = {}) {
|
|
|
955
967
|
points: drawing.points.map((point) => ({ ...point })),
|
|
956
968
|
visible: drawing.visible,
|
|
957
969
|
color: drawing.color,
|
|
970
|
+
colors: [...drawing.colors],
|
|
958
971
|
style: drawing.style,
|
|
959
972
|
width: drawing.width,
|
|
960
973
|
locked: drawing.locked,
|
|
@@ -2244,32 +2257,33 @@ function createChart(element, options = {}) {
|
|
|
2244
2257
|
const secondY = yFromPrice(second.price);
|
|
2245
2258
|
const lineLeft = chartLeft;
|
|
2246
2259
|
const lineRight = chartRight;
|
|
2260
|
+
const palette = drawing.colors.length > 0 ? drawing.colors : null;
|
|
2261
|
+
const levelColorAt = (index) => palette ? palette[index % palette.length] : drawing.color;
|
|
2247
2262
|
const levelLines = FIB_RATIOS.map((ratio) => {
|
|
2248
2263
|
const price = first.price + (second.price - first.price) * (1 - ratio);
|
|
2249
2264
|
return { ratio, price, y: yFromPrice(price) };
|
|
2250
2265
|
});
|
|
2251
|
-
const bandColor = hexToRgba(drawing.color, 0.1);
|
|
2252
2266
|
for (let index = 0; index < levelLines.length - 1; index += 1) {
|
|
2253
2267
|
const top = levelLines[index];
|
|
2254
2268
|
const bottom = levelLines[index + 1];
|
|
2255
2269
|
const bandTop = Math.min(top.y, bottom.y);
|
|
2256
2270
|
const bandBottom = Math.max(top.y, bottom.y);
|
|
2257
2271
|
ctx.save();
|
|
2258
|
-
ctx.fillStyle =
|
|
2272
|
+
ctx.fillStyle = hexToRgba(levelColorAt(index), 0.1);
|
|
2259
2273
|
ctx.globalAlpha = draft ? 0.5 : 1;
|
|
2260
2274
|
ctx.fillRect(lineLeft, bandTop, lineRight - lineLeft, bandBottom - bandTop);
|
|
2261
2275
|
ctx.restore();
|
|
2262
2276
|
}
|
|
2263
2277
|
ctx.save();
|
|
2264
2278
|
ctx.lineWidth = drawing.width;
|
|
2265
|
-
ctx.strokeStyle = drawing.color;
|
|
2266
2279
|
applyDashPattern(drawing.style, dashPatterns.dotted, dashPatterns.dashed);
|
|
2267
|
-
|
|
2280
|
+
levelLines.forEach((level, index) => {
|
|
2281
|
+
ctx.strokeStyle = levelColorAt(index);
|
|
2268
2282
|
ctx.beginPath();
|
|
2269
2283
|
ctx.moveTo(crisp(lineLeft), crisp(level.y));
|
|
2270
2284
|
ctx.lineTo(crisp(lineRight), crisp(level.y));
|
|
2271
2285
|
ctx.stroke();
|
|
2272
|
-
}
|
|
2286
|
+
});
|
|
2273
2287
|
ctx.restore();
|
|
2274
2288
|
ctx.save();
|
|
2275
2289
|
ctx.strokeStyle = hexToRgba(drawing.color, 0.5);
|
|
@@ -2284,7 +2298,7 @@ function createChart(element, options = {}) {
|
|
|
2284
2298
|
drawDrawingHandle(secondX, secondY, drawing.color);
|
|
2285
2299
|
const prevFont = ctx.font;
|
|
2286
2300
|
ctx.font = `500 11px ${mergedOptions.fontFamily}`;
|
|
2287
|
-
|
|
2301
|
+
levelLines.forEach((level, index) => {
|
|
2288
2302
|
const labelText = `${level.ratio} (${formatPrice(level.price)})`;
|
|
2289
2303
|
const textWidth = ctx.measureText(labelText).width;
|
|
2290
2304
|
const padding = 4;
|
|
@@ -2292,11 +2306,11 @@ function createChart(element, options = {}) {
|
|
|
2292
2306
|
const bgY = level.y - 9;
|
|
2293
2307
|
ctx.fillStyle = mergedOptions.backgroundColor;
|
|
2294
2308
|
fillRoundedRect(bgX, bgY, textWidth + padding * 2, 16, 3);
|
|
2295
|
-
ctx.fillStyle =
|
|
2309
|
+
ctx.fillStyle = levelColorAt(index);
|
|
2296
2310
|
ctx.textAlign = "left";
|
|
2297
2311
|
ctx.textBaseline = "middle";
|
|
2298
2312
|
ctx.fillText(labelText, bgX + padding, bgY + 8);
|
|
2299
|
-
}
|
|
2313
|
+
});
|
|
2300
2314
|
ctx.font = prevFont;
|
|
2301
2315
|
}
|
|
2302
2316
|
}
|
|
@@ -3620,6 +3634,7 @@ function createChart(element, options = {}) {
|
|
|
3620
3634
|
type: "fib-retracement",
|
|
3621
3635
|
points: [point, point],
|
|
3622
3636
|
color: defaults.color ?? "#2563eb",
|
|
3637
|
+
colors: defaults.colors ?? FIB_DEFAULT_PALETTE,
|
|
3623
3638
|
style: defaults.style ?? "solid",
|
|
3624
3639
|
width: defaults.width ?? 1
|
|
3625
3640
|
});
|
|
@@ -4549,5 +4564,6 @@ function createChart(element, options = {}) {
|
|
|
4549
4564
|
}
|
|
4550
4565
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4551
4566
|
0 && (module.exports = {
|
|
4567
|
+
FIB_DEFAULT_PALETTE,
|
|
4552
4568
|
createChart
|
|
4553
4569
|
});
|
|
@@ -56,11 +56,19 @@ interface DrawingObjectOptions {
|
|
|
56
56
|
points: DrawingPoint[];
|
|
57
57
|
visible?: boolean;
|
|
58
58
|
color?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Optional per-level colors. Currently used by `fib-retracement`: when set
|
|
61
|
+
* (non-empty), each level/band cycles through these colors instead of using
|
|
62
|
+
* the single `color`. Leave empty for a monochrome drawing.
|
|
63
|
+
*/
|
|
64
|
+
colors?: string[];
|
|
59
65
|
style?: "solid" | "dotted" | "dashed";
|
|
60
66
|
width?: number;
|
|
61
67
|
label?: string;
|
|
62
68
|
locked?: boolean;
|
|
63
69
|
}
|
|
70
|
+
/** Default multi-color palette for fib-retracement levels. */
|
|
71
|
+
declare const FIB_DEFAULT_PALETTE: string[];
|
|
64
72
|
interface DrawingSelectEvent {
|
|
65
73
|
drawing: DrawingObjectOptions;
|
|
66
74
|
target: "line" | "handle";
|
|
@@ -74,7 +82,7 @@ interface DrawingHoverEvent {
|
|
|
74
82
|
x: number;
|
|
75
83
|
y: number;
|
|
76
84
|
}
|
|
77
|
-
type DrawingDefaults = Partial<Pick<DrawingObjectOptions, "color" | "style" | "width">>;
|
|
85
|
+
type DrawingDefaults = Partial<Pick<DrawingObjectOptions, "color" | "colors" | "style" | "width">>;
|
|
78
86
|
interface IndicatorInstanceOptions<TInputs extends Record<string, unknown> = Record<string, unknown>> {
|
|
79
87
|
id?: string;
|
|
80
88
|
type: string;
|
|
@@ -447,4 +455,4 @@ interface ViewportState {
|
|
|
447
455
|
}
|
|
448
456
|
declare function createChart(element: HTMLElement, options?: ChartOptions): ChartInstance;
|
|
449
457
|
|
|
450
|
-
export { type AxisOptions, type BuiltInIndicatorInfo, type ChartClickEvent, type ChartInstance, type ChartOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingToolType, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, type PriceLineOptions, type TickerLineOptions, type ViewportState, type WatermarkOptions, createChart };
|
|
458
|
+
export { type AxisOptions, type BuiltInIndicatorInfo, type ChartClickEvent, type ChartInstance, type ChartOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingToolType, FIB_DEFAULT_PALETTE, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, type PriceLineOptions, type TickerLineOptions, type ViewportState, type WatermarkOptions, createChart };
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
var FIB_DEFAULT_PALETTE = [
|
|
3
|
+
"#787b86",
|
|
4
|
+
"#f23645",
|
|
5
|
+
"#ff9800",
|
|
6
|
+
"#4caf50",
|
|
7
|
+
"#089981",
|
|
8
|
+
"#00bcd4",
|
|
9
|
+
"#2962ff",
|
|
10
|
+
"#9c27b0"
|
|
11
|
+
];
|
|
2
12
|
var DEFAULT_GRID_OPTIONS = {
|
|
3
13
|
color: "#2b2f38",
|
|
4
14
|
opacity: 0.38,
|
|
@@ -920,6 +930,7 @@ function createChart(element, options = {}) {
|
|
|
920
930
|
})),
|
|
921
931
|
visible: drawing.visible ?? true,
|
|
922
932
|
color: drawing.color ?? "#94a3b8",
|
|
933
|
+
colors: Array.isArray(drawing.colors) ? drawing.colors.filter((value) => typeof value === "string") : [],
|
|
923
934
|
style: drawing.style ?? "dotted",
|
|
924
935
|
width: Math.max(1, Number(drawing.width) || 1),
|
|
925
936
|
locked: drawing.locked ?? false,
|
|
@@ -931,6 +942,7 @@ function createChart(element, options = {}) {
|
|
|
931
942
|
points: drawing.points.map((point) => ({ ...point })),
|
|
932
943
|
visible: drawing.visible,
|
|
933
944
|
color: drawing.color,
|
|
945
|
+
colors: [...drawing.colors],
|
|
934
946
|
style: drawing.style,
|
|
935
947
|
width: drawing.width,
|
|
936
948
|
locked: drawing.locked,
|
|
@@ -2220,32 +2232,33 @@ function createChart(element, options = {}) {
|
|
|
2220
2232
|
const secondY = yFromPrice(second.price);
|
|
2221
2233
|
const lineLeft = chartLeft;
|
|
2222
2234
|
const lineRight = chartRight;
|
|
2235
|
+
const palette = drawing.colors.length > 0 ? drawing.colors : null;
|
|
2236
|
+
const levelColorAt = (index) => palette ? palette[index % palette.length] : drawing.color;
|
|
2223
2237
|
const levelLines = FIB_RATIOS.map((ratio) => {
|
|
2224
2238
|
const price = first.price + (second.price - first.price) * (1 - ratio);
|
|
2225
2239
|
return { ratio, price, y: yFromPrice(price) };
|
|
2226
2240
|
});
|
|
2227
|
-
const bandColor = hexToRgba(drawing.color, 0.1);
|
|
2228
2241
|
for (let index = 0; index < levelLines.length - 1; index += 1) {
|
|
2229
2242
|
const top = levelLines[index];
|
|
2230
2243
|
const bottom = levelLines[index + 1];
|
|
2231
2244
|
const bandTop = Math.min(top.y, bottom.y);
|
|
2232
2245
|
const bandBottom = Math.max(top.y, bottom.y);
|
|
2233
2246
|
ctx.save();
|
|
2234
|
-
ctx.fillStyle =
|
|
2247
|
+
ctx.fillStyle = hexToRgba(levelColorAt(index), 0.1);
|
|
2235
2248
|
ctx.globalAlpha = draft ? 0.5 : 1;
|
|
2236
2249
|
ctx.fillRect(lineLeft, bandTop, lineRight - lineLeft, bandBottom - bandTop);
|
|
2237
2250
|
ctx.restore();
|
|
2238
2251
|
}
|
|
2239
2252
|
ctx.save();
|
|
2240
2253
|
ctx.lineWidth = drawing.width;
|
|
2241
|
-
ctx.strokeStyle = drawing.color;
|
|
2242
2254
|
applyDashPattern(drawing.style, dashPatterns.dotted, dashPatterns.dashed);
|
|
2243
|
-
|
|
2255
|
+
levelLines.forEach((level, index) => {
|
|
2256
|
+
ctx.strokeStyle = levelColorAt(index);
|
|
2244
2257
|
ctx.beginPath();
|
|
2245
2258
|
ctx.moveTo(crisp(lineLeft), crisp(level.y));
|
|
2246
2259
|
ctx.lineTo(crisp(lineRight), crisp(level.y));
|
|
2247
2260
|
ctx.stroke();
|
|
2248
|
-
}
|
|
2261
|
+
});
|
|
2249
2262
|
ctx.restore();
|
|
2250
2263
|
ctx.save();
|
|
2251
2264
|
ctx.strokeStyle = hexToRgba(drawing.color, 0.5);
|
|
@@ -2260,7 +2273,7 @@ function createChart(element, options = {}) {
|
|
|
2260
2273
|
drawDrawingHandle(secondX, secondY, drawing.color);
|
|
2261
2274
|
const prevFont = ctx.font;
|
|
2262
2275
|
ctx.font = `500 11px ${mergedOptions.fontFamily}`;
|
|
2263
|
-
|
|
2276
|
+
levelLines.forEach((level, index) => {
|
|
2264
2277
|
const labelText = `${level.ratio} (${formatPrice(level.price)})`;
|
|
2265
2278
|
const textWidth = ctx.measureText(labelText).width;
|
|
2266
2279
|
const padding = 4;
|
|
@@ -2268,11 +2281,11 @@ function createChart(element, options = {}) {
|
|
|
2268
2281
|
const bgY = level.y - 9;
|
|
2269
2282
|
ctx.fillStyle = mergedOptions.backgroundColor;
|
|
2270
2283
|
fillRoundedRect(bgX, bgY, textWidth + padding * 2, 16, 3);
|
|
2271
|
-
ctx.fillStyle =
|
|
2284
|
+
ctx.fillStyle = levelColorAt(index);
|
|
2272
2285
|
ctx.textAlign = "left";
|
|
2273
2286
|
ctx.textBaseline = "middle";
|
|
2274
2287
|
ctx.fillText(labelText, bgX + padding, bgY + 8);
|
|
2275
|
-
}
|
|
2288
|
+
});
|
|
2276
2289
|
ctx.font = prevFont;
|
|
2277
2290
|
}
|
|
2278
2291
|
}
|
|
@@ -3596,6 +3609,7 @@ function createChart(element, options = {}) {
|
|
|
3596
3609
|
type: "fib-retracement",
|
|
3597
3610
|
points: [point, point],
|
|
3598
3611
|
color: defaults.color ?? "#2563eb",
|
|
3612
|
+
colors: defaults.colors ?? FIB_DEFAULT_PALETTE,
|
|
3599
3613
|
style: defaults.style ?? "solid",
|
|
3600
3614
|
width: defaults.width ?? 1
|
|
3601
3615
|
});
|
|
@@ -4524,5 +4538,6 @@ function createChart(element, options = {}) {
|
|
|
4524
4538
|
};
|
|
4525
4539
|
}
|
|
4526
4540
|
export {
|
|
4541
|
+
FIB_DEFAULT_PALETTE,
|
|
4527
4542
|
createChart
|
|
4528
4543
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -20,9 +20,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
FIB_DEFAULT_PALETTE: () => FIB_DEFAULT_PALETTE,
|
|
23
24
|
createChart: () => createChart
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var FIB_DEFAULT_PALETTE = [
|
|
28
|
+
"#787b86",
|
|
29
|
+
"#f23645",
|
|
30
|
+
"#ff9800",
|
|
31
|
+
"#4caf50",
|
|
32
|
+
"#089981",
|
|
33
|
+
"#00bcd4",
|
|
34
|
+
"#2962ff",
|
|
35
|
+
"#9c27b0"
|
|
36
|
+
];
|
|
26
37
|
var DEFAULT_GRID_OPTIONS = {
|
|
27
38
|
color: "#2b2f38",
|
|
28
39
|
opacity: 0.38,
|
|
@@ -944,6 +955,7 @@ function createChart(element, options = {}) {
|
|
|
944
955
|
})),
|
|
945
956
|
visible: drawing.visible ?? true,
|
|
946
957
|
color: drawing.color ?? "#94a3b8",
|
|
958
|
+
colors: Array.isArray(drawing.colors) ? drawing.colors.filter((value) => typeof value === "string") : [],
|
|
947
959
|
style: drawing.style ?? "dotted",
|
|
948
960
|
width: Math.max(1, Number(drawing.width) || 1),
|
|
949
961
|
locked: drawing.locked ?? false,
|
|
@@ -955,6 +967,7 @@ function createChart(element, options = {}) {
|
|
|
955
967
|
points: drawing.points.map((point) => ({ ...point })),
|
|
956
968
|
visible: drawing.visible,
|
|
957
969
|
color: drawing.color,
|
|
970
|
+
colors: [...drawing.colors],
|
|
958
971
|
style: drawing.style,
|
|
959
972
|
width: drawing.width,
|
|
960
973
|
locked: drawing.locked,
|
|
@@ -2244,32 +2257,33 @@ function createChart(element, options = {}) {
|
|
|
2244
2257
|
const secondY = yFromPrice(second.price);
|
|
2245
2258
|
const lineLeft = chartLeft;
|
|
2246
2259
|
const lineRight = chartRight;
|
|
2260
|
+
const palette = drawing.colors.length > 0 ? drawing.colors : null;
|
|
2261
|
+
const levelColorAt = (index) => palette ? palette[index % palette.length] : drawing.color;
|
|
2247
2262
|
const levelLines = FIB_RATIOS.map((ratio) => {
|
|
2248
2263
|
const price = first.price + (second.price - first.price) * (1 - ratio);
|
|
2249
2264
|
return { ratio, price, y: yFromPrice(price) };
|
|
2250
2265
|
});
|
|
2251
|
-
const bandColor = hexToRgba(drawing.color, 0.1);
|
|
2252
2266
|
for (let index = 0; index < levelLines.length - 1; index += 1) {
|
|
2253
2267
|
const top = levelLines[index];
|
|
2254
2268
|
const bottom = levelLines[index + 1];
|
|
2255
2269
|
const bandTop = Math.min(top.y, bottom.y);
|
|
2256
2270
|
const bandBottom = Math.max(top.y, bottom.y);
|
|
2257
2271
|
ctx.save();
|
|
2258
|
-
ctx.fillStyle =
|
|
2272
|
+
ctx.fillStyle = hexToRgba(levelColorAt(index), 0.1);
|
|
2259
2273
|
ctx.globalAlpha = draft ? 0.5 : 1;
|
|
2260
2274
|
ctx.fillRect(lineLeft, bandTop, lineRight - lineLeft, bandBottom - bandTop);
|
|
2261
2275
|
ctx.restore();
|
|
2262
2276
|
}
|
|
2263
2277
|
ctx.save();
|
|
2264
2278
|
ctx.lineWidth = drawing.width;
|
|
2265
|
-
ctx.strokeStyle = drawing.color;
|
|
2266
2279
|
applyDashPattern(drawing.style, dashPatterns.dotted, dashPatterns.dashed);
|
|
2267
|
-
|
|
2280
|
+
levelLines.forEach((level, index) => {
|
|
2281
|
+
ctx.strokeStyle = levelColorAt(index);
|
|
2268
2282
|
ctx.beginPath();
|
|
2269
2283
|
ctx.moveTo(crisp(lineLeft), crisp(level.y));
|
|
2270
2284
|
ctx.lineTo(crisp(lineRight), crisp(level.y));
|
|
2271
2285
|
ctx.stroke();
|
|
2272
|
-
}
|
|
2286
|
+
});
|
|
2273
2287
|
ctx.restore();
|
|
2274
2288
|
ctx.save();
|
|
2275
2289
|
ctx.strokeStyle = hexToRgba(drawing.color, 0.5);
|
|
@@ -2284,7 +2298,7 @@ function createChart(element, options = {}) {
|
|
|
2284
2298
|
drawDrawingHandle(secondX, secondY, drawing.color);
|
|
2285
2299
|
const prevFont = ctx.font;
|
|
2286
2300
|
ctx.font = `500 11px ${mergedOptions.fontFamily}`;
|
|
2287
|
-
|
|
2301
|
+
levelLines.forEach((level, index) => {
|
|
2288
2302
|
const labelText = `${level.ratio} (${formatPrice(level.price)})`;
|
|
2289
2303
|
const textWidth = ctx.measureText(labelText).width;
|
|
2290
2304
|
const padding = 4;
|
|
@@ -2292,11 +2306,11 @@ function createChart(element, options = {}) {
|
|
|
2292
2306
|
const bgY = level.y - 9;
|
|
2293
2307
|
ctx.fillStyle = mergedOptions.backgroundColor;
|
|
2294
2308
|
fillRoundedRect(bgX, bgY, textWidth + padding * 2, 16, 3);
|
|
2295
|
-
ctx.fillStyle =
|
|
2309
|
+
ctx.fillStyle = levelColorAt(index);
|
|
2296
2310
|
ctx.textAlign = "left";
|
|
2297
2311
|
ctx.textBaseline = "middle";
|
|
2298
2312
|
ctx.fillText(labelText, bgX + padding, bgY + 8);
|
|
2299
|
-
}
|
|
2313
|
+
});
|
|
2300
2314
|
ctx.font = prevFont;
|
|
2301
2315
|
}
|
|
2302
2316
|
}
|
|
@@ -3620,6 +3634,7 @@ function createChart(element, options = {}) {
|
|
|
3620
3634
|
type: "fib-retracement",
|
|
3621
3635
|
points: [point, point],
|
|
3622
3636
|
color: defaults.color ?? "#2563eb",
|
|
3637
|
+
colors: defaults.colors ?? FIB_DEFAULT_PALETTE,
|
|
3623
3638
|
style: defaults.style ?? "solid",
|
|
3624
3639
|
width: defaults.width ?? 1
|
|
3625
3640
|
});
|
|
@@ -4549,5 +4564,6 @@ function createChart(element, options = {}) {
|
|
|
4549
4564
|
}
|
|
4550
4565
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4551
4566
|
0 && (module.exports = {
|
|
4567
|
+
FIB_DEFAULT_PALETTE,
|
|
4552
4568
|
createChart
|
|
4553
4569
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -56,11 +56,19 @@ interface DrawingObjectOptions {
|
|
|
56
56
|
points: DrawingPoint[];
|
|
57
57
|
visible?: boolean;
|
|
58
58
|
color?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Optional per-level colors. Currently used by `fib-retracement`: when set
|
|
61
|
+
* (non-empty), each level/band cycles through these colors instead of using
|
|
62
|
+
* the single `color`. Leave empty for a monochrome drawing.
|
|
63
|
+
*/
|
|
64
|
+
colors?: string[];
|
|
59
65
|
style?: "solid" | "dotted" | "dashed";
|
|
60
66
|
width?: number;
|
|
61
67
|
label?: string;
|
|
62
68
|
locked?: boolean;
|
|
63
69
|
}
|
|
70
|
+
/** Default multi-color palette for fib-retracement levels. */
|
|
71
|
+
declare const FIB_DEFAULT_PALETTE: string[];
|
|
64
72
|
interface DrawingSelectEvent {
|
|
65
73
|
drawing: DrawingObjectOptions;
|
|
66
74
|
target: "line" | "handle";
|
|
@@ -74,7 +82,7 @@ interface DrawingHoverEvent {
|
|
|
74
82
|
x: number;
|
|
75
83
|
y: number;
|
|
76
84
|
}
|
|
77
|
-
type DrawingDefaults = Partial<Pick<DrawingObjectOptions, "color" | "style" | "width">>;
|
|
85
|
+
type DrawingDefaults = Partial<Pick<DrawingObjectOptions, "color" | "colors" | "style" | "width">>;
|
|
78
86
|
interface IndicatorInstanceOptions<TInputs extends Record<string, unknown> = Record<string, unknown>> {
|
|
79
87
|
id?: string;
|
|
80
88
|
type: string;
|
|
@@ -447,4 +455,4 @@ interface ViewportState {
|
|
|
447
455
|
}
|
|
448
456
|
declare function createChart(element: HTMLElement, options?: ChartOptions): ChartInstance;
|
|
449
457
|
|
|
450
|
-
export { type AxisOptions, type BuiltInIndicatorInfo, type ChartClickEvent, type ChartInstance, type ChartOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingToolType, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, type PriceLineOptions, type TickerLineOptions, type ViewportState, type WatermarkOptions, createChart };
|
|
458
|
+
export { type AxisOptions, type BuiltInIndicatorInfo, type ChartClickEvent, type ChartInstance, type ChartOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingToolType, FIB_DEFAULT_PALETTE, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, type PriceLineOptions, type TickerLineOptions, type ViewportState, type WatermarkOptions, createChart };
|
package/dist/index.d.ts
CHANGED
|
@@ -56,11 +56,19 @@ interface DrawingObjectOptions {
|
|
|
56
56
|
points: DrawingPoint[];
|
|
57
57
|
visible?: boolean;
|
|
58
58
|
color?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Optional per-level colors. Currently used by `fib-retracement`: when set
|
|
61
|
+
* (non-empty), each level/band cycles through these colors instead of using
|
|
62
|
+
* the single `color`. Leave empty for a monochrome drawing.
|
|
63
|
+
*/
|
|
64
|
+
colors?: string[];
|
|
59
65
|
style?: "solid" | "dotted" | "dashed";
|
|
60
66
|
width?: number;
|
|
61
67
|
label?: string;
|
|
62
68
|
locked?: boolean;
|
|
63
69
|
}
|
|
70
|
+
/** Default multi-color palette for fib-retracement levels. */
|
|
71
|
+
declare const FIB_DEFAULT_PALETTE: string[];
|
|
64
72
|
interface DrawingSelectEvent {
|
|
65
73
|
drawing: DrawingObjectOptions;
|
|
66
74
|
target: "line" | "handle";
|
|
@@ -74,7 +82,7 @@ interface DrawingHoverEvent {
|
|
|
74
82
|
x: number;
|
|
75
83
|
y: number;
|
|
76
84
|
}
|
|
77
|
-
type DrawingDefaults = Partial<Pick<DrawingObjectOptions, "color" | "style" | "width">>;
|
|
85
|
+
type DrawingDefaults = Partial<Pick<DrawingObjectOptions, "color" | "colors" | "style" | "width">>;
|
|
78
86
|
interface IndicatorInstanceOptions<TInputs extends Record<string, unknown> = Record<string, unknown>> {
|
|
79
87
|
id?: string;
|
|
80
88
|
type: string;
|
|
@@ -447,4 +455,4 @@ interface ViewportState {
|
|
|
447
455
|
}
|
|
448
456
|
declare function createChart(element: HTMLElement, options?: ChartOptions): ChartInstance;
|
|
449
457
|
|
|
450
|
-
export { type AxisOptions, type BuiltInIndicatorInfo, type ChartClickEvent, type ChartInstance, type ChartOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingToolType, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, type PriceLineOptions, type TickerLineOptions, type ViewportState, type WatermarkOptions, createChart };
|
|
458
|
+
export { type AxisOptions, type BuiltInIndicatorInfo, type ChartClickEvent, type ChartInstance, type ChartOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingToolType, FIB_DEFAULT_PALETTE, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, type PriceLineOptions, type TickerLineOptions, type ViewportState, type WatermarkOptions, createChart };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
var FIB_DEFAULT_PALETTE = [
|
|
3
|
+
"#787b86",
|
|
4
|
+
"#f23645",
|
|
5
|
+
"#ff9800",
|
|
6
|
+
"#4caf50",
|
|
7
|
+
"#089981",
|
|
8
|
+
"#00bcd4",
|
|
9
|
+
"#2962ff",
|
|
10
|
+
"#9c27b0"
|
|
11
|
+
];
|
|
2
12
|
var DEFAULT_GRID_OPTIONS = {
|
|
3
13
|
color: "#2b2f38",
|
|
4
14
|
opacity: 0.38,
|
|
@@ -920,6 +930,7 @@ function createChart(element, options = {}) {
|
|
|
920
930
|
})),
|
|
921
931
|
visible: drawing.visible ?? true,
|
|
922
932
|
color: drawing.color ?? "#94a3b8",
|
|
933
|
+
colors: Array.isArray(drawing.colors) ? drawing.colors.filter((value) => typeof value === "string") : [],
|
|
923
934
|
style: drawing.style ?? "dotted",
|
|
924
935
|
width: Math.max(1, Number(drawing.width) || 1),
|
|
925
936
|
locked: drawing.locked ?? false,
|
|
@@ -931,6 +942,7 @@ function createChart(element, options = {}) {
|
|
|
931
942
|
points: drawing.points.map((point) => ({ ...point })),
|
|
932
943
|
visible: drawing.visible,
|
|
933
944
|
color: drawing.color,
|
|
945
|
+
colors: [...drawing.colors],
|
|
934
946
|
style: drawing.style,
|
|
935
947
|
width: drawing.width,
|
|
936
948
|
locked: drawing.locked,
|
|
@@ -2220,32 +2232,33 @@ function createChart(element, options = {}) {
|
|
|
2220
2232
|
const secondY = yFromPrice(second.price);
|
|
2221
2233
|
const lineLeft = chartLeft;
|
|
2222
2234
|
const lineRight = chartRight;
|
|
2235
|
+
const palette = drawing.colors.length > 0 ? drawing.colors : null;
|
|
2236
|
+
const levelColorAt = (index) => palette ? palette[index % palette.length] : drawing.color;
|
|
2223
2237
|
const levelLines = FIB_RATIOS.map((ratio) => {
|
|
2224
2238
|
const price = first.price + (second.price - first.price) * (1 - ratio);
|
|
2225
2239
|
return { ratio, price, y: yFromPrice(price) };
|
|
2226
2240
|
});
|
|
2227
|
-
const bandColor = hexToRgba(drawing.color, 0.1);
|
|
2228
2241
|
for (let index = 0; index < levelLines.length - 1; index += 1) {
|
|
2229
2242
|
const top = levelLines[index];
|
|
2230
2243
|
const bottom = levelLines[index + 1];
|
|
2231
2244
|
const bandTop = Math.min(top.y, bottom.y);
|
|
2232
2245
|
const bandBottom = Math.max(top.y, bottom.y);
|
|
2233
2246
|
ctx.save();
|
|
2234
|
-
ctx.fillStyle =
|
|
2247
|
+
ctx.fillStyle = hexToRgba(levelColorAt(index), 0.1);
|
|
2235
2248
|
ctx.globalAlpha = draft ? 0.5 : 1;
|
|
2236
2249
|
ctx.fillRect(lineLeft, bandTop, lineRight - lineLeft, bandBottom - bandTop);
|
|
2237
2250
|
ctx.restore();
|
|
2238
2251
|
}
|
|
2239
2252
|
ctx.save();
|
|
2240
2253
|
ctx.lineWidth = drawing.width;
|
|
2241
|
-
ctx.strokeStyle = drawing.color;
|
|
2242
2254
|
applyDashPattern(drawing.style, dashPatterns.dotted, dashPatterns.dashed);
|
|
2243
|
-
|
|
2255
|
+
levelLines.forEach((level, index) => {
|
|
2256
|
+
ctx.strokeStyle = levelColorAt(index);
|
|
2244
2257
|
ctx.beginPath();
|
|
2245
2258
|
ctx.moveTo(crisp(lineLeft), crisp(level.y));
|
|
2246
2259
|
ctx.lineTo(crisp(lineRight), crisp(level.y));
|
|
2247
2260
|
ctx.stroke();
|
|
2248
|
-
}
|
|
2261
|
+
});
|
|
2249
2262
|
ctx.restore();
|
|
2250
2263
|
ctx.save();
|
|
2251
2264
|
ctx.strokeStyle = hexToRgba(drawing.color, 0.5);
|
|
@@ -2260,7 +2273,7 @@ function createChart(element, options = {}) {
|
|
|
2260
2273
|
drawDrawingHandle(secondX, secondY, drawing.color);
|
|
2261
2274
|
const prevFont = ctx.font;
|
|
2262
2275
|
ctx.font = `500 11px ${mergedOptions.fontFamily}`;
|
|
2263
|
-
|
|
2276
|
+
levelLines.forEach((level, index) => {
|
|
2264
2277
|
const labelText = `${level.ratio} (${formatPrice(level.price)})`;
|
|
2265
2278
|
const textWidth = ctx.measureText(labelText).width;
|
|
2266
2279
|
const padding = 4;
|
|
@@ -2268,11 +2281,11 @@ function createChart(element, options = {}) {
|
|
|
2268
2281
|
const bgY = level.y - 9;
|
|
2269
2282
|
ctx.fillStyle = mergedOptions.backgroundColor;
|
|
2270
2283
|
fillRoundedRect(bgX, bgY, textWidth + padding * 2, 16, 3);
|
|
2271
|
-
ctx.fillStyle =
|
|
2284
|
+
ctx.fillStyle = levelColorAt(index);
|
|
2272
2285
|
ctx.textAlign = "left";
|
|
2273
2286
|
ctx.textBaseline = "middle";
|
|
2274
2287
|
ctx.fillText(labelText, bgX + padding, bgY + 8);
|
|
2275
|
-
}
|
|
2288
|
+
});
|
|
2276
2289
|
ctx.font = prevFont;
|
|
2277
2290
|
}
|
|
2278
2291
|
}
|
|
@@ -3596,6 +3609,7 @@ function createChart(element, options = {}) {
|
|
|
3596
3609
|
type: "fib-retracement",
|
|
3597
3610
|
points: [point, point],
|
|
3598
3611
|
color: defaults.color ?? "#2563eb",
|
|
3612
|
+
colors: defaults.colors ?? FIB_DEFAULT_PALETTE,
|
|
3599
3613
|
style: defaults.style ?? "solid",
|
|
3600
3614
|
width: defaults.width ?? 1
|
|
3601
3615
|
});
|
|
@@ -4524,5 +4538,6 @@ function createChart(element, options = {}) {
|
|
|
4524
4538
|
};
|
|
4525
4539
|
}
|
|
4526
4540
|
export {
|
|
4541
|
+
FIB_DEFAULT_PALETTE,
|
|
4527
4542
|
createChart
|
|
4528
4543
|
};
|
package/docs/API.md
CHANGED
|
@@ -424,6 +424,7 @@ Drawings are user-created chart tools, separate from indicators. They are intera
|
|
|
424
424
|
- `points: DrawingPoint[]`
|
|
425
425
|
- `visible?: boolean`
|
|
426
426
|
- `color?: string`
|
|
427
|
+
- `colors?: string[]` (per-level colors; used by `fib-retracement`. When non-empty, each level/band cycles through these instead of `color`. New fib drawings default to `FIB_DEFAULT_PALETTE`; set `colors: []` for a monochrome fib that follows `color`.)
|
|
427
428
|
- `style?: "solid" | "dotted" | "dashed"`
|
|
428
429
|
- `width?: number`
|
|
429
430
|
- `label?: string`
|