Lurker News

Comments (61) 30 threads

anoother1 reply#
This is lovely. When I see this, I don't think 'patterns', rather, 'hatches'.

Makes me wonder what the state of modern SVG is w.r.t. real-world units - something like this really makes SVG look useful for for technical drawing, but pixels are not the best unit to draw to...

hardmath123#
Hmm, an Asymptote to SVG renderer would be pretty useful for displaying mathematical diagrams on the web.
ttty2 replies#
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.
findjashua#
imho, if the operations are to be performed in a certain order, use chaining. Otherwise, passing a config object is much cleaner
wayfarer2s#
An 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#
Yeah, it makes sense to mimic the D3 style: the only thing worse than a bad convention is two conventions.
mbostock1 reply#
Aren’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.

ttty2 replies#
Image 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'});
siddboots#
"heavier: this.button.on" has ambiguous semantics. Do libraries really use this pattern?

Also, use of the "new" keyword is contentious. You can hardly pretend that it is best practice.

ricsca#
It should be

    var t = texture().lines().stroke('red')
    if(this.button.on) t.heavier()
ricsca#
:D thanks! Very good point.
bennstancil#
This is pretty cool. I made a really basic example, but in doing it, I could imagine playing around with having the colors or orientation change with the data as well. And it might make for cool transitions too. That obviously get way too complicated pretty quickly, but it'd be fun to see what you could come up with that might work.

https://modeanalytics.com/benn/reports/a4515d9b9024

Load more comments