GithubHelp home page GithubHelp logo

to attach or to extend? about d3.chart HOT 1 OPEN

smarc avatar smarc commented on August 21, 2024
to attach or to extend?

from d3.chart.

Comments (1)

jugglinmike avatar jugglinmike commented on August 21, 2024

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?

from d3.chart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.