plotly.js icon indicating copy to clipboard operation
plotly.js copied to clipboard

Plotly resizes incorrectly

Open t0mm13b opened this issue 10 years ago • 3 comments

This issue has come up with latest version of plotly.js v1.4.1

Below, is a plotly consisting of three data kinds, bar and two scatter

plotlybefore

After that, more data comes in, using scatter and markers, using the in-built symbol types, 'cross' and 'circle'.

var graph = document.getElementById('graph');
var graphData = graph.data;
// Code to process and iterate through the bar data to position the markers
var plotDataOne = { x: xValsOne, y: yValsOne, mode: 'markers', type: 'scatter', marker: { color: markersOne, size: 12, symbol: 'circle' } };
var plotDataTwo = { x: xValsTwo, y: yValsTwo, mode: 'markers', type: 'scatter', marker: { color: markersTwo, size: 12, symbol: 'circle' } };
graphData.push(plotDataOne);
graphData.push(plotDataTwo);
Plotly.redraw(graph).then(function(){
    console.log('Additional data added to plotly!');
});

plotlyafter

The bars got resized, was expecting the bars to remain as shown in the first image, with the markers placed in the appropriate spot.

Any advice would be appreciated.

t0mm13b avatar Jan 21 '16 21:01 t0mm13b

I believe this the intended behaviour (although I'll have to double check to be sure).

But in the meantime, here's an explanation and a workaround:

plotly.js -- by default -- expands the axis ranges for scatter traces with mode 'markers' by some fraction of the marker.size value. So the fact that the range of your x-axis increased is not surprising.

If you'll like to keep the original x-axis range, you can turn off the auto-range algorithm in your redraw call with:

graphData.layout.xaxis.autorange = false;

I hope this helps.

etpinard avatar Jan 21 '16 21:01 etpinard

Many thanks for the response. :+1:

Had to specify it twice, in the first plotting of the data pulled in from remote end-point, autorange: false in the layout and in the second pull of the data to plot in the markers for the second plot as indicated by your one-line code in previous comment.

Thanks again :)

Any plans to enable panning and zooming using two fingers on mobile devices which is something I have made attempts to do, it did turn out to be fiddly though using plotly modebar, for the record, using plotly.js and Ionic framework combined together to achieve a data-driven type of application.

t0mm13b avatar Jan 21 '16 23:01 t0mm13b

Any plans to enable panning and zooming using two fingers on mobile devices which is something I have made attempts to do,

Not in the short term I'm afraid. plotly.js is definitely not a mobile-first graphing library.

etpinard avatar Jan 22 '16 14:01 etpinard