// @ts-check /** @import {IChartApi, ISeriesApi, SeriesDefinition, SingleValueData as _SingleValueData, CandlestickData as _CandlestickData, BaselineData, SeriesType, IPaneApi, BaselineStyleOptions, CandlestickStyleOptions, WhitespaceData} from './v5.0.7-treeshaked/types' */ /** * @typedef {[number, number, number, number]} OHLCTuple * * @typedef {Object} Valued * @property {number} value * * @typedef {Object} Indexed * @property {number} index */ /** * @typedef {Object} Series * @property {ISeriesApi} inner * @property {string} id * @property {Signal} active * @property {VoidFunction} remove */ /** * @template T * @typedef {T & Valued & Indexed} ChartData */ /** * @typedef {ChartData<_SingleValueData>} SingleValueData * @typedef {ChartData<_CandlestickData>} CandlestickData */ export default import("./v5.0.7-treeshaked/script.js").then((lc) => { const oklchToRGBA = createOklchToRGBA(); /** * @param {Object} args * @param {string} args.id * @param {HTMLElement} args.parent * @param {Signals} args.signals * @param {Colors} args.colors * @param {Utilities} args.utils * @param {Elements} args.elements * @param {VecsResources} args.vecsResources * @param {Accessor} args.index * @param {((unknownTimeScaleCallback: VoidFunction) => void)} [args.timeScaleSetCallback] * @param {Owner | null} args.owner * @param {true} [args.fitContentOnResize] * @param {{unit: Unit; blueprints: AnySeriesBlueprint[]}[]} [args.config] */ function createChartElement({ parent, signals, colors, utils, elements, id, index, vecsResources, timeScaleSetCallback, owner: _owner, fitContentOnResize, config, }) { const owner = _owner || signals.getOwner(); const div = window.document.createElement("div"); div.classList.add("chart"); parent.append(div); const legendTop = createLegend({ utils, signals, paneIndex: 0, }); div.append(legendTop.element); const chartDiv = window.document.createElement("div"); chartDiv.classList.add("lightweight-chart"); div.append(chartDiv); const legendBottom = createLegend({ utils, signals, paneIndex: 1, }); div.append(legendBottom.element); /** @type {IChartApi} */ const ichart = lc.createChart( chartDiv, /** @satisfies {DeepPartial} */ ({ autoSize: true, layout: { fontFamily: elements.style.fontFamily, background: { color: "transparent" }, attributionLogo: false, colorSpace: "display-p3", colorParsers: [oklchToRGBA], }, grid: { vertLines: { visible: false }, horzLines: { visible: false }, }, rightPriceScale: { borderVisible: false, }, timeScale: { borderVisible: false, }, localization: { priceFormatter: numberToShortUSFormat, locale: "en-us", }, crosshair: { mode: 3, }, ...(fitContentOnResize ? { handleScroll: false, handleScale: false, timeScale: { minBarSpacing: 0.001, }, } : {}), // ..._options, }), ); ichart.priceScale("right").applyOptions({ minimumWidth: 80, }); signals.createEffect( () => ({ defaultColor: colors.default(), offColor: colors.gray(), borderColor: colors.border(), }), ({ defaultColor, offColor, borderColor }) => { ichart.applyOptions({ layout: { textColor: offColor, panes: { separatorColor: borderColor, }, }, crosshair: { horzLine: { color: offColor, labelBackgroundColor: defaultColor, }, vertLine: { color: offColor, labelBackgroundColor: defaultColor, }, }, }); }, ); signals.createEffect(index, (index) => { ichart.applyOptions({ timeScale: { timeVisible: index === /** @satisfies {Height} */ (5) || index === /** @satisfies {DifficultyEpoch} */ (2) || index === /** @satisfies {HalvingEpoch} */ (4), }, }); if (!fitContentOnResize) { ichart.applyOptions({ timeScale: { minBarSpacing: index === /** @satisfies {MonthIndex} */ (7) ? 1 : index === /** @satisfies {QuarterIndex} */ (19) ? 3 : index === /** @satisfies {YearIndex} */ (23) ? 12 : index === /** @satisfies {DecadeIndex} */ (1) ? 120 : undefined, }, }); } }); const activeResources = /** @type {Set} */ (new Set()); ichart.subscribeCrosshairMove( utils.debounce(() => { activeResources.forEach((v) => { v.fetch(); }); }), ); const timeResource = signals.createMemo(() => { const i = index(); const timeResource = vecsResources.getOrCreate( i, i === /** @satisfies {Height} */ (5) ? "timestamp-fixed" : "timestamp", ); timeResource.fetch(); return timeResource; }); let timeScaleSet = false; if (fitContentOnResize) { new ResizeObserver(() => ichart.timeScale().fitContent()).observe( chartDiv, ); } /** * @param {Object} args * @param {string} args.id * @param {number} args.paneIndex * @param {"nw" | "ne" | "se" | "sw"} args.position * @param {number} [args.timeout] * @param {(args: {owner: Owner | null, pane: IPaneApi