@macrostrat/column-components
Version:
React rendering primitives for stratigraphic columns
3 lines (2 loc) • 1.9 kB
JavaScript
import t from"labella";let{Node:e,Renderer:r,Force:s}=t;class i{constructor(t,e,r=null){this.allowedRange=t,this.centerPos=(this.allowedRange[0]+this.allowedRange[1])/2,this.currentPos=this.centerPos,this.width=e,this.data=r,this.layerIndex=0}get idealPos(){let[t,e]=this.allowedRange;return this.currentPos<e?e:this.currentPos>t?t:this.currentPos}distanceFrom(t){let e=this.width/2,r=t.width/2;return Math.max(this.currentPos-e,t.currentPos-r)-Math.min(this.currentPos+e,t.currentPos+r)}moveToIdealPosition(){return this.currentPos=this.idealPos,this}displacement(){return this.idealPos-this.currentPos}overlapWithNode(t,e=0){return this.distanceFrom(t)-e<0}overlapWithPoint(t){let e=this.width/2;return t>=this.currentPos-e&&t<=this.currentPos+e}positionBefore(t,e=0){return t.currentLeft()-this.width/2-e}positionAfter(t,e=0){return t.currentRight()+this.width/2+e}currentRight(){return this.currentPos+this.width/2}currentLeft(){return this.currentPos-this.width/2}idealRight(){return this.idealPos+this.width/2}idealLeft(){return this.idealPos-this.width/2}createStub(t){let r=new e(this.idealPos,t,this.data);return r.currentPos=this.currentPos,r.child=this,this.parent=r,r}removeStub(){return this.parent&&(this.parent.child=null,this.parent=null),this}isStub(){return!!this.child}getPathToRoot(){let t=[],e=this;for(;e;)t.push(e),e=e.parent;return t}getPathFromRoot(){return this.getPathToRoot().reverse()}getPathToRootLength(){let t=0,e=this;for(;e;){let r=e.parent?e.parent.currentPos:e.idealPos;t+=Math.abs(e.currentPos-r),e=e.parent}return t}getRoot(){let t=this,e=this;for(;e;)t=e,e=e.parent;return t}getLayerIndex(){return this.layerIndex}clone(){let t=new i(this.allowedRange,this.width,this.data);return t.currentPos=this.currentPos,t.layerIndex=this.layerIndex,t}}export{e as Node,r as Renderer,s as Force,i as FlexibleNode};
//# sourceMappingURL=column-components.89b08d55.js.map