Skip to content

Commit 6c86e08

Browse files
committed
split Box & Bar .style + add .styleOnSelect
1 parent b6d4ebc commit 6c86e08

File tree

6 files changed

+68
-27
lines changed

6 files changed

+68
-27
lines changed

src/traces/bar/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Bar.setPositions = require('./set_positions');
2020
Bar.colorbar = require('../scatter/colorbar');
2121
Bar.arraysToCalcdata = require('./arrays_to_calcdata');
2222
Bar.plot = require('./plot');
23-
Bar.style = require('./style');
23+
Bar.style = require('./style').style;
24+
Bar.styleOnSelect = require('./style').styleOnSelect;
2425
Bar.hoverPoints = require('./hover');
2526
Bar.selectPoints = require('./select');
2627

src/traces/bar/style.js

+43-22
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var d3 = require('d3');
1313
var Drawing = require('../../components/drawing');
1414
var Registry = require('../../registry');
1515

16-
module.exports = function style(gd, cd) {
16+
function style(gd, cd) {
1717
var s = cd ? cd[0].node3 : d3.select(gd).selectAll('g.trace.bars');
1818
var barcount = s.size();
1919
var fullLayout = gd._fullLayout;
@@ -35,34 +35,55 @@ module.exports = function style(gd, cd) {
3535

3636
s.selectAll('g.points').each(function(d) {
3737
var sel = d3.select(this);
38-
var pts = sel.selectAll('path');
39-
var txs = sel.selectAll('text');
4038
var trace = d[0].trace;
39+
stylePoints(sel, trace, gd);
40+
});
4141

42-
Drawing.pointStyle(pts, trace, gd);
43-
Drawing.selectedPointStyle(pts, trace);
42+
Registry.getComponentMethod('errorbars', 'style')(s);
43+
}
4444

45-
txs.each(function(d) {
46-
var tx = d3.select(this);
47-
var textFont;
45+
function stylePoints(sel, trace, gd) {
46+
var pts = sel.selectAll('path');
47+
var txs = sel.selectAll('text');
4848

49-
if(tx.classed('bartext-inside')) {
50-
textFont = trace.insidetextfont;
51-
} else if(tx.classed('bartext-outside')) {
52-
textFont = trace.outsidetextfont;
53-
}
54-
if(!textFont) textFont = trace.textfont;
49+
Drawing.pointStyle(pts, trace, gd);
50+
Drawing.selectedPointStyle(pts, trace);
5551

56-
function cast(k) {
57-
var cont = textFont[k];
58-
return Array.isArray(cont) ? cont[d.i] : cont;
59-
}
52+
txs.each(function(d) {
53+
var tx = d3.select(this);
54+
var textFont;
6055

61-
Drawing.font(tx, cast('family'), cast('size'), cast('color'));
62-
});
56+
if(tx.classed('bartext-inside')) {
57+
textFont = trace.insidetextfont;
58+
} else if(tx.classed('bartext-outside')) {
59+
textFont = trace.outsidetextfont;
60+
}
61+
if(!textFont) textFont = trace.textfont;
62+
63+
function cast(k) {
64+
var cont = textFont[k];
65+
return Array.isArray(cont) ? cont[d.i] : cont;
66+
}
6367

64-
Drawing.selectedTextStyle(txs, trace);
68+
Drawing.font(tx, cast('family'), cast('size'), cast('color'));
6569
});
6670

67-
Registry.getComponentMethod('errorbars', 'style')(s);
71+
Drawing.selectedTextStyle(txs, trace);
72+
}
73+
74+
function styleOnSelect(gd, cd) {
75+
var s = cd[0].node3;
76+
var trace = cd[0].trace;
77+
78+
if(trace.selectedpoints) {
79+
Drawing.selectedPointStyle(s.selectAll('path'), trace, gd);
80+
Drawing.selectedPointStyle(s.selectAll('text'), trace, gd);
81+
} else {
82+
stylePoints(s, trace, gd);
83+
}
84+
}
85+
86+
module.exports = {
87+
style: style,
88+
styleOnSelect: styleOnSelect
6889
};

src/traces/box/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ Box.supplyLayoutDefaults = require('./layout_defaults').supplyLayoutDefaults;
1717
Box.calc = require('./calc');
1818
Box.setPositions = require('./set_positions').setPositions;
1919
Box.plot = require('./plot').plot;
20-
Box.style = require('./style');
20+
Box.style = require('./style').style;
21+
Box.styleOnSelect = require('./style').styleOnSelect;
2122
Box.hoverPoints = require('./hover').hoverPoints;
2223
Box.selectPoints = require('./select');
2324

src/traces/box/style.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var d3 = require('d3');
1212
var Color = require('../../components/color');
1313
var Drawing = require('../../components/drawing');
1414

15-
module.exports = function style(gd, cd) {
15+
function style(gd, cd) {
1616
var s = cd ? cd[0].node3 : d3.select(gd).selectAll('g.trace.boxes');
1717

1818
s.style('opacity', function(d) { return d[0].trace.opacity; });
@@ -53,4 +53,21 @@ module.exports = function style(gd, cd) {
5353
Drawing.selectedPointStyle(pts, trace);
5454
}
5555
});
56+
}
57+
58+
function styleOnSelect(gd, cd) {
59+
var s = cd[0].node3;
60+
var trace = cd[0].trace;
61+
var pts = s.selectAll('path.point');
62+
63+
if(trace.selectedpoints) {
64+
Drawing.selectedPointStyle(pts, trace, gd);
65+
} else {
66+
Drawing.pointStyle(pts, trace, gd);
67+
}
68+
}
69+
70+
module.exports = {
71+
style: style,
72+
styleOnSelect: styleOnSelect
5673
};

src/traces/candlestick/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = {
3636
supplyDefaults: require('./defaults'),
3737
calc: require('./calc'),
3838
plot: require('../box/plot').plot,
39-
style: require('../box/style'),
39+
style: require('../box/style').style,
4040
hoverPoints: require('../ohlc/hover'),
4141
selectPoints: require('../ohlc/select')
4242
};

src/traces/histogram/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ Histogram.supplyLayoutDefaults = require('../bar/layout_defaults');
3232
Histogram.calc = require('./calc');
3333
Histogram.setPositions = require('../bar/set_positions');
3434
Histogram.plot = require('../bar/plot');
35-
Histogram.style = require('../bar/style');
35+
Histogram.style = require('../bar/style').style;
36+
Histogram.styleOnSelect = require('../bar/style').styleOnSelect;
3637
Histogram.colorbar = require('../scatter/colorbar');
3738
Histogram.hoverPoints = require('./hover');
3839
Histogram.selectPoints = require('../bar/select');

0 commit comments

Comments
 (0)