From 593fb4f593afbf5fb9bbd1ca0f75780d01fb78e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Tue, 26 Jun 2018 17:03:50 -0400 Subject: [PATCH 1/2] add 'table' safeMode specs --- src/component/plotly-graph/parse.js | 8 +++++++- test/unit/plotly-graph_test.js | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/component/plotly-graph/parse.js b/src/component/plotly-graph/parse.js index a91f1eca..5982fc05 100644 --- a/src/component/plotly-graph/parse.js +++ b/src/component/plotly-graph/parse.js @@ -148,7 +148,12 @@ function findMaxArrayLength (cont) { } }) - return Math.max(0, ...lengths) + let l = Math.max(0, ...lengths) + + if (cont.type === 'table' && isPlainObj(cont.cells)) { + l = Math.max(l, findMaxArrayLength(cont.cells)) + } + return l } function estimateDataLength (trace) { @@ -169,6 +174,7 @@ function maxPtsPerTrace (trace) { case 'scattergl': case 'splom': case 'pointcloud': + case 'table': return 1e7 case 'scatterpolargl': diff --git a/test/unit/plotly-graph_test.js b/test/unit/plotly-graph_test.js index 16c66712..777515fa 100644 --- a/test/unit/plotly-graph_test.js +++ b/test/unit/plotly-graph_test.js @@ -395,6 +395,25 @@ tap.test('parse:', t => { }) }) + t.test('failing table case', t => { + fn({ + data: [{ + type: 'table', + cells: { + values: [ + new Array(5e6), + new Array(5e6), + new Array(5e6) + ] + } + }] + }, {safeMode: true}, (errorCode, result) => { + t.equal(errorCode, 400, 'code') + t.type(result.msg, 'string', 'msg type') + t.end() + }) + }) + t.test('failing case from too many traces', t => { var data = new Array(3e3) From 2b5cf94ab214c52f988303878d46fe894e0bc80b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 13 Aug 2018 12:43:49 -0400 Subject: [PATCH 2/2] simplify estimateDataLength logic - look up the trace's "top" level and "dimensions" and "cells" regardless of trace type --- src/component/plotly-graph/parse.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/component/plotly-graph/parse.js b/src/component/plotly-graph/parse.js index 5982fc05..3155df5d 100644 --- a/src/component/plotly-graph/parse.js +++ b/src/component/plotly-graph/parse.js @@ -148,23 +148,27 @@ function findMaxArrayLength (cont) { } }) - let l = Math.max(0, ...lengths) - - if (cont.type === 'table' && isPlainObj(cont.cells)) { - l = Math.max(l, findMaxArrayLength(cont.cells)) - } - return l + return Math.max(0, ...lengths) } function estimateDataLength (trace) { + const topLevel = findMaxArrayLength(trace) + let dimLevel = 0 + let cellLevel = 0 + // special case for e.g. parcoords and splom traces if (Array.isArray(trace.dimensions)) { - return trace.dimensions + dimLevel = trace.dimensions .map(findMaxArrayLength) .reduce((a, v) => a + v) } - return findMaxArrayLength(trace) + // special case for e.g. table traces + if (isPlainObj(trace.cells)) { + cellLevel = findMaxArrayLength(trace.cells) + } + + return Math.max(topLevel, dimLevel, cellLevel) } function maxPtsPerTrace (trace) {