Skip to content

3D cone traces #2641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
May 18, 2018
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ec64895
scaffold cone
etpinard Apr 16, 2018
5736290
move 3d parseColorScale to gl_format_color
etpinard May 16, 2018
cb7cb7f
get cone colorbar and vx/vy/vz mesh grid to work
etpinard May 16, 2018
89eaf11
add three cone mocks
etpinard May 16, 2018
863b0da
implement 'sizemode' and 'sizeref'
etpinard May 16, 2018
fa32a74
add lib/cone.js + add cone to gl3d bundle
etpinard May 16, 2018
71e46af
hook in hover labels for cones
etpinard May 16, 2018
a2c3694
clean up scene computeTraceBounds
etpinard May 17, 2018
a2db567
find min/max u/v/w norm in calc directly
etpinard May 17, 2018
db8222b
add "pad" using max u/v/w norm around cone bounds
etpinard May 17, 2018
55700b8
add 'anchor' to mimic gl-cone3d's coneOffset
etpinard May 17, 2018
e4a2035
add cone-specific hoverinfo flags
etpinard May 17, 2018
a02dd11
fixup cmin/cmax -> vertexIntensityBounds
etpinard May 17, 2018
cb7ef43
improve interplay between vector and cone position attributes
etpinard May 17, 2018
e718c66
fixup hover gl-scatter3d trace for cone with set `cones.(x|y|z)`
etpinard May 17, 2018
f651eec
use stashed gl-cone3d field as hover x/y/z u/v/w fields
etpinard May 17, 2018
3f3bfac
rename image-exporter -> orca
etpinard May 17, 2018
aaf7249
mv gl3d_cone-* out of `npm run test-image` into noci_test.sh
etpinard May 17, 2018
d5d6f33
add some cone tests
etpinard May 17, 2018
b7465fb
add hover label test for cones
etpinard May 17, 2018
5a42de0
comment out cones.(x|y|z) attributes for now
etpinard May 17, 2018
04d3d91
better pad value for autoranged cones
etpinard May 18, 2018
2a45dae
revert to current gl-cone3d master
etpinard May 18, 2018
8dca9ae
factor out `visible: false` converse test
etpinard May 18, 2018
3d26d47
fixup cone autorange pad computation
etpinard May 18, 2018
5a59bc7
fixup pad autorange (again)
etpinard May 18, 2018
3dd6cf5
pass gl-mesh3d lighting params
etpinard May 18, 2018
fb2ec1e
use gl-cone2d "vectorScale" to get better autorange pad value
etpinard May 18, 2018
74ecbf8
scaled pad value by normMax only under sizemode: 'scaled'
etpinard May 18, 2018
abb11e0
sub in npm version for gl-cone3d
etpinard May 18, 2018
8e8f5d6
fixup tests post 74ecbf8
etpinard May 18, 2018
2c08357
add autorange test case for "scaled up the x/y/z arrays"
etpinard May 18, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/cone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright 2012-2018, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

module.exports = require('../src/traces/cone');
3 changes: 2 additions & 1 deletion lib/index-gl3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var Plotly = require('./core');
Plotly.register([
require('./scatter3d'),
require('./surface'),
require('./mesh3d')
require('./mesh3d'),
require('./cone')
]);

module.exports = Plotly;
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Plotly.register([
require('./scatter3d'),
require('./surface'),
require('./mesh3d'),
require('./cone'),

require('./scattergeo'),
require('./choropleth'),
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"es6-promise": "^3.0.2",
"fast-isnumeric": "^1.1.1",
"font-atlas-sdf": "^1.3.3",
"gl-cone3d": "^v1.0.0",
"gl-contour2d": "^1.1.4",
"gl-error3d": "^1.0.7",
"gl-heatmap2d": "^1.0.4",
Expand Down
20 changes: 19 additions & 1 deletion src/lib/gl_format_color.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'use strict';

var isNumeric = require('fast-isnumeric');
var tinycolor = require('tinycolor2');
var rgba = require('color-normalize');

var Colorscale = require('../components/colorscale');
Expand Down Expand Up @@ -85,4 +86,21 @@ function formatColor(containerIn, opacityIn, len) {
return colorOut;
}

module.exports = formatColor;
function parseColorScale(colorscale, alpha) {
if(alpha === undefined) alpha = 1;

return colorscale.map(function(elem) {
var index = elem[0];
var color = tinycolor(elem[1]);
var rgb = color.toRgb();
return {
index: index,
rgb: [rgb.r, rgb.g, rgb.b, alpha]
};
});
}

module.exports = {
formatColor: formatColor,
parseColorScale: parseColorScale
};
105 changes: 68 additions & 37 deletions src/plots/gl3d/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,53 @@ function render(scene) {
trace = lastPicked.data;
var ptNumber = selection.index;
var hoverinfo = Fx.castHoverinfo(trace, scene.fullLayout, ptNumber);
var hoverinfoParts = hoverinfo.split('+');
var isHoverinfoAll = hoverinfo === 'all';

var xVal = formatter('xaxis', selection.traceCoordinate[0]),
yVal = formatter('yaxis', selection.traceCoordinate[1]),
zVal = formatter('zaxis', selection.traceCoordinate[2]);
var xVal = formatter('xaxis', selection.traceCoordinate[0]);
var yVal = formatter('yaxis', selection.traceCoordinate[1]);
var zVal = formatter('zaxis', selection.traceCoordinate[2]);

if(hoverinfo !== 'all') {
var hoverinfoParts = hoverinfo.split('+');
if(!isHoverinfoAll) {
if(hoverinfoParts.indexOf('x') === -1) xVal = undefined;
if(hoverinfoParts.indexOf('y') === -1) yVal = undefined;
if(hoverinfoParts.indexOf('z') === -1) zVal = undefined;
if(hoverinfoParts.indexOf('text') === -1) selection.textLabel = undefined;
if(hoverinfoParts.indexOf('name') === -1) lastPicked.name = undefined;
}

var tx;

if(trace.type === 'cone') {
var coneTx = [];
if(isHoverinfoAll || hoverinfoParts.indexOf('u') !== -1) {
coneTx.push('u: ' + formatter('xaxis', selection.traceCoordinate[3]));
}
if(isHoverinfoAll || hoverinfoParts.indexOf('v') !== -1) {
coneTx.push('v: ' + formatter('yaxis', selection.traceCoordinate[4]));
}
if(isHoverinfoAll || hoverinfoParts.indexOf('w') !== -1) {
coneTx.push('w: ' + formatter('zaxis', selection.traceCoordinate[5]));
}
if(isHoverinfoAll || hoverinfoParts.indexOf('norm') !== -1) {
coneTx.push('norm: ' + selection.traceCoordinate[6].toPrecision(3));
}
if(selection.textLabel) {
coneTx.push(selection.textLabel);
}
tx = coneTx.join('<br>');
} else {
tx = selection.textLabel;
}

if(scene.fullSceneLayout.hovermode) {
Fx.loneHover({
x: (0.5 + 0.5 * pdata[0] / pdata[3]) * width,
y: (0.5 - 0.5 * pdata[1] / pdata[3]) * height,
xLabel: xVal,
yLabel: yVal,
zLabel: zVal,
text: selection.textLabel,
text: tx,
name: lastPicked.name,
color: Fx.castHoverOption(trace, ptNumber, 'bgcolor') || lastPicked.color,
borderColor: Fx.castHoverOption(trace, ptNumber, 'bordercolor'),
Expand Down Expand Up @@ -306,41 +331,44 @@ proto.recoverContext = function() {

var axisProperties = [ 'xaxis', 'yaxis', 'zaxis' ];

function coordinateBound(axis, coord, len, d, bounds, calendar) {
var x;
if(!Lib.isArrayOrTypedArray(coord)) {
bounds[0][d] = Math.min(bounds[0][d], 0);
bounds[1][d] = Math.max(bounds[1][d], len - 1);
return;
}
function computeTraceBounds(scene, trace, bounds) {
var sceneLayout = scene.fullSceneLayout;

for(var i = 0; i < (len || coord.length); ++i) {
if(Lib.isArrayOrTypedArray(coord[i])) {
for(var j = 0; j < coord[i].length; ++j) {
x = axis.d2l(coord[i][j], 0, calendar);
if(!isNaN(x) && isFinite(x)) {
bounds[0][d] = Math.min(bounds[0][d], x);
bounds[1][d] = Math.max(bounds[1][d], x);
for(var d = 0; d < 3; d++) {
var axisName = axisProperties[d];
var axLetter = axisName.charAt(0);
var ax = sceneLayout[axisName];
var coords = trace[axLetter];
var calendar = trace[axLetter + 'calendar'];
var len = trace['_' + axLetter + 'length'];

if(!Lib.isArrayOrTypedArray(coords)) {
bounds[0][d] = Math.min(bounds[0][d], 0);
bounds[1][d] = Math.max(bounds[1][d], len - 1);
} else {
var v;

for(var i = 0; i < (len || coords.length); i++) {
if(Lib.isArrayOrTypedArray(coords[i])) {
for(var j = 0; j < coords[i].length; ++j) {
v = ax.d2l(coords[i][j], 0, calendar);
if(!isNaN(v) && isFinite(v)) {
bounds[0][d] = Math.min(bounds[0][d], v);
bounds[1][d] = Math.max(bounds[1][d], v);
}
}
} else {
v = ax.d2l(coords[i], 0, calendar);
if(!isNaN(v) && isFinite(v)) {
bounds[0][d] = Math.min(bounds[0][d], v);
bounds[1][d] = Math.max(bounds[1][d], v);
}
}
}
}
else {
x = axis.d2l(coord[i], 0, calendar);
if(!isNaN(x) && isFinite(x)) {
bounds[0][d] = Math.min(bounds[0][d], x);
bounds[1][d] = Math.max(bounds[1][d], x);
}
}
}
}

function computeTraceBounds(scene, trace, bounds) {
var sceneLayout = scene.fullSceneLayout;
coordinateBound(sceneLayout.xaxis, trace.x, trace._xlength, 0, bounds, trace.xcalendar);
coordinateBound(sceneLayout.yaxis, trace.y, trace._ylength, 1, bounds, trace.ycalendar);
coordinateBound(sceneLayout.zaxis, trace.z, trace._zlength, 2, bounds, trace.zcalendar);
}

proto.plot = function(sceneData, fullLayout, layout) {

// Save parameters
Expand Down Expand Up @@ -477,9 +505,12 @@ proto.plot = function(sceneData, fullLayout, layout) {
var axLetter = axis._name.charAt(0);

for(j = 0; j < objects.length; j++) {
var objBounds = objects[j].bounds;
sceneBounds[0][i] = Math.min(sceneBounds[0][i], objBounds[0][i] / dataScale[i]);
sceneBounds[1][i] = Math.max(sceneBounds[1][i], objBounds[1][i] / dataScale[i]);
var obj = objects[j];
var objBounds = obj.bounds;
var pad = obj._trace.data._pad || 0;

sceneBounds[0][i] = Math.min(sceneBounds[0][i], objBounds[0][i] / dataScale[i] - pad);
sceneBounds[1][i] = Math.max(sceneBounds[1][i], objBounds[1][i] / dataScale[i] + pad);
}

for(j = 0; j < annotations.length; j++) {
Expand Down
Loading