D3 cartogram.js contiguous cartogram values not reflected

128 Views Asked by At

I'm building a contiguous cartogram of inward refugee numbers, based on this example using cartogram.js for D3.

When I just use the refugee number, the map does not move. Base refugee number

But when I add an arbitrary number to "r" on line, the it works. And the higher the arbitrary number, the more dramatic the change. Example 1 Example 2

Why is this? Is it because some of my values are 0, or because the variance is too high?

1

There are 1 best solutions below

0
On

Shortly after starting this question, a friend and I found the answer. We suspect it was the zero values and the extreme variance of my dataset. Adding a scale seems to have sorted it. They are doing this in the example too, I just didn't notice.

// normalize the scale to positive numbers
    var scale = d3.scale.linear()
        .domain([lo, hi])
        .range([1, 1000]);

// tell the cartogram to use the scaled values
    carto.value(function(d) {
        return scale(value(d));
    });