-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
SVG trace on selection perf #2583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
53a5a64
b6d4ebc
6c86e08
0a50295
7103fab
01df2d2
3776e8f
4adc091
46858a7
0e91c6e
84ca51f
3e32b23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ var d3 = require('d3'); | |
var Drawing = require('../../components/drawing'); | ||
var Registry = require('../../registry'); | ||
|
||
module.exports = function style(gd, cd) { | ||
function style(gd, cd) { | ||
var s = cd ? cd[0].node3 : d3.select(gd).selectAll('g.trace.bars'); | ||
var barcount = s.size(); | ||
var fullLayout = gd._fullLayout; | ||
|
@@ -35,34 +35,52 @@ module.exports = function style(gd, cd) { | |
|
||
s.selectAll('g.points').each(function(d) { | ||
var sel = d3.select(this); | ||
var pts = sel.selectAll('path'); | ||
var txs = sel.selectAll('text'); | ||
var trace = d[0].trace; | ||
stylePoints(sel, trace, gd); | ||
}); | ||
|
||
Registry.getComponentMethod('errorbars', 'style')(s); | ||
} | ||
|
||
Drawing.pointStyle(pts, trace, gd); | ||
Drawing.selectedPointStyle(pts, trace); | ||
function stylePoints(sel, trace, gd) { | ||
var pts = sel.selectAll('path'); | ||
var txs = sel.selectAll('text'); | ||
|
||
txs.each(function(d) { | ||
var tx = d3.select(this); | ||
var textFont; | ||
Drawing.pointStyle(pts, trace, gd); | ||
|
||
if(tx.classed('bartext-inside')) { | ||
textFont = trace.insidetextfont; | ||
} else if(tx.classed('bartext-outside')) { | ||
textFont = trace.outsidetextfont; | ||
} | ||
if(!textFont) textFont = trace.textfont; | ||
txs.each(function(d) { | ||
var tx = d3.select(this); | ||
var textFont; | ||
|
||
function cast(k) { | ||
var cont = textFont[k]; | ||
return Array.isArray(cont) ? cont[d.i] : cont; | ||
} | ||
if(tx.classed('bartext-inside')) { | ||
textFont = trace.insidetextfont; | ||
} else if(tx.classed('bartext-outside')) { | ||
textFont = trace.outsidetextfont; | ||
} | ||
if(!textFont) textFont = trace.textfont; | ||
|
||
Drawing.font(tx, cast('family'), cast('size'), cast('color')); | ||
}); | ||
function cast(k) { | ||
var cont = textFont[k]; | ||
return Array.isArray(cont) ? cont[d.i] : cont; | ||
} | ||
|
||
Drawing.selectedTextStyle(txs, trace); | ||
Drawing.font(tx, cast('family'), cast('size'), cast('color')); | ||
}); | ||
} | ||
|
||
Registry.getComponentMethod('errorbars', 'style')(s); | ||
function styleOnSelect(gd, cd) { | ||
var s = cd[0].node3; | ||
var trace = cd[0].trace; | ||
|
||
if(trace.selectedpoints) { | ||
Drawing.selectedPointStyle(s.selectAll('path'), trace); | ||
Drawing.selectedTextStyle(s.selectAll('text'), trace); | ||
} else { | ||
stylePoints(s, trace, gd); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this BTW, I'm hesitant to suggest this after the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah oops, this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
To get back to the original state after double-click. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
added in 01df2d2 |
||
} | ||
} | ||
|
||
module.exports = { | ||
style: style, | ||
styleOnSelect: styleOnSelect | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like
styleOnSelect
, very nice solution!But please call it something more descriptive than
fn
here -styleSelection
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure thing 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in 0e91c6e