Skip to content

Commit 33b7e8c

Browse files
authored
Merge pull request #6938 from plotly/cone-sizemode-vector
Add "raw" `sizemode` to cone trace
2 parents e555e1d + 65da347 commit 33b7e8c

14 files changed

+390
-20
lines changed

Diff for: draftlogs/6938_add.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Add "raw" sizemode to cone trace [[#6938](https://github.com/plotly/plotly.js/pull/6938)]
2+

Diff for: src/traces/cone/attributes.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,14 @@ var attrs = {
9696

9797
sizemode: {
9898
valType: 'enumerated',
99-
values: ['scaled', 'absolute'],
99+
values: ['scaled', 'absolute', 'raw'],
100100
editType: 'calc',
101101
dflt: 'scaled',
102102
description: [
103103
'Determines whether `sizeref` is set as a *scaled* (i.e unitless) scalar',
104104
'(normalized by the max u/v/w norm in the vector field) or as',
105-
'*absolute* value (in the same units as the vector field).'
105+
'*absolute* value (in the same units as the vector field).',
106+
'To display sizes in actual vector length use *raw*.'
106107
].join(' ')
107108
},
108109
sizeref: {
@@ -115,7 +116,8 @@ var attrs = {
115116
'This factor (computed internally) corresponds to the minimum "time" to travel across',
116117
'two successive x/y/z positions at the average velocity of those two successive positions.',
117118
'All cones in a given trace use the same factor.',
118-
'With `sizemode` set to *scaled*, `sizeref` is unitless, its default value is *0.5*',
119+
'With `sizemode` set to *raw*, its default value is *1*.',
120+
'With `sizemode` set to *scaled*, `sizeref` is unitless, its default value is *0.5*.',
119121
'With `sizemode` set to *absolute*, `sizeref` has the same units as the u/v/w vector field,',
120122
'its the default value is half the sample\'s maximum vector norm.'
121123
].join(' ')

Diff for: src/traces/cone/convert.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,20 @@ function convert(scene, trace) {
7979
coneOpts.vertexIntensityBounds = [cOpts.min / trace._normMax, cOpts.max / trace._normMax];
8080
coneOpts.coneOffset = anchor2coneOffset[trace.anchor];
8181

82-
if(trace.sizemode === 'scaled') {
82+
83+
var sizemode = trace.sizemode;
84+
if(sizemode === 'scaled') {
8385
// unitless sizeref
8486
coneOpts.coneSize = trace.sizeref || 0.5;
85-
} else {
87+
} else if(sizemode === 'absolute') {
8688
// sizeref here has unit of velocity
8789
coneOpts.coneSize = trace.sizeref && trace._normMax ?
8890
trace.sizeref / trace._normMax :
8991
0.5;
92+
} else if(sizemode === 'raw') {
93+
coneOpts.coneSize = trace.sizeref;
9094
}
95+
coneOpts.coneSizemode = sizemode;
9196

9297
var meshData = conePlot(coneOpts);
9398

Diff for: src/traces/cone/defaults.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2626
return;
2727
}
2828

29-
coerce('sizeref');
30-
coerce('sizemode');
29+
var sizemode = coerce('sizemode');
30+
coerce('sizeref', sizemode === 'raw' ? 1 : 0.5);
3131

3232
coerce('anchor');
3333

Diff for: stackgl_modules/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -13782,6 +13782,7 @@ module.exports = function(vectorfield, bounds) {
1378213782
var positionVectors = [];
1378313783
var vectorScale = Infinity;
1378413784
var skipIt = false;
13785+
var rawSizemodemode = vectorfield.coneSizemode === 'raw';
1378513786
for (var i = 0; i < positions.length; i++) {
1378613787
var p = positions[i];
1378713788
minX = Math.min(p[0], minX);
@@ -13795,7 +13796,7 @@ module.exports = function(vectorfield, bounds) {
1379513796
if (vec3.length(u) > maxNorm) {
1379613797
maxNorm = vec3.length(u);
1379713798
}
13798-
if (i) {
13799+
if (i && !rawSizemodemode) {
1379913800
// Find vector scale [w/ units of time] using "successive" positions
1380013801
// (not "adjacent" with would be O(n^2)),
1380113802
//
@@ -13834,7 +13835,9 @@ module.exports = function(vectorfield, bounds) {
1383413835
}
1383513836
geo.vectorScale = vectorScale;
1383613837

13837-
var coneScale = vectorfield.coneSize || 0.5;
13838+
var coneScale = vectorfield.coneSize || (
13839+
rawSizemodemode ? 1 :0.5
13840+
);
1383813841

1383913842
if (vectorfield.absoluteConeSize) {
1384013843
coneScale = vectorfield.absoluteConeSize * invertedMaxNorm;

Diff for: stackgl_modules/package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: stackgl_modules/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"box-intersect": "plotly/box-intersect#v1.1.0",
1414
"convex-hull": "^1.0.3",
1515
"delaunay-triangulate": "^1.1.6",
16-
"gl-cone3d": "^1.5.2",
16+
"gl-cone3d": "^1.6.0",
1717
"gl-error3d": "^1.0.16",
1818
"gl-heatmap2d": "^1.1.1",
1919
"gl-line3d": "1.2.1",
38.7 KB
Loading
38.5 KB
Loading
88.4 KB
Loading

Diff for: test/image/mocks/zz-gl3d_cone-sizemode_vector.json

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"data": [
3+
{
4+
"type": "cone",
5+
"x": [1, 2, 3],
6+
"y": [1, 2, 3],
7+
"z": [1, 2, 3],
8+
"u": [1, 0, 0],
9+
"v": [0, 3, 0],
10+
"w": [0, 0, 2],
11+
"sizemode": "raw",
12+
"anchor": "tip",
13+
"colorbar": {
14+
"title": { "text": "raw<br>sizeref: 1" },
15+
"x": 0,
16+
"xanchor": "right"
17+
}
18+
},
19+
{
20+
"type": "cone",
21+
"x": [1, 2, 3],
22+
"y": [1, 2, 3],
23+
"z": [1, 2, 3],
24+
"u": [0.5, 0, 0],
25+
"v": [0, 1.5, 0],
26+
"w": [0, 0, 1],
27+
"sizemode": "raw",
28+
"anchor": "tip",
29+
"colorbar": {
30+
"title": { "text": "rawr<br>sizeref: 1" }
31+
},
32+
"scene": "scene2"
33+
}
34+
],
35+
"layout": {
36+
"scene": {
37+
"domain": {"x": [0, 0.5]},
38+
"aspectratio": {
39+
"x": 1.5,
40+
"y": 1.5,
41+
"z": 1.5
42+
},
43+
"camera": {
44+
"projection": {"type": "orthographic"},
45+
"up": {"x": 0, "y": 1, "z": 0},
46+
"eye": {"x": 0, "y": 0, "z": 3}
47+
}
48+
},
49+
"scene2": {
50+
"domain": {"x": [0.5, 1]},
51+
"aspectratio": {
52+
"x": 1.5,
53+
"y": 1.5,
54+
"z": 1.5
55+
},
56+
"camera": {
57+
"projection": {"type": "orthographic"},
58+
"up": {"x": 0, "y": 1, "z": 0},
59+
"eye": {"x": 0, "y": 0, "z": 3}
60+
}
61+
},
62+
"width": 1000,
63+
"height": 500
64+
}
65+
}

Diff for: test/image/mocks/zz-gl3d_cone-sizemode_vector2.json

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"data": [
3+
{
4+
"type": "cone",
5+
"x": [1, 2, 3],
6+
"y": [1, 2, 3],
7+
"z": [1, 2, 3],
8+
"u": [1, 0, 0],
9+
"v": [0, 3, 0],
10+
"w": [0, 0, 2],
11+
"sizemode": "raw",
12+
"anchor": "tip",
13+
"sizeref": 0.5,
14+
"colorbar": {
15+
"title": { "text": "raw<br>sizeref: 2" },
16+
"x": 0,
17+
"xanchor": "right"
18+
}
19+
},
20+
{
21+
"type": "cone",
22+
"x": [1, 2, 3],
23+
"y": [1, 2, 3],
24+
"z": [1, 2, 3],
25+
"u": [0.5, 0, 0],
26+
"v": [0, 1.5, 0],
27+
"w": [0, 0, 1],
28+
"sizemode": "raw",
29+
"anchor": "tip",
30+
"sizeref": 2,
31+
"colorbar": {
32+
"title": { "text": "raw<br>sizeref: 2" }
33+
},
34+
"scene": "scene2"
35+
}
36+
],
37+
"layout": {
38+
"scene": {
39+
"domain": {"x": [0, 0.5]},
40+
"aspectratio": {
41+
"x": 1.5,
42+
"y": 1.5,
43+
"z": 1.5
44+
},
45+
"camera": {
46+
"projection": {"type": "orthographic"},
47+
"up": {"x": 0, "y": 1, "z": 0},
48+
"eye": {"x": 0, "y": 0, "z": 3}
49+
}
50+
},
51+
"scene2": {
52+
"domain": {"x": [0.5, 1]},
53+
"aspectratio": {
54+
"x": 1.5,
55+
"y": 1.5,
56+
"z": 1.5
57+
},
58+
"camera": {
59+
"projection": {"type": "orthographic"},
60+
"up": {"x": 0, "y": 1, "z": 0},
61+
"eye": {"x": 0, "y": 0, "z": 3}
62+
}
63+
},
64+
"width": 1000,
65+
"height": 500
66+
}
67+
}

0 commit comments

Comments
 (0)