hyperprop-charting-library 0.1.7 → 0.1.8
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.cjs +43 -2
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +43 -2
- package/docs/API.md +9 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -42,7 +42,12 @@ var DEFAULT_CROSSHAIR_OPTIONS = {
|
|
|
42
42
|
width: 1,
|
|
43
43
|
style: "dotted",
|
|
44
44
|
showHorizontal: true,
|
|
45
|
-
showVertical: true
|
|
45
|
+
showVertical: true,
|
|
46
|
+
showPriceLabel: true,
|
|
47
|
+
showTimeLabel: true,
|
|
48
|
+
labelBackgroundColor: "#0b1220",
|
|
49
|
+
labelTextColor: "#cbd5e1",
|
|
50
|
+
labelBorderRadius: 3
|
|
46
51
|
};
|
|
47
52
|
var DEFAULT_WATERMARK_OPTIONS = {
|
|
48
53
|
visible: false,
|
|
@@ -1009,6 +1014,42 @@ function createChart(element, options = {}) {
|
|
|
1009
1014
|
});
|
|
1010
1015
|
drawText(timeLabel, x, chartBottom + 8, "center", "top", axis.textColor);
|
|
1011
1016
|
}
|
|
1017
|
+
if (crosshair.visible && crosshairPoint) {
|
|
1018
|
+
const cx = clamp(crosshairPoint.x, chartLeft, chartRight);
|
|
1019
|
+
const cy = clamp(crosshairPoint.y, chartTop, chartBottom);
|
|
1020
|
+
const labelPaddingX = 8;
|
|
1021
|
+
const labelHeight = 20;
|
|
1022
|
+
const labelRadius = Math.max(0, crosshair.labelBorderRadius);
|
|
1023
|
+
const labelBackground = crosshair.labelBackgroundColor;
|
|
1024
|
+
const labelTextColor = crosshair.labelTextColor;
|
|
1025
|
+
if (crosshair.showPriceLabel) {
|
|
1026
|
+
const hoverPrice = yMin + (chartBottom - cy) / chartHeight * yRange;
|
|
1027
|
+
const priceText = formatPrice(hoverPrice);
|
|
1028
|
+
const priceWidth = Math.ceil(ctx.measureText(priceText).width) + labelPaddingX * 2;
|
|
1029
|
+
const priceX = chartRight + 4;
|
|
1030
|
+
const priceY = clamp(cy - labelHeight / 2, chartTop, chartBottom - labelHeight);
|
|
1031
|
+
ctx.fillStyle = labelBackground;
|
|
1032
|
+
fillRoundedRect(Math.round(priceX), Math.round(priceY), priceWidth, labelHeight, labelRadius);
|
|
1033
|
+
drawText(priceText, priceX + labelPaddingX, priceY + labelHeight / 2, "left", "middle", labelTextColor);
|
|
1034
|
+
}
|
|
1035
|
+
if (crosshair.showTimeLabel) {
|
|
1036
|
+
const ratio = clamp((cx - chartLeft) / chartWidth, 0, 1);
|
|
1037
|
+
const hoverIndex = Math.round(xStart + ratio * xSpan - 0.5);
|
|
1038
|
+
const hoverTime = getTimeForIndex(hoverIndex);
|
|
1039
|
+
if (hoverTime) {
|
|
1040
|
+
const timeText = hoverTime.toLocaleDateString(void 0, {
|
|
1041
|
+
month: "short",
|
|
1042
|
+
day: "numeric"
|
|
1043
|
+
});
|
|
1044
|
+
const timeWidth = Math.ceil(ctx.measureText(timeText).width) + labelPaddingX * 2;
|
|
1045
|
+
const timeX = clamp(cx - timeWidth / 2, chartLeft, chartRight - timeWidth);
|
|
1046
|
+
const timeY = chartBottom + 8;
|
|
1047
|
+
ctx.fillStyle = labelBackground;
|
|
1048
|
+
fillRoundedRect(Math.round(timeX), Math.round(timeY), timeWidth, labelHeight, labelRadius);
|
|
1049
|
+
drawText(timeText, timeX + labelPaddingX, timeY + labelHeight / 2, "left", "middle", labelTextColor);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1012
1053
|
};
|
|
1013
1054
|
const zoomX = (factor, anchorX) => {
|
|
1014
1055
|
if (!drawState || data.length === 0) {
|
|
@@ -1254,7 +1295,7 @@ function createChart(element, options = {}) {
|
|
|
1254
1295
|
}
|
|
1255
1296
|
const hoverRegion = getHitRegion(point.x, point.y);
|
|
1256
1297
|
if (hoverRegion === "plot") {
|
|
1257
|
-
canvas.style.cursor = "
|
|
1298
|
+
canvas.style.cursor = "default";
|
|
1258
1299
|
setCrosshairPoint(point);
|
|
1259
1300
|
} else if (hoverRegion === "x-axis") {
|
|
1260
1301
|
canvas.style.cursor = "ew-resize";
|
package/dist/index.d.cts
CHANGED
|
@@ -47,6 +47,11 @@ interface CrosshairOptions {
|
|
|
47
47
|
style?: "solid" | "dotted" | "dashed";
|
|
48
48
|
showHorizontal?: boolean;
|
|
49
49
|
showVertical?: boolean;
|
|
50
|
+
showPriceLabel?: boolean;
|
|
51
|
+
showTimeLabel?: boolean;
|
|
52
|
+
labelBackgroundColor?: string;
|
|
53
|
+
labelTextColor?: string;
|
|
54
|
+
labelBorderRadius?: number;
|
|
50
55
|
}
|
|
51
56
|
interface WatermarkOptions {
|
|
52
57
|
visible?: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,11 @@ interface CrosshairOptions {
|
|
|
47
47
|
style?: "solid" | "dotted" | "dashed";
|
|
48
48
|
showHorizontal?: boolean;
|
|
49
49
|
showVertical?: boolean;
|
|
50
|
+
showPriceLabel?: boolean;
|
|
51
|
+
showTimeLabel?: boolean;
|
|
52
|
+
labelBackgroundColor?: string;
|
|
53
|
+
labelTextColor?: string;
|
|
54
|
+
labelBorderRadius?: number;
|
|
50
55
|
}
|
|
51
56
|
interface WatermarkOptions {
|
|
52
57
|
visible?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,12 @@ var DEFAULT_CROSSHAIR_OPTIONS = {
|
|
|
18
18
|
width: 1,
|
|
19
19
|
style: "dotted",
|
|
20
20
|
showHorizontal: true,
|
|
21
|
-
showVertical: true
|
|
21
|
+
showVertical: true,
|
|
22
|
+
showPriceLabel: true,
|
|
23
|
+
showTimeLabel: true,
|
|
24
|
+
labelBackgroundColor: "#0b1220",
|
|
25
|
+
labelTextColor: "#cbd5e1",
|
|
26
|
+
labelBorderRadius: 3
|
|
22
27
|
};
|
|
23
28
|
var DEFAULT_WATERMARK_OPTIONS = {
|
|
24
29
|
visible: false,
|
|
@@ -985,6 +990,42 @@ function createChart(element, options = {}) {
|
|
|
985
990
|
});
|
|
986
991
|
drawText(timeLabel, x, chartBottom + 8, "center", "top", axis.textColor);
|
|
987
992
|
}
|
|
993
|
+
if (crosshair.visible && crosshairPoint) {
|
|
994
|
+
const cx = clamp(crosshairPoint.x, chartLeft, chartRight);
|
|
995
|
+
const cy = clamp(crosshairPoint.y, chartTop, chartBottom);
|
|
996
|
+
const labelPaddingX = 8;
|
|
997
|
+
const labelHeight = 20;
|
|
998
|
+
const labelRadius = Math.max(0, crosshair.labelBorderRadius);
|
|
999
|
+
const labelBackground = crosshair.labelBackgroundColor;
|
|
1000
|
+
const labelTextColor = crosshair.labelTextColor;
|
|
1001
|
+
if (crosshair.showPriceLabel) {
|
|
1002
|
+
const hoverPrice = yMin + (chartBottom - cy) / chartHeight * yRange;
|
|
1003
|
+
const priceText = formatPrice(hoverPrice);
|
|
1004
|
+
const priceWidth = Math.ceil(ctx.measureText(priceText).width) + labelPaddingX * 2;
|
|
1005
|
+
const priceX = chartRight + 4;
|
|
1006
|
+
const priceY = clamp(cy - labelHeight / 2, chartTop, chartBottom - labelHeight);
|
|
1007
|
+
ctx.fillStyle = labelBackground;
|
|
1008
|
+
fillRoundedRect(Math.round(priceX), Math.round(priceY), priceWidth, labelHeight, labelRadius);
|
|
1009
|
+
drawText(priceText, priceX + labelPaddingX, priceY + labelHeight / 2, "left", "middle", labelTextColor);
|
|
1010
|
+
}
|
|
1011
|
+
if (crosshair.showTimeLabel) {
|
|
1012
|
+
const ratio = clamp((cx - chartLeft) / chartWidth, 0, 1);
|
|
1013
|
+
const hoverIndex = Math.round(xStart + ratio * xSpan - 0.5);
|
|
1014
|
+
const hoverTime = getTimeForIndex(hoverIndex);
|
|
1015
|
+
if (hoverTime) {
|
|
1016
|
+
const timeText = hoverTime.toLocaleDateString(void 0, {
|
|
1017
|
+
month: "short",
|
|
1018
|
+
day: "numeric"
|
|
1019
|
+
});
|
|
1020
|
+
const timeWidth = Math.ceil(ctx.measureText(timeText).width) + labelPaddingX * 2;
|
|
1021
|
+
const timeX = clamp(cx - timeWidth / 2, chartLeft, chartRight - timeWidth);
|
|
1022
|
+
const timeY = chartBottom + 8;
|
|
1023
|
+
ctx.fillStyle = labelBackground;
|
|
1024
|
+
fillRoundedRect(Math.round(timeX), Math.round(timeY), timeWidth, labelHeight, labelRadius);
|
|
1025
|
+
drawText(timeText, timeX + labelPaddingX, timeY + labelHeight / 2, "left", "middle", labelTextColor);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
988
1029
|
};
|
|
989
1030
|
const zoomX = (factor, anchorX) => {
|
|
990
1031
|
if (!drawState || data.length === 0) {
|
|
@@ -1230,7 +1271,7 @@ function createChart(element, options = {}) {
|
|
|
1230
1271
|
}
|
|
1231
1272
|
const hoverRegion = getHitRegion(point.x, point.y);
|
|
1232
1273
|
if (hoverRegion === "plot") {
|
|
1233
|
-
canvas.style.cursor = "
|
|
1274
|
+
canvas.style.cursor = "default";
|
|
1234
1275
|
setCrosshairPoint(point);
|
|
1235
1276
|
} else if (hoverRegion === "x-axis") {
|
|
1236
1277
|
canvas.style.cursor = "ew-resize";
|
package/docs/API.md
CHANGED
|
@@ -78,6 +78,11 @@ Top-level options:
|
|
|
78
78
|
- `style` (`"solid" | "dotted" | "dashed"`, default `"dotted"`)
|
|
79
79
|
- `showHorizontal` (default `true`)
|
|
80
80
|
- `showVertical` (default `true`)
|
|
81
|
+
- `showPriceLabel` (default `true`)
|
|
82
|
+
- `showTimeLabel` (default `true`)
|
|
83
|
+
- `labelBackgroundColor` (default `#0b1220`)
|
|
84
|
+
- `labelTextColor` (default `#cbd5e1`)
|
|
85
|
+
- `labelBorderRadius` (default `3`)
|
|
81
86
|
|
|
82
87
|
### `WatermarkOptions`
|
|
83
88
|
|
|
@@ -98,12 +103,12 @@ Top-level options:
|
|
|
98
103
|
### `TickerLineOptions`
|
|
99
104
|
|
|
100
105
|
- `visible` (default `true`)
|
|
101
|
-
- `style` (`"solid" | "dotted" | "dashed"`, default `"
|
|
106
|
+
- `style` (`"solid" | "dotted" | "dashed"`, default `"dotted"`)
|
|
102
107
|
- `thickness` (default `1`)
|
|
103
|
-
- `color` (default `#
|
|
104
|
-
- `labelBackgroundColor` (default `#
|
|
108
|
+
- `color` (default `#38bdf8`)
|
|
109
|
+
- `labelBackgroundColor` (default `#38bdf8`)
|
|
105
110
|
- `labelTextColor` (default `#0b1220`)
|
|
106
|
-
- `labelBorderRadius` (default `
|
|
111
|
+
- `labelBorderRadius` (default `3`)
|
|
107
112
|
|
|
108
113
|
### `PriceLineOptions`
|
|
109
114
|
|