Skip to content
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

to attach or to extend? #118

Open
smarc opened this issue Dec 23, 2015 · 1 comment
Open

to attach or to extend? #118

smarc opened this issue Dec 23, 2015 · 1 comment

Comments

@smarc
Copy link

smarc commented Dec 23, 2015

Hi,

thanks a lot for the work of adding an abstract layer to d3, although I'm still climbing the learning curve.

I'm trying to add a layer to the contributed chart d3.chart.candlestick in the miso project page...The layer depends on another set of data namely a set of transactions. I initially tried extend the chart as I thought I was only adding a layer, however as the dataset now consists of additional data, the whole base chart functions break down. What is the strategy for such as case, should I be composing 2 charts in one using .attach and <?>.demux ? one doubt I have is that both charts share the same scales, so not sure how to re-use was is available in the candlestick chart.

thanks,
Stefan

@jugglinmike
Copy link
Member

If I understand your problem correctly, this sounds like a case for attach. You should be able to re-use the scales; how you do it depends on how you structure your code. Here are two approaches that come to mind:

  1. You could define a single chart that initializes the chart you wish to extend, retrieves references to that instance's scales immediately following initialization, and defines the new layer in terms of that reference.
  2. You could define two charts. "Chart A" would define the layer you want to add, and it would accept a set of scales as an initialization option. "Chart B" would create one instance of the chart you wish to reuse and one instance of Chart A, passing in the scales as appropriate. Finally, Chart B would use attach to hook up the draw cycles.

The second approach requires more abstraction, but it's also more composable and potentially more flexible for it. Would either work for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants