visjs / vis-timeline

📅 Create a fully customizable, interactive timelines and 2d-graphs with items and ranges.
https://visjs.github.io/vis-timeline/
Other
1.74k stars 302 forks source link

Support group level orientation #1797

Open allmonday opened 1 month ago

allmonday commented 1 month ago

image I hack this effect by setting orientation in each items like

[{
          id: 22,
          group: 1,
          content: "g-2. .... ggggggggg",
          start: "2023-01-07",
          orientation: "bottom",
        },
        {
          id: 3,
          group: 2,
          content: "g-3. .... gggggg",
          start: "2023-01-11",
          orientation: "top",
        },
        {
          id: 4,
          group: 2,
          content: "g-4. .... gggggg",
          start: "2023-01-12",
          orientation: "top",
        }]

and read it in BoxItem.repositionY

  repositionY() {
    let orientation = this.data.orientation;
    // const scoped = this.options.scoped;
    const scoped = true;
    const lineStyle = this.dom.line.style;
    // orientation = Math.random() > 0.5 ? 'top': 'bottom'

    if (orientation == "top") {
      // console.log(this.parent.height)
      // console.log(this.height)

      let lineHeight = 0;
      if (scoped) {
        lineHeight = this.top + 1;
      } else {
        lineHeight = this.parent.top + this.top + 1;
      }

      this.boxY = this.top || 0;
      lineStyle.height = `${lineHeight}px`;
      lineStyle.bottom = "";
      lineStyle.top = "0";

      if (scoped) {
        this.lineY = this.parent.top;
      } else {
        this.lineY = undefined;
      }
    } else {
      // orientation 'bottom' or 'both'
      const itemSetHeight = this.parent.itemSet.props.height; // TODO: this is nasty  // total height

      let lineHeight = 0;
      if (scoped) {
        lineHeight = this.top;
      } else {
        lineHeight =
          itemSetHeight - this.parent.top - this.parent.height + this.top;
      }
      // console.dir({
      //   id: this.id,
      //   item: itemSetHeight,
      //   pt: this.parent.top,
      //   ph: this.parent.height,
      //   top: this.top,
      //   result: lineHeight,
      //   result2: itemSetHeight - this.parent.top - this.parent.height + this.top
      // })

      this.boxY = this.parent.height - this.top - (this.height || 0);
      lineStyle.height = `${lineHeight}px`;
      lineStyle.top = "";
      lineStyle.bottom = "0";

      if (scoped) {
        this.lineY = -(itemSetHeight - this.parent.height - this.parent.top);
      } else {
        this.lineY = undefined;
      }
    }

    this.dotY = -this.props.dot.height / 2;

    this.repositionXY();
  }

I think the layout requirement of bi-direction with time axis in the center it real useful. image

my implementation is a mess, I hope group can support params:

and it will be much elegant.

thanks.