Coder Social home page Coder Social logo

Comments (5)

rulai-ymwang avatar rulai-ymwang commented on July 20, 2024 1

I figured this out. Check the code below.

prepareDates() {
let firstTaskTime = Number.MAX_SAFE_INTEGER;
let lastTaskTime = 0;
for (let index = 0, len = this.state.tasks.length; index < len; index++) {
let task = this.state.tasks[index];
if (task.startTime < firstTaskTime) {
firstTaskTime = task.startTime;
}
if (task.startTime + task.duration > lastTaskTime) {
lastTaskTime = task.startTime + task.duration;
}
}
this.state.options.times.firstTaskTime = firstTaskTime;
this.state.options.times.lastTaskTime = lastTaskTime;
this.state.options.times.firstTime = dayjs(firstTaskTime)
.locale(this.state.options.locale.name)
.startOf('day')
.subtract(this.state.options.scope.before, 'days')
.startOf('day')
.valueOf();
this.state.options.times.lastTime = dayjs(lastTaskTime)
.locale(this.state.options.locale.name)
.endOf('day')
.add(this.state.options.scope.after, 'days')
.endOf('day')
.valueOf();
},

If no tasks given, the firstTaskTime will be Number.MAX_SAFE_INTEGER and the lastTaskTime will be 0. They are both invalid time ms.

We can set reasonable values to them when no tasks given. Fix could like below (set the default time range from today to 7 days later ):

let firstTaskTime = Number.MAX_SAFE_INTEGER;
      let lastTaskTime = 0;
      if (this.state.tasks.length === 0 ) {
        firstTaskTime = dayjs().hour(0).minute(0).second(0).toDate().getTime();
        lastTaskTime = dayjs().hour(0).minute(0).second(0).add(7, 'day').toDate().getTime();
      } else {
        for (let index = 0, len = this.state.tasks.length; index < len; index++) {
          let task = this.state.tasks[index];
          if (task.startTime < firstTaskTime) {
            firstTaskTime = task.startTime;
          }
          if (task.startTime + task.duration > lastTaskTime) {
            lastTaskTime = task.startTime + task.duration;
          }
        }
      }

@neuronetio I will give a PR later. Could you please help reviewing it? Thanks!

from gantt-elastic.

DanielRuf avatar DanielRuf commented on July 20, 2024

Following is thrown then:

image

from gantt-elastic.

skanehira avatar skanehira commented on July 20, 2024

@DanielRuf @neuronetio
I have same problem...
Is there a solution or alternative?

from gantt-elastic.

rulai-ymwang avatar rulai-ymwang commented on July 20, 2024

Here is the pr: #101

from gantt-elastic.

monroenikko avatar monroenikko commented on July 20, 2024

I figured this out. Check the code below.

prepareDates() {
let firstTaskTime = Number.MAX_SAFE_INTEGER;
let lastTaskTime = 0;
for (let index = 0, len = this.state.tasks.length; index < len; index++) {
let task = this.state.tasks[index];
if (task.startTime < firstTaskTime) {
firstTaskTime = task.startTime;
}
if (task.startTime + task.duration > lastTaskTime) {
lastTaskTime = task.startTime + task.duration;
}
}
this.state.options.times.firstTaskTime = firstTaskTime;
this.state.options.times.lastTaskTime = lastTaskTime;
this.state.options.times.firstTime = dayjs(firstTaskTime)
.locale(this.state.options.locale.name)
.startOf('day')
.subtract(this.state.options.scope.before, 'days')
.startOf('day')
.valueOf();
this.state.options.times.lastTime = dayjs(lastTaskTime)
.locale(this.state.options.locale.name)
.endOf('day')
.add(this.state.options.scope.after, 'days')
.endOf('day')
.valueOf();
},

If no tasks given, the firstTaskTime will be Number.MAX_SAFE_INTEGER and the lastTaskTime will be 0. They are both invalid time ms.

We can set reasonable values to them when no tasks given. Fix could like below (set the default time range from today to 7 days later ):

let firstTaskTime = Number.MAX_SAFE_INTEGER;
      let lastTaskTime = 0;
      if (this.state.tasks.length === 0 ) {
        firstTaskTime = dayjs().hour(0).minute(0).second(0).toDate().getTime();
        lastTaskTime = dayjs().hour(0).minute(0).second(0).add(7, 'day').toDate().getTime();
      } else {
        for (let index = 0, len = this.state.tasks.length; index < len; index++) {
          let task = this.state.tasks[index];
          if (task.startTime < firstTaskTime) {
            firstTaskTime = task.startTime;
          }
          if (task.startTime + task.duration > lastTaskTime) {
            lastTaskTime = task.startTime + task.duration;
          }
        }
      }

@neuronetio I will give a PR later. Could you please help reviewing it? Thanks!

My gantt is working now. Nice! thanks

from gantt-elastic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.