Skip to content

Commit aec946e

Browse files
committed
revisions after etpinard comments
1 parent 424d6f5 commit aec946e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+705
-248
lines changed

src/components/legend/style.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,12 @@ module.exports = function style(s, gd) {
319319
var marker = trace.marker || {};
320320
var markerLine = marker.line || {};
321321

322-
var selection = (!desiredType) ? Registry.traceIs(trace, 'bar') :
322+
var isVisible = (!desiredType) ? Registry.traceIs(trace, 'bar') :
323323
(trace.type === desiredType && trace.visible);
324324

325325
var barpath = d3.select(lThis).select('g.legendpoints')
326326
.selectAll('path.legend' + desiredType)
327-
.data(selection ? [d] : []);
327+
.data(isVisible ? [d] : []);
328328
barpath.enter().append('path').classed('legend' + desiredType, true)
329329
.attr('d', 'M6,6H-6V-6H6Z')
330330
.attr('transform', 'translate(20,0)');

src/plot_api/helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ exports.cleanData = function(data) {
328328
trace.scene = Plots.subplotsRegistry.gl3d.cleanId(trace.scene);
329329
}
330330

331-
if(!traceIs(trace, 'pie') && !traceIs(trace, 'bar') && trace.type !== 'waterfall' && trace.type !== 'funnel') {
331+
if(!traceIs(trace, 'pie') && !traceIs(trace, 'bar-like')) {
332332
if(Array.isArray(trace.textposition)) {
333333
for(i = 0; i < trace.textposition.length; i++) {
334334
trace.textposition[i] = cleanTextPosition(trace.textposition[i]);

src/plots/cartesian/axes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,7 @@ axes.drawOne = function(gd, ax, opts) {
16471647
vals[i].axInfo = axInfo;
16481648
}
16491649

1650-
if(!ax.visible || ax._hide) return;
1650+
if(!ax.visible) return;
16511651

16521652
// stash selections to avoid DOM queries e.g.
16531653
// - stash tickLabels selection, so that drawTitle can use it to scoot title
@@ -2813,7 +2813,7 @@ function hasBarsOrFill(gd, ax) {
28132813

28142814
if(trace.visible === true && (trace.xaxis + trace.yaxis) === subplot) {
28152815
if(
2816-
(Registry.traceIs(trace, 'bar') || trace.type === 'waterfall' || trace.type === 'funnel') &&
2816+
Registry.traceIs(trace, 'bar-like') &&
28172817
trace.orientation === {x: 'h', y: 'v'}[axLetter]
28182818
) return true;
28192819

src/plots/cartesian/axis_defaults.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
3737
var font = options.font || {};
3838
var splomStash = options.splomStash || {};
3939

40-
var visible = coerce('visible', !options.cheateronly);
40+
var visible = coerce('visible', !options.visibleDflt);
4141

4242
var axType = containerOut.type;
4343

src/plots/cartesian/constants.js

+7
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ module.exports = {
7373
'scattercarpetlayer', 'scatterlayer'
7474
],
7575

76+
clipOnAxisFalseQuery: [
77+
'.scatterlayer',
78+
'.barlayer',
79+
'.funnellayer',
80+
'.waterfalllayer'
81+
],
82+
7683
layerValue2layerClass: {
7784
'above traces': 'above',
7885
'below traces': 'below'

src/plots/cartesian/index.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,7 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
260260
);
261261

262262
// layers that allow `cliponaxis: false`
263-
if(className !== 'scatterlayer' &&
264-
className !== 'barlayer' &&
265-
className !== 'funnellayer' &&
266-
className !== 'waterfalllayer') {
263+
if(constants.clipOnAxisFalseQuery.indexOf('.' + className) === -1) {
267264
Drawing.setClipUrl(sel, plotinfo.layerClipId, gd);
268265
}
269266
});
@@ -279,7 +276,7 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
279276
if(!gd._context.staticPlot) {
280277
if(plotinfo._hasClipOnAxisFalse) {
281278
plotinfo.clipOnAxisFalseTraces = plotinfo.plot
282-
.selectAll('.scatterlayer, .barlayer, .funnellayer, .waterfalllayer')
279+
.selectAll(constants.clipOnAxisFalseQuery.join(','))
283280
.selectAll('.trace');
284281
}
285282

src/plots/cartesian/layout_defaults.js

+112-32
Original file line numberDiff line numberDiff line change
@@ -35,51 +35,57 @@ function appendList(cont, k, item) {
3535

3636
module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
3737
var ax2traces = {};
38-
var xaCheater = {};
39-
var xaNonCheater = {};
38+
var hideX = {};
39+
var hideY = {};
4040
var outerTicks = {};
4141
var noGrids = {};
4242
var i, j;
43+
var trace;
44+
var xaName, yaName;
4345

44-
// look for axes in the data
45-
for(i = 0; i < fullData.length; i++) {
46-
var trace = fullData[i];
47-
if(!traceIs(trace, 'cartesian') && !traceIs(trace, 'gl2d')) continue;
46+
function skipType() {
47+
return (!traceIs(trace, 'cartesian') && !traceIs(trace, 'gl2d'));
48+
}
49+
50+
function append(list) {
51+
for(var k = 0; k < list.length; k++) {
52+
appendList(ax2traces, id2name(list[k]), trace);
53+
}
54+
}
4855

49-
var xaName;
56+
function listXnames(trace) {
57+
var list = [];
5058
if(trace.xaxis) {
51-
xaName = id2name(trace.xaxis);
52-
appendList(ax2traces, xaName, trace);
59+
list = [trace.xaxis];
5360
} else if(trace.xaxes) {
54-
for(j = 0; j < trace.xaxes.length; j++) {
55-
appendList(ax2traces, id2name(trace.xaxes[j]), trace);
56-
}
61+
list = trace.xaxes;
5762
}
5863

59-
var yaName;
64+
append(list);
65+
}
66+
67+
function listYnames(trace) {
68+
var list = [];
6069
if(trace.yaxis) {
61-
yaName = id2name(trace.yaxis);
62-
appendList(ax2traces, yaName, trace);
70+
list = [trace.yaxis];
6371
} else if(trace.yaxes) {
64-
for(j = 0; j < trace.yaxes.length; j++) {
65-
appendList(ax2traces, id2name(trace.yaxes[j]), trace);
66-
}
72+
list = trace.yaxes;
6773
}
6874

69-
// Two things trigger axis visibility:
70-
// 1. is not carpet
71-
// 2. carpet that's not cheater
72-
if(!traceIs(trace, 'carpet') || (trace.type === 'carpet' && !trace._cheater)) {
73-
if(xaName) xaNonCheater[xaName] = 1;
74-
}
75+
append(list);
76+
}
7577

76-
// The above check for definitely-not-cheater is not adequate. This
77-
// second list tracks which axes *could* be a cheater so that the
78-
// full condition triggering hiding is:
79-
// *could* be a cheater and *is not definitely visible*
80-
if(trace.type === 'carpet' && trace._cheater) {
81-
if(xaName) xaCheater[xaName] = 1;
82-
}
78+
// look for axes in the data
79+
for(i = 0; i < fullData.length; i++) {
80+
trace = fullData[i];
81+
if(skipType(trace)) continue;
82+
83+
// create lists
84+
listXnames(trace);
85+
listYnames(trace);
86+
87+
xaName = (trace.xaxis) ? id2name(trace.xaxis) : undefined; // TODO: why these should be left undefined?
88+
yaName = (trace.yaxis) ? id2name(trace.yaxis) : undefined;
8389

8490
// check for default formatting tweaks
8591
if(traceIs(trace, '2dMap')) {
@@ -93,6 +99,80 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
9399
}
94100
}
95101

102+
function getXname() {
103+
return (trace.xaxis) ? id2name(trace.xaxis) : undefined; // TODO: why these should be left undefined?
104+
}
105+
106+
function getYname() {
107+
return (trace.yaxis) ? id2name(trace.yaxis) : undefined; // TODO: why these should be left undefined?
108+
}
109+
110+
function includesOnly(desiredType, xaNameIn, yaNameIn) {
111+
var result = false;
112+
for(var k = 0; k < fullData.length; k++) {
113+
var otherTrace = fullData[k];
114+
if(skipType(otherTrace)) continue;
115+
116+
if(
117+
xaNameIn !== getXname(otherTrace) ||
118+
yaNameIn !== getYname(otherTrace)
119+
) continue;
120+
121+
var found = false;
122+
123+
if(desiredType === 'cheater' && traceIs(trace, 'carpet') && trace._cheater !== false) {
124+
found = true;
125+
} else if(trace.type === desiredType) {
126+
found = true;
127+
}
128+
129+
if(!found) {
130+
result = false;
131+
break;
132+
}
133+
result = true;
134+
}
135+
return result;
136+
}
137+
138+
var funnelOnlyX = {};
139+
var funnelOnlyY = {};
140+
var cheaterOnlyX = {};
141+
142+
for(i = 0; i < fullData.length; i++) {
143+
trace = fullData[i];
144+
if(skipType(trace)) continue;
145+
146+
xaName = getXname(trace);
147+
yaName = getYname(trace);
148+
149+
if(funnelOnlyX[xaName] !== false) funnelOnlyX[xaName] = includesOnly('funnel', xaName, yaName);
150+
if(funnelOnlyY[yaName] !== false) funnelOnlyY[yaName] = includesOnly('funnel', xaName, yaName);
151+
if(cheaterOnlyX[xaName] !== false) cheaterOnlyX[xaName] = includesOnly('cheater', xaName, yaName);
152+
}
153+
154+
for(i = 0; i < fullData.length; i++) {
155+
trace = fullData[i];
156+
if(skipType(trace)) continue;
157+
158+
xaName = getXname(trace);
159+
yaName = getYname(trace);
160+
161+
if(traceIs(trace, 'carpet') && trace._cheater) {
162+
if(cheaterOnlyX[xaName] && xaName) hideX[xaName] = 1;
163+
}
164+
165+
if(trace.type === 'funnel') {
166+
if(funnelOnlyX[xaName] && trace.orientation === 'h') {
167+
hideX[xaName] = 1;
168+
}
169+
170+
if(funnelOnlyY[yaName] && trace.orientation === 'v') {
171+
hideY[yaName] = 1;
172+
}
173+
}
174+
}
175+
96176
var subplots = layoutOut._subplots;
97177
var xIds = subplots.xaxis;
98178
var yIds = subplots.yaxis;
@@ -176,7 +256,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
176256
bgColor: bgColor,
177257
calendar: layoutOut.calendar,
178258
automargin: true,
179-
cheateronly: axLetter === 'x' && xaCheater[axName] && !xaNonCheater[axName],
259+
visibleDflt: (axLetter === 'x' && !!hideX[axName]) || (axLetter === 'y' && !!hideY[axName]),
180260
splomStash: ((layoutOut._splomAxes || {})[axLetter] || {})[id]
181261
};
182262

src/traces/bar/attributes.js

+22
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,28 @@ module.exports = {
8686
].join(' ')
8787
},
8888

89+
insidetextanchor: {
90+
valType: 'enumerated',
91+
values: ['end', 'middle', 'start'],
92+
dflt: 'end',
93+
role: 'info',
94+
editType: 'plot',
95+
description: [
96+
'Determines if texts are kept at center or start/end points in `textposition` *inside* mode.'
97+
].join(' ')
98+
},
99+
100+
insidetextrotate: {
101+
valType: 'enumerated',
102+
values: ['auto', 'none'],
103+
dflt: 'auto',
104+
role: 'info',
105+
editType: 'plot',
106+
description: [
107+
'Determines if texts could automatically be rotated to fit inside bars in `textposition` *inside* mode.'
108+
].join(' ')
109+
},
110+
89111
textfont: extendFlat({}, textFontAttrs, {
90112
description: 'Sets the font used for `text`.'
91113
}),

src/traces/bar/cross_trace_calc.js

+27-38
Original file line numberDiff line numberDiff line change
@@ -524,47 +524,43 @@ function setBaseAndTop(gd, sa, sieve) {
524524
}
525525
}
526526

527-
function computeTotalVaules(calcTraces) {
528-
var totalValues = [];
529-
530-
for(var i = 0; i < calcTraces.length; i++) {
531-
var calcTrace = calcTraces[i];
532-
var fullTrace = calcTrace[0].trace;
527+
function stackBars(gd, sa, sieve) {
528+
var fullLayout = gd._fullLayout;
529+
var barnorm = fullLayout.barnorm;
530+
var sLetter = getAxisLetter(sa);
531+
var calcTraces = sieve.traces;
532+
var calcTrace;
533+
var fullTrace;
534+
var isFunnel;
535+
var i, j;
536+
var bar;
533537

534-
var isFunnel = (fullTrace.type === 'funnel');
535-
if(!isFunnel) continue; // for the moment we only need to compute this for funnels
538+
for(i = 0; i < calcTraces.length; i++) {
539+
calcTrace = calcTraces[i];
540+
fullTrace = calcTrace[0].trace;
536541

537-
for(var j = 0; j < calcTrace.length; j++) {
538-
totalValues[j] = totalValues[j] || 0;
542+
if(fullTrace.type === 'funnel') {
543+
for(j = 0; j < calcTrace.length; j++) {
544+
bar = calcTrace[j];
539545

540-
var bar = calcTrace[j];
541-
if(bar.s !== BADNUM) {
542-
totalValues[j] += bar.s;
546+
if(bar.s !== BADNUM) {
547+
// create base of funnels
548+
sieve.put(bar.p, -0.5 * bar.s);
549+
}
543550
}
544551
}
545552
}
546553

547-
return totalValues;
548-
}
549-
550-
function stackBars(gd, sa, sieve) {
551-
var fullLayout = gd._fullLayout;
552-
var barnorm = fullLayout.barnorm;
553-
var sLetter = getAxisLetter(sa);
554-
var calcTraces = sieve.traces;
554+
for(i = 0; i < calcTraces.length; i++) {
555+
calcTrace = calcTraces[i];
556+
fullTrace = calcTrace[0].trace;
555557

556-
var totalValues = computeTotalVaules(sieve.traces);
557-
var seen = [];
558+
isFunnel = (fullTrace.type === 'funnel');
558559

559-
for(var i = 0; i < calcTraces.length; i++) {
560-
var calcTrace = calcTraces[i];
561-
var fullTrace = calcTrace[0].trace;
562560
var pts = [];
563561

564-
var isFunnel = (fullTrace.type === 'funnel');
565-
566-
for(var j = 0; j < calcTrace.length; j++) {
567-
var bar = calcTrace[j];
562+
for(j = 0; j < calcTrace.length; j++) {
563+
bar = calcTrace[j];
568564

569565
if(bar.s !== BADNUM) {
570566
// stack current bar and get previous sum
@@ -575,14 +571,7 @@ function stackBars(gd, sa, sieve) {
575571
value = bar.s + bar.b;
576572
}
577573

578-
var initValue = 0;
579-
if(isFunnel) {
580-
if(!seen[j]) {
581-
seen[j] = true;
582-
initValue = -0.5 * totalValues[j];
583-
}
584-
}
585-
var base = sieve.put(bar.p, value, initValue);
574+
var base = sieve.put(bar.p, value);
586575

587576
var top = base + value;
588577

src/traces/bar/defaults.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ function handleText(traceIn, traceOut, layout, coerce, moduleHasSelUnselected) {
144144
coerce('cliponaxis');
145145
}
146146

147-
if(hasInside && traceIn.type === 'funnel') {
148-
coerce('insidetextcenter');
147+
if(hasInside) {
148+
coerce('insidetextanchor');
149+
coerce('insidetextrotate');
149150
}
150151
}
151152

0 commit comments

Comments
 (0)