Open artjoma opened 6 years ago
I needed something like that so I used the following boolean flag:
let update = x.zoomable().domain()[1] >= feed.length - 10;
where the rationale is that when zoom contains the latest 10 bars, then it is safe to redraw the chart because it will not reset user zooming.
Yet, it's just a workaround. I guess there is a better solution.
I'm not sure how similar your example is to mine, but I was able to add data to my zoomable series without resetting the chart to default.
This is my zoomed
function. Some of the stuff is defined above, but note how I'm storing rescaledY
and rescaledX
to a variable.
var rescaledY;
var rescaledX;
function zoomed() {
rescaledY = d3.event.transform.rescaleY(y);
rescaledX = d3.event.transform.rescaleX(zoomableInit);
yAxis.scale(rescaledY);
candlestick.yScale(rescaledY);
// Emulates D3 behaviour, required for financetime due to secondary zoomable scale
x.zoomable().domain(rescaledX.domain());
draw();
}
Now in the redraw function (called when new data is added to my series), if either rescaledY
or rescaledX
are defined, I rescale.
function redraw(d) {
var accessor = candlestick.accessor();
x.domain(d.map(accessor.d));
y.domain(techan.scale.plot.ohlc(d, accessor).domain());
zoomableInit = x.zoomable().clamp(true).copy();
if (rescaledY || rescaledX) {
yAxis.scale(rescaledY);
candlestick.yScale(rescaledY);
x.zoomable().domain(rescaledX.domain());
}
svg.select('g.x.axis').call(xAxis);
svg.select('g.y.axis').call(yAxis);
svg.select("g.candlestick").datum(d).call(candlestick);
}
Hope this helps.
Bump.
Hi ! I try to create a diagram with zooming and feed functionality. Every time after add new bar(OHLC) called redraw and zoom reset to default. How can I fix it ?
`