hyperprop-charting-library 0.1.61 → 0.1.62

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.
@@ -2023,16 +2023,17 @@ function createChart(element, options = {}) {
2023
2023
  return chartBottom - (price - yMin) / yRange * chartHeight;
2024
2024
  };
2025
2025
  const xFromDrawingPoint = (point) => chartLeft + (point.index + 0.5 - xStart) / xSpan * chartWidth;
2026
- const FIB_LEVELS = [
2027
- { ratio: 0, color: "#787b86" },
2028
- { ratio: 0.236, color: "#f23645", band: "rgba(242,54,69,0.10)" },
2029
- { ratio: 0.382, color: "#ff9800", band: "rgba(255,152,0,0.10)" },
2030
- { ratio: 0.5, color: "#4caf50", band: "rgba(76,175,80,0.10)" },
2031
- { ratio: 0.618, color: "#089981", band: "rgba(8,153,129,0.10)" },
2032
- { ratio: 0.786, color: "#00bcd4", band: "rgba(0,188,212,0.10)" },
2033
- { ratio: 1, color: "#787b86", band: "rgba(120,123,134,0.10)" },
2034
- { ratio: 1.618, color: "#2962ff", band: "rgba(41,98,255,0.08)" }
2035
- ];
2026
+ const FIB_RATIOS = [0, 0.236, 0.382, 0.5, 0.618, 0.786, 1, 1.618];
2027
+ const hexToRgba = (hex, alpha) => {
2028
+ const cleaned = hex.replace("#", "");
2029
+ if (cleaned.length !== 6) {
2030
+ return `rgba(0,0,0,${alpha})`;
2031
+ }
2032
+ const r = parseInt(cleaned.slice(0, 2), 16);
2033
+ const g = parseInt(cleaned.slice(2, 4), 16);
2034
+ const b = parseInt(cleaned.slice(4, 6), 16);
2035
+ return `rgba(${r},${g},${b},${alpha})`;
2036
+ };
2036
2037
  const drawDrawingHandle = (x, y, color) => {
2037
2038
  ctx.save();
2038
2039
  ctx.setLineDash([]);
@@ -2119,28 +2120,27 @@ function createChart(element, options = {}) {
2119
2120
  const secondY = yFromPrice(second.price);
2120
2121
  const lineLeft = chartLeft;
2121
2122
  const lineRight = chartRight;
2122
- const levelLines = FIB_LEVELS.map((level) => {
2123
- const price = first.price + (second.price - first.price) * (1 - level.ratio);
2124
- return { ...level, price, y: yFromPrice(price) };
2123
+ const levelLines = FIB_RATIOS.map((ratio) => {
2124
+ const price = first.price + (second.price - first.price) * (1 - ratio);
2125
+ return { ratio, price, y: yFromPrice(price) };
2125
2126
  });
2127
+ const bandColor = hexToRgba(drawing.color, 0.1);
2126
2128
  for (let index = 0; index < levelLines.length - 1; index += 1) {
2127
2129
  const top = levelLines[index];
2128
2130
  const bottom = levelLines[index + 1];
2129
- const fillColor = bottom.band ?? top.band;
2130
- if (!fillColor) continue;
2131
2131
  const bandTop = Math.min(top.y, bottom.y);
2132
2132
  const bandBottom = Math.max(top.y, bottom.y);
2133
2133
  ctx.save();
2134
- ctx.fillStyle = fillColor;
2134
+ ctx.fillStyle = bandColor;
2135
2135
  ctx.globalAlpha = draft ? 0.5 : 1;
2136
2136
  ctx.fillRect(lineLeft, bandTop, lineRight - lineLeft, bandBottom - bandTop);
2137
2137
  ctx.restore();
2138
2138
  }
2139
2139
  ctx.save();
2140
2140
  ctx.lineWidth = drawing.width;
2141
+ ctx.strokeStyle = drawing.color;
2141
2142
  applyDashPattern(drawing.style, dashPatterns.dotted, dashPatterns.dashed);
2142
2143
  for (const level of levelLines) {
2143
- ctx.strokeStyle = level.color;
2144
2144
  ctx.beginPath();
2145
2145
  ctx.moveTo(crisp(lineLeft), crisp(level.y));
2146
2146
  ctx.lineTo(crisp(lineRight), crisp(level.y));
@@ -2148,7 +2148,7 @@ function createChart(element, options = {}) {
2148
2148
  }
2149
2149
  ctx.restore();
2150
2150
  ctx.save();
2151
- ctx.strokeStyle = "rgba(148,163,184,0.7)";
2151
+ ctx.strokeStyle = hexToRgba(drawing.color, 0.5);
2152
2152
  ctx.setLineDash([4, 4]);
2153
2153
  ctx.lineWidth = 1;
2154
2154
  ctx.beginPath();
@@ -2168,7 +2168,7 @@ function createChart(element, options = {}) {
2168
2168
  const bgY = level.y - 9;
2169
2169
  ctx.fillStyle = mergedOptions.backgroundColor;
2170
2170
  fillRoundedRect(bgX, bgY, textWidth + padding * 2, 16, 3);
2171
- ctx.fillStyle = level.color;
2171
+ ctx.fillStyle = drawing.color;
2172
2172
  ctx.textAlign = "left";
2173
2173
  ctx.textBaseline = "middle";
2174
2174
  ctx.fillText(labelText, bgX + padding, bgY + 8);
@@ -1999,16 +1999,17 @@ function createChart(element, options = {}) {
1999
1999
  return chartBottom - (price - yMin) / yRange * chartHeight;
2000
2000
  };
2001
2001
  const xFromDrawingPoint = (point) => chartLeft + (point.index + 0.5 - xStart) / xSpan * chartWidth;
2002
- const FIB_LEVELS = [
2003
- { ratio: 0, color: "#787b86" },
2004
- { ratio: 0.236, color: "#f23645", band: "rgba(242,54,69,0.10)" },
2005
- { ratio: 0.382, color: "#ff9800", band: "rgba(255,152,0,0.10)" },
2006
- { ratio: 0.5, color: "#4caf50", band: "rgba(76,175,80,0.10)" },
2007
- { ratio: 0.618, color: "#089981", band: "rgba(8,153,129,0.10)" },
2008
- { ratio: 0.786, color: "#00bcd4", band: "rgba(0,188,212,0.10)" },
2009
- { ratio: 1, color: "#787b86", band: "rgba(120,123,134,0.10)" },
2010
- { ratio: 1.618, color: "#2962ff", band: "rgba(41,98,255,0.08)" }
2011
- ];
2002
+ const FIB_RATIOS = [0, 0.236, 0.382, 0.5, 0.618, 0.786, 1, 1.618];
2003
+ const hexToRgba = (hex, alpha) => {
2004
+ const cleaned = hex.replace("#", "");
2005
+ if (cleaned.length !== 6) {
2006
+ return `rgba(0,0,0,${alpha})`;
2007
+ }
2008
+ const r = parseInt(cleaned.slice(0, 2), 16);
2009
+ const g = parseInt(cleaned.slice(2, 4), 16);
2010
+ const b = parseInt(cleaned.slice(4, 6), 16);
2011
+ return `rgba(${r},${g},${b},${alpha})`;
2012
+ };
2012
2013
  const drawDrawingHandle = (x, y, color) => {
2013
2014
  ctx.save();
2014
2015
  ctx.setLineDash([]);
@@ -2095,28 +2096,27 @@ function createChart(element, options = {}) {
2095
2096
  const secondY = yFromPrice(second.price);
2096
2097
  const lineLeft = chartLeft;
2097
2098
  const lineRight = chartRight;
2098
- const levelLines = FIB_LEVELS.map((level) => {
2099
- const price = first.price + (second.price - first.price) * (1 - level.ratio);
2100
- return { ...level, price, y: yFromPrice(price) };
2099
+ const levelLines = FIB_RATIOS.map((ratio) => {
2100
+ const price = first.price + (second.price - first.price) * (1 - ratio);
2101
+ return { ratio, price, y: yFromPrice(price) };
2101
2102
  });
2103
+ const bandColor = hexToRgba(drawing.color, 0.1);
2102
2104
  for (let index = 0; index < levelLines.length - 1; index += 1) {
2103
2105
  const top = levelLines[index];
2104
2106
  const bottom = levelLines[index + 1];
2105
- const fillColor = bottom.band ?? top.band;
2106
- if (!fillColor) continue;
2107
2107
  const bandTop = Math.min(top.y, bottom.y);
2108
2108
  const bandBottom = Math.max(top.y, bottom.y);
2109
2109
  ctx.save();
2110
- ctx.fillStyle = fillColor;
2110
+ ctx.fillStyle = bandColor;
2111
2111
  ctx.globalAlpha = draft ? 0.5 : 1;
2112
2112
  ctx.fillRect(lineLeft, bandTop, lineRight - lineLeft, bandBottom - bandTop);
2113
2113
  ctx.restore();
2114
2114
  }
2115
2115
  ctx.save();
2116
2116
  ctx.lineWidth = drawing.width;
2117
+ ctx.strokeStyle = drawing.color;
2117
2118
  applyDashPattern(drawing.style, dashPatterns.dotted, dashPatterns.dashed);
2118
2119
  for (const level of levelLines) {
2119
- ctx.strokeStyle = level.color;
2120
2120
  ctx.beginPath();
2121
2121
  ctx.moveTo(crisp(lineLeft), crisp(level.y));
2122
2122
  ctx.lineTo(crisp(lineRight), crisp(level.y));
@@ -2124,7 +2124,7 @@ function createChart(element, options = {}) {
2124
2124
  }
2125
2125
  ctx.restore();
2126
2126
  ctx.save();
2127
- ctx.strokeStyle = "rgba(148,163,184,0.7)";
2127
+ ctx.strokeStyle = hexToRgba(drawing.color, 0.5);
2128
2128
  ctx.setLineDash([4, 4]);
2129
2129
  ctx.lineWidth = 1;
2130
2130
  ctx.beginPath();
@@ -2144,7 +2144,7 @@ function createChart(element, options = {}) {
2144
2144
  const bgY = level.y - 9;
2145
2145
  ctx.fillStyle = mergedOptions.backgroundColor;
2146
2146
  fillRoundedRect(bgX, bgY, textWidth + padding * 2, 16, 3);
2147
- ctx.fillStyle = level.color;
2147
+ ctx.fillStyle = drawing.color;
2148
2148
  ctx.textAlign = "left";
2149
2149
  ctx.textBaseline = "middle";
2150
2150
  ctx.fillText(labelText, bgX + padding, bgY + 8);
package/dist/index.cjs CHANGED
@@ -2023,16 +2023,17 @@ function createChart(element, options = {}) {
2023
2023
  return chartBottom - (price - yMin) / yRange * chartHeight;
2024
2024
  };
2025
2025
  const xFromDrawingPoint = (point) => chartLeft + (point.index + 0.5 - xStart) / xSpan * chartWidth;
2026
- const FIB_LEVELS = [
2027
- { ratio: 0, color: "#787b86" },
2028
- { ratio: 0.236, color: "#f23645", band: "rgba(242,54,69,0.10)" },
2029
- { ratio: 0.382, color: "#ff9800", band: "rgba(255,152,0,0.10)" },
2030
- { ratio: 0.5, color: "#4caf50", band: "rgba(76,175,80,0.10)" },
2031
- { ratio: 0.618, color: "#089981", band: "rgba(8,153,129,0.10)" },
2032
- { ratio: 0.786, color: "#00bcd4", band: "rgba(0,188,212,0.10)" },
2033
- { ratio: 1, color: "#787b86", band: "rgba(120,123,134,0.10)" },
2034
- { ratio: 1.618, color: "#2962ff", band: "rgba(41,98,255,0.08)" }
2035
- ];
2026
+ const FIB_RATIOS = [0, 0.236, 0.382, 0.5, 0.618, 0.786, 1, 1.618];
2027
+ const hexToRgba = (hex, alpha) => {
2028
+ const cleaned = hex.replace("#", "");
2029
+ if (cleaned.length !== 6) {
2030
+ return `rgba(0,0,0,${alpha})`;
2031
+ }
2032
+ const r = parseInt(cleaned.slice(0, 2), 16);
2033
+ const g = parseInt(cleaned.slice(2, 4), 16);
2034
+ const b = parseInt(cleaned.slice(4, 6), 16);
2035
+ return `rgba(${r},${g},${b},${alpha})`;
2036
+ };
2036
2037
  const drawDrawingHandle = (x, y, color) => {
2037
2038
  ctx.save();
2038
2039
  ctx.setLineDash([]);
@@ -2119,28 +2120,27 @@ function createChart(element, options = {}) {
2119
2120
  const secondY = yFromPrice(second.price);
2120
2121
  const lineLeft = chartLeft;
2121
2122
  const lineRight = chartRight;
2122
- const levelLines = FIB_LEVELS.map((level) => {
2123
- const price = first.price + (second.price - first.price) * (1 - level.ratio);
2124
- return { ...level, price, y: yFromPrice(price) };
2123
+ const levelLines = FIB_RATIOS.map((ratio) => {
2124
+ const price = first.price + (second.price - first.price) * (1 - ratio);
2125
+ return { ratio, price, y: yFromPrice(price) };
2125
2126
  });
2127
+ const bandColor = hexToRgba(drawing.color, 0.1);
2126
2128
  for (let index = 0; index < levelLines.length - 1; index += 1) {
2127
2129
  const top = levelLines[index];
2128
2130
  const bottom = levelLines[index + 1];
2129
- const fillColor = bottom.band ?? top.band;
2130
- if (!fillColor) continue;
2131
2131
  const bandTop = Math.min(top.y, bottom.y);
2132
2132
  const bandBottom = Math.max(top.y, bottom.y);
2133
2133
  ctx.save();
2134
- ctx.fillStyle = fillColor;
2134
+ ctx.fillStyle = bandColor;
2135
2135
  ctx.globalAlpha = draft ? 0.5 : 1;
2136
2136
  ctx.fillRect(lineLeft, bandTop, lineRight - lineLeft, bandBottom - bandTop);
2137
2137
  ctx.restore();
2138
2138
  }
2139
2139
  ctx.save();
2140
2140
  ctx.lineWidth = drawing.width;
2141
+ ctx.strokeStyle = drawing.color;
2141
2142
  applyDashPattern(drawing.style, dashPatterns.dotted, dashPatterns.dashed);
2142
2143
  for (const level of levelLines) {
2143
- ctx.strokeStyle = level.color;
2144
2144
  ctx.beginPath();
2145
2145
  ctx.moveTo(crisp(lineLeft), crisp(level.y));
2146
2146
  ctx.lineTo(crisp(lineRight), crisp(level.y));
@@ -2148,7 +2148,7 @@ function createChart(element, options = {}) {
2148
2148
  }
2149
2149
  ctx.restore();
2150
2150
  ctx.save();
2151
- ctx.strokeStyle = "rgba(148,163,184,0.7)";
2151
+ ctx.strokeStyle = hexToRgba(drawing.color, 0.5);
2152
2152
  ctx.setLineDash([4, 4]);
2153
2153
  ctx.lineWidth = 1;
2154
2154
  ctx.beginPath();
@@ -2168,7 +2168,7 @@ function createChart(element, options = {}) {
2168
2168
  const bgY = level.y - 9;
2169
2169
  ctx.fillStyle = mergedOptions.backgroundColor;
2170
2170
  fillRoundedRect(bgX, bgY, textWidth + padding * 2, 16, 3);
2171
- ctx.fillStyle = level.color;
2171
+ ctx.fillStyle = drawing.color;
2172
2172
  ctx.textAlign = "left";
2173
2173
  ctx.textBaseline = "middle";
2174
2174
  ctx.fillText(labelText, bgX + padding, bgY + 8);
package/dist/index.js CHANGED
@@ -1999,16 +1999,17 @@ function createChart(element, options = {}) {
1999
1999
  return chartBottom - (price - yMin) / yRange * chartHeight;
2000
2000
  };
2001
2001
  const xFromDrawingPoint = (point) => chartLeft + (point.index + 0.5 - xStart) / xSpan * chartWidth;
2002
- const FIB_LEVELS = [
2003
- { ratio: 0, color: "#787b86" },
2004
- { ratio: 0.236, color: "#f23645", band: "rgba(242,54,69,0.10)" },
2005
- { ratio: 0.382, color: "#ff9800", band: "rgba(255,152,0,0.10)" },
2006
- { ratio: 0.5, color: "#4caf50", band: "rgba(76,175,80,0.10)" },
2007
- { ratio: 0.618, color: "#089981", band: "rgba(8,153,129,0.10)" },
2008
- { ratio: 0.786, color: "#00bcd4", band: "rgba(0,188,212,0.10)" },
2009
- { ratio: 1, color: "#787b86", band: "rgba(120,123,134,0.10)" },
2010
- { ratio: 1.618, color: "#2962ff", band: "rgba(41,98,255,0.08)" }
2011
- ];
2002
+ const FIB_RATIOS = [0, 0.236, 0.382, 0.5, 0.618, 0.786, 1, 1.618];
2003
+ const hexToRgba = (hex, alpha) => {
2004
+ const cleaned = hex.replace("#", "");
2005
+ if (cleaned.length !== 6) {
2006
+ return `rgba(0,0,0,${alpha})`;
2007
+ }
2008
+ const r = parseInt(cleaned.slice(0, 2), 16);
2009
+ const g = parseInt(cleaned.slice(2, 4), 16);
2010
+ const b = parseInt(cleaned.slice(4, 6), 16);
2011
+ return `rgba(${r},${g},${b},${alpha})`;
2012
+ };
2012
2013
  const drawDrawingHandle = (x, y, color) => {
2013
2014
  ctx.save();
2014
2015
  ctx.setLineDash([]);
@@ -2095,28 +2096,27 @@ function createChart(element, options = {}) {
2095
2096
  const secondY = yFromPrice(second.price);
2096
2097
  const lineLeft = chartLeft;
2097
2098
  const lineRight = chartRight;
2098
- const levelLines = FIB_LEVELS.map((level) => {
2099
- const price = first.price + (second.price - first.price) * (1 - level.ratio);
2100
- return { ...level, price, y: yFromPrice(price) };
2099
+ const levelLines = FIB_RATIOS.map((ratio) => {
2100
+ const price = first.price + (second.price - first.price) * (1 - ratio);
2101
+ return { ratio, price, y: yFromPrice(price) };
2101
2102
  });
2103
+ const bandColor = hexToRgba(drawing.color, 0.1);
2102
2104
  for (let index = 0; index < levelLines.length - 1; index += 1) {
2103
2105
  const top = levelLines[index];
2104
2106
  const bottom = levelLines[index + 1];
2105
- const fillColor = bottom.band ?? top.band;
2106
- if (!fillColor) continue;
2107
2107
  const bandTop = Math.min(top.y, bottom.y);
2108
2108
  const bandBottom = Math.max(top.y, bottom.y);
2109
2109
  ctx.save();
2110
- ctx.fillStyle = fillColor;
2110
+ ctx.fillStyle = bandColor;
2111
2111
  ctx.globalAlpha = draft ? 0.5 : 1;
2112
2112
  ctx.fillRect(lineLeft, bandTop, lineRight - lineLeft, bandBottom - bandTop);
2113
2113
  ctx.restore();
2114
2114
  }
2115
2115
  ctx.save();
2116
2116
  ctx.lineWidth = drawing.width;
2117
+ ctx.strokeStyle = drawing.color;
2117
2118
  applyDashPattern(drawing.style, dashPatterns.dotted, dashPatterns.dashed);
2118
2119
  for (const level of levelLines) {
2119
- ctx.strokeStyle = level.color;
2120
2120
  ctx.beginPath();
2121
2121
  ctx.moveTo(crisp(lineLeft), crisp(level.y));
2122
2122
  ctx.lineTo(crisp(lineRight), crisp(level.y));
@@ -2124,7 +2124,7 @@ function createChart(element, options = {}) {
2124
2124
  }
2125
2125
  ctx.restore();
2126
2126
  ctx.save();
2127
- ctx.strokeStyle = "rgba(148,163,184,0.7)";
2127
+ ctx.strokeStyle = hexToRgba(drawing.color, 0.5);
2128
2128
  ctx.setLineDash([4, 4]);
2129
2129
  ctx.lineWidth = 1;
2130
2130
  ctx.beginPath();
@@ -2144,7 +2144,7 @@ function createChart(element, options = {}) {
2144
2144
  const bgY = level.y - 9;
2145
2145
  ctx.fillStyle = mergedOptions.backgroundColor;
2146
2146
  fillRoundedRect(bgX, bgY, textWidth + padding * 2, 16, 3);
2147
- ctx.fillStyle = level.color;
2147
+ ctx.fillStyle = drawing.color;
2148
2148
  ctx.textAlign = "left";
2149
2149
  ctx.textBaseline = "middle";
2150
2150
  ctx.fillText(labelText, bgX + padding, bgY + 8);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperprop-charting-library",
3
- "version": "0.1.61",
3
+ "version": "0.1.62",
4
4
  "description": "Lightweight TypeScript charting core",
5
5
  "type": "module",
6
6
  "main": "./dist/hyperprop-charting-library.cjs",