feat: add vertical drawing toolbar on market chart
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -82,6 +82,11 @@
|
||||
const chartHost = document.getElementById("market-chart");
|
||||
if (!chartHost) return;
|
||||
|
||||
const elDrawToolbar = document.getElementById("market-draw-toolbar");
|
||||
const elDrawCanvas = document.getElementById("market-draw-canvas");
|
||||
const elChartMain = chartHost.closest(".market-chart-main");
|
||||
let drawAttached = false;
|
||||
|
||||
const elExchange = document.getElementById("market-exchange");
|
||||
const elSymbol = document.getElementById("market-symbol");
|
||||
const elTf = document.getElementById("market-timeframe");
|
||||
@@ -233,10 +238,33 @@
|
||||
syncChartWrapLayout();
|
||||
}
|
||||
|
||||
function ensureDrawLayer() {
|
||||
if (drawAttached || !window.HubChartDraw || !chart || !candleSeries) return;
|
||||
window.HubChartDraw.attach({
|
||||
chart: chart,
|
||||
series: candleSeries,
|
||||
hostEl: chartHost,
|
||||
mainEl: elChartMain,
|
||||
canvasEl: elDrawCanvas,
|
||||
toolbarEl: elDrawToolbar,
|
||||
});
|
||||
window.HubChartDraw.setViewKey(currentChartViewKey());
|
||||
drawAttached = true;
|
||||
}
|
||||
|
||||
function syncDrawViewKey() {
|
||||
if (window.HubChartDraw && drawAttached) {
|
||||
window.HubChartDraw.setViewKey(currentChartViewKey());
|
||||
}
|
||||
}
|
||||
|
||||
function resizeChart() {
|
||||
if (!chart || !chartHost) return;
|
||||
chart.applyOptions({ width: chartHost.clientWidth, height: chartHost.clientHeight });
|
||||
updatePriceTag();
|
||||
if (window.HubChartDraw && drawAttached) {
|
||||
window.HubChartDraw.resize();
|
||||
}
|
||||
}
|
||||
|
||||
let resizeChartRaf = 0;
|
||||
@@ -1985,6 +2013,7 @@
|
||||
scheduleChartResize();
|
||||
});
|
||||
scheduleChartResize();
|
||||
ensureDrawLayer();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2338,6 +2367,7 @@
|
||||
}
|
||||
if (elUpdated) elUpdated.textContent = "数据 " + (meta.updated_at || "--");
|
||||
tickLiveClock();
|
||||
if (window.HubChartDraw && drawAttached) window.HubChartDraw.redraw();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2660,6 +2690,8 @@
|
||||
}
|
||||
applyCandlesToChart(alignCandlesToTick(data.candles), 0);
|
||||
lastViewKey = vKey;
|
||||
ensureDrawLayer();
|
||||
syncDrawViewKey();
|
||||
if (resetView) {
|
||||
applyDefaultVisibleRange();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user