-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathmarker_defaults.js
More file actions
82 lines (68 loc) · 2.65 KB
/
marker_defaults.js
File metadata and controls
82 lines (68 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
var Color = require('../../components/color');
var hasColorscale = require('../../components/colorscale/helpers').hasColorscale;
var colorscaleDefaults = require('../../components/colorscale/defaults');
var subTypes = require('./subtypes');
/*
* opts: object of flags to control features not all marker users support
* noLine: caller does not support marker lines
* gradient: caller supports gradients
* noSelect: caller does not support selected/unselected attribute containers
*/
module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout, coerce, opts) {
var isBubble = subTypes.isBubble(traceIn);
var lineColor = (traceIn.line || {}).color;
var defaultMLC;
opts = opts || {};
// marker.color inherit from line.color (even if line.color is an array)
if(lineColor) defaultColor = lineColor;
coerce('marker.symbol');
coerce('marker.opacity', isBubble ? 0.7 : 1);
coerce('marker.size');
if(!opts.noAngle) {
coerce('marker.angle');
if(!opts.noAngleRef) {
coerce('marker.angleref');
}
if(!opts.noStandOff) {
coerce('marker.standoff');
}
}
coerce('marker.color', defaultColor);
if(hasColorscale(traceIn, 'marker')) {
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'});
}
if(!opts.noSelect) {
coerce('selected.marker.color');
coerce('unselected.marker.color');
coerce('selected.marker.size');
coerce('unselected.marker.size');
}
if(!opts.noLine) {
// if there's a line with a different color than the marker, use
// that line color as the default marker line color
// (except when it's an array)
// mostly this is for transparent markers to behave nicely
if(lineColor && !Array.isArray(lineColor) && (traceOut.marker.color !== lineColor)) {
defaultMLC = lineColor;
} else if(isBubble) defaultMLC = Color.background;
else defaultMLC = Color.defaultLine;
coerce('marker.line.color', defaultMLC);
if(hasColorscale(traceIn, 'marker.line')) {
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'marker.line.', cLetter: 'c'});
}
coerce('marker.line.width', isBubble ? 1 : 0);
coerce('marker.line.dash');
}
if(isBubble) {
coerce('marker.sizeref');
coerce('marker.sizemin');
coerce('marker.sizemode');
}
if(opts.gradient) {
var gradientType = coerce('marker.gradient.type');
if(gradientType !== 'none') {
coerce('marker.gradient.color');
}
}
};