hyperprop-charting-library 0.1.48 → 0.1.50

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/docs/RECIPES.md CHANGED
@@ -146,6 +146,34 @@ const rsiId = chart.addIndicator("rsi", { length: 14 }, { pane: "separate", pane
146
146
  const volumeId = chart.addIndicator("volume", { upOpacity: 0.72, downOpacity: 0.72 });
147
147
  ```
148
148
 
149
+ ## Move the main indicator legend away from a HUD
150
+
151
+ The main overlay indicator legend defaults to the chart pane's top-left corner. If your app renders a symbol/OHLC HUD over the canvas, move the legend with `labels.indicatorLegend*`.
152
+
153
+ ```ts
154
+ const chart = createChart(root, {
155
+ labels: {
156
+ showIndicatorNames: true,
157
+ showIndicatorValues: true,
158
+ indicatorLegendPosition: "top-left",
159
+ indicatorLegendOffsetX: 10,
160
+ indicatorLegendOffsetY: 34
161
+ }
162
+ });
163
+ ```
164
+
165
+ You can also place it in another corner:
166
+
167
+ ```ts
168
+ chart.updateOptions({
169
+ labels: {
170
+ indicatorLegendPosition: "top-right",
171
+ indicatorLegendOffsetX: 12,
172
+ indicatorLegendOffsetY: 10
173
+ }
174
+ });
175
+ ```
176
+
149
177
  ## Prevent one volume spike from crushing all bars
150
178
 
151
179
  ```ts
@@ -160,6 +188,78 @@ Available built-ins:
160
188
 
161
189
  - `volume`, `sma`, `ema`, `rsi`, `wma`, `vwma`, `rma`, `hma`, `stddev`, `atr`
162
190
 
191
+ ## Add a custom separate-pane indicator with scale labels
192
+
193
+ Separate-pane plugins can return pane metadata from `draw()` so the chart renders the right-side scale, top-left legend, and latest-value tag.
194
+
195
+ ```ts
196
+ import { type IndicatorPlugin } from "hyperprop-charting-library";
197
+
198
+ const momentumPlugin: IndicatorPlugin<{ length: number; color: string }> = {
199
+ id: "momentum",
200
+ name: "Momentum",
201
+ pane: "separate",
202
+ paneHeightRatio: 0.18,
203
+ defaultInputs: { length: 10, color: "#38bdf8" },
204
+ draw: (ctx, renderContext, inputs) => {
205
+ const values = renderContext.data.map((point, index, data) => {
206
+ const prior = data[index - inputs.length];
207
+ return prior ? point.c - prior.c : null;
208
+ });
209
+ const visibleValues = values
210
+ .slice(renderContext.startIndex, renderContext.endIndex + 1)
211
+ .filter((value): value is number => Number.isFinite(value ?? Number.NaN));
212
+ if (visibleValues.length === 0) return;
213
+
214
+ const maxAbs = Math.max(...visibleValues.map((value) => Math.abs(value)), 1);
215
+ const min = -maxAbs;
216
+ const max = maxAbs;
217
+ const yFromValue = (value: number) => {
218
+ const ratio = (value - min) / (max - min || 1);
219
+ return renderContext.chartBottom - ratio * renderContext.chartHeight;
220
+ };
221
+
222
+ ctx.save();
223
+ ctx.strokeStyle = inputs.color;
224
+ ctx.lineWidth = 2;
225
+ ctx.beginPath();
226
+ let drawing = false;
227
+ for (let index = renderContext.startIndex; index <= renderContext.endIndex; index += 1) {
228
+ const value = values[index];
229
+ if (!Number.isFinite(value ?? Number.NaN)) {
230
+ drawing = false;
231
+ continue;
232
+ }
233
+ const x = renderContext.xFromIndex(index);
234
+ const y = yFromValue(value as number);
235
+ if (!drawing) {
236
+ ctx.moveTo(x, y);
237
+ drawing = true;
238
+ } else {
239
+ ctx.lineTo(x, y);
240
+ }
241
+ }
242
+ ctx.stroke();
243
+ ctx.restore();
244
+
245
+ const latest = [...values].reverse().find((value): value is number => Number.isFinite(value ?? Number.NaN));
246
+ return {
247
+ title: `Momentum ${inputs.length}`,
248
+ axis: { min, max, ticks: [min, 0, max], decimals: 2 },
249
+ guideLines: [{ value: 0, label: "0", style: "dotted" }],
250
+ legendValues: latest === undefined ? [] : [{ value: latest, text: latest.toFixed(2), color: inputs.color }],
251
+ valueLabels:
252
+ latest === undefined
253
+ ? []
254
+ : [{ value: latest, text: latest.toFixed(2), backgroundColor: inputs.color, textColor: "#0f172a" }]
255
+ };
256
+ }
257
+ };
258
+
259
+ chart.registerIndicator(momentumPlugin);
260
+ chart.addIndicator("momentum", { length: 10 });
261
+ ```
262
+
163
263
  ## Resize indicator pane from frontend
164
264
 
165
265
  Use `paneHeightRatio` so your app can wire a drag handle or slider:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperprop-charting-library",
3
- "version": "0.1.48",
3
+ "version": "0.1.50",
4
4
  "description": "Lightweight TypeScript charting core",
5
5
  "type": "module",
6
6
  "main": "./dist/hyperprop-charting-library.cjs",