d3plus / d3plus-viz

Abstract ES6 class that drives d3plus visualizations.
MIT License
7 stars 2 forks source link

fixes timeline bug when changing dataset #173

Closed davelandry closed 2 years ago

davelandry commented 2 years ago

If you create a visualization with a certain set of data, and then change to a new dataset with less time resolution, the timeline brush will still try to maintain the old time extent. This PR analyzes for that data change, and adjusts the bounds of the timeline selection accordingly.

Code used for testing:

const myData = [
    {
        "year": 2010,
        "year2": 2009,
        "color": "blue",
        "parent": "Parent 1",
        "id": "alpha",
        "value": 20,
        "value2": 40
    },
    {
        "year": 2010,
        "year2": 2010,
        "color": "blue",
        "parent": "Parent 2",
        "id": "beta",
        "value": 10,
        "value2": 5
    },
    {
        "year": 2011,
        "year2": 2011,
        "color": "red",
        "parent": "Parent 2",
        "id": "gamma",
        "value": 40,
        "value2": 45
    },
    {
        "year": 2011,
        "year2": 2012,
        "color": "red",
        "parent": "Parent 2",
        "id": "beta",
        "value": 20,
        "value2": 15
    },
    {
        "year": 2011,
        "year2": 2013,
        "color": "red",
        "parent": "Parent 2",
        "id": "delta",
        "value": 30,
        "value2": 5
    }
];

var viz = new d3plus.Viz()
  .data(myData)
  .time("year2")
  .timelineConfig({
    brushing: true
  })
  .timeFilter(d => d)
  .render();

setTimeout(() => {
  viz.time("year").render();
}, 2000);