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

Add "raw" sizemode to cone trace #6938

Merged
merged 9 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 2 additions & 0 deletions draftlogs/6938_add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add "raw" sizemode to cone trace [[#6938](https://github.com/plotly/plotly.js/pull/6938)]

8 changes: 5 additions & 3 deletions src/traces/cone/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ var attrs = {

sizemode: {
valType: 'enumerated',
values: ['scaled', 'absolute'],
values: ['scaled', 'absolute', 'raw'],
editType: 'calc',
dflt: 'scaled',
description: [
'Determines whether `sizeref` is set as a *scaled* (i.e unitless) scalar',
'(normalized by the max u/v/w norm in the vector field) or as',
'*absolute* value (in the same units as the vector field).'
'*absolute* value (in the same units as the vector field).',
'To display sizes in actual vector length use *raw*.'
].join(' ')
},
sizeref: {
Expand All @@ -115,7 +116,8 @@ var attrs = {
'This factor (computed internally) corresponds to the minimum "time" to travel across',
'two successive x/y/z positions at the average velocity of those two successive positions.',
'All cones in a given trace use the same factor.',
'With `sizemode` set to *scaled*, `sizeref` is unitless, its default value is *0.5*',
'With `sizemode` set to *raw*, its default value is *1*.',
'With `sizemode` set to *scaled*, `sizeref` is unitless, its default value is *0.5*.',
'With `sizemode` set to *absolute*, `sizeref` has the same units as the u/v/w vector field,',
'its the default value is half the sample\'s maximum vector norm.'
].join(' ')
Expand Down
9 changes: 7 additions & 2 deletions src/traces/cone/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,20 @@ function convert(scene, trace) {
coneOpts.vertexIntensityBounds = [cOpts.min / trace._normMax, cOpts.max / trace._normMax];
coneOpts.coneOffset = anchor2coneOffset[trace.anchor];

if(trace.sizemode === 'scaled') {

var sizemode = trace.sizemode;
if(sizemode === 'scaled') {
// unitless sizeref
coneOpts.coneSize = trace.sizeref || 0.5;
} else {
} else if(sizemode === 'absolute') {
// sizeref here has unit of velocity
coneOpts.coneSize = trace.sizeref && trace._normMax ?
trace.sizeref / trace._normMax :
0.5;
} else if(sizemode === 'raw') {
coneOpts.coneSize = trace.sizeref;
}
coneOpts.coneSizemode = sizemode;

var meshData = conePlot(coneOpts);

Expand Down
4 changes: 2 additions & 2 deletions src/traces/cone/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
return;
}

coerce('sizeref');
coerce('sizemode');
var sizemode = coerce('sizemode');
coerce('sizeref', sizemode === 'raw' ? 1 : 0.5);

coerce('anchor');

Expand Down
7 changes: 5 additions & 2 deletions stackgl_modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13782,6 +13782,7 @@ module.exports = function(vectorfield, bounds) {
var positionVectors = [];
var vectorScale = Infinity;
var skipIt = false;
var vectorSizemode = vectorfield.coneSizemode === 'raw';
for (var i = 0; i < positions.length; i++) {
var p = positions[i];
minX = Math.min(p[0], minX);
Expand All @@ -13795,7 +13796,7 @@ module.exports = function(vectorfield, bounds) {
if (vec3.length(u) > maxNorm) {
maxNorm = vec3.length(u);
}
if (i) {
if (i && !vectorSizemode) {
// Find vector scale [w/ units of time] using "successive" positions
// (not "adjacent" with would be O(n^2)),
//
Expand Down Expand Up @@ -13834,7 +13835,9 @@ module.exports = function(vectorfield, bounds) {
}
geo.vectorScale = vectorScale;

var coneScale = vectorfield.coneSize || 0.5;
var coneScale = vectorfield.coneSize || (
vectorSizemode ? 1 :0.5
);

if (vectorfield.absoluteConeSize) {
coneScale = vectorfield.absoluteConeSize * invertedMaxNorm;
Expand Down
13 changes: 7 additions & 6 deletions stackgl_modules/package-lock.json

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

2 changes: 1 addition & 1 deletion stackgl_modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"box-intersect": "plotly/box-intersect#v1.1.0",
"convex-hull": "^1.0.3",
"delaunay-triangulate": "^1.1.6",
"gl-cone3d": "^1.5.2",
"gl-cone3d": "github:gl-vis/gl-cone3d#846764e2c95157fcfcf1ef264401c3cf665faaaa",
archmoj marked this conversation as resolved.
Show resolved Hide resolved
"gl-error3d": "^1.0.16",
"gl-heatmap2d": "^1.1.1",
"gl-line3d": "1.2.1",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions test/image/mocks/zz-gl3d_cone-sizemode_vector.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"data": [
{
"type": "cone",
"x": [1, 2, 3],
"y": [1, 2, 3],
"z": [1, 2, 3],
"u": [1, 0, 0],
"v": [0, 3, 0],
"w": [0, 0, 2],
"sizemode": "raw",
"anchor": "tip",
"colorbar": {
"title": { "text": "raw<br>sizeref: 1" },
"x": 0,
"xanchor": "right"
}
},
{
"type": "cone",
"x": [1, 2, 3],
"y": [1, 2, 3],
"z": [1, 2, 3],
"u": [0.5, 0, 0],
"v": [0, 1.5, 0],
"w": [0, 0, 1],
"sizemode": "raw",
"anchor": "tip",
"colorbar": {
"title": { "text": "rawr<br>sizeref: 1" }
},
"scene": "scene2"
}
],
"layout": {
"scene": {
"domain": {"x": [0, 0.5]},
"aspectratio": {
"x": 1.5,
"y": 1.5,
"z": 1.5
},
"camera": {
"projection": {"type": "orthographic"},
"up": {"x": 0, "y": 1, "z": 0},
"eye": {"x": 0, "y": 0, "z": 3}
}
},
"scene2": {
"domain": {"x": [0.5, 1]},
"aspectratio": {
"x": 1.5,
"y": 1.5,
"z": 1.5
},
"camera": {
"projection": {"type": "orthographic"},
"up": {"x": 0, "y": 1, "z": 0},
"eye": {"x": 0, "y": 0, "z": 3}
}
},
"width": 1000,
"height": 500
}
}
67 changes: 67 additions & 0 deletions test/image/mocks/zz-gl3d_cone-sizemode_vector2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"data": [
{
"type": "cone",
"x": [1, 2, 3],
"y": [1, 2, 3],
"z": [1, 2, 3],
"u": [1, 0, 0],
"v": [0, 3, 0],
"w": [0, 0, 2],
"sizemode": "raw",
"anchor": "tip",
"sizeref": 0.5,
"colorbar": {
"title": { "text": "raw<br>sizeref: 2" },
"x": 0,
"xanchor": "right"
}
},
{
"type": "cone",
"x": [1, 2, 3],
"y": [1, 2, 3],
"z": [1, 2, 3],
"u": [0.5, 0, 0],
"v": [0, 1.5, 0],
"w": [0, 0, 1],
"sizemode": "raw",
"anchor": "tip",
"sizeref": 2,
"colorbar": {
"title": { "text": "raw<br>sizeref: 2" }
},
"scene": "scene2"
}
],
"layout": {
"scene": {
"domain": {"x": [0, 0.5]},
"aspectratio": {
"x": 1.5,
"y": 1.5,
"z": 1.5
},
"camera": {
"projection": {"type": "orthographic"},
"up": {"x": 0, "y": 1, "z": 0},
"eye": {"x": 0, "y": 0, "z": 3}
}
},
"scene2": {
"domain": {"x": [0.5, 1]},
"aspectratio": {
"x": 1.5,
"y": 1.5,
"z": 1.5
},
"camera": {
"projection": {"type": "orthographic"},
"up": {"x": 0, "y": 1, "z": 0},
"eye": {"x": 0, "y": 0, "z": 3}
}
},
"width": 1000,
"height": 500
}
}
Loading