Skip to content

Simplify imports (scales, curves, projections, etc) #478

Open

Description

@techniq

Instead of requiring imports from d3-scales, d3-shape, d3-geo, we should support simple strings for many of these use cases (but still support functions for custom implementations including pulling from other sources such as d3-geo-projection) or d3-geo-polygon).

This will

  • Simplify the packages needing to be installed by the user
  • Knowing the packages and import names (prefixes like scale*, geo*, curve*, etc)
  • Explorability of the API (ex. auto complete when <Spline curve=" is typed with available options)

Scale

Before

<script>
  import { scaleBand } from 'd3-scale';
</script>

<Chart xScale={scaleBand()} />

After

<Chart xScale="band" />

Curve

Before

<script>
  import { curveMonotoneX } from 'd3-shape';
</script>

<Spline curve={curveMonotoneX} />

After

<Spline curve="monotoneX" />

Projection

Before

<script>
  import { geoOrthographic } from 'd3-geo';
</script>

<Chart geo={{ projection: geoOrthographic }}>...</Chart>

After

<Chart geo={{ projection: 'orthographic' }}>...</Chart>

Will need to consider how this impacts the library size / tree shaking.

Activity

  1. added this to the v2 milestone on May 1, 2025
  2. moved this to Todo in Roadmapon May 1, 2025
  3. ecstrema commented on Jul 27, 2025

    @ecstrema

    This seems hard to do without breaking tree shaking. A cleaner solution would be to reexport these functions from layerchart.

    However, I don't think it's a problem as is right now. As long as it's made clear where these functions are coming from in the docs.

  4. techniq commented on Jul 28, 2025

    @techniq
    OwnerAuthor

    @ecstrema that's a good point. Maybe re-exporting (possibly with simplified names) is a descent compromise. I still like the ergonomics of intellisense with known string values though).

    Before

    <script>
      import { scaleBand } from 'd3-scale';
      import { curveMonotoneX } from 'd3-shape';
    </script>
    
    <Chart xScale={scaleBand()} />
    <Spline curve={curveMonotoneX} />

    After

    <script>
      import { band } from 'layerchart/scale';
      import { monotoneX } from 'layerchart/curve';
    </script>
    
    <Chart xScale={band()} />
    <Spline curve={monotoneX} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    • Status
      Todo

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions