Skip to content

Commit d8b5659

Browse files
committed
First cut at base carpet axis trace type
1 parent be918f0 commit d8b5659

12 files changed

+416
-78
lines changed

src/traces/carpet/ab_defaults.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,17 @@
1313

1414
// var isNumeric = require('fast-isnumeric');
1515

16-
var hasColumns = require('./has_columns');
17-
18-
1916
module.exports = function handleABDefaults(traceIn, traceOut, coerce) {
2017
var a = coerce('a');
2118

22-
if (!a) {
19+
if(!a) {
2320
coerce('da');
2421
coerce('a0');
2522
}
2623

2724
var b = coerce('b');
2825

29-
if (!b) {
26+
if(!b) {
3027
coerce('db');
3128
coerce('b0');
3229
}

src/traces/carpet/array_minmax.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@
88

99
'use strict';
1010

11-
module.exports = function (a) {
11+
module.exports = function(a) {
1212
return minMax(a, 0);
13-
}
13+
};
1414

15-
function minMax (a, depth) {
15+
function minMax(a, depth) {
1616
// Limit to ten dimensional datasets. This seems *exceedingly* unlikely to
1717
// ever cause problems or even be a concern. It's include strictly so that
1818
// circular arrays could never cause this to loop.
19-
if (!Array.isArray(a) || depth >= 10) {
19+
if(!Array.isArray(a) || depth >= 10) {
2020
return null;
2121
}
2222

2323
var min = Infinity;
2424
var max = -Infinity;
2525
var n = a.length;
26-
for (var i = 0; i < n; i++) {
26+
for(var i = 0; i < n; i++) {
2727
var datum = a[i];
2828

29-
if (Array.isArray(datum)) {
29+
if(Array.isArray(datum)) {
3030
var result = minMax(datum, depth + 1);
3131

32-
if (result) {
32+
if(result) {
3333
min = Math.min(result[0], min);
3434
max = Math.max(result[1], max);
3535
}
@@ -40,4 +40,4 @@ function minMax (a, depth) {
4040
}
4141

4242
return [min, max];
43-
};
43+
}

src/traces/carpet/attributes.js

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
'use strict';
1010

11+
var extendFlat = require('../../lib/extend').extendFlat;
12+
var axisAttrs = require('./axis_attributes');
13+
1114
module.exports = {
1215
carpetid: {
1316
valType: 'string',
@@ -88,4 +91,6 @@ module.exports = {
8891
'Only used if `x` is been ommitted.'
8992
].join(' ')
9093
},
94+
aaxis: extendFlat({}, axisAttrs),
95+
baxis: extendFlat({}, axisAttrs),
9196
};

src/traces/carpet/axis_attributes.js

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var extendFlat = require('../../lib/extend').extendFlat;
12+
var fontAttrs = require('../../plots/font_attributes');
13+
var colorAttrs = require('../../components/color/attributes');
14+
15+
module.exports = {
16+
showlabels: {
17+
valType: 'enumerated',
18+
values: ['start', 'end', 'both', 'none'],
19+
dflt: 'end',
20+
role: 'style',
21+
description: [
22+
'Determines whether axis labels are drawn on the low side,',
23+
'the high side, both, or neither side of the axis.'
24+
]
25+
},
26+
labelpadding: {
27+
valType: 'integer',
28+
role: 'style',
29+
dflt: 10,
30+
description: 'Extra padding between label and the axis'
31+
},
32+
labelprefix: {
33+
valType: 'string',
34+
role: 'style',
35+
description: 'Sets a axis label prefix.'
36+
},
37+
labelsuffix: {
38+
valType: 'string',
39+
dflt: '',
40+
role: 'style',
41+
description: 'Sets a axis label suffix.'
42+
},
43+
showstartlabel: {
44+
valType: 'boolean',
45+
dflt: true,
46+
},
47+
showendlabel: {
48+
valType: 'boolean',
49+
dflt: true,
50+
},
51+
showlabelprefix: {
52+
valType: 'enumerated',
53+
values: ['all', 'first', 'last', 'none'],
54+
dflt: 'all',
55+
role: 'style',
56+
description: [
57+
'If *all*, all tick labels are displayed with a prefix.',
58+
'If *first*, only the first tick is displayed with a prefix.',
59+
'If *last*, only the last tick is displayed with a suffix.',
60+
'If *none*, tick prefixes are hidden.'
61+
].join(' ')
62+
},
63+
showlabelsuffix: {
64+
valType: 'enumerated',
65+
values: ['all', 'first', 'last', 'none'],
66+
dflt: 'all',
67+
role: 'style',
68+
description: 'Same as `showtickprefix` but for tick suffixes.'
69+
},
70+
labelfont: extendFlat({}, fontAttrs, {
71+
description: 'Sets the label font.'
72+
}),
73+
gridoffset: {
74+
valType: 'integer',
75+
min: 0,
76+
dflt: 0,
77+
role: 'info',
78+
description: 'The starting index of grid lines along the axis'
79+
},
80+
gridstep: {
81+
valType: 'integer',
82+
min: 1,
83+
dflt: 1,
84+
role: 'info',
85+
description: 'The stride between grid lines along the axis'
86+
},
87+
gridwidth: {
88+
valType: 'number',
89+
min: 0,
90+
dflt: 1,
91+
role: 'style',
92+
description: 'Sets the width (in px) of the grid lines.'
93+
},
94+
gridcolor: {
95+
valType: 'color',
96+
dflt: colorAttrs.defaultLine,
97+
role: 'style',
98+
description: 'Sets the color of the grid lines.'
99+
},
100+
minorgridoffset: {
101+
valType: 'integer',
102+
min: 0,
103+
dflt: 0,
104+
role: 'info',
105+
description: 'The starting index of grid lines along the axis'
106+
},
107+
minorgridstep: {
108+
valType: 'integer',
109+
min: 1,
110+
dflt: 1,
111+
role: 'info',
112+
description: 'The stride between grid lines along the axis'
113+
},
114+
minorgridwidth: {
115+
valType: 'number',
116+
min: 0,
117+
dflt: 1,
118+
role: 'style',
119+
description: 'Sets the width (in px) of the grid lines.'
120+
},
121+
minorgridcolor: {
122+
valType: 'color',
123+
dflt: colorAttrs.lightLine,
124+
role: 'style',
125+
description: 'Sets the color of the grid lines.'
126+
},
127+
};

src/traces/carpet/calc.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,42 @@
88

99
'use strict';
1010

11-
var isNumeric = require('fast-isnumeric');
12-
13-
var Registry = require('../../registry');
14-
var Lib = require('../../lib');
1511
var Axes = require('../../plots/cartesian/axes');
1612
var cheaterBasis = require('./cheater_basis');
13+
var arrayMinmax = require('./array_minmax');
1714

1815

1916
module.exports = function calc(gd, trace) {
2017
var xa = Axes.getFromId(gd, trace.xaxis || 'x'),
2118
ya = Axes.getFromId(gd, trace.yaxis || 'y');
2219

2320
var xdata;
21+
var ydata = trace.y;
2422

2523
if(trace._cheater) {
2624
xdata = cheaterBasis(trace.a.length, trace.b.length, trace.cheaterslope);
2725
} else {
2826
xdata = trace.x;
2927
}
3028

29+
// This is a rather expensive scan. Nothing guarantees monotonicity,
30+
// so we need to scan through all data to get proper ranges:
31+
var xrange = arrayMinmax(xdata);
32+
var yrange = arrayMinmax(ydata);
33+
34+
var dx = 0.5 * (xrange[1] - xrange[0]);
35+
var xc = 0.5 * (xrange[1] + xrange[0]);
36+
37+
var dy = 0.5 * (yrange[1] - yrange[0]);
38+
var yc = 0.5 * (yrange[1] + yrange[0]);
39+
40+
var grow = 1.3;
41+
xrange = [xc - dx * grow, xc + dx * grow];
42+
yrange = [yc - dy * grow, yc + dy * grow];
43+
44+
Axes.expand(xa, xrange, {padded: true});
45+
Axes.expand(ya, yrange, {padded: true});
46+
3147
var cd0 = {
3248
x: xdata,
3349
y: trace.y,

src/traces/carpet/cheater_basis.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88

99
'use strict';
1010

11-
module.exports = function (na, nb, cheaterslope) {
11+
module.exports = function(na, nb, cheaterslope) {
1212
var i, j;
1313
var data = [];
1414

15-
for (i = 0; i < na; i++) {
15+
for(i = 0; i < na; i++) {
1616
data[i] = [];
17-
for (j = 0; j < nb; j++) {
17+
for(j = 0; j < nb; j++) {
1818
data[i][j] = i - j * cheaterslope;
1919
}
2020
}
2121

2222
return data;
23-
}
23+
};

src/traces/carpet/compute_bounds.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = function computeBounds() {
12+
13+
};

src/traces/carpet/construct_cheater.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
/* this function constructs an array of arrays with offset per row in the
1313
* style of a cheater plot.
1414
*/
15-
module.exports = function constructCheater () {
15+
module.exports = function constructCheater() {
1616
};

0 commit comments

Comments
 (0)