Giter VIP home page Giter VIP logo

Comments (2)

mbostock avatar mbostock commented on May 2, 2024 1

I don’t think it’s a good idea to expose an enumeration of axis orientations. There might be other orientations in the future, such as for polar coordinates. And it feels icky, especially if the orientation is defined as a string.

By analogy, consider scales: there’s no scale.type method to distinguish different types of scales such as d3.scaleLinear and d3.scaleOrdinal. Occasionally you need to distinguish scale types; for example, d3-axis tests for the presence of scale.bandwidth to shift ticks to the middle of each band for band scales. But as that case demonstrates, it’s better to test for a specific feature (bandwidth) than to enumerate the scale types explicitly. Extending the analogy, when developing on the web, it’s better to test whether the current browser supports a feature than to write code that checks the user-agent.

It’d be nice, maybe, if you could use instanceof to test whether something is a particular type of scale, but alas that does not play nice with D3’s use of functions-as-objects, where a scale (like an axis) is both a function and an object. There’s no way to extend Function in JavaScript. (Actually that’s not totally true because you can say class Foo extends Function {}, but I think that requires using the Function constructor—there’s no way to extend a closure defined by a function expression, as far as I know.) So you can’t say x instanceof d3.scaleLinear, either, although that is supported for D3 classes that do not extend function, such as d3.selection.

I can’t see the code you’re writing, but it might be better for you to expose four of your own constructors, and then instantiate the axis internally. That way you’re in control of how the axis gets instantiated, and you know what orientation it is, and there’s no possibility of receiving an axis of an unsupported (or unknown) orientation.

from d3-axis.

c-dante avatar c-dante commented on May 2, 2024

I was considering either wrapping the axis construction or just adding a property to it (such as "type" or otherwise) -- doesn't need to be a string or the like. That's probably the avenue I'll take moving forward.

from d3-axis.

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.