Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q Calendar event overlapping #404

Open
nyh1234444 opened this issue Nov 16, 2022 · 2 comments
Open

Q Calendar event overlapping #404

nyh1234444 opened this issue Nov 16, 2022 · 2 comments

Comments

@nyh1234444
Copy link

Good Days, sorry for disturbing. May i ask some question regarding the q calendar event. If i got more than 2 event in one time-slot and had been overlapping . How to display cause i just find the resource for 2 event only. Thanks

@zuck
Copy link

zuck commented Jan 17, 2023

This is what I'm doing currently (the list of events comes from an API, each event has a unique id). However I agree it would be great to a have a built-in support in the extension for that...

    function getEventStyle(event, events, timeStartPos, timeDurationHeight) {
      const { from, to, duration } = this.getEventRange(event);
      const matches = this.getMatchingEvents(event, events);
      const idx = matches.findIndex((id) => id === event.id);
      const gutter = (matches.length - 1) * 1.25;
      const width = (100 - gutter) / matches.length;
      const margin = matches.length ? gutter / (matches.length - 1) : 0;
      return {
        position: "absolute",
        background: "yellow",
        color: "black",
        top: timeStartPos(event.from) + "px",
        height: timeDurationHeight(duration) + "px",
        left: `${idx * (width + margin)}%`,
        width: `${width}%`,
      };
    }

    function getMatchingEvents(event, events) {
     return events
       filter((e) => {
        if (e.date !== event.date) {
          return false;
        }
        const { from: start, to: end } = this.getEventRange(e);
        return this.areOverlapping(from, to, start, end);
      })
      .map((e) => e.id);
    }
    
    function areOverlapping(start1, end1, start2, end2) {
      if (start1 <= start2 && start2 <= end1) return true; // b starts in a
      if (start1 <= end2 && end2 <= end1) return true; // b ends in a
      if (start2 < start1 && end1 < end2) return true; // a in b
      return false;
    }

@yohn-cheung
Copy link

This is what I'm doing currently (the list of events comes from an API, each event has a unique id). However I agree it would be great to a have a built-in support in the extension for that...

    function getEventStyle(event, events, timeStartPos, timeDurationHeight) {
      const { from, to, duration } = this.getEventRange(event);
      const matches = this.getMatchingEvents(event, events);
      const idx = matches.findIndex((id) => id === event.id);
      const gutter = (matches.length - 1) * 1.25;
      const width = (100 - gutter) / matches.length;
      const margin = matches.length ? gutter / (matches.length - 1) : 0;
      return {
        position: "absolute",
        background: "yellow",
        color: "black",
        top: timeStartPos(event.from) + "px",
        height: timeDurationHeight(duration) + "px",
        left: `${idx * (width + margin)}%`,
        width: `${width}%`,
      };
    }

    function getMatchingEvents(event, events) {
     return events
       filter((e) => {
        if (e.date !== event.date) {
          return false;
        }
        const { from: start, to: end } = this.getEventRange(e);
        return this.areOverlapping(from, to, start, end);
      })
      .map((e) => e.id);
    }
    
    function areOverlapping(start1, end1, start2, end2) {
      if (start1 <= start2 && start2 <= end1) return true; // b starts in a
      if (start1 <= end2 && end2 <= end1) return true; // b ends in a
      if (start2 < start1 && end1 < end2) return true; // a in b
      return false;
    }

Hello Zuck, can you explain what the function getEventRange is? I don't see the function getEventRange in your code snippet. I have the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants