web: fix stutter on update and save default chart settings to url params

This commit is contained in:
nym21
2025-06-16 18:56:38 +02:00
parent 985e961876
commit 43a6081dd6
4 changed files with 25 additions and 27 deletions
@@ -176,20 +176,16 @@ function createChartElement({
}
);
let timeScaleSet = false;
signals.createEffect(index, (index) => {
timeScaleSet = false;
const minBarSpacing =
index === /** @satisfies {MonthIndex} */ (7)
? 1
: index === /** @satisfies {QuarterIndex} */ (19)
? 3
? 2
: index === /** @satisfies {YearIndex} */ (23)
? 12
? 6
: index === /** @satisfies {DecadeIndex} */ (1)
? 120
? 60
: 0.5;
ichart.applyOptions({
@@ -408,8 +404,10 @@ function createChartElement({
let length = Math.min(indexes.length, values.length);
// TODO: Don't create new Array if data already present, update instead
/** @type {LineData[] | CandlestickData[]} */
const data = new Array(length);
let prevTime = null;
let timeOffset = 0;
@@ -458,11 +456,24 @@ function createChartElement({
const seriesData = series.inner.data();
if (!seriesData.length) {
console.log("set: vecid:", vecId);
iseries.setData(data);
if (fitContent) {
ichart.timeScale().fitContent();
}
timeScaleSetCallback?.(() => {
if (
index === /** @satisfies {QuarterIndex} */ (19) ||
index === /** @satisfies {YearIndex} */ (23) ||
index === /** @satisfies {DecadeIndex} */ (1)
) {
ichart.timeScale().setVisibleLogicalRange({
from: -1,
to: data.length,
});
}
});
} else if (data.length) {
let i = 0;
const first = seriesData[0];
@@ -517,21 +528,6 @@ function createChartElement({
index,
unit,
});
timeScaleSetCallback?.(() => {
if (
!timeScaleSet &&
(index === /** @satisfies {QuarterIndex} */ (19) ||
index === /** @satisfies {YearIndex} */ (23) ||
index === /** @satisfies {DecadeIndex} */ (1))
) {
ichart.timeScale().setVisibleLogicalRange({
from: -1,
to: data.length,
});
}
});
timeScaleSet = true;
}
);
} else {
@@ -69,7 +69,7 @@ const signals = {
/**
* @template T
* @param {T} initialValue
* @param {SignalOptions<T> & {save?: {keyPrefix: string | Accessor<string>; key: string; serialize: (v: T) => string; deserialize: (v: string) => T; serializeParam?: boolean}}} [options]
* @param {SignalOptions<T> & {save?: {keyPrefix: string | Accessor<string>; key: string; serialize: (v: T) => string; deserialize: (v: string) => T; serializeParam?: boolean; saveDefaultValue?: boolean}}} [options]
* @returns {Signal<T>}
*/
createSignal(initialValue, options) {
@@ -134,6 +134,7 @@ const signals = {
value !== null &&
(initialValue === undefined ||
initialValue === null ||
save.saveDefaultValue ||
save.serialize(value) !== save.serialize(initialValue))
) {
localStorage.setItem(storageKey(), save.serialize(value));
@@ -148,6 +149,7 @@ const signals = {
value !== null &&
(initialValue === undefined ||
initialValue === null ||
save.saveDefaultValue ||
save.serialize(value) !== save.serialize(initialValue))
) {
writeParam(paramKey, save.serialize(value));
+1 -2
View File
@@ -171,7 +171,6 @@ export function init({
latest.high = Math.floor(ONE_BTC_IN_SATS / latest.high);
latest.low = Math.floor(ONE_BTC_IN_SATS / latest.low);
latest.close = Math.floor(ONE_BTC_IN_SATS / latest.close);
latest.value = Math.floor(ONE_BTC_IN_SATS / latest.value);
}
const last_ = iseries.data().at(-1);
@@ -182,7 +181,7 @@ export function init({
last.close = latest.close;
}
if ("value" in last) {
last.value = latest.value;
last.value = latest.close;
}
const date = new Date(latest.time * 1000);
+2 -1
View File
@@ -388,6 +388,7 @@ function createUtils() {
...serde.string,
keyPrefix: keyPrefix ?? "",
key,
saveDefaultValue: true,
},
});
@@ -1163,7 +1164,7 @@ function createUtils() {
},
chartableIndex: {
/**
* @param {Index} v
* @param {number} v
*/
serialize(v) {
switch (v) {