global: snapshot

This commit is contained in:
nym21
2026-02-28 00:22:55 +01:00
parent 85c7933ad6
commit a2bd7ca299
38 changed files with 279 additions and 166 deletions

View File

@@ -1383,6 +1383,25 @@ export function createChart({ parent, brk, fitContent }) {
serieses.addCandlestick({ ...common, colors: blueprint.colors }),
);
break;
case "Price":
if (idx === "height" || idx.startsWith("minute")) {
pane.series.push(
serieses.addLine({
...common,
color: colors.default,
options: { ...common.options, priceLineVisible: true },
}),
);
} else {
pane.series.push(
serieses.addCandlestick({
...common,
metric: blueprint.ohlcMetric,
colors: blueprint.colors,
}),
);
}
break;
case "Dots":
pane.series.push(
serieses.addDots({

View File

@@ -370,7 +370,7 @@ export function createMarketSection() {
title: "Sats per Dollar",
bottom: [
line({
metric: prices.split.close.sats,
metric: prices.price.sats,
name: "Sats/$",
unit: Unit.sats,
}),

View File

@@ -42,7 +42,14 @@
* @property {BaselineSeriesPartialOptions} [options]
* @typedef {BaseSeriesBlueprint & DotsBaselineSeriesBlueprintSpecific} DotsBaselineSeriesBlueprint
*
* @typedef {BaselineSeriesBlueprint | CandlestickSeriesBlueprint | LineSeriesBlueprint | HistogramSeriesBlueprint | DotsSeriesBlueprint | DotsBaselineSeriesBlueprint} AnySeriesBlueprint
* @typedef {Object} PriceSeriesBlueprintSpecific
* @property {"Price"} type
* @property {AnyMetricPattern} ohlcMetric - OHLC metric for candlestick (>= 1h indexes)
* @property {[Color, Color]} [colors]
* @property {CandlestickSeriesPartialOptions} [options]
* @typedef {BaseSeriesBlueprint & PriceSeriesBlueprintSpecific} PriceSeriesBlueprint
*
* @typedef {BaselineSeriesBlueprint | CandlestickSeriesBlueprint | LineSeriesBlueprint | HistogramSeriesBlueprint | DotsSeriesBlueprint | DotsBaselineSeriesBlueprint | PriceSeriesBlueprint} AnySeriesBlueprint
*
* @typedef {AnySeriesBlueprint["type"]} SeriesType
*

View File

@@ -40,24 +40,28 @@ export function init() {
/** @type {Map<Unit, AnyFetchedSeriesBlueprint[]>} */
const result = new Map();
// USD price + option blueprints
/** @type {FetchedCandlestickSeriesBlueprint} */
const usdPrice = {
type: "Candlestick",
title: "Price",
metric: brk.metrics.prices.ohlc.usd,
};
result.set(Unit.usd, [usdPrice, ...(optionTop.get(Unit.usd) ?? [])]);
const { ohlc, price } = brk.metrics.prices;
// Sats price + option blueprints
/** @type {FetchedCandlestickSeriesBlueprint} */
const satsPrice = {
type: "Candlestick",
title: "Price",
metric: brk.metrics.prices.ohlc.sats,
colors: /** @type {const} */ ([colors.bi.p1[1], colors.bi.p1[0]]),
};
result.set(Unit.sats, [satsPrice, ...(optionTop.get(Unit.sats) ?? [])]);
result.set(Unit.usd, [
/** @type {AnyFetchedSeriesBlueprint} */ ({
type: "Price",
title: "Price",
metric: price.usd,
ohlcMetric: ohlc.usd,
}),
...(optionTop.get(Unit.usd) ?? []),
]);
result.set(Unit.sats, [
/** @type {AnyFetchedSeriesBlueprint} */ ({
type: "Price",
title: "Price",
metric: price.sats,
ohlcMetric: ohlc.sats,
colors: /** @type {const} */ ([colors.bi.p1[1], colors.bi.p1[0]]),
}),
...(optionTop.get(Unit.sats) ?? []),
]);
return result;
}
@@ -70,9 +74,7 @@ export function init() {
const unit = chart.panes[0].unit;
if (!priceSeries?.hasData() || !unit) return;
const last = /** @type {CandlestickData | undefined} */ (
priceSeries.getData().at(-1)
);
const last = priceSeries.getData().at(-1);
if (!last) return;
// Convert to sats if needed
@@ -81,7 +83,13 @@ export function init() {
? Math.floor(ONE_BTC_IN_SATS / latest)
: latest;
priceSeries.update({ ...last, close });
if ("close" in last) {
// Candlestick data
priceSeries.update({ ...last, close });
} else {
// Line data
priceSeries.update({ ...last, value: close });
}
}
// Set up the setOption function