5 ms·
I never like how they chain methods. A better way would be: texture({lines: true, heavier: true, stroke: 'red'}) Is easier to configure if you need reusab
by ttty 12y ago
I never like how they chain methods. A better way would be:
texture({lines: true, heavier: true, stroke: 'red'})
Is easier to configure if you need reusable textures.
- ricsca 12y agoInteresting point. I simply relied o this post of Mike Bostock http://bost.ocks.org/mike/chart/ http://bost.ocks.org/mike/chart/.
- findjashua 12y agoimho, if the operations are to be performed in a certain order, use chaining. Otherwise, passing a config object is much cleaner
- wayfarer2s 12y agoAn initial config object would probably be ideal, and then you could have the chaining to supplement those values. You could have the initial method take in the config and use the values in that in place of the defaults. So textures.circles() .radius(4) .fill("transparent") .strokeWidth(2); could initially be var circles = textures.circles({ radius: 4, fill: "transparent", strokeWidth: 2 }); and later updated to be circles.strokeWidth( 1 ); Which works rather nicely especially when the config object is generated dynamically.
- bkirwi 12y agoYeah, it makes sense to mimic the D3 style: the only thing worse than a bad convention is two conventions.
- mbostock 12y agoAren’t these textures already reusable? The constructed texture object (the result of textures.lines(), e.g.) can be called on as many selections as you like to reuse it. I feel it’s a matter of taste, but one practical reason I prefer chaining to configuration objects is that you get a runtime error when you misspell a property, rather than it being silently ignored.
- ttty 12y agoImage you have an UI which talks to this. For example you have a button on/off. How would you do? var t = texture().lines().stroke('red') if(this.button.on) t= texture.heavier() Compare the previous with this one. var t = texture({lines: true, heavier: this.button.on, stroke: 'red'}) I also hate the non standard constructor: this should be like this var texture = new Texture({lines: true, heavier: this.button.on, stroke: 'red'});