Skip to content

Commit bf039ab

Browse files
committed
resolve #1862 - add marker.opacity to bar (& histogram) traces
- by doing so, we can use Drawing.pointStyle straight-up!
1 parent eeace5b commit bf039ab

File tree

3 files changed

+24
-44
lines changed

3 files changed

+24
-44
lines changed

src/components/drawing/index.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,6 @@ drawing.symbolNumber = function(v) {
249249
};
250250

251251
function singlePointStyle(d, sel, trace, markerScale, lineScale, marker, markerLine, gd) {
252-
// only scatter & box plots get marker path and opacity
253-
// bars, histograms don't
254252
if(Registry.traceIs(trace, 'symbols')) {
255253
var sizeFn = makeBubbleSizeFn(trace);
256254

@@ -277,12 +275,13 @@ function singlePointStyle(d, sel, trace, markerScale, lineScale, marker, markerL
277275

278276
return drawing.symbolFuncs[xBase](r) +
279277
(x >= 200 ? DOTPATH : '');
280-
})
281-
.style('opacity', function(d) {
282-
return (d.mo + 1 || marker.opacity + 1) - 1;
283278
});
284279
}
285280

281+
sel.style('opacity', function(d) {
282+
return (d.mo + 1 || marker.opacity + 1) - 1;
283+
});
284+
286285
var perPointGradient = false;
287286

288287
// 'so' is suspected outliers, for box plots
@@ -410,7 +409,6 @@ drawing.singlePointStyle = function(d, sel, trace, markerScale, lineScale, gd) {
410409
var marker = trace.marker;
411410

412411
singlePointStyle(d, sel, trace, markerScale, lineScale, marker, marker.line, gd);
413-
414412
};
415413

416414
drawing.pointStyle = function(s, trace, gd) {

src/traces/bar/attributes.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,17 @@ var marker = extendFlat({
3838
editType: 'calc'
3939
}, colorAttributes('marker'), {
4040
showscale: scatterMarkerAttrs.showscale,
41-
colorbar: colorbarAttrs
41+
colorbar: colorbarAttrs,
42+
opacity: {
43+
valType: 'number',
44+
arrayOk: true,
45+
dflt: 1,
46+
min: 0,
47+
max: 1,
48+
role: 'style',
49+
editType: 'style',
50+
description: 'Sets the opacity of the bars.'
51+
}
4252
});
4353

4454

src/traces/bar/style.js

+9-37
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010
'use strict';
1111

1212
var d3 = require('d3');
13-
14-
var Color = require('../../components/color');
1513
var Drawing = require('../../components/drawing');
1614
var ErrorBars = require('../../components/errorbars');
1715

18-
19-
module.exports = function style(gd) {
20-
var s = d3.select(gd).selectAll('g.trace.bars'),
21-
barcount = s.size(),
22-
fullLayout = gd._fullLayout;
16+
module.exports = function style(gd, cd) {
17+
var s = cd ? cd[0].node3 : d3.select(gd).selectAll('g.trace.bars');
18+
var barcount = s.size();
19+
var fullLayout = gd._fullLayout;
2320

2421
// trace styling
2522
s.style('opacity', function(d) { return d[0].trace.opacity; })
@@ -36,38 +33,13 @@ module.exports = function style(gd) {
3633
}
3734
});
3835

39-
// then style the individual bars
4036
s.selectAll('g.points').each(function(d) {
41-
var trace = d[0].trace,
42-
marker = trace.marker,
43-
markerLine = marker.line,
44-
markerScale = Drawing.tryColorscale(marker, ''),
45-
lineScale = Drawing.tryColorscale(marker, 'line');
46-
47-
d3.select(this).selectAll('path').each(function(d) {
48-
// allow all marker and marker line colors to be scaled
49-
// by given max and min to colorscales
50-
var fillColor,
51-
lineColor,
52-
lineWidth = (d.mlw + 1 || markerLine.width + 1) - 1,
53-
p = d3.select(this);
54-
55-
if('mc' in d) fillColor = d.mcc = markerScale(d.mc);
56-
else if(Array.isArray(marker.color)) fillColor = Color.defaultLine;
57-
else fillColor = marker.color;
58-
59-
p.style('stroke-width', lineWidth + 'px')
60-
.call(Color.fill, fillColor);
61-
if(lineWidth) {
62-
if('mlc' in d) lineColor = d.mlcc = lineScale(d.mlc);
63-
// weird case: array wasn't long enough to apply to every point
64-
else if(Array.isArray(markerLine.color)) lineColor = Color.defaultLine;
65-
else lineColor = markerLine.color;
37+
var sel = d3.select(this);
38+
var pts = sel.selectAll('.point');
39+
var trace = d[0].trace;
6640

67-
p.call(Color.stroke, lineColor);
68-
}
69-
});
41+
Drawing.pointStyle(pts, trace, gd);
7042
});
7143

72-
s.call(ErrorBars.style);
44+
ErrorBars.style(s);
7345
};

0 commit comments

Comments
 (0)