Skip to content

Commit 94177e0

Browse files
committed
add marker.angle to gl2d traces
1 parent 1a27d5f commit 94177e0

File tree

13 files changed

+112
-33
lines changed

13 files changed

+112
-33
lines changed

src/components/drawing/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1557,3 +1557,5 @@ function getMarkerAngle(d, trace) {
15571557

15581558
return angle;
15591559
}
1560+
1561+
drawing.getMarkerAngle = getMarkerAngle;

src/traces/scatter/marker_defaults.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout
2727
coerce('marker.size');
2828
if(!opts.noAngle) {
2929
coerce('marker.angle');
30-
coerce('marker.angleref');
30+
if(!opts.noAngleRef) {
31+
coerce('marker.angleref');
32+
}
3133
}
3234

3335
coerce('marker.color', defaultColor);

src/traces/scattergl/attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ var attrs = module.exports = overrideAll({
6767
},
6868
marker: extendFlat({}, colorScaleAttrs('marker'), {
6969
symbol: scatterMarkerAttrs.symbol,
70+
angle: scatterMarkerAttrs.angle,
7071
size: scatterMarkerAttrs.size,
7172
sizeref: scatterMarkerAttrs.sizeref,
7273
sizemin: scatterMarkerAttrs.sizemin,

src/traces/scattergl/calc.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ var TOO_MANY_POINTS = require('./constants').TOO_MANY_POINTS;
2020

2121
module.exports = function calc(gd, trace) {
2222
var fullLayout = gd._fullLayout;
23-
var xa = AxisIDs.getFromId(gd, trace.xaxis);
24-
var ya = AxisIDs.getFromId(gd, trace.yaxis);
23+
var xa = trace._xA = AxisIDs.getFromId(gd, trace.xaxis, 'x');
24+
var ya = trace._yA = AxisIDs.getFromId(gd, trace.yaxis, 'y');
25+
2526
var subplot = fullLayout._plots[trace.xaxis + trace.yaxis];
2627
var len = trace._length;
2728
var hasTooManyPoints = len >= TOO_MANY_POINTS;

src/traces/scattergl/convert.js

+52-23
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ function convertStyle(gd, trace) {
5050
}
5151

5252
if(subTypes.hasMarkers(trace)) {
53-
opts.marker = convertMarkerStyle(trace);
54-
opts.markerSel = convertMarkerSelection(trace, trace.selected);
55-
opts.markerUnsel = convertMarkerSelection(trace, trace.unselected);
53+
opts.marker = convertMarkerStyle(gd, trace);
54+
opts.markerSel = convertMarkerSelection(gd, trace, trace.selected);
55+
opts.markerUnsel = convertMarkerSelection(gd, trace, trace.unselected);
5656

5757
if(!trace.unselected && Lib.isArrayOrTypedArray(trace.marker.opacity)) {
5858
var mo = trace.marker.opacity;
@@ -207,13 +207,14 @@ function convertTextStyle(gd, trace) {
207207
}
208208

209209

210-
function convertMarkerStyle(trace) {
210+
function convertMarkerStyle(gd, trace) {
211211
var count = trace._length;
212212
var optsIn = trace.marker;
213213
var optsOut = {};
214214
var i;
215215

216216
var multiSymbol = Lib.isArrayOrTypedArray(optsIn.symbol);
217+
var multiAngle = Lib.isArrayOrTypedArray(optsIn.angle);
217218
var multiColor = Lib.isArrayOrTypedArray(optsIn.color);
218219
var multiLineColor = Lib.isArrayOrTypedArray(optsIn.line.color);
219220
var multiOpacity = Lib.isArrayOrTypedArray(optsIn.opacity);
@@ -224,10 +225,14 @@ function convertMarkerStyle(trace) {
224225
if(!multiSymbol) isOpen = helpers.isOpenSymbol(optsIn.symbol);
225226

226227
// prepare colors
227-
if(multiSymbol || multiColor || multiLineColor || multiOpacity) {
228+
if(multiSymbol || multiColor || multiLineColor || multiOpacity || multiAngle) {
229+
optsOut.symbols = new Array(count);
230+
optsOut.angles = new Array(count);
228231
optsOut.colors = new Array(count);
229232
optsOut.borderColors = new Array(count);
230233

234+
var symbols = optsIn.symbol;
235+
var angles = optsIn.angle;
231236
var colors = formatColor(optsIn, optsIn.opacity, count);
232237
var borderColors = formatColor(optsIn.line, optsIn.opacity, count);
233238

@@ -245,14 +250,29 @@ function convertMarkerStyle(trace) {
245250
colors[i] = color;
246251
}
247252
}
253+
if(!Array.isArray(symbols)) {
254+
var symbol = symbols;
255+
symbols = Array(count);
256+
for(i = 0; i < count; i++) {
257+
symbols[i] = symbol;
258+
}
259+
}
260+
if(!Array.isArray(angles)) {
261+
var angle = angles;
262+
angles = Array(count);
263+
for(i = 0; i < count; i++) {
264+
angles[i] = angle;
265+
}
266+
}
248267

268+
optsOut.symbols = symbols;
269+
optsOut.angles = angles;
249270
optsOut.colors = colors;
250271
optsOut.borderColors = borderColors;
251272

252273
for(i = 0; i < count; i++) {
253274
if(multiSymbol) {
254-
var symbol = optsIn.symbol[i];
255-
isOpen = helpers.isOpenSymbol(symbol);
275+
isOpen = helpers.isOpenSymbol(optsIn.symbol[i]);
256276
}
257277
if(isOpen) {
258278
borderColors[i] = colors[i].slice();
@@ -262,6 +282,14 @@ function convertMarkerStyle(trace) {
262282
}
263283

264284
optsOut.opacity = trace.opacity;
285+
286+
optsOut.markers = new Array(count);
287+
for(i = 0; i < count; i++) {
288+
optsOut.markers[i] = getSymbolSdf({
289+
mx: optsOut.symbols[i],
290+
ma: optsOut.angles[i]
291+
}, trace);
292+
}
265293
} else {
266294
if(isOpen) {
267295
optsOut.color = rgba(optsIn.color, 'uint8');
@@ -273,16 +301,11 @@ function convertMarkerStyle(trace) {
273301
}
274302

275303
optsOut.opacity = trace.opacity * optsIn.opacity;
276-
}
277304

278-
// prepare symbols
279-
if(multiSymbol) {
280-
optsOut.markers = new Array(count);
281-
for(i = 0; i < count; i++) {
282-
optsOut.markers[i] = getSymbolSdf(optsIn.symbol[i]);
283-
}
284-
} else {
285-
optsOut.marker = getSymbolSdf(optsIn.symbol);
305+
optsOut.marker = getSymbolSdf({
306+
mx: optsIn.symbol,
307+
ma: optsIn.angle
308+
}, trace);
286309
}
287310

288311
// prepare sizes
@@ -330,14 +353,14 @@ function convertMarkerStyle(trace) {
330353
return optsOut;
331354
}
332355

333-
function convertMarkerSelection(trace, target) {
356+
function convertMarkerSelection(gd, trace, target) {
334357
var optsIn = trace.marker;
335358
var optsOut = {};
336359

337360
if(!target) return optsOut;
338361

339362
if(target.marker && target.marker.symbol) {
340-
optsOut = convertMarkerStyle(Lib.extendFlat({}, optsIn, target.marker));
363+
optsOut = convertMarkerStyle(gd, Lib.extendFlat({}, optsIn, target.marker));
341364
} else if(target.marker) {
342365
if(target.marker.size) optsOut.size = target.marker.size;
343366
if(target.marker.color) optsOut.colors = target.marker.color;
@@ -389,7 +412,8 @@ var SYMBOL_STROKE = constants.SYMBOL_STROKE;
389412
var SYMBOL_SDF = {};
390413
var SYMBOL_SVG_CIRCLE = Drawing.symbolFuncs[0](SYMBOL_SIZE * 0.05);
391414

392-
function getSymbolSdf(symbol) {
415+
function getSymbolSdf(d, trace) {
416+
var symbol = d.mx;
393417
if(symbol === 'circle') return null;
394418

395419
var symbolPath, symbolSdf;
@@ -400,13 +424,17 @@ function getSymbolSdf(symbol) {
400424

401425
var isDot = helpers.isDotSymbol(symbol);
402426

427+
// until we may handle angles in shader?
428+
if(d.ma) symbol += '_' + d.ma;
429+
403430
// get symbol sdf from cache or generate it
404431
if(SYMBOL_SDF[symbol]) return SYMBOL_SDF[symbol];
405432

433+
var angle = Drawing.getMarkerAngle(d, trace);
406434
if(isDot && !symbolNoDot) {
407-
symbolPath = symbolFunc(SYMBOL_SIZE * 1.1) + SYMBOL_SVG_CIRCLE;
435+
symbolPath = symbolFunc(SYMBOL_SIZE * 1.1, angle) + SYMBOL_SVG_CIRCLE;
408436
} else {
409-
symbolPath = symbolFunc(SYMBOL_SIZE);
437+
symbolPath = symbolFunc(SYMBOL_SIZE, angle);
410438
}
411439

412440
symbolSdf = svgSdf(symbolPath, {
@@ -415,6 +443,7 @@ function getSymbolSdf(symbol) {
415443
viewBox: [-SYMBOL_SIZE, -SYMBOL_SIZE, SYMBOL_SIZE, SYMBOL_SIZE],
416444
stroke: symbolNoFill ? SYMBOL_STROKE : -SYMBOL_STROKE
417445
});
446+
418447
SYMBOL_SDF[symbol] = symbolSdf;
419448

420449
return symbolSdf || null;
@@ -545,8 +574,8 @@ function convertLinePositions(gd, trace, positions) {
545574

546575
function convertErrorBarPositions(gd, trace, positions, x, y) {
547576
var makeComputeError = Registry.getComponentMethod('errorbars', 'makeComputeError');
548-
var xa = AxisIDs.getFromId(gd, trace.xaxis);
549-
var ya = AxisIDs.getFromId(gd, trace.yaxis);
577+
var xa = AxisIDs.getFromId(gd, trace.xaxis, 'x');
578+
var ya = AxisIDs.getFromId(gd, trace.yaxis, 'y');
550579
var count = positions.length / 2;
551580
var out = {};
552581

src/traces/scattergl/defaults.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
4646
}
4747

4848
if(subTypes.hasMarkers(traceOut)) {
49-
handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {noAngle: true});
49+
handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {noAngleRef: true});
5050
coerce('marker.line.width', isOpen || isBubble ? 1 : 0);
5151
}
5252

src/traces/scattergl/hover.js

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ function calcHover(pointData, x, y, trace) {
139139
di.ms = Lib.isArrayOrTypedArray(marker.size) ? marker.size[id] : marker.size;
140140
di.mo = Lib.isArrayOrTypedArray(marker.opacity) ? marker.opacity[id] : marker.opacity;
141141
di.mx = Lib.isArrayOrTypedArray(marker.symbol) ? marker.symbol[id] : marker.symbol;
142+
di.ma = Lib.isArrayOrTypedArray(marker.angle) ? marker.angle[id] : marker.angle;
142143
di.mc = Lib.isArrayOrTypedArray(marker.color) ? marker.color[id] : marker.color;
143144
}
144145

src/traces/scatterpolargl/defaults.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3535
}
3636

3737
if(subTypes.hasMarkers(traceOut)) {
38-
handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {noAngle: true});
38+
handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {noAngleRef: true});
3939
}
4040

4141
if(subTypes.hasText(traceOut)) {

src/traces/splom/attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var markerLineAttrs = extendFlat(colorScaleAttrs('marker.line', {editTypeOverrid
1919

2020
var markerAttrs = extendFlat(colorScaleAttrs('marker'), {
2121
symbol: scatterMarkerAttrs.symbol,
22+
angle: scatterMarkerAttrs.angle,
2223
size: extendFlat({}, scatterMarkerAttrs.size, {editType: 'markerSize'}),
2324
sizeref: scatterMarkerAttrs.sizeref,
2425
sizemin: scatterMarkerAttrs.sizemin,

src/traces/splom/calc.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module.exports = function calc(gd, trace) {
6767
}
6868

6969
calcColorscale(gd, trace);
70-
Lib.extendFlat(opts, convertMarkerStyle(trace));
70+
Lib.extendFlat(opts, convertMarkerStyle(gd, trace));
7171

7272
var visibleLength = cdata.length;
7373
var hasTooManyPoints = (visibleLength * commonLength) > TOO_MANY_POINTS;
@@ -94,8 +94,8 @@ module.exports = function calc(gd, trace) {
9494
if(!scene.matrix) scene.matrix = true;
9595
scene.matrixOptions = opts;
9696

97-
scene.selectedOptions = convertMarkerSelection(trace, trace.selected);
98-
scene.unselectedOptions = convertMarkerSelection(trace, trace.unselected);
97+
scene.selectedOptions = convertMarkerSelection(gd, trace, trace.selected);
98+
scene.unselectedOptions = convertMarkerSelection(gd, trace, trace.unselected);
9999

100100
return [{x: false, y: false, t: {}, trace: trace}];
101101
};

src/traces/splom/defaults.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3636
coerce('xhoverformat');
3737
coerce('yhoverformat');
3838

39-
handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {noAngle: true});
39+
handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {noAngleRef: true});
4040

4141
var isOpen = isOpenSymbol(traceOut.marker.symbol);
4242
var isBubble = subTypes.isBubble(traceOut);

src/traces/splom/edit_style.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = function editStyle(gd, cd0) {
1111
if(scene) {
1212
calcColorscale(gd, trace);
1313

14-
Lib.extendFlat(scene.matrixOptions, convertMarkerStyle(trace));
14+
Lib.extendFlat(scene.matrixOptions, convertMarkerStyle(gd, trace));
1515
// TODO [un]selected styles?
1616

1717
var opts = Lib.extendFlat({}, scene.matrixOptions, scene.viewOpts);

test/plot-schema.json

+42
Original file line numberDiff line numberDiff line change
@@ -51488,6 +51488,20 @@
5148851488
}
5148951489
},
5149051490
"marker": {
51491+
"angle": {
51492+
"arrayOk": true,
51493+
"description": "Sets the marker angle in respect to `angleref`.",
51494+
"dflt": 0,
51495+
"editType": "calc",
51496+
"max": 360,
51497+
"min": -360,
51498+
"valType": "number"
51499+
},
51500+
"anglesrc": {
51501+
"description": "Sets the source reference on Chart Studio Cloud for `angle`.",
51502+
"editType": "none",
51503+
"valType": "string"
51504+
},
5149151505
"autocolorscale": {
5149251506
"description": "Determines whether the colorscale is a default palette (`autocolorscale: true`) or the palette determined by `marker.colorscale`. Has an effect only if in `marker.color` is set to a numerical array. In case `colorscale` is unspecified or `autocolorscale` is true, the default palette will be chosen according to whether numbers in the `color` array are all positive, all negative or mixed.",
5149351507
"dflt": true,
@@ -56443,6 +56457,20 @@
5644356457
}
5644456458
},
5644556459
"marker": {
56460+
"angle": {
56461+
"arrayOk": true,
56462+
"description": "Sets the marker angle in respect to `angleref`.",
56463+
"dflt": 0,
56464+
"editType": "calc",
56465+
"max": 360,
56466+
"min": -360,
56467+
"valType": "number"
56468+
},
56469+
"anglesrc": {
56470+
"description": "Sets the source reference on Chart Studio Cloud for `angle`.",
56471+
"editType": "none",
56472+
"valType": "string"
56473+
},
5644656474
"autocolorscale": {
5644756475
"description": "Determines whether the colorscale is a default palette (`autocolorscale: true`) or the palette determined by `marker.colorscale`. Has an effect only if in `marker.color` is set to a numerical array. In case `colorscale` is unspecified or `autocolorscale` is true, the default palette will be chosen according to whether numbers in the `color` array are all positive, all negative or mixed.",
5644856476
"dflt": true,
@@ -61978,6 +62006,20 @@
6197862006
"valType": "number"
6197962007
},
6198062008
"marker": {
62009+
"angle": {
62010+
"arrayOk": true,
62011+
"description": "Sets the marker angle in respect to `angleref`.",
62012+
"dflt": 0,
62013+
"editType": "plot",
62014+
"max": 360,
62015+
"min": -360,
62016+
"valType": "number"
62017+
},
62018+
"anglesrc": {
62019+
"description": "Sets the source reference on Chart Studio Cloud for `angle`.",
62020+
"editType": "none",
62021+
"valType": "string"
62022+
},
6198162023
"autocolorscale": {
6198262024
"description": "Determines whether the colorscale is a default palette (`autocolorscale: true`) or the palette determined by `marker.colorscale`. Has an effect only if in `marker.color` is set to a numerical array. In case `colorscale` is unspecified or `autocolorscale` is true, the default palette will be chosen according to whether numbers in the `color` array are all positive, all negative or mixed.",
6198362025
"dflt": true,

0 commit comments

Comments
 (0)