Skip to content
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

Streamtubes [WIP] #701

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Core.register([
require('./pie'),
require('./contour'),
require('./scatter3d'),
require('./streamtube'),
require('./surface'),
require('./mesh3d'),
require('./scattergeo'),
Expand Down
9 changes: 9 additions & 0 deletions lib/streamtube.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, 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.
*/

module.exports = require('../src/traces/streamtube');
2 changes: 1 addition & 1 deletion src/plots/gl3d/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ proto.plot = function(sceneData, fullLayout, layout) {
}

/*
* Write aspect Ratio back to user data and fullLayout so that it is modifies as user
* Write aspect Ratio back to user data and fullLayout so that it is modified as user
* manipulates the aspectmode settings and the fullLayout is up-to-date.
*/
fullSceneLayout.aspectratio.x = sceneLayout.aspectratio.x = aspectRatio[0];
Expand Down
2 changes: 1 addition & 1 deletion src/traces/mesh3d/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Mesh3D.colorbar = require('../heatmap/colorbar');
Mesh3D.plot = require('./convert');

Mesh3D.moduleType = 'trace';
Mesh3D.name = 'mesh3d',
Mesh3D.name = 'mesh3d';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good 👀

Mesh3D.basePlotModule = require('../../plots/gl3d');
Mesh3D.categories = ['gl3d'];
Mesh3D.meta = {
Expand Down
30 changes: 30 additions & 0 deletions src/traces/scatter/basic_line_defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright 2012-2016, 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';

var hasColorscale = require('../../components/colorscale/has_colorscale');
var colorscaleDefaults = require('../../components/colorscale/defaults');


// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
module.exports = function lineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {

var markerColor = (traceIn.marker || {}).color;

coerce('line.color', defaultColor);
if(hasColorscale(traceIn, 'line')) {
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c'}
);
} else {
coerce('line.color', (Array.isArray(markerColor) ? false : markerColor) ||
defaultColor);
}
};
16 changes: 2 additions & 14 deletions src/traces/scatter/line_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,13 @@

'use strict';

var hasColorscale = require('../../components/colorscale/has_colorscale');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var basicLineDefaults = require('./basic_line_defaults');


// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
module.exports = function lineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {

var markerColor = (traceIn.marker || {}).color;

coerce('line.color', defaultColor);
if(hasColorscale(traceIn, 'line')) {
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c'}
);
} else {
coerce('line.color', (Array.isArray(markerColor) ? false : markerColor) ||
defaultColor);
}

basicLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);

coerce('line.width');
coerce('line.dash');
Expand Down
42 changes: 42 additions & 0 deletions src/traces/scatter/marker_basic_defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright 2012-2016, 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';

var hasColorscale = require('../../components/colorscale/has_colorscale');
var colorscaleDefaults = require('../../components/colorscale/defaults');

var subTypes = require('./subtypes');


// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
var isBubble = subTypes.isBubble(traceIn),
lineColor = !Array.isArray(traceIn.line) ? (traceIn.line || {}).color : undefined;

if(lineColor) defaultColor = lineColor;

coerce('marker.opacity', isBubble ? 0.7 : 1);
coerce('marker.size');

coerce('marker.color', defaultColor);
if(hasColorscale(traceIn, 'marker')) {
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'}
);
}

if(isBubble) {
coerce('marker.sizeref');
coerce('marker.sizemin');
coerce('marker.sizemode');
}

return lineColor;
};
26 changes: 7 additions & 19 deletions src/traces/scatter/marker_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,22 @@

'use strict';

var markerBasicDefaults = require('./marker_basic_defaults');
var Color = require('../../components/color');
var hasColorscale = require('../../components/colorscale/has_colorscale');
var colorscaleDefaults = require('../../components/colorscale/defaults');

var subTypes = require('./subtypes');


// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
var isBubble = subTypes.isBubble(traceIn),
lineColor = !Array.isArray(traceIn.line) ? (traceIn.line || {}).color : undefined,
defaultMLC;

if(lineColor) defaultColor = lineColor;
var defaultMLC;

coerce('marker.symbol');
coerce('marker.opacity', isBubble ? 0.7 : 1);
coerce('marker.size');
var isBubble = subTypes.isBubble(traceIn);
var lineColor = markerBasicDefaults(traceIn, traceOut, defaultColor, layout, coerce);

coerce('marker.color', defaultColor);
if(hasColorscale(traceIn, 'marker')) {
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'}
);
}
coerce('marker.symbol');

// if there's a line with a different color than the marker, use
// that line color as the default marker line color
Expand All @@ -45,6 +36,7 @@ module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout
else defaultMLC = Color.defaultLine;

coerce('marker.line.color', defaultMLC);

if(hasColorscale(traceIn, 'marker.line')) {
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: 'marker.line.', cLetter: 'c'}
Expand All @@ -53,9 +45,5 @@ module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout

coerce('marker.line.width', isBubble ? 1 : 0);

if(isBubble) {
coerce('marker.sizeref');
coerce('marker.sizemin');
coerce('marker.sizemode');
}

};
141 changes: 141 additions & 0 deletions src/traces/streamtube/attributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/**
* Copyright 2012-2016, 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';

var scatterAttrs = require('../scatter/attributes');
var colorAttributes = require('../../components/colorscale/color_attributes');

var extendFlat = require('../../lib/extend').extendFlat;

var scatterMarkerAttrs = scatterAttrs.marker;

function makeProjectionAttr(axLetter) {
return {
show: {
valType: 'boolean',
role: 'info',
dflt: false,
description: [
'Sets whether or not projections are shown along the',
axLetter, 'axis.'
].join(' ')
},
opacity: {
valType: 'number',
role: 'style',
min: 0,
max: 1,
dflt: 1,
description: 'Sets the projection color.'
},
scale: {
valType: 'number',
role: 'style',
min: 0,
max: 10,
dflt: 2 / 3,
description: [
'Sets the scale factor determining the size of the',
'projection marker points.'
].join(' ')
}
};
}

module.exports = {
x: {
valType: 'data_array',
description: 'Sets the x coordinates.'
},
y: {
valType: 'data_array',
description: 'Sets the y coordinates.'
},
z: {
valType: 'data_array',
description: 'Sets the z coordinates.'
},
text: extendFlat({}, scatterAttrs.text, {
description: [
'Sets text elements associated with each (x,y,z) triplet.',
'If a single string, the same string appears over',
'all the data points.',
'If an array of string, the items are mapped in order to the',
'this trace\'s (x,y,z) coordinates.'
].join(' ')
}),
mode: extendFlat({}, scatterAttrs.mode, // shouldn't this be on-par with 2D?
{dflt: 'lines+markers'}),
projection: {
x: makeProjectionAttr('x'),
y: makeProjectionAttr('y'),
z: makeProjectionAttr('z')
},
sizingaxis: {
valType: 'enumerated',
role: 'info',
values: [0, 1, 2],
dflt: 0,
description: [
'Specifies the axis index in relation to which the `line.width` and `marker.size` values are determined. The',
'default value is `0`, which specifies the `x` axis, i.e. sizes will be determined as a multiple of one unit',
'on the `x` axis. `0`, `1`, `2` refer to `x`, `y`, `z`, respectively.'
].join(' ')
},
connectgaps: scatterAttrs.connectgaps,
line: extendFlat({}, {
connectiondiameter: extendFlat({}, scatterMarkerAttrs.size, {
dflt: 1,
description: 'Sets the radius of the line connection. Either a number, or an array with as many elements as the number of points.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify the current behaviour:

Starting from:

image

then Plotly.relayout(gd, 'scene.zaxis.range', [-10, 10]); yields:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. In this case, the light reflection can be more of a distraction than a positive. So with this type of use, it's good to avoid using a specular light component.

}),
showscale: {
valType: 'boolean',
role: 'info',
dflt: false,
description: [
'Has an effect only if `line.color` is set to a numerical array.',
'Determines whether or not a colorbar is displayed.'
].join(' ')
}
},
colorAttributes('line')
),
marker: extendFlat({}, {
size: {
valType: 'number',
min: 0,
dflt: 1,
arrayOk: true,
role: 'style',
description: 'Sets the marker radius, in units of `sizingaxis`. May be a number or an array of numbers.'
},
sizeref: scatterMarkerAttrs.sizeref,
sizemin: scatterMarkerAttrs.sizemin,
sizemode: scatterMarkerAttrs.sizemode,
opacity: extendFlat({}, scatterMarkerAttrs.opacity, {
arrayOk: false,
description: [
'Sets the marker opacity.',
'Note that the marker opacity for scatter3d traces',
'must be a scalar value for performance reasons.',
'To set a blending opacity value',
'(i.e. which is not transparent), set *marker.color*',
'to an rgba color and use its alpha channel.'
].join(' ')
}),
showscale: scatterMarkerAttrs.showscale
},
colorAttributes('marker')
),
textposition: extendFlat({}, scatterAttrs.textposition, {dflt: 'top center'}),
textfont: scatterAttrs.textfont,
_nestedModules: {
'marker.colorbar': 'Colorbar'
}
};
27 changes: 27 additions & 0 deletions src/traces/streamtube/calc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright 2012-2016, 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';

var arraysToCalcdata = require('../scatter/arrays_to_calcdata');
var calcColorscales = require('../scatter/colorscale_calc');


/**
* This is a kludge to put the array attributes into
* calcdata the way Scatter.plot does, so that legends and
* popovers know what to do with them.
*/
module.exports = function calc(gd, trace) {
var cd = [{x: false, y: false, trace: trace, t: {}}];

arraysToCalcdata(cd);
calcColorscales(trace);

return cd;
};
Loading