@trdrs/quickcharts 5.7.1 → 5.8.0

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/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 5.8.0
6
+
7
+ `ChartHandle.setVisibleRange` pages in older history for a window that starts before the oldest loaded bar: it asks the datafeed with the same older-page `to` and `countBack` asks a scroll back makes, page after page until the bars reach the window's start, the feed states the end of its history or the chart holds 20,000 bars, and then frames the window. A window inside the loaded bars frames at once, as before. A page that fails frames the window over the bars already loaded, and a symbol or timeframe switch, any other navigation or a disposal while a page is away leaves the window unframed. The `chart.range.set` command with an explicit window does the same.
8
+
9
+ The indicator picker's kind filters stand at the head of the list's column, over its column headings: 28px chips 4px apart, 40px in from the column's start, in line with the names, 16px under the search field and 8px over the headings. The rail runs the full height beside them. The keyboard reaches the filters right after the field, and on a narrow screen they span the picker above the rail's row of chips.
10
+
11
+ `ChartExtensionContext.stateChanged()` says that the state an extension's `serialize()` answers has changed. It joins the one debounced save-needed signal every change on the chart raises: `saveNeeded` fires, the saved-layouts menu marks the open layout unsaved, and a layout the viewer autosaves is written, once for a burst of calls. A call made while the chart restores saved content, while the extension attaches or while the chart reads its state does nothing, and so does a call after detach.
12
+
5
13
  ## 5.7.1
6
14
 
7
15
  A press of the pointer on the price scale's corner button leaves the keyboard focus where it stands, so a key pressed afterwards draws no focus ring on the button. The keyboard reaches it and rings it as before.
package/README.md CHANGED
@@ -922,7 +922,8 @@ widget.dispose() // teardown; every handle and subscription is inert afterwards
922
922
  ```
923
923
 
924
924
  The widget paints the main series and volume, applies live updates by the bar rules above, pages
925
- older history in as the viewer scrolls left (stopping at the feed's `noData`), persists the viewer's
925
+ older history in as the viewer scrolls left and as a window set with `setVisibleRange` reaches back
926
+ past the loaded bars (stopping at the feed's `noData`), persists the viewer's
926
927
  preferences through `ChartStorage`, runs configured indicator instances through the manifest
927
928
  pipeline, and mounts the drawing layer, the legend and the context menu.
928
929
 
@@ -973,6 +974,7 @@ function drive(widget: ChartWidget): void {
973
974
  chart.zoom(0.8) // show fewer bars
974
975
  chart.reset() // fit the loaded data
975
976
  chart.goLive() // back to the live edge, same span
977
+ chart.setVisibleRange({ from: 1_735_689_600, to: 1_738_368_000 }) // January 2025, paged in if older
976
978
  chart.indicators.set([])
977
979
  void chart.visibleRange()
978
980
  void chart.rangePreset() // selected bottom-bar range, or null after other navigation
@@ -980,6 +982,16 @@ function drive(widget: ChartWidget): void {
980
982
  }
981
983
  ```
982
984
 
985
+ `setVisibleRange({ from, to })` frames a window in the feed's unix seconds. A window inside the
986
+ loaded bars frames at once. A window that starts before the oldest loaded bar first pages older
987
+ history in through your feed's `history`, with the same `to` and `countBack` asks a scroll back
988
+ makes, each sized to the bars still missing, page after page until the bars reach `from`, the feed
989
+ answers `noData` or the chart holds 20,000 bars. It then frames the window over the bars it holds;
990
+ the view stays where it stands while the pages are away. A page that rejects ends the paging and
991
+ frames the window over the bars already loaded. A symbol or timeframe switch, any other navigation
992
+ or `dispose()` while a page is away leaves the window unframed. The `chart.range.set` command with
993
+ an explicit `{ from, to }` window does the same.
994
+
983
995
  ### The live edge and the plot
984
996
 
985
997
  `goLive()` glides the view back to the live edge on an easing curve, moving it sideways only: the
@@ -1662,7 +1674,10 @@ chart's own Personal joins Favorites in its section. An absent count stays blank
1662
1674
  to omit that action on a contributed item.
1663
1675
 
1664
1676
  Declare `kinds` when your rows come in kinds beside indicators. The picker then shows a row of
1665
- filters under its field: All, the chart's own Indicators, and each of your kinds in order. An item
1677
+ filters at the head of the list's column, over its column headings and in line with the names: All,
1678
+ the chart's own Indicators, and each of your kinds in order. The keyboard reaches them right after
1679
+ the search field, before the rail. On a narrow screen they span the picker above the rail's row of
1680
+ chips. An item
1666
1681
  names its kind with `kind`; an item that names none, and every shipped definition, is an
1667
1682
  indicator. The kind id `indicator` is reserved, and an item of a kind you did not declare refuses
1668
1683
  the response.
@@ -3505,10 +3520,22 @@ const alertLines: ChartExtension = {
3505
3520
  id: 'add',
3506
3521
  label: `Add alert at ${menu.priceText}`,
3507
3522
  icon: { paths: [{ d: 'M14 6 L22 20 H6 Z' }] },
3508
- run: () => levels.push(menu.price),
3523
+ run: () => {
3524
+ levels.push(menu.price)
3525
+ ctx.stateChanged()
3526
+ },
3527
+ },
3528
+ ])
3529
+ ctx.contributeCommands([
3530
+ {
3531
+ id: 'acme.alerts.clear',
3532
+ label: 'Clear alerts',
3533
+ execute: () => {
3534
+ levels = []
3535
+ ctx.stateChanged()
3536
+ },
3509
3537
  },
3510
3538
  ])
3511
- ctx.contributeCommands([{ id: 'acme.alerts.clear', label: 'Clear alerts', execute: () => (levels = []) }])
3512
3539
  ctx.onSymbolChange(() => (levels = []))
3513
3540
  return {
3514
3541
  serialize: () => levels,
@@ -3637,6 +3664,13 @@ What to know:
3637
3664
  - **State is namespaced.** `serialize()` is stored under the extension's `id` inside the chart's
3638
3665
  content blob, and `restore(state)` receives only that slot, after the saved symbol, timeframe,
3639
3666
  scale and comparisons are on screen. One `id`, one attachment: a duplicate is refused.
3667
+ - **A change to your state is saved like a change to the chart.** Call `ctx.stateChanged()` when
3668
+ what `serialize()` answers changes. The call joins the one debounced signal every change on the
3669
+ chart raises: `saveNeeded` fires, the saved-layouts menu marks the open layout unsaved, and a
3670
+ layout the viewer autosaves is written, once for a burst of calls. Without it, your state reaches
3671
+ storage only when something else on the chart is saved. A call made while the chart restores
3672
+ saved content, while your extension attaches or while the chart reads its state does nothing, and
3673
+ so does a call after detach.
3640
3674
  - **Scope is a declaration.** By default an extension stays attached for the chart's life and hears
3641
3675
  symbol switches through `onSymbolChange`. Declare `scope: 'symbol'` and the chart detaches and
3642
3676
  re-attaches it on every switch, so a market-scoped overlay cannot carry one market's drawing onto
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.7.1",
2
+ "version": "5.8.0",
3
3
  "styles": [
4
4
  {
5
5
  "id": "candles",
package/dist/index.d.ts CHANGED
@@ -3686,12 +3686,19 @@ interface ChartExtensionContext {
3686
3686
  * taken, or paint over the image what the chart's canvases do not carry. The returned function
3687
3687
  * withdraws the contribution, and detach withdraws it either way. */
3688
3688
  contributeCapture(capture: ChartExtensionCapture): () => void;
3689
+ /** Say that the state the handle's `serialize()` answers has changed, so the open layout holds
3690
+ * changes it has not written: it reads as unsaved, and an autosave writes it. The call joins the
3691
+ * one debounced save-needed signal every change on the chart raises, so a burst of calls writes
3692
+ * once. A call made while the chart restores saved content, while the extension attaches or
3693
+ * while the chart reads its state does nothing, and so does a call after detach. */
3694
+ stateChanged(): void;
3689
3695
  }
3690
3696
  /** What an extension gives back at attach. `detach` is required; the two state methods are the
3691
3697
  * opt-in for anything the viewer would expect a saved chart to bring back. */
3692
3698
  interface ChartExtensionHandle {
3693
3699
  /** Viewer state to store in the chart's save blob, under this extension's id. Anything
3694
- * JSON-serializable. Return undefined to store nothing. */
3700
+ * JSON-serializable. Return undefined to store nothing. When what it answers changes, the
3701
+ * context's `stateChanged()` says so, and the layout writes it. */
3695
3702
  serialize?(): unknown;
3696
3703
  /** Apply state a previous `serialize()` produced. Never called with another extension's state. */
3697
3704
  restore?(state: unknown): void;
@@ -3777,7 +3784,8 @@ interface IndicatorPickerBuiltInState {
3777
3784
  interface IndicatorPickerSource {
3778
3785
  collections: readonly IndicatorPickerCollection[];
3779
3786
  /** The kinds the source's items come in beside indicators. With at least one, the picker shows a
3780
- * row of filters (All, Indicators, then these in order) under its search field. */
3787
+ * row of filters (All, Indicators, then these in order) at the head of its list's column, over
3788
+ * the column headings. */
3781
3789
  kinds?: readonly IndicatorPickerKind[];
3782
3790
  /** The host supplies localized text. A new query or collection aborts the previous read.
3783
3791
  * `builtInIds` are the built-ins the picker lists: every one, or those `builtInIndicators`
@@ -5159,6 +5167,14 @@ interface ChartHandle {
5159
5167
  visibleRange(): TimeRange | null;
5160
5168
  /** The range preset currently framing this chart, or null after other navigation. */
5161
5169
  rangePreset(): string | null;
5170
+ /** Frame a window of the feed's unix seconds. A window inside the bars the chart holds frames at
5171
+ * once. A window starting before the oldest bar held first pages older history in through the
5172
+ * datafeed, the same older-page ask a scroll back makes, page after page until the bars reach
5173
+ * `from`, the feed states the end of its history or the chart holds 20,000 bars, and then frames
5174
+ * the window over the bars held; the view stays where it stands while the pages are away. A page
5175
+ * that fails ends the paging and frames the window over the bars held. A symbol or timeframe
5176
+ * switch, any other navigation or the chart's disposal while a page is away leaves the window
5177
+ * unframed. */
5162
5178
  setVisibleRange(range: TimeRange): void;
5163
5179
  logicalRange(): LogicalRange | null;
5164
5180
  setLogicalRange(range: LogicalRange): void;
package/dist/index.js CHANGED
@@ -16824,6 +16824,15 @@ function sameJsonState(left, right) {
16824
16824
  function createExtensionHost(deps, extensions = []) {
16825
16825
  const attached = [];
16826
16826
  let hostLive = true;
16827
+ let quiet = 0;
16828
+ const quietly = (run) => {
16829
+ quiet++;
16830
+ try {
16831
+ return run();
16832
+ } finally {
16833
+ quiet--;
16834
+ }
16835
+ };
16827
16836
  const detachOne = (record3) => {
16828
16837
  if (!record3.live) return;
16829
16838
  record3.live = false;
@@ -17042,6 +17051,13 @@ function createExtensionHost(deps, extensions = []) {
17042
17051
  } catch {
17043
17052
  }
17044
17053
  },
17054
+ stateChanged() {
17055
+ if (!record3.live || !hostLive || quiet > 0) return;
17056
+ try {
17057
+ deps.stateChanged?.();
17058
+ } catch {
17059
+ }
17060
+ },
17045
17061
  contributeHideLayer(layer) {
17046
17062
  const taken = !record3.live || record3.hideLayers.has(layer.id) || attached.some((a) => a.live && a.hideLayers.has(layer.id)) || layer.id === "drawings" || layer.id === "indicators" || layer.id === "all";
17047
17063
  if (taken) return { hidden: () => false, setHidden: () => {
@@ -17065,7 +17081,7 @@ function createExtensionHost(deps, extensions = []) {
17065
17081
  }
17066
17082
  };
17067
17083
  try {
17068
- record3.handle = extension.attach(context);
17084
+ record3.handle = quietly(() => extension.attach(context));
17069
17085
  } catch {
17070
17086
  detachOne(record3);
17071
17087
  return;
@@ -17185,7 +17201,7 @@ function createExtensionHost(deps, extensions = []) {
17185
17201
  for (const record3 of liveRecords()) {
17186
17202
  if (!record3.handle.serialize) continue;
17187
17203
  try {
17188
- const state = record3.handle.serialize();
17204
+ const state = quietly(() => record3.handle.serialize());
17189
17205
  if (state !== void 0) out[record3.extension.id] = state;
17190
17206
  } catch {
17191
17207
  }
@@ -17195,21 +17211,23 @@ function createExtensionHost(deps, extensions = []) {
17195
17211
  restore(state) {
17196
17212
  if (!hostLive || !state || typeof state !== "object" || Array.isArray(state)) return false;
17197
17213
  const byId2 = state;
17198
- let complete = true;
17199
- for (const record3 of liveRecords()) {
17200
- const supplied = Object.hasOwn(byId2, record3.extension.id);
17201
- try {
17202
- const expected = supplied ? JSON.stringify(byId2[record3.extension.id]) : void 0;
17203
- if (record3.handle.restore && supplied) record3.handle.restore(byId2[record3.extension.id]);
17204
- const actual = record3.handle.serialize ? JSON.stringify(record3.handle.serialize()) : void 0;
17205
- if (actual !== void 0 || record3.handle.restore) {
17206
- if (!supplied || !record3.handle.restore || expected === void 0 || actual === void 0 || !sameJsonState(JSON.parse(expected), JSON.parse(actual))) complete = false;
17214
+ return quietly(() => {
17215
+ let complete = true;
17216
+ for (const record3 of liveRecords()) {
17217
+ const supplied = Object.hasOwn(byId2, record3.extension.id);
17218
+ try {
17219
+ const expected = supplied ? JSON.stringify(byId2[record3.extension.id]) : void 0;
17220
+ if (record3.handle.restore && supplied) record3.handle.restore(byId2[record3.extension.id]);
17221
+ const actual = record3.handle.serialize ? JSON.stringify(record3.handle.serialize()) : void 0;
17222
+ if (actual !== void 0 || record3.handle.restore) {
17223
+ if (!supplied || !record3.handle.restore || expected === void 0 || actual === void 0 || !sameJsonState(JSON.parse(expected), JSON.parse(actual))) complete = false;
17224
+ }
17225
+ } catch {
17226
+ complete = false;
17207
17227
  }
17208
- } catch {
17209
- complete = false;
17210
17228
  }
17211
- }
17212
- return complete;
17229
+ return complete;
17230
+ });
17213
17231
  },
17214
17232
  subscriberCount() {
17215
17233
  let total2 = 0;
@@ -17335,7 +17353,8 @@ function attachExtensionsPlane(deps) {
17335
17353
  setHide: deps.setHide,
17336
17354
  hideLayersChanged: deps.hideLayersChanged,
17337
17355
  ...deps.legendRowsChanged ? { legendRowsChanged: deps.legendRowsChanged } : {},
17338
- ...deps.refreshMarks ? { refreshMarks: deps.refreshMarks } : {}
17356
+ ...deps.refreshMarks ? { refreshMarks: deps.refreshMarks } : {},
17357
+ ...deps.stateChanged ? { stateChanged: deps.stateChanged } : {}
17339
17358
  },
17340
17359
  deps.extensions
17341
17360
  );
@@ -22281,6 +22300,7 @@ var PAGE_RUNWAY = 4;
22281
22300
  var REPLAY_DEPTH = 2e4;
22282
22301
  var REPLAY_PAGE_BARS = 2e3;
22283
22302
  var SPAN_PAGE_MAX_BARS = 4e3;
22303
+ var RANGE_DEPTH = 2e4;
22284
22304
  function barsForSpan(span, tf) {
22285
22305
  const secs = rangeSpanSeconds(span, Math.floor(Date.now() / 1e3));
22286
22306
  const parsed = parseTimeframe(tf);
@@ -23001,7 +23021,12 @@ function createChartInstance(deps) {
23001
23021
  hideLayersChanged: () => drawings2.syncHideLayers(),
23002
23022
  // A contributed legend row stands in the legend under the symbol's reading.
23003
23023
  legendRowsChanged: () => legend2.setSlotRows(extensionsHost?.legendRows().map((row2) => row2.element) ?? []),
23004
- refreshMarks: () => refreshMarks()
23024
+ refreshMarks: () => refreshMarks(),
23025
+ // Extension state rides the chart's content, so a change to it raises the same debounced
23026
+ // save-needed every other content change does, quiet under hydration like the rest.
23027
+ stateChanged: () => {
23028
+ if (!disposed) deps.contentChanged?.();
23029
+ }
23005
23030
  });
23006
23031
  extensionsHost = extensions.host;
23007
23032
  legend2.setSlotRows(extensions.host.legendRows().map((row2) => row2.element));
@@ -23547,6 +23572,48 @@ function createChartInstance(deps) {
23547
23572
  if (!disposed && myEpoch === epoch) place();
23548
23573
  });
23549
23574
  }
23575
+ function showRange(range2) {
23576
+ const parsed = parseTimeframe(tf);
23577
+ const before = () => {
23578
+ const oldest = bars[0];
23579
+ return !!oldest && range2.from < oldest.t && !noMoreHistory && bars.length < RANGE_DEPTH && (earliestBarSecs === null || oldest.t > earliestBarSecs);
23580
+ };
23581
+ if (disposed || replay2.active() || !(range2.to > range2.from) || !before()) {
23582
+ ranges.setVisibleRange(range2);
23583
+ return;
23584
+ }
23585
+ paging = true;
23586
+ const myEpoch = epoch;
23587
+ const myNavigation = navigationEpoch;
23588
+ const current = () => !disposed && myEpoch === epoch && myNavigation === navigationEpoch && !replay2.active();
23589
+ void (async () => {
23590
+ try {
23591
+ while (before()) {
23592
+ const oldest = bars[0].t;
23593
+ const count2 = parsed && parsed.unit !== "t" ? Math.min(SPAN_PAGE_MAX_BARS, Math.ceil((oldest - range2.from) / timeframeSeconds(parsed)) + PAGE_TRIGGER_BARS) : PAGE_BARS;
23594
+ const { olderBars, end } = await fetchOlder(oldest - 1, count2);
23595
+ if (disposed || myEpoch !== epoch) return;
23596
+ if (end) noMoreHistory = true;
23597
+ const first = bars[0]?.t;
23598
+ if (first === void 0 || replay2.active()) return;
23599
+ const merged2 = mergeBarSnapshot(bars, olderBars.filter((bar) => bar.t < first), true);
23600
+ if (merged2.length === bars.length) break;
23601
+ maintainTimeline(() => {
23602
+ bars = merged2;
23603
+ paintAll();
23604
+ });
23605
+ refreshMarks();
23606
+ if (!current()) return;
23607
+ }
23608
+ } catch {
23609
+ } finally {
23610
+ if (myEpoch === epoch) paging = false;
23611
+ }
23612
+ if (!current()) return;
23613
+ maintenanceRange = null;
23614
+ ranges.setVisibleRange(range2);
23615
+ })();
23616
+ }
23550
23617
  let walkingBack = false;
23551
23618
  async function replayFromFirst() {
23552
23619
  if (!symbol || walkingBack || disposed) return;
@@ -23989,7 +24056,7 @@ function createChartInstance(deps) {
23989
24056
  rangePreset: () => selectedRangePreset,
23990
24057
  setVisibleRange: (range2) => {
23991
24058
  beginNavigation();
23992
- ranges.setVisibleRange(range2);
24059
+ showRange(range2);
23993
24060
  },
23994
24061
  logicalRange: () => ranges.logicalRange(),
23995
24062
  setLogicalRange: (range2) => {
@@ -26117,7 +26184,7 @@ function openIndicatorPicker(deps) {
26117
26184
  input.focus();
26118
26185
  });
26119
26186
  clear.hidden = true;
26120
- const strip = h("div", { class: "qc-search-classes" });
26187
+ const strip = h("div", { class: "qc-search-classes qc-picker-kinds" });
26121
26188
  const nav = h("nav", { class: "qc-picker-nav", "aria-label": t("picker.collections") });
26122
26189
  const list = h("div", { class: "qc-picker-list", role: "table", "aria-label": t("picker.title") });
26123
26190
  const vacant = h("div", { class: "qc-picker-empty" });
@@ -26357,7 +26424,7 @@ function openIndicatorPicker(deps) {
26357
26424
  input.focus();
26358
26425
  } else if (roveFocus(list, event)) event.preventDefault();
26359
26426
  });
26360
- box2.append(searchField(deps.icons, input, clear), strip, h("div", { class: "qc-picker-body" }, nav, h("div", { class: "qc-picker-content" }, list, vacant, status2)));
26427
+ box2.append(searchField(deps.icons, input, clear), h("div", { class: "qc-picker-body" }, strip, nav, h("div", { class: "qc-picker-content" }, list, vacant, status2)));
26361
26428
  renderKinds();
26362
26429
  renderNavigation();
26363
26430
  redraw = render;