@hpcc-js/timeline 3.0.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,32 +1,1209 @@
1
- var N=Object.defineProperty;var F=(S,t)=>N(S,"name",{value:t,configurable:!0});var mt="@hpcc-js/timeline",ut="3.0.0",dt="3.2.0";import{ITooltip as I}from"@hpcc-js/api";import{Axis as M}from"@hpcc-js/chart";import{d3Event as E,EntityPin as U,EntityRect as j,local as W,select as O,SVGWidget as Q,Utility as L}from"@hpcc-js/common";import{extent as q}from"@hpcc-js/common";import{scaleBand as J}from"@hpcc-js/common";import{timeFormat as B,timeParse as K}from"@hpcc-js/common";import{zoom as tt,zoomIdentity as et}from"@hpcc-js/common";(function(){if(!document.getElementById("815a87be")){var S=document.createElement("style");S.id="815a87be",S.textContent=`.timeline_MiniGantt .line {
2
- fill: none;
3
- stroke: lightgrey;
4
- opacity: 0.7;
5
- }
6
-
7
- .timeline_MiniGantt .common_TextBox .rect {
8
- fill: lightskyblue;
9
- stroke: blue;
10
- opacity: 0.5;
11
- }
12
-
13
- .timeline_MiniGantt .buckets .entity_shape rect {
14
- stroke: #333;
15
- }
16
-
17
- .timeline_MiniGantt .buckets.selected .common_EntityRect .common_Shape > rect {
18
- stroke: red;
19
- }
20
-
21
- .timeline_MiniGantt .common_TextBox .rect text {
22
- fill: black;
23
- stroke: none;
24
- }
25
- .timeline_MiniGantt .over {
26
- stroke: transparent;
27
- opacity: 0.8;
28
- }
29
- .timeline_MiniGantt rect {
30
- shape-rendering: crispEdges;
31
- }`,document.head.appendChild(S)}})();var b=class extends Q{static{F(this,"MiniGantt")}tlAxis;brAxis;verticalBands;_zoom;gUpperContent;gUpperAxis;gMiddleContent;gLowerAxis;gLowerContent;localRect=W();localEntityPin=W();tooltipFormatter;_dateCache;rootExtent;_title_idx=0;_startDate_idx=1;_endDate_idx=2;_icon_idx=-1;_color_idx=-1;_yoffset_idx=-1;constructor(){super(),I.call(this),L.SimpleSelectionMixin.call(this),this._drawStartPos="origin",this.tooltipHTML(t=>`<center>${t[this._title_idx]}</center><br>${this.tooltipFormatter(this.brAxis.parse(t[this._startDate_idx]))} -> ${this.tooltipFormatter(this.brAxis.parse(t[this._endDate_idx]))}`),this.tlAxis=new M().type("time"),this.brAxis=new M().type("time"),this.verticalBands=J().paddingOuter(.2).paddingInner(.2)}isHorizontal(){return this.orientation()==="horizontal"}fullExtent(){let t=[...this.data().map(i=>i[this._startDate_idx]),...this.data().filter(i=>!!i[this._endDate_idx]).map(i=>i[this._endDate_idx])];return q(t)}extent(){let t=this.rootExtent?[this.rootExtent[1],this.rootExtent[2]]:this.fullExtent();if(t[0]!==void 0&&t[1]!==void 0&&(t[0]===t[1]||this.centerOnMostRecent())){let i=K(this.timePattern()),e=B(this.timePattern()),n=i(t[0]),s=i(t[1]);if(t[0]===t[1])t[0]=e(new Date(n.setFullYear(n.getFullYear()-1))),t[1]=e(new Date(n.setFullYear(n.getFullYear()+2)));else{let p=n.getTime(),h=s.getTime()-p;t[0]=e(n),t[1]=e(new Date(p+h*2))}}return t}dataStartPos(t){if(typeof this._dateCache[t[this._startDate_idx]]<"u")return this._dateCache[t[this._startDate_idx]];let i=this.brAxis.scalePos(t[this._startDate_idx]);return this._dateCache[t[this._startDate_idx]]=i,i}dataEndPos(t){if(typeof this._dateCache[t[this._endDate_idx]]<"u")return this._dateCache[t[this._endDate_idx]];let i=this.brAxis.scalePos(t[this._endDate_idx]);return this._dateCache[t[this._endDate_idx]]=i,i}dataWidth(t){return this.dataEndPos(t)-this.dataStartPos(t)}transform;resetZoom(){this._zoom.transform(this.element(),et.translate(0,this.isHorizontal()?0:this.height()))}zoomed(){this.transform=E().transform,this.render()}background;enter(t,i){super.enter(t,i),this._zoom=tt().scaleExtent([0,this.maxZoom()]).on("zoom",()=>{this.zoomed()}),this.background=i.append("rect").attr("fill","white").attr("opacity",0).on("dblclick",()=>{E().stopPropagation(),delete this.rootExtent,this.resetZoom()}),this.gUpperContent=i.append("g").attr("class","gUpperContent"),this.gUpperAxis=i.append("g").attr("class","gUpperAxis"),this.gMiddleContent=i.append("g").attr("class","gMiddleContent"),this.gLowerAxis=i.append("g").attr("class","gLowerAxis"),this.gLowerContent=i.append("g").attr("class","gLowerContent"),this.tlAxis.target(this.gUpperAxis.node()).tickFormat(this.tickFormat()).guideTarget(this.gUpperAxis.append("g").node()).shrinkToFit("none").overlapMode(this.tickFormat_exists()?"stagger":"none").extend(.1),this.brAxis.target(this.gLowerAxis.node()).tickFormat(this.tickFormat()).guideTarget(this.gLowerAxis.append("g").node()).shrinkToFit("none").overlapMode(this.tickFormat_exists()?"stagger":"none").extend(.1),i.call(this._zoom),this._selection.widgetElement(this.gMiddleContent)}_prevIsHorizontal;update(t,i){if(super.update(t,i),this._dateCache={},this._title_idx=this.titleColumn()!==null?this.columns().indexOf(this.titleColumn()):this._title_idx,this._startDate_idx=this.startDateColumn()!==null?this.columns().indexOf(this.startDateColumn()):this._startDate_idx,this._endDate_idx=this.endDateColumn()!==null?this.columns().indexOf(this.endDateColumn()):this._endDate_idx,this._icon_idx=this.iconColumn()!==null?this.columns().indexOf(this.iconColumn()):this._icon_idx,this._color_idx=this.colorColumn()!==null?this.columns().indexOf(this.colorColumn()):this._color_idx,this._yoffset_idx=this.yOffsetColumn()!==null?this.columns().indexOf(this.yOffsetColumn()):this._yoffset_idx,this._prevIsHorizontal!==this.isHorizontal()){this._prevIsHorizontal=this.isHorizontal(),this.resetZoom();return}this.tooltipFormatter=B(this.tooltipTimeFormat());let e=this.width(),n=this.height();this.background.attr("x",0).attr("y",0).attr("width",e).attr("height",n);let s=this.extent();if(this.tlAxis.x(e/2).orientation(this.isHorizontal()?"top":"left").reverse(!this.isHorizontal()).timePattern(this.timePattern()).width(e-1).low(s[0]).high(s[1]).updateScale(),this.brAxis.x(e/2).y(n/2).orientation(this.isHorizontal()?"bottom":"right").reverse(!this.isHorizontal()).timePattern(this.timePattern()).width(e-1).height(n).low(s[0]).high(s[1]).updateScale(),this.transform){let u,k;this.isHorizontal()?(u=this.tlAxis.parseInvert(this.tlAxis.invert(this.transform.invertX(0))),k=this.tlAxis.parseInvert(this.tlAxis.invert(this.transform.invertX(e-1)))):(u=this.tlAxis.parseInvert(this.tlAxis.invert(-this.transform.invertY(0))),k=this.tlAxis.parseInvert(this.tlAxis.invert(-this.transform.invertY(n-1)))),this.tlAxis.low(u).high(k).updateScale(),this.brAxis.low(u).high(k).updateScale()}let p=this.data().sort(this.isHorizontal()?(u,k)=>{let w=this.brAxis.scalePos(u[1])-this.brAxis.scalePos(k[1]);return w===0?(""+u[0]).localeCompare(""+k[0]):w}:(u,k)=>this.brAxis.scalePos(k[1])-this.brAxis.scalePos(u[1])),h=p.filter(u=>!u[this._endDate_idx]),r=p.filter(u=>!!u[this._endDate_idx]);this.tlAxis.render(),this.brAxis.render();let _=this.brAxis.getBBox(),y=this.updateEntityPins(h),c=_.height,l=n-y,o=this._yoffset_idx!==-1?Math.min.apply(void 0,this.data().filter(u=>!isNaN(u[this._yoffset_idx])).map(u=>u[this._yoffset_idx])):0;if(h.length>0&&r.length===0){this.tlAxis.visible(!1);let u=y/4;u>n/2-c&&(u=n/2-c);let k=n/2+u,w=(n/2-c-u)*-1,H=o!==0?o/2:0;this.gUpperContent.attr("transform",`translate(0, ${k-H})`),this.gLowerAxis.attr("transform",`translate(0, ${w-H})`)}else h.length===0&&r.length>0?(this.tlAxis.visible(!0),this.gUpperContent.attr("transform",`translate(0, ${y})`),this.gUpperAxis.attr("transform",`translate(0, ${y})`)):(y-=o,l+=o,this.tlAxis.visible(!0),this.gUpperContent.attr("transform",`translate(0, ${y})`),this.gUpperAxis.attr("transform",`translate(0, ${y})`),this.gMiddleContent.attr("transform",`translate(0, ${y})`));this.tlAxis.render();let m=this.tlAxis.getBBox(),a=[],d={};for(let u of r){for(let k=0;k<a.length;++k){let w=a[k];if(w.endPos+this.overlapTolerence()<=this.dataStartPos(u)){d[u]=k,w.endPos=this.dataEndPos(u);break}}d[u]===void 0&&(d[u]=a.length,a.push({endPos:this.dataEndPos(u)}))}let C=this.isHorizontal()?0+m.height:0+m.width,v=this.isHorizontal()?l-_.height:e-_.width;this.verticalBands.range([C,v]).domain(a.map((u,k)=>k)),r.length>0&&this.updateEventRanges(h,r,d,l,m,_,e)}updateEntityPins(t){let i=0,e=this,n=this.gUpperContent.selectAll(".entity_pin").data(t,o=>o[0]+":"+o[1]),s=this.eventFontColorColumn()?this.columns().indexOf(this.eventFontColorColumn()):-1,p=this.eventBorderColorColumn()?this.columns().indexOf(this.eventBorderColorColumn()):-1,h=this.eventBackgroundColorColumn()?this.columns().indexOf(this.eventBackgroundColorColumn()):-1,r={};for(let o of t){let m=typeof o[e._title_idx]<"u"?o[e._title_idx]:o[0];r[m]=r[m]?r[m]+1:1}let _=Object.keys(r),y=e.eventGroupOffset(),c=n.enter().append("g").attr("class","entity_pin");c.append("line").attr("class","entity_line"),c.on("mouseover",function(o){O(this).raise()}).each(function(o,m){let a=new U().target(this).icon("\uF024").iconOnlyShowOnHover(e.hideIconWhenCollapsed()).titleOnlyShowOnHover(e.hideTitleWhenCollapsed()).descriptionOnlyShowOnHover(e.hideDescriptionWhenCollapsed()).annotationOnlyShowOnHover(e.hideAnnotationsWhenCollapsed()).iconDiameter(18).iconPaddingPercent(1).titleFontSize(14).descriptionColor("#333").descriptionFontSize(15).iconColor(s===-1?"#333":o[s]).titleColor(s===-1?"#333":o[s]).descriptionColor(s===-1?"#333":o[s]).backgroundShape("pin").backgroundColorFill(s===-1?"#f8f8f8":o[h]).backgroundColorStroke(s===-1?"#ccc":o[p]).cornerRadius(5).arrowHeight(10).arrowWidth(16);e.localEntityPin.set(this,a)}).merge(n).each(function(o,m){let a=e.localEntityPin.get(this),d=typeof o[e._title_idx]<"u"?o[e._title_idx]:a.title(),C=e.dataStartPos(o)-0,v=_.indexOf(d)%e.eventGroupMod()*y-5;if(typeof o[e._yoffset_idx]<"u"&&(v+=o[e._yoffset_idx]?o[e._yoffset_idx]:0),o[e._title_idx]!==a.title()&&o[e._startDate_idx]!==a.description()){let k=e.brAxis.parse(o[e._startDate_idx]),w=e.tooltipFormatter(k);a.x(C).y(v).iconOnlyShowOnHover(e.hideIconWhenCollapsed()).titleOnlyShowOnHover(e.hideTitleWhenCollapsed()).descriptionOnlyShowOnHover(e.hideDescriptionWhenCollapsed()).annotationOnlyShowOnHover(e.hideAnnotationsWhenCollapsed()).icon(typeof o[e._icon_idx]<"u"?o[e._icon_idx]:a.icon()).title(d).description(w).animationFrameRender()}else a.move({x:C,y:v});let u=a.calcHeight();i<u&&(i=u),O(this).selectAll(".entity_line").attr("x1",C).attr("x2",C).attr("y1",0).attr("y2",v).style("stroke",s===-1?"#ccc":o[p]).style("stroke-width",1)}),n.exit().each(function(o,m){e.localEntityPin.get(this).target(null)}).remove();let l=Math.abs(Math.min(t.length,e.eventGroupMod())*e.eventGroupOffset());return i+l}updateEventRanges(t,i,e,n,s,p,h){let r=this,_=this.gMiddleContent.selectAll(".line").data(t,c=>c[r._title_idx]);_.enter().append("line").attr("class","line").merge(_).attr(this.isHorizontal()?"x1":"y1",c=>this.dataStartPos(c)-0).attr(this.isHorizontal()?"x2":"y2",c=>this.dataStartPos(c)-0).attr(this.isHorizontal()?"y1":"x1",this.isHorizontal()?s.height:s.width).attr(this.isHorizontal()?"y2":"x2",this.isHorizontal()?n-p.height:h-p.width),_.exit().remove();let y=this.gMiddleContent.selectAll(".buckets").data(i,c=>c[r._title_idx]);y.enter().append("g").attr("class","buckets").call(this._selection.enter.bind(this._selection)).each(function(c){let l=new j().target(this).iconDiameter(28).iconPaddingPercent(0).titleFontSize(28).titleColor(r.rangeFontColor()).descriptionColor(r.rangeFontColor()).iconColor(r.rangeFontColor()).backgroundShape("rect").backgroundColorFill(c[r._color_idx]);r.localRect.set(this,l),r.enterEntityRect(l,c)}).on("click",function(c){r.click(r.rowToObj(c),"range",r._selection.selected(this))},!1).on("dblclick",function(c){r.rootExtent=c,r.resetZoom(),r.dblclick(r.rowToObj(c),"range",r._selection.selected(this))},!0).on("mouseout.tooltip",this.tooltip.hide).on("mousemove.tooltip",this.tooltip.show).merge(y).attr("transform",c=>r.isHorizontal()?`translate(${this.dataStartPos(c)}, ${this.verticalBands(e[c])}) `:`translate(${this.verticalBands(e[c])}, ${this.dataStartPos(c)}) `).each(function(c){let l=r.localRect.get(this),o=r.dataWidth(c)/2,m=r.verticalBands.bandwidth()/2,a=Math.max(r.dataWidth(c),2),d=Math.max(r.verticalBands.bandwidth(),2),C=.618,u=(1-C)/2*d,k=d*C,w=k;l.pos(r.isHorizontal()?{x:o,y:m}:{x:m,y:o}).fixedHeight(r.isHorizontal()?d:a).fixedWidth(r.isHorizontal()?a:d).icon(typeof c[r._icon_idx]<"u"?c[r._icon_idx]:"").title(typeof c[r._title_idx]<"u"?c[r._title_idx]:"").padding(u).iconDiameter(w).titleFontSize(k),w*1.5>a&&l.icon(null),r.updateEntityRect(l,c[r._icon_idx]),l.render()}),y.exit().remove()}exit(t,i){this.brAxis.target(null),this.tlAxis.target(null),super.exit(t,i)}click(t,i,e){}dblclick(t,i,e){}enterEntityRect(t,i){}updateEntityRect(t,i){}};b.prototype._class+=" timeline_MiniGantt";b.prototype.implements(I.prototype);b.prototype.mixin(L.SimpleSelectionMixin);b.prototype.publish("timePattern","%Y-%m-%d","string","timePattern");b.prototype.publish("tickFormat",null,"string","tickFormat",void 0,{optional:!0});b.prototype.publish("tooltipTimeFormat","%Y-%m-%d","string","tooltipTimeFormat");b.prototype.publish("overlapTolerence",2,"number","overlapTolerence");b.prototype.publish("orientation","horizontal","set","orientation",["horizontal","vertical"]);b.prototype.publish("rangeFontColor","#ecf0f1","html-color","rangeFontColor");b.prototype.publish("titleColumn",null,"string","titleColumn");b.prototype.publish("startDateColumn",null,"string","startDateColumn");b.prototype.publish("endDateColumn",null,"string","endDateColumn");b.prototype.publish("iconColumn",null,"string","iconColumn");b.prototype.publish("colorColumn",null,"string","colorColumn");b.prototype.publish("yOffsetColumn",null,"string","yOffsetColumn");b.prototype.publish("maxZoom",16,"number","maxZoom");b.prototype.publish("eventGroupOffset",-50,"number","eventGroupOffset");b.prototype.publish("eventGroupMod",5,"number","eventGroupMod");b.prototype.publish("eventFontColorColumn",null,"string","eventFontColorColumn");b.prototype.publish("eventBorderColorColumn",null,"string","eventBorderColorColumn");b.prototype.publish("eventBackgroundColorColumn",null,"string","eventBackgroundColorColumn");b.prototype.publish("hideIconWhenCollapsed",!1,"boolean","hideIconWhenCollapsed");b.prototype.publish("hideTitleWhenCollapsed",!1,"boolean","hideTitleWhenCollapsed");b.prototype.publish("hideDescriptionWhenCollapsed",!1,"boolean","hideDescriptionWhenCollapsed");b.prototype.publish("hideAnnotationsWhenCollapsed",!0,"boolean","hideAnnotationsWhenCollapsed");b.prototype.publish("centerOnMostRecent",!1,"boolean","If true, the timeline will be centered on the most recent data point");import{d3Event as D,select as A,SVGZoomWidget as it,Utility as P}from"@hpcc-js/common";import{HTMLTooltip as ot}from"@hpcc-js/html";import{scaleLinear as G}from"@hpcc-js/common";import{render as nt,LabelledRect as st}from"@hpcc-js/react";var g=class extends it{static{F(this,"ReactGantt")}_selection=new P.Selection(this);_buckets;_interpolateX;_interpolateY;_bucketsBySeries;_dataBySeries;_origIdxMap;_seriesBackgrounds;_maxFontSize;_tooltip;_minStart;_maxEnd;_title_idx=0;_startDate_idx=1;_endDate_idx=2;_icon_idx=-1;_color_idx=-1;_series_idx=-1;_bucket_idx=-1;_yoffset_idx=-1;_maxX;_maxY;_rangeOptions={rangePadding:2,fontFamily:"Verdana",fontSize:12,fill:"white",stroke:"black",textFill:"black",cornerRadius:3,strokeWidth:0};constructor(t="origin"){super(),this._drawStartPos=t,this.showToolbar_default(!1),this._tooltip=new ot,this._tooltip.tooltipHTML(i=>`<div style="text-align:center;">${i[0]}<br/><br/>${i[1]} -&gt; ${i[2]}</div>`),this._tooltip.followCursor(!0)}selection(t){return arguments.length?(this._selection.set(t),this):this._selection.get()}_rangeRenderer=st;rangeRenderer(t){return arguments.length?(this._rangeRenderer=t,this._rangeRenderer):this._rangeRenderer}enter(t,i){super.enter(t,i);let e=this;i.on("click",function(n){e._selection.clear()}),this._tooltip.target(t)}update(t,i){super.update(t,i),this.zoomExtent([.05,this.maxZoom()]),this._title_idx=this.titleColumn()!==null?this.columns().indexOf(this.titleColumn()):this._title_idx,this._startDate_idx=this.startDateColumn()!==null?this.columns().indexOf(this.startDateColumn()):this._startDate_idx,this._endDate_idx=this.endDateColumn()!==null?this.columns().indexOf(this.endDateColumn()):this._endDate_idx,this._icon_idx=this.iconColumn()!==null?this.columns().indexOf(this.iconColumn()):this._icon_idx,this._color_idx=this.colorColumn()!==null?this.columns().indexOf(this.colorColumn()):this._color_idx,this._series_idx=this.seriesColumn()!==null?this.columns().indexOf(this.seriesColumn()):this._series_idx,this._bucket_idx=this.bucketColumn()!==null?this.columns().indexOf(this.bucketColumn()):-1;let e=this,n=this.width(),s=0,p=n;if(this._interpolateX=G().domain([this._minStart,this._maxEnd]).range([s,p]),this.data().sort((l,o)=>l[1]-o[1]),this._series_idx>-1){this._origIdxMap={},this._dataBySeries={},this._bucketsBySeries={},this.data().forEach((a,d)=>{let C=a[this._series_idx];this._dataBySeries[C]||(this._origIdxMap[C]={},this._dataBySeries[C]=[]),this._dataBySeries[C].push({dataRow:a,origIdx:d})});let l=this.gutter(),o=0,m=Object.keys(this._dataBySeries);m.forEach(a=>{this._dataBySeries[a].sort((d,C)=>d.dataRow[1]-C.dataRow[1]),this._bucketsBySeries[a]=this.calcBuckets(this._dataBySeries[a].map(d=>d.dataRow),1,2),this._bucketsBySeries[a].bucketHeight=this.bucketHeight(),this._bucketsBySeries[a].bucketOffset=o,o+=(this._bucketsBySeries[a].bucketHeight+this.strokeWidth()+this.gutter())*(this._bucketsBySeries[a].maxBucket+1),this._dataBySeries[a].forEach((d,C)=>{this._origIdxMap[a][d.origIdx]=C})}),this._seriesBackgrounds=this._renderElement.selectAll(".series-background").data(m.map(a=>this._bucketsBySeries[a])),this._seriesBackgrounds.join(a=>a.append("rect").attr("class","series-background"),a=>a,a=>a.each(function(d){delete d.element}).remove()).attr("opacity",a=>a.props&&a.props.hidden?0:1).each(function(a,d){A(this).attr("x",0).attr("y",a.bucketOffset-l/2).attr("width",n).attr("height",(a.bucketHeight+l)*(a.maxBucket+1)+l).attr("fill",d%2?e.oddSeriesBackground():e.evenSeriesBackground())})}else this._bucket_idx!==-1?this._buckets=this.calcBuckets(this.data(),this._startDate_idx,this._endDate_idx,this._bucket_idx):this._buckets=this.calcBuckets(this.data(),this._startDate_idx,this._endDate_idx);let h=this._interpolateX(this._minStart);this.zoomTo([h,0],1);let r=this.bucketHeight();this.setRangeOptions(),this._maxFontScale=r-this.rangePadding()*2,this.measureDataText();let _=this._renderElement.selectAll(".item").data(this.data()),y=this.strokeWidth(),c=y*2;_.join(l=>l.append("g").attr("class","item").on("click.selectionBag",function(o,m){let a=o.id===void 0?m:o.id;e._selection.isSelected({_id:a,element:o.element})?e._selection.clear():e._selection.click({_id:a,element:F(()=>o.element,"element")},D),e.selectionChanged(),D().stopPropagation()}).on("click",function(o){let m=o.element.classed("selected");o[e.columns().length]&&(o.__lparam=o[e.columns().length]),e.click(o,"",m)}).on("dblclick",function(o){let m=o.element.classed("selected");o[e.columns().length]&&(o.__lparam=o[e.columns().length]),e.click(o,"",m)}).on("mousein",function(o){e.highlightItem(A(this),o);let m=o.element.classed("selected");e.mousein(o,"",m)}).on("mouseover",function(o){let m=D();e._tooltip._triggerElement=o.element,e._tooltip._cursorLoc=[m.clientX,m.clientY],e._tooltip.data(o).visible(!0).fitContent(!0).render(),e.highlightItem(A(this),o);let a=o.element.classed("selected");e.mouseover(o,"",a)}).on("mouseout",function(o){e._tooltip.visible(!1).render(),e.highlightItem(null,null);let m=o.element.classed("selected");e.mouseout(o,"",m)}).each(function(o,m){o.that=this,o.element=A(this),o.x=e._interpolateX(o[1]);let a=e._interpolateX(o[2]);if(e._series_idx>-1){let d=o[e._series_idx],C=e._bucketsBySeries[d].bucketMap[e._origIdxMap[d][m]];o.y=e._bucketsBySeries[d].interpolateY(C)+e._bucketsBySeries[d].bucketOffset}else{let d=e._bucket_idx===-1?m:o[e._bucket_idx];o.y=e._buckets.interpolateY(e._buckets.bucketMap[d])}o.props={...o[3],text:o[0]},o.props.width=a-o.x,o.props.height=r,o.x+=y,o.y+=y,o.props.width-=c,o.props.height-=c,o.element.attr("transform",`translate(${o.x+o.props.width/2} ${o.y+o.props.height/2})`)}),l=>l,l=>l.each(function(o){delete o.element}).remove()).attr("opacity",l=>l.props&&l.props.hidden?0:1).each(function(l,o){if(l.that=this,e._series_idx>-1){let m=l[e._series_idx];l.x=e.renderRangeElement(l,o,!1,e._rangeOptions,m)}else l.x=e.renderRangeElement(l,o,!1,e._rangeOptions)}).on("dblclick.zoom",l=>{let o=this._interpolateX(l[1]),a=this._interpolateX(l[2])-o,d=n/a;this.zoomTo([-o*d,0],d)}),i.on("dblclick.zoom",null)}exit(t,i){this._tooltip.target(null),super.exit(t,i)}renderRangeElement(t,i,e=!1,n={},s){let p=n.strokeWidth,h=p*2,r=n.rangePadding,_,y=isNaN(this._transform.x)?0:this._transform.x,c=isNaN(this._transform.k)?1:this._transform.k,l,o=this.bucketHeight();t.that.setAttribute("data-series",s),this._color_idx>-1&&t.that.setAttribute("data-color",t[this._color_idx]),s!==void 0?(l=this._bucketsBySeries[s].bucketMap[this._origIdxMap[s][i]],t.that.setAttribute("data-b",l),t.that.setAttribute("data-bucketOffset",this._bucketsBySeries[s].bucketOffset),t.y=this._bucketsBySeries[s].interpolateY(l)+this._bucketsBySeries[s].bucketOffset,t.that.setAttribute("data-dy",t.y)):(l=this._buckets.bucketMap[i],t.y=this._buckets.interpolateY(l)),this._color_idx>-1&&(n.fill=t[this._color_idx]),e?(t.x=this._interpolateX(t[1])*c,_=this._interpolateX(t[2])*c,t.props={...t[3],text:t[0]},t.props.width=(_-t.x)/c,t.x+=y,t.props.width*=c):(t.x=this._interpolateX(t[1]),_=this._interpolateX(t[2]),t.props={...t[3],text:t[0]},t.props.width=(_-t.x)/c),t.props.height=o,s===void 0&&this._buckets.bucketScale<1&&(t.props.height=this._buckets.bucketScale*o),t.element===void 0&&t.that&&(t.element=A(t.that)),t.element.attr("transform",`translate(${t.x+t.props.width/2} ${t.y+t.props.height/2})`),t.x+=p,t.y+=p,t.props.width-=h,t.props.height-=h,t.props.width=t.props.width<1?1:t.props.width,t.props.height=t.props.height<1?1:t.props.height;let m=this.truncateText(t.props.text,t.props.width-r,this._maxFontScale);m!==t.props.text?m=this.truncateText(t.props.text,t.props.width-r):t.props.fontSize=this._maxFontScale*n.fontSize,s===void 0&&this._buckets.bucketScale<1&&(t.props.fontSize=Math.min(this._maxFontScale,this._buckets.bucketScale)*n.fontSize),(!this._maxY||this._maxY<t.y+t.props.height)&&(this._maxY=t.y+t.props.height),(!this._maxX||this._maxX<t.x+t.props.width)&&(this._maxX=t.x+t.props.width),nt(this._rangeRenderer,{...n,...t.props,text:m},t.that)}setRangeOptions(){this._rangeOptions={rangePadding:this.rangePadding(),fontFamily:this.fontFamily(),fontSize:this.fontSize(),strokeWidth:this.strokeWidth(),fill:this.fill(),stroke:this.stroke(),textFill:this.rangeFontColor(),cornerRadius:this.cornerRadius()}}_transform={k:1,x:0,y:0};zoomed(t){switch(this._transform=t,this.renderMode()){case"scale-all":this._zoomScale=t.k,this._zoomTranslate=[t.x,0],this._zoomG.attr("transform",`translate(${t.x} 0)scale(${t.k} 1)`);break;default:let i=this._rangeOptions;this.data().forEach((e,n)=>{if(this._color_idx>-1&&(i.fill=e[this._color_idx]),this._series_idx>-1){let s=e[this._series_idx];this.renderRangeElement(e,n,!0,i,s)}else this.renderRangeElement(e,n,!0,i)})}this.zoomedHook(t)}zoomedHook(t){}calcBuckets(t,i,e,n){let s={},p={},h=this.overlapTolerence(),r=[{end:-1/0}],_=0;n!==void 0?(t.forEach((c,l)=>{s[l]=c[n],p[c[n]]=!0}),_=Object.keys(p).length):t.forEach((c,l)=>{for(let o=0;o<r.length;++o)if(l===0||r[o][e]+h<=c[i]){s[l]=o,_<o&&(_=o),r[o][e]=c[e];break}if(s[l]===void 0){s[l]=r.length;let o={};o[e]=c[e],r.push(o)}_<s[l]&&(_=s[l])});let y=(_+1)*(this.bucketHeight()+this.gutter());return{bucketMap:s,maxBucket:_,bucketScale:this.height()/y,interpolateY:G().domain([0,_+1]).range([0,Math.min(this.height(),y)])}}data(t){let i=super.data.apply(this,arguments);return arguments.length>0&&(this._minStart=Math.min(...this.data().map(e=>e[1]))??0,this._maxEnd=Math.max(...this.data().map(e=>e[2]))??1,this.measureDataText(!0)),i}_textWidths;_maxFontScale;_characterWidths;_prevFontFamily;_prevFontSize;measureDataText(t=!1){let i={},e={},n=this.fontFamily(),s=this.fontSize(),p=this.bucketHeight();p&&(this._maxFontScale=(p-this.rangePadding()*2)/s),(t||this._prevFontFamily!==n||this._prevFontSize!==s)&&(e["."]=P.textSize(".",n,s).width,this.data().forEach(h=>{i[h[0]]||(i[h[0]]=P.textSize(h[0],n,s).width),h[0].split("").forEach(r=>{e[r]||(e[r]=P.textSize(r,n,s).width)})}),this._textWidths=i,this._characterWidths=e),this._prevFontFamily=n,this._prevFontSize=s}truncateText(t,i,e=1){if(this._textWidths[t]*e<i)return t;let s="",p=0,h=i-this._characterWidths["."]*3;for(let r of t)if(p+=this._characterWidths[r],p<h)s+=r;else break;return h<0?"":s+"..."}resize(t){let i;return this.fitWidthToContent()||this.fitHeightToContent()?i=super.resize.call(this,{width:t.width,height:this._maxY}):i=super.resize.apply(this,arguments),i}selectionChanged(){}highlightItem(t,i){}click(t,i,e){}dblclick(t,i,e){}mousein(t,i,e){}mouseover(t,i,e){}mouseout(t,i,e){}};g.prototype._class+=" timeline_ReactGantt";g.prototype.publish("fitWidthToContent",!1,"boolean","If true, resize will simply reapply the bounding box width");g.prototype.publish("fitHeightToContent",!1,"boolean","If true, resize will simply reapply the bounding box height");g.prototype.publish("titleColumn",null,"string","Column name to for the title");g.prototype.publish("startDateColumn",null,"string","Column name to for the start date");g.prototype.publish("endDateColumn",null,"string","Column name to for the end date");g.prototype.publish("iconColumn",null,"string","Column name to for the icon");g.prototype.publish("colorColumn",null,"string","Column name to for the color");g.prototype.publish("seriesColumn",null,"string","Column name to for the series identifier");g.prototype.publish("bucketColumn",null,"string","Column name to for the bucket identifier");g.prototype.publish("renderMode","default","set","Render modes vary in features and performance",["default","scale-all"]);g.prototype.publish("rangePadding",3,"number","Padding within each range rectangle (pixels)");g.prototype.publish("fill","#1f77b4","string","Background color of range rectangle");g.prototype.publish("stroke",null,"string","Color of range rectangle border");g.prototype.publish("strokeWidth",null,"number","Width of range rectangle border (pixels)");g.prototype.publish("cornerRadius",3,"number","Space between range buckets (pixels)");g.prototype.publish("fontFamily",null,"string","Font family within range rectangle",null,{optional:!0});g.prototype.publish("fontSize",10,"number","Size of font within range rectangle (pixels)");g.prototype.publish("rangeFontColor","#ecf0f1","html-color","rangeFontColor");g.prototype.publish("overlapTolerence",2,"number","overlapTolerence");g.prototype.publish("smallestRangeWidth",10,"number","Width of the shortest range (pixels)");g.prototype.publish("bucketHeight",100,"number","Max height of range element (pixels)");g.prototype.publish("gutter",2,"number","Space between range buckets (pixels)");g.prototype.publish("maxZoom",16,"number","Maximum zoom");g.prototype.publish("evenSeriesBackground","#FFFFFF","html-color","Background color of even series rows");g.prototype.publish("oddSeriesBackground","#DDDDDD","html-color","Background color of odd series rows");import{Axis as $}from"@hpcc-js/chart";import{SVGWidget as rt}from"@hpcc-js/common";var f=class extends rt{static{F(this,"ReactAxisGantt")}_topAxis=new $("center").orientation("top").type("linear").shrinkToFit("none").overlapMode("hide").extend(0).tickFormat("d");_gantt=new g("center").stroke("#000000");_bottomAxis=new $("center").orientation("bottom").type("linear").shrinkToFit("none").overlapMode("hide").extend(0).tickFormat("d");_topAxisElement;_contentElement;_bottomAxisElement;_topRect;_contentRect;_bottomRect;rangeRenderer;constructor(){super(),this._drawStartPos="origin",this.rangeRenderer=function(){let t=this._gantt.rangeRenderer.apply(this._gantt,arguments);return arguments.length?this:t}}selection(t){return arguments.length?(this._gantt.selection(t),this):this._gantt.selection()}resizeWrappers(){let t=this.width(),i=this.height(),e=this.axisHeight(),n=i-e*2,s=this.strokeWidth();this._topRect.attr("height",e).attr("width",t).attr("fill","transparent"),this._topAxisElement.attr("transform","translate(0 0)"),this._topAxis.resize({height:e,width:t}),this._contentRect.attr("height",n).attr("width",t).attr("fill","transparent"),this._contentElement.attr("transform",`translate(0 ${e+s})`),this._gantt.resize({height:n,width:t}),this._bottomRect.attr("height",e).attr("width",t).attr("fill","transparent"),this._bottomAxisElement.attr("transform",`translate(0 ${e+n+s})`),this._bottomAxis.resize({height:e,width:t})}enter(t,i){super.enter(t,i),this._gantt.click=(e,n,s)=>{this.click(e,n,s)},this._gantt.dblclick=(e,n,s)=>{this.dblclick(e,n,s)},this._topAxisElement=i.append("g").attr("class","top-axis-wrapper"),this._topRect=this._topAxisElement.append("rect").attr("class","top-axis-rect"),this._contentElement=i.append("g").attr("class","content-wrapper"),this._contentRect=this._contentElement.append("rect").attr("class","content-rect"),this._bottomAxisElement=i.append("g").attr("class","bottom-axis-wrapper"),this._bottomRect=this._bottomAxisElement.append("rect").attr("class","top-axis-rect"),this._topAxis.target(this._topAxisElement.node()),this._gantt.target(this._contentElement.node()).bucketHeight(30),this._bottomAxis.target(this._bottomAxisElement.node()),this.resizeWrappers(),this._gantt.zoomedHook=e=>{this.onzoom(e)}}onzoom(t){let i=this.width(),e=this._gantt._minStart,s=this._gantt._maxEnd-e,p=s/i,h=Math.floor(e-p*(t.x/t.k)),r=Math.ceil(s/t.k+h);this._topAxis.fontFamily(this.axisFontFamily()).fontSize(this.axisFontSize()).tickLength(this.axisTickLength()).low(h).high(r).render(),this._bottomAxis.fontFamily(this.axisFontFamily()).fontSize(this.axisFontSize()).tickLength(this.axisTickLength()).low(h).high(r).render()}update(t,i){super.update(t,i),this._topAxis.tickFormat(this.tickFormat()).render(),this._bottomAxis.tickFormat(this.tickFormat()).render(),this._gantt.render()}exit(t,i){this._bottomAxis.target(null),this._gantt.target(null),this._topAxis.target(null),super.exit(t,i)}columns(t){let i=super.columns.apply(this,arguments);return arguments.length>0&&this._gantt.columns(t),i}data(t){let i=super.data.apply(this,arguments);if(arguments.length>0){let e=this.data().map(n=>{let s=[...n];return s[1]=isNaN(n[1])?new Date(n[1]).getTime():Number(n[1]),s[2]=isNaN(n[2])?new Date(n[2]).getTime():Number(n[2]),s});this._gantt._minStart=Math.min(...e.map(n=>n[1]))??0,this._gantt._maxEnd=Math.max(...e.map(n=>n[2]))??1,this._gantt.data(e)}return i}resize(t){let i=super.resize.apply(this,arguments);return this._topAxisElement&&this.resizeWrappers(),i}click(t,i,e){}dblclick(t,i,e){}tooltip(){return this._gantt._tooltip}};f.prototype._class+=" timeline_ReactAxisGantt";f.prototype.publish("tickFormat",null,"string","Format rule applied to axis tick labels",void 0,{optional:!0});f.prototype.publish("axisHeight",22,"number","Height of axes (pixels)");f.prototype.publish("overlapTolerence",2,"number","overlapTolerence");f.prototype.publish("smallestRangeWidth",10,"number","Width of the shortest range (pixels)");f.prototype.publish("axisFontSize",null,"number","Font size of axis tick labels");f.prototype.publish("axisFontFamily",null,"string","Font family of axis tick labels");f.prototype.publish("axisTickLength",null,"number","Length of axis ticks");f.prototype.publishProxy("gutter","_gantt");f.prototype.publishProxy("renderMode","_gantt");f.prototype.publishProxy("strokeWidth","_gantt");f.prototype.publishProxy("fontSize","_gantt");f.prototype.publishProxy("fontFamily","_gantt");f.prototype.publishProxy("stroke","_gantt");f.prototype.publishProxy("cornerRadius","_gantt");f.prototype.publishProxy("titleColumn","_gantt");f.prototype.publishProxy("startDateColumn","_gantt");f.prototype.publishProxy("endDateColumn","_gantt");f.prototype.publishProxy("iconColumn","_gantt");f.prototype.publishProxy("colorColumn","_gantt");f.prototype.publishProxy("bucketColumn","_gantt");f.prototype.publishProxy("maxZoom","_gantt");f.prototype.publishProxy("bucketHeight","_gantt");import{min as at,max as lt}from"@hpcc-js/common";import{Axis as V}from"@hpcc-js/chart";import{Border2 as ht}from"@hpcc-js/layout";var x=class extends ht{static{F(this,"ReactAxisGanttSeries")}_topAxis=new V("origin").orientation("top").type("linear").shrinkToFit("none").overlapMode("hide").extend(0).tickFormat("d");_gantt=new g("origin").stroke("#000000").fitHeightToContent(!0);_bottomAxis=new V("origin").orientation("bottom").type("linear").shrinkToFit("none").overlapMode("hide").extend(0).tickFormat("d");_topAxisElement;_contentElement;_bottomAxisElement;_topRect;_contentRect;_bottomRect;constructor(){super(),this.centerOverflowX_default("hidden"),this.centerOverflowY_default("auto")}selection(t){return arguments.length?(this._gantt.selection(t),this):this._gantt.selection()}rangeRenderer(t){let i=this._gantt.rangeRenderer.apply(this._gantt,arguments);return arguments.length?this:i}resizeWrappers(){let t=this.width(),i=this.height(),e=this.axisHeight(),n=i-e*2;this.bottomHeight(e),this._topWA.resize({width:t,height:e}),this._centerWA.resize({width:t,height:n}),this._bottomWA.resize({width:t,height:e}),this.top().render(),this.bottom().render(),this.center().render()}enter(t,i){super.enter(t,i),this._gantt.click=(e,n,s)=>{this.click(e,n,s)},this._gantt.dblclick=(e,n,s)=>{this.dblclick(e,n,s)},this.top(this._topAxis),this.center(this._gantt),this.bottom(this._bottomAxis),this.resizeWrappers(),this._gantt.zoomedHook=e=>{this.onzoom(e)}}onzoom(t){let i=this.width(),e=this._gantt._minStart,s=this._gantt._maxEnd-e,p=s/i,h=Math.floor(e-p*(t.x/t.k)),r=Math.ceil(s/t.k+h);this._topAxis.fontFamily(this.axisFontFamily()).fontSize(this.axisFontSize()).tickLength(this.axisTickLength()).low(h).high(r).lazyRender(),this._bottomAxis.fontFamily(this.axisFontFamily()).fontSize(this.axisFontSize()).tickLength(this.axisTickLength()).low(h).high(r).lazyRender()}update(t,i){super.update(t,i),this._topAxis.tickFormat(this.tickFormat()).render(),this._bottomAxis.tickFormat(this.tickFormat()).render(),this._gantt.render()}columns(t){let i=super.columns.apply(this,arguments);return arguments.length>0&&this._gantt.columns(t),i}data(t){let i=super.data.apply(this,arguments);if(arguments.length>0){let e=this.data().map(n=>{let s=[...n];return s[1]=isNaN(n[1])?new Date(n[1]).getTime():Number(n[1]),s[2]=isNaN(n[2])?new Date(n[2]).getTime():Number(n[2]),s});this._gantt._minStart=at(e,n=>n[1]),this._gantt._maxEnd=lt(e,n=>n[2]),this._gantt.data(e)}return i}resize(t){let i=super.resize.apply(this,arguments);return this._topAxisElement&&this.resizeWrappers(),i}click(t,i,e){}dblclick(t,i,e){}tooltip(){return this._gantt._tooltip}};x.prototype._class+=" timeline_ReactAxisGanttSeries";x.prototype.publish("tickFormat",null,"string","Format rule applied to axis tick labels",void 0,{optional:!0});x.prototype.publish("axisHeight",22,"number","Height of axes (pixels)");x.prototype.publish("overlapTolerence",2,"number","overlapTolerence");x.prototype.publish("smallestRangeWidth",10,"number","Width of the shortest range (pixels)");x.prototype.publish("axisFontSize",null,"number","Font size of axis tick labels");x.prototype.publish("axisFontFamily",null,"string","Font family of axis tick labels");x.prototype.publish("axisTickLength",null,"number","Length of axis ticks");x.prototype.publishProxy("gutter","_gantt");x.prototype.publishProxy("renderMode","_gantt");x.prototype.publishProxy("strokeWidth","_gantt");x.prototype.publishProxy("fontSize","_gantt");x.prototype.publishProxy("fontFamily","_gantt");x.prototype.publishProxy("stroke","_gantt");x.prototype.publishProxy("cornerRadius","_gantt");x.prototype.publishProxy("titleColumn","_gantt");x.prototype.publishProxy("startDateColumn","_gantt");x.prototype.publishProxy("endDateColumn","_gantt");x.prototype.publishProxy("iconColumn","_gantt");x.prototype.publishProxy("colorColumn","_gantt");x.prototype.publishProxy("seriesColumn","_gantt");x.prototype.publishProxy("bucketColumn","_gantt");x.prototype.publishProxy("maxZoom","_gantt");x.prototype.publishProxy("evenSeriesBackground","_gantt");x.prototype.publishProxy("oddSeriesBackground","_gantt");x.prototype.publishProxy("bucketHeight","_gantt");import{timeFormat as Y,timeParse as Z}from"@hpcc-js/common";var T=class extends f{static{F(this,"ReactTimeline")}_axisLabelFormatter;constructor(){super(),this._drawStartPos="origin",this._topAxis.type("time"),this._bottomAxis.type("time"),this.tooltipHTML(t=>{let i=Z("%Q"),e=i(t[1]),n=i(t[2]),s=Y(this.tooltipTimeFormat());return`<div style="text-align:center;">${t[0]}<br/><br/>${s(e)} -&gt; ${s(n)}</div>`})}update(t,i){if(super.update(t,i),this.timePattern_exists()){let e=1/0,n=-1/0,s="",p="";this.data().map(h=>{let r=new Date(h[1]).getTime(),_=new Date(h[2]).getTime();e>r&&(e=r,s=""+h[1]),n<_&&(n=_,p=""+h[2])}),this._topAxis.type("time").timePattern(this.timePattern()).overlapMode("none").tickFormat(this._axisLabelFormatter).low(s).high(p),this._bottomAxis.type("time").timePattern(this.timePattern()).overlapMode("none").tickFormat(this._axisLabelFormatter).low(s).high(p),this._gantt._minStart=e,this._gantt._maxEnd=n}}tooltipHTML(t){return this._tooltipHTML=t,this.tooltip().tooltipHTML(this._tooltipHTML),this}parseAxisValue(t){let e=Z("%Q")(t);return Y(this.timePattern())(e)}onzoom(t){let i=this.width(),e=this._gantt._minStart,s=this._gantt._maxEnd-e,p=s/i,h=Math.floor(e-p*(t.x/t.k)),r=Math.ceil(s/t.k+h);this._topAxis.low(this.parseAxisValue(h)).high(this.parseAxisValue(r)).render(),this._bottomAxis.low(this.parseAxisValue(h)).high(this.parseAxisValue(r)).render()}};T.prototype._class+=" timeline_ReactTimeline";T.prototype.publish("timePattern","%Y-%m-%d","string","Time pattern used for parsing datetime strings on each data row",null,{optional:!0});T.prototype.publish("tooltipTimeFormat","%Y-%m-%d","string","Time format used in the default html tooltip");import{timeFormat as X,timeParse as ct}from"@hpcc-js/common";var R=ct("%Q"),z=class extends x{static{F(this,"ReactTimelineSeries")}_axisLabelFormatter;constructor(){super(),this._topAxis.type("time"),this._bottomAxis.type("time"),this.tooltipHTML(t=>{let i=R(t[1]),e=R(t[2]),n=X(this.tooltipTimeFormat());return`<div style="text-align:center;">${t[0]}<br/><br/>${n(i)} -&gt; ${n(e)}</div>`})}update(t,i){if(super.update(t,i),this.timePattern_exists()){let e=1/0,n=-1/0,s="",p="";this.data().forEach(h=>{let r=new Date(h[1]).getTime(),_=new Date(h[2]).getTime();e>r&&(e=r,s=""+h[1]),n<_&&(n=_,p=""+h[2])}),this._topAxis.type("time").timePattern(this.timePattern()).overlapMode("none").tickFormat(this._axisLabelFormatter).low(s).high(p),this._bottomAxis.type("time").timePattern(this.timePattern()).overlapMode("none").tickFormat(this._axisLabelFormatter).low(s).high(p),this._gantt._minStart=e,this._gantt._maxEnd=n}}tooltipHTML(t){return this._tooltipHTML=t,this.tooltip().tooltipHTML(this._tooltipHTML),this}parseAxisValue(t){let i=R(t);return X(this.timePattern())(i)}onzoom(t){let i=this.width(),e=this._gantt._minStart,s=this._gantt._maxEnd-e,p=s/i,h=Math.floor(e-p*(t.x/t.k)),r=Math.ceil(s/t.k+h);this._topAxis.low(this.parseAxisValue(h)).high(this.parseAxisValue(r)).render(),this._bottomAxis.low(this.parseAxisValue(h)).high(this.parseAxisValue(r)).render()}_tooltipHTML};z.prototype._class+=" timeline_ReactTimelineSeries";z.prototype.publish("timePattern","%Y-%m-%d","string","Time pattern used for parsing datetime strings on each data row",null,{optional:!0});z.prototype.publish("tooltipTimeFormat","%Y-%m-%d","string","Time format used in the default html tooltip");export{dt as BUILD_VERSION,b as MiniGantt,mt as PKG_NAME,ut as PKG_VERSION,f as ReactAxisGantt,x as ReactAxisGanttSeries,g as ReactGantt,T as ReactTimeline,z as ReactTimelineSeries};
32
- //# sourceMappingURL=index.js.map
1
+ import { ITooltip } from "@hpcc-js/api";
2
+ import { Axis } from "@hpcc-js/chart";
3
+ import { EntityPin, EntityRect, SVGWidget, SVGZoomWidget, Utility, d3Event, extent, local, max, min, scaleBand, scaleLinear, select, timeFormat, timeParse, zoom, zoomIdentity } from "@hpcc-js/common";
4
+ import { HTMLTooltip } from "@hpcc-js/html";
5
+ import { LabelledRect, render } from "@hpcc-js/react";
6
+ import { Border2 } from "@hpcc-js/layout";
7
+
8
+ //#region src/__package__.ts
9
+ const PKG_NAME = "@hpcc-js/timeline";
10
+ const PKG_VERSION = "3.2.0";
11
+ const BUILD_VERSION = "3.15.0";
12
+
13
+ //#endregion
14
+ //#region src/MiniGantt.ts
15
+ var MiniGantt = class extends SVGWidget {
16
+ tlAxis;
17
+ brAxis;
18
+ verticalBands;
19
+ _zoom;
20
+ gUpperContent;
21
+ gUpperAxis;
22
+ gMiddleContent;
23
+ gLowerAxis;
24
+ gLowerContent;
25
+ localRect = local();
26
+ localEntityPin = local();
27
+ tooltipFormatter;
28
+ _dateCache;
29
+ rootExtent;
30
+ _title_idx = 0;
31
+ _startDate_idx = 1;
32
+ _endDate_idx = 2;
33
+ _icon_idx = -1;
34
+ _color_idx = -1;
35
+ _yoffset_idx = -1;
36
+ constructor() {
37
+ super();
38
+ ITooltip.call(this);
39
+ Utility.SimpleSelectionMixin.call(this);
40
+ this._drawStartPos = "origin";
41
+ this.tooltipHTML((d) => `<center>${d[this._title_idx]}</center><br>${this.tooltipFormatter(this.brAxis.parse(d[this._startDate_idx]))} -> ${this.tooltipFormatter(this.brAxis.parse(d[this._endDate_idx]))}`);
42
+ this.tlAxis = new Axis().type("time");
43
+ this.brAxis = new Axis().type("time");
44
+ this.verticalBands = scaleBand().paddingOuter(.2).paddingInner(.2);
45
+ }
46
+ isHorizontal() {
47
+ return this.orientation() === "horizontal";
48
+ }
49
+ fullExtent() {
50
+ return extent([...this.data().map((d) => d[this._startDate_idx]), ...this.data().filter((d) => !!d[this._endDate_idx]).map((d) => d[this._endDate_idx])]);
51
+ }
52
+ extent() {
53
+ const extent$1 = this.rootExtent ? [this.rootExtent[1], this.rootExtent[2]] : this.fullExtent();
54
+ if (extent$1[0] !== void 0 && extent$1[1] !== void 0) {
55
+ if (extent$1[0] === extent$1[1] || this.centerOnMostRecent()) {
56
+ const parser = timeParse(this.timePattern());
57
+ const formatter = timeFormat(this.timePattern());
58
+ const date1 = parser(extent$1[0]);
59
+ const date2 = parser(extent$1[1]);
60
+ if (extent$1[0] === extent$1[1]) {
61
+ extent$1[0] = formatter(new Date(date1.setFullYear(date1.getFullYear() - 1)));
62
+ extent$1[1] = formatter(new Date(date1.setFullYear(date1.getFullYear() + 2)));
63
+ } else {
64
+ const time1 = date1.getTime();
65
+ const timeDiff = date2.getTime() - time1;
66
+ extent$1[0] = formatter(date1);
67
+ extent$1[1] = formatter(new Date(time1 + timeDiff * 2));
68
+ }
69
+ }
70
+ }
71
+ return extent$1;
72
+ }
73
+ dataStartPos(d) {
74
+ if (typeof this._dateCache[d[this._startDate_idx]] !== "undefined") return this._dateCache[d[this._startDate_idx]];
75
+ const pos = this.brAxis.scalePos(d[this._startDate_idx]);
76
+ this._dateCache[d[this._startDate_idx]] = pos;
77
+ return pos;
78
+ }
79
+ dataEndPos(d) {
80
+ if (typeof this._dateCache[d[this._endDate_idx]] !== "undefined") return this._dateCache[d[this._endDate_idx]];
81
+ const pos = this.brAxis.scalePos(d[this._endDate_idx]);
82
+ this._dateCache[d[this._endDate_idx]] = pos;
83
+ return pos;
84
+ }
85
+ dataWidth(d) {
86
+ return this.dataEndPos(d) - this.dataStartPos(d);
87
+ }
88
+ transform;
89
+ resetZoom() {
90
+ this._zoom.transform(this.element(), zoomIdentity.translate(0, this.isHorizontal() ? 0 : this.height()));
91
+ }
92
+ zoomed() {
93
+ this.transform = d3Event().transform;
94
+ this.render();
95
+ }
96
+ background;
97
+ enter(domNode, element) {
98
+ super.enter(domNode, element);
99
+ this._zoom = zoom().scaleExtent([0, this.maxZoom()]).on("zoom", () => {
100
+ this.zoomed();
101
+ });
102
+ this.background = element.append("rect").attr("fill", "white").attr("opacity", 0).on("dblclick", () => {
103
+ d3Event().stopPropagation();
104
+ delete this.rootExtent;
105
+ this.resetZoom();
106
+ });
107
+ this.gUpperContent = element.append("g").attr("class", "gUpperContent");
108
+ this.gUpperAxis = element.append("g").attr("class", "gUpperAxis");
109
+ this.gMiddleContent = element.append("g").attr("class", "gMiddleContent");
110
+ this.gLowerAxis = element.append("g").attr("class", "gLowerAxis");
111
+ this.gLowerContent = element.append("g").attr("class", "gLowerContent");
112
+ this.tlAxis.target(this.gUpperAxis.node()).tickFormat(this.tickFormat()).guideTarget(this.gUpperAxis.append("g").node()).shrinkToFit("none").overlapMode(this.tickFormat_exists() ? "stagger" : "none").extend(.1);
113
+ this.brAxis.target(this.gLowerAxis.node()).tickFormat(this.tickFormat()).guideTarget(this.gLowerAxis.append("g").node()).shrinkToFit("none").overlapMode(this.tickFormat_exists() ? "stagger" : "none").extend(.1);
114
+ element.call(this._zoom);
115
+ this._selection.widgetElement(this.gMiddleContent);
116
+ }
117
+ _prevIsHorizontal;
118
+ update(domNode, element) {
119
+ super.update(domNode, element);
120
+ this._dateCache = {};
121
+ this._title_idx = this.titleColumn() !== null ? this.columns().indexOf(this.titleColumn()) : this._title_idx;
122
+ this._startDate_idx = this.startDateColumn() !== null ? this.columns().indexOf(this.startDateColumn()) : this._startDate_idx;
123
+ this._endDate_idx = this.endDateColumn() !== null ? this.columns().indexOf(this.endDateColumn()) : this._endDate_idx;
124
+ this._icon_idx = this.iconColumn() !== null ? this.columns().indexOf(this.iconColumn()) : this._icon_idx;
125
+ this._color_idx = this.colorColumn() !== null ? this.columns().indexOf(this.colorColumn()) : this._color_idx;
126
+ this._yoffset_idx = this.yOffsetColumn() !== null ? this.columns().indexOf(this.yOffsetColumn()) : this._yoffset_idx;
127
+ if (this._prevIsHorizontal !== this.isHorizontal()) {
128
+ this._prevIsHorizontal = this.isHorizontal();
129
+ this.resetZoom();
130
+ return;
131
+ }
132
+ this.tooltipFormatter = timeFormat(this.tooltipTimeFormat());
133
+ const width = this.width();
134
+ const height = this.height();
135
+ this.background.attr("x", 0).attr("y", 0).attr("width", width).attr("height", height);
136
+ const extent$1 = this.extent();
137
+ this.tlAxis.x(width / 2).orientation(this.isHorizontal() ? "top" : "left").reverse(!this.isHorizontal()).timePattern(this.timePattern()).width(width - 1).low(extent$1[0]).high(extent$1[1]).updateScale();
138
+ this.brAxis.x(width / 2).y(height / 2).orientation(this.isHorizontal() ? "bottom" : "right").reverse(!this.isHorizontal()).timePattern(this.timePattern()).width(width - 1).height(height).low(extent$1[0]).high(extent$1[1]).updateScale();
139
+ if (this.transform) {
140
+ let low;
141
+ let hi;
142
+ if (this.isHorizontal()) {
143
+ low = this.tlAxis.parseInvert(this.tlAxis.invert(this.transform.invertX(0)));
144
+ hi = this.tlAxis.parseInvert(this.tlAxis.invert(this.transform.invertX(width - 1)));
145
+ } else {
146
+ low = this.tlAxis.parseInvert(this.tlAxis.invert(-this.transform.invertY(0)));
147
+ hi = this.tlAxis.parseInvert(this.tlAxis.invert(-this.transform.invertY(height - 1)));
148
+ }
149
+ this.tlAxis.low(low).high(hi).updateScale();
150
+ this.brAxis.low(low).high(hi).updateScale();
151
+ }
152
+ const data = this.data().sort(this.isHorizontal() ? (l, r) => {
153
+ const retVal = this.brAxis.scalePos(l[1]) - this.brAxis.scalePos(r[1]);
154
+ if (retVal === 0) return ("" + l[0]).localeCompare("" + r[0]);
155
+ return retVal;
156
+ } : (l, r) => {
157
+ return this.brAxis.scalePos(r[1]) - this.brAxis.scalePos(l[1]);
158
+ });
159
+ const events = data.filter((d) => !d[this._endDate_idx]);
160
+ const ranges = data.filter((d) => !!d[this._endDate_idx]);
161
+ this.tlAxis.render();
162
+ this.brAxis.render();
163
+ const brAxisBBox = this.brAxis.getBBox();
164
+ let upperContentHeight = this.updateEntityPins(events);
165
+ const lowerAxisHeight = brAxisBBox.height;
166
+ let lowerHeight = height - upperContentHeight;
167
+ const minYOffset = this._yoffset_idx !== -1 ? Math.min.apply(void 0, this.data().filter((row) => !isNaN(row[this._yoffset_idx])).map((row) => row[this._yoffset_idx])) : 0;
168
+ if (events.length > 0 && ranges.length === 0) {
169
+ this.tlAxis.visible(false);
170
+ let y_offset = upperContentHeight / 4;
171
+ if (y_offset > height / 2 - lowerAxisHeight) y_offset = height / 2 - lowerAxisHeight;
172
+ const upperContentYOffset = height / 2 + y_offset;
173
+ const lowerAxisYOffset = (height / 2 - lowerAxisHeight - y_offset) * -1;
174
+ const halfMinYOffset = minYOffset !== 0 ? minYOffset / 2 : 0;
175
+ this.gUpperContent.attr("transform", `translate(0, ${upperContentYOffset - halfMinYOffset})`);
176
+ this.gLowerAxis.attr("transform", `translate(0, ${lowerAxisYOffset - halfMinYOffset})`);
177
+ } else if (events.length === 0 && ranges.length > 0) {
178
+ this.tlAxis.visible(true);
179
+ this.gUpperContent.attr("transform", `translate(0, ${upperContentHeight})`);
180
+ this.gUpperAxis.attr("transform", `translate(0, ${upperContentHeight})`);
181
+ } else {
182
+ upperContentHeight -= minYOffset;
183
+ lowerHeight += minYOffset;
184
+ this.tlAxis.visible(true);
185
+ this.gUpperContent.attr("transform", `translate(0, ${upperContentHeight})`);
186
+ this.gUpperAxis.attr("transform", `translate(0, ${upperContentHeight})`);
187
+ this.gMiddleContent.attr("transform", `translate(0, ${upperContentHeight})`);
188
+ }
189
+ this.tlAxis.render();
190
+ const tlAxisBBox = this.tlAxis.getBBox();
191
+ const bucketData = [];
192
+ const bucketIndex = {};
193
+ for (const range of ranges) {
194
+ for (let i = 0; i < bucketData.length; ++i) {
195
+ const bucket = bucketData[i];
196
+ if (bucket.endPos + this.overlapTolerence() <= this.dataStartPos(range)) {
197
+ bucketIndex[range] = i;
198
+ bucket.endPos = this.dataEndPos(range);
199
+ break;
200
+ }
201
+ }
202
+ if (bucketIndex[range] === void 0) {
203
+ bucketIndex[range] = bucketData.length;
204
+ bucketData.push({ endPos: this.dataEndPos(range) });
205
+ }
206
+ }
207
+ const vbLower = this.isHorizontal() ? 0 + tlAxisBBox.height : 0 + tlAxisBBox.width;
208
+ const vbHigher = this.isHorizontal() ? lowerHeight - brAxisBBox.height : width - brAxisBBox.width;
209
+ this.verticalBands.range([vbLower, vbHigher]).domain(bucketData.map((_d, i) => i));
210
+ if (ranges.length > 0) this.updateEventRanges(events, ranges, bucketIndex, lowerHeight, tlAxisBBox, brAxisBBox, width);
211
+ }
212
+ updateEntityPins(events) {
213
+ let event_height = 0;
214
+ const context = this;
215
+ const entityPins = this.gUpperContent.selectAll(".entity_pin").data(events, (d) => d[0] + ":" + d[1]);
216
+ const eventFontColor_idx = this.eventFontColorColumn() ? this.columns().indexOf(this.eventFontColorColumn()) : -1;
217
+ const eventBorderColor_idx = this.eventBorderColorColumn() ? this.columns().indexOf(this.eventBorderColorColumn()) : -1;
218
+ const eventBackgroundColor_idx = this.eventBackgroundColorColumn() ? this.columns().indexOf(this.eventBackgroundColorColumn()) : -1;
219
+ const title_counts = {};
220
+ for (const d of events) {
221
+ const type = typeof d[context._title_idx] !== "undefined" ? d[context._title_idx] : d[0];
222
+ title_counts[type] = title_counts[type] ? title_counts[type] + 1 : 1;
223
+ }
224
+ const title_types = Object.keys(title_counts);
225
+ const title_group_offset = context.eventGroupOffset();
226
+ const entityPinsEnter = entityPins.enter().append("g").attr("class", "entity_pin");
227
+ entityPinsEnter.append("line").attr("class", "entity_line");
228
+ entityPinsEnter.on("mouseover", function(d) {
229
+ select(this).raise();
230
+ }).each(function(d, i) {
231
+ const entityPin = new EntityPin().target(this).icon("").iconOnlyShowOnHover(context.hideIconWhenCollapsed()).titleOnlyShowOnHover(context.hideTitleWhenCollapsed()).descriptionOnlyShowOnHover(context.hideDescriptionWhenCollapsed()).annotationOnlyShowOnHover(context.hideAnnotationsWhenCollapsed()).iconDiameter(18).iconPaddingPercent(1).titleFontSize(14).descriptionColor("#333").descriptionFontSize(15).iconColor(eventFontColor_idx === -1 ? "#333" : d[eventFontColor_idx]).titleColor(eventFontColor_idx === -1 ? "#333" : d[eventFontColor_idx]).descriptionColor(eventFontColor_idx === -1 ? "#333" : d[eventFontColor_idx]).backgroundShape("pin").backgroundColorFill(eventFontColor_idx === -1 ? "#f8f8f8" : d[eventBackgroundColor_idx]).backgroundColorStroke(eventFontColor_idx === -1 ? "#ccc" : d[eventBorderColor_idx]).cornerRadius(5).arrowHeight(10).arrowWidth(16);
232
+ context.localEntityPin.set(this, entityPin);
233
+ }).merge(entityPins).each(function(d, i) {
234
+ const entityPin = context.localEntityPin.get(this);
235
+ const _title = typeof d[context._title_idx] !== "undefined" ? d[context._title_idx] : entityPin.title();
236
+ const x_offset = context.dataStartPos(d) - 0;
237
+ let y_offset = title_types.indexOf(_title) % context.eventGroupMod() * title_group_offset - 5;
238
+ if (typeof d[context._yoffset_idx] !== "undefined") y_offset += d[context._yoffset_idx] ? d[context._yoffset_idx] : 0;
239
+ if (d[context._title_idx] !== entityPin.title() && d[context._startDate_idx] !== entityPin.description()) {
240
+ const parsed_start_time = context.brAxis.parse(d[context._startDate_idx]);
241
+ const formatted_start_time = context.tooltipFormatter(parsed_start_time);
242
+ entityPin.x(x_offset).y(y_offset).iconOnlyShowOnHover(context.hideIconWhenCollapsed()).titleOnlyShowOnHover(context.hideTitleWhenCollapsed()).descriptionOnlyShowOnHover(context.hideDescriptionWhenCollapsed()).annotationOnlyShowOnHover(context.hideAnnotationsWhenCollapsed()).icon(typeof d[context._icon_idx] !== "undefined" ? d[context._icon_idx] : entityPin.icon()).title(_title).description(formatted_start_time).animationFrameRender();
243
+ } else entityPin.move({
244
+ x: x_offset,
245
+ y: y_offset
246
+ });
247
+ const calc_height = entityPin.calcHeight();
248
+ if (event_height < calc_height) event_height = calc_height;
249
+ select(this).selectAll(".entity_line").attr("x1", x_offset).attr("x2", x_offset).attr("y1", 0).attr("y2", y_offset).style("stroke", eventFontColor_idx === -1 ? "#ccc" : d[eventBorderColor_idx]).style("stroke-width", 1);
250
+ });
251
+ entityPins.exit().each(function(d, i) {
252
+ context.localEntityPin.get(this).target(null);
253
+ }).remove();
254
+ const event_offset = Math.abs(Math.min(events.length, context.eventGroupMod()) * context.eventGroupOffset());
255
+ return event_height + event_offset;
256
+ }
257
+ updateEventRanges(events, ranges, bucketIndex, eventRangeHeight, tlAxisBBox, brAxisBBox, width) {
258
+ const context = this;
259
+ const lines = this.gMiddleContent.selectAll(".line").data(events, (d) => {
260
+ return d[context._title_idx];
261
+ });
262
+ lines.enter().append("line").attr("class", "line").merge(lines).attr(this.isHorizontal() ? "x1" : "y1", (d) => this.dataStartPos(d) - 0).attr(this.isHorizontal() ? "x2" : "y2", (d) => this.dataStartPos(d) - 0).attr(this.isHorizontal() ? "y1" : "x1", this.isHorizontal() ? tlAxisBBox.height : tlAxisBBox.width).attr(this.isHorizontal() ? "y2" : "x2", this.isHorizontal() ? eventRangeHeight - brAxisBBox.height : width - brAxisBBox.width);
263
+ lines.exit().remove();
264
+ const buckets = this.gMiddleContent.selectAll(".buckets").data(ranges, (d) => d[context._title_idx]);
265
+ buckets.enter().append("g").attr("class", "buckets").call(this._selection.enter.bind(this._selection)).each(function(d) {
266
+ const entityRect = new EntityRect().target(this).iconDiameter(28).iconPaddingPercent(0).titleFontSize(28).titleColor(context.rangeFontColor()).descriptionColor(context.rangeFontColor()).iconColor(context.rangeFontColor()).backgroundShape("rect").backgroundColorFill(d[context._color_idx]);
267
+ context.localRect.set(this, entityRect);
268
+ context.enterEntityRect(entityRect, d);
269
+ }).on("click", function(d) {
270
+ context.click(context.rowToObj(d), "range", context._selection.selected(this));
271
+ }, false).on("dblclick", function(d) {
272
+ context.rootExtent = d;
273
+ context.resetZoom();
274
+ context.dblclick(context.rowToObj(d), "range", context._selection.selected(this));
275
+ }, true).on("mouseout.tooltip", this.tooltip.hide).on("mousemove.tooltip", this.tooltip.show).merge(buckets).attr("transform", (d) => context.isHorizontal() ? `translate(${this.dataStartPos(d)}, ${this.verticalBands(bucketIndex[d])}) ` : `translate(${this.verticalBands(bucketIndex[d])}, ${this.dataStartPos(d)}) `).each(function(d) {
276
+ const textBox = context.localRect.get(this);
277
+ const x = context.dataWidth(d) / 2;
278
+ const y = context.verticalBands.bandwidth() / 2;
279
+ const rectWidth = Math.max(context.dataWidth(d), 2);
280
+ const rectHeight = Math.max(context.verticalBands.bandwidth(), 2);
281
+ const fontHeightRatio = .618;
282
+ const paddingSize = (1 - fontHeightRatio) / 2 * rectHeight;
283
+ const fontSize = rectHeight * fontHeightRatio;
284
+ const iconSize = fontSize;
285
+ textBox.pos(context.isHorizontal() ? {
286
+ x,
287
+ y
288
+ } : {
289
+ x: y,
290
+ y: x
291
+ }).fixedHeight(context.isHorizontal() ? rectHeight : rectWidth).fixedWidth(context.isHorizontal() ? rectWidth : rectHeight).icon(typeof d[context._icon_idx] !== "undefined" ? d[context._icon_idx] : "").title(typeof d[context._title_idx] !== "undefined" ? d[context._title_idx] : "").padding(paddingSize).iconDiameter(iconSize).titleFontSize(fontSize);
292
+ if (iconSize * 1.5 > rectWidth) textBox.icon(null);
293
+ context.updateEntityRect(textBox, d[context._icon_idx]);
294
+ textBox.render();
295
+ });
296
+ buckets.exit().remove();
297
+ }
298
+ exit(domNode, element) {
299
+ this.brAxis.target(null);
300
+ this.tlAxis.target(null);
301
+ super.exit(domNode, element);
302
+ }
303
+ click(row, col, sel) {}
304
+ dblclick(row, col, sel) {}
305
+ enterEntityRect(textbox, d) {}
306
+ updateEntityRect(textbox, d) {}
307
+ };
308
+ MiniGantt.prototype._class += " timeline_MiniGantt";
309
+ MiniGantt.prototype.implements(ITooltip.prototype);
310
+ MiniGantt.prototype.mixin(Utility.SimpleSelectionMixin);
311
+ MiniGantt.prototype.publish("timePattern", "%Y-%m-%d", "string", "timePattern");
312
+ MiniGantt.prototype.publish("tickFormat", null, "string", "tickFormat", void 0, { optional: true });
313
+ MiniGantt.prototype.publish("tooltipTimeFormat", "%Y-%m-%d", "string", "tooltipTimeFormat");
314
+ MiniGantt.prototype.publish("overlapTolerence", 2, "number", "overlapTolerence");
315
+ MiniGantt.prototype.publish("orientation", "horizontal", "set", "orientation", ["horizontal", "vertical"]);
316
+ MiniGantt.prototype.publish("rangeFontColor", "#ecf0f1", "html-color", "rangeFontColor");
317
+ MiniGantt.prototype.publish("titleColumn", null, "string", "titleColumn");
318
+ MiniGantt.prototype.publish("startDateColumn", null, "string", "startDateColumn");
319
+ MiniGantt.prototype.publish("endDateColumn", null, "string", "endDateColumn");
320
+ MiniGantt.prototype.publish("iconColumn", null, "string", "iconColumn");
321
+ MiniGantt.prototype.publish("colorColumn", null, "string", "colorColumn");
322
+ MiniGantt.prototype.publish("yOffsetColumn", null, "string", "yOffsetColumn");
323
+ MiniGantt.prototype.publish("maxZoom", 16, "number", "maxZoom");
324
+ MiniGantt.prototype.publish("eventGroupOffset", -50, "number", "eventGroupOffset");
325
+ MiniGantt.prototype.publish("eventGroupMod", 5, "number", "eventGroupMod");
326
+ MiniGantt.prototype.publish("eventFontColorColumn", null, "string", "eventFontColorColumn");
327
+ MiniGantt.prototype.publish("eventBorderColorColumn", null, "string", "eventBorderColorColumn");
328
+ MiniGantt.prototype.publish("eventBackgroundColorColumn", null, "string", "eventBackgroundColorColumn");
329
+ MiniGantt.prototype.publish("hideIconWhenCollapsed", false, "boolean", "hideIconWhenCollapsed");
330
+ MiniGantt.prototype.publish("hideTitleWhenCollapsed", false, "boolean", "hideTitleWhenCollapsed");
331
+ MiniGantt.prototype.publish("hideDescriptionWhenCollapsed", false, "boolean", "hideDescriptionWhenCollapsed");
332
+ MiniGantt.prototype.publish("hideAnnotationsWhenCollapsed", true, "boolean", "hideAnnotationsWhenCollapsed");
333
+ MiniGantt.prototype.publish("centerOnMostRecent", false, "boolean", "If true, the timeline will be centered on the most recent data point");
334
+
335
+ //#endregion
336
+ //#region src/ReactGantt.ts
337
+ var ReactGantt = class extends SVGZoomWidget {
338
+ _selection = new Utility.Selection(this);
339
+ _buckets;
340
+ _interpolateX;
341
+ _interpolateY;
342
+ _bucketsBySeries;
343
+ _dataBySeries;
344
+ _origIdxMap;
345
+ _seriesBackgrounds;
346
+ _maxFontSize;
347
+ _tooltip;
348
+ _minStart;
349
+ _maxEnd;
350
+ _title_idx = 0;
351
+ _startDate_idx = 1;
352
+ _endDate_idx = 2;
353
+ _icon_idx = -1;
354
+ _color_idx = -1;
355
+ _series_idx = -1;
356
+ _bucket_idx = -1;
357
+ _yoffset_idx = -1;
358
+ _maxX;
359
+ _maxY;
360
+ _rangeOptions = {
361
+ rangePadding: 2,
362
+ fontFamily: "Verdana",
363
+ fontSize: 12,
364
+ fill: "white",
365
+ stroke: "black",
366
+ textFill: "black",
367
+ cornerRadius: 3,
368
+ strokeWidth: 0
369
+ };
370
+ constructor(drawStartPosition = "origin") {
371
+ super();
372
+ this._drawStartPos = drawStartPosition;
373
+ this.showToolbar_default(false);
374
+ this._tooltip = new HTMLTooltip();
375
+ this._tooltip.tooltipHTML((d) => {
376
+ return `<div style="text-align:center;">${d[0]}<br/><br/>${d[1]} -&gt; ${d[2]}</div>`;
377
+ });
378
+ this._tooltip.followCursor(true);
379
+ }
380
+ selection(_) {
381
+ if (!arguments.length) return this._selection.get();
382
+ this._selection.set(_);
383
+ return this;
384
+ }
385
+ _rangeRenderer = LabelledRect;
386
+ rangeRenderer(_) {
387
+ if (!arguments.length) return this._rangeRenderer;
388
+ this._rangeRenderer = _;
389
+ return this._rangeRenderer;
390
+ }
391
+ enter(domNode, element) {
392
+ super.enter(domNode, element);
393
+ const context = this;
394
+ element.on("click", function(d) {
395
+ context._selection.clear();
396
+ });
397
+ this._tooltip.target(domNode);
398
+ }
399
+ update(domNode, element) {
400
+ super.update(domNode, element);
401
+ this.zoomExtent([.05, this.maxZoom()]);
402
+ this._title_idx = this.titleColumn() !== null ? this.columns().indexOf(this.titleColumn()) : this._title_idx;
403
+ this._startDate_idx = this.startDateColumn() !== null ? this.columns().indexOf(this.startDateColumn()) : this._startDate_idx;
404
+ this._endDate_idx = this.endDateColumn() !== null ? this.columns().indexOf(this.endDateColumn()) : this._endDate_idx;
405
+ this._icon_idx = this.iconColumn() !== null ? this.columns().indexOf(this.iconColumn()) : this._icon_idx;
406
+ this._color_idx = this.colorColumn() !== null ? this.columns().indexOf(this.colorColumn()) : this._color_idx;
407
+ this._series_idx = this.seriesColumn() !== null ? this.columns().indexOf(this.seriesColumn()) : this._series_idx;
408
+ this._bucket_idx = this.bucketColumn() !== null ? this.columns().indexOf(this.bucketColumn()) : -1;
409
+ const context = this;
410
+ const w = this.width();
411
+ const x0 = 0;
412
+ const x1 = w;
413
+ this._interpolateX = scaleLinear().domain([this._minStart, this._maxEnd]).range([x0, x1]);
414
+ this.data().sort((a, b) => a[1] - b[1]);
415
+ if (this._series_idx > -1) {
416
+ this._origIdxMap = {};
417
+ this._dataBySeries = {};
418
+ this._bucketsBySeries = {};
419
+ this.data().forEach((dataRow, origIdx) => {
420
+ const seriesKey = dataRow[this._series_idx];
421
+ if (!this._dataBySeries[seriesKey]) {
422
+ this._origIdxMap[seriesKey] = {};
423
+ this._dataBySeries[seriesKey] = [];
424
+ }
425
+ this._dataBySeries[seriesKey].push({
426
+ dataRow,
427
+ origIdx
428
+ });
429
+ });
430
+ const gutter = this.gutter();
431
+ let bucketOffset = 0;
432
+ const seriesKeys = Object.keys(this._dataBySeries);
433
+ seriesKeys.forEach((seriesKey) => {
434
+ this._dataBySeries[seriesKey].sort((a, b) => a.dataRow[1] - b.dataRow[1]);
435
+ this._bucketsBySeries[seriesKey] = this.calcBuckets(this._dataBySeries[seriesKey].map((n) => n.dataRow), 1, 2);
436
+ this._bucketsBySeries[seriesKey].bucketHeight = this.bucketHeight();
437
+ this._bucketsBySeries[seriesKey].bucketOffset = bucketOffset;
438
+ bucketOffset += (this._bucketsBySeries[seriesKey].bucketHeight + this.strokeWidth() + this.gutter()) * (this._bucketsBySeries[seriesKey].maxBucket + 1);
439
+ this._dataBySeries[seriesKey].forEach((n, i) => {
440
+ this._origIdxMap[seriesKey][n.origIdx] = i;
441
+ });
442
+ });
443
+ this._seriesBackgrounds = this._renderElement.selectAll(".series-background").data(seriesKeys.map((key) => {
444
+ return this._bucketsBySeries[key];
445
+ }));
446
+ this._seriesBackgrounds.join((enter) => enter.append("rect").attr("class", "series-background"), (update) => update, (exit) => exit.each(function(d) {
447
+ delete d.element;
448
+ }).remove()).attr("opacity", (d) => d.props && d.props.hidden ? 0 : 1).each(function(d, i) {
449
+ select(this).attr("x", 0).attr("y", d.bucketOffset - gutter / 2).attr("width", w).attr("height", (d.bucketHeight + gutter) * (d.maxBucket + 1) + gutter).attr("fill", i % 2 ? context.oddSeriesBackground() : context.evenSeriesBackground());
450
+ });
451
+ } else if (this._bucket_idx !== -1) this._buckets = this.calcBuckets(this.data(), this._startDate_idx, this._endDate_idx, this._bucket_idx);
452
+ else this._buckets = this.calcBuckets(this.data(), this._startDate_idx, this._endDate_idx);
453
+ const interpedStart = this._interpolateX(this._minStart);
454
+ this.zoomTo([interpedStart, 0], 1);
455
+ const bucketHeight = this.bucketHeight();
456
+ this.setRangeOptions();
457
+ this._maxFontScale = bucketHeight - this.rangePadding() * 2;
458
+ this.measureDataText();
459
+ const itemSelection = this._renderElement.selectAll(".item").data(this.data());
460
+ const borderOffset1 = this.strokeWidth();
461
+ const borderOffset2 = borderOffset1 * 2;
462
+ itemSelection.join((enter) => enter.append("g").attr("class", "item").on("click.selectionBag", function(d, i) {
463
+ const _id = d.id === void 0 ? i : d.id;
464
+ if (context._selection.isSelected({
465
+ _id,
466
+ element: d.element
467
+ })) context._selection.clear();
468
+ else context._selection.click({
469
+ _id,
470
+ element: () => d.element
471
+ }, d3Event);
472
+ context.selectionChanged();
473
+ d3Event().stopPropagation();
474
+ }).on("click", function(d) {
475
+ const selected = d.element.classed("selected");
476
+ if (d[context.columns().length]) d.__lparam = d[context.columns().length];
477
+ context.click(d, "", selected);
478
+ }).on("dblclick", function(d) {
479
+ const selected = d.element.classed("selected");
480
+ if (d[context.columns().length]) d.__lparam = d[context.columns().length];
481
+ context.click(d, "", selected);
482
+ }).on("mousein", function(d) {
483
+ context.highlightItem(select(this), d);
484
+ const selected = d.element.classed("selected");
485
+ context.mousein(d, "", selected);
486
+ }).on("mouseover", function(d) {
487
+ const d3evt = d3Event();
488
+ context._tooltip._triggerElement = d.element;
489
+ context._tooltip._cursorLoc = [d3evt.clientX, d3evt.clientY];
490
+ context._tooltip.data(d).visible(true).fitContent(true).render();
491
+ context.highlightItem(select(this), d);
492
+ const selected = d.element.classed("selected");
493
+ context.mouseover(d, "", selected);
494
+ }).on("mouseout", function(d) {
495
+ context._tooltip.visible(false).render();
496
+ context.highlightItem(null, null);
497
+ const selected = d.element.classed("selected");
498
+ context.mouseout(d, "", selected);
499
+ }).each(function(d, i) {
500
+ d.that = this;
501
+ d.element = select(this);
502
+ d.x = context._interpolateX(d[1]);
503
+ const endX = context._interpolateX(d[2]);
504
+ if (context._series_idx > -1) {
505
+ const seriesKey = d[context._series_idx];
506
+ const bucket = context._bucketsBySeries[seriesKey].bucketMap[context._origIdxMap[seriesKey][i]];
507
+ d.y = context._bucketsBySeries[seriesKey].interpolateY(bucket) + context._bucketsBySeries[seriesKey].bucketOffset;
508
+ } else {
509
+ const _i = context._bucket_idx === -1 ? i : d[context._bucket_idx];
510
+ d.y = context._buckets.interpolateY(context._buckets.bucketMap[_i]);
511
+ }
512
+ d.props = {
513
+ ...d[3],
514
+ text: d[0]
515
+ };
516
+ d.props.width = endX - d.x;
517
+ d.props.height = bucketHeight;
518
+ d.x += borderOffset1;
519
+ d.y += borderOffset1;
520
+ d.props.width -= borderOffset2;
521
+ d.props.height -= borderOffset2;
522
+ d.element.attr("transform", `translate(${d.x + d.props.width / 2} ${d.y + d.props.height / 2})`);
523
+ }), (update) => update, (exit) => exit.each(function(d) {
524
+ delete d.element;
525
+ }).remove()).attr("opacity", (d) => d.props && d.props.hidden ? 0 : 1).each(function(d, i) {
526
+ d.that = this;
527
+ if (context._series_idx > -1) {
528
+ const seriesKey = d[context._series_idx];
529
+ d.x = context.renderRangeElement(d, i, false, context._rangeOptions, seriesKey);
530
+ } else d.x = context.renderRangeElement(d, i, false, context._rangeOptions);
531
+ }).on("dblclick.zoom", (d) => {
532
+ const x1$1 = this._interpolateX(d[1]);
533
+ const xScale = w / (this._interpolateX(d[2]) - x1$1);
534
+ this.zoomTo([-x1$1 * xScale, 0], xScale);
535
+ });
536
+ element.on("dblclick.zoom", null);
537
+ }
538
+ exit(domNode, element) {
539
+ this._tooltip.target(null);
540
+ super.exit(domNode, element);
541
+ }
542
+ renderRangeElement(d, i, transformEach = false, options = {}, seriesKey) {
543
+ const borderOffset1 = options.strokeWidth;
544
+ const borderOffset2 = borderOffset1 * 2;
545
+ const padding = options.rangePadding;
546
+ let endX;
547
+ const x = isNaN(this._transform.x) ? 0 : this._transform.x;
548
+ const k = isNaN(this._transform.k) ? 1 : this._transform.k;
549
+ let b;
550
+ const bucketHeight = this.bucketHeight();
551
+ d.that.setAttribute("data-series", seriesKey);
552
+ if (this._color_idx > -1) d.that.setAttribute("data-color", d[this._color_idx]);
553
+ if (seriesKey !== void 0) {
554
+ b = this._bucketsBySeries[seriesKey].bucketMap[this._origIdxMap[seriesKey][i]];
555
+ d.that.setAttribute("data-b", b);
556
+ d.that.setAttribute("data-bucketOffset", this._bucketsBySeries[seriesKey].bucketOffset);
557
+ d.y = this._bucketsBySeries[seriesKey].interpolateY(b) + this._bucketsBySeries[seriesKey].bucketOffset;
558
+ d.that.setAttribute("data-dy", d.y);
559
+ } else {
560
+ b = this._buckets.bucketMap[i];
561
+ d.y = this._buckets.interpolateY(b);
562
+ }
563
+ if (this._color_idx > -1) options.fill = d[this._color_idx];
564
+ if (!transformEach) {
565
+ d.x = this._interpolateX(d[1]);
566
+ endX = this._interpolateX(d[2]);
567
+ d.props = {
568
+ ...d[3],
569
+ text: d[0]
570
+ };
571
+ d.props.width = (endX - d.x) / k;
572
+ } else {
573
+ d.x = this._interpolateX(d[1]) * k;
574
+ endX = this._interpolateX(d[2]) * k;
575
+ d.props = {
576
+ ...d[3],
577
+ text: d[0]
578
+ };
579
+ d.props.width = (endX - d.x) / k;
580
+ d.x += x;
581
+ d.props.width *= k;
582
+ }
583
+ d.props.height = bucketHeight;
584
+ if (seriesKey === void 0 && this._buckets.bucketScale < 1) d.props.height = this._buckets.bucketScale * bucketHeight;
585
+ if (d.element === void 0 && d.that) d.element = select(d.that);
586
+ d.element.attr("transform", `translate(${d.x + d.props.width / 2} ${d.y + d.props.height / 2})`);
587
+ d.x += borderOffset1;
588
+ d.y += borderOffset1;
589
+ d.props.width -= borderOffset2;
590
+ d.props.height -= borderOffset2;
591
+ d.props.width = d.props.width < 1 ? 1 : d.props.width;
592
+ d.props.height = d.props.height < 1 ? 1 : d.props.height;
593
+ let text = this.truncateText(d.props.text, d.props.width - padding, this._maxFontScale);
594
+ if (text !== d.props.text) text = this.truncateText(d.props.text, d.props.width - padding);
595
+ else d.props.fontSize = this._maxFontScale * options.fontSize;
596
+ if (seriesKey === void 0 && this._buckets.bucketScale < 1) d.props.fontSize = Math.min(this._maxFontScale, this._buckets.bucketScale) * options.fontSize;
597
+ if (!this._maxY || this._maxY < d.y + d.props.height) this._maxY = d.y + d.props.height;
598
+ if (!this._maxX || this._maxX < d.x + d.props.width) this._maxX = d.x + d.props.width;
599
+ render(this._rangeRenderer, {
600
+ ...options,
601
+ ...d.props,
602
+ text
603
+ }, d.that);
604
+ }
605
+ setRangeOptions() {
606
+ this._rangeOptions = {
607
+ rangePadding: this.rangePadding(),
608
+ fontFamily: this.fontFamily(),
609
+ fontSize: this.fontSize(),
610
+ strokeWidth: this.strokeWidth(),
611
+ fill: this.fill(),
612
+ stroke: this.stroke(),
613
+ textFill: this.rangeFontColor(),
614
+ cornerRadius: this.cornerRadius()
615
+ };
616
+ }
617
+ _transform = {
618
+ k: 1,
619
+ x: 0,
620
+ y: 0
621
+ };
622
+ zoomed(transform) {
623
+ this._transform = transform;
624
+ switch (this.renderMode()) {
625
+ case "scale-all":
626
+ this._zoomScale = transform.k;
627
+ this._zoomTranslate = [transform.x, 0];
628
+ this._zoomG.attr("transform", `translate(${transform.x} 0)scale(${transform.k} 1)`);
629
+ break;
630
+ default:
631
+ const options = this._rangeOptions;
632
+ this.data().forEach((d, i) => {
633
+ if (this._color_idx > -1) options.fill = d[this._color_idx];
634
+ if (this._series_idx > -1) {
635
+ const seriesKey = d[this._series_idx];
636
+ this.renderRangeElement(d, i, true, options, seriesKey);
637
+ } else this.renderRangeElement(d, i, true, options);
638
+ });
639
+ }
640
+ this.zoomedHook(transform);
641
+ }
642
+ zoomedHook(transform) {}
643
+ calcBuckets(data, startKey, endKey, bucketKey) {
644
+ const bucketMap = {};
645
+ const bucketKeyMap = {};
646
+ const tol = this.overlapTolerence();
647
+ const buckets = [{ end: -Infinity }];
648
+ let maxBucket = 0;
649
+ if (bucketKey !== void 0) {
650
+ data.forEach((d, i) => {
651
+ bucketMap[i] = d[bucketKey];
652
+ bucketKeyMap[d[bucketKey]] = true;
653
+ });
654
+ maxBucket = Object.keys(bucketKeyMap).length;
655
+ } else data.forEach((d, i) => {
656
+ for (let i2 = 0; i2 < buckets.length; ++i2) if (i === 0 || buckets[i2][endKey] + tol <= d[startKey]) {
657
+ bucketMap[i] = i2;
658
+ if (maxBucket < i2) maxBucket = i2;
659
+ buckets[i2][endKey] = d[endKey];
660
+ break;
661
+ }
662
+ if (bucketMap[i] === void 0) {
663
+ bucketMap[i] = buckets.length;
664
+ const b = {};
665
+ b[endKey] = d[endKey];
666
+ buckets.push(b);
667
+ }
668
+ if (maxBucket < bucketMap[i]) maxBucket = bucketMap[i];
669
+ });
670
+ const height = (maxBucket + 1) * (this.bucketHeight() + this.gutter());
671
+ return {
672
+ bucketMap,
673
+ maxBucket,
674
+ bucketScale: this.height() / height,
675
+ interpolateY: scaleLinear().domain([0, maxBucket + 1]).range([0, Math.min(this.height(), height)])
676
+ };
677
+ }
678
+ data(_) {
679
+ const retVal = super.data.apply(this, arguments);
680
+ if (arguments.length > 0) {
681
+ this._minStart = Math.min(...this.data().map((n) => n[1])) ?? 0;
682
+ this._maxEnd = Math.max(...this.data().map((n) => n[2])) ?? 1;
683
+ this.measureDataText(true);
684
+ }
685
+ return retVal;
686
+ }
687
+ _textWidths;
688
+ _maxFontScale;
689
+ _characterWidths;
690
+ _prevFontFamily;
691
+ _prevFontSize;
692
+ measureDataText(forceMeasure = false) {
693
+ const textWidths = {};
694
+ const characterWidths = {};
695
+ const fontFamily = this.fontFamily();
696
+ const fontSize = this.fontSize();
697
+ const bucketHeight = this.bucketHeight();
698
+ if (bucketHeight) this._maxFontScale = (bucketHeight - this.rangePadding() * 2) / fontSize;
699
+ if (forceMeasure || this._prevFontFamily !== fontFamily || this._prevFontSize !== fontSize) {
700
+ characterWidths["."] = Utility.textSize(".", fontFamily, fontSize).width;
701
+ this.data().forEach((d) => {
702
+ if (!textWidths[d[0]]) textWidths[d[0]] = Utility.textSize(d[0], fontFamily, fontSize).width;
703
+ d[0].split("").forEach((char) => {
704
+ if (!characterWidths[char]) characterWidths[char] = Utility.textSize(char, fontFamily, fontSize).width;
705
+ });
706
+ });
707
+ this._textWidths = textWidths;
708
+ this._characterWidths = characterWidths;
709
+ }
710
+ this._prevFontFamily = fontFamily;
711
+ this._prevFontSize = fontSize;
712
+ }
713
+ truncateText(text, width, scale = 1) {
714
+ if (this._textWidths[text] * scale < width) return text;
715
+ let ret = "";
716
+ let sum = 0;
717
+ const _width = width - this._characterWidths["."] * 3;
718
+ for (const char of text) {
719
+ sum += this._characterWidths[char];
720
+ if (sum < _width) ret += char;
721
+ else break;
722
+ }
723
+ return _width < 0 ? "" : ret + "...";
724
+ }
725
+ resize(_size) {
726
+ let retVal;
727
+ if (this.fitWidthToContent() || this.fitHeightToContent()) retVal = super.resize.call(this, {
728
+ width: _size.width,
729
+ height: this._maxY
730
+ });
731
+ else retVal = super.resize.apply(this, arguments);
732
+ return retVal;
733
+ }
734
+ selectionChanged() {}
735
+ highlightItem(_element, d) {}
736
+ click(row, _col, sel) {}
737
+ dblclick(row, _col, sel) {}
738
+ mousein(row, _col, sel) {}
739
+ mouseover(row, _col, sel) {}
740
+ mouseout(row, _col, sel) {}
741
+ };
742
+ ReactGantt.prototype._class += " timeline_ReactGantt";
743
+ ReactGantt.prototype.publish("fitWidthToContent", false, "boolean", "If true, resize will simply reapply the bounding box width");
744
+ ReactGantt.prototype.publish("fitHeightToContent", false, "boolean", "If true, resize will simply reapply the bounding box height");
745
+ ReactGantt.prototype.publish("titleColumn", null, "string", "Column name to for the title");
746
+ ReactGantt.prototype.publish("startDateColumn", null, "string", "Column name to for the start date");
747
+ ReactGantt.prototype.publish("endDateColumn", null, "string", "Column name to for the end date");
748
+ ReactGantt.prototype.publish("iconColumn", null, "string", "Column name to for the icon");
749
+ ReactGantt.prototype.publish("colorColumn", null, "string", "Column name to for the color");
750
+ ReactGantt.prototype.publish("seriesColumn", null, "string", "Column name to for the series identifier");
751
+ ReactGantt.prototype.publish("bucketColumn", null, "string", "Column name to for the bucket identifier");
752
+ ReactGantt.prototype.publish("renderMode", "default", "set", "Render modes vary in features and performance", ["default", "scale-all"]);
753
+ ReactGantt.prototype.publish("rangePadding", 3, "number", "Padding within each range rectangle (pixels)");
754
+ ReactGantt.prototype.publish("fill", "#1f77b4", "string", "Background color of range rectangle");
755
+ ReactGantt.prototype.publish("stroke", null, "string", "Color of range rectangle border");
756
+ ReactGantt.prototype.publish("strokeWidth", null, "number", "Width of range rectangle border (pixels)");
757
+ ReactGantt.prototype.publish("cornerRadius", 3, "number", "Space between range buckets (pixels)");
758
+ ReactGantt.prototype.publish("fontFamily", null, "string", "Font family within range rectangle", null, { optional: true });
759
+ ReactGantt.prototype.publish("fontSize", 10, "number", "Size of font within range rectangle (pixels)");
760
+ ReactGantt.prototype.publish("rangeFontColor", "#ecf0f1", "html-color", "rangeFontColor");
761
+ ReactGantt.prototype.publish("overlapTolerence", 2, "number", "overlapTolerence");
762
+ ReactGantt.prototype.publish("smallestRangeWidth", 10, "number", "Width of the shortest range (pixels)");
763
+ ReactGantt.prototype.publish("bucketHeight", 100, "number", "Max height of range element (pixels)");
764
+ ReactGantt.prototype.publish("gutter", 2, "number", "Space between range buckets (pixels)");
765
+ ReactGantt.prototype.publish("maxZoom", 16, "number", "Maximum zoom");
766
+ ReactGantt.prototype.publish("evenSeriesBackground", "#FFFFFF", "html-color", "Background color of even series rows");
767
+ ReactGantt.prototype.publish("oddSeriesBackground", "#DDDDDD", "html-color", "Background color of odd series rows");
768
+
769
+ //#endregion
770
+ //#region src/ReactAxisGantt.ts
771
+ var ReactAxisGantt = class extends SVGWidget {
772
+ _topAxis = new Axis("center").orientation("top").type("linear").shrinkToFit("none").overlapMode("hide").extend(0).tickFormat("d");
773
+ _gantt = new ReactGantt("center").stroke("#000000");
774
+ _bottomAxis = new Axis("center").orientation("bottom").type("linear").shrinkToFit("none").overlapMode("hide").extend(0).tickFormat("d");
775
+ _topAxisElement;
776
+ _contentElement;
777
+ _bottomAxisElement;
778
+ _topRect;
779
+ _contentRect;
780
+ _bottomRect;
781
+ rangeRenderer;
782
+ constructor() {
783
+ super();
784
+ this._drawStartPos = "origin";
785
+ this.rangeRenderer = function() {
786
+ const ret = this._gantt.rangeRenderer.apply(this._gantt, arguments);
787
+ if (!arguments.length) return ret;
788
+ return this;
789
+ };
790
+ }
791
+ selection(_) {
792
+ if (!arguments.length) return this._gantt.selection();
793
+ this._gantt.selection(_);
794
+ return this;
795
+ }
796
+ resizeWrappers() {
797
+ const w = this.width();
798
+ const h = this.height();
799
+ const axisHeight = this.axisHeight();
800
+ const contentHeight = h - axisHeight * 2;
801
+ const borderOffset1 = this.strokeWidth();
802
+ this._topRect.attr("height", axisHeight).attr("width", w).attr("fill", "transparent");
803
+ this._topAxisElement.attr("transform", "translate(0 0)");
804
+ this._topAxis.resize({
805
+ height: axisHeight,
806
+ width: w
807
+ });
808
+ this._contentRect.attr("height", contentHeight).attr("width", w).attr("fill", "transparent");
809
+ this._contentElement.attr("transform", `translate(0 ${axisHeight + borderOffset1})`);
810
+ this._gantt.resize({
811
+ height: contentHeight,
812
+ width: w
813
+ });
814
+ this._bottomRect.attr("height", axisHeight).attr("width", w).attr("fill", "transparent");
815
+ this._bottomAxisElement.attr("transform", `translate(0 ${axisHeight + contentHeight + borderOffset1})`);
816
+ this._bottomAxis.resize({
817
+ height: axisHeight,
818
+ width: w
819
+ });
820
+ }
821
+ enter(domNode, element) {
822
+ super.enter(domNode, element);
823
+ this._gantt.click = (row, col, sel) => {
824
+ this.click(row, col, sel);
825
+ };
826
+ this._gantt.dblclick = (row, col, sel) => {
827
+ this.dblclick(row, col, sel);
828
+ };
829
+ this._topAxisElement = element.append("g").attr("class", "top-axis-wrapper");
830
+ this._topRect = this._topAxisElement.append("rect").attr("class", "top-axis-rect");
831
+ this._contentElement = element.append("g").attr("class", "content-wrapper");
832
+ this._contentRect = this._contentElement.append("rect").attr("class", "content-rect");
833
+ this._bottomAxisElement = element.append("g").attr("class", "bottom-axis-wrapper");
834
+ this._bottomRect = this._bottomAxisElement.append("rect").attr("class", "top-axis-rect");
835
+ this._topAxis.target(this._topAxisElement.node());
836
+ this._gantt.target(this._contentElement.node()).bucketHeight(30);
837
+ this._bottomAxis.target(this._bottomAxisElement.node());
838
+ this.resizeWrappers();
839
+ this._gantt.zoomedHook = (transform) => {
840
+ this.onzoom(transform);
841
+ };
842
+ }
843
+ onzoom(transform) {
844
+ const w = this.width();
845
+ const low = this._gantt._minStart;
846
+ const range = this._gantt._maxEnd - low;
847
+ const wpp = range / w;
848
+ const nextLow = Math.floor(low - wpp * (transform.x / transform.k));
849
+ const nextHigh = Math.ceil(range / transform.k + nextLow);
850
+ this._topAxis.fontFamily(this.axisFontFamily()).fontSize(this.axisFontSize()).tickLength(this.axisTickLength()).low(nextLow).high(nextHigh).render();
851
+ this._bottomAxis.fontFamily(this.axisFontFamily()).fontSize(this.axisFontSize()).tickLength(this.axisTickLength()).low(nextLow).high(nextHigh).render();
852
+ }
853
+ update(domNode, element) {
854
+ super.update(domNode, element);
855
+ this._topAxis.tickFormat(this.tickFormat()).render();
856
+ this._bottomAxis.tickFormat(this.tickFormat()).render();
857
+ this._gantt.render();
858
+ }
859
+ exit(domNode, element) {
860
+ this._bottomAxis.target(null);
861
+ this._gantt.target(null);
862
+ this._topAxis.target(null);
863
+ super.exit(domNode, element);
864
+ }
865
+ columns(_) {
866
+ const retVal = super.columns.apply(this, arguments);
867
+ if (arguments.length > 0) this._gantt.columns(_);
868
+ return retVal;
869
+ }
870
+ data(_) {
871
+ const retVal = super.data.apply(this, arguments);
872
+ if (arguments.length > 0) {
873
+ const ganttData = this.data().map((n) => {
874
+ const ret = [...n];
875
+ ret[1] = isNaN(n[1]) ? new Date(n[1]).getTime() : Number(n[1]);
876
+ ret[2] = isNaN(n[2]) ? new Date(n[2]).getTime() : Number(n[2]);
877
+ return ret;
878
+ });
879
+ this._gantt._minStart = Math.min(...ganttData.map((n) => n[1])) ?? 0;
880
+ this._gantt._maxEnd = Math.max(...ganttData.map((n) => n[2])) ?? 1;
881
+ this._gantt.data(ganttData);
882
+ }
883
+ return retVal;
884
+ }
885
+ resize(_size) {
886
+ const retVal = super.resize.apply(this, arguments);
887
+ if (this._topAxisElement) this.resizeWrappers();
888
+ return retVal;
889
+ }
890
+ click(row, col, sel) {}
891
+ dblclick(row, col, sel) {}
892
+ tooltip() {
893
+ return this._gantt._tooltip;
894
+ }
895
+ };
896
+ ReactAxisGantt.prototype._class += " timeline_ReactAxisGantt";
897
+ ReactAxisGantt.prototype.publish("tickFormat", null, "string", "Format rule applied to axis tick labels", void 0, { optional: true });
898
+ ReactAxisGantt.prototype.publish("axisHeight", 22, "number", "Height of axes (pixels)");
899
+ ReactAxisGantt.prototype.publish("overlapTolerence", 2, "number", "overlapTolerence");
900
+ ReactAxisGantt.prototype.publish("smallestRangeWidth", 10, "number", "Width of the shortest range (pixels)");
901
+ ReactAxisGantt.prototype.publish("axisFontSize", null, "number", "Font size of axis tick labels");
902
+ ReactAxisGantt.prototype.publish("axisFontFamily", null, "string", "Font family of axis tick labels");
903
+ ReactAxisGantt.prototype.publish("axisTickLength", null, "number", "Length of axis ticks");
904
+ ReactAxisGantt.prototype.publishProxy("gutter", "_gantt");
905
+ ReactAxisGantt.prototype.publishProxy("renderMode", "_gantt");
906
+ ReactAxisGantt.prototype.publishProxy("strokeWidth", "_gantt");
907
+ ReactAxisGantt.prototype.publishProxy("fontSize", "_gantt");
908
+ ReactAxisGantt.prototype.publishProxy("fontFamily", "_gantt");
909
+ ReactAxisGantt.prototype.publishProxy("stroke", "_gantt");
910
+ ReactAxisGantt.prototype.publishProxy("cornerRadius", "_gantt");
911
+ ReactAxisGantt.prototype.publishProxy("titleColumn", "_gantt");
912
+ ReactAxisGantt.prototype.publishProxy("startDateColumn", "_gantt");
913
+ ReactAxisGantt.prototype.publishProxy("endDateColumn", "_gantt");
914
+ ReactAxisGantt.prototype.publishProxy("iconColumn", "_gantt");
915
+ ReactAxisGantt.prototype.publishProxy("colorColumn", "_gantt");
916
+ ReactAxisGantt.prototype.publishProxy("bucketColumn", "_gantt");
917
+ ReactAxisGantt.prototype.publishProxy("maxZoom", "_gantt");
918
+ ReactAxisGantt.prototype.publishProxy("bucketHeight", "_gantt");
919
+
920
+ //#endregion
921
+ //#region src/ReactAxisGanttSeries.ts
922
+ var ReactAxisGanttSeries = class extends Border2 {
923
+ _topAxis = new Axis("origin").orientation("top").type("linear").shrinkToFit("none").overlapMode("hide").extend(0).tickFormat("d");
924
+ _gantt = new ReactGantt("origin").stroke("#000000").fitHeightToContent(true);
925
+ _bottomAxis = new Axis("origin").orientation("bottom").type("linear").shrinkToFit("none").overlapMode("hide").extend(0).tickFormat("d");
926
+ _topAxisElement;
927
+ _contentElement;
928
+ _bottomAxisElement;
929
+ _topRect;
930
+ _contentRect;
931
+ _bottomRect;
932
+ constructor() {
933
+ super();
934
+ this.centerOverflowX_default("hidden");
935
+ this.centerOverflowY_default("auto");
936
+ }
937
+ selection(_) {
938
+ if (!arguments.length) return this._gantt.selection();
939
+ this._gantt.selection(_);
940
+ return this;
941
+ }
942
+ rangeRenderer(_) {
943
+ const ret = this._gantt.rangeRenderer.apply(this._gantt, arguments);
944
+ if (!arguments.length) return ret;
945
+ return this;
946
+ }
947
+ resizeWrappers() {
948
+ const w = this.width();
949
+ const h = this.height();
950
+ const axisHeight = this.axisHeight();
951
+ const contentHeight = h - axisHeight * 2;
952
+ this.bottomHeight(axisHeight);
953
+ this._topWA.resize({
954
+ width: w,
955
+ height: axisHeight
956
+ });
957
+ this._centerWA.resize({
958
+ width: w,
959
+ height: contentHeight
960
+ });
961
+ this._bottomWA.resize({
962
+ width: w,
963
+ height: axisHeight
964
+ });
965
+ this.top().render();
966
+ this.bottom().render();
967
+ this.center().render();
968
+ }
969
+ enter(domNode, element) {
970
+ super.enter(domNode, element);
971
+ this._gantt.click = (row, col, sel) => {
972
+ this.click(row, col, sel);
973
+ };
974
+ this._gantt.dblclick = (row, col, sel) => {
975
+ this.dblclick(row, col, sel);
976
+ };
977
+ this.top(this._topAxis);
978
+ this.center(this._gantt);
979
+ this.bottom(this._bottomAxis);
980
+ this.resizeWrappers();
981
+ this._gantt.zoomedHook = (transform) => {
982
+ this.onzoom(transform);
983
+ };
984
+ }
985
+ onzoom(transform) {
986
+ const w = this.width();
987
+ const low = this._gantt._minStart;
988
+ const range = this._gantt._maxEnd - low;
989
+ const wpp = range / w;
990
+ const nextLow = Math.floor(low - wpp * (transform.x / transform.k));
991
+ const nextHigh = Math.ceil(range / transform.k + nextLow);
992
+ this._topAxis.fontFamily(this.axisFontFamily()).fontSize(this.axisFontSize()).tickLength(this.axisTickLength()).low(nextLow).high(nextHigh).lazyRender();
993
+ this._bottomAxis.fontFamily(this.axisFontFamily()).fontSize(this.axisFontSize()).tickLength(this.axisTickLength()).low(nextLow).high(nextHigh).lazyRender();
994
+ }
995
+ update(domNode, element) {
996
+ super.update(domNode, element);
997
+ this._topAxis.tickFormat(this.tickFormat()).render();
998
+ this._bottomAxis.tickFormat(this.tickFormat()).render();
999
+ this._gantt.render();
1000
+ }
1001
+ columns(_) {
1002
+ const retVal = super.columns.apply(this, arguments);
1003
+ if (arguments.length > 0) this._gantt.columns(_);
1004
+ return retVal;
1005
+ }
1006
+ data(_) {
1007
+ const retVal = super.data.apply(this, arguments);
1008
+ if (arguments.length > 0) {
1009
+ const ganttData = this.data().map((n) => {
1010
+ const ret = [...n];
1011
+ ret[1] = isNaN(n[1]) ? new Date(n[1]).getTime() : Number(n[1]);
1012
+ ret[2] = isNaN(n[2]) ? new Date(n[2]).getTime() : Number(n[2]);
1013
+ return ret;
1014
+ });
1015
+ this._gantt._minStart = min(ganttData, (n) => n[1]);
1016
+ this._gantt._maxEnd = max(ganttData, (n) => n[2]);
1017
+ this._gantt.data(ganttData);
1018
+ }
1019
+ return retVal;
1020
+ }
1021
+ resize(_size) {
1022
+ const retVal = super.resize.apply(this, arguments);
1023
+ if (this._topAxisElement) this.resizeWrappers();
1024
+ return retVal;
1025
+ }
1026
+ click(row, col, sel) {}
1027
+ dblclick(row, col, sel) {}
1028
+ tooltip() {
1029
+ return this._gantt._tooltip;
1030
+ }
1031
+ };
1032
+ ReactAxisGanttSeries.prototype._class += " timeline_ReactAxisGanttSeries";
1033
+ ReactAxisGanttSeries.prototype.publish("tickFormat", null, "string", "Format rule applied to axis tick labels", void 0, { optional: true });
1034
+ ReactAxisGanttSeries.prototype.publish("axisHeight", 22, "number", "Height of axes (pixels)");
1035
+ ReactAxisGanttSeries.prototype.publish("overlapTolerence", 2, "number", "overlapTolerence");
1036
+ ReactAxisGanttSeries.prototype.publish("smallestRangeWidth", 10, "number", "Width of the shortest range (pixels)");
1037
+ ReactAxisGanttSeries.prototype.publish("axisFontSize", null, "number", "Font size of axis tick labels");
1038
+ ReactAxisGanttSeries.prototype.publish("axisFontFamily", null, "string", "Font family of axis tick labels");
1039
+ ReactAxisGanttSeries.prototype.publish("axisTickLength", null, "number", "Length of axis ticks");
1040
+ ReactAxisGanttSeries.prototype.publishProxy("gutter", "_gantt");
1041
+ ReactAxisGanttSeries.prototype.publishProxy("renderMode", "_gantt");
1042
+ ReactAxisGanttSeries.prototype.publishProxy("strokeWidth", "_gantt");
1043
+ ReactAxisGanttSeries.prototype.publishProxy("fontSize", "_gantt");
1044
+ ReactAxisGanttSeries.prototype.publishProxy("fontFamily", "_gantt");
1045
+ ReactAxisGanttSeries.prototype.publishProxy("stroke", "_gantt");
1046
+ ReactAxisGanttSeries.prototype.publishProxy("cornerRadius", "_gantt");
1047
+ ReactAxisGanttSeries.prototype.publishProxy("titleColumn", "_gantt");
1048
+ ReactAxisGanttSeries.prototype.publishProxy("startDateColumn", "_gantt");
1049
+ ReactAxisGanttSeries.prototype.publishProxy("endDateColumn", "_gantt");
1050
+ ReactAxisGanttSeries.prototype.publishProxy("iconColumn", "_gantt");
1051
+ ReactAxisGanttSeries.prototype.publishProxy("colorColumn", "_gantt");
1052
+ ReactAxisGanttSeries.prototype.publishProxy("seriesColumn", "_gantt");
1053
+ ReactAxisGanttSeries.prototype.publishProxy("bucketColumn", "_gantt");
1054
+ ReactAxisGanttSeries.prototype.publishProxy("maxZoom", "_gantt");
1055
+ ReactAxisGanttSeries.prototype.publishProxy("evenSeriesBackground", "_gantt");
1056
+ ReactAxisGanttSeries.prototype.publishProxy("oddSeriesBackground", "_gantt");
1057
+ ReactAxisGanttSeries.prototype.publishProxy("bucketHeight", "_gantt");
1058
+
1059
+ //#endregion
1060
+ //#region src/ReactTimeline.ts
1061
+ var ReactTimeline = class extends ReactAxisGantt {
1062
+ _axisLabelFormatter;
1063
+ constructor() {
1064
+ super();
1065
+ this._drawStartPos = "origin";
1066
+ this._topAxis.type("time");
1067
+ this._bottomAxis.type("time");
1068
+ this.tooltipHTML((d) => {
1069
+ const parser = timeParse("%Q");
1070
+ const startTime = parser(d[1]);
1071
+ const endTime = parser(d[2]);
1072
+ const formatter = timeFormat(this.tooltipTimeFormat());
1073
+ return `<div style="text-align:center;">${d[0]}<br/><br/>${formatter(startTime)} -&gt; ${formatter(endTime)}</div>`;
1074
+ });
1075
+ }
1076
+ update(domNode, element) {
1077
+ super.update(domNode, element);
1078
+ if (this.timePattern_exists()) {
1079
+ let minTimestamp = Infinity;
1080
+ let maxTimestamp = -Infinity;
1081
+ let lowDateStr = "";
1082
+ let highDateStr = "";
1083
+ this.data().map((n) => {
1084
+ const start = new Date(n[1]).getTime();
1085
+ const end = new Date(n[2]).getTime();
1086
+ if (minTimestamp > start) {
1087
+ minTimestamp = start;
1088
+ lowDateStr = "" + n[1];
1089
+ }
1090
+ if (maxTimestamp < end) {
1091
+ maxTimestamp = end;
1092
+ highDateStr = "" + n[2];
1093
+ }
1094
+ });
1095
+ const axisTickFormat = this._axisLabelFormatter ? this._axisLabelFormatter : this.tickFormat_exists && this.tickFormat_exists() ? this.tickFormat() : void 0;
1096
+ this._topAxis.type("time").timePattern(this.timePattern()).overlapMode("none").low(lowDateStr).high(highDateStr);
1097
+ this._bottomAxis.type("time").timePattern(this.timePattern()).overlapMode("none").low(lowDateStr).high(highDateStr);
1098
+ if (axisTickFormat) {
1099
+ this._topAxis.tickFormat(axisTickFormat);
1100
+ this._bottomAxis.tickFormat(axisTickFormat);
1101
+ } else {
1102
+ this._topAxis.tickFormat_reset();
1103
+ this._bottomAxis.tickFormat_reset();
1104
+ }
1105
+ this._gantt._minStart = minTimestamp;
1106
+ this._gantt._maxEnd = maxTimestamp;
1107
+ }
1108
+ }
1109
+ tooltipHTML(callback) {
1110
+ this._tooltipHTML = callback;
1111
+ this.tooltip().tooltipHTML(this._tooltipHTML);
1112
+ return this;
1113
+ }
1114
+ parseAxisValue(v) {
1115
+ const parsedTime = timeParse("%Q")(v);
1116
+ return timeFormat(this.timePattern())(parsedTime);
1117
+ }
1118
+ onzoom(transform) {
1119
+ const w = this.width();
1120
+ const low = this._gantt._minStart;
1121
+ const range = this._gantt._maxEnd - low;
1122
+ const wpp = range / w;
1123
+ const nextLow = Math.floor(low - wpp * (transform.x / transform.k));
1124
+ const nextHigh = Math.ceil(range / transform.k + nextLow);
1125
+ this._topAxis.low(this.parseAxisValue(nextLow)).high(this.parseAxisValue(nextHigh)).render();
1126
+ this._bottomAxis.low(this.parseAxisValue(nextLow)).high(this.parseAxisValue(nextHigh)).render();
1127
+ }
1128
+ };
1129
+ ReactTimeline.prototype._class += " timeline_ReactTimeline";
1130
+ ReactTimeline.prototype.publish("timePattern", "%Y-%m-%d", "string", "Time pattern used for parsing datetime strings on each data row", null, { optional: true });
1131
+ ReactTimeline.prototype.publish("tooltipTimeFormat", "%Y-%m-%d", "string", "Time format used in the default html tooltip");
1132
+
1133
+ //#endregion
1134
+ //#region src/ReactTimelineSeries.ts
1135
+ var parseTime = timeParse("%Q");
1136
+ var ReactTimelineSeries = class extends ReactAxisGanttSeries {
1137
+ _axisLabelFormatter;
1138
+ constructor() {
1139
+ super();
1140
+ this._topAxis.type("time");
1141
+ this._bottomAxis.type("time");
1142
+ this.tooltipHTML((d) => {
1143
+ const startTime = parseTime(d[1]);
1144
+ const endTime = parseTime(d[2]);
1145
+ const formatter = timeFormat(this.tooltipTimeFormat());
1146
+ return `<div style="text-align:center;">${d[0]}<br/><br/>${formatter(startTime)} -&gt; ${formatter(endTime)}</div>`;
1147
+ });
1148
+ }
1149
+ update(domNode, element) {
1150
+ super.update(domNode, element);
1151
+ if (this.timePattern_exists()) {
1152
+ let minTimestamp = Infinity;
1153
+ let maxTimestamp = -Infinity;
1154
+ let lowDateStr = "";
1155
+ let highDateStr = "";
1156
+ this.data().forEach((n) => {
1157
+ const start = new Date(n[1]).getTime();
1158
+ const end = new Date(n[2]).getTime();
1159
+ if (minTimestamp > start) {
1160
+ minTimestamp = start;
1161
+ lowDateStr = "" + n[1];
1162
+ }
1163
+ if (maxTimestamp < end) {
1164
+ maxTimestamp = end;
1165
+ highDateStr = "" + n[2];
1166
+ }
1167
+ });
1168
+ const axisTickFormat = this._axisLabelFormatter ? this._axisLabelFormatter : this.tickFormat_exists && this.tickFormat_exists() ? this.tickFormat() : void 0;
1169
+ this._topAxis.type("time").timePattern(this.timePattern()).overlapMode("none").low(lowDateStr).high(highDateStr);
1170
+ this._bottomAxis.type("time").timePattern(this.timePattern()).overlapMode("none").low(lowDateStr).high(highDateStr);
1171
+ if (axisTickFormat) {
1172
+ this._topAxis.tickFormat(axisTickFormat);
1173
+ this._bottomAxis.tickFormat(axisTickFormat);
1174
+ } else {
1175
+ this._topAxis.tickFormat_reset();
1176
+ this._bottomAxis.tickFormat_reset();
1177
+ }
1178
+ this._gantt._minStart = minTimestamp;
1179
+ this._gantt._maxEnd = maxTimestamp;
1180
+ }
1181
+ }
1182
+ tooltipHTML(callback) {
1183
+ this._tooltipHTML = callback;
1184
+ this.tooltip().tooltipHTML(this._tooltipHTML);
1185
+ return this;
1186
+ }
1187
+ parseAxisValue(v) {
1188
+ const parsedTime = parseTime(v);
1189
+ return timeFormat(this.timePattern())(parsedTime);
1190
+ }
1191
+ onzoom(transform) {
1192
+ const w = this.width();
1193
+ const low = this._gantt._minStart;
1194
+ const range = this._gantt._maxEnd - low;
1195
+ const wpp = range / w;
1196
+ const nextLow = Math.floor(low - wpp * (transform.x / transform.k));
1197
+ const nextHigh = Math.ceil(range / transform.k + nextLow);
1198
+ this._topAxis.low(this.parseAxisValue(nextLow)).high(this.parseAxisValue(nextHigh)).render();
1199
+ this._bottomAxis.low(this.parseAxisValue(nextLow)).high(this.parseAxisValue(nextHigh)).render();
1200
+ }
1201
+ _tooltipHTML;
1202
+ };
1203
+ ReactTimelineSeries.prototype._class += " timeline_ReactTimelineSeries";
1204
+ ReactTimelineSeries.prototype.publish("timePattern", "%Y-%m-%d", "string", "Time pattern used for parsing datetime strings on each data row", null, { optional: true });
1205
+ ReactTimelineSeries.prototype.publish("tooltipTimeFormat", "%Y-%m-%d", "string", "Time format used in the default html tooltip");
1206
+
1207
+ //#endregion
1208
+ export { BUILD_VERSION, MiniGantt, PKG_NAME, PKG_VERSION, ReactAxisGantt, ReactAxisGanttSeries, ReactGantt, ReactTimeline, ReactTimelineSeries };
1209
+ //# sourceMappingURL=index.js.map!function(){try{if("undefined"!=typeof document){var e=document.createElement("style");e.appendChild(document.createTextNode(".timeline_MiniGantt .line{fill:none;stroke:#d3d3d3;opacity:.7}.timeline_MiniGantt .common_TextBox .rect{fill:#87cefa;stroke:#00f;opacity:.5}.timeline_MiniGantt .buckets .entity_shape rect{stroke:#333}.timeline_MiniGantt .buckets.selected .common_EntityRect .common_Shape>rect{stroke:red}.timeline_MiniGantt .common_TextBox .rect text{fill:#000;stroke:none}.timeline_MiniGantt .over{stroke:#0000;opacity:.8}.timeline_MiniGantt rect{shape-rendering:crispEdges}\n/*$vite$:1*/")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}}();