Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ce47ee1

Browse filesBrowse files
committed
refactor splom - add files for calc plot hover select helpers and update_scene
1 parent aa84535 commit ce47ee1
Copy full SHA for ce47ee1

File tree

Expand file treeCollapse file tree

8 files changed

+512
-425
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+512
-425
lines changed

‎src/traces/splom/calc.js

Copy file name to clipboard
+109Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/**
2+
* Copyright 2012-2019, 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 Lib = require('../../lib');
12+
var AxisIDs = require('../../plots/cartesian/axis_ids');
13+
14+
var calcMarkerSize = require('../scatter/calc').calcMarkerSize;
15+
var calcAxisExpansion = require('../scatter/calc').calcAxisExpansion;
16+
var calcColorscale = require('../scatter/colorscale_calc');
17+
var convertMarkerSelection = require('../scattergl/convert').markerSelection;
18+
var convertMarkerStyle = require('../scattergl/convert').markerStyle;
19+
var sceneUpdate = require('./scene_update');
20+
21+
var BADNUM = require('../../constants/numerical').BADNUM;
22+
var TOO_MANY_POINTS = require('../scattergl/constants').TOO_MANY_POINTS;
23+
24+
module.exports = function calc(gd, trace) {
25+
var dimensions = trace.dimensions;
26+
var commonLength = trace._length;
27+
var opts = {};
28+
// 'c' for calculated, 'l' for linear,
29+
// only differ here for log axes, pass ldata to createMatrix as 'data'
30+
var cdata = opts.cdata = [];
31+
var ldata = opts.data = [];
32+
// keep track of visible dimensions
33+
var visibleDims = trace._visibleDims = [];
34+
var i, k, dim, xa, ya;
35+
36+
function makeCalcdata(ax, dim) {
37+
// call makeCalcdata with fake input
38+
var ccol = ax.makeCalcdata({
39+
v: dim.values,
40+
vcalendar: trace.calendar
41+
}, 'v');
42+
43+
for(var j = 0; j < ccol.length; j++) {
44+
ccol[j] = ccol[j] === BADNUM ? NaN : ccol[j];
45+
}
46+
cdata.push(ccol);
47+
ldata.push(ax.type === 'log' ? Lib.simpleMap(ccol, ax.c2l) : ccol);
48+
}
49+
50+
for(i = 0; i < dimensions.length; i++) {
51+
dim = dimensions[i];
52+
53+
if(dim.visible) {
54+
xa = AxisIDs.getFromId(gd, trace._diag[i][0]);
55+
ya = AxisIDs.getFromId(gd, trace._diag[i][1]);
56+
57+
// if corresponding x & y axes don't have matching types, skip dim
58+
if(xa && ya && xa.type !== ya.type) {
59+
Lib.log('Skipping splom dimension ' + i + ' with conflicting axis types');
60+
continue;
61+
}
62+
63+
if(xa) {
64+
makeCalcdata(xa, dim);
65+
if(ya && ya.type === 'category') {
66+
ya._categories = xa._categories.slice();
67+
}
68+
} else {
69+
// should not make it here, if both xa and ya undefined
70+
makeCalcdata(ya, dim);
71+
}
72+
73+
visibleDims.push(i);
74+
}
75+
}
76+
77+
calcColorscale(gd, trace);
78+
Lib.extendFlat(opts, convertMarkerStyle(trace));
79+
80+
var visibleLength = cdata.length;
81+
var hasTooManyPoints = (visibleLength * commonLength) > TOO_MANY_POINTS;
82+
83+
// Reuse SVG scatter axis expansion routine.
84+
// For graphs with very large number of points and array marker.size,
85+
// use average marker size instead to speed things up.
86+
var ppad;
87+
if(hasTooManyPoints) {
88+
ppad = 2 * (opts.sizeAvg || Math.max(opts.size, 3));
89+
} else {
90+
ppad = calcMarkerSize(trace, commonLength);
91+
}
92+
93+
for(k = 0; k < visibleDims.length; k++) {
94+
i = visibleDims[k];
95+
dim = dimensions[i];
96+
xa = AxisIDs.getFromId(gd, trace._diag[i][0]) || {};
97+
ya = AxisIDs.getFromId(gd, trace._diag[i][1]) || {};
98+
calcAxisExpansion(gd, trace, xa, ya, cdata[k], cdata[k], ppad);
99+
}
100+
101+
var scene = sceneUpdate(gd, trace);
102+
if(!scene.matrix) scene.matrix = true;
103+
scene.matrixOptions = opts;
104+
105+
scene.selectedOptions = convertMarkerSelection(trace, trace.selected);
106+
scene.unselectedOptions = convertMarkerSelection(trace, trace.unselected);
107+
108+
return [{x: false, y: false, t: {}, trace: trace}];
109+
};

‎src/traces/splom/helpers.js

Copy file name to clipboard
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright 2012-2019, 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+
exports.getDimIndex = function getDimIndex(trace, ax) {
12+
var axId = ax._id;
13+
var axLetter = axId.charAt(0);
14+
var ind = {x: 0, y: 1}[axLetter];
15+
var visibleDims = trace._visibleDims;
16+
17+
for(var k = 0; k < visibleDims.length; k++) {
18+
var i = visibleDims[k];
19+
if(trace._diag[i][ind] === axId) return k;
20+
}
21+
return false;
22+
};

‎src/traces/splom/hover.js

Copy file name to clipboard
+61Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Copyright 2012-2019, 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 helpers = require('./helpers');
12+
var calcHover = require('../scattergl/hover').calcHover;
13+
14+
function hoverPoints(pointData, xval, yval) {
15+
var cd = pointData.cd;
16+
var trace = cd[0].trace;
17+
var scene = pointData.scene;
18+
var cdata = scene.matrixOptions.cdata;
19+
var xa = pointData.xa;
20+
var ya = pointData.ya;
21+
var xpx = xa.c2p(xval);
22+
var ypx = ya.c2p(yval);
23+
var maxDistance = pointData.distance;
24+
25+
var xi = helpers.getDimIndex(trace, xa);
26+
var yi = helpers.getDimIndex(trace, ya);
27+
if(xi === false || yi === false) return [pointData];
28+
29+
var x = cdata[xi];
30+
var y = cdata[yi];
31+
32+
var id, dxy;
33+
var minDist = maxDistance;
34+
35+
for(var i = 0; i < x.length; i++) {
36+
var ptx = x[i];
37+
var pty = y[i];
38+
var dx = xa.c2p(ptx) - xpx;
39+
var dy = ya.c2p(pty) - ypx;
40+
var dist = Math.sqrt(dx * dx + dy * dy);
41+
42+
if(dist < minDist) {
43+
minDist = dxy = dist;
44+
id = i;
45+
}
46+
}
47+
48+
pointData.index = id;
49+
pointData.distance = minDist;
50+
pointData.dxy = dxy;
51+
52+
if(id === undefined) return [pointData];
53+
54+
calcHover(pointData, x, y, trace);
55+
56+
return [pointData];
57+
}
58+
59+
module.exports = {
60+
hoverPoints: hoverPoints
61+
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.