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

Can the d3 axis piecewise feature be used to replace discontinuous scales? #1629

Open
ColinEberhardt opened this issue Sep 21, 2020 · 1 comment

Comments

@ColinEberhardt
Copy link
Member

The D3 scale has a "piecewise" feature that allows you to create a scale with multiple domain / range elements. This has some similarities to the D3FC discontinuous scale.

The following example demonstrates how you can create a linear scale with a 'break' between 75-100 using this feature:

const svg = d3.select('body').append('svg');

svg.append('g')
    .attr('transform', 'translate(0, 20)')
    .call(sel => {
        const scale = fc
            .scaleDiscontinuous(d3.scaleLinear())
            .discontinuityProvider(fc.discontinuityRange([50, 75]))
            .domain([0, 100])
            .range([0, 600]);

        d3.axisBottom(scale)(sel);
    });

svg.append('g')
    .attr('transform', 'translate(0, 60)')
    .call(sel => {
        const scale = d3
            .scaleLinear()
            .domain([0, 50, 75, 100])
            .range([0, 400, 400, 600]);

        d3.axisBottom(scale)(sel);
    });

This yields the following result:

image

One possible option would be to use this functionality to simplify the implementation of fc.scaleDiscontinuous, however, it would still need work to remove ticks from within the discontinuities.

@ColinEberhardt
Copy link
Member Author

see: d3/d3-scale#222

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

No branches or pull requests

1 participant