{"version":3,"file":"GanttGrid.vue.mjs","sources":["../../../../../../src/components/ganttView/ganttBody/ganttGrid/GanttGrid.vue"],"sourcesContent":["<template>\n  <svg class=\"vg-grid-container\">\n    <g stroke-width=\"1\"\n       stroke=\"#e9e9e9\"\n       stroke-dasharray=\"12, 8\"\n       transform=\"translate(-0.5,-0.5)\">\n      <line v-for=\"position in verticalLinesList\"\n            :key=\"position\"\n            :x1=\"position\"\n            y1=\"0\"\n            :x2=\"position\"\n            y2=\"100%\"/>\n    </g>\n    <g stroke-width=\"1\" stroke=\"#e9e9e9\" transform=\"translate(-0.5,-0.5)\">\n      <line v-for=\"position in horizontalLinesList\"\n            :key=\"position\"\n            x1=\"0\"\n            :y1=\"position\"\n            x2=\"100%\"\n            :y2=\"position\"/>\n    </g>\n  </svg>\n</template>\n<script lang=\"ts\" setup>\nimport { GanttStyleOption, GanttBodyStartInfo } from '@/types';\nimport { ref, inject, Ref, computed, watch, toRef } from 'vue';\nimport { getRound } from '@/utils/common';\nimport dayjs from 'dayjs';\n\nexport interface Props {\n  rowHeight: number,\n  perHourSpacing: number,\n  rowBuffer: number,\n  edgeSpacing: number,\n  ganttMinDate: dayjs.Dayjs,\n  styleOption?: GanttStyleOption\n}\n\nconst props = defineProps<Props>();\n\nconst wrapRef = inject('wrapRef') as Ref<HTMLDivElement | undefined>;\nconst verticalLinesList = ref<number[]>([]);\nconst horizontalLinesList = ref<number[]>([]);\nconst wrapWidth = ref(0);\nconst wrapHeight = ref(0);\n\nconst scrollViewScrollTop = ref(0);\nconst scrollViewScrollLeft = ref(0);\nconst bufferWidth = 200;\nconst styleOption = toRef(props, 'styleOption');\n\nconst showHorizontalGridLines = computed(() => {\n  return styleOption.value?.showHorizontalGridLines;\n});\n\nconst freshGrid = () => {\n  freshVerticalLines();\n  freshHorizontalLines();\n};\n\n// get the left position of the first month vertical line\nconst startInfo = computed<GanttBodyStartInfo>(() => {\n  const { perHourSpacing, edgeSpacing, ganttMinDate } = props;\n  const diffHour = edgeSpacing / perHourSpacing;\n  const startDate = ganttMinDate.subtract(diffHour, 'hour');\n  const endDate = startDate.endOf('month');\n  const diff = endDate.diff(startDate, 'hour', true);\n  const startLeft = diff * perHourSpacing;\n\n  return {\n    startLeft,\n    startMonthDate: endDate,\n  };\n});\n\nconst freshVerticalLines = () => {\n  if (!wrapRef.value) return;\n\n  const { perHourSpacing } = props;\n\n  const { startMonthDate, startLeft } = startInfo.value;\n\n  const startLeftInView = scrollViewScrollLeft.value - bufferWidth;\n  const endLeftInView = scrollViewScrollLeft.value + wrapWidth.value + bufferWidth;\n\n  const newVerticalLinesList: number[] = [];\n  let start = startLeft;\n  let startMonthDateInView = startMonthDate;\n\n  if (startLeftInView > startLeft) {\n    const diffHour = (startLeftInView - startLeft) / perHourSpacing;\n    const startDateInView = startMonthDate.add(diffHour, 'hour');\n    const endMonthDate = startDateInView.endOf('month');\n    const diff = endMonthDate.diff(startMonthDate, 'hour', true);\n    start = startLeft + diff * perHourSpacing;\n    startMonthDateInView = endMonthDate;\n\n  }\n\n  const perDaySpacing = perHourSpacing * 24;\n  let nextStartMonthDateInView = startMonthDateInView;\n\n  while (start <= endLeftInView) {\n    newVerticalLinesList.push(getRound(start));\n    nextStartMonthDateInView = nextStartMonthDateInView.add(1, 'month');\n    const nextMonthDays = nextStartMonthDateInView.daysInMonth();\n    start += nextMonthDays * perDaySpacing;\n  }\n\n  verticalLinesList.value = newVerticalLinesList;\n};\n\nconst freshHorizontalLines = () => {\n  if (!wrapRef.value) return;\n\n  if (!showHorizontalGridLines.value) {\n    horizontalLinesList.value = [];\n    return;\n  }\n  const { rowHeight, rowBuffer } = props;\n  const bufferHeight = rowHeight * rowBuffer;\n  const startNumInView = Math.ceil((scrollViewScrollTop.value - bufferHeight) / rowHeight);\n  const endIdNumView = Math.floor((scrollViewScrollTop.value + wrapHeight.value + bufferHeight) / rowHeight);\n\n  const newHorizontalLinesList: number[] = [];\n  const start = Math.max(1, startNumInView);\n  for (let i = start; i <= endIdNumView + 1; i++) {\n    newHorizontalLinesList.push(i * rowHeight);\n  }\n\n  horizontalLinesList.value = newHorizontalLinesList;\n\n};\n\nwatch([startInfo, scrollViewScrollLeft], freshVerticalLines);\nwatch([scrollViewScrollTop, showHorizontalGridLines], freshHorizontalLines);\n\nconst onScroll = ({ scrollTop, scrollLeft }: {scrollTop: number, scrollLeft: number}) => {\n  scrollViewScrollTop.value = scrollTop;\n  scrollViewScrollLeft.value = scrollLeft;\n};\n\nconst onResize = () => {\n  wrapWidth.value = wrapRef.value?.offsetWidth || 0;\n  wrapHeight.value = wrapRef.value?.offsetHeight || 0;\n  freshGrid();\n\n};\n\ndefineExpose({\n  onScroll,\n  onResize\n});\n\n</script>\n<style lang=\"scss\">\n.vg-grid-container {\n  width: 100%;\n  height: 100%;\n  position: relative;\n}\n</style>"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAgDA,MAAM,cAAc;;;;;;;;;;;;AAVpB,UAAM,QAAQ;AAER,UAAA,UAAU,OAAO,SAAS;AAC1B,UAAA,oBAAoB,IAAc,EAAE;AACpC,UAAA,sBAAsB,IAAc,EAAE;AACtC,UAAA,YAAY,IAAI,CAAC;AACjB,UAAA,aAAa,IAAI,CAAC;AAElB,UAAA,sBAAsB,IAAI,CAAC;AAC3B,UAAA,uBAAuB,IAAI,CAAC;AAE5B,UAAA,cAAc,MAAM,OAAO,aAAa;AAExC,UAAA,0BAA0B,SAAS,MAAM;;AAC7C,cAAO,iBAAY,UAAZ,mBAAmB;AAAA,IAAA,CAC3B;AAED,UAAM,YAAY,MAAM;AACH,yBAAA;AACE,2BAAA;AAAA,IACvB;AAGM,UAAA,YAAY,SAA6B,MAAM;AACnD,YAAM,EAAE,gBAAgB,aAAa,aAAiB,IAAA;AACtD,YAAM,WAAW,cAAc;AAC/B,YAAM,YAAY,aAAa,SAAS,UAAU,MAAM;AAClD,YAAA,UAAU,UAAU,MAAM,OAAO;AACvC,YAAM,OAAO,QAAQ,KAAK,WAAW,QAAQ,IAAI;AACjD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