How to change prototype of scale

15 views
Skip to first unread message

Pavel S

unread,
Apr 16, 2015, 8:42:06 AM4/16/15
to d3...@googlegroups.com
Hi,
I would like to modify the prototype of scales, e.g. to add new method walk() to all scales, however I faced the problem, that scales (linear, logarithmic, etc..) don't share the prototype.

Scales have the same outer API, but not common prototype: linear is instance of d3_scale_linear(), logarithmic is instance of d3_scale_log().

Is there any best practice, how to do that?

P

Sean Upton

unread,
Apr 16, 2015, 2:07:58 PM4/16/15
to d3...@googlegroups.com
You might consider writing your own factory function for obtaining
scales (and use it consistently). Create a scale as usual, and attach
appropriate additional behaviors/state (such as a function) per
instance. That seems most practical, seeing this as a wrapping
problem instead of trying to globally modify a base that does not
exist.

Sean
> --
> You received this message because you are subscribed to the Google Groups
> "d3-js" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to d3-js+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Pavel S

unread,
Apr 17, 2015, 1:58:47 AM4/17/15
to d3...@googlegroups.com
Hi,

from my perspective it's more a design problem in D3 - overuse of function closures, where inheritance would be better paradigm.

Why not to have an abstract class 'scale' and then concrete classes linear, log,.. inheriting from the 'scale'?




Dne čtvrtek 16. dubna 2015 20:07:58 UTC+2 Sean Upton napsal(a):
Reply all
Reply to author
Forward
0 new messages