Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a9ef87

Browse files
committed
mv maxRowLength to lib/array.js, use it it in xy defaults
1 parent c680558 commit 2a9ef87

File tree

8 files changed

+19
-35
lines changed

8 files changed

+19
-35
lines changed

src/lib/array.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,13 @@ exports.concat = function() {
132132
}
133133
return out;
134134
};
135+
136+
exports.maxRowLength = function(z) {
137+
var len = 0;
138+
139+
for(var i = 0; i < z.length; i++) {
140+
len = Math.max(len, z[i].length);
141+
}
142+
143+
return len;
144+
};

src/lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ lib.isArrayOrTypedArray = arrayModule.isArrayOrTypedArray;
3131
lib.isArray1D = arrayModule.isArray1D;
3232
lib.ensureArray = arrayModule.ensureArray;
3333
lib.concat = arrayModule.concat;
34+
lib.maxRowLength = arrayModule.maxRowLength;
3435

3536
var modModule = require('./mod');
3637
lib.mod = modModule.mod;

src/traces/contourcarpet/calc.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
'use strict';
1010

1111
var colorscaleCalc = require('../../components/colorscale/calc');
12-
var isArray1D = require('../../lib').isArray1D;
12+
var Lib = require('../../lib');
1313

1414
var convertColumnData = require('../heatmap/convert_column_xyz');
1515
var clean2dArray = require('../heatmap/clean_2d_array');
16-
var maxRowLength = require('../heatmap/max_row_length');
1716
var interp2d = require('../heatmap/interp2d');
1817
var findEmpties = require('../heatmap/find_empties');
1918
var makeBoundArray = require('../heatmap/make_bound_array');
@@ -70,7 +69,7 @@ function heatmappishCalc(gd, trace) {
7069
aax._minDtick = 0;
7170
bax._minDtick = 0;
7271

73-
if(isArray1D(trace.z)) convertColumnData(trace, aax, bax, 'a', 'b', ['z']);
72+
if(Lib.isArray1D(trace.z)) convertColumnData(trace, aax, bax, 'a', 'b', ['z']);
7473
a = trace._a = trace._a || trace.a;
7574
b = trace._b = trace._b || trace.b;
7675

@@ -87,7 +86,7 @@ function heatmappishCalc(gd, trace) {
8786
interp2d(z, trace._emptypoints);
8887

8988
// create arrays of brick boundaries, to be used by autorange and heatmap.plot
90-
var xlen = maxRowLength(z),
89+
var xlen = Lib.maxRowLength(z),
9190
xIn = trace.xtype === 'scaled' ? '' : a,
9291
xArray = makeBoundArray(trace, xIn, a0, da, xlen, aax),
9392
yIn = trace.ytype === 'scaled' ? '' : b,

src/traces/heatmap/calc.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ var Axes = require('../../plots/cartesian/axes');
1616
var histogram2dCalc = require('../histogram2d/calc');
1717
var colorscaleCalc = require('../../components/colorscale/calc');
1818
var convertColumnData = require('./convert_column_xyz');
19-
var maxRowLength = require('./max_row_length');
2019
var clean2dArray = require('./clean_2d_array');
2120
var interp2d = require('./interp2d');
2221
var findEmpties = require('./find_empties');
@@ -116,7 +115,7 @@ module.exports = function calc(gd, trace) {
116115
}
117116

118117
// create arrays of brick boundaries, to be used by autorange and heatmap.plot
119-
var xlen = maxRowLength(z);
118+
var xlen = Lib.maxRowLength(z);
120119
var xIn = trace.xtype === 'scaled' ? '' : x;
121120
var xArray = makeBoundArray(trace, xIn, x0, dx, xlen, xa);
122121
var yIn = trace.ytype === 'scaled' ? '' : y;

src/traces/heatmap/find_empties.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
'use strict';
1010

11-
var maxRowLength = require('./max_row_length');
11+
var maxRowLength = require('../../lib').maxRowLength;
1212

1313
/* Return a list of empty points in 2D array z
1414
* each empty point z[i][j] gives an array [i, j, neighborCount]

src/traces/heatmap/max_row_length.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/traces/heatmap/plot.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ var Lib = require('../../lib');
1717
var Colorscale = require('../../components/colorscale');
1818
var xmlnsNamespaces = require('../../constants/xmlns_namespaces');
1919

20-
var maxRowLength = require('./max_row_length');
21-
2220
module.exports = function(gd, plotinfo, cdheatmaps, heatmapLayer) {
2321
var xa = plotinfo.xaxis;
2422
var ya = plotinfo.yaxis;
@@ -38,7 +36,7 @@ module.exports = function(gd, plotinfo, cdheatmaps, heatmapLayer) {
3836

3937
// get z dims
4038
var m = z.length;
41-
var n = maxRowLength(z);
39+
var n = Lib.maxRowLength(z);
4240
var xrev = false;
4341
var yrev = false;
4442

src/traces/scatter/xy_defaults.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
'use strict';
1111

12+
var Lib = require('../../lib');
1213
var Registry = require('../../registry');
1314

14-
1515
module.exports = function handleXYDefaults(traceIn, traceOut, layout, coerce) {
1616
var x = coerce('x');
1717
var y = coerce('y');
@@ -21,10 +21,7 @@ module.exports = function handleXYDefaults(traceIn, traceOut, layout, coerce) {
2121
handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);
2222

2323
if(x) {
24-
xlen = Array.isArray(x[0]) ?
25-
x.map(function(c) { return c.length; })
26-
.sort(function(a, b) { return a - b; })[0] :
27-
x.length;
24+
xlen = Array.isArray(x[0]) ? Lib.maxRowLength(x) : x.length;
2825
if(y) {
2926
len = Math.min(xlen, y.length);
3027
}

0 commit comments

Comments
 (0)