-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathlayout_defaults.js
58 lines (45 loc) · 1.77 KB
/
layout_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
/**
* 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 Registry = require('../../registry');
var Axes = require('../../plots/cartesian/axes');
var Lib = require('../../lib');
var layoutAttributes = require('./layout_attributes');
module.exports = function(layoutIn, layoutOut, fullData) {
function coerce(attr, dflt) {
return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);
}
var hasBars = false;
var shouldBeGapless = false;
var gappedAnyway = false;
var usedSubplots = {};
for(var i = 0; i < fullData.length; i++) {
var trace = fullData[i];
if((Registry.traceIs(trace, 'bar') ||
Registry.traceIs(trace, 'waterfall')) &&
trace.visible) hasBars = true;
else continue;
// if we have at least 2 grouped bar traces on the same subplot,
// we should default to a gap anyway, even if the data is histograms
if(layoutIn.barmode !== 'overlay' && layoutIn.barmode !== 'stack') {
var subploti = trace.xaxis + trace.yaxis;
if(usedSubplots[subploti]) gappedAnyway = true;
usedSubplots[subploti] = true;
}
if(trace.visible && trace.type === 'histogram') {
var pa = Axes.getFromId({_fullLayout: layoutOut},
trace[trace.orientation === 'v' ? 'xaxis' : 'yaxis']);
if(pa.type !== 'category') shouldBeGapless = true;
}
}
if(!hasBars) return;
var mode = coerce('barmode');
if(mode !== 'overlay') coerce('barnorm');
coerce('bargap', (shouldBeGapless && !gappedAnyway) ? 0 : 0.2);
coerce('bargroupgap');
};