Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 9388445

Browse files
committed
ChartEditor: define MAX_ROWS
1 parent 3f836fb commit 9388445

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

app/components/Settings/Preview/chart-editor.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ export default class ChartEditor extends React.Component {
1616
hidden: PropTypes.bool
1717
}
1818

19+
/**
20+
* Maximum number of rows to be displayed in a chart
21+
*
22+
* @type {number}
23+
*/
24+
static MAX_ROWS = 100000;
25+
1926
/**
2027
* ChartEditor displays a Plotly.js chart using the query results
2128
*
@@ -54,8 +61,8 @@ export default class ChartEditor extends React.Component {
5461
dataSources[name] = [];
5562
});
5663

57-
// Cap plots to 100k rows
58-
const length = Math.min(rows.length, 100000);
64+
// Cap number of rows displayed in a chart
65+
const length = Math.min(rows.length, ChartEditor.MAX_ROWS);
5966

6067
for (let i = 0; i < length; i++) {
6168
const row = rows[i];

test/app/components/Settings/Preview/chart-editor.test.jsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ jest.unmock('../../../../../app/components/Settings/Preview/chart-editor.jsx');
1111
const ChartEditor = require('../../../../../app/components/Settings/Preview/chart-editor.jsx');
1212

1313
describe('ChartEditor', () => {
14-
const MAX_LENGTH = 100000;
1514
let chartEditor, columnNames, rows, plotlyJSON, onUpdate, hidden;
1615

1716
beforeAll(() => {
@@ -20,7 +19,7 @@ describe('ChartEditor', () => {
2019
columnNames = ['x', 'y'];
2120

2221
rows = [];
23-
for (let i = 0; i < 100001; i++) {
22+
for (let i = 0; i < 1 + ChartEditor.MAX_ROWS; i++) {
2423
rows.push([i, 10 * i]);
2524
}
2625

@@ -58,19 +57,19 @@ describe('ChartEditor', () => {
5857
const dataSourceOption = dataSourceOptions[i];
5958
expect(dataSourceOption).toEqual({value: name, label: name});
6059

61-
// check length has been capped to 100000
60+
// check length has been capped
6261
const dataSource = dataSources[name];
63-
expect(dataSource.length).toEqual(MAX_LENGTH);
62+
expect(dataSource.length).toEqual(ChartEditor.MAX_ROWS);
6463
});
6564

6665
// check a few data
6766
expect(dataSources.x[0]).toBe(0);
6867
expect(dataSources.x[1]).toBe(1);
69-
expect(dataSources.x[MAX_LENGTH - 1]).toBe(MAX_LENGTH - 1);
68+
expect(dataSources.x[ChartEditor.MAX_ROWS - 1]).toBe(ChartEditor.MAX_ROWS - 1);
7069

7170
expect(dataSources.y[0]).toBe(0);
7271
expect(dataSources.y[1]).toBe(10);
73-
expect(dataSources.y[MAX_LENGTH - 1]).toBe(10 * (MAX_LENGTH - 1));
72+
expect(dataSources.y[ChartEditor.MAX_ROWS - 1]).toBe(10 * (ChartEditor.MAX_ROWS - 1));
7473
});
7574

7675
// requires node-canvas

0 commit comments

Comments
 (0)