Skip to content

Commit

Permalink
Add bin count limit
Browse files Browse the repository at this point in the history
  • Loading branch information
deecay committed Oct 1, 2023
1 parent 252d9ba commit 7f9287a
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion viz-lib/src/visualizations/chart/plotly/prepareDefaultData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,31 @@ function prepareBoxSeries(series: any, options: any, { seriesColor }: any) {
}

function prepareHistogramSeries(series: any, options: any) {
function estimateBinCount(xValues: any) {
const start = xValues[0];
const end = xValues.slice(-1)[0];
if (!isNaN(start)) { // number axis
return (end - start) / options.binSize;
} else if (!isNaN(new Date(start).getTime())) { // date axis
return (Date.parse(end) - Date.parse(start)) / options.binSize;
} else { // category axis
return xValues.length / options.binSize;
}
}

series.type = 'histogram';
series.hoverinfo = 'x+y+name';

if (!isNil(options.binSize)) {
if (!isNil(options.binSize) && (options.binSize !== "")) {
// avoid hanging by limiting the number of bins
const binCount = estimateBinCount(series.x);
if (binCount > 10000) {
// throwing error results in visualization page to crash after leaving Editor
// so instead draw an empty plot
series.x = [];
series.y = [];
}

series.autobinx = false;
series.xbins = series.xbins || {};
series.xbins.size = options.binSize;
Expand Down

0 comments on commit 7f9287a

Please sign in to comment.