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

allow row domain not to start/end at zero #1580

Open
gordonwoodhull opened this issue Sep 20, 2019 · 0 comments
Open

allow row domain not to start/end at zero #1580

gordonwoodhull opened this issue Sep 20, 2019 · 0 comments

Comments

@gordonwoodhull
Copy link
Contributor

gordonwoodhull commented Sep 20, 2019

This is related to #646, which also needs better control over the zero point of the chart.

It came up in this SO question: dcjs dynamic zooming to fit range of values (thanks Isaac!)

The row chart expects always to start at zero and has code to set either the start or the end of the domain to zero:

dc.js/src/row-chart.js

Lines 53 to 66 in 7c55500

function calculateAxisScale () {
if (!_x || _elasticX) {
var extent = d3.extent(_rowData, _chart.cappedValueAccessor);
if (extent[0] > 0) {
extent[0] = 0;
}
if (extent[1] < 0) {
extent[1] = 0;
}
_x = d3.scaleLinear().domain(extent)
.range([0, _chart.effectiveWidth()]);
}
_xAxis.scale(_x);
}

Then it draws the rects starting from where the scale says zero is:

dc.js/src/row-chart.js

Lines 167 to 170 in 7c55500

function rootValue () {
var root = _x(0);
return (root === -Infinity || root !== root) ? _x(1) : root;
}

If the range start is not zero, this will be off the chart.

Example fiddle

A temporary fix, but it has flicker because, as usual, it's fighting with the chart's transitions and pretransition won't work here. Well maybe it could with more work.

chart.on('renderlet', function(chart) {
    var transform = chart.select('g.row rect').attr('transform');
    var tx = +transform.split('(')[1].split(',')[0];
    chart.selectAll('g.row rect')
        .attr('transform', null)
        .attr('width', function(d) {
            return +d3.select(this).attr('width') + tx;
        })
    chart.selectAll('g.row text.row')
        .attr('transform', null);    
})
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

1 participant