Search code examples
javascriptvis.jsvis.js-timeline

min/max and start/end don't work together


The options for my Vis timeline are as follows...

var options = {

    height: '150px',
    min: start.add(-3, 'M'),
    max: finish.add(3, 'M'),
    start: start,
    end: finish,
    zoomMin: 21600000
};

I'm finding that with this config, start and finish are ignored and the initial visible period is bounded by min and max.

If I remove min and max, then the initial visible period is start and end, except that the min and max are thousands of years in the past and future.

How do I use both of these sets of properties at the same time?


Solution

  • Vis is not the problem here but moment.js. The documentation for the add method says:

    Mutates the original moment by adding time.

    So the adding is made in place and basically when you call it to set min and max, this also does it for the start and end.

    To solve this, you can either initialize two objects when you create your start and finish object or you can go with some other workaround like is suggested here.