gantt-source_management
Version:
Gantt, Schedule,
61 lines • 181 kB
JavaScript
import{d as t,u as e,a as o,S as a,A as i,h as s,l as n,v as l,D as r,_ as c,m as d,b as h,c as u,p as m,P as g,e as f,f as p,J as w,V as b}from"./vendor.esm.min.js";
/**
* Gantt-Schedule-Timeline-Calendar Time api
*
* @copyright NEURONET - Rafal Pospiech
* @author Rafal Pospiech <neuronet.io@gmail.com>
* @module gantt-schedule-timeline-calendar
* @link https://github.com/neuronetio/gantt-schedule-timeline-calendar
* @link https://gantt-schedule-timeline-calendar.neuronet.io
* @version 3.37.5
* @released 2024-07-19
* @license SEE LICENSE IN LICENSE FILE
*/class v{constructor(a,i){this.utcMode=!1,this.unsubs=[],this.currentDateLastCheck=0,this.state=a,this.api=i,this.dayjs=t,this.dayjs.extend(e),this.dayjs.extend(o),this.unsubs.push(a.subscribe("config.utcMode",(t=>{this.utcMode=t}))),this.unsubs.push(a.subscribe("config.locale",(t=>{if(!t.name)throw new Error("Locale must have a name property.");this.locale=t,this.dayjs.locale(this.locale,null,!0)})))}destroy(){for(const t of this.unsubs)t()}date(e=void 0){return this.utcMode?t.utc(e).locale(this.locale.name):e?t(e).locale(this.locale.name):t().locale(this.locale.name)}recalculateTime(){this.api.main.recalculateTimes([{name:"all"}])}recalculateFromTo(t,e=!1){const o=t.period;if((t=Object.assign({},t)).from=+t.from,t.to=+t.to,t.fromDate=this.date(t.from).startOf(o),t.from=t.fromDate.valueOf(),t.toDate=this.date(t.to).endOf(o),t.to=t.toDate.valueOf(),!t.autoExpandTimeFromItems||t.calculatedZoomMode)return t;let a=Number.MAX_SAFE_INTEGER,i=0;const s=this.state.get("config.chart.items");if(Object.keys(s).length>0&&(0===t.from||0===t.to||e)){for(const t in s){const e=s[t];e.time.start<a&&e.time.start&&(a=e.time.start),e.time.end>i&&(i=e.time.end)}a<t.from&&(t.fromDate=this.date(a).startOf(o),t.from=t.fromDate.valueOf()),i>t.to&&(t.toDate=this.date(i).endOf(o),t.to=t.toDate.valueOf())}return t}getCenter(t){return t.leftGlobal+Math.round((t.rightGlobal-t.leftGlobal)/2)}isInCurrentView(t,e=this.state.get("$data.chart.time")){const o=t.valueOf();return!(o<e.leftGlobal||o>e.rightGlobal)}recalculateDatesWidths(t,e=this.state.get("$data.chart.time")){if(!e.timePerPixel)throw new Error("[gantt-schedule-timeline-calendar] No timePerPixel");for(const o of t){if(!o.leftGlobal||!o.rightGlobal)throw new Error("[gantt-schedule-timeline-calendar] No date leftGlobal or rightGlobal.");o.width=(o.rightGlobal+1-o.leftGlobal)/e.timePerPixel}return t}recalculateDatesPositions(t,e=this.state.get("$data.chart.time"),o=!0,a=!1){let i=0;if(o)for(const o of t){if(o.leftGlobal>=e.leftGlobal)break;if(isNaN(o.width))throw new Error("[gantt-schedule-timeline-calendar] NaN date width.");i-=o.width}for(let o of t){if(a&&(o=this.api.mergeDeep({},o)),o.leftPx=i,o.rightPx=i+o.width,isNaN(o.leftPx)||isNaN(o.rightPx))throw new Error("[gantt-schedule-timeline-calendar] Date leftPx or rightPx is a NaN.");o.currentView&&(o.currentView.leftPx=o.leftPx-e.leftPx,o.currentView.rightPx=o.rightPx-e.leftPx,o.currentView.width=o.currentView.rightPx-o.currentView.leftPx),i+=o.width}return t}setDatesCacheLevel(t,e,o=this.state.get("$data.chart.time")){if(!e.length)return;o.datesCache||(o.datesCache={timePerPixel:0,levels:[]}),o.datesCache.timePerPixel=o.timePerPixel,o.datesCache.levels[t]||(o.datesCache.levels[t]={leftTime:0,rightTime:0,dates:[]});const a=o.datesCache.levels[t];a.leftTime=e[0].leftGlobal,a.rightTime=e[e.length-1].rightGlobal,a.dates=[...e]}addDatesToCacheLevel(t,e,o=this.state.get("$data.chart.time")){if(!e.length)return;if(!o.datesCache)return;if(o.datesCache.timePerPixel!==o.timePerPixel)return e;const a=e[0],i=e[e.length-1],s=o.datesCache.levels[t];if(!s)return e;if(s.leftTime<=a.leftGlobal&&s.rightTime>=i.rightGlobal)return s.dates;if(s.dates.length>=1e6)throw new Error("[gantt-schedule-timeline-calendar] To many dates.");const n=[];if(a.leftGlobal<s.leftTime){for(const t of e){if(!(t.leftGlobal<s.leftTime))break;n.push(t)}s.leftTime=n[0].leftGlobal}for(const t of s.dates)n.push(t);if(i.rightGlobal>s.rightTime){for(const t of e)t.rightGlobal>s.rightTime&&n.push(t);s.rightTime=n[n.length-1].rightGlobal}return s.dates=n,s.dates}isLevelDateInCache(t,e,o=this.state.get("$data.chart.time")){if(!o.datesCache)return!1;if(o.datesCache.timePerPixel!==o.timePerPixel)return!1;const a=o.datesCache.levels[t];return!(!a||!a.dates.length)&&(e>=a.leftTime&&e<=a.rightTime)}getLevelDatesFromCache(t,e,o,a=this.state.get("$data.chart.time")){if(a.datesCache.timePerPixel!==a.timePerPixel)return[];const i=a.datesCache.levels[t];if(!i)return[];if(!(e>=i.leftTime&&o<=i.rightTime))return[];let s=0,n=0,l=!1;const r=i.dates.length;for(;n<r;n++){const t=i.dates[n];if(t.rightGlobal>=e&&(l=!0),t.rightGlobal>=o)break;l||s++}return{[Symbol.iterator](){let t=s;return{next:()=>t<=n?{value:i.dates[t++],done:!1}:(t=s,{done:!0})}},length:n-s+1}}getLevelDateFromCache(t,e,o=this.state.get("$data.chart.time")){if(!this.isLevelDateInCache(t,e,o))return null;for(const a of o.datesCache.levels[t].dates)if(a.rightGlobal>=e)return a;return null}getAllLevelDatesFromCache(t,e=this.state.get("$data.chart.time")){return e.datesCache.levels[t].dates}findOrCreateMainDateAtTime(t,e=this.state.get("$data.chart.time")){if(this.isLevelDateInCache(e.level,t,e))return this.getLevelDateFromCache(e.level,t,e);let o=[];e.datesCache.levels[e.level]&&(o=e.datesCache.levels[e.level].dates),o=this.addMissingDates(o,this.date(t),e);for(const e of o)if(e.rightGlobal>=t)return e;return null}addMissingDates(t,e,o=this.state.get("$data.chart.time"),a=!0){if(!t.length)return[];const i=t[0],s=t[t.length-1];if(!(e.valueOf()<i.leftGlobal||e.valueOf()>s.rightGlobal))return t;if(this.isLevelDateInCache(o.level,e.valueOf(),o))return this.getAllLevelDatesFromCache(o.level,o);const n=t.length;let l=t;if(a){l=new Array(n);for(let e=0;e<n;e++)l[e]=this.api.mergeDeep({},t[e])}const r=this.state.get(`config.chart.calendarLevels.${o.level}`),c=this.getCurrentFormatForLevel(r,o);let d=1;if("number"==typeof c.periodIncrement&&(d=c.periodIncrement),e.valueOf()<i.leftGlobal){if("function"==typeof c.periodIncrement)return t;const s=i.leftGlobalDate.subtract(1,"ms");let n=i.leftGlobalDate.subtract(d,o.period).startOf(o.period);for(;e.valueOf()<n.valueOf();)n=n.subtract(d,o.period).startOf(o.period);let r=[];do{r=this.generatePeriodDates({leftDate:n,rightDate:s,period:o.period,level:this.state.get(`config.chart.calendarLevels.${o.level}`),levelIndex:o.level,callOnDate:!0,callOnLevelDates:!0,time:o}),n=n.subtract(1,o.period)}while(!r.length||r[0].leftGlobal>e.valueOf());return r=r.filter((t=>!l.find((e=>e.leftGlobal===t.leftGlobal)))),t=[...r,...l],t=this.recalculateDatesWidths(t,o),t=this.recalculateDatesPositions(t,o,!0,a),this.addDatesToCacheLevel(o.level,t,o)}if(e.valueOf()>s.rightGlobal){let i=s.rightGlobalDate.add(d,o.period).endOf(o.period);for(;e.valueOf()>i.valueOf();)i=i.add(d,o.period).endOf(o.period);let n=this.generatePeriodDates({leftDate:s.rightGlobalDate.add(1,"ms"),rightDate:i,period:o.period,level:this.state.get(`config.chart.calendarLevels.${o.level}`),levelIndex:o.level,callOnDate:!0,callOnLevelDates:!0,time:o});return n=n.filter((t=>!l.find((e=>e.leftGlobal===t.leftGlobal)))),t=[...l,...n],t=this.recalculateDatesWidths(t,o),t=this.recalculateDatesPositions(t,o,!0,a),this.addDatesToCacheLevel(o.level,t,o)}return l}getGlobalOffsetPxFromDates(t,e=!0,o=this.state.get("$data.chart.time"),a=void 0){const i=t.valueOf();if(!o.allDates||0===o.allDates.length)return-100;if(void 0===a&&(a=o.allDates[o.level]),e&&(a=this.addMissingDates(a,t,o)),!a||0===a.length)return-1;let s;for(let t=0,e=a.length;t<e;t++){const e=a[t];if(i<=e.rightGlobal+1){s=e;break}}return s?i<s.leftGlobal?s.leftPx:s.rightPx-(s.rightGlobal-i)/o.timePerPixel:i<=o.leftGlobal?0:i>=o.rightGlobal?o.totalViewDurationPx+(i-o.rightGlobal+1)/o.timePerPixel:-1}getViewOffsetPxFromDates(t,e=!0,o=this.state.get("$data.chart.time"),a=void 0,i=!0){a||(a=o.allDates[o.level]),i&&(a=this.addMissingDates(a,t,o));const s=this.getDatesDiffPx(o.leftGlobalDate,t,o,!0,a);return e?this.limitOffsetPxToView(s):s}limitOffsetPxToView(t,e=this.state.get("$data.chart.time")){if(t<0)return 0;if(!e.levels.length)return e.width;const o=e.levels[e.level];if(!o.length)return e.width;const a=o[o.length-1];return t>a.currentView.rightPx?a.currentView.rightPx:t}findDateAtViewOffsetPx(t,e){return e.find((e=>e.currentView.rightPx>=t))}findDateIndex(t,e){let o=0;for(const a of e){if(a.rightGlobal>=t)return o;o++}return-1}findDateAtTime(t,e=void 0){if(!e){const t=this.state.get("$data.chart.time");e=t.allDates[t.level]}return e.find((e=>e.rightGlobal>=t))}getMainDateFromRelativePosition(t,e){const o=t.leftPx+e,a=this.state.get("$data.chart.time"),i=a.allDates[a.level];for(const t of i)if(t.rightPx>o)return t}getTimeFromOffsetPx(t,e=!0,o=this.state.get("$data.chart.time"),a=void 0){let i=t;e&&(i+=o.leftPx),a||(a=o.allDates[o.level]);const s=this.state.get(`config.chart.calendarLevels.${o.level}`),n=this.getCurrentFormatForLevel(s,o);let l=1;if("number"==typeof n.periodIncrement&&(l=n.periodIncrement),i<0){if("function"==typeof n.periodIncrement)return o.from;let t,e=o.fromDate.subtract(l,o.period).startOf(o.period),a=0;for(let s=0;s<1e3;s++){const s=this.generatePeriodDates({leftDate:e,rightDate:e.add(l,o.period).subtract(1,"ms"),period:o.period,time:o,level:this.state.get(`config.chart.calendarLevels.${o.level}`),levelIndex:o.level,callOnDate:!0,callOnLevelDates:!0,expandIfMissing:!1});if(s.length&&(t=s[0],a-=t.width,a<=i))return t.leftGlobal+(i-a)*o.timePerPixel;e=e.subtract(l,o.period).startOf(o.period)}}else if(i>o.totalViewDurationPx){let t,e=o.toDate.add(1,o.period).startOf(o.period),a=o.totalViewDurationPx;for(let s=0;s<1e3;s++){const s=this.generatePeriodDates({leftDate:e,rightDate:e.add(l,o.period).subtract(1,"ms"),period:o.period,time:o,level:this.state.get(`config.chart.calendarLevels.${o.level}`),levelIndex:o.level,callOnDate:!0,callOnLevelDates:!0,expandIfMissing:!1});if(s.length&&(t=s[0],a+=t.width,a>i))return t.rightGlobal+1-(a-i)*o.timePerPixel;e=e.add(l,o.period).startOf(o.period)}}for(let t=0,e=a.length;t<e;t++){const e=a[t];if(e.rightPx>i){const t=(e.rightPx-i)*o.timePerPixel;return e.rightGlobal+1-t}}const r=a[a.length-1];return r.rightGlobal+1-(r.rightPx-i)*o.timePerPixel}getCurrentFormatForLevel(t,e){return t.find((t=>+e.zoom<=+t.zoomTo))}alignLevelToMain(t,e,o=this.state.get("$data.chart.time")){if(t===o.level)return e;if(!this.state.get("config.chart.time.alignLevelsToMain"))return e;const a=o.allDates[o.level];if(!a||!a.length)return e;if(!e||!e.length)return e;const i=e.length;for(let t=0;t<i;t++){const i=e[t];let s,n=!1,l=0;for(const t of a){if(t.rightGlobal>=i.leftGlobal){if(!n)if(t.leftGlobal>=i.leftGlobal)i.leftGlobal=t.leftGlobal,i.leftGlobalDate=this.date(i.leftGlobal),i.leftPx=t.leftPx;else{const e=(t.rightGlobal-i.leftGlobal)/o.timePerPixel;l=-(t.width-e)}n=!0}if(t.leftGlobal>i.rightGlobal)break;n&&(l+=t.width,s=t)}if(s)if(s.rightGlobal<=i.rightGlobal)i.rightGlobal=s.rightGlobal,i.rightGlobalDate=this.date(i.rightGlobal),i.width=l,i.rightPx=i.leftPx+i.width;else{const t=(s.rightGlobal-i.rightGlobal)/o.timePerPixel;i.width=l-t,i.rightPx=i.leftPx+i.width}}return e}stopCheckingCurrentDates(){this.checkCurrentDateTimeoutId&&clearTimeout(this.checkCurrentDateTimeoutId)}checkCurrentDates(t=!1,e=this.state.get("$data.chart.time")){const o=this.date().valueOf(),a=e.checkCurrentDateInterval;if(this.stopCheckingCurrentDates(),t&&(this.checkCurrentDateTimeoutId=setTimeout((()=>{this.checkCurrentDates(t,e)}),a)),o-this.currentDateLastCheck<a)return;const i=e.allDates;let s=!1;for(const t of i){const e=t.length;for(let a=0;a<e;a++){const i=t[a],n=i.current;i.current=!1,i.previous=!1,i.next=!1,i.leftGlobal<=o&&i.rightGlobal>=o&&(!0!==n&&(s=!0),i.current=!0,a>0&&(t[a-1].previous=!0),a+1<e&&(t[a+1].next=!0))}}this.currentDateLastCheck=o,s&&this.state.update("$data.chart.time.levels",(t=>t),{data:"current-time"}),this.api.render()}getDSTDiffForLevel(t,e,o,a=this.state.get("$data.chart.time")){const i=this.api.time.getLevelDatesFromCache(t,e,o,a);let s=0;for(const t of i)t.DST.diffMs&&e<=t.DST.afterTime&&o>t.DST.afterTime&&(s+=t.DST.diffMs);return s}setDatesDST(t){for(const e of t){const t=e.rightGlobal-e.leftGlobal,o=e.rightGlobalDate.utc(!0).valueOf()-e.leftGlobalDate.utc(!0).valueOf();if(t!==o){e.DST={diffMs:t-o,afterTime:0,afterDate:null};for(let t=0;t<9216;t++)if(e.leftGlobalDate.add(t,"hour").hour()!==e.leftGlobalDate.utc(!0).add(t,"hour").hour()){e.DST.afterDate=e.leftGlobalDate.add(t,"hour").subtract(1,"ms"),e.DST.afterTime=e.DST.afterDate.valueOf();break}}}return t}_generatePeriodDates(t){const e=[];t=Object.assign({},t);const{datesCount:o,rightDate:a,period:i,level:s,levelIndex:n,time:l,originalLeftDate:r,format:c}=t;let d=t.leftDate;const h=this.date().valueOf();for(let t=0;t<o;t++){let t=c.periodIncrement||1;"function"==typeof t&&(t=t({currentDates:e,date:d,leftDate:r,rightDate:a,period:i,level:s,levelIndex:n,time:l,vido:this.api.vido,api:this.api}));const o=d.add(t-1,i).endOf(i),u=d.valueOf()<=h&&o.valueOf()>=h,m={id:`gstcid-${d.valueOf()}`,leftGlobal:d.valueOf(),leftGlobalDate:d,rightGlobalDate:o,rightGlobal:o.valueOf(),width:0,leftPx:0,rightPx:0,period:i,formatted:null,current:u,previous:!1,next:!1,periodIncrementedBy:t,DST:{diffMs:0,afterTime:0,afterDate:null}};u&&e.length&&(e[e.length-1].previous=!0),e.length&&e[e.length-1].current&&(m.next=!0);const g=m.rightGlobal+1-m.leftGlobal;m.width=g/l.timePerPixel,e.push(m),d=d.add(t||1,i)}return this.setDatesDST(e)}generatePeriodDates({leftDate:t,rightDate:e,period:o,level:a,levelIndex:i,time:s,callOnDate:n,callOnLevelDates:l,expandIfMissing:r=!0}){if(!s.timePerPixel)return[];const c=this.getCurrentFormatForLevel(a,s);t=t.startOf(o),e=e.endOf(o);const d=Math.ceil(e.diff(t,o,!0)),h=t.clone();let u=this._generatePeriodDates({datesCount:d,leftDate:t,rightDate:e,period:o,level:a,levelIndex:i,time:s,originalLeftDate:h,format:c});if(n){const t=[];for(let e=0;e<u.length;e++){let o=u[e];if(o){for(let t=0,e=s.onDate.length;t<e;t++)o=s.onDate[t]({date:o,format:c,time:s,level:a,levelIndex:i});o&&t.push(o)}}u=t}if(l)for(let t=0,e=s.onLevelDates.length;t<e;t++)u=s.onLevelDates[t]({dates:u,format:c,time:s,level:a,levelIndex:i});if((!u.length||u[u.length-1].rightGlobal<e.valueOf())&&r){let r=this._generatePeriodDates({datesCount:d+100,leftDate:t,rightDate:e,period:o,level:a,levelIndex:i,time:s,originalLeftDate:h,format:c});if(n){const t=[];for(let e=0;e<r.length;e++){let o=r[e];if(o){for(let t=0,e=s.onDate.length;t<e;t++)o=s.onDate[t]({date:o,format:c,time:s,level:a,levelIndex:i});o&&t.push(o)}}r=t}if(l)for(let t=0,e=s.onLevelDates.length;t<e;t++)r=s.onLevelDates[t]({dates:r,format:c,time:s,level:a,levelIndex:i});const u=[];for(const t of r)if(u.push(t),t.rightGlobal>=e.valueOf())return u}this.addDatesToCacheLevel(i,u,s);const m=[];for(const t of u)if(m.push(t),t.rightGlobal>=e.valueOf())return m;return m}getDatesDiffPx(t,e,o,a=!0,i=void 0){if(t.valueOf()===e.valueOf())return 0;let s,n,l=0,r=!1;if(e.valueOf()<t.valueOf()){const o=t;t=e,e=o,r=!0}if(void 0===i){if(!o.allDates||!o.allDates.length||!o.allDates[o.level])return 0;i=o.allDates[o.level]}if(0===i.length)return 0;if(this.isLevelDateInCache(o.level,t.valueOf(),o)?i=this.getAllLevelDatesFromCache(o.level,o):t.valueOf()<i[0].leftGlobal&&(i=this.addMissingDates(i,t,o)),this.isLevelDateInCache(o.level,e.valueOf(),o))i=this.getAllLevelDatesFromCache(o.level,o);else{const t=i[i.length-1].rightGlobalDate.clone();e.valueOf()>t.valueOf()&&(i=this.addMissingDates(i,e,o))}this.addDatesToCacheLevel(o.level,i,o);let c=!1,d=0;for(const o of i)if(o.rightGlobal+1>=t.valueOf()&&!c&&(c=!0,n=o),c&&(l+=o.width),o.rightGlobal+1>=e.valueOf()){s=o,d=o.width;break}if(a){let a=t.valueOf()-n.leftGlobal;t.valueOf()<n.leftGlobal&&(a=0);let i=s.rightGlobal+1-e.valueOf();s.leftGlobal>e.valueOf()&&(i=s.rightGlobal+1-s.leftGlobal);const c=(i+a)/o.timePerPixel;return r?-(l-c):l-c}return l-=d,r?-l:l}getDatesDiffMs(t,e,o,a=!0,i=void 0){if(t.valueOf()===e.valueOf())return 0;let s,n,l=0,r=!1;if(e.valueOf()<t.valueOf()){const o=t;t=e,e=o,r=!0}if(void 0===i){if(!o.allDates||!o.allDates.length||!o.allDates[o.level])return 0;i=o.allDates[o.level]}if(0===i.length)return 0;if(this.isLevelDateInCache(o.level,t.valueOf(),o)?i=this.getAllLevelDatesFromCache(o.level,o):t.valueOf()<i[0].leftGlobal&&(i=this.addMissingDates(i,t,o)),this.isLevelDateInCache(o.level,e.valueOf(),o))i=this.getAllLevelDatesFromCache(o.level,o);else{const t=i[i.length-1].rightGlobalDate.clone();e.valueOf()>t.valueOf()&&(i=this.addMissingDates(i,e,o))}this.addDatesToCacheLevel(o.level,i,o);let c=!1,d=0;for(const o of i)if(o.rightGlobal+1>=t.valueOf()&&!c&&(c=!0,n=o),c&&(l+=o.rightGlobal+1-o.leftGlobal),o.rightGlobal+1>=e.valueOf()){s=o,d=o.rightGlobal+1-o.leftGlobal;break}if(a){let o=t.valueOf()-n.leftGlobal;t.valueOf()<n.leftGlobal&&(o=0);let a=s.rightGlobal+1-e.valueOf();s.leftGlobal>e.valueOf()&&(a=s.rightGlobal+1-s.leftGlobal);const i=a+o;return r?-(l-i):l-i}return l-=d,r?-l:l}addTimeFromDates(t,e,o=this.state.get("$data.chart.time")){if(!o.allDates||!o.allDates.length||!o.allDates[o.level])return t+e;if(!e)return t;let a=this.getAllLevelDatesFromCache(o.level,o);const i=this.date(t);a=this.addMissingDates(a,i,o,!0);let s=this.findDateIndex(t,a),n=t-a[s].leftGlobal;n<0&&(n=0);let l=0;if(e>0){for(;l<e;){const t=a[s];if(l+=t.rightGlobal+1-t.leftGlobal,n&&(l-=n,n=0),l>=e)break;s++,a[s]||(a=this.addMissingDates(a,t.leftGlobalDate.add(1,o.period),o,!0))}return a[s].rightGlobal+1-(l-e)}for(;l>e;){let t=a[s];if(l-=n,n&&(n=0),l<=e)break;if(s--,s<0&&(a=this.addMissingDates(a,t.leftGlobalDate.subtract(1,o.period),o,!0),s=0),t=a[s],l-=t.rightGlobal+1-t.leftGlobal,l<=e)break}return a[s].leftGlobal+(-l+e)}getLeftViewDate(t=this.state.get("$data.chart.time")){if(!t.levels||!t.levels.length)return null;const e=t.levels[t.level];return e.length?e[0]:null}getRightViewDate(t=this.state.get("$data.chart.time")){if(!t.levels||!t.levels.length||!t.levels[t.level])return null;const e=t.levels[t.level];return e.length?e[e.length-1]:null}getLowerPeriod(t){switch(t){case"year":return"month";case"month":case"week":return"day";case"day":return"hour";case"hour":return"minute";case"minute":return"second";case"second":return"millisecond";default:return t}}getHigherPeriod(t){switch(t){case"month":return"year";case"week":case"day":return"month";case"hour":return"day";case"minute":return"hour";case"second":return"minute";case"millisecond":return"second";default:return t}}}
/**
* Gantt-Schedule-Timeline-Calendar IDApi
*
* @copyright NEURONET - Rafal Pospiech
* @author Rafal Pospiech <neuronet.io@gmail.com>
* @module gantt-schedule-timeline-calendar
* @link https://github.com/neuronetio/gantt-schedule-timeline-calendar
* @link https://gantt-schedule-timeline-calendar.neuronet.io
* @version 3.37.5
* @released 2024-07-19
* @license SEE LICENSE IN LICENSE FILE
*/var D=new class{constructor(){this.GSTCID=this.GSTCID.bind(this),this.isGSTCID=this.isGSTCID.bind(this),this.sourceID=this.sourceID.bind(this)}GSTCID(t){return this.isGSTCID(t)?t:`gstcid-${t}`}isGSTCID(t){return String(t).startsWith("gstcid-")}sourceID(t){return this.isGSTCID(t)?t.substring(7):t}};
/**
* Gantt-Schedule-Timeline-Calendar Slots
*
* @copyright NEURONET - Rafal Pospiech
* @author Rafal Pospiech <neuronet.io@gmail.com>
* @module gantt-schedule-timeline-calendar
* @link https://github.com/neuronetio/gantt-schedule-timeline-calendar
* @link https://gantt-schedule-timeline-calendar.neuronet.io
* @version 3.37.5
* @released 2024-07-19
* @license SEE LICENSE IN LICENSE FILE
*/class y extends a{constructor(t,e,o){super(e,o),this.subs=[],this.name=t,this.subs.push(e.state.subscribe(`config.slots.${t}`,this.setComponents,{queue:!0}))}destroy(){this.subs.forEach((t=>t())),super.destroy()}getName(){return this.name}}function P(t,e,o){return new y(t,e,o)}
/**
* Gantt-Schedule-Timeline-Calendar helpers
*
* @copyright NEURONET - Rafal Pospiech
* @author Rafal Pospiech <neuronet.io@gmail.com>
* @module gantt-schedule-timeline-calendar
* @link https://github.com/neuronetio/gantt-schedule-timeline-calendar
* @link https://gantt-schedule-timeline-calendar.neuronet.io
* @version 3.37.5
* @released 2024-07-19
* @license SEE LICENSE IN LICENSE FILE
*/const x="gstc";function W(t,e=""){let o=`${x}__${t}`;return t===x&&(o=x),e?`${o} ${o}--${e.replace(":","-")}`:o}function C(t,e){let o=`${x}__${t}`;return t===x&&(o=x),`${o}--${e}`}
/**
* Api functions
*
* @copyright NEURONET - Rafal Pospiech
* @author Rafal Pospiech <neuronet.io@gmail.com>
* @module gantt-schedule-timeline-calendar
* @link https://github.com/neuronetio/gantt-schedule-timeline-calendar
* @link https://gantt-schedule-timeline-calendar.neuronet.io
* @version 3.37.5
* @released 2024-07-19
* @license SEE LICENSE IN LICENSE FILE
*/let $=0;const I=new Map;function S(t){return I.get(t.apiId)}class M{constructor(t){this.apiId=0,this.name=x,this.debug=!1,this.plugins={},this.iconsCache={},this.unsubscribes=[],this.mutedMethods=new Set,this.mergeDeep=null,this.generateSlots=P,this.getClass=W,this.getId=C,this.GSTCID=D.GSTCID,this.isGSTCID=D.isGSTCID,this.sourceID=D.sourceID,this.allActions=[],this.keysToKeep=["id","parents","children","allChildren","parentId"],this.apiId=++$,I.set(this.apiId,{rowsDataWithParentsExpanded:[],rowsIdsWithParentsExpanded:[],rowsWithParentsExpanded:[],rowsWithParentsExpandedAsMap:new Map,rowsPositionsMap:{id:"",dataIndex:0,keys:[]},allRowsIds:[],allRowsAsArray:[],rowsWithParentsExpandedDataIndexMap:new Map,itemsAsArray:[],itemsDataAsArray:[]}),this.state=t,this.time=new v(this.state,this),this.unsubscribes.push(this.state.subscribe("config.debug",(t=>this.debug=t))),this.debug&&(window.state=t)}render(){return this.vido.update()}getListenerPosition(t){for(const e of this.state.getListeners().values())for(const o of e.listeners)if(o[1].fn===t)return o[0]}setVido(t){this.vido=t}clone(t){return this.mergeDeep({},t)}setMergeDeep(t){this.mergeDeep=t}log(...t){this.debug&&console.log.call(console,...t)}getInitializedPlugins(){return this.state.get("$data.initializedPlugins")}pluginInitialized(t){this.getInitializedPlugins().add(t)}pluginDestroyed(t){this.getInitializedPlugins().delete(t)}clearPluginsPositions(){this.getInitializedPlugins().clear()}isPluginInitialized(t){return this.getInitializedPlugins().has(t)}getPluginPosition(t){return[...this.getInitializedPlugins()].indexOf(t)}getPluginsPositions(){const t={};let e=0;for(const o of this.getInitializedPlugins())t[o]=e++;return t}isPluginInitializedBefore(t,e){return this.getPluginPosition(t)<this.getPluginPosition(e)}getActions(t){this.allActions.includes(t)||this.allActions.push(t);let e=this.state.get("config.actions."+t);return void 0===e&&(e=[]),e.slice()}isItemInViewport(t,e=void 0,o=void 0){if(!e||!o){const t=this.state.get("config.chart.time");e=t.leftGlobal,o=t.rightGlobal}return t.time.start<=o&&t.time.end>=e}getChildrenLinkedItemsIds(t,e,o=[]){const a=e[t];if(a.linkedWith&&a.linkedWith.length){o.includes(t)||o.push(t);for(const t of a.linkedWith){if(o.includes(t))continue;o.push(t);const a=e[t];a.linkedWith&&a.linkedWith.length&&this.getChildrenLinkedItemsIds(t,e,o)}}return o}collectAllLinkedItems(t,e){const o=Object.keys(t),a=Object.keys(e),i=o.filter((t=>!a.includes(t)));if(i.length)throw new Error(`Items with id [${i.join(", ")}] does not exists in "$data.chart.items". TIP: For performance reasons, state is mutable, so try not to modify items from the "state.get" method before you copy them (with "gstc.api.clone(items)" for example).`);for(const o in t){const a=t[o];e[a.id].linkedWith=a.linkedWith||[]}const s=new Map;for(const t in e){if(s.has(t))continue;const o=this.getChildrenLinkedItemsIds(t,e);e[t].linkedWith.splice(e[t].linkedWith.length,0,...o);const a=Array.from(new Set(e[t].linkedWith));e[t].linkedWith=a.filter((e=>e!==t)),s.set(t,!0);for(const t of a)e[t].linkedWith=a.filter((e=>e!==t)),s.set(t,!0)}}getChildrenDependantItemsIds(t,e,o=[]){if(t.dependant&&t.dependant.length)for(const a of t.dependant){if(o.includes(a))continue;o.push(a);const i=e[a];if(!i)throw new Error(`Dependant item not found [id:'${a}'] found in item [id:'${t.id}']`);i.dependant&&i.dependant.length&&this.getChildrenDependantItemsIds(i,e,o)}return o}calculateItemVerticalPosition(t,e=null,o=null,a=null){if(a||(a=this.getItem(t)),e||(e=this.getItemData(t)),o||(o=this.getRowData(a.rowId)),a.gap&&e||(this.prepareItem(a),e=this.getItemData(t)),!o)return e.position;const i=o.position.top+a.gap.top,s=e.position.rowTop+a.gap.top,n=this.getRowViewTop(o.id);let l=n+e.position.actualRowTop;return n===1/0?l=1/0:-1===n&&(l=-1),e.position.top=i,e.position.actualRowTop=s,e.position.viewTop=l,e.position}setItemDataOutOfView(t,e=this.state.get("$data.chart.time")){t.outOfView||(t.outOfView={left:!1,right:!1,whole:!1});const o=t.time.startDate.valueOf(),a=t.time.endDate.valueOf();return t.outOfView.left=o<e.leftGlobal||o>=e.rightGlobal,t.outOfView.right=a>e.rightGlobal||a<=e.leftGlobal,t.outOfView.whole=a<=e.leftGlobal||o>=e.rightGlobal,t}calculateItemHorizontalPosition(t,e=null,o=null,a=this.state.get("$data.chart.time"),i=null){if(i||(i=this.getItem(t)),e||(e=this.getItemData(t)),o||(o=this.getRowData(i.rowId)),!o)return e.position;if(this.state.get("$data.chart.allItemsOnTheLeftOrRight"))return;const s=e.time.startDate.valueOf()===i.time.start?e.time.startDate:this.time.date(i.time.start),n=e.time.endDate.valueOf()===i.time.end?e.time.endDate:this.time.date(i.time.end),l=this.time.getViewOffsetPxFromDates(s,!1,a),r=this.time.getViewOffsetPxFromDates(n.add(1,"ms"),!1,a);e.position.left=l,e.position.actualLeft=this.time.limitOffsetPxToView(l,a),e.position.right=r,e.position.actualRight=this.time.limitOffsetPxToView(r,a),e.width=r-l;let c=this.time.getViewOffsetPxFromDates(n,!1,a);c===r&&(c-=1/a.timePerPixel),e.timeWidth=c-l,e.actualWidth=e.position.actualRight-e.position.actualLeft;const d=this.state.get("config.chart.item.minWidth");return"number"==typeof d&&e.actualWidth<d&&(e.actualWidth=d),this.setItemDataOutOfView(e,a),e.position}calculateItemPosition(t,e=null,o=null,a=this.state.get("$data.chart.time"),i=null){return e||(e=this.state.get(`$data.chart.items.${t}`)),i||(i=this.state.get(`config.chart.items.${t}`)),o||(o=this.state.get(`$data.list.rows.${i.rowId}`)),this.calculateItemHorizontalPosition(t,e,o,a,i),this.calculateItemVerticalPosition(t,e,o,i),e.position}getItemPosition(t,e=null,o=null,a=this.state.get("$data.chart.time"),i=null){return i||(i=this.getItem(t)),e||(e=this.getItemData(t)),0===e.position.left&&0===e.position.right&&this.calculateItemPosition(t,e,o,a,i),e.position}getRow(t){return this.state.get(`config.list.rows.${t}`)}getRows(t){if(!t.length)return[];const e=this.getAllRows(),o=[];for(const a of t)e[a]&&o.push(e[a]);return o}getAllRows(){return this.state.get("config.list.rows")}getVisibleRowsId(){return this.state.get("$data.list.visibleRows")}getRowsData(){return this.state.get("$data.list.rows")}setRowsData(t){this.state.update("$data.list.rows",t)}getRowData(t){return this.state.get(`$data.list.rows.${t}`)}setRowData(t,e){this.state.update(`$data.list.rows.${t}`,e)}getItem(t){return this.state.get(`config.chart.items.${t}`)}getItems(t=[]){const e=[],o=this.getAllItems();for(const a of t)o[a]&&e.push(o[a]);return e}getAllItemsAsArray(){return S(this).itemsAsArray}getAllItemsDataAsArray(){return S(this).itemsDataAsArray}getAllItems(){return this.state.get("config.chart.items")}getItemData(t){return this.state.get(`$data.chart.items.${t}`)}getItemsData(){return this.state.get("$data.chart.items")}setItemData(t,e){this.state.update(`$data.chart.items.${t}`,(t=>{for(const o in e)t[o]=e[o];return t}))}setItemsData(t){this.state.update("$data.chart.items",t)}prepareDependantItems(t,e){return this.getChildrenDependantItemsIds(t,e).filter((e=>e!==t.id))}prepareItem(t,e=this.state.get("config.chart.item.height"),o=this.getItemsData(),a=this.getAllItems(),i=this.getAllRows()){let s=t.id;if(s=String(s),t.id=s,o[t.id]||(o[t.id]={id:t.id,actualHeight:0,outerHeight:0,time:null,position:{left:0,actualLeft:0,right:0,actualRight:0,rowTop:t.rowTop||0,actualRowTop:t.actualRowTop||0,top:0,viewTop:0},outOfView:{left:!1,right:!1,whole:!1},width:-1,actualWidth:-1,timeWidth:-1,detached:!1,linkedWith:[],dependant:this.getChildrenDependantItemsIds(t,a)}),t.time||console.error("There is something wrong with this item.",t),"number"!=typeof t.time.start||"number"!=typeof t.time.end)throw new Error('[gantt-schedule-timeline-calendar] Item "time.start" and "time.end" values should be a number (unix epoch milliseconds).');const n=t.rowId;if("string"!=typeof n)throw new Error('[gantt-schedule-timeline-calendar] Item "rowId" should be a string.');if(!n.startsWith("gstcid-"))throw new Error('[gantt-schedule-timeline-calendar] Item "rowId" should start with "gstcid-".');if(!i[n])throw new Error(`[gantt-schedule-timeline-calendar] Row for item "${t.id}" does not exists ("${n}"). TIP: Try updating the rows first to make sure the rows for the items exist.`);t.time.start=+t.time.start,t.time.end=+t.time.end,t.id=String(t.id);const l=this.state.get("config.chart.item");"number"!=typeof t.height&&(t.height=e),o[t.id].time={startDate:this.time.date(t.time.start),endDate:this.time.date(t.time.end)},o[t.id].actualHeight=t.height,void 0===t.overlap&&(t.overlap=l.overlap),"number"!=typeof t.top&&(t.top=0),t.gap||(t.gap={}),"number"!=typeof t.gap.top&&(t.gap.top=l.gap.top),"number"!=typeof t.gap.bottom&&(t.gap.bottom=l.gap.bottom),"number"!=typeof t.minWidth&&(t.minWidth=l.minWidth),o[t.id].outerHeight=o[t.id].actualHeight+t.gap.top+t.gap.bottom,o[t.id].position.actualRowTop=o[t.id].position.rowTop+t.gap.top}prepareItems(t){const e=this.state.get("config.chart.item.height"),o=this.getItemsData(),a=S(this);a.itemsAsArray.length=0,a.itemsDataAsArray.length=0;for(const i in t){const s=t[i];this.prepareItem(s,e,o,t),a.itemsAsArray.push(t[i]),a.itemsDataAsArray.push(o[i])}return this.collectAllLinkedItems(t,o),t}sortRowsByChildren(t,e={},o=this.state.get("config.list.rows"),a=this.state.get("$data.list.rows")){for(const i of t){const t=o[i],s=a[i],n=t.parentId&&e[t.parentId]||!t.parentId;!e[i]&&n&&(e[i]=t),s.children.length&&this.sortRowsByChildren(s.children,e,o,a)}return e}getSortableValue(t,e){return"string"==typeof t?e[t]:"function"==typeof t?t({row:e,vido:this.vido}):""}sortRowsByColumn(t,e=!0){const o=this.state.get("config.list.sort.compare");let a=this.getAllRows();const i=S(this);if(0===i.allRowsIds.length)return a;const s=i.allRowsAsArray;o?s.sort(o(t)):s.sort(((o,a)=>{const i=this.getSortableValue(t.sortable,o),s=this.getSortableValue(t.sortable,a);return"number"==typeof i?e?i-s:s-i:"string"==typeof i?e?i.localeCompare(s):s.localeCompare(i):void 0}));const n=s.map((t=>t.id)),l=this.getRowsData();for(const t of n){const e=l[t];e.children&&e.children.length&&e.children.sort(((t,e)=>n.indexOf(t)-n.indexOf(e)))}a=this.sortRowsByChildren(n),this.state.update("config.list.rows",a,{data:"sortRowsByColumn"});const r=this.getScrollTop();return this.state.get("config.scroll.vertical.byPixels")?this.setScrollTop(r.absolutePosPx):this.setScrollTop(r.dataIndex,r.preciseOffset),a}fillEmptyRowValues(t){const e=this.state.get("config.list.row.height"),o=this.getRowsData();let a=0;for(let i in t){const s=t[i];let n=o[i];if(i=String(i),s.id=i,"string"!=typeof i)throw new Error('[gantt-schedule-timeline-calendar] Row "id" must be a string.');if(!i.startsWith("gstcid-"))throw new Error(`[gantt-schedule-timeline-calendar] Row "id" should start with "gstcid-" (your row id: "${i}").`);if(i.startsWith("gstcid-gstcid-"))throw new Error(`[gantt-schedule-timeline-calendar] Your row "id" is wrapped more than once. It should look like this "gstcid-something" and it looks like this: "${i}".`);o[i]||(n={id:s.id,parentId:s.parentId,parents:[],children:[],allChildren:[],position:{top:0,bottom:0},items:[],itemsOrder:[],actualHeight:0,outerHeight:0,parentsExpanded:!0,inView:!0}),"number"!=typeof s.height&&(s.height=e),n.actualHeight=s.height,"boolean"!=typeof s.expanded&&(s.expanded=!1),n.position.top=a,"object"!=typeof s.gap&&(s.gap={}),"number"!=typeof s.gap.top&&(s.gap.top=0),"number"!=typeof s.gap.bottom&&(s.gap.bottom=0),void 0===s.visible&&(s.visible=!0),n.outerHeight=n.actualHeight+s.gap.top+s.gap.bottom,o[i]=n,a+=n.outerHeight}return t}itemsOnTheSameLevel(t,e){const o=this.getItemData(t.id),a=this.getItemData(e.id),i=o.position.rowTop+o.outerHeight,s=a.position.rowTop+a.outerHeight;return a.position.rowTop<=o.position.rowTop&&s>o.position.rowTop||(a.position.rowTop>=o.position.rowTop&&a.position.rowTop<i||a.position.rowTop>=o.position.rowTop&&s<i)}itemsTimeOverlaps(t,e){return e.time.start>=t.time.start&&e.time.start<=t.time.end||(e.time.end>=t.time.start&&e.time.end<=t.time.end||(e.time.start>=t.time.start&&e.time.end<=t.time.end||e.time.start<=t.time.start&&e.time.end>=t.time.end))}itemOverlapsWithOthers(t,e){for(let o=0,a=e.length;o<a;o++){const a=e[o],i=a.time.start&&t.time.start&&a.time.end&&t.time.end;if(t.id!==a.id&&this.itemsOnTheSameLevel(t,a)&&this.itemsTimeOverlaps(t,a)&&i)return a}return null}fixOverlappedItems(t){if(this.isMutedMethod("fixOverlapped"))return;if(0===t.length)return;const e=this.getItemsData();for(const o of t){if(o.overlap)continue;const t=e[o.id];t&&(t.position.rowTop=o.top)}for(let o=0;o<t.length;o++){const a=t[o];if(a.overlap)continue;const i=e[a.id];if(!i)continue;i.position.actualRowTop=i.position.rowTop+a.gap.top;let s=this.itemOverlapsWithOthers(a,t);if(s)for(;s=this.itemOverlapsWithOthers(a,t);){const e=this.getItemData(s.id),n=t.findIndex((t=>t.id===s.id));n<o?(i.position.rowTop+=e.outerHeight,i.position.actualRowTop=i.position.rowTop+a.gap.top):(e.position.rowTop+=i.outerHeight,e.position.actualRowTop=e.position.rowTop+s.gap.top)}}}makeChildren(t,e={parents:[]}){if("object"!=typeof t)return[];t.children||(t.children=[]),t.allChildren||(t.allChildren=[]),t.parents||(t.parents=[...e.parents]),t.parentId&&"undefined"!==t.parentId&&t.parents.push(t.parentId);for(const e in t)if("id"!==e&&"parentId"!==e&&"children"!==e&&"allChildren"!==e&&"parents"!==e){"undefined"!==e&&(t.children.push(e),t.allChildren.push(e));const o=t[e];if("object"!=typeof o)continue;const a=this.makeChildren(o,t);t.allChildren.splice(t.allChildren.length,0,...a)}return t.allChildren}clearNested(t){for(const e in t)"object"!=typeof t[e]||Array.isArray(t[e])||this.clearNested(t[e]),this.keysToKeep.includes(e)||delete t[e],"parentId"===e&&"undefined"===t[e]&&(t[e]=void 0);return t}fastTree(t,e=null){var o,a;if(!e){e={undefined:{},id:"undefined"};for(const a in t){const i=t[a];e[i.id]||(e[i.id]={parentId:null!==(o=i.parentId)&&void 0!==o?o:"undefined",id:i.id})}}for(const t in e){const o=e[t];e[null!==(a=o.parentId)&&void 0!==a?a:"undefined"][o.id]=o}this.makeChildren(e[void 0]),delete e[void 0],delete e.id,delete e.parents,delete e.children,delete e.allChildren;for(const t in e)e[t]=this.clearNested(e[t]);return e}updateItemRowMapForItem(t,e,o=this.state.get("$data.itemRowMap"),a=this.state.get("$data.list.rows")){if(!a[e])return;a[e].items||(a[e].items=[]);const i=o[t];i&&a[i]&&(a[i].items=a[i].items.filter((e=>e!==t)).sort(((t,e)=>this.getItem(t).time.start-this.getItem(e).time.start))),o[t]=e,a[e].items.includes(t)||a[e].items.push(t)}sortRowItemsInAddOrder(t,e){e.itemsOrder=e.items.slice(),e.itemsOrder.sort(((e,o)=>t.indexOf(e)-t.indexOf(o)))}sortRowItemsByTime(t){t.items=t.items.sort(((t,e)=>this.getItem(t).time.start-this.getItem(e).time.start))}makeTreeMap(t,e,o=!1){let a=this.state.get("$data.treeMap");if(!o||!a){a=this.fastTree(t);for(const e in t){const o=t[e],i=a[e];for(const t in i)o[t]=i[t]}}const i=this.state.get("$data.reloading")?{}:this.state.get("$data.itemRowMap");for(const t in e){const o=e[t];this.updateItemRowMapForItem(t,o.rowId,i)}const s=Object.keys(this.state.get("config.chart.items"));for(const e in t){const o=t[e];this.sortRowItemsByTime(o),this.sortRowItemsInAddOrder(s,o)}return this.state.update("$data.itemRowMap",i),o||this.state.update("$data.treeMap",a),t}_updateRowsWithParentsExpandedCache(t){const e=S(this);e.rowsIdsWithParentsExpanded.length=0,e.rowsIdsWithParentsExpanded.splice(0,0,...t),e.rowsWithParentsExpanded.length=0,e.rowsDataWithParentsExpanded.length=0,e.rowsWithParentsExpandedDataIndexMap.clear();const o=this.state.get("config.list.rows"),a=this.state.get("$data.list.rows");e.rowsWithParentsExpandedAsMap.clear();let i=0;for(const t of e.rowsIdsWithParentsExpanded){const s=o[t];s&&(e.rowsWithParentsExpanded.push(s),e.rowsWithParentsExpandedAsMap.set(t,s),e.rowsDataWithParentsExpanded.push(a[t]),e.rowsWithParentsExpandedDataIndexMap.set(t,i),i++)}}generateRowsWithParentsExpanded(t){const e=[],o=this.getRowsData();t:for(const a in t){if(!o[a]||!o[a].parents)return[];if(this.isRowVisible(a)){for(const e of o[a].parents){const o=t[e];if(!o||!o.expanded)continue t}e.push(a)}}return this._updateRowsWithParentsExpandedCache(e),e}getRowInfoFromTop(t){const e=this.state.get("config.list.rows"),o=this.state.get("$data.list.rows"),a=this.getRowPositionMapNode(t);return{dataIndex:a.dataIndex,row:e[a.id],rowData:o[a.id]}}getRowViewTop(t,e=this.state.get("$data.list.rows"),o=this.state.get("$data.scroll.vertical")){return e[t].position.top-o.absolutePosPx-o.preciseOffset}parentsExpanded(t){return S(this).rowsWithParentsExpandedAsMap.has(t)}setAllRowsIdsCache(t){const e=S(this);e.allRowsIds=t;const o=this.state.get("config.list.rows");e.allRowsAsArray.length=0;for(const a of t)e.allRowsAsArray.push(o[a])}recalculateRowHeight(t,e){if(!e||!t||!t.gap)return 0;let o=0;const a=this.getItemsData();if(!a)return 0;if(!1===t.visible)return e.actualHeight=0,e.outerHeight=0,0;const i=this.getItems(e.itemsOrder);this.fixOverlappedItems(i);for(const t of i){const e=a[t.id];o=Math.max(o,e.position.rowTop+e.outerHeight)}return o<t.height&&(o=t.height),e.actualHeight=o,e.outerHeight=e.actualHeight+t.gap.top+t.gap.bottom,e.outerHeight}calculateVisibleRowsHeights(){if(this.isMutedMethod("calculateVisibleRowsHeights"))return;const t=this.state.get("$data.list.visibleRows");let e=0;const o=this.getAllRows(),a=this.getRowsData();for(const i of t)e+=this.recalculateRowHeight(o[i],a[i]);this.state.update("$data.list.visibleRowsHeight",e)}getRealChartHeight(t=!0){const e=this.state.get("$data.scroll.vertical.preciseOffset")||0,o=t?this.state.get("config.innerHeight"):this.state.get("$data.chart.dimensions.heightWithoutScrollBar"),a=this.state.get("config.additionalSpace");return o-a.top-a.bottom+-1*e}getLastRowId(t=S(this).rowsIdsWithParentsExpanded,e=this.state.get("$data.scroll.vertical")){return t[this.getLastRowIndex(t,e)]}getLastRowIndex(t=S(this).rowsIdsWithParentsExpanded,e=this.state.get("$data.scroll.vertical")){return t.length-e.lastPageCount}generateRowsPositionsMap(t,e=0,o={id:"",dataIndex:0,keys:[]}){if(0===t.length)return o;if(1===t.length)return o[t[0].position.top]={id:t[0].id,dataIndex:e,keys:[]},o.keys=[t[0].position.top],o;const a=Math.floor(t.length/2),i=e,s=e+a,n=t.slice(1,a),l=t.slice(a+1);o.keys.push(t[0].position.top),o.keys.push(t[a].position.top);const r=o[t[0].position.top]={id:t[0].id,dataIndex:i,keys:[]},c=o[t[a].position.top]={id:t[a].id,dataIndex:s,keys:[]};return this.generateRowsPositionsMap(n,i+1,r),this.generateRowsPositionsMap(l,s+1,c),o}getRowPositionMapNode(t,e=S(this).rowsPositionsMap){return t>=e.keys[1]?this.getRowPositionMapNode(t,e[e.keys[1]]):t>=e.keys[0]?this.getRowPositionMapNode(t,e[e.keys[0]]):e}measureRows(){if(this.isMutedMethod("measureRows"))return;const t=this.state.get("$data.scroll.vertical"),e=this.state.get("config.list.rows"),o=this.getRealChartHeight(),a=this.getRowsData(),i=S(this);if(void 0===t.dataIndex)return[];const s=this.state.get("$data.list.rowsIds");let n=0;if(t.data&&(n=i.rowsWithParentsExpandedDataIndexMap.get(t.data.id),-1===n)){const e=this.getLastRowId(i.rowsIdsWithParentsExpanded,t);n=i.rowsWithParentsExpandedDataIndexMap.get(e)}let l=0,r=0,c=0;for(let d=s.length;c<d;c++){const d=s[c],h=i.rowsWithParentsExpandedAsMap.has(d),u=this.getRowViewTop(d,a,t),m=c>=n&&u<=o,g=a[d];if(!g)return[];this.recalculateRowHeight(e[d],g),g.inView=m,g.parentsExpanded=h,g.position.top=l,r=l+g.outerHeight,g.position.bottom=r,h&&(l+=g.outerHeight)}return i.rowsPositionsMap=this.generateRowsPositionsMap(i.rowsDataWithParentsExpanded),this.state.update("$data.list.rows",a),this.state.update("$data.list.rowsHeight",r),this.state.update("$data.scroll.vertical.absoluteSize",r),r}isRowVisible(t,e=this.getAllRows(),o=this.getRowsData()){if(!e[t])return!1;if(!1===e[t].visible)return!1;if(!o[t])return!1;const a=o[t].parents;for(const t of a)if(!e[t]||!1===e[t].visible)return!1;return!0}getVisibleRows(){const t=this.state.get("$data.scroll.vertical"),e=S(this),o=e.rowsIdsWithParentsExpanded,a=this.getRowsData();if(!t.data)return[];const i=this.getRealChartHeight();if(!i)return[];let s=e.rowsWithParentsExpandedDataIndexMap.get(t.data.id);-1!==s&&void 0!==s||(s=t.dataIndex>e.rowsDataWithParentsExpanded.length-1?o.length-t.lastPageCount:t.dataIndex);const n=[];let l,r;for(let e=s,c=o.length;e<c;e++){const s=o[e];if(a[s]&&(r=a[s],l=this.getRowViewTop(s,a,t),l>=0&&l<=i?(n.push(s),r.parentsExpanded=!0):r.parentsExpanded=!1,l>i))break}return n}normalizeMouseWheelEvent(t){let e=t.deltaX||0,o=t.deltaY||0,a=t.deltaZ||0;const i=t.deltaMode,s=this.state.get("config.list.rowHeight");let n=1;switch(i){case 1:s&&(n=s);break;case 2:n=window.height}return e*=n,o*=n,a*=n,{x:e,y:o,z:a,event:t}}resetHorizontalScroll(t=this.state.get("$data.scroll.horizontal")){t.data=null,t.dataId="",t.dataIndex=0,t.handlePosPx=0,t.absolutePosPx=0,t.preciseOffset=0;const e=this.state.get("$data.chart.time");if(!e.allDates||!e.allDates.length)return;const o=e.allDates[e.level];if(!o||!o.length)return;const a=o[0];return t.data=Object.assign({},a),t.dataId=a.id,t}resetVerticalScroll(t=this.state.get("$data.scroll.vertical")){return t.data=null,t.dataId="",t.dataIndex=0,t.handlePosPx=0,t.absolutePosPx=0,t.preciseOffset=0,t.data=null,t.dataId=null,t}limitHorizontalScrollToView(t=this.state.get("$data.chart.time")){const e=this.state.get("$data.scroll.horizontal");if(!t.allDates||!t.allDates.length)return;const o=t.allDates[t.level].length-e.lastPageCount;e.dataIndex>o&&this.setScrollLeft(o,0,t)}calculateHorizontalScrollPosPxFromDates(t,e=0,o=this.state.get("$data.scroll.horizontal"),a=this.state.get("$data.chart.time")){if(a.calculatedZoomMode)return 0;if(void 0===t&&(t=0),!a.allDates||!a.allDates.length)return;const i=a.allDates[a.level];if(!i||!i.length)return;let s,n=0,l=0;if("number"==typeof t||""===t){""===t&&(t=0),l=t,s=i[l],s||(l=0,s=i[l]);const e=a.allDates[a.level].length-o.lastPageCount;l>e&&e>=0&&(l=e,s=i[l])}else if("string"==typeof t)for(let e=0;e<i.length;e++){const o=i[e];if(o.id===t){s=o,l=e;break}}if(!s&&o.data)for(let t=0;t<i.length;t++){const e=i[t];if(e.leftGlobal>=o.data.leftGlobal){s=e,l=t;break}}if(s||(l>0?(l=i.length-1,s=i[l]):(s=i[0],l=0)),l>i.length-o.lastPageCount&&(l=i.length-o.lastPageCount,s=i[l]),o.data=Object.assign({},s),n=s.leftPx-e,o.dataIndex=l,o.dataId=s.id,n){const t=n/o.absoluteSizeWithoutLastPage*o.maxHandlePosPx;o.handlePosPx=Math.max(t,0)}else o.handlePosPx=0;return o.handlePosPx>o.maxHandlePosPx&&(o.handlePosPx=Math.max(o.maxHandlePosPx,0)),o.preciseOffset=e,o.maxHandlePosPx>0?o.percent=o.handlePosPx/o.maxHandlePosPx*100:o.percent=0,o.absolutePosPx=Math.max(n,0),o}setScrollLeftByPixels(t){const e=this.state.get("$data.chart.time"),o=e.allDates[e.level];return o&&o.length?(t<0&&(t=0),this.state.update("$data.scroll.horizontal",(a=>{t>a.absoluteSizeWithoutLastPage&&(t=a.absoluteSizeWithoutLastPage);let i=0;const s=Math.round(t);let n;for(n of o){if(Math.round(n.rightPx)>s)break;i++}return a.dataIndex=i,a.dataId=n.id,a.preciseOffset=n.leftPx-t,this.calculateHorizontalScrollSizeAndPosFromDates(e.totalViewDurationPx,e,a,!1),t=a.absolutePosPx,a}),{data:"set-scroll-left"}),t):0}setScrollLeft(t,e=0,o=this.state.get("$data.chart.time")){if(o.calculatedZoomMode)return 0;if(this.state.get("config.scroll.horizontal.byPixels")){if("number"!=typeof t)throw new Error("When 'config.scroll.horizontal.byPixels' is true, 'dataIndexOrDateId' must be a number.");return t<0&&(t=0),this.setScrollLeftByPixels(t)}let a=0;const i=o.allDates[o.level];return i&&i.length?(this.state.update("$data.scroll.horizontal",(s=>{let n,l;if("number"==typeof t||""===t)n=t,l=i[n];else if("string"==typeof t)for(let e=0;e<i.length;e++)if(i[e].id===t){l=i[e],n=e;break}return l||(n>0?(n=i.length-1,l=i[n]):(n=0,l=i[0])),s.dataIndex=n,s.dataId=l.id,s.preciseOffset=e,this.calculateHorizontalScrollSizeAndPosFromDates(o.totalViewDurationPx,o,s,!1),a=s.absolutePosPx,s}),{data:"set-scroll-left"}),a):0}scrollToTime(t,e=!0){const o=this.state.get("$data.chart.time");if(o.calculatedZoomMode)return 0;if(!o.allDates)return 0;const a=this.time.findDateAtTime(t,o.allDates[o.level]);if(!a)return console.warn(`[gstc.api.scrollToTime] Time out of bounds (${t} -> ${this.time.date(t).format("YYYY-MM-DD HH:mm:ss")}).`),0;let i,s=0,n=0;if(e){const e=this.getChartWidth(!0)/2;n=(t-a.leftGlobal)/o.timePerPixel,a.rightPx<e&&(n=0);const l=-(e-n);if(i=this.time.getMainDateFromRelativePosition(a,l),!i)return console.warn(`[gstc.api.scrollToTime] Time out of bounds (${t} -> ${this.time.date(t).format("YYYY-MM-DD HH:mm:ss")}).`),0;s=o.allDates[o.level].indexOf(i)}else s=o.allDates[o.level].indexOf(a),n=(t-a.leftGlobal)/o.timePerPixel,i=a;if(-1===s)return 0;return this.state.get("config.scroll.horizontal").byPixels?this.setScrollLeft(i.leftPx+(e?i.width/2:0)):this.setScrollLeft(s,-n)}getScrollLeft(){return this.state.get("$data.scroll.horizontal")}getScrollSize(t){const e=this.state.get("$data.scroll.vertical.visible")?this.state.get("$data.chart.dimensions.widthWithoutScrollBar"):this.state.get("$data.chart.dimensions.width"),o=this.state.get("$data.scroll.horizontal.visible")?this.state.get("$data.chart.dimensions.heightWithoutScrollBar"):this.state.get("$data.chart.dimensions.innerHeight"),a=this.state.get("config.additionalSpace");return"horizontal"===t?e:o-a.top-a.bottom}getLastPageDatesWidth(t,e){let o=0,a=0;if(0===e.length)return{lastPageSize:o,lastPageCount:a};const i=this.state.get("config.scroll.horizontal"),s=i.byPixels||i.precise;for(let i=e.length-1;i>=0;i--){const s=e[i];if(o+=s.width,o>=t){o-=s.width;break}a++}return 0===o&&(o=t),s&&(o=t),{lastPageSize:o,lastPageCount:a}}calculateInitialChartWidth(t=!1){const e=this.state.get("config.initialWidth"),o=this.state.get("config.list.columns.data");let a=0;for(const t in o){a+=o[t].width}let i=e-a;return t&&(i-=this.state.get("config.scroll.horizontal.width")||0),i}getChartWidth(t=!1){let e=t?this.state.get("$data.chart.dimensions.widthWithoutScrollBar"):this.state.get("$data.chart.dimensions.width");return e||(e=this.calculateInitialChartWidth(t)),e}isHorizontalScrollVisible(t){const e=this.state.get("$data.scroll.horizontal");if(null!==e.data)return e.visible;const o=this.state.get("config.scroll.horizontal"),a=this.state.get("$data.chart.time"),i=a.totalViewDurationPx,s=this.getChartWidth(t),n=a.allDates[a.level];if(!n||!n.length)return!1;const{lastPageSize:l,lastPageCount:r}=this.getLastPageDatesWidth(s,n),c=this.getScrollSize("horizontal");let d=l/i*c;d<o.minInnerSize&&(d=o.minInnerSize);return!(r===n.length||c===d)}calculateHorizontalScrollSizeAndPosFromDates(t,e=this.state.get("$data.chart.time"),o=this.state.get("$data.scroll.horizontal"),a=!0){if(!e.allDates.length)return;const i=e.allDates[e.level],s=this.state.get("$data.scroll.vertical.visible"),n=this.getChartWidth(s),l=t,{lastPageSize:r,lastPageCount:c}=this.getLastPageDatesWidth(n,i),d=l-r,h=this.state.get("config.scroll.horizontal"),u=this.getScrollSize("horizontal");let m=r/l*u;m<h.minInnerSize&&(m=h.minInnerSize);const g=o.visible,f=!(c===i.length||u===m),p=Math.max(u?u-m:0,0);return o.absoluteSize=l,o.absoluteSizeWithoutLastPage=Math.max(d,0),o.innerHandleSize=m,o.maxHandlePosPx=p,o.scrollSize=f?u:0,o.lastPageCount=c,o.lastPageSize=r,o.visible=f,this.calculateHorizontalScrollPosPxFromDates(o.dataId,o.preciseOffset,o,e),a&&this.state.update("$data.scroll.horizontal",o),g!==f&&this.calculateVerticalScrollSize(),o}getLastPageRowsHeight(t,e){let o=0,a=0;const i=this.state.get("config.additionalSpace"),s=t-i.top-i.bottom;if(0===e.length)return{lastPageSize:o,lastPageCount:a};const n=this.getRowsData();for(let t=e.length-1;t>=0;t--){const i=n[e[t]];if(o+=i.outerHeight,o>=s){o-=i.outerHeight;break}a++}0===o&&(o=t);const l=this.state.get("config.scroll.vertical");return(l.byPixels||l.precise)&&(o=t),{lastPageSize:o,lastPageCount:a}}calculateVerticalScrollSize(){const t=this.state.get("$data.list.rowsWithParentsExpanded"),e=this.state.get("$data.list.rowsHeight"),o=this.isHorizontalScrollVisible(!0)?this.state.get("$data.chart.dimensions.heightWithoutScrollBar"):this.state.get("$data.chart.dimensions.innerHeight"),{lastPageSize:a,lastPageCount:i}=this.getLastPageRowsHeight(o,t),s=this.state.get("config.scroll.vertical"),n=o;let l=a/e*n;l<s.minInnerSize&&(l=s.minInnerSize);const r=!(i===t.length||n===l),c=n-l;this.state.update("$data.scroll.vertical",(o=>{if(o.absoluteSize=e,o.absoluteSizeWithoutLastPage=e-a,o.innerHandleSize=l,o.maxHandlePosPx=c,o.scrollSize=r?n:0,o.lastPageCount=i,o.lastPageSize=a,o.handlePosPx>c&&(o.handlePosPx=c),o.dataIndex>t.length-i){const e=this.getAllRows(),a=this.getRowsData();o.dataIndex=t.length-i;const s=t[o.dataIndex];e&&s?(o.data=e[s],o.dataId=o.data.id,o.absolutePosPx=a[s].position.top):(o.dataIndex=0,o.dataId="",o.data=null,o.handlePosPx=0,o.absolutePosPx=0),o.preciseOffset=0}else{const e=this.getRowsData(),a=t[o.dataIndex];e[a]&&(o.data=e[a],o.dataId=a,o.absolutePosPx=o.data.position.top-o.preciseOffset)}return o.visible=r,o}))}setScrollTopByPixels