-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathdefaults.js
118 lines (94 loc) · 3.52 KB
/
defaults.js
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* Copyright 2012-2019, 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 Lib = require('../../lib');
var attributes = require('./attributes');
var Color = require('../../components/color');
var handleDomainDefaults = require('../../plots/domain').defaults;
var handleText = require('../bar/defaults').handleText;
var TEXTPAD = require('../bar/constants').TEXTPAD;
var Colorscale = require('../../components/colorscale');
var hasColorscale = Colorscale.hasColorscale;
var colorscaleDefaults = Colorscale.handleDefaults;
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}
var labels = coerce('labels');
var parents = coerce('parents');
if(!labels || !labels.length || !parents || !parents.length) {
traceOut.visible = false;
return;
}
var vals = coerce('values');
if(vals && vals.length) {
coerce('branchvalues');
} else {
coerce('count');
}
coerce('level');
coerce('maxdepth');
var packing = coerce('tiling.packing');
if(packing === 'squarify') {
coerce('tiling.squarifyratio');
}
coerce('tiling.flip');
coerce('tiling.pad');
var text = coerce('text');
coerce('texttemplate');
if(!traceOut.texttemplate) coerce('textinfo', Array.isArray(text) ? 'text+label' : 'label');
coerce('hovertext');
coerce('hovertemplate');
var textposition = 'auto';
handleText(traceIn, traceOut, layout, coerce, textposition, {
moduleHasSelected: false,
moduleHasUnselected: false,
moduleHasConstrain: false,
moduleHasCliponaxis: false,
moduleHasTextangle: false,
moduleHasInsideanchor: false
});
coerce('textposition');
var bottomText = traceOut.textposition.indexOf('bottom') !== -1;
var lineWidth = coerce('marker.line.width');
if(lineWidth) coerce('marker.line.color', layout.paper_bgcolor);
var colors = coerce('marker.colors');
var withColorscale = traceOut._hasColorscale = hasColorscale(traceIn, 'marker', 'colors');
if(withColorscale) {
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'});
} else {
coerce('marker.depthfade', !(colors || []).length);
}
var headerSize = traceOut.textfont.size * 2;
coerce('marker.pad.t', bottomText ? headerSize / 4 : headerSize);
coerce('marker.pad.l', headerSize / 4);
coerce('marker.pad.r', headerSize / 4);
coerce('marker.pad.b', bottomText ? headerSize : headerSize / 4);
if(withColorscale) {
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'});
}
traceOut._hovered = {
marker: {
line: {
width: 2,
color: Color.contrast(layout.paper_bgcolor)
}
}
};
var hasPathbar = coerce('pathbar.visible');
if(hasPathbar) {
Lib.coerceFont(coerce, 'pathbar.textfont', layout.font);
// This works even for multi-line labels as treemap pathbar trim out line breaks
coerce('pathbar.thickness', traceOut.pathbar.textfont.size + 2 * TEXTPAD);
coerce('pathbar.side');
coerce('pathbar.edgeshape');
}
handleDomainDefaults(traceOut, layout, coerce);
// do not support transforms for now
traceOut._length = null;
};