Skip to content

geoChoropleth: Alter underlying topojson WITHOUT re-rendering #1196

@aaronrudkin

Description

@aaronrudkin

I have a geoChoropleth of the US that shows a political party's control of a given state at a given time. One of the functions I have implemented is a smooth animation where the user can drag a bar through history to an arbitrary year and see how data changes or just press play and watch the advance of time. This looks great--I do it by switching crossfilter groups on the fly and redrawing the map. Smooth transitions, looks great, good performance. For areas of the continent that are not yet states, I simply grey them out so users have a visual cue as to why they are not present in the data.

One limitation of this is that, in point of fact, the actual shapes of states change a good deal during the course of history, beyond just joining and leaving the United States. The partitioning of Virginia is one good example, but actually many states started out having large swaths of mostly unoccupied land which were later carved away into territories and then finally admitted as new states later. As a result, my map is anachronistic up until Hawaii and Alaska join. This is an acceptable limitation for the project, but not an ideal one, so I'd like to fix it.

I can get around this by dynamically loading a new json for each time period. It's not difficult:

d3.json("/static/json/states"+loadNum+".json", function(error, stateboundaries)
        {
                if(!error)
                {
                        var mapTopo = topojson.feature(stateboundaries, stateboundaries.objects.states).features;
                        partyMapChart.overlayGeoJson(mapTopo, 'state', function(d) { return d.id; })
                }
        });

But now, having substituted the data, I need to draw the new map. However, just running partyMapChart.redraw() will not actually update the underlying GeoJson overlay the way it would for a group switch. Instead, I need to force partyMapChart.render(). This is unfortunate, because it breaks the transition animations (suppose a state does not change, and should be coloured dark blue both before and after the switch: instead, we see a flash of white and another fade to dark blue). This creates sort of strobe effect that is very unpleasant. Also, we use a custom legend overlay that we have hooked to a postRender listener, so the legend disappears and flashes in again.

Any advice for the best way to do this? If not, I'd like to suggest the ability to update the json overlay without re-rendering as an enhancement.

The project is private and due to grant restrictions shouldn't be shared before it is ready, so I'd prefer not to give a working example, but if you have difficulty grasping the issue I'm running into I could try to come up with one.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions