From 200cd1011e4b4e84f10eac22cca1287084293311 Mon Sep 17 00:00:00 2001 From: nym21 Date: Mon, 1 Jun 2026 12:04:44 +0200 Subject: [PATCH] heatmaps: part 15 --- crates/brk_query/src/impl/oracle.rs | 13 +++--------- website/scripts/_types.js | 2 +- website/scripts/options/types.js | 3 ++- website/src/heatmap/index.js | 32 +++++++++++++++++++++++++---- website/src/heatmap/oracle.js | 9 ++++++++ website/src/heatmap/types.js | 6 ++++++ 6 files changed, 49 insertions(+), 16 deletions(-) diff --git a/crates/brk_query/src/impl/oracle.rs b/crates/brk_query/src/impl/oracle.rs index 44ce1d5ed..a50a0244d 100644 --- a/crates/brk_query/src/impl/oracle.rs +++ b/crates/brk_query/src/impl/oracle.rs @@ -233,21 +233,14 @@ impl Query { let indexer = self.indexer(); let safe_height = safe.height.to_usize(); let total_outputs = safe.txout_index.to_usize(); + let first_txout_index = &indexer.vecs.outputs.first_txout_index; - let out_start = indexer - .vecs - .outputs - .first_txout_index + let out_start = first_txout_index .collect_one_at(range.start) .unwrap() .to_usize(); let out_end = if range.end < safe_height { - indexer - .vecs - .outputs - .first_txout_index - .collect_one_at(range.end) - .unwrap() + first_txout_index.collect_one_at(range.end).unwrap() } else { TxOutIndex::from(total_outputs) } diff --git a/website/scripts/_types.js b/website/scripts/_types.js index 01c3b159f..4ac176e55 100644 --- a/website/scripts/_types.js +++ b/website/scripts/_types.js @@ -12,7 +12,7 @@ * * @import { Color } from "./utils/colors.js" * - * @import { HeatmapAxis, HeatmapPointSource, HeatmapGridFactory, HeatmapColorFn, HeatmapTooltipFn } from "../src/heatmap/types.js" + * @import { HeatmapAxis, HeatmapDefaults, HeatmapPointSource, HeatmapGridFactory, HeatmapColorFn, HeatmapTooltipFn } from "../src/heatmap/types.js" * * @import { Option, PartialChartOption, ChartOption, AnyPartialOption, ProcessedOptionAddons, OptionsTree, AnySeriesBlueprint, SeriesType, AnyFetchedSeriesBlueprint, ExplorerOption, UrlOption, PartialOptionsGroup, OptionsGroup, PartialOptionsTree, UtxoCohortObject, AddrCohortObject, CohortObject, CohortGroupObject, FetchedLineSeriesBlueprint, FetchedBaselineSeriesBlueprint, FetchedHistogramSeriesBlueprint, FetchedDotsBaselineSeriesBlueprint, PatternAll, PatternFull, PatternWithAdjusted, PatternWithPercentiles, PatternBasic, PatternBasicWithMarketCap, PatternBasicWithoutMarketCap, PatternWithoutRelative, CohortAll, CohortFull, CohortWithAdjusted, CohortWithPercentiles, CohortBasic, CohortBasicWithMarketCap, CohortBasicWithoutMarketCap, CohortWithoutRelative, CohortAddr, CohortLongTerm, CohortAgeRange, CohortAgeRangeWithMatured, CohortGroupFull, CohortGroupWithAdjusted, CohortGroupWithPercentiles, CohortGroupLongTerm, CohortGroupAgeRange, CohortGroupBasic, CohortGroupBasicWithMarketCap, CohortGroupBasicWithoutMarketCap, CohortGroupWithoutRelative, CohortGroupAddr, UtxoCohortGroupObject, AddrCohortGroupObject, FetchedDotsSeriesBlueprint, HeatmapOption, FetchedCandlestickSeriesBlueprint, FetchedPriceSeriesBlueprint, AnyPricePattern, AnyValuePattern } from "./options/partial.js" * diff --git a/website/scripts/options/types.js b/website/scripts/options/types.js index 4f455b1d3..c7099ee47 100644 --- a/website/scripts/options/types.js +++ b/website/scripts/options/types.js @@ -111,11 +111,12 @@ * @property {HeatmapGridFactory} grid * @property {HeatmapColorFn} color * @property {HeatmapAxis} [axis] + * @property {HeatmapDefaults} [defaults] * @property {HeatmapTooltipFn} [tooltip] * * @typedef {PartialOption & PartialHeatmapOptionSpecific} PartialHeatmapOption * - * @typedef {Required> & Pick & ProcessedOptionAddons} HeatmapOption + * @typedef {PartialHeatmapOption & ProcessedOptionAddons} HeatmapOption * * @typedef {Object} PartialUrlOptionSpecific * @property {"link"} [kind] diff --git a/website/src/heatmap/index.js b/website/src/heatmap/index.js index 64db186e1..440d46264 100644 --- a/website/src/heatmap/index.js +++ b/website/src/heatmap/index.js @@ -347,8 +347,20 @@ function updateDateControls(option) { const currentYear = new Date().getUTCFullYear(); const fromChoices = createFromChoices(currentYear); const toChoices = createToChoices(currentYear); - const defaultFromChoice = fromChoices.at(-1) ?? fromChoices[0]; - const defaultToChoice = toChoices[0]; + const fallbackFromChoice = fromChoices.at(-1) ?? fromChoices[0]; + const fallbackToChoice = toChoices[0]; + const defaultFromChoice = findChoiceByKey( + fromChoices, + option.defaults?.from ?? "", + fallbackFromChoice, + rangeChoiceLabel, + ); + const defaultToChoice = findChoiceByKey( + toChoices, + option.defaults?.to ?? "", + fallbackToChoice, + rangeChoiceLabel, + ); const persistedFrom = createHeatmapPersistedValue( option, @@ -437,8 +449,20 @@ function updateYControls(option) { return; } - const defaultMinChoice = choices[0]; - const defaultMaxChoice = choices.at(-1) ?? choices[0]; + const fallbackMinChoice = choices[0]; + const fallbackMaxChoice = choices.at(-1) ?? choices[0]; + const defaultMinChoice = findChoiceByKey( + choices, + String(option.defaults?.yMin ?? ""), + fallbackMinChoice, + axisChoiceKey, + ); + const defaultMaxChoice = findChoiceByKey( + choices, + String(option.defaults?.yMax ?? ""), + fallbackMaxChoice, + axisChoiceKey, + ); const persistedMin = createHeatmapPersistedValue( option, "y-min", diff --git a/website/src/heatmap/oracle.js b/website/src/heatmap/oracle.js index 7cc63be6d..1f7006bbb 100644 --- a/website/src/heatmap/oracle.js +++ b/website/src/heatmap/oracle.js @@ -63,6 +63,15 @@ function createOracleHeatmapOption(mode, name) { format: formatAmount, }, }, + defaults: + mode === "payments" + ? { + from: "2015", + to: "today", + yMin: -5, + yMax: 2, + } + : undefined, tooltip: defaultTooltip, }; } diff --git a/website/src/heatmap/types.js b/website/src/heatmap/types.js index 8ebe1718b..2d36a5bd6 100644 --- a/website/src/heatmap/types.js +++ b/website/src/heatmap/types.js @@ -19,6 +19,12 @@ * @property {number} start * @property {number} end * + * @typedef {Object} HeatmapDefaults + * @property {string} [from] + * @property {string} [to] + * @property {number} [yMin] + * @property {number} [yMax] + * * @typedef {Object} HeatmapGridAddResult * @property {number} col * @property {boolean} maxChanged