Skip to content

Commit be918f0

Browse files
committed
First signs of life with carpet
1 parent 587bae4 commit be918f0

File tree

6 files changed

+152
-8
lines changed

6 files changed

+152
-8
lines changed

src/plots/plots.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,6 @@ plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {
664664
var trace = dataIn[i],
665665
fullTrace = plots.supplyTraceDefaults(trace, cnt, fullLayout, i);
666666

667-
console.log('fullLayout:', JSON.stringify(fullLayout));
668667
fullTrace.index = i;
669668
fullTrace._input = trace;
670669
fullTrace._expandedIndex = cnt;

src/plots/subplot_defaults.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ module.exports = function handleSubplotDefaults(layoutIn, layoutOut, fullData, o
4949
var ids = Plots.findSubplotIds(fullData, subplotType),
5050
idsLength = ids.length;
5151

52-
console.log('ids:', ids);
53-
5452
var subplotLayoutIn, subplotLayoutOut;
5553

5654
function coerce(attr, dflt) {

src/traces/carpet/array_minmax.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 (a) {
12+
return minMax(a, 0);
13+
}
14+
15+
function minMax (a, depth) {
16+
// Limit to ten dimensional datasets. This seems *exceedingly* unlikely to
17+
// ever cause problems or even be a concern. It's include strictly so that
18+
// circular arrays could never cause this to loop.
19+
if (!Array.isArray(a) || depth >= 10) {
20+
return null;
21+
}
22+
23+
var min = Infinity;
24+
var max = -Infinity;
25+
var n = a.length;
26+
for (var i = 0; i < n; i++) {
27+
var datum = a[i];
28+
29+
if (Array.isArray(datum)) {
30+
var result = minMax(datum, depth + 1);
31+
32+
if (result) {
33+
min = Math.min(result[0], min);
34+
max = Math.max(result[1], max);
35+
}
36+
} else {
37+
min = Math.min(datum, min);
38+
max = Math.max(datum, max);
39+
}
40+
}
41+
42+
return [min, max];
43+
};

src/traces/carpet/calc.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/**
32
* Copyright 2012-2016, Plotly, Inc.
43
* All rights reserved.
@@ -7,24 +6,34 @@
76
* LICENSE file in the root directory of this source tree.
87
*/
98

10-
119
'use strict';
1210

1311
var isNumeric = require('fast-isnumeric');
1412

1513
var Registry = require('../../registry');
1614
var Lib = require('../../lib');
1715
var Axes = require('../../plots/cartesian/axes');
18-
var maxRowLength =
16+
var cheaterBasis = require('./cheater_basis');
1917

2018

2119
module.exports = function calc(gd, trace) {
2220
var xa = Axes.getFromId(gd, trace.xaxis || 'x'),
2321
ya = Axes.getFromId(gd, trace.yaxis || 'y');
2422

23+
var xdata;
2524

26-
var cd0 = {};
25+
if(trace._cheater) {
26+
xdata = cheaterBasis(trace.a.length, trace.b.length, trace.cheaterslope);
27+
} else {
28+
xdata = trace.x;
29+
}
2730

31+
var cd0 = {
32+
x: xdata,
33+
y: trace.y,
34+
a: trace.a,
35+
b: trace.b
36+
};
2837

2938
return [cd0];
3039
};

src/traces/carpet/cheater_basis.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 (na, nb, cheaterslope) {
12+
var i, j;
13+
var data = [];
14+
15+
for (i = 0; i < na; i++) {
16+
data[i] = [];
17+
for (j = 0; j < nb; j++) {
18+
data[i][j] = i - j * cheaterslope;
19+
}
20+
}
21+
22+
return data;
23+
}

src/traces/carpet/plot.js

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,77 @@ var d3 = require('d3');
1414
var Lib = require('../../lib');
1515
var Drawing = require('../../components/drawing');
1616

17-
module.exports = function plot(gd, plotinfo, cdscatter) {
17+
module.exports = function plot(gd, plotinfo, cdcarpet) {
18+
for(var i = 0; i < cdcarpet.length; i++) {
19+
plotOne(gd, plotinfo, cdcarpet[i]);
20+
}
1821
};
22+
23+
function plotOne(gd, plotinfo, cd) {
24+
var trace = cd[0].trace,
25+
uid = trace.uid,
26+
xa = plotinfo.xaxis,
27+
ya = plotinfo.yaxis,
28+
fullLayout = gd._fullLayout,
29+
id = 'carpet' + uid;
30+
31+
var x = cd[0].x;
32+
var y = cd[0].y;
33+
var a = cd[0].a;
34+
var b = cd[0].b;
35+
var xp = xa.c2p;
36+
var yp = ya.c2p;
37+
38+
window.x = x;
39+
window.y = y;
40+
window.xa = xa;
41+
window.ya = ya;
42+
43+
// XXX: Layer choice??
44+
var gridLayer = plotinfo.plot.selectAll('.maplayer');
45+
46+
var linesets = [{
47+
class: 'const-a-line',
48+
data: b,
49+
xc: function (i, j) { return xp(x[i][j]); },
50+
yc: function (i, j) { return yp(y[i][j]); },
51+
n: a.length
52+
}, {
53+
class: 'const-b-line',
54+
data: a,
55+
xc: function (i, j) { return xp(x[j][i]); },
56+
yc: function (i, j) { return yp(y[j][i]); },
57+
n: b.length
58+
}];
59+
60+
for (var i = 0; i < linesets.length; i++) {
61+
var lineset = linesets[i];
62+
drawGridLines(gridLayer, lineset);
63+
}
64+
}
65+
66+
function drawAxisLabels () {
67+
}
68+
69+
function drawGridLines (layer, ls) {
70+
var gridjoin = layer.selectAll('.' + ls.class).data(ls.data);
71+
72+
gridjoin.enter().append('path')
73+
.classed(ls.class, true)
74+
.style('vector-effect', 'non-scaling-stroke');
75+
76+
gridjoin.each(function (d, i) {
77+
var el = d3.select(this);
78+
el.attr('d', function () {
79+
var pts = [];
80+
for(var k = 0; k < ls.n; k++) {
81+
pts.push(ls.xc(i, k) + ',' + ls.yc(i, k));
82+
}
83+
return 'M' + pts.join('L');
84+
})
85+
el.style('stroke-width', 1)
86+
.style('stroke', 'gray')
87+
.style('fill', 'none');
88+
})
89+
.exit().remove();
90+
}

0 commit comments

Comments
 (0)