@cosmograph/cosmograph
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
import{brush as s}from"d3-brush";import{select as t}from"d3-selection";import e from"./style.module.css.js";class l{constructor(l){var i;this._=l,this._brush=s().on("end",(s=>{var t;if(!s.sourceEvent)return;const e=s.selection;null===(t=this._onSelectCallback)||void 0===t||t.call(this,e)})),this._svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this._svg.classList.add(e.areaSelect),null===(i=this._.containerElement)||void 0===i||i.appendChild(this._svg),this._onSelectCallback=this._.eventManager.onAreaSelect,t(this._svg).select(".brush-group").remove(),this._brush.extent([[0,0],[this._svg.clientWidth,this._svg.clientHeight]]),t(this._svg).append("g").attr("class","brush-group").call(this._brush),this.updateSelectionClassName(),t(this._svg).style("display","none")}updateSelectionClassName(){var s;const e=`selection ${null!==(s=this._.public.config.rectangularSelectorClassName)&&void 0!==s?s:""}`;t(this._svg).select(".brush-group").selectAll(".selection").attr("class",e)}enable(){t(this._svg).style("display",null),this._brush.extent([[0,0],[this._svg.clientWidth,this._svg.clientHeight]]),t(this._svg).select(".brush-group").call(this._brush)}disable(){t(this._svg).style("display","none"),t(this._svg).select(".brush-group").call(this._brush.clear)}destroy(){t(this._svg).select(".brush-group").remove(),this._svg.remove()}}export{l as RectangularSelect}; | ||
import{brush as s}from"d3-brush";import{select as t}from"d3-selection";import e from"./style.module.css.js";class l{constructor(l){var i;this._=l,this._brush=s().on("end",(s=>{var t;if(!s.sourceEvent)return;const e=s.selection;null===(t=this._onSelectCallback)||void 0===t||t.call(this,e)})),this._svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this._svg.classList.add(e.areaSelect),null===(i=this._.containerElement)||void 0===i||i.appendChild(this._svg),this._onSelectCallback=this._.eventManager.onAreaSelect,t(this._svg).select(".brush-group").remove(),this._brush.extent([[0,0],[this._svg.clientWidth,this._svg.clientHeight]]),t(this._svg).append("g").attr("class","brush-group").call(this._brush),this.updateSelectionClassName(),t(this._svg).style("display","none")}updateSelectionClassName(){var s;const e=`selection ${null!==(s=this._.config.rectangularSelectorClassName)&&void 0!==s?s:""}`;t(this._svg).select(".brush-group").selectAll(".selection").attr("class",e)}enable(){t(this._svg).style("display",null),this._brush.extent([[0,0],[this._svg.clientWidth,this._svg.clientHeight]]),t(this._svg).select(".brush-group").call(this._brush)}disable(){t(this._svg).style("display","none"),t(this._svg).select(".brush-group").call(this._brush.clear)}destroy(){t(this._svg).select(".brush-group").remove(),this._svg.remove()}}export{l as RectangularSelect}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import{LabelRenderer as e,CssLabel as s}from"@interacta/css-labels";import{cosmographLog as i}from"../../../utils/log.js";import{checkColumnsExist as t}from"../../graph-utils/misc.js";import{getRGBAFromPointColors as o,rgbaArrayToRgbString as a}from"../../graph-utils/colors.js";import{getLabelsByIndices as l,getLabelsByIds as n,getTopLabels as c}from"./queries.js";import r from"./style.module.css.js";class d{constructor(i,t){var o;this._=i,this._staticLabelsMap=new Map,this._dynamicLabelsMap=new Map,this._validLabelAccessor=!1,this._validLabelWeightAccessor=!1,this._validTopLabelsAccessor=!1,this._labelDataMap=new Map,this._customLabelsMap=new Map,this.div=document.createElement("div"),this._checkLabelEvents=()=>{const{onLabelClick:e,selectPointOnLabelClick:s,focusPointOnLabelClick:i}=this._.public.config;return void 0!==e||s||i?"all":"none"};const{config:a}=this._.public,l=this._.eventManager.getLabelEvents();let n;if(null===(o=i.containerElement)||void 0===o||o.appendChild(this.div),a.labelPadding){const[e,s,i,t]=a.labelPadding;n={left:e,top:s,right:i,bottom:t}}this._cssLabelsRenderer=new e(this.div,{dispatchWheelEventElement:t,pointerEvents:this._checkLabelEvents(),onLabelClick:l.onLabelClick,padding:n}),this._onHoveredLabelClick=l.onHoveredLabelClick,this._hoveredCssLabel=new s(this.div),this._hoveredCssLabel.setPointerEvents(this._checkLabelEvents()),this._hoveredCssLabel.element.addEventListener("click",l.onHoveredLabelClick,{passive:!0})}async render(){this._.cosmos&&this._.public.config&&((this._validLabelAccessor||this._.public.config.customLabels)&&await this._updateLabels(),this._renderLabels())}async update(){if(!this._.cosmos||!this._.dbCoordinator)return;const{config:e,pointsTableName:s}=this._.public,{pointLabelBy:o,pointLabelWeightBy:a,showTopLabelsBy:l,customLabels:n}=e;if(await this._.configManager.configUpdated(),n&&this.setCustomLabels(n),o){const e=[];await t(this._.dbCoordinator,s,[o,l,a].filter(Boolean),e),this._validLabelAccessor=!e.includes(o),this._validTopLabelsAccessor=!!l&&!e.includes(l),this._validLabelWeightAccessor=!!a&&!e.includes(a),this._validLabelAccessor?(await this._updateStaticLabels(),await this.render()):(i(`Column "${o}" for \`pointLabelBy\` not found`,"Labels > update","warn"),this.clear())}else this._customLabelsMap.size>0?await this.render():this.clear()}async _updateLabels(){var e,s,i,t,o;const{dbCoordinator:a,public:{config:n,pointsTableName:c,focusedPointIndex:r}}=this._,{showDynamicLabels:d,pointLabelBy:h,showLabels:b}=n;if(this._dynamicLabelsMap.clear(),b&&d&&h){const s=this._.public.getSampledPointPositionsMap();if(a&&(null==s?void 0:s.size)){const i=await l(a,c,n,Array.from(null!==(e=null==s?void 0:s.keys())&&void 0!==e?e:[]),this._validLabelWeightAccessor);this._setLabels(this._dynamicLabelsMap,i)}}if(b&&this._.dbCoordinator&&r){if(!this._focusedLabel||this._focusedLabel&&this._focusedLabel[0]!==r){const e=await l(this._.dbCoordinator,c,n,[r],!1);this._focusedLabel=[null===(s=e.indices)||void 0===s?void 0:s.get(0),null===(i=e.ids)||void 0===i?void 0:i.get(0),null===(t=e.labels)||void 0===t?void 0:t.get(0)],null===(o=this._.cosmos)||void 0===o||o.trackPointPositionsByIndices(Array.from(this._staticLabelsMap.keys()).concat(r))}}else this._focusedLabel=void 0;this._populateLabelDataMap()}async _updateStaticLabels(){var e;const{dbCoordinator:s,public:{config:i,pointsTableName:t,focusedPointIndex:o}}=this._,{pointLabelBy:a,showTopLabels:l,showTopLabelsBy:c,showLabelsFor:r,showLabels:d}=i;if(this._staticLabelsMap.clear(),d){if(s&&a){if(null==r?void 0:r.length){const e=await n(s,t,i,this._validLabelWeightAccessor);this._setLabels(this._staticLabelsMap,e)}if(l){const e=await this._getTopLabels(c);this._setLabels(this._staticLabelsMap,e)}}null===(e=this._.cosmos)||void 0===e||e.trackPointPositionsByIndices(Array.from(this._staticLabelsMap.keys()).concat(null!=o?o:[]))}}async _getTopLabels(e){const{dbCoordinator:s,public:{config:t,pointsTableName:o}}=this._;if(s){if(e){if(this._validTopLabelsAccessor)return await c(s,o,t,this._validLabelWeightAccessor);i(`Column "${e}" for \`showTopLabelsBy\` not found, getting top labels by degree`,"Labels > _getTopLabels","warn")}return await l(s,o,t,this._findTopIndicesByDegree(),this._validLabelWeightAccessor)}}_setLabels(e,s){var i;if(s&&s.indices&&s.labels&&s.ids)for(let t=0;t<s.indices.length;t++)e.set(s.indices.get(t),[s.ids.get(t),s.labels.get(t),null===(i=s.weights)||void 0===i?void 0:i.get(t)])}_findTopIndicesByDegree(){const{showTopLabelsLimit:e=100}=this._.public.config,{pointDegrees:s}=this._.public;if(!s)return[];const i=new Set(this._.public.getSelectedPointIndices()),t=new Array,o=Array.from(i).sort(((e,i)=>(s[i]||0)-(s[e]||0))).slice(0,e);if(t.push(...o),t.length<e){const o=Array.from(s,((e,s)=>({index:s,degree:e}))).filter((e=>!i.has(e.index))).sort(((e,s)=>s.degree-e.degree)).slice(0,e-t.length).map((e=>e.index));t.push(...o)}return t}_populateLabelDataMap(){var e;const{showLabels:s,pointLabelColor:i,staticLabelWeight:t,dynamicLabelWeight:o}=this._.public.config;if(this._labelDataMap.clear(),!s)return;const a=null===(e=this._.cosmos)||void 0===e?void 0:e.getTrackedPointPositionsMap();this._staticLabelsMap.size&&(null==a||a.forEach(((e,s)=>{const i=this._staticLabelsMap.get(s);if(void 0!==i){const[o,a,l]=i;this._labelDataMap.set(o,{index:s,text:a,position:e,className:r.cosmographStaticLabel,weight:null!=l?l:t})}})));const l=this._.public.getSampledPointPositionsMap();if(null==l||l.forEach(((e,s)=>{const i=this._dynamicLabelsMap.get(s);if(void 0!==i){const[t,a,l]=i;this._labelDataMap.set(t,{index:s,text:a,position:e,className:r.cosmographDynamicLabel,weight:null!=l?l:o})}})),this._customLabelsMap.forEach(((e,s)=>{var o,a,l,n;this._labelDataMap.set(s,{index:0,text:e.text,position:e.position,className:null!==(o=e.className)&&void 0!==o?o:r.cosmographCustomLabel,color:null!==(l=null!==(a=e.color)&&void 0!==a?a:i)&&void 0!==l?l:"white",weight:null!==(n=e.weight)&&void 0!==n?n:t})})),this._focusedLabel){const[e,s,i]=this._focusedLabel,t=null==a?void 0:a.get(e);if(!t)return;this._labelDataMap.set(s,{index:e,text:i,position:t,className:r.cosmographStaticLabel,weight:100})}}_renderLabels(){var e,s,i,t;const{public:{crossfilter:o,maxPointSize:a}}=this._,{pointLabelClassName:l,scalePointsOnZoom:n,labelMargin:c,pointLabelColor:d,pointLabelFontSize:h}=this._.public.config,b=null!==(s=null===(e=this._.cosmos)||void 0===e?void 0:e.config.pointSizeScale)&&void 0!==s?s:1,p=o.intersection,L=this._.public.getZoomLevel(),_=this._.crossfilter.isFilteringActive,u=Array.from(this._labelDataMap.entries()).map((([e,s])=>{var i,t;const{index:o,text:u,position:v,className:g,weight:m,color:f}=s,[y,C]=this._.public.spaceToScreenPosition(v),w=this._.public.getPointRadiusByIndex(o),M=!1!==n?Math.min(b*w*L,a):this._.public.spaceToScreenRadius(b*w),P=(null===(i=this._focusedLabel)||void 0===i?void 0:i[0])===o,x=!_||p.has(o),S="function"==typeof l?null!==(t=l(u,o,e))&&void 0!==t?t:"":null!=l?l:"",T=S.includes(":"),k=x?r.cosmographLabel:r.cosmographLabelHidden;let A=T?`${k} ${g}`:`${k} ${S} ${g}`;return this._checkLabelEvents()&&(A+=` ${r.cosmographLabelInteractive}`),{id:e,text:u,x:y,y:C-M/2-c,weight:x?100:m?.1*m:.1,shouldBeShown:P,fontSize:h,color:(null!=f?f:void 0!==l)?void 0:null!=d?d:this._getLabelColorByIndex(o),style:S,className:A}}));null===(i=this._cssLabelsRenderer)||void 0===i||i.setLabels(u),null===(t=this._cssLabelsRenderer)||void 0===t||t.draw(!0)}async renderHoveredLabel(e,s){var i,t,o,a,n;if(!this._.cosmos)return;const{dbCoordinator:c,public:{config:d,maxPointSize:h,pointsTableName:b}}=this._,{pointLabelBy:p,showHoveredPointLabel:L,hoveredPointLabelClassName:_,scalePointsOnZoom:u,labelMargin:v,pointLabelFontSize:g}=d;if(this._hoveredCssLabel.setPointerEvents(this._checkLabelEvents()),!(c&&L&&p&&void 0!==e&&s&&this._validLabelAccessor))return this._hoveredCssLabel.setVisibility(!1),void this._hoveredCssLabel.draw();const m=await l(c,b,d,[e],!1);if(!m)return;const f=null===(i=m.ids)||void 0===i?void 0:i.get(0),y=null!==(o=null===(t=m.labels)||void 0===t?void 0:t.get(0))&&void 0!==o?o:"",[C,w]=this._.public.spaceToScreenPosition(s),M=null!==(a=this._.cosmos.config.pointSizeScale)&&void 0!==a?a:1,P=this._.public.getPointRadiusByIndex(e),x=!1!==u?Math.min(M*P*this._.public.getZoomLevel(),h):this._.public.spaceToScreenRadius(M*P),S="function"==typeof _?null!==(n=_(y,e,f))&&void 0!==n?n:"":null!=_?_:"",T=S.includes(":"),k=T?r.cosmographLabelHovered:[r.cosmographLabelHovered,S].join(" "),A=T?S:"";if(this._hoveredCssLabel.setText(y),this._hoveredCssLabel.setVisibility(!0),this._hoveredCssLabel.setPosition(C,w-x/2-v),this._hoveredCssLabel.setClassName(k),this._hoveredCssLabel.setStyle(A),this._hoveredCssLabel.setFontSize(g),_||this._hoveredCssLabel.setColor(this._getLabelColorByIndex(e)),d.labelPadding){const[e,s,i,t]=d.labelPadding;this._hoveredCssLabel.setPadding({left:e,top:s,right:i,bottom:t})}this._hoveredCssLabel.draw()}setCustomLabels(e){const{rescaleXFn:s,rescaleYFn:i}=this._.public;this._customLabelsMap.clear(),e.forEach(((e,t)=>{const o={...e};s&&i&&void 0!==o.position[0]&&void 0!==o.position[1]&&(o.position=[s(o.position[0]),i(o.position[1])]),this._customLabelsMap.set(`custom-${t}`,o)}))}destroy(){var e,s,i;this.clear(),this._onHoveredLabelClick&&(null===(e=this._hoveredCssLabel)||void 0===e||e.element.removeEventListener("click",this._onHoveredLabelClick,{passive:!0})),null===(s=this._hoveredCssLabel)||void 0===s||s.destroy(),null===(i=this._cssLabelsRenderer)||void 0===i||i.destroy()}clear(){var e,s,i;this._labelDataMap.size&&(this._customLabelsMap.clear(),this._staticLabelsMap.clear(),this._dynamicLabelsMap.clear(),this._labelDataMap.clear(),null===(e=this._cssLabelsRenderer)||void 0===e||e.setLabels([]),null===(s=this._cssLabelsRenderer)||void 0===s||s.draw(),null===(i=this._hoveredCssLabel)||void 0===i||i.destroy())}_getLabelColorByIndex(e){var s,i;const t=null===(s=this._.cosmos)||void 0===s?void 0:s.graph.pointColors,l=null!==(i=o(t,e))&&void 0!==i?i:this._.public.config.pointColor;return a(l)}}export{d as Labels}; | ||
import{LabelRenderer as e,CssLabel as s}from"@interacta/css-labels";import{cosmographLog as i}from"../../../utils/log.js";import{checkColumnsExist as t}from"../../graph-utils/misc.js";import{getRGBAFromPointColors as o,rgbaArrayToRgbString as a}from"../../graph-utils/colors.js";import{getLabelsByIndices as l,getLabelsByIds as n,getTopLabels as c}from"./queries.js";import r from"./style.module.css.js";class d{constructor(i,t){var o;this._=i,this._staticLabelsMap=new Map,this._dynamicLabelsMap=new Map,this._validLabelAccessor=!1,this._validLabelWeightAccessor=!1,this._validTopLabelsAccessor=!1,this._labelDataMap=new Map,this._customLabelsMap=new Map,this.div=document.createElement("div"),this._checkLabelEvents=()=>{const{onLabelClick:e,selectPointOnLabelClick:s,focusPointOnLabelClick:i}=this._.config;return void 0!==e||s||i?"all":"none"};const{config:a}=this._,l=this._.eventManager.getLabelEvents();let n;if(null===(o=i.containerElement)||void 0===o||o.appendChild(this.div),a.labelPadding){const[e,s,i,t]=a.labelPadding;n={left:e,top:s,right:i,bottom:t}}this._cssLabelsRenderer=new e(this.div,{dispatchWheelEventElement:t,pointerEvents:this._checkLabelEvents(),onLabelClick:l.onLabelClick,padding:n}),this._onHoveredLabelClick=l.onHoveredLabelClick,this._hoveredCssLabel=new s(this.div),this._hoveredCssLabel.setPointerEvents(this._checkLabelEvents()),this._hoveredCssLabel.element.addEventListener("click",l.onHoveredLabelClick,{passive:!0})}async render(){this._.cosmos&&this._.config&&((this._validLabelAccessor||this._.config.customLabels)&&await this._updateLabels(),this._renderLabels())}async update(){if(!this._.cosmos||!this._.dbCoordinator)return;const{config:e,public:{pointsTableName:s}}=this._,{pointLabelBy:o,pointLabelWeightBy:a,showTopLabelsBy:l,customLabels:n}=e;if(await this._.configManager.configUpdated(),n&&this.setCustomLabels(n),o){const e=[];await t(this._.dbCoordinator,s,[o,l,a].filter(Boolean),e),this._validLabelAccessor=!e.includes(o),this._validTopLabelsAccessor=!!l&&!e.includes(l),this._validLabelWeightAccessor=!!a&&!e.includes(a),this._validLabelAccessor?(await this._updateStaticLabels(),await this.render()):(i(`Column "${o}" for \`pointLabelBy\` not found`,"Labels > update","warn"),this.clear())}else this._customLabelsMap.size>0?await this.render():this.clear()}async _updateLabels(){var e,s,i,t,o;const{config:a,dbCoordinator:n,public:{pointsTableName:c,focusedPointIndex:r}}=this._,{showDynamicLabels:d,pointLabelBy:h,showLabels:b}=a;if(this._dynamicLabelsMap.clear(),b&&d&&h){const s=this._.public.getSampledPointPositionsMap();if(n&&(null==s?void 0:s.size)){const i=await l(n,c,a,Array.from(null!==(e=null==s?void 0:s.keys())&&void 0!==e?e:[]),this._validLabelWeightAccessor);this._setLabels(this._dynamicLabelsMap,i)}}if(b&&this._.dbCoordinator&&r){if(!this._focusedLabel||this._focusedLabel&&this._focusedLabel[0]!==r){const e=await l(this._.dbCoordinator,c,a,[r],!1);this._focusedLabel=[null===(s=e.indices)||void 0===s?void 0:s.get(0),null===(i=e.ids)||void 0===i?void 0:i.get(0),null===(t=e.labels)||void 0===t?void 0:t.get(0)],null===(o=this._.cosmos)||void 0===o||o.trackPointPositionsByIndices(Array.from(this._staticLabelsMap.keys()).concat(r))}}else this._focusedLabel=void 0;this._populateLabelDataMap()}async _updateStaticLabels(){var e;const{config:s,dbCoordinator:i,public:{pointsTableName:t,focusedPointIndex:o}}=this._,{pointLabelBy:a,showTopLabels:l,showTopLabelsBy:c,showLabelsFor:r,showLabels:d}=s;if(this._staticLabelsMap.clear(),d){if(i&&a){if(null==r?void 0:r.length){const e=await n(i,t,s,this._validLabelWeightAccessor);this._setLabels(this._staticLabelsMap,e)}if(l){const e=await this._getTopLabels(c);this._setLabels(this._staticLabelsMap,e)}}null===(e=this._.cosmos)||void 0===e||e.trackPointPositionsByIndices(Array.from(this._staticLabelsMap.keys()).concat(null!=o?o:[]))}}async _getTopLabels(e){const{config:s,dbCoordinator:t,public:{pointsTableName:o}}=this._;if(t){if(e){if(this._validTopLabelsAccessor)return await c(t,o,s,this._validLabelWeightAccessor);i(`Column "${e}" for \`showTopLabelsBy\` not found, getting top labels by degree`,"Labels > _getTopLabels","warn")}return await l(t,o,s,this._findTopIndicesByDegree(),this._validLabelWeightAccessor)}}_setLabels(e,s){var i;if(s&&s.indices&&s.labels&&s.ids)for(let t=0;t<s.indices.length;t++)e.set(s.indices.get(t),[s.ids.get(t),s.labels.get(t),null===(i=s.weights)||void 0===i?void 0:i.get(t)])}_findTopIndicesByDegree(){const{showTopLabelsLimit:e=100}=this._.config,{pointDegrees:s}=this._.public;if(!s)return[];const i=new Set(this._.public.getSelectedPointIndices()),t=new Array,o=Array.from(i).sort(((e,i)=>(s[i]||0)-(s[e]||0))).slice(0,e);if(t.push(...o),t.length<e){const o=Array.from(s,((e,s)=>({index:s,degree:e}))).filter((e=>!i.has(e.index))).sort(((e,s)=>s.degree-e.degree)).slice(0,e-t.length).map((e=>e.index));t.push(...o)}return t}_populateLabelDataMap(){var e;const{showLabels:s,pointLabelColor:i,staticLabelWeight:t,dynamicLabelWeight:o}=this._.config;if(this._labelDataMap.clear(),!s)return;const a=null===(e=this._.cosmos)||void 0===e?void 0:e.getTrackedPointPositionsMap();this._staticLabelsMap.size&&(null==a||a.forEach(((e,s)=>{const i=this._staticLabelsMap.get(s);if(void 0!==i){const[o,a,l]=i;this._labelDataMap.set(o,{index:s,text:a,position:e,className:r.cosmographStaticLabel,weight:null!=l?l:t})}})));const l=this._.public.getSampledPointPositionsMap();if(null==l||l.forEach(((e,s)=>{const i=this._dynamicLabelsMap.get(s);if(void 0!==i){const[t,a,l]=i;this._labelDataMap.set(t,{index:s,text:a,position:e,className:r.cosmographDynamicLabel,weight:null!=l?l:o})}})),this._customLabelsMap.forEach(((e,s)=>{var o,a,l,n;this._labelDataMap.set(s,{index:0,text:e.text,position:e.position,className:null!==(o=e.className)&&void 0!==o?o:r.cosmographCustomLabel,color:null!==(l=null!==(a=e.color)&&void 0!==a?a:i)&&void 0!==l?l:"white",weight:null!==(n=e.weight)&&void 0!==n?n:t})})),this._focusedLabel){const[e,s,i]=this._focusedLabel,t=null==a?void 0:a.get(e);if(!t)return;this._labelDataMap.set(s,{index:e,text:i,position:t,className:r.cosmographStaticLabel,weight:100})}}_renderLabels(){var e,s,i,t;const{public:{crossfilter:o,maxPointSize:a}}=this._,{pointLabelClassName:l,scalePointsOnZoom:n,labelMargin:c,pointLabelColor:d,pointLabelFontSize:h}=this._.config,b=null!==(s=null===(e=this._.cosmos)||void 0===e?void 0:e.config.pointSizeScale)&&void 0!==s?s:1,p=o.intersection,L=this._.public.getZoomLevel(),_=this._.crossfilter.isFilteringActive,v=Array.from(this._labelDataMap.entries()).map((([e,s])=>{var i,t;const{index:o,text:v,position:u,className:g,weight:m,color:f}=s,[y,C]=this._.public.spaceToScreenPosition(u),w=this._.public.getPointRadiusByIndex(o),M=!1!==n?Math.min(b*w*L,a):this._.public.spaceToScreenRadius(b*w),P=(null===(i=this._focusedLabel)||void 0===i?void 0:i[0])===o,x=!_||p.has(o),S="function"==typeof l?null!==(t=l(v,o,e))&&void 0!==t?t:"":null!=l?l:"",T=S.includes(":"),k=x?r.cosmographLabel:r.cosmographLabelHidden;let A=T?`${k} ${g}`:`${k} ${S} ${g}`;return this._checkLabelEvents()&&(A+=` ${r.cosmographLabelInteractive}`),{id:e,text:v,x:y,y:C-M/2-c,weight:x?100:m?.1*m:.1,shouldBeShown:P,fontSize:h,color:(null!=f?f:void 0!==l)?void 0:null!=d?d:this._getLabelColorByIndex(o),style:S,className:A}}));null===(i=this._cssLabelsRenderer)||void 0===i||i.setLabels(v),null===(t=this._cssLabelsRenderer)||void 0===t||t.draw(!0)}async renderHoveredLabel(e,s){var i,t,o,a,n;if(!this._.cosmos)return;const{config:c,dbCoordinator:d,public:{maxPointSize:h,pointsTableName:b}}=this._,{pointLabelBy:p,showHoveredPointLabel:L,hoveredPointLabelClassName:_,scalePointsOnZoom:v,labelMargin:u,pointLabelFontSize:g}=c;if(this._hoveredCssLabel.setPointerEvents(this._checkLabelEvents()),!(d&&L&&p&&void 0!==e&&s&&this._validLabelAccessor))return this._hoveredCssLabel.setVisibility(!1),void this._hoveredCssLabel.draw();const m=await l(d,b,c,[e],!1);if(!m)return;const f=null===(i=m.ids)||void 0===i?void 0:i.get(0),y=null!==(o=null===(t=m.labels)||void 0===t?void 0:t.get(0))&&void 0!==o?o:"",[C,w]=this._.public.spaceToScreenPosition(s),M=null!==(a=this._.cosmos.config.pointSizeScale)&&void 0!==a?a:1,P=this._.public.getPointRadiusByIndex(e),x=!1!==v?Math.min(M*P*this._.public.getZoomLevel(),h):this._.public.spaceToScreenRadius(M*P),S="function"==typeof _?null!==(n=_(y,e,f))&&void 0!==n?n:"":null!=_?_:"",T=S.includes(":"),k=T?r.cosmographLabelHovered:[r.cosmographLabelHovered,S].join(" "),A=T?S:"";if(this._hoveredCssLabel.setText(y),this._hoveredCssLabel.setVisibility(!0),this._hoveredCssLabel.setPosition(C,w-x/2-u),this._hoveredCssLabel.setClassName(k),this._hoveredCssLabel.setStyle(A),this._hoveredCssLabel.setFontSize(g),_||this._hoveredCssLabel.setColor(this._getLabelColorByIndex(e)),c.labelPadding){const[e,s,i,t]=c.labelPadding;this._hoveredCssLabel.setPadding({left:e,top:s,right:i,bottom:t})}this._hoveredCssLabel.draw()}setCustomLabels(e){const{rescaleXFn:s,rescaleYFn:i}=this._.public;this._customLabelsMap.clear(),e.forEach(((e,t)=>{const o={...e};s&&i&&void 0!==o.position[0]&&void 0!==o.position[1]&&(o.position=[s(o.position[0]),i(o.position[1])]),this._customLabelsMap.set(`custom-${t}`,o)}))}destroy(){var e,s,i;this.clear(),this._onHoveredLabelClick&&(null===(e=this._hoveredCssLabel)||void 0===e||e.element.removeEventListener("click",this._onHoveredLabelClick,{passive:!0})),null===(s=this._hoveredCssLabel)||void 0===s||s.destroy(),null===(i=this._cssLabelsRenderer)||void 0===i||i.destroy()}clear(){var e,s,i;this._labelDataMap.size&&(this._customLabelsMap.clear(),this._staticLabelsMap.clear(),this._dynamicLabelsMap.clear(),this._labelDataMap.clear(),null===(e=this._cssLabelsRenderer)||void 0===e||e.setLabels([]),null===(s=this._cssLabelsRenderer)||void 0===s||s.draw(),null===(i=this._hoveredCssLabel)||void 0===i||i.destroy())}_getLabelColorByIndex(e){var s,i;const t=null===(s=this._.cosmos)||void 0===s?void 0:s.graph.pointColors,l=null!==(i=o(t,e))&&void 0!==i?i:this._.config.pointColor;return a(l)}}export{d as Labels}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import{merge as t}from"@cosmograph/ui";import{vectorFromArray as i}from"apache-arrow";import{isEqual as n}from"../../utils/utils.js";import{cosmographLog as o}from"../../utils/log.js";import{defaultCosmographConfig as s}from"./index.js";import{defaultBackgroundColor as e,defaultPointClusterStrength as r,defaultLinkStrength as a}from"./defaults.js";import{getAllPoints as l,getPointPositionsFromTable as h,fillMissingPointPositions as d,getRandomPointPositions as u}from"../graph-utils/points.js";import{getAllLinks as c,mergeLinkPositions as p}from"../graph-utils/links.js";import{getHexColor as _,hexToBrightness as g}from"../graph-utils/colors.js";import{getSizeScale as C}from"../graph-utils/sizes.js";import{colorProcessor as f,sizeProcessor as k,arrowProcessor as y}from"../graph-utils/vectors.js";import{PointColorStrategy as v,resolveOptimalPointColorStrategy as P,getActivePointColorFn as m}from"../strategies/point-color.js";import{PointSizeStrategy as S,resolveOptimalPointSizeStrategy as w,getActivePointSizeFn as L}from"../strategies/point-size.js";import{labelsUpdateKeys as F}from"./interfaces/labels.js";import{CosmographConfigValidator as B}from"./validator.js";import{BasePointsConfigKeys as A,BaseLinksConfigKeys as z,requiredPointsConfigKeys as b,requiredLinksConfigKeys as W,unrequiredProps as E}from"./interfaces/data.js";class U{constructor(t){this._=t,this.config={},this._rawConfig={},this._cosmosConfig={},this._dataUploadPromise=null,this._configUpdatePromise=null,this._currentPointColorStrategy=v.Direct,this._currentPointSizeStrategy=S.Direct,this.resetCosmographConfig=()=>{this.config=s},this._checkPointEvents=()=>!(void 0===this.config.onClick&&!this.config.selectPointOnClick&&!this.config.focusPointOnClick),this._validator=new B(t)}get activePointColorStrategy(){return this._currentPointColorStrategy}get activePointSizeStrategy(){return this._currentPointSizeStrategy}get activePointColorFn(){return this._currentPointColorFn}get activePointSizeFn(){return this._currentPointSizeFn}get activeLinkColorFn(){return this._currentLinkColorFn}get activeLinkWidthFn(){return this._currentLinkWidthFn}get cosmosConfig(){return this._cosmosConfig}async configUpdated(){await this._configUpdatePromise}async dataReady(){var t;(null===(t=this._.dbCoordinator)||void 0===t?void 0:t.internalDB)&&this._dataUploadPromise&&await this._dataUploadPromise}setConfig(i){this._configUpdatePromise=(async()=>{var n;try{await this._.dbReady();const o=this.config;if(o.points&&!(null==i?void 0:i.points)&&!this._.public.stats.pointsCount)return void this._.public.reset();this.config=t(s,null!=i?i:{}),this._rawConfig=null!=i?i:{},this._controlBackgroundColor(o,this.config),this._.rectangularSelection.updateSelectionClassName(),this._cosmosConfig=this._createCosmosConfig(),null===(n=this._.cosmos)||void 0===n||n.setConfig(this._cosmosConfig),await this._processConfigUpdate(o),this._handleScaleChangeEvents(o,this.config)}finally{}})()}async _processConfigUpdate(t){var i;const n=this._detectPointsChanged(t),o=this._detectLinksChanged(t),s=this._detectVisualChanges(t),e=this._detectLabelChanges(t);if(n||o){if(await this._updateGraphData(n,o))return void await this._rebuildGraph(!n&&o,o)}s&&this._.cosmos&&(await this._updateGraphProperties(t),this._.cosmos.render()),!e||n||o||s||null===(i=this._.labels)||void 0===i||i.update()}async _updateGraphData(t,i){let n=!1;return this._dataUploadPromise&&(o("Data upload is already in progress, waiting for it to complete.","uploadData","info"),await this._dataUploadPromise),this._dataUploadPromise=(async()=>{var o,s,e,r;(null===(o=this._.cosmos)||void 0===o?void 0:o.isSimulationRunning)&&(null===(s=this._.cosmos)||void 0===s||s.pause()),this._.dbCoordinator.clearCache();try{if(t){const{pointsOk:t}=await this._uploadAndValidateGraphData(i);n=t}else if(i){const{linksOk:i}=await this._uploadAndValidateLinksData();n=t?n&&i:i}}finally{this._dataUploadPromise=null,this._.dispatchEvent(new CustomEvent("dataUploaded")),null===(r=null===(e=this.config)||void 0===e?void 0:e.onGraphDataUpdated)||void 0===r||r.call(e)}})(),await this._dataUploadPromise,n}async _uploadAndValidateGraphData(t){const{config:i}=this;if(!i.points){this._.public.reset(!1);const t="Points source data is not provided in `points`.";return o(t,"_uploadAndValidateGraphData","error"),this._.updateMessage(`🚨 ${t}`),{pointsOk:!1,linksOk:!1}}const{pointsError:n,linksError:s}=await this._.dataUploader.uploadData(i.points,i.links);if(n){const t="Failed to upload points data: The data is invalid or empty.";return o(t,"_uploadAndValidateGraphData","error"),this._.updateMessage(`🚨 ${t}`),{pointsOk:!1,linksOk:!1}}const e=!n&&await this._validator.validatePoints();if(!e)return{pointsOk:e,linksOk:!1};const r=t&&!s&&await this._validator.validateLinks();return i.links&&!r&&o("Provided links data is empty or invalid. Only points will be rendered.","_uploadAndValidateGraphData","warn"),{pointsOk:e,linksOk:r}}async _uploadAndValidateLinksData(){let t=!1;if(0===this._.public.stats.pointsCount)return{linksOk:t};if(this.clearCosmosBuffers(!0),!this.config.links)return await this._.dropLocalTables(!0),{linksOk:t};const{linksError:i}=await this._.dataUploader.uploadData(void 0,this.config.links);return t=!i&&await this._validator.validateLinks(),t||await this._.dropLocalTables(!0),{linksOk:t}}async _rebuildGraph(t,i){var n,s,e;try{t?await this._updateGraphProperties(void 0,!1):(await this._.initializeCosmos(),this._.initializeLabels(),await this._updateGraphProperties(void 0,!0,i))}catch(t){o(t,"_rebuildGraph","error"),this._.updateMessage(`🚨 ${t}`)}finally{this._.updateMessage(null),null===(n=this._.cosmos)||void 0===n||n.render(1),await this._.updateStats(),null===(e=(s=this.config).onGraphRebuilt)||void 0===e||e.call(s,this._.public.stats),this.config.points&&o(`Rendered graph with ${this._.public.stats.pointsCount} points and ${this._.public.stats.linksCount} links.`)}}async _updateGraphProperties(t,i=!0,n=!0){n&&await this._updateLinkProperties(t),i&&await this._updatePointProperties(t),this._updateClusterProperties(t)}async _updatePointProperties(t,i=!1){var n,o,s;const{_:{dbCoordinator:e,public:{pointsTableName:r}}}=this,a=await l(e,r);let h=!1;(null==a?void 0:a.numRows)?(h=await this._handlePointPositions(t,a,i),h&&(null===(n=this._.cosmos)||void 0===n||n.graph.update()),this._handlePointColors(t,a),this._handlePointSizes(t,a),this._handlePointMiscProps(t,a),h?null===(o=this._.labels)||void 0===o||o.update():null===(s=this._.labels)||void 0===s||s.render()):await this._.public.reset(!1)}async _updateLinkProperties(t){const{dbCoordinator:i,cosmos:n,public:{linksTableName:o}}=this._,s=await c(i,o);if(s.numRows!==(null==n?void 0:n.graph.linksNumber)){const t=p(s,this.config);null==n||n.setLinks(t)}this._handleLinkColors(t,s),this._handleLinkWidths(t,s),this._handleLinkStrengths(t,s),this._handleLinkArrows(t,s)}_updateClusterProperties(t){var i;const{config:n,_:{cosmos:o}}=this;t&&(null==t?void 0:t.clusterPositions)===n.clusterPositions||null==o||o.setClusterPositions(null!==(i=n.clusterPositions)&&void 0!==i?i:[])}async _handlePointPositions(t,i,n=!1){const{config:o,_:{cosmos:s}}=this;if((null==s?void 0:s.graph.pointsNumber)&&t&&t.pointXBy===o.pointXBy&&t.pointYBy===o.pointYBy)return!1;let e=[];if(o.pointXBy||o.pointYBy){if(!await this._validator.validatePointPositions())return!1;e=h(i,o)}else e=n?d(s,i.numRows):u(i.numRows,o.spaceSize);return null==s||s.setPointPositions(new Float32Array(e)),!0}_handlePointColors(t,n){const{config:s,_:{cosmos:e}}=this,r=[A.PointColor,A.PointColorStrategy,A.PointColorPalette,A.PointColorFn,A.PointColorMap,"pointColor"];if(t&&!this._hasConfigChanged(t,s,r))return;let a=new Float32Array;const l=s.pointColorBy?n.getChild(s.pointColorBy):void 0;if(this._currentPointColorStrategy=P(this._rawConfig,null==l?void 0:l.type),this._currentPointColorFn=void 0,this._currentPointColorStrategy===v.Degree){const t=null==e?void 0:e.graph.degree;t&&(this._currentPointColorFn=m(this._currentPointColorStrategy,s,t),a=f(i(t),s.pointColor,this._currentPointColorFn))}else l?(this._currentPointColorFn=m(this._currentPointColorStrategy,s,l.toArray(),null==l?void 0:l.type),a=f(l,s.pointColor,this._currentPointColorFn)):s.pointColorBy&&o(`Column "${s.pointColorBy}" for \`${A.PointColor}\` not found`,"_handlePointColors","warn");null==e||e.setPointColors(a),this._.dispatchEvent(new CustomEvent("pointColorUpdated"))}_handlePointSizes(t,n){const{config:s,_:{cosmos:e}}=this,r=[A.PointSize,A.PointSizeStrategy,A.PointSizeRange,A.PointSizeFn,"pointSize"];if(t&&!this._hasConfigChanged(t,s,r))return;let a=new Float32Array;const l=s.pointSizeBy?n.getChild(s.pointSizeBy):void 0;if(this._currentPointSizeStrategy=w(this._rawConfig,null==l?void 0:l.type),this._currentPointSizeFn=void 0,this._currentPointSizeStrategy===S.Degree){const t=null==e?void 0:e.graph.degree;t&&(this._currentPointSizeFn=L(this._currentPointSizeStrategy,s,t),a=k(i(t),s.pointSize,this._currentPointSizeFn))}else l?(this._currentPointSizeFn=L(this._currentPointSizeStrategy,s,l.toArray()),a=k(l,s.pointSize,this._currentPointSizeFn)):s.pointSizeBy&&o(`Column "${s.pointSizeBy}" for \`${A.PointSize}\` not found`,"_handlePointSizes","warn");null==e||e.setPointSizes(a),this._.dispatchEvent(new CustomEvent("pointSizeUpdated"))}_handlePointMiscProps(t,i){const{config:n,_:{cosmos:o}}=this;if(!t||t.pointClusterBy!==n.pointClusterBy){const t=n.pointClusterBy?i.getChild(n.pointClusterBy):void 0;null==o||o.setPointClusters(null==t?void 0:t.toArray())}if(!t||t.pointClusterStrengthBy!==n.pointClusterStrengthBy){const t=n.pointClusterStrengthBy?i.getChild(n.pointClusterStrengthBy):void 0;let s=new Float32Array;t&&(s=k(t,r)),null==o||o.setPointClusterStrength(s)}}_handleLinkColors(t,i){const{config:n,_:{cosmos:s}}=this,e=[z.LinkColor,z.LinkColorFn,"linkColor"];if(t&&!this._hasConfigChanged(t,n,e))return;let r=new Float32Array;const a=n.linkColorBy?i.getChild(n.linkColorBy):void 0;this._currentLinkColorFn=void 0,a?(this._currentLinkColorFn=n.linkColorByFn,r=f(a,n.linkColor,this._currentLinkColorFn)):n.linkColorBy&&o(`Column "${n.linkColorBy}" for \`${z.LinkColor}\` not found`,"_handleLinkColors","warn"),null==s||s.setLinkColors(r),this._.dispatchEvent(new CustomEvent("linkColorUpdated"))}_handleLinkWidths(t,i){var n;const{config:s,_:{cosmos:e}}=this,r=[z.LinkWidth,z.LinkWidthRange,z.LinkWidthFn,"linkWidth"];if(t&&!this._hasConfigChanged(t,s,r))return;let a=new Float32Array;const l=s.linkWidthBy?i.getChild(s.linkWidthBy):void 0;this._currentLinkWidthFn=void 0,l?(this._currentLinkWidthFn=null!==(n=s.linkWidthByFn)&&void 0!==n?n:C(l.toArray(),s.linkWidthRange),a=k(l,s.linkWidth,this._currentLinkWidthFn)):s.linkWidthBy&&o(`Column "${s.linkWidthBy}" for \`${z.LinkWidth}\` not found`,"_handleLinkWidths","warn"),null==e||e.setLinkWidths(a),this._.dispatchEvent(new CustomEvent("linkWidthUpdated"))}_handleLinkStrengths(t,i){var n;const{config:s,_:{cosmos:e}}=this,r=[z.LinkStrength,z.LinkStrengthRange,z.LinkStrengthFn];if(t&&!this._hasConfigChanged(t,s,r))return;let l=new Float32Array;const h=s.linkStrengthBy?i.getChild(s.linkStrengthBy):void 0;if(h){const t=null!==(n=s.linkStrengthByFn)&&void 0!==n?n:C(h.toArray(),s.linkStrengthRange);l=k(h,a,t)}else s.linkStrengthBy&&o(`Column "${s.linkStrengthBy}" for \`${z.LinkStrength}\` not found`,"_handleLinkStrengths","warn");null==e||e.setLinkStrength(l)}_handleLinkArrows(t,i){const{config:n,_:{cosmos:s}}=this,e=[z.LinkArrow,z.LinkArrowFn];if(t&&!this._hasConfigChanged(t,n,e))return;let r=[];const a=n.linkArrowBy?i.getChild(n.linkArrowBy):void 0;a?r=y(a,n.linkArrows,n.linkArrowByFn):n.linkArrowBy&&o(`Column "${n.linkArrowBy}" for \`${z.LinkArrow}\` not found`,"_handleLinkArrows","warn"),null==s||s.setLinkArrows(r)}_handleScaleChangeEvents(t,i){(null==t?void 0:t.pointSizeScale)!==i.pointSizeScale&&this._.dispatchEvent(new CustomEvent("pointSizeScaleUpdated")),(null==t?void 0:t.linkWidthScale)!==i.linkWidthScale&&this._.dispatchEvent(new CustomEvent("linkWidthScaleUpdated"))}_hasConfigChanged(t,i,o){return o.some((o=>!n(t[o],i[o])))}_detectPointsChanged(t){return this._hasConfigChanged(t,this.config,b)}_detectLinksChanged(t){return this._hasConfigChanged(t,this.config,W)}_detectLabelChanges(t){return this._hasConfigChanged(t,this.config,F)}_detectVisualChanges(t){return this._hasConfigChanged(t,this.config,E)}_controlBackgroundColor(t,i){var n,o;if((null==t?void 0:t.backgroundColor)===i.backgroundColor)return;const s=_(i.backgroundColor),r=s&&g(s)>.65?"#000000":"#ffffff";null===(n=this._.containerElement)||void 0===n||n.style.setProperty("--cosmograph-text-color",r),null===(o=this._.cosmosElement)||void 0===o||o.style.setProperty("backgroundColor",null!=s?s:e)}_createCosmosConfig(){var t,i;const n={...this.config,hoveredPointCursor:this._checkPointEvents()?null!==(i=null===(t=this.config)||void 0===t?void 0:t.hoveredPointCursor)&&void 0!==i?i:"pointer":"auto"};return delete n.disableSimulation,this._.eventManager.attachCosmosEvents(n),n}clearCosmosBuffers(t){const{_:{cosmos:i}}=this;t||(null==i||i.setPointPositions(new Float32Array),null==i||i.setPointColors(new Float32Array),null==i||i.setPointSizes(new Float32Array),null==i||i.setPointClusters([]),null==i||i.setPointClusterStrength(new Float32Array),null==i||i.setClusterPositions([])),null==i||i.setLinks(new Float32Array),null==i||i.setLinkColors(new Float32Array),null==i||i.setLinkWidths(new Float32Array),null==i||i.setLinkStrength(new Float32Array),null==i||i.setLinkArrows([])}}export{U as CosmographConfigManager}; | ||
import{merge as t}from"@cosmograph/ui";import{vectorFromArray as i}from"apache-arrow";import{isEqual as n}from"../../utils/utils.js";import{cosmographLog as o}from"../../utils/log.js";import{defaultCosmographConfig as s}from"./index.js";import{defaultBackgroundColor as e,defaultPointClusterStrength as r,defaultLinkStrength as a}from"./defaults.js";import{getAllPoints as l,getPointPositionsFromTable as h,fillMissingPointPositions as d,getRandomPointPositions as u}from"../graph-utils/points.js";import{getAllLinks as c,mergeLinkPositions as p}from"../graph-utils/links.js";import{getHexColor as _,hexToBrightness as g}from"../graph-utils/colors.js";import{getSizeScale as C}from"../graph-utils/sizes.js";import{colorProcessor as f,sizeProcessor as k,arrowProcessor as v}from"../graph-utils/vectors.js";import{PointColorStrategy as P,resolveOptimalPointColorStrategy as y,getActivePointColorFn as m}from"../strategies/point-color.js";import{PointSizeStrategy as w,resolveOptimalPointSizeStrategy as S,getActivePointSizeFn as L}from"../strategies/point-size.js";import{labelsUpdateKeys as F}from"./interfaces/labels.js";import{CosmographConfigValidator as B}from"./validator.js";import{BasePointsConfigKeys as A,BaseLinksConfigKeys as b,requiredPointsConfigKeys as z,requiredLinksConfigKeys as E,unrequiredProps as W}from"./interfaces/data.js";class U{constructor(t){this._=t,this.config={},this._rawConfig={},this._cosmosConfig={},this._dataUploadPromise=null,this._configUpdatePromise=null,this._currentPointColorStrategy=P.Direct,this._currentPointSizeStrategy=w.Direct,this.resetCosmographConfig=()=>{this.config=s},this._checkPointEvents=()=>!(void 0===this.config.onClick&&!this.config.selectPointOnClick&&!this.config.focusPointOnClick),this._validator=new B(t)}get activePointColorStrategy(){return this._currentPointColorStrategy}get activePointSizeStrategy(){return this._currentPointSizeStrategy}get activePointColorFn(){return this._currentPointColorFn}get activePointSizeFn(){return this._currentPointSizeFn}get activeLinkColorFn(){return this._currentLinkColorFn}get activeLinkWidthFn(){return this._currentLinkWidthFn}get cosmosConfig(){return this._cosmosConfig}async configUpdated(){await this._configUpdatePromise}async dataReady(){var t;(null===(t=this._.dbCoordinator)||void 0===t?void 0:t.internalDB)&&this._dataUploadPromise&&await this._dataUploadPromise}setConfig(i){this._configUpdatePromise=(async()=>{var n;try{await this._.dbReady();const o=this.config;if(o.points&&!(null==i?void 0:i.points)&&!this._.public.stats.pointsCount)return void this._.public.reset();this.config=t(s,null!=i?i:{}),this._rawConfig=null!=i?i:{},this._controlBackgroundColor(o,this.config),this._.rectangularSelection.updateSelectionClassName(),this._cosmosConfig=this._createCosmosConfig(),null===(n=this._.cosmos)||void 0===n||n.setConfig(this._cosmosConfig),await this._processConfigUpdate(o),this._handleScaleChangeEvents(o,this.config)}finally{this._configUpdatePromise=null}})()}async _processConfigUpdate(t){var i;const n=this._detectPointsChanged(t),o=this._detectLinksChanged(t),s=this._detectVisualChanges(t),e=this._detectLabelChanges(t);if(n||o){if(await this._updateGraphData(n,o))return void await this._rebuildGraph(!n&&o,o)}s&&this._.cosmos&&(await this._updateGraphProperties(t,!0,this._.public.stats.linksCount>0),this._.cosmos.render()),!e||n||o||s||null===(i=this._.labels)||void 0===i||i.update()}async _updateGraphData(t,i){let n=!1;return this._dataUploadPromise&&(o("Data upload is already in progress, waiting for it to complete.","uploadData","info"),await this._dataUploadPromise),this._dataUploadPromise=(async()=>{var o,s,e,r;(null===(o=this._.cosmos)||void 0===o?void 0:o.isSimulationRunning)&&(null===(s=this._.cosmos)||void 0===s||s.pause()),this._.dbCoordinator.clearCache();try{if(t){const{pointsOk:t}=await this._uploadAndValidateGraphData(i);n=t}else if(i){const{linksOk:i}=await this._uploadAndValidateLinksData();n=t?n&&i:i}}finally{this._dataUploadPromise=null,this._.dispatchEvent(new CustomEvent("dataUploaded")),null===(r=null===(e=this.config)||void 0===e?void 0:e.onGraphDataUpdated)||void 0===r||r.call(e)}})(),await this._dataUploadPromise,n}async _uploadAndValidateGraphData(t){const{config:i}=this;if(!i.points){this._.public.reset(!1);const t="Points source data is not provided in `points`.";return o(t,"_uploadAndValidateGraphData","error"),this._.updateMessage(`🚨 ${t}`),{pointsOk:!1,linksOk:!1}}const{pointsError:n,linksError:s}=await this._.dataUploader.uploadData(i.points,i.links);if(n){const t="Failed to upload points data: The data is invalid or empty.";return o(t,"_uploadAndValidateGraphData","error"),this._.updateMessage(`🚨 ${t}`),{pointsOk:!1,linksOk:!1}}const e=!n&&await this._validator.validatePoints();if(!e)return{pointsOk:e,linksOk:!1};const r=t&&!s&&await this._validator.validateLinks();return i.links&&!r&&o("Provided links data is empty or invalid. Only points will be rendered.","_uploadAndValidateGraphData","warn"),{pointsOk:e,linksOk:r}}async _uploadAndValidateLinksData(){let t=!1;if(0===this._.public.stats.pointsCount)return{linksOk:t};if(this.clearCosmosBuffers(!0),!this.config.links)return await this._.dropLocalTables(!0),{linksOk:t};const{linksError:i}=await this._.dataUploader.uploadData(void 0,this.config.links);return t=!i&&await this._validator.validateLinks(),t||await this._.dropLocalTables(!0),{linksOk:t}}async _rebuildGraph(t,i){var n,s,e;try{t?await this._updateGraphProperties(void 0,!1):(await this._.initializeCosmos(),this._.initializeLabels(),await this._updateGraphProperties(void 0,!0,i)),this._.updateMessage(null),null===(n=this._.cosmos)||void 0===n||n.render(1),this._.dispatchEvent(new CustomEvent("graphRebuilt")),await this._.updateStats(),null===(e=(s=this.config).onGraphRebuilt)||void 0===e||e.call(s,this._.public.stats),this.config.points&&o(`Rendered graph with ${this._.public.stats.pointsCount} points and ${this._.public.stats.linksCount} links.`)}catch(t){o(t,"_rebuildGraph","error"),this._.updateMessage(`🚨 ${t}`)}}async _updateGraphProperties(t,i=!0,n=!0){n&&await this._updateLinkProperties(t),i&&await this._updatePointProperties(t),this._updateClusterProperties(t)}async _updatePointProperties(t,i=!1){var n,o,s;const{_:{dbCoordinator:e,public:{pointsTableName:r}}}=this,a=await l(e,r);let h=!1;(null==a?void 0:a.numRows)?(h=await this._handlePointPositions(t,a,i),h&&(null===(n=this._.cosmos)||void 0===n||n.graph.update()),this._handlePointColors(t,a),this._handlePointSizes(t,a),this._handlePointMiscProps(t,a),h?null===(o=this._.labels)||void 0===o||o.update():null===(s=this._.labels)||void 0===s||s.render()):await this._.public.reset(!1)}async _updateLinkProperties(t){const{dbCoordinator:i,cosmos:n,public:{linksTableName:o}}=this._,s=await c(i,o);if(s.numRows!==(null==n?void 0:n.graph.linksNumber)){const t=p(s,this.config);null==n||n.setLinks(t)}this._handleLinkColors(t,s),this._handleLinkWidths(t,s),this._handleLinkStrengths(t,s),this._handleLinkArrows(t,s)}_updateClusterProperties(t){var i;const{config:n,_:{cosmos:o}}=this;t&&(null==t?void 0:t.clusterPositions)===n.clusterPositions||null==o||o.setClusterPositions(null!==(i=n.clusterPositions)&&void 0!==i?i:[])}async _handlePointPositions(t,i,n=!1){const{config:o,_:{cosmos:s}}=this;if((null==s?void 0:s.graph.pointsNumber)&&t&&t.pointXBy===o.pointXBy&&t.pointYBy===o.pointYBy)return!1;let e=[];if(o.pointXBy||o.pointYBy){if(!await this._validator.validatePointPositions())return!1;e=h(i,o)}else e=n?d(s,i.numRows):u(i.numRows,o.spaceSize);return null==s||s.setPointPositions(new Float32Array(e)),!0}_handlePointColors(t,n){const{config:s,_:{cosmos:e}}=this,r=[A.PointColor,A.PointColorStrategy,A.PointColorPalette,A.PointColorFn,A.PointColorMap,"pointColor"];if(t&&!this._hasConfigChanged(t,s,r))return;let a=new Float32Array;const l=s.pointColorBy?n.getChild(s.pointColorBy):void 0;if(this._currentPointColorStrategy=y(this._rawConfig,null==l?void 0:l.type),this._currentPointColorFn=void 0,this._currentPointColorStrategy===P.Degree){const t=null==e?void 0:e.graph.degree;t&&(this._currentPointColorFn=m(this._currentPointColorStrategy,s,t),a=f(i(t),s.pointColor,this._currentPointColorFn))}else l?(this._currentPointColorFn=m(this._currentPointColorStrategy,s,l.toArray(),null==l?void 0:l.type),a=f(l,s.pointColor,this._currentPointColorFn)):s.pointColorBy&&o(`Column "${s.pointColorBy}" for \`${A.PointColor}\` not found`,"_handlePointColors","warn");null==e||e.setPointColors(a),this._.dispatchEvent(new CustomEvent("pointColorUpdated"))}_handlePointSizes(t,n){const{config:s,_:{cosmos:e}}=this,r=[A.PointSize,A.PointSizeStrategy,A.PointSizeRange,A.PointSizeFn,"pointSize"];if(t&&!this._hasConfigChanged(t,s,r))return;let a=new Float32Array;const l=s.pointSizeBy?n.getChild(s.pointSizeBy):void 0;if(this._currentPointSizeStrategy=S(this._rawConfig,null==l?void 0:l.type),this._currentPointSizeFn=void 0,this._currentPointSizeStrategy===w.Degree){const t=null==e?void 0:e.graph.degree;t&&(this._currentPointSizeFn=L(this._currentPointSizeStrategy,s,t),a=k(i(t),s.pointSize,this._currentPointSizeFn))}else l?(this._currentPointSizeFn=L(this._currentPointSizeStrategy,s,l.toArray()),a=k(l,s.pointSize,this._currentPointSizeFn)):s.pointSizeBy&&o(`Column "${s.pointSizeBy}" for \`${A.PointSize}\` not found`,"_handlePointSizes","warn");null==e||e.setPointSizes(a),this._.dispatchEvent(new CustomEvent("pointSizeUpdated"))}_handlePointMiscProps(t,i){const{config:n,_:{cosmos:o}}=this;if(!t||t.pointClusterBy!==n.pointClusterBy){const t=n.pointClusterBy?i.getChild(n.pointClusterBy):void 0;null==o||o.setPointClusters(null==t?void 0:t.toArray())}if(!t||t.pointClusterStrengthBy!==n.pointClusterStrengthBy){const t=n.pointClusterStrengthBy?i.getChild(n.pointClusterStrengthBy):void 0;let s=new Float32Array;t&&(s=k(t,r)),null==o||o.setPointClusterStrength(s)}}_handleLinkColors(t,i){const{config:n,_:{cosmos:s}}=this,e=[b.LinkColor,b.LinkColorFn,"linkColor"];if(t&&!this._hasConfigChanged(t,n,e))return;let r=new Float32Array;const a=n.linkColorBy?i.getChild(n.linkColorBy):void 0;this._currentLinkColorFn=void 0,a?(this._currentLinkColorFn=n.linkColorByFn,r=f(a,n.linkColor,this._currentLinkColorFn)):n.linkColorBy&&o(`Column "${n.linkColorBy}" for \`${b.LinkColor}\` not found`,"_handleLinkColors","warn"),null==s||s.setLinkColors(r),this._.dispatchEvent(new CustomEvent("linkColorUpdated"))}_handleLinkWidths(t,i){var n;const{config:s,_:{cosmos:e}}=this,r=[b.LinkWidth,b.LinkWidthRange,b.LinkWidthFn,"linkWidth"];if(t&&!this._hasConfigChanged(t,s,r))return;let a=new Float32Array;const l=s.linkWidthBy?i.getChild(s.linkWidthBy):void 0;this._currentLinkWidthFn=void 0,l?(this._currentLinkWidthFn=null!==(n=s.linkWidthByFn)&&void 0!==n?n:C(l.toArray(),s.linkWidthRange),a=k(l,s.linkWidth,this._currentLinkWidthFn)):s.linkWidthBy&&o(`Column "${s.linkWidthBy}" for \`${b.LinkWidth}\` not found`,"_handleLinkWidths","warn"),null==e||e.setLinkWidths(a),this._.dispatchEvent(new CustomEvent("linkWidthUpdated"))}_handleLinkStrengths(t,i){var n;const{config:s,_:{cosmos:e}}=this,r=[b.LinkStrength,b.LinkStrengthRange,b.LinkStrengthFn];if(t&&!this._hasConfigChanged(t,s,r))return;let l=new Float32Array;const h=s.linkStrengthBy?i.getChild(s.linkStrengthBy):void 0;if(h){const t=null!==(n=s.linkStrengthByFn)&&void 0!==n?n:C(h.toArray(),s.linkStrengthRange);l=k(h,a,t)}else s.linkStrengthBy&&o(`Column "${s.linkStrengthBy}" for \`${b.LinkStrength}\` not found`,"_handleLinkStrengths","warn");null==e||e.setLinkStrength(l)}_handleLinkArrows(t,i){const{config:n,_:{cosmos:s}}=this,e=[b.LinkArrow,b.LinkArrowFn];if(t&&!this._hasConfigChanged(t,n,e))return;let r=[];const a=n.linkArrowBy?i.getChild(n.linkArrowBy):void 0;a?r=v(a,n.linkArrows,n.linkArrowByFn):n.linkArrowBy&&o(`Column "${n.linkArrowBy}" for \`${b.LinkArrow}\` not found`,"_handleLinkArrows","warn"),null==s||s.setLinkArrows(r)}_handleScaleChangeEvents(t,i){(null==t?void 0:t.pointSizeScale)!==i.pointSizeScale&&this._.dispatchEvent(new CustomEvent("pointSizeScaleUpdated")),(null==t?void 0:t.linkWidthScale)!==i.linkWidthScale&&this._.dispatchEvent(new CustomEvent("linkWidthScaleUpdated"))}_hasConfigChanged(t,i,o){return o.some((o=>!n(t[o],i[o])))}_detectPointsChanged(t){return this._hasConfigChanged(t,this.config,z)}_detectLinksChanged(t){return this._hasConfigChanged(t,this.config,E)}_detectLabelChanges(t){return this._hasConfigChanged(t,this.config,F)}_detectVisualChanges(t){return this._hasConfigChanged(t,this.config,W)}_controlBackgroundColor(t,i){var n,o;if((null==t?void 0:t.backgroundColor)===i.backgroundColor)return;const s=_(i.backgroundColor),r=s&&g(s)>.65?"#000000":"#ffffff";null===(n=this._.containerElement)||void 0===n||n.style.setProperty("--cosmograph-text-color",r),null===(o=this._.cosmosElement)||void 0===o||o.style.setProperty("backgroundColor",null!=s?s:e)}_createCosmosConfig(){var t,i;const n={...this.config,hoveredPointCursor:this._checkPointEvents()?null!==(i=null===(t=this.config)||void 0===t?void 0:t.hoveredPointCursor)&&void 0!==i?i:"pointer":"auto"};return delete n.disableSimulation,this._.eventManager.attachCosmosEvents(n),n}clearCosmosBuffers(t){const{_:{cosmos:i}}=this;t||(null==i||i.setPointPositions(new Float32Array),null==i||i.setPointColors(new Float32Array),null==i||i.setPointSizes(new Float32Array),null==i||i.setPointClusters([]),null==i||i.setPointClusterStrength(new Float32Array),null==i||i.setClusterPositions([])),null==i||i.setLinks(new Float32Array),null==i||i.setLinkColors(new Float32Array),null==i||i.setLinkWidths(new Float32Array),null==i||i.setLinkStrength(new Float32Array),null==i||i.setLinkArrows([])}}export{U as CosmographConfigManager}; | ||
//# sourceMappingURL=manager.js.map |
@@ -1,2 +0,2 @@ | ||
import{cosmographLog as i}from"../../utils/log.js";import{isTableExists as s,checkColumnsExist as t}from"../graph-utils/misc.js";import{requiredPointsConfigKeys as n,requiredLinksConfigKeys as o,BasePointsConfigKeys as e}from"./interfaces/data.js";import"./interfaces/labels.js";class r{constructor(i){this._=i}async validatePoints(){const{public:{config:t,pointsTableName:o},dbCoordinator:e}=this._,r=n.slice(1),a=s=>(i(s,"validatePoints","error"),this._.updateMessage(`🚨 ${s}`),!1);if(!await s(e,o))return a(`Failed to get points data. Table "${o}" does not exist`);const l=this._getMissingProperties(t,r);if(l.length)return a(`Failed to get points data.\n\nMissing required properties: ${this._formatMissingProps(l)}.`);const{exists:d,missingColumns:p}=await this._validateColumns(t,o,r);return!!d||a(`Failed to get points data.\n\nMissing provided columns for required properties: ${this._formatMissingColumns(p,r)}.`)}async validateLinks(){const{public:{config:t,linksTableName:n},dbCoordinator:e}=this._,r=o.slice(1);if(!await s(e,n)){const s=`Failed to get links data. Table "${n}" does not exist`;return i(s,"validateLinks","error"),this._.updateMessage(`🚨 ${s}`),!1}const a=this._getMissingProperties(t,r);if(a.length)return i(`Failed to get links data.\n\nMissing required properties: ${this._formatMissingProps(a)}.`,"validateLinks","warn"),!1;const{exists:l,missingColumns:d}=await this._validateColumns(t,n,r);return!!l||(i(`Failed to get links data.\n\nMissing provided columns for required properties: ${this._formatMissingColumns(d,r)}.`,"validateLinks","warn"),!1)}async validatePointPositions(){const{public:{pointsTableName:s,config:t,config:{pointXBy:n,pointYBy:o}}}=this._;if(Boolean(n)!==Boolean(o)){const s=`Couldn't render points: Only one of \`${e.PointX}\` or \`${e.PointY}\` provided.`;return i(s,"error"),this._.updateMessage(`🚨 ${s}`),!1}if(n&&o){const{exists:n,missingColumns:o}=await this._validateColumns(t,s,[e.PointX,e.PointY]);if(!n){const s=`Couldn't render points: Failed to get provided point positions, missing columns for positions: ${this._formatMissingProps(o)}.`;return i(s,"error"),this._.updateMessage(`🚨 ${s}`),!1}}return!0}async _validateColumns(i,s,n){const o=n.map((s=>i[s])),e=[];return{exists:await t(this._.dbCoordinator,s,o,e),missingColumns:e}}_getMissingProperties(i,s){return s.filter((s=>void 0===i[s]))}_formatMissingProps(i){return i.map((i=>`"${i}"`)).join(", ")}_formatMissingColumns(i,s){return i.map((t=>`"${t}" (${s[i.indexOf(t)]})`)).join(", ")}}export{r as CosmographConfigValidator}; | ||
import{cosmographLog as i}from"../../utils/log.js";import{isTableExists as s,checkColumnsExist as t}from"../graph-utils/misc.js";import{requiredPointsConfigKeys as o,requiredLinksConfigKeys as n,BasePointsConfigKeys as e}from"./interfaces/data.js";import"./interfaces/labels.js";class r{constructor(i){this._=i}async validatePoints(){const{config:t,dbCoordinator:n,public:{pointsTableName:e}}=this._,r=o.slice(1),a=s=>{throw i(s,"validatePoints","error"),this._.updateMessage(`🚨 ${s}`),new Error(s)};if(!await s(n,e))return a(`Failed to get points data. Table "${e}" does not exist`);const l=this._getMissingProperties(t,r);if(l.length)return a(`Failed to get points data.\n\nMissing required properties: ${this._formatMissingProps(l)}.`);const{exists:d,missingColumns:p}=await this._validateColumns(t,e,r);return!!d||a(`Failed to get points data.\n\nMissing provided columns for required properties: ${this._formatMissingColumns(p,r)}.`)}async validateLinks(){const{config:t,dbCoordinator:o,public:{linksTableName:e}}=this._,r=n.slice(1);if(!await s(o,e)){const s=`Failed to get links data. Table "${e}" does not exist`;return i(s,"validateLinks","error"),this._.updateMessage(`🚨 ${s}`),!1}const a=this._getMissingProperties(t,r);if(a.length)return i(`Failed to get links data.\n\nMissing required properties: ${this._formatMissingProps(a)}.`,"validateLinks","warn"),!1;const{exists:l,missingColumns:d}=await this._validateColumns(t,e,r);return!!l||(i(`Failed to get links data.\n\nMissing provided columns for required properties: ${this._formatMissingColumns(d,r)}.`,"validateLinks","warn"),!1)}async validatePointPositions(){const{config:s,config:{pointXBy:t,pointYBy:o},public:{pointsTableName:n}}=this._;if(Boolean(t)!==Boolean(o)){const s=`Couldn't render points: Only one of \`${e.PointX}\` or \`${e.PointY}\` provided.`;throw i(s,"validatePointPositions","error"),this._.updateMessage(`🚨 ${s}`),new Error(s)}if(t&&o){const{exists:t,missingColumns:o}=await this._validateColumns(s,n,[e.PointX,e.PointY]);if(!t){const s=`Couldn't render points: Failed to get provided point positions, missing columns for positions: ${this._formatMissingProps(o)}.`;throw i(s,"validatePointPositions","error"),this._.updateMessage(`🚨 ${s}`),new Error(s)}}return!0}async _validateColumns(i,s,o){const n=o.map((s=>i[s])),e=[];return{exists:await t(this._.dbCoordinator,s,n,e),missingColumns:e}}_getMissingProperties(i,s){return s.filter((s=>void 0===i[s]))}_formatMissingProps(i){return i.map((i=>`"${i}"`)).join(", ")}_formatMissingColumns(i,s){return i.map((t=>`"${t}" (${s[i.indexOf(t)]})`)).join(", ")}}export{r as CosmographConfigValidator}; | ||
//# sourceMappingURL=validator.js.map |
@@ -49,3 +49,3 @@ import { WasmDuckDBConnection } from "../duckdb/duckdb-wasm"; | ||
dataUploaded(): Promise<void>; | ||
get config(): CosmographConfig; | ||
private get _config(); | ||
get stats(): CosmographStats; | ||
@@ -64,2 +64,3 @@ get crossfilter(): Crossfilter; | ||
get pointsTableName(): string; | ||
getConfig(): Promise<CosmographConfig>; | ||
getActivePointColorFn(): Promise<ColorAccessorFn | undefined>; | ||
@@ -66,0 +67,0 @@ getActivePointSizeFn(): Promise<SizeAccessorFn | undefined>; |
import { Graph } from '@cosmograph/cosmos'; | ||
import { Cosmograph } from "./"; | ||
import { Cosmograph, CosmographConfig } from "./"; | ||
import { MosaicDBCoordinator } from "../duckdb/mosaic-coordinator"; | ||
@@ -15,2 +15,3 @@ import { CosmographEventManager, CosmographDataUploader, CosmographCrossfilter } from './managers'; | ||
readonly cosmos?: Graph; | ||
readonly config: CosmographConfig; | ||
readonly eventManager: CosmographEventManager; | ||
@@ -17,0 +18,0 @@ readonly configManager: CosmographConfigManager; |
@@ -1,2 +0,2 @@ | ||
import{debounce as t}from"throttle-debounce";import{Selection as e}from"@uwdata/mosaic-core";import{getPointIndicesFromLinks as i}from"../graph-utils/links.js";class s{constructor(i){this._=i,this._linksSelection=e.crossfilter(),this._pointsSelection=e.crossfilter(),this._crossfilter={links:new Set,points:new Set,intersection:new Set},this._onLinksFiltered=t(10,(t=>this._handleCrossfiltering(t,"links"))),this._onPointsFiltered=t(10,(t=>this._handleCrossfiltering(t,"points")))}get filtered(){return this._crossfilter}get pointsSelection(){return this._pointsSelection}get linksSelection(){return this._linksSelection}get onLinksFiltered(){return this._onLinksFiltered}get onPointsFiltered(){return this._onPointsFiltered}get isFilteringActive(){return this._linksSelection.clauses.length>0||this._pointsSelection.clauses.length>0}_handleCrossfiltering(t,e){var i,s;const{cosmos:n,labels:l,public:{config:o}}=this._;this._getSetForCrossfilter(t,e),this._getIntersection(),this.isFilteringActive?null==n||n.selectPointsByIndices(Array.from(this._crossfilter.intersection)):null==n||n.unselectPoints(),"points"===e&&(null===(i=o.onPointsFiltered)||void 0===i||i.call(o,t)),"links"===e&&(null===(s=o.onLinksFiltered)||void 0===s||s.call(o,t)),null==l||l.update(),this._.dispatchEvent(new CustomEvent("dataFiltered"))}_getSetForCrossfilter(t,e){var s;const{public:{config:n}}=this._,l="links"===e?i(t,n):new Set(null===(s=t.getChild(n.pointIndexBy))||void 0===s?void 0:s.toArray());this._crossfilter[e]=l}_getIntersection(){const{links:t,points:e}=this._crossfilter,i=e.values();let s=new Set;if(this._linksSelection.clauses.length&&this._pointsSelection.clauses.length)for(const e of i)t.has(e)&&s.add(e);else s=this._linksSelection.clauses.length?t:e;this._crossfilter.intersection=s}}export{s as CosmographCrossfilter}; | ||
import{debounce as t}from"throttle-debounce";import{Selection as e}from"@uwdata/mosaic-core";import{getPointIndicesFromLinks as i}from"../graph-utils/links.js";class s{constructor(i){this._=i,this._linksSelection=e.crossfilter(),this._pointsSelection=e.crossfilter(),this._crossfilter={links:new Set,points:new Set,intersection:new Set},this._onLinksFiltered=t(10,(t=>this._handleCrossfiltering(t,"links"))),this._onPointsFiltered=t(10,(t=>this._handleCrossfiltering(t,"points")))}get filtered(){return this._crossfilter}get pointsSelection(){return this._pointsSelection}get linksSelection(){return this._linksSelection}get onLinksFiltered(){return this._onLinksFiltered}get onPointsFiltered(){return this._onPointsFiltered}get isFilteringActive(){return this._linksSelection.clauses.length>0||this._pointsSelection.clauses.length>0}_handleCrossfiltering(t,e){var i,s;const{config:n,cosmos:l,labels:o}=this._;this._getSetForCrossfilter(t,e),this._getIntersection(),this.isFilteringActive?null==l||l.selectPointsByIndices(Array.from(this._crossfilter.intersection)):null==l||l.unselectPoints(),"points"===e&&(null===(i=n.onPointsFiltered)||void 0===i||i.call(n,t)),"links"===e&&(null===(s=n.onLinksFiltered)||void 0===s||s.call(n,t)),null==o||o.update(),this._.dispatchEvent(new CustomEvent("dataFiltered"))}_getSetForCrossfilter(t,e){var s;const{config:n}=this._,l="links"===e?i(t,n):new Set(null===(s=t.getChild(n.pointIndexBy))||void 0===s?void 0:s.toArray());this._crossfilter[e]=l}_getIntersection(){const{links:t,points:e}=this._crossfilter,i=e.values();let s=new Set;if(this._linksSelection.clauses.length&&this._pointsSelection.clauses.length)for(const e of i)t.has(e)&&s.add(e);else s=this._linksSelection.clauses.length?t:e;this._crossfilter.intersection=s}}export{s as CosmographCrossfilter}; | ||
//# sourceMappingURL=crossfilter.js.map |
@@ -1,2 +0,2 @@ | ||
import{getPointIndicesByIds as i,getPointIdsByIndices as o}from"../graph-utils/points.js";class n{constructor(i){this._=i}attachCosmosEvents(i={}){i.onSimulationStart=this.onSimulationStart.bind(this),i.onSimulationTick=this.onSimulationTick.bind(this),i.onSimulationEnd=this.onSimulationEnd.bind(this),i.onSimulationPause=this.onSimulationPause.bind(this),i.onSimulationRestart=this.onSimulationRestart.bind(this),i.onClick=this.onClick.bind(this),i.onPointMouseOver=this.onPointMouseOver.bind(this),i.onPointMouseOut=this.onPointMouseOut.bind(this),i.onMouseMove=this.onMouseMove.bind(this),i.onZoomStart=this.onZoomStart.bind(this),i.onZoom=this.onZoom.bind(this),i.onZoomEnd=this.onZoomEnd.bind(this)}getLabelEvents(){return{onLabelClick:this.onLabelClick.bind(this),onHoveredLabelClick:this.onHoveredLabelClick.bind(this)}}onClick(...i){var o;const{config:n}=this._.public;n.selectPointOnClick&&this._.public.selectPoint(i[0],"single"!==n.selectPointOnClick),n.focusPointOnClick&&this._.public.setFocusedPointByIndex(i[0]),null===(o=n.onClick)||void 0===o||o.call(n,...i)}async onLabelClick(o,n){var t;const{pointsTableName:l,config:e}=this._.public,s=this._.dbCoordinator;if(!s)return;const a=await i(s,l,e,[n.id]);a&&a[0]&&(e.selectPointOnLabelClick&&this._.public.selectPoint(a[0]),e.focusPointOnLabelClick&&this._.public.setFocusedPointByIndex(a[0]),null===(t=e.onLabelClick)||void 0===t||t.call(e,a[0],n.id,o))}async onHoveredLabelClick(i){var n;const{pointsTableName:t,config:l}=this._.public,e=this._.dbCoordinator;if(void 0===this._hoveredPointIndex||!e)return;const s=await o(e,t,l,[this._hoveredPointIndex]);s&&s[0]&&(null===(n=l.onLabelClick)||void 0===n||n.call(l,this._hoveredPointIndex,s[0],i))}onAreaSelect(i){var o,n;this._.public.selectPointsInRect(i),null===(n=(o=this._.public.config).onAreaSelected)||void 0===n||n.call(o,i),this._.dispatchEvent(new CustomEvent("areaSelected"))}onPointMouseOver(...i){var o,n,t;const[l,e]=i;null===(n=(o=this._.public.config).onPointMouseOver)||void 0===n||n.call(o,...i),this._hoveredPointIndex=l,null===(t=this._.labels)||void 0===t||t.renderHoveredLabel(l,e)}onPointMouseOut(...i){var o,n,t;null===(n=(o=this._.public.config).onPointMouseOut)||void 0===n||n.call(o,...i),null===(t=this._.labels)||void 0===t||t.renderHoveredLabel()}onMouseMove(...i){var o,n,t;const[l,e]=i;null===(n=(o=this._.public.config).onMouseMove)||void 0===n||n.call(o,...i),null===(t=this._.labels)||void 0===t||t.renderHoveredLabel(l,e)}onZoomStart(...i){var o,n;null===(n=(o=this._.public.config).onZoomStart)||void 0===n||n.call(o,...i)}async onZoom(...i){var o,n,t,l;null===(n=(o=this._.public.config).onZoom)||void 0===n||n.call(o,...i),null===(t=this._.labels)||void 0===t||t.render(),null===(l=this._.labels)||void 0===l||l.renderHoveredLabel(),this._.dispatchEvent(new CustomEvent("pointSizeScaleUpdated")),this._.dispatchEvent(new CustomEvent("linkWidthScaleUpdated"))}onZoomEnd(...i){var o,n;null===(n=(o=this._.public.config).onZoomEnd)||void 0===n||n.call(o,...i)}onSimulationStart(...i){var o,n;null===(n=(o=this._.public.config).onSimulationStart)||void 0===n||n.call(o,...i)}onSimulationTick(...i){var o,n,t;null===(n=(o=this._.public.config).onSimulationTick)||void 0===n||n.call(o,...i),null===(t=this._.labels)||void 0===t||t.render()}onSimulationEnd(...i){var o,n;null===(n=(o=this._.public.config).onSimulationEnd)||void 0===n||n.call(o,...i),this._.dispatchEvent(new CustomEvent("onSimulationEnd"))}onSimulationPause(...i){var o,n;null===(n=(o=this._.public.config).onSimulationPause)||void 0===n||n.call(o,...i)}onSimulationRestart(...i){var o,n;null===(n=(o=this._.public.config).onSimulationRestart)||void 0===n||n.call(o,...i)}}export{n as CosmographEventManager}; | ||
import{getPointIndicesByIds as i,getPointIdsByIndices as o}from"../graph-utils/points.js";class n{constructor(i){this._=i}attachCosmosEvents(i={}){i.onSimulationStart=this.onSimulationStart.bind(this),i.onSimulationTick=this.onSimulationTick.bind(this),i.onSimulationEnd=this.onSimulationEnd.bind(this),i.onSimulationPause=this.onSimulationPause.bind(this),i.onSimulationRestart=this.onSimulationRestart.bind(this),i.onClick=this.onClick.bind(this),i.onPointMouseOver=this.onPointMouseOver.bind(this),i.onPointMouseOut=this.onPointMouseOut.bind(this),i.onMouseMove=this.onMouseMove.bind(this),i.onZoomStart=this.onZoomStart.bind(this),i.onZoom=this.onZoom.bind(this),i.onZoomEnd=this.onZoomEnd.bind(this)}getLabelEvents(){return{onLabelClick:this.onLabelClick.bind(this),onHoveredLabelClick:this.onHoveredLabelClick.bind(this)}}onClick(...i){var o;const{config:n}=this._;n.selectPointOnClick&&this._.public.selectPoint(i[0],"single"!==n.selectPointOnClick),n.focusPointOnClick&&this._.public.setFocusedPointByIndex(i[0]),null===(o=n.onClick)||void 0===o||o.call(n,...i)}async onLabelClick(o,n){var t;const{public:{pointsTableName:l},config:e,dbCoordinator:s}=this._;if(!s)return;const a=await i(s,l,e,[n.id]);a&&a[0]&&(e.selectPointOnLabelClick&&this._.public.selectPoint(a[0]),e.focusPointOnLabelClick&&this._.public.setFocusedPointByIndex(a[0]),null===(t=e.onLabelClick)||void 0===t||t.call(e,a[0],n.id,o))}async onHoveredLabelClick(i){var n;const{public:{pointsTableName:t},config:l,dbCoordinator:e}=this._;if(void 0===this._hoveredPointIndex||!e)return;const s=await o(e,t,l,[this._hoveredPointIndex]);s&&s[0]&&(null===(n=l.onLabelClick)||void 0===n||n.call(l,this._hoveredPointIndex,s[0],i))}onAreaSelect(i){var o,n;this._.public.selectPointsInRect(i),null===(n=(o=this._.config).onAreaSelected)||void 0===n||n.call(o,i),this._.dispatchEvent(new CustomEvent("areaSelected"))}onPointMouseOver(...i){var o,n,t;const[l,e]=i;null===(n=(o=this._.config).onPointMouseOver)||void 0===n||n.call(o,...i),this._hoveredPointIndex=l,null===(t=this._.labels)||void 0===t||t.renderHoveredLabel(l,e)}onPointMouseOut(...i){var o,n,t;null===(n=(o=this._.config).onPointMouseOut)||void 0===n||n.call(o,...i),null===(t=this._.labels)||void 0===t||t.renderHoveredLabel()}onMouseMove(...i){var o,n,t;const[l,e]=i;null===(n=(o=this._.config).onMouseMove)||void 0===n||n.call(o,...i),null===(t=this._.labels)||void 0===t||t.renderHoveredLabel(l,e)}onZoomStart(...i){var o,n;null===(n=(o=this._.config).onZoomStart)||void 0===n||n.call(o,...i)}async onZoom(...i){var o,n,t,l;null===(n=(o=this._.config).onZoom)||void 0===n||n.call(o,...i),null===(t=this._.labels)||void 0===t||t.render(),null===(l=this._.labels)||void 0===l||l.renderHoveredLabel(),this._.dispatchEvent(new CustomEvent("pointSizeScaleUpdated")),this._.dispatchEvent(new CustomEvent("linkWidthScaleUpdated"))}onZoomEnd(...i){var o,n;null===(n=(o=this._.config).onZoomEnd)||void 0===n||n.call(o,...i)}onSimulationStart(...i){var o,n;null===(n=(o=this._.config).onSimulationStart)||void 0===n||n.call(o,...i)}onSimulationTick(...i){var o,n,t;null===(n=(o=this._.config).onSimulationTick)||void 0===n||n.call(o,...i),null===(t=this._.labels)||void 0===t||t.render()}onSimulationEnd(...i){var o,n;null===(n=(o=this._.config).onSimulationEnd)||void 0===n||n.call(o,...i),this._.dispatchEvent(new CustomEvent("onSimulationEnd"))}onSimulationPause(...i){var o,n;null===(n=(o=this._.config).onSimulationPause)||void 0===n||n.call(o,...i)}onSimulationRestart(...i){var o,n;null===(n=(o=this._.config).onSimulationRestart)||void 0===n||n.call(o,...i)}}export{n as CosmographEventManager}; | ||
//# sourceMappingURL=event-manager.js.map |
@@ -1,2 +0,2 @@ | ||
import{MosaicClient as e}from"@uwdata/mosaic-core";import{Query as t}from"@uwdata/mosaic-sql";class i extends e{constructor(e){super(e.crossfilter.pointsSelection),this._=e,this._filterIndexable=!1}get filterIndexable(){return this._filterIndexable}get selection(){return this._.crossfilter.pointsSelection}query(e=[]){return this.selection.clauses.active?(this._filterIndexable=!0,t.from(this._.public.pointsTableName).select(this._.public.config.pointIndexBy).where(e)):(this._filterIndexable=!1,null)}publish(e){this.selection.update({source:this,predicate:!!e&&`(${this._.public.config.pointIndexBy} IN (${e.join(",")}))`})}queryResult(e){var t,i;return(null===(i=null===(t=this.selection)||void 0===t?void 0:t.active)||void 0===i?void 0:i.source)===this&&this._.crossfilter.onPointsFiltered(e),this}}export{i as PointSelectionClient}; | ||
import{MosaicClient as e}from"@uwdata/mosaic-core";import{Query as t}from"@uwdata/mosaic-sql";class i extends e{constructor(e){super(e.crossfilter.pointsSelection),this._=e,this._filterIndexable=!1}get filterIndexable(){return this._filterIndexable}get selection(){return this._.crossfilter.pointsSelection}query(e=[]){return this.selection.clauses.active?(this._filterIndexable=!0,t.from(this._.public.pointsTableName).select(this._.config.pointIndexBy).where(e)):(this._filterIndexable=!1,null)}publish(e){this.selection.update({source:this,predicate:!!e&&`(${this._.config.pointIndexBy} IN (${e.join(",")}))`})}queryResult(e){var t,i;return(null===(i=null===(t=this.selection)||void 0===t?void 0:t.active)||void 0===i?void 0:i.source)===this&&this._.crossfilter.onPointsFiltered(e),this}}export{i as PointSelectionClient}; | ||
//# sourceMappingURL=point-selection-client.js.map |
@@ -10,7 +10,2 @@ import { CosmographConfig } from "./config"; | ||
/** | ||
* Provides access to the current configuration of the Cosmograph instance. | ||
* @returns The current Cosmograph configuration. | ||
*/ | ||
readonly config: CosmographConfig; | ||
/** | ||
* Statistical information about current points and links in the graph. | ||
@@ -105,2 +100,7 @@ * | ||
/** | ||
* Retrieves the current configuration of the Cosmograph. | ||
* @returns A promise that resolves with the current Cosmograph configuration. | ||
*/ | ||
getConfig(): Promise<CosmographConfig>; | ||
/** | ||
* Gets the current coloring function. | ||
@@ -107,0 +107,0 @@ * @returns The point coloring function, or `undefined` if not available. |
@@ -0,1 +1,2 @@ | ||
import { GraphConfigInterface } from '@cosmograph/cosmos'; | ||
import { CosmographConfig } from "../cosmograph"; | ||
@@ -35,3 +36,3 @@ import { CosmographData, CosmographInputData, CosmographLinksConfig, CosmographPointsConfig } from "../cosmograph/config/interfaces"; | ||
*/ | ||
export interface CosmographDataPrepPointsConfig extends Omit<CosmographPointsConfig, 'points' | 'pointIndexBy'> { | ||
export interface CosmographDataPrepPointsConfig extends Omit<CosmographPointsConfig, 'points' | 'pointIndexBy'>, Pick<GraphConfigInterface, 'pointColor' | 'pointGreyoutOpacity' | 'pointSize' | 'pointSizeScale'> { | ||
linkSourceBy?: string; | ||
@@ -51,3 +52,3 @@ linkTargetsBy?: string[]; | ||
*/ | ||
export interface CosmographDataPrepLinksConfig extends Omit<CosmographLinksConfig, 'links' | 'linkTargetBy' | 'linkSourceIndexBy' | 'linkTargetIndexBy'> { | ||
export interface CosmographDataPrepLinksConfig extends Omit<CosmographLinksConfig, 'links' | 'linkTargetBy' | 'linkSourceIndexBy' | 'linkTargetIndexBy'>, Pick<GraphConfigInterface, 'linkColor' | 'linkGreyoutOpacity' | 'linkWidth' | 'linkWidthScale'> { | ||
linkTargetsBy: string[]; | ||
@@ -54,0 +55,0 @@ outputFilename?: string; |
@@ -17,1 +17,3 @@ export * from './cosmograph'; | ||
export type { CosmographInputData, CosmographData } from './cosmograph/config/interfaces'; | ||
export type { PointColorStrategyType as CosmographPointColorStrategy } from './cosmograph/strategies/point-color'; | ||
export type { PointSizeStrategyType as CosmographPointSizeStrategy } from './cosmograph/strategies/point-size'; |
@@ -1,2 +0,2 @@ | ||
import{merge as t}from"@cosmograph/ui";import{getInternalApi as i}from"../../cosmograph/internal.js";import{isTableExists as e,checkColumnsExist as n}from"../../cosmograph/graph-utils/misc.js";import{FilteringClient as s}from"../../cosmograph/selection-clients/filtering-client.js";class a{constructor(t,e,n){this._isValidAccessor=!1,this._isInternalSelection=!1,this._internalApi=i(t),this._config=this._mergeWithDefaultConfig(n),this._filter=this.useLinksData?this._internalApi.crossfilter.linksSelection:this._internalApi.crossfilter.pointsSelection,this._uiComponent=this._createUIComponent(e),this._dataUpdatedHandler=()=>this._getData(),this._dataFilteredHandler=()=>this._onDataFiltered(),this._internalApi.addEventListener("dataUploaded",this._dataUpdatedHandler),this._internalApi.addEventListener("dataFiltered",this._dataFilteredHandler),this._initialize()}async setConfig(t){const i=this._config;this._config=this._mergeWithDefaultConfig(t),await this._onConfigUpdate(i)}getConfig(){return this._config}remove(){var t;null===(t=this._client)||void 0===t||t.reset(),this._internalApi.removeEventListener("dataUploaded",this._dataUpdatedHandler),this._internalApi.removeEventListener("dataFiltered",this._dataFilteredHandler)}get useLinksData(){return this._config.useLinksData}get pointAccessors(){const{pointIdBy:t,pointIndexBy:i}=this._internalApi.public.config;return t&&i?[t,i]:t?[t]:i?[i]:[]}get linkAccessors(){const{linkSourceIndexBy:t,linkTargetIndexBy:i}=this._internalApi.public.config;return t&&i?[t,i]:t?[t]:i?[i]:[]}get tableName(){return this.useLinksData?this._internalApi.public.linksTableName:this._internalApi.public.pointsTableName}_mergeWithDefaultConfig(i){return t(this.defaultConfig,null!=i?i:{})}async _initialize(){this._uiComponent.setLoadingState(),await this._createClient(),(this._internalApi.public.stats.linksCount||this._internalApi.public.stats.pointsCount)&&await this._getData()}async _getData(){var t;await this._internalApi.configManager.dataReady(),this._uiComponent.setLoadingState();const i=await e(this._internalApi.dbCoordinator,this.tableName);this._isValidAccessor=i&&await n(this._internalApi.dbCoordinator,this.tableName,[this.accessor]),i&&this._isValidAccessor?(this._client&&(this._client.preventQuerying=!1),this._currentData=await(null===(t=this._client)||void 0===t?void 0:t.getCurrentData())):(this._currentData=void 0,this._client&&(this._client.preventQuerying=!0)),this._onDataUpdated()}async _createClient(){if(await this._internalApi.dbReady(),!this._internalApi.dbCoordinator)return;const t={tableName:this.tableName,filterBy:this._filter,accessor:this.accessor,include:()=>this.useLinksData?this.linkAccessors:this.pointAccessors,onFiltered:this._handleSelectionUpdate.bind(this),coordinator:this._internalApi.dbCoordinator};this._client=new s(t),this._internalApi.dbCoordinator.connect(this._client)}_handleSelectionUpdate(t){this.accessor&&(this.useLinksData?this._internalApi.crossfilter.onLinksFiltered(t):this._internalApi.crossfilter.onPointsFiltered(t))}_filterByIdx(t,i){var e,n,s,a;const{crossfilter:r,public:{config:l}}=this._internalApi,o=t.getChild(this.accessor);if(!o)return[];const h=o.toArray(),c=null===(e=t.getChild(this.useLinksData?l.linkSourceIndexBy:l.pointIndexBy))||void 0===e?void 0:e.toArray();if(!c)return[];const d=this.useLinksData?null===(n=t.getChild(l.linkTargetIndexBy))||void 0===n?void 0:n.toArray():null,_=this.useLinksData?null===(a=null===(s=r.linksSelection.active)||void 0===s?void 0:s.predicate)||void 0===a?void 0:a.range:null,p=new Array(h.length);let u=0;for(let t=0;t<h.length;t++){const e=h[t];(i.has(c[t])||d&&i.has(d[t]))&&(!_||e>=_[0]&&e<=_[1])&&(p[u++]=e)}return u===p.length?p:p.slice(0,u)}_updateCrossfilteredData(){var t,i;const{crossfilter:e}=this._internalApi;if(!this._currentData||!this._isValidAccessor)return;const n=e.filtered.intersection;if(e.isFilteringActive){const t=this._filterByIdx(this._currentData,n);this._updateHighlightedData(t)}else{const e=null===(i=null===(t=this._currentData)||void 0===t?void 0:t.getChild(this.accessor))||void 0===i?void 0:i.toArray();this._updateHighlightedData(e)}}}export{a as CosmographFilteringComponent}; | ||
import{merge as t}from"@cosmograph/ui";import{getInternalApi as i}from"../../cosmograph/internal.js";import{isTableExists as e,checkColumnsExist as n}from"../../cosmograph/graph-utils/misc.js";import{FilteringClient as s}from"../../cosmograph/selection-clients/filtering-client.js";class a{constructor(t,e,n){this._isValidAccessor=!1,this._isInternalSelection=!1,this._internalApi=i(t),this._config=this._mergeWithDefaultConfig(n),this._filter=this.useLinksData?this._internalApi.crossfilter.linksSelection:this._internalApi.crossfilter.pointsSelection,this._uiComponent=this._createUIComponent(e),this._dataUpdatedHandler=()=>this._getData(),this._dataFilteredHandler=()=>this._onDataFiltered(),this._internalApi.addEventListener("dataUploaded",this._dataUpdatedHandler),this._internalApi.addEventListener("dataFiltered",this._dataFilteredHandler),this._initialize()}async setConfig(t){const i=this._config;this._config=this._mergeWithDefaultConfig(t),await this._onConfigUpdate(i)}getConfig(){return this._config}remove(){var t;null===(t=this._client)||void 0===t||t.reset(),this._internalApi.removeEventListener("dataUploaded",this._dataUpdatedHandler),this._internalApi.removeEventListener("dataFiltered",this._dataFilteredHandler)}get useLinksData(){return this._config.useLinksData}get pointAccessors(){const{pointIdBy:t,pointIndexBy:i}=this._internalApi.config;return t&&i?[t,i]:t?[t]:i?[i]:[]}get linkAccessors(){const{linkSourceIndexBy:t,linkTargetIndexBy:i}=this._internalApi.config;return t&&i?[t,i]:t?[t]:i?[i]:[]}get tableName(){return this.useLinksData?this._internalApi.public.linksTableName:this._internalApi.public.pointsTableName}_mergeWithDefaultConfig(i){return t(this.defaultConfig,null!=i?i:{})}async _initialize(){await this._createClient(),(this._internalApi.public.stats.linksCount||this._internalApi.public.stats.pointsCount)&&await this._getData()}async _getData(){var t;await this._internalApi.configManager.dataReady(),this._uiComponent.setLoadingState();const i=await e(this._internalApi.dbCoordinator,this.tableName);this._isValidAccessor=i&&await n(this._internalApi.dbCoordinator,this.tableName,[this.accessor]),i&&this._isValidAccessor?(this._client&&(this._client.preventQuerying=!1),this._currentData=await(null===(t=this._client)||void 0===t?void 0:t.getCurrentData())):(this._currentData=void 0,this._client&&(this._client.preventQuerying=!0)),this._onDataUpdated()}async _createClient(){if(await this._internalApi.dbReady(),!this._internalApi.dbCoordinator)return;const t={tableName:this.tableName,filterBy:this._filter,accessor:this.accessor,include:()=>this.useLinksData?this.linkAccessors:this.pointAccessors,onFiltered:this._handleSelectionUpdate.bind(this),coordinator:this._internalApi.dbCoordinator};this._client=new s(t),this._internalApi.dbCoordinator.connect(this._client)}_handleSelectionUpdate(t){this.accessor&&(this.useLinksData?this._internalApi.crossfilter.onLinksFiltered(t):this._internalApi.crossfilter.onPointsFiltered(t))}_filterByIdx(t,i){var e,n,s,a;const{crossfilter:r,config:l}=this._internalApi,o=t.getChild(this.accessor);if(!o)return[];const h=o.toArray(),c=null===(e=t.getChild(this.useLinksData?l.linkSourceIndexBy:l.pointIndexBy))||void 0===e?void 0:e.toArray();if(!c)return[];const d=this.useLinksData?null===(n=t.getChild(l.linkTargetIndexBy))||void 0===n?void 0:n.toArray():null,_=this.useLinksData?null===(a=null===(s=r.linksSelection.active)||void 0===s?void 0:s.predicate)||void 0===a?void 0:a.range:null,p=new Array(h.length);let u=0;for(let t=0;t<h.length;t++){const e=h[t];(i.has(c[t])||d&&i.has(d[t]))&&(!_||e>=_[0]&&e<=_[1])&&(p[u++]=e)}return u===p.length?p:p.slice(0,u)}_updateCrossfilteredData(){var t,i;const{crossfilter:e}=this._internalApi;if(!this._currentData||!this._isValidAccessor)return;const n=e.filtered.intersection;if(e.isFilteringActive){const t=this._filterByIdx(this._currentData,n);this._updateHighlightedData(t)}else{const e=null===(i=null===(t=this._currentData)||void 0===t?void 0:t.getChild(this.accessor))||void 0===i?void 0:i.toArray();this._updateHighlightedData(e)}}}export{a as CosmographFilteringComponent}; | ||
//# sourceMappingURL=filtering-component.js.map |
@@ -7,3 +7,5 @@ import { BarsConfigInterface, BarsEvents } from '@cosmograph/ui'; | ||
useLinksData?: boolean; | ||
/** Data column key to access time values for the `CosmographBars`. Default: `undefined` */ | ||
accessor?: string; | ||
/** Enables or disables selecting points with bar value on graph by clicking. Default: `true` */ | ||
selectOnClick?: boolean; | ||
@@ -10,0 +12,0 @@ } |
@@ -1,2 +0,2 @@ | ||
const e={useLinksData:!1,selectOnClick:!0,accessor:"value"};export{e as defaultCosmographBarsConfig}; | ||
const s={useLinksData:!1,selectOnClick:!0,accessor:void 0};export{s as defaultCosmographBarsConfig}; | ||
//# sourceMappingURL=config.js.map |
@@ -12,3 +12,4 @@ import { Cosmograph } from "../../../cosmograph"; | ||
private _handleClick; | ||
private _show; | ||
} | ||
export type { CosmographButtonFitViewConfigInterface }; |
@@ -1,2 +0,2 @@ | ||
import{Button as i,merge as t}from"@cosmograph/ui";import{getInternalApi as o}from"../../../cosmograph/internal.js";import{defaultCosmographButtonFitViewConfig as n}from"./config.js";class s{constructor(t,n,s){this._handleClick=()=>{var i,t;null===(t=(i=this._config).onClick)||void 0===t||t.call(i),this._internalApi.public.fitView(this._config.duration,this._config.padding)},this._internalApi=o(t),this._fitViewButton=new i(n),this.setConfig(null!=s?s:{})}setConfig(i){this._internalApi.cosmos&&(this._config=t(n,null!=i?i:{}),this._uiButtonConfig={...this._config,onClick:this._handleClick},this._fitViewButton.setConfig(this._uiButtonConfig))}remove(){this._fitViewButton.destroy()}}export{s as CosmographButtonFitView}; | ||
import{Button as i,merge as t}from"@cosmograph/ui";import{getInternalApi as n}from"../../../cosmograph/internal.js";import{defaultCosmographButtonFitViewConfig as o}from"./config.js";class s{constructor(t,o,s){this._handleClick=()=>{var i,t;null===(t=(i=this._config).onClick)||void 0===t||t.call(i),this._internalApi.public.fitView(this._config.duration,this._config.padding)},this._show=()=>{this._fitViewButton.show()},this._internalApi=n(t),this._fitViewButton=new i(o),this._internalApi.addEventListener("graphRebuilt",this._show),this.setConfig(null!=s?s:{})}setConfig(i){this._config=t(o,null!=i?i:{}),this._uiButtonConfig={...this._config,onClick:this._handleClick},this._fitViewButton.setConfig(this._uiButtonConfig)}remove(){this._fitViewButton.destroy(),this._internalApi.removeEventListener("graphRebuilt",this._show)}}export{s as CosmographButtonFitView}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import{Button as i,merge as n}from"@cosmograph/ui";import{getInternalApi as t}from"../../../cosmograph/internal.js";import{defaultCosmographButtonPlayPauseConfig as s}from"./config.js";import{playSVG as o,pauseSVG as e}from"./variables.js";class a{constructor(n,e,a){this._config=s,this._onSimulationEndHandler=()=>{this._update()},this._onCosmosInitializedHandler=()=>{this._update()},this._internalApi=t(n),this._playPauseButton=new i(e,{iconSvg:o}),this._internalApi.addEventListener("onSimulationEnd",this._onSimulationEndHandler),this._internalApi.addEventListener("cosmosInitialized",this._onCosmosInitializedHandler),this.setConfig(null!=a?a:{})}async setConfig(i){this._internalApi.cosmos&&(this._config=n(s,i),this._config.onClick=()=>{var n;null===(n=null==i?void 0:i.onClick)||void 0===n||n.call(i),this._internalApi.public.isSimulationRunning?this._internalApi.public.pause():1===this._internalApi.public.progress?this._internalApi.public.start():this._internalApi.public.restart(),this._update()},this._update())}remove(){this._playPauseButton.destroy(),this._internalApi.removeEventListener("onSimulationEnd",this._onSimulationEndHandler),this._internalApi.removeEventListener("cosmosInitialized",this._onCosmosInitializedHandler)}_update(){if(!this._internalApi.cosmos)return;!0===this._internalApi.cosmos.config.disableSimulation?this._playPauseButton.hide():this._playPauseButton.show(),this._config.iconSvg=this._internalApi.public.isSimulationRunning?e:o,this._playPauseButton.setConfig(this._config)}}export{a as CosmographButtonPlayPause}; | ||
import{Button as i,merge as t}from"@cosmograph/ui";import{getInternalApi as n}from"../../../cosmograph/internal.js";import{defaultCosmographButtonPlayPauseConfig as s}from"./config.js";import{playSVG as o,pauseSVG as e}from"./variables.js";class a{constructor(t,e,a){this._config=s,this._onSimulationEndHandler=()=>{this._update()},this._onCosmosInitializedHandler=()=>{this._update()},this._internalApi=n(t),this._playPauseButton=new i(e,{iconSvg:o}),this._internalApi.addEventListener("onSimulationEnd",this._onSimulationEndHandler),this._internalApi.addEventListener("graphRebuilt",this._onCosmosInitializedHandler),this.setConfig(null!=a?a:{})}async setConfig(i){this._config=t(s,i),this._config.onClick=()=>{var t;null===(t=null==i?void 0:i.onClick)||void 0===t||t.call(i),this._internalApi.public.isSimulationRunning?this._internalApi.public.pause():1===this._internalApi.public.progress?this._internalApi.public.start():this._internalApi.public.restart(),this._update()},this._update()}remove(){this._playPauseButton.destroy(),this._internalApi.removeEventListener("onSimulationEnd",this._onSimulationEndHandler),this._internalApi.removeEventListener("graphRebuilt",this._onCosmosInitializedHandler)}_update(){if(!this._internalApi.cosmos)return;!0===this._internalApi.cosmos.config.disableSimulation?this._playPauseButton.hide():this._playPauseButton.show(),this._config.iconSvg=this._internalApi.public.isSimulationRunning?e:o,this._playPauseButton.setConfig(this._config)}}export{a as CosmographButtonPlayPause}; | ||
//# sourceMappingURL=index.js.map |
@@ -11,3 +11,4 @@ import { Cosmograph } from "../../../cosmograph"; | ||
remove(): void; | ||
private _show; | ||
} | ||
export type { CosmographButtonSelectAreaConfigInterface }; |
@@ -1,2 +0,2 @@ | ||
import{merge as e,Button as t}from"@cosmograph/ui";import{getInternalApi as i}from"../../../cosmograph/internal.js";import{defaultCosmographButtonSelectAreaConfig as n}from"./config.js";class r{constructor(r,a,l){this._internalApi=i(r),this._config=e(n,l),this._config.onClick=()=>{var e;null===(e=null==l?void 0:l.onClick)||void 0===e||e.call(l),this._internalApi.public.activateRectSelection()},this._selectAreaButton=new t(a,this._config),this._areaSelectedHandler=()=>{this._internalApi.public.deactivateRectSelection()},this._internalApi.addEventListener("areaSelected",this._areaSelectedHandler)}setConfig(t){this._config=e(n,null!=t?t:{})}remove(){this._selectAreaButton.destroy(),this._internalApi.removeEventListener("areaSelected",this._areaSelectedHandler)}}export{r as CosmographButtonSelectArea}; | ||
import{merge as e,Button as t}from"@cosmograph/ui";import{getInternalApi as i}from"../../../cosmograph/internal.js";import{defaultCosmographButtonSelectAreaConfig as n}from"./config.js";class r{constructor(r,s,a){this._show=()=>{this._selectAreaButton.show()},this._internalApi=i(r),this._config=e(n,a),this._config.onClick=()=>{var e;null===(e=null==a?void 0:a.onClick)||void 0===e||e.call(a),this._internalApi.public.activateRectSelection()},this._selectAreaButton=new t(s,this._config),this._areaSelectedHandler=()=>{this._internalApi.public.deactivateRectSelection()},this._internalApi.addEventListener("graphRebuilt",this._show),this._internalApi.addEventListener("areaSelected",this._areaSelectedHandler)}setConfig(t){this._config=e(n,null!=t?t:{})}remove(){this._selectAreaButton.destroy(),this._internalApi.removeEventListener("graphRebuilt",this._show),this._internalApi.removeEventListener("areaSelected",this._areaSelectedHandler)}}export{r as CosmographButtonSelectArea}; | ||
//# sourceMappingURL=index.js.map |
@@ -15,3 +15,4 @@ import { Cosmograph } from "../../../cosmograph"; | ||
remove(): void; | ||
private _show; | ||
} | ||
export type { CosmographButtonZoomInOutConfigInterface }; |
@@ -1,2 +0,2 @@ | ||
import{Button as o,merge as t}from"@cosmograph/ui";import{getInternalApi as n}from"../../../cosmograph/internal.js";import{defaultCosmographButtonZoomInOutConfig as i}from"./config.js";import s from"./style.module.css.js";class m{constructor(t,i,m){this._internalApi=n(t),i.classList.add(s.zoomButtons),this._zoomInButtonDiv=document.createElement("div"),this._zoomInButtonDiv.classList.add(s.zoomButton,s.zoomInButton),this._zoomOutButtonDiv=document.createElement("div"),this._zoomOutButtonDiv.classList.add(s.zoomButton,s.zoomOutButton),i.appendChild(this._zoomInButtonDiv),i.appendChild(this._zoomOutButtonDiv),this._zoomInButton=new o(this._zoomInButtonDiv),this._zoomOutButton=new o(this._zoomOutButtonDiv),this.setConfig(null!=m?m:{})}setConfig(o){this._config=t(i,null!=o?o:{}),this._zoomInButtonConfig={onClick:()=>{var o,t,n;const s=this._internalApi.public.getZoomLevel();if(s){const t=null!==(o=this._config.zoomIncrement)&&void 0!==o?o:i.zoomIncrement;this._internalApi.public.setZoomLevel(s*t,this._config.duration)}null===(n=(t=this._config).onZoomInClick)||void 0===n||n.call(t)},iconSvg:this._config.zoomInIconSvg},this._zoomOutButtonConfig={onClick:()=>{var o,t,n;const s=this._internalApi.public.getZoomLevel();if(s){const t=null!==(o=this._config.zoomIncrement)&&void 0!==o?o:i.zoomIncrement;this._internalApi.public.setZoomLevel(s/t,this._config.duration)}null===(n=(t=this._config).onZoomOutClick)||void 0===n||n.call(t)},iconSvg:this._config.zoomOutIconSvg},this._zoomInButton.setConfig(this._zoomInButtonConfig),this._zoomOutButton.setConfig(this._zoomOutButtonConfig)}remove(){this._zoomInButton.destroy(),this._zoomOutButton.destroy()}}export{m as CosmographButtonZoomInOut}; | ||
import{Button as o,merge as t}from"@cosmograph/ui";import{getInternalApi as i}from"../../../cosmograph/internal.js";import{defaultCosmographButtonZoomInOutConfig as n}from"./config.js";import s from"./style.module.css.js";class e{constructor(t,n,e){this._show=()=>{this._zoomInButton.show(),this._zoomOutButton.show()},this._internalApi=i(t),n.classList.add(s.zoomButtons),this._zoomInButtonDiv=document.createElement("div"),this._zoomInButtonDiv.classList.add(s.zoomButton,s.zoomInButton),this._zoomOutButtonDiv=document.createElement("div"),this._zoomOutButtonDiv.classList.add(s.zoomButton,s.zoomOutButton),n.appendChild(this._zoomInButtonDiv),n.appendChild(this._zoomOutButtonDiv),this._zoomInButton=new o(this._zoomInButtonDiv),this._zoomOutButton=new o(this._zoomOutButtonDiv),this._internalApi.addEventListener("graphRebuilt",this._show),this.setConfig(null!=e?e:{})}setConfig(o){this._config=t(n,null!=o?o:{}),this._zoomInButtonConfig={onClick:()=>{var o,t,i;const s=this._internalApi.public.getZoomLevel();if(s){const t=null!==(o=this._config.zoomIncrement)&&void 0!==o?o:n.zoomIncrement;this._internalApi.public.setZoomLevel(s*t,this._config.duration)}null===(i=(t=this._config).onZoomInClick)||void 0===i||i.call(t)},iconSvg:this._config.zoomInIconSvg},this._zoomOutButtonConfig={onClick:()=>{var o,t,i;const s=this._internalApi.public.getZoomLevel();if(s){const t=null!==(o=this._config.zoomIncrement)&&void 0!==o?o:n.zoomIncrement;this._internalApi.public.setZoomLevel(s/t,this._config.duration)}null===(i=(t=this._config).onZoomOutClick)||void 0===i||i.call(t)},iconSvg:this._config.zoomOutIconSvg},this._zoomInButton.setConfig(this._zoomInButtonConfig),this._zoomOutButton.setConfig(this._zoomOutButtonConfig)}remove(){this._zoomInButton.destroy(),this._zoomOutButton.destroy(),this._internalApi.removeEventListener("graphRebuilt",this._show)}}export{e as CosmographButtonZoomInOut}; | ||
//# sourceMappingURL=index.js.map |
import type { HistogramConfigInterface, HistogramEvents } from '@cosmograph/ui'; | ||
export interface CosmographHistogramConfigInterface { | ||
/** | ||
* Data column key to access numeric values for the `CosmographHistogram`. Default: `'value'` | ||
* Data column key to access numeric values for the `CosmographHistogram`. Default: `undefined` | ||
*/ | ||
@@ -6,0 +6,0 @@ accessor?: string; |
@@ -1,2 +0,2 @@ | ||
const s={accessor:"value",useLinksData:!1,highlightCrossfiltered:!0};export{s as defaultCosmographHistogramConfig}; | ||
const s={accessor:void 0,useLinksData:!1,highlightCrossfiltered:!0};export{s as defaultCosmographHistogramConfig}; | ||
//# sourceMappingURL=config.js.map |
@@ -1,2 +0,2 @@ | ||
import{RangeColorLegend as i,merge as t}from"@cosmograph/ui";import{quantile as e,extent as n}from"d3-array";import{getInternalApi as s}from"../../../../cosmograph/internal.js";import{percentileMin as l,percentileMax as o}from"../../../../cosmograph/config/defaults.js";import{PointColorStrategy as a}from"../../../../cosmograph/strategies/point-color.js";import{defaultCosmographRangeColorLegendConfig as r}from"./config.js";import c from"./style.module.css.js";class h{constructor(t,e,n){this._config={},this._uiConfig={},this._initialized=!1,this._isInternalSelection=!1,this._onClick=(...i)=>{var t,e;null===(e=(t=this._config).onClick)||void 0===e||e.call(t,...i)},this._onHover=(...i)=>{var t,e;null===(e=(t=this._config).onHover)||void 0===e||e.call(t,...i)},this._onMaxClick=async(...i)=>{var t,e;null===(e=(t=this._config).onMaxClick)||void 0===e||e.call(t,...i),await this._selectOnClick(i[1])},this._onMinClick=async(...i)=>{var t,e;null===(e=(t=this._config).onMinClick)||void 0===e||e.call(t,...i),await this._selectOnClick(i[1],!0)},this._selectOnClick=async(i,t=!1)=>{var e,n,s,l,o,r,h;const{activePointColorStrategy:d}=this._internalApi.public;if(!i||!this._config.selectOnClick)return;if(d===a.Degree)return;const _=t?"min":"max",g=t?"max":"min";if(this._selected===_)null===(e=this._internalApi.selectionClient)||void 0===e||e.publish(void 0),null===(n=this._legend.extentElements)||void 0===n||n[_].classList.remove(c.selected),null===(s=this._legend.extentElements)||void 0===s||s[g].classList.remove(c.unselected),this._selected=void 0;else{if(null===(l=this._legend.extentElements)||void 0===l||l[_].classList.remove(c.unselected),null===(o=this._legend.extentElements)||void 0===o||o[_].classList.add(c.selected),null===(r=this._legend.extentElements)||void 0===r||r[g].classList.remove(c.selected),null===(h=this._legend.extentElements)||void 0===h||h[g].classList.add(c.unselected),this.accessor){let e;this._isInternalSelection=!0,e=this._config.useLinksData?(i,t,e)=>this._internalApi.public.getPointIndicesByLinksNumericValue(i,t,e):(i,t,e)=>this._internalApi.public.getPointIndicesByNumericValue(i,t,e),await e(this.accessor,i,!t).then((i=>{var t;null===(t=this._internalApi.selectionClient)||void 0===t||t.publish(i)}))}this._selected=_}},this._onColorUpdated=async()=>{await this._getExtent(),this._legend.setConfig({...this._config,...this._uiConfig})},this._internalApi=s(t),this._legend=new i(e),this._dataUpdatedHandler=()=>this._update,this._dataFilteredHandler=()=>this._resetAllSelections,this._linkColorUpdateHandler=async()=>{this._config.useLinksData&&await this._onColorUpdated()},this._pointColorUpdateHandler=async()=>{this._config.useLinksData||await this._onColorUpdated()},this._internalApi.addEventListener("dataUploaded",this._dataUpdatedHandler),this._internalApi.addEventListener("dataFiltered",this._dataFilteredHandler),this._internalApi.addEventListener("pointColorUpdated",this._pointColorUpdateHandler),this._internalApi.addEventListener("linkColorUpdated",this._linkColorUpdateHandler),this._initialize(n)}async _initialize(i){this._legend.setLoadingState(),await this.setConfig(i),this._initialized=!0}get accessor(){const{linkColorBy:i,pointColorBy:t}=this._internalApi.public.config;return this._config.useLinksData?i:t}async setConfig(i){const e=this._config;let n=!0;if(this._config=t(r,null!=i?i:{}),this._uiConfig.extent=this._config.overrideColors,this._config.overrideColors&&(this._uiConfig.enableEvents=(void 0!==this._config.onClick||void 0!==this._config.onMaxClick||void 0!==this._config.onMinClick)&&this._config.enableEvents),!this._config.overrideColors||this._config.overrideColors!==e.overrideColors||this._config.useLinksData!==e.useLinksData){this._config.useLinksData!==e.useLinksData&&this._resetAllSelections();n=!1!==await this._getExtent()}n&&this._legend.setConfig(this._createLegendConfig({...this._config,...this._uiConfig}))}async getConfig(){return this._config}hide(){this._legend.hide()}show(){this._legend.show()}remove(){this._legend.destroy(),this._internalApi.removeEventListener("dataUploaded",this._dataUpdatedHandler),this._internalApi.removeEventListener("dataFiltered",this._dataFilteredHandler),this._internalApi.removeEventListener("pointColorUpdated",this._pointColorUpdateHandler),this._internalApi.removeEventListener("linkColorUpdated",this._linkColorUpdateHandler)}async _update(){this._initialized&&this._internalApi.cosmos&&await this.setConfig()}_createLegendConfig(i){return{...i,events:{onClick:this._onClick.bind(this),onHover:this._onHover.bind(this),onMaxClick:this._onMaxClick.bind(this),onMinClick:this._onMinClick.bind(this)}}}async _getExtent(){if(this._initialized&&this._internalApi.cosmos){if(this._legend.setLoadingState(),await this._internalApi.configManager.configUpdated(),!this._config.overrideColors)return this._config.useLinksData?this._getLinksExtent():this._getPointsExtent();this._uiConfig.extentLabels=this._config.extentLabels}}async _getLinksExtent(){var i;const{public:{linksTableName:t,stats:e}}=this._internalApi,n=null===(i=e.linksSummary)||void 0===i?void 0:i.find((i=>i.column_name===this.accessor));if(!n)return;const s=await this._internalApi.public.getActiveLinkColorFn(),[l,o]=await this._calculateExtentValues(t,n);this._updateUIConfig(l,o,s)}async _getPointsExtent(){var i;const{public:{pointsTableName:t,activePointColorStrategy:e}}=this._internalApi;if(!this._internalApi.public.stats.pointsCount)return!1;if(e===a.Degree)return this._handleDegreeStrategy(this._config.enableEvents);{const e=null===(i=this._internalApi.public.stats.pointsSummary)||void 0===i?void 0:i.find((i=>i.column_name===this.accessor));if(!e)return;return this._handleDefaultStrategy(t,e)}}async _handleDegreeStrategy(i){const t=await this._internalApi.public.getActivePointColorFn(),[e,n]=this._getPointsDegreeExtent();this._updateUIConfig(e,n,t,void 0!==i&&i)}async _handleDefaultStrategy(i,t){const{public:{activePointColorStrategy:e}}=this._internalApi,[n,s]=await this._calculateExtentValues(i,t);if(e!==a.Map)if(e!==a.Direct)this._updateUIConfig(n,s,void 0,void 0,e===a.Palette);else{const i=await this._internalApi.public.getActivePointColorFn();this._updateUIConfig(n,s,i)}}_getPointsDegreeExtent(){const i=this._internalApi.public.pointDegrees;return(null==i?void 0:i.length)?this._config.useQuantiles?[e(i,l),e(i,o)]:n(i):[0,0]}_updateLabel(){var i;const t=this._internalApi.public.activePointColorStrategy===a.Degree?"connection count":this.accessor;this._uiConfig.label="function"==typeof this._config.label?this._config.label(t):null!==(i=this._config.label)&&void 0!==i?i:t}_updateUIConfig(i,t,e,n,s=!1){var l,o;this._uiConfig.discreteColors=s;const a=e?Array.from({length:this._config.steps},((n,s)=>{const l=i+s/(this._config.steps-1)*(t-i);return e(l)})).filter(Boolean):this._internalApi.public.config.pointColorPalette;this._updateLabel(),this._uiConfig.extent=(null==a?void 0:a.length)?a:void 0,this._uiConfig.extentLabels=null!==(l=this._config.extentLabels)&&void 0!==l?l:[i,t],this._uiConfig.showSublabels=null!==(o=this._config.showSublabels)&&void 0!==o?o:this._config.useQuantiles,this._uiConfig.enableEvents=void 0===n||n}async _calculateExtentValues(i,t){if(this._config.useQuantiles){const t=`\n SELECT \n quantile(${this.accessor}, ${l}) as min_quantile,\n quantile(${this.accessor}, ${o}) as max_quantile\n FROM ${i}\n `,e=await this._internalApi.dbCoordinator.query(t);if(e){const i=e.toArray()[0];return[i.min_quantile,i.max_quantile]}}return[+t.min,+t.max]}_resetAllSelections(){var i,t,e;this._initialized&&this._internalApi.cosmos&&(!this._isInternalSelection&&this._selected?(null===(i=this._internalApi.selectionClient)||void 0===i||i.publish(void 0),null===(t=this._legend.extentElements)||void 0===t||t.min.classList.remove(c.selected,c.unselected),null===(e=this._legend.extentElements)||void 0===e||e.max.classList.remove(c.selected,c.unselected),this._selected=void 0):this._isInternalSelection&&(this._isInternalSelection=!1))}}export{h as CosmographRangeColorLegend}; | ||
import{RangeColorLegend as i,merge as t}from"@cosmograph/ui";import{quantile as e,extent as n}from"d3-array";import{getInternalApi as s}from"../../../../cosmograph/internal.js";import{percentileMin as l,percentileMax as o}from"../../../../cosmograph/config/defaults.js";import{PointColorStrategy as a}from"../../../../cosmograph/strategies/point-color.js";import{defaultCosmographRangeColorLegendConfig as r}from"./config.js";import c from"./style.module.css.js";class h{constructor(t,e,n){this._config={},this._uiConfig={},this._initialized=!1,this._isInternalSelection=!1,this._onClick=(...i)=>{var t,e;null===(e=(t=this._config).onClick)||void 0===e||e.call(t,...i)},this._onHover=(...i)=>{var t,e;null===(e=(t=this._config).onHover)||void 0===e||e.call(t,...i)},this._onMaxClick=async(...i)=>{var t,e;null===(e=(t=this._config).onMaxClick)||void 0===e||e.call(t,...i),await this._selectOnClick(i[1])},this._onMinClick=async(...i)=>{var t,e;null===(e=(t=this._config).onMinClick)||void 0===e||e.call(t,...i),await this._selectOnClick(i[1],!0)},this._selectOnClick=async(i,t=!1)=>{var e,n,s,l,o,r,h;const{activePointColorStrategy:d}=this._internalApi.public;if(!i||!this._config.selectOnClick)return;if(d===a.Degree)return;const _=t?"min":"max",g=t?"max":"min";if(this._selected===_)null===(e=this._internalApi.selectionClient)||void 0===e||e.publish(void 0),null===(n=this._legend.extentElements)||void 0===n||n[_].classList.remove(c.selected),null===(s=this._legend.extentElements)||void 0===s||s[g].classList.remove(c.unselected),this._selected=void 0;else{if(null===(l=this._legend.extentElements)||void 0===l||l[_].classList.remove(c.unselected),null===(o=this._legend.extentElements)||void 0===o||o[_].classList.add(c.selected),null===(r=this._legend.extentElements)||void 0===r||r[g].classList.remove(c.selected),null===(h=this._legend.extentElements)||void 0===h||h[g].classList.add(c.unselected),this.accessor){let e;this._isInternalSelection=!0,e=this._config.useLinksData?(i,t,e)=>this._internalApi.public.getPointIndicesByLinksNumericValue(i,t,e):(i,t,e)=>this._internalApi.public.getPointIndicesByNumericValue(i,t,e),await e(this.accessor,i,!t).then((i=>{var t;null===(t=this._internalApi.selectionClient)||void 0===t||t.publish(i)}))}this._selected=_}},this._onColorUpdated=async()=>{await this._getExtent(),this._legend.setConfig({...this._config,...this._uiConfig})},this._internalApi=s(t),this._legend=new i(e),this._dataUpdatedHandler=()=>this._update,this._dataFilteredHandler=()=>this._resetAllSelections,this._linkColorUpdateHandler=async()=>{this._config.useLinksData&&await this._onColorUpdated()},this._pointColorUpdateHandler=async()=>{this._config.useLinksData||await this._onColorUpdated()},this._internalApi.addEventListener("dataUploaded",this._dataUpdatedHandler),this._internalApi.addEventListener("dataFiltered",this._dataFilteredHandler),this._internalApi.addEventListener("pointColorUpdated",this._pointColorUpdateHandler),this._internalApi.addEventListener("linkColorUpdated",this._linkColorUpdateHandler),this._initialize(n)}async _initialize(i){await this.setConfig(i),this._initialized=!0}get accessor(){const{linkColorBy:i,pointColorBy:t}=this._internalApi.config;return this._config.useLinksData?i:t}async setConfig(i){const e=this._config;let n=!0;if(this._config=t(r,null!=i?i:{}),this._uiConfig.extent=this._config.overrideColors,this._config.overrideColors&&(this._uiConfig.enableEvents=(void 0!==this._config.onClick||void 0!==this._config.onMaxClick||void 0!==this._config.onMinClick)&&this._config.enableEvents),!this._config.overrideColors||this._config.overrideColors!==e.overrideColors||this._config.useLinksData!==e.useLinksData){this._config.useLinksData!==e.useLinksData&&this._resetAllSelections();n=!1!==await this._getExtent()}n&&this._legend.setConfig(this._createLegendConfig({...this._config,...this._uiConfig}))}async getConfig(){return this._config}hide(){this._legend.hide()}show(){this._legend.show()}remove(){this._legend.destroy(),this._internalApi.removeEventListener("dataUploaded",this._dataUpdatedHandler),this._internalApi.removeEventListener("dataFiltered",this._dataFilteredHandler),this._internalApi.removeEventListener("pointColorUpdated",this._pointColorUpdateHandler),this._internalApi.removeEventListener("linkColorUpdated",this._linkColorUpdateHandler)}async _update(){this._initialized&&this._internalApi.cosmos&&await this.setConfig()}_createLegendConfig(i){return{...i,events:{onClick:this._onClick.bind(this),onHover:this._onHover.bind(this),onMaxClick:this._onMaxClick.bind(this),onMinClick:this._onMinClick.bind(this)}}}async _getExtent(){if(this._initialized&&this._internalApi.cosmos){if(this._legend.setLoadingState(),await this._internalApi.configManager.configUpdated(),!this._config.overrideColors)return this._config.useLinksData?this._getLinksExtent():this._getPointsExtent();this._uiConfig.extentLabels=this._config.extentLabels}}async _getLinksExtent(){var i;const{public:{linksTableName:t,stats:e}}=this._internalApi,n=null===(i=e.linksSummary)||void 0===i?void 0:i.find((i=>i.column_name===this.accessor));if(!n)return;const s=await this._internalApi.public.getActiveLinkColorFn(),[l,o]=await this._calculateExtentValues(t,n);this._updateUIConfig(l,o,s)}async _getPointsExtent(){var i;const{public:{pointsTableName:t,activePointColorStrategy:e}}=this._internalApi;if(!this._internalApi.public.stats.pointsCount)return!1;if(e===a.Degree)return this._handleDegreeStrategy(this._config.enableEvents);{const e=null===(i=this._internalApi.public.stats.pointsSummary)||void 0===i?void 0:i.find((i=>i.column_name===this.accessor));if(!e)return;return this._handleDefaultStrategy(t,e)}}async _handleDegreeStrategy(i){const t=await this._internalApi.public.getActivePointColorFn(),[e,n]=this._getPointsDegreeExtent();this._updateUIConfig(e,n,t,void 0!==i&&i)}async _handleDefaultStrategy(i,t){const{public:{activePointColorStrategy:e}}=this._internalApi,[n,s]=await this._calculateExtentValues(i,t);if(e!==a.Map)if(e!==a.Direct)this._updateUIConfig(n,s,void 0,void 0,e===a.Palette);else{const i=await this._internalApi.public.getActivePointColorFn();this._updateUIConfig(n,s,i)}}_getPointsDegreeExtent(){const i=this._internalApi.public.pointDegrees;return(null==i?void 0:i.length)?this._config.useQuantiles?[e(i,l),e(i,o)]:n(i):[0,0]}_updateLabel(){var i;const t=this._internalApi.public.activePointColorStrategy===a.Degree?"connection count":this.accessor;this._uiConfig.label="function"==typeof this._config.label?this._config.label(t):null!==(i=this._config.label)&&void 0!==i?i:t}_updateUIConfig(i,t,e,n,s=!1){var l,o;this._uiConfig.discreteColors=s;const a=e?Array.from({length:this._config.steps},((n,s)=>{const l=i+s/(this._config.steps-1)*(t-i);return e(l)})).filter(Boolean):this._internalApi.config.pointColorPalette;this._updateLabel(),this._uiConfig.extent=(null==a?void 0:a.length)?a:void 0,this._uiConfig.extentLabels=null!==(l=this._config.extentLabels)&&void 0!==l?l:[i,t],this._uiConfig.showSublabels=null!==(o=this._config.showSublabels)&&void 0!==o?o:this._config.useQuantiles,this._uiConfig.enableEvents=void 0===n||n}async _calculateExtentValues(i,t){if(this._config.useQuantiles){const t=`\n SELECT \n quantile(${this.accessor}, ${l}) as min_quantile,\n quantile(${this.accessor}, ${o}) as max_quantile\n FROM ${i}\n `,e=await this._internalApi.dbCoordinator.query(t);if(e){const i=e.toArray()[0];return[i.min_quantile,i.max_quantile]}}return[+t.min,+t.max]}_resetAllSelections(){var i,t,e;this._initialized&&this._internalApi.cosmos&&(!this._isInternalSelection&&this._selected?(null===(i=this._internalApi.selectionClient)||void 0===i||i.publish(void 0),null===(t=this._legend.extentElements)||void 0===t||t.min.classList.remove(c.selected,c.unselected),null===(e=this._legend.extentElements)||void 0===e||e.max.classList.remove(c.selected,c.unselected),this._selected=void 0):this._isInternalSelection&&(this._isInternalSelection=!1))}}export{h as CosmographRangeColorLegend}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import{TypeColorLegend as i,merge as t}from"@cosmograph/ui";import{getInternalApi as e}from"../../../../cosmograph/internal.js";import{checkColumnsExist as n}from"../../../../cosmograph/graph-utils/misc.js";import{PointColorStrategy as s}from"../../../../cosmograph/strategies/point-color.js";import{rgbaArrayToRgbString as o}from"../../../../cosmograph/graph-utils/colors.js";import{defaultCosmographTypeColorLegendConfig as a}from"./config.js";class l{constructor(t,n,s){this._config={},this._uiConfig={},this._initialized=!1,this._isInternalSelection=!1,this._onClick=async(...i)=>{var t,e;null===(e=(t=this._config).onClick)||void 0===e||e.call(t,...i),await this._selectOnClick(...i)},this._onHover=(...i)=>{var t,e;null===(e=(t=this._config).onHover)||void 0===e||e.call(t,...i)},this._selectOnClick=async(i,t)=>{var e,n;if(t&&this._config.selectOnClick)if((null===(e=this._selected)||void 0===e?void 0:e.label)===t.label)null===(n=this._internalApi.selectionClient)||void 0===n||n.publish(void 0),this._legend.setSelectedItem();else if(this._selected=t,this._legend.setSelectedItem(t),this.accessor){let i;this._isInternalSelection=!0,i=this._config.useLinksData?(i,t)=>this._internalApi.public.getPointIndicesByLinksExactValues(i,t):(i,t)=>this._internalApi.public.getPointIndicesByExactValues(i,t),await i(this.accessor,[t.label]).then((i=>{var t;null===(t=this._internalApi.selectionClient)||void 0===t||t.publish(i)}))}},this._internalApi=e(t),this._legend=new i(n),this._dataUpdatedHandler=()=>this._updateItems(!0),this._dataFilteredHandler=()=>this._resetAllSelections(),this._linkColorUpdateHandler=async()=>{this._config.useLinksData&&await this._updateItems(!1)},this._pointColorUpdateHandler=async()=>{this._config.useLinksData||await this._updateItems(!1)},this._internalApi.addEventListener("dataUploaded",this._dataUpdatedHandler),this._internalApi.addEventListener("dataFiltered",this._dataFilteredHandler),this._internalApi.addEventListener("pointColorUpdated",this._pointColorUpdateHandler),this._internalApi.addEventListener("linkColorUpdated",this._linkColorUpdateHandler),this._initialize(s)}async _initialize(i){this._legend.setLoadingState(),await this.setConfig(i),this._initialized=!0}get accessor(){const{linkColorBy:i,pointColorBy:t}=this._internalApi.public.config;return this._config.useLinksData?i:t}async setConfig(i){const e=this._config;let n=!0;if(this._config=t(a,null!=i?i:{}),this._config.overrideItems&&(this._uiConfig.enableEvents=void 0!==this._config.onClick&&this._config.enableEvents),!this._config.overrideItems||this._config.overrideItems!==e.overrideItems||this._config.useLinksData!==e.useLinksData){this._config.useLinksData!==e.useLinksData&&this._resetAllSelections();n=!1!==await this._getItems()}n&&(this._legend.setConfig(this._createLegendConfig({...this._config,...this._uiConfig})),this._checkCurrentSelection())}async getConfig(){return this._config}remove(){this._legend.destroy(),this._internalApi.removeEventListener("dataUploaded",this._dataUpdatedHandler),this._internalApi.removeEventListener("dataFiltered",this._dataFilteredHandler),this._internalApi.removeEventListener("pointColorUpdated",this._pointColorUpdateHandler),this._internalApi.removeEventListener("linkColorUpdated",this._linkColorUpdateHandler)}show(){this._legend.show()}hide(){this._legend.hide()}_createLegendConfig(i){return{...i,events:{onClick:this._onClick.bind(this),onHover:this._onHover.bind(this)}}}async _getItems(){if(!this._initialized||!this._internalApi.cosmos)return;if(this._config.overrideItems)return void(this._uiConfig.items=this._config.overrideItems);this._legend.setLoadingState(),await this._internalApi.configManager.configUpdated();const{linksTableName:i,pointsTableName:t,stats:e,config:o}=this._internalApi.public;if(!this.accessor||o.pointColorStrategy===s.Degree)return this._uiConfig.items=void 0,!1;const a=this._config.useLinksData?i:t,l=this._config.useLinksData?e.linksSummary:e.pointsSummary;if(!await n(this._internalApi.dbCoordinator,a,[this.accessor])||!l)return void(this._uiConfig.items=void 0);const r=await this._getDistinctValues(a,l);r&&await this._createAndSetLegendItems(r)}async _getDistinctValues(i,t){var e,n,o,a,l;const{public:{activePointColorStrategy:r}}=this._internalApi;let c="DESC";r!==s.InterpolatePalette&&r!==s.Palette||(c=null!==(e=this._config.sortOrder)&&void 0!==e?e:"DESC");const h=`ORDER BY "${null!==(n=this._config.sortBy)&&void 0!==n?n:"count"}" ${c}`,d=null===(o=t.find((i=>i.column_name===this.accessor)))||void 0===o?void 0:o.column_type,_=await(null===(a=this._internalApi.dbCoordinator)||void 0===a?void 0:a.query((t=>"VARCHAR"===t?`SELECT "${this.accessor}", COUNT(*) as count \n FROM ${i}\n GROUP BY "${this.accessor}"\n ${h}`:`SELECT DISTINCT "${this.accessor}"\n FROM ${i}\n ORDER BY "${this.accessor}" ${this._config.sortOrder||c}`)(d)));return(null==_?void 0:_.numRows)?null===(l=_.getChildAt(0))||void 0===l?void 0:l.toArray():null}async _createAndSetLegendItems(i){var t,e;const{public:{activePointColorStrategy:n,config:a}}=this._internalApi;let l;if(l=this._config.useLinksData?await this._internalApi.public.getActiveLinkColorFn():await this._internalApi.public.getActivePointColorFn(),l){const r=i=>({color:o(l(i)),label:String(i)});if(n===s.Map){const n=new Set(null!==(e=null===(t=a.pointColorByMap)||void 0===t?void 0:t.map((i=>i[0])))&&void 0!==e?e:[]),s=Array.from(i.filter((i=>n.has(i))),r),o=this._config.hideUnknown?[]:Array.from(i.filter((i=>!n.has(i))),r);this._uiConfig.items=[...s,...o]}else this._uiConfig.items=Array.from(i,r)}}async _updateItems(i=!1){var t;this._initialized&&this._internalApi.cosmos&&(i&&this._resetAllSelections(),await this._getItems(),!this._selected&&(null===(t=this._uiConfig.items)||void 0===t?void 0:t.length)&&this._legend.resetList(),this._legend.setConfig(this._createLegendConfig({...this._config,...this._uiConfig})))}_resetAllSelections(){var i;!this._isInternalSelection&&this._selected?(null===(i=this._internalApi.selectionClient)||void 0===i||i.publish(void 0),this._selected=void 0,this._legend.setSelectedItem()):this._isInternalSelection&&(this._isInternalSelection=!1)}_checkCurrentSelection(){this._selected&&this._legend.setSelectedItem(this._selected)}}export{l as CosmographTypeColorLegend}; | ||
import{TypeColorLegend as i,merge as t}from"@cosmograph/ui";import{getInternalApi as e}from"../../../../cosmograph/internal.js";import{checkColumnsExist as n}from"../../../../cosmograph/graph-utils/misc.js";import{PointColorStrategy as s}from"../../../../cosmograph/strategies/point-color.js";import{rgbaArrayToRgbString as o}from"../../../../cosmograph/graph-utils/colors.js";import{defaultCosmographTypeColorLegendConfig as a}from"./config.js";class l{constructor(t,n,s){this._config={},this._uiConfig={},this._initialized=!1,this._isInternalSelection=!1,this._onClick=async(...i)=>{var t,e;null===(e=(t=this._config).onClick)||void 0===e||e.call(t,...i),await this._selectOnClick(...i)},this._onHover=(...i)=>{var t,e;null===(e=(t=this._config).onHover)||void 0===e||e.call(t,...i)},this._selectOnClick=async(i,t)=>{var e,n;if(t&&this._config.selectOnClick)if((null===(e=this._selected)||void 0===e?void 0:e.label)===t.label)null===(n=this._internalApi.selectionClient)||void 0===n||n.publish(void 0),this._legend.setSelectedItem();else if(this._selected=t,this._legend.setSelectedItem(t),this.accessor){let i;this._isInternalSelection=!0,i=this._config.useLinksData?(i,t)=>this._internalApi.public.getPointIndicesByLinksExactValues(i,t):(i,t)=>this._internalApi.public.getPointIndicesByExactValues(i,t),await i(this.accessor,[t.label]).then((i=>{var t;null===(t=this._internalApi.selectionClient)||void 0===t||t.publish(i)}))}},this._internalApi=e(t),this._legend=new i(n),this._dataUpdatedHandler=()=>this._updateItems(!0),this._dataFilteredHandler=()=>this._resetAllSelections(),this._linkColorUpdateHandler=async()=>{this._config.useLinksData&&await this._updateItems(!1)},this._pointColorUpdateHandler=async()=>{this._config.useLinksData||await this._updateItems(!1)},this._internalApi.addEventListener("dataUploaded",this._dataUpdatedHandler),this._internalApi.addEventListener("dataFiltered",this._dataFilteredHandler),this._internalApi.addEventListener("pointColorUpdated",this._pointColorUpdateHandler),this._internalApi.addEventListener("linkColorUpdated",this._linkColorUpdateHandler),this._initialize(s)}async _initialize(i){await this.setConfig(i),this._initialized=!0}get accessor(){const{linkColorBy:i,pointColorBy:t}=this._internalApi.config;return this._config.useLinksData?i:t}async setConfig(i){const e=this._config;let n=!0;if(this._config=t(a,null!=i?i:{}),this._config.overrideItems&&(this._uiConfig.enableEvents=void 0!==this._config.onClick&&this._config.enableEvents),!this._config.overrideItems||this._config.overrideItems!==e.overrideItems||this._config.useLinksData!==e.useLinksData){this._config.useLinksData!==e.useLinksData&&this._resetAllSelections();n=!1!==await this._getItems()}n&&(this._legend.setConfig(this._createLegendConfig({...this._config,...this._uiConfig})),this._checkCurrentSelection())}async getConfig(){return this._config}remove(){this._legend.destroy(),this._internalApi.removeEventListener("dataUploaded",this._dataUpdatedHandler),this._internalApi.removeEventListener("dataFiltered",this._dataFilteredHandler),this._internalApi.removeEventListener("pointColorUpdated",this._pointColorUpdateHandler),this._internalApi.removeEventListener("linkColorUpdated",this._linkColorUpdateHandler)}show(){this._legend.show()}hide(){this._legend.hide()}_createLegendConfig(i){return{...i,events:{onClick:this._onClick.bind(this),onHover:this._onHover.bind(this)}}}async _getItems(){if(!this._initialized||!this._internalApi.cosmos)return;if(this._config.overrideItems)return void(this._uiConfig.items=this._config.overrideItems);this._legend.setLoadingState(),await this._internalApi.configManager.configUpdated();const{pointColorStrategy:i}=this._internalApi.config,{linksTableName:t,pointsTableName:e,stats:o}=this._internalApi.public;if(!this.accessor||i===s.Degree)return this._uiConfig.items=void 0,!1;const a=this._config.useLinksData?t:e,l=this._config.useLinksData?o.linksSummary:o.pointsSummary;if(!await n(this._internalApi.dbCoordinator,a,[this.accessor])||!l)return void(this._uiConfig.items=void 0);const r=await this._getDistinctValues(a,l);r&&await this._createAndSetLegendItems(r)}async _getDistinctValues(i,t){var e,n,o,a,l;const{public:{activePointColorStrategy:r}}=this._internalApi;let h="DESC";r!==s.InterpolatePalette&&r!==s.Palette||(h=null!==(e=this._config.sortOrder)&&void 0!==e?e:"DESC");const c=`ORDER BY "${null!==(n=this._config.sortBy)&&void 0!==n?n:"count"}" ${h}`,d=null===(o=t.find((i=>i.column_name===this.accessor)))||void 0===o?void 0:o.column_type,_=await(null===(a=this._internalApi.dbCoordinator)||void 0===a?void 0:a.query((t=>"VARCHAR"===t?`SELECT "${this.accessor}", COUNT(*) as count \n FROM ${i}\n GROUP BY "${this.accessor}"\n ${c}`:`SELECT DISTINCT "${this.accessor}"\n FROM ${i}\n ORDER BY "${this.accessor}" ${this._config.sortOrder||h}`)(d)));return(null==_?void 0:_.numRows)?null===(l=_.getChildAt(0))||void 0===l?void 0:l.toArray():null}async _createAndSetLegendItems(i){var t,e;const{public:{activePointColorStrategy:n},config:a}=this._internalApi;let l;if(l=this._config.useLinksData?await this._internalApi.public.getActiveLinkColorFn():await this._internalApi.public.getActivePointColorFn(),l){const r=i=>({color:o(l(i)),label:String(i)});if(n===s.Map){const n=new Set(null!==(e=null===(t=a.pointColorByMap)||void 0===t?void 0:t.map((i=>i[0])))&&void 0!==e?e:[]),s=Array.from(i.filter((i=>n.has(i))),r),o=this._config.hideUnknown?[]:Array.from(i.filter((i=>!n.has(i))),r);this._uiConfig.items=[...s,...o]}else this._uiConfig.items=Array.from(i,r)}}async _updateItems(i=!1){var t;this._initialized&&this._internalApi.cosmos&&(i&&this._resetAllSelections(),await this._getItems(),!this._selected&&(null===(t=this._uiConfig.items)||void 0===t?void 0:t.length)&&this._legend.resetList(),this._legend.setConfig(this._createLegendConfig({...this._config,...this._uiConfig})))}_resetAllSelections(){var i;!this._isInternalSelection&&this._selected?(null===(i=this._internalApi.selectionClient)||void 0===i||i.publish(void 0),this._selected=void 0,this._legend.setSelectedItem()):this._isInternalSelection&&(this._isInternalSelection=!1)}_checkCurrentSelection(){this._selected&&this._legend.setSelectedItem(this._selected)}}export{l as CosmographTypeColorLegend}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import{quantile as i,extent as t}from"d3-array";import{SizeLegend as e,merge as n}from"@cosmograph/ui";import{getInternalApi as s}from"../../../cosmograph/internal.js";import{defaultLinkWidthRange as a,defaultPointSizeRange as l,percentileMin as o,percentileMax as h}from"../../../cosmograph/config/defaults.js";import{PointSizeStrategy as d}from"../../../cosmograph/strategies/point-size.js";import{defaultCosmographSizeLegendConfig as c}from"./config.js";import _ from"./style.module.css.js";class r{constructor(i,t,n){this._config={},this._uiConfig={},this._isInternalSelection=!1,this._manuallyHidden=!1,this._initialized=!1,this._originalMaxValue=0,this._onClick=(...i)=>{var t,e;null===(e=(t=this._config).onClick)||void 0===e||e.call(t,...i)},this._onHover=(...i)=>{var t,e;null===(e=(t=this._config).onHover)||void 0===e||e.call(t,...i)},this._onMaxClick=async(...i)=>{var t,e;null===(e=(t=this._config).onMaxClick)||void 0===e||e.call(t,...i),await this._selectOnClick(i[1])},this._onMinClick=async(...i)=>{var t,e;null===(e=(t=this._config).onMinClick)||void 0===e||e.call(t,...i),await this._selectOnClick(i[1],!0)},this._selectOnClick=async(i,t=!1)=>{var e,n,s,a,l,o,h;if(!i||!this._config.selectOnClick)return;const d=t?"min":"max",c=t?"max":"min";if(this._selected===d)null===(e=this._internalApi.selectionClient)||void 0===e||e.publish(void 0),null===(n=this._legend.sizeElements)||void 0===n||n[d].classList.remove(_.selected),null===(s=this._legend.sizeElements)||void 0===s||s[c].classList.remove(_.unselected),this._selected=void 0;else{if(null===(a=this._legend.sizeElements)||void 0===a||a[d].classList.remove(_.unselected),null===(l=this._legend.sizeElements)||void 0===l||l[d].classList.add(_.selected),null===(o=this._legend.sizeElements)||void 0===o||o[c].classList.remove(_.selected),null===(h=this._legend.sizeElements)||void 0===h||h[c].classList.add(_.unselected),this.accessor){let e;this._isInternalSelection=!0,e=this._config.useLinksData?(i,t,e)=>this._internalApi.public.getPointIndicesByLinksNumericValue(i,t,e):(i,t,e)=>this._internalApi.public.getPointIndicesByNumericValue(i,t,e),await e(this.accessor,i,!t).then((i=>{var t;null===(t=this._internalApi.selectionClient)||void 0===t||t.publish(i)}))}this._selected=d}},this._onSizeScaleUpdated=async()=>{this._initialized&&this._uiConfig.extent&&(await this._updateSizeMultiplier(),this._updateLegendVisibility(),this._legend.setConfig({...this._config,...this._uiConfig}))},this._onSizeUpdated=async()=>{await this._getExtent(),await this._onSizeScaleUpdated()},this._internalApi=s(i),this._legend=new e(t),this._dataUpdatedHandler=()=>this._update(),this._dataFilteredHandler=()=>this._resetAllSelections(),this._pointSizeScaleUpdateHandler=async()=>{this._config.useLinksData||await this._onSizeScaleUpdated()},this._linkWidthScaleUpdateHandler=async()=>{this._config.useLinksData&&await this._onSizeScaleUpdated()},this._pointSizeUpdateHandler=async()=>{this._config.useLinksData||await this._onSizeUpdated()},this._linkWidthUpdateHandler=async()=>{this._config.useLinksData&&await this._onSizeUpdated()},this._internalApi.addEventListener("dataFiltered",this._dataFilteredHandler),this._internalApi.addEventListener("dataUploaded",this._dataUpdatedHandler),this._internalApi.addEventListener("pointSizeScaleUpdated",this._pointSizeScaleUpdateHandler),this._internalApi.addEventListener("linkWidthScaleUpdated",this._linkWidthScaleUpdateHandler),this._internalApi.addEventListener("pointSizeUpdated",this._pointSizeUpdateHandler),this._internalApi.addEventListener("linkWidthUpdated",this._linkWidthUpdateHandler),this._initialize(n)}async _initialize(i){this._legend.setLoadingState(),await this.setConfig(i),this._initialized=!0}get accessor(){const{linkWidthBy:i,pointSizeBy:t}=this._internalApi.public.config;return this._config.useLinksData?i:t}async setConfig(i){const t=this._config;let e=!0;if(this._config=n(c,null!=i?i:{}),this._uiConfig.extent=this._config.overrideExtent,this._config.overrideExtent&&(this._uiConfig.enableEvents=(void 0!==this._config.onClick||void 0!==this._config.onMaxClick||void 0!==this._config.onMinClick)&&this._config.enableEvents),!this._config.overrideExtent||this._config.overrideExtent!==t.overrideExtent||this._config.useLinksData!==t.useLinksData){this._config.useLinksData!==t.useLinksData&&this._resetAllSelections();e=!1!==await this._getExtent()}e&&(await this._updateSizeMultiplier(),this._uiConfig.form=this._config.useLinksData?"line":"point",this._config.useLinksData!==t.useLinksData&&this._updateLegendVisibility(),this._legend.setConfig(this._createLegendConfig({...this._config,...this._uiConfig})))}async getConfig(){return this._config}remove(){this._legend.destroy(),this._internalApi.removeEventListener("dataFiltered",this._dataFilteredHandler),this._internalApi.removeEventListener("dataUploaded",this._dataUpdatedHandler),this._internalApi.removeEventListener("pointSizeScaleUpdated",this._pointSizeScaleUpdateHandler),this._internalApi.removeEventListener("linkWidthScaleUpdated",this._linkWidthScaleUpdateHandler),this._internalApi.removeEventListener("pointSizeUpdated",this._pointSizeUpdateHandler),this._internalApi.removeEventListener("linkWidthUpdated",this._linkWidthUpdateHandler)}hide(){this._manuallyHidden=!0,this._legend.hide()}show(){this._manuallyHidden=!1,this._legend.show()}async _update(){this._initialized&&(await this.setConfig(this._config),await this._onSizeUpdated())}_createLegendConfig(i){return{...i,events:{onClick:this._onClick.bind(this),onHover:this._onHover.bind(this),onMaxClick:this._onMaxClick.bind(this),onMinClick:this._onMinClick.bind(this)}}}async _getExtent(){if(this._initialized&&this._internalApi.cosmos){if(this._legend.setLoadingState(),await this._internalApi.configManager.configUpdated(),!this._config.overrideExtent)return this._config.useLinksData?this._getLinksExtent():this._getPointsExtent();this._uiConfig.extentLabels=this._config.extentLabels}}async _getLinksExtent(){var i;const{public:{config:t,linksTableName:e,stats:n}}=this._internalApi,s=null===(i=n.linksSummary)||void 0===i?void 0:i.find((i=>i.column_name===this.accessor));if(!s)return;const[l,o]=await this._calculateExtentValues(e,s);let h=[l,o];if(t.linkWidthByFn){const i=await this._getMappingFunction();i&&(h=h.map((t=>+i(t))))}else h=t.linkWidthRange||a;this._updateUIConfig(l,o,h)}async _getPointsExtent(){var i;const{public:{config:t,pointsTableName:e,stats:n,activePointSizeStrategy:s}}=this._internalApi,a=null===(i=n.pointsSummary)||void 0===i?void 0:i.find((i=>i.column_name===this.accessor));if(!n.pointsCount&&!a)return!1;let o,h,c,_=this._config.enableEvents;if(s===d.Degree)o=await this._internalApi.public.getActivePointSizeFn(),h=this._getPointsDegreeExtent(),_=!1;else{if(!a)return;h=await this._calculateExtentValues(e,a),t.pointSizeByFn&&t.pointSizeStrategy!==d.Auto?o=await this._getMappingFunction():c=s===d.Direct?h:t.pointSizeRange||l}c||(c=h.map((i=>o?+o(i):i))),this._updateUIConfig(h[0],h[1],c,_)}_getPointsDegreeExtent(){const e=this._internalApi.public.pointDegrees;return(null==e?void 0:e.length)?this._config.useQuantiles?[i(e,o),i(e,h)]:t(e):[0,0]}async _calculateExtentValues(i,t){if(this._config.useQuantiles){const t=`\n SELECT \n quantile(${this.accessor}, ${o}) as min_quantile,\n quantile(${this.accessor}, ${h}) as max_quantile\n FROM ${i}\n `,e=await this._internalApi.dbCoordinator.query(t);if(e){const i=e.toArray()[0];return[i.min_quantile,i.max_quantile]}}return[t.min,t.max]}_updateLabel(){var i;const t=this._internalApi.public.activePointSizeStrategy===d.Degree?"connection count":this.accessor;this._uiConfig.label="function"==typeof this._config.label?this._config.label(t):null!==(i=this._config.label)&&void 0!==i?i:t}_updateUIConfig(i,t,e,n){var s;this._updateLabel(),this._originalMaxValue=+t,this._uiConfig.extent=e.filter(Boolean).length?e:void 0,this._uiConfig.extentLabels=null!==(s=this._config.extentLabels)&&void 0!==s?s:[+i,+t],this._uiConfig.showSublabels=void 0!==this._config.showSublabels?this._config.showSublabels:this._config.useQuantiles,this._uiConfig.enableEvents=void 0===n||n}_resetAllSelections(){var i,t,e;this._initialized&&this._internalApi.cosmos&&(!this._isInternalSelection&&this._selected?(null===(i=this._internalApi.selectionClient)||void 0===i||i.publish(void 0),null===(t=this._legend.sizeElements)||void 0===t||t.min.classList.remove(_.selected,_.unselected),null===(e=this._legend.sizeElements)||void 0===e||e.max.classList.remove(_.selected,_.unselected),this._selected=void 0):this._isInternalSelection&&(this._isInternalSelection=!1))}async _getMappingFunction(){return this._config.useLinksData?await this._internalApi.public.getActiveLinkWidthFn():await this._internalApi.public.getActivePointSizeFn()}async _calcVisibleMaxLabel(i,t,e){const n=await this._getMappingFunction();if(n){const s=i/n(1),a=Math.min(Math.abs(e),Math.max(Math.abs(t),Math.abs(s))),l=Math.sign(e)*a;return Number(l.toFixed(0))}return 0}async _updateMaxLabel(){if(this._internalApi.public.config.pointSizeByFn&&this._uiConfig.extentLabels&&!this._legend.isHidden&&this._uiConfig.sizeMultiplier){const i=await this._calcVisibleMaxLabel(this._internalApi.public.maxPointSize/this._uiConfig.sizeMultiplier,this._uiConfig.extentLabels[0],this._originalMaxValue);this._uiConfig.extentLabels=[this._uiConfig.extentLabels[0],i]}}async _updateSizeMultiplier(){var i,t,e,n;const{config:s}=this._internalApi.public,a=null!==(i=this._internalApi.public.getZoomLevel())&&void 0!==i?i:1;this._config.useLinksData?this._uiConfig.sizeMultiplier=null!==(t=s.linkWidthScale)&&void 0!==t?t:1:!1!==s.scalePointsOnZoom&&this._config.dynamicPointSize?(this._uiConfig.sizeMultiplier=(null!==(n=s.pointSizeScale)&&void 0!==n?n:1)*a,await this._updateMaxLabel()):this._uiConfig.sizeMultiplier=null!==(e=s.pointSizeScale)&&void 0!==e?e:1}_updateLegendVisibility(){var i,t;if(this._uiConfig.extent){const e=(null!==(t=null===(i=this._uiConfig)||void 0===i?void 0:i.sizeMultiplier)&&void 0!==t?t:1)*this._uiConfig.extent[1];this._config.hideWhenSizeMoreThan&&this._config.hideWhenSizeMoreThan<e?this._legend.hide():this._manuallyHidden||this._legend.show()}}}export{r as CosmographSizeLegend}; | ||
import{quantile as i,extent as t}from"d3-array";import{SizeLegend as e,merge as n}from"@cosmograph/ui";import{getInternalApi as s}from"../../../cosmograph/internal.js";import{defaultLinkWidthRange as a,defaultPointSizeRange as l,percentileMin as o,percentileMax as h}from"../../../cosmograph/config/defaults.js";import{PointSizeStrategy as d}from"../../../cosmograph/strategies/point-size.js";import{defaultCosmographSizeLegendConfig as c}from"./config.js";import _ from"./style.module.css.js";class r{constructor(i,t,n){this._config={},this._uiConfig={},this._isInternalSelection=!1,this._manuallyHidden=!1,this._initialized=!1,this._originalMaxValue=0,this._onClick=(...i)=>{var t,e;null===(e=(t=this._config).onClick)||void 0===e||e.call(t,...i)},this._onHover=(...i)=>{var t,e;null===(e=(t=this._config).onHover)||void 0===e||e.call(t,...i)},this._onMaxClick=async(...i)=>{var t,e;null===(e=(t=this._config).onMaxClick)||void 0===e||e.call(t,...i),await this._selectOnClick(i[1])},this._onMinClick=async(...i)=>{var t,e;null===(e=(t=this._config).onMinClick)||void 0===e||e.call(t,...i),await this._selectOnClick(i[1],!0)},this._selectOnClick=async(i,t=!1)=>{var e,n,s,a,l,o,h;if(!i||!this._config.selectOnClick)return;const d=t?"min":"max",c=t?"max":"min";if(this._selected===d)null===(e=this._internalApi.selectionClient)||void 0===e||e.publish(void 0),null===(n=this._legend.sizeElements)||void 0===n||n[d].classList.remove(_.selected),null===(s=this._legend.sizeElements)||void 0===s||s[c].classList.remove(_.unselected),this._selected=void 0;else{if(null===(a=this._legend.sizeElements)||void 0===a||a[d].classList.remove(_.unselected),null===(l=this._legend.sizeElements)||void 0===l||l[d].classList.add(_.selected),null===(o=this._legend.sizeElements)||void 0===o||o[c].classList.remove(_.selected),null===(h=this._legend.sizeElements)||void 0===h||h[c].classList.add(_.unselected),this.accessor){let e;this._isInternalSelection=!0,e=this._config.useLinksData?(i,t,e)=>this._internalApi.public.getPointIndicesByLinksNumericValue(i,t,e):(i,t,e)=>this._internalApi.public.getPointIndicesByNumericValue(i,t,e),await e(this.accessor,i,!t).then((i=>{var t;null===(t=this._internalApi.selectionClient)||void 0===t||t.publish(i)}))}this._selected=d}},this._onSizeScaleUpdated=async()=>{this._initialized&&this._uiConfig.extent&&(await this._updateSizeMultiplier(),this._updateLegendVisibility(),this._legend.setConfig({...this._config,...this._uiConfig}))},this._onSizeUpdated=async()=>{await this._getExtent(),await this._onSizeScaleUpdated()},this._internalApi=s(i),this._legend=new e(t),this._dataUpdatedHandler=()=>this._update(),this._dataFilteredHandler=()=>this._resetAllSelections(),this._pointSizeScaleUpdateHandler=async()=>{this._config.useLinksData||await this._onSizeScaleUpdated()},this._linkWidthScaleUpdateHandler=async()=>{this._config.useLinksData&&await this._onSizeScaleUpdated()},this._pointSizeUpdateHandler=async()=>{this._config.useLinksData||await this._onSizeUpdated()},this._linkWidthUpdateHandler=async()=>{this._config.useLinksData&&await this._onSizeUpdated()},this._internalApi.addEventListener("dataFiltered",this._dataFilteredHandler),this._internalApi.addEventListener("dataUploaded",this._dataUpdatedHandler),this._internalApi.addEventListener("pointSizeScaleUpdated",this._pointSizeScaleUpdateHandler),this._internalApi.addEventListener("linkWidthScaleUpdated",this._linkWidthScaleUpdateHandler),this._internalApi.addEventListener("pointSizeUpdated",this._pointSizeUpdateHandler),this._internalApi.addEventListener("linkWidthUpdated",this._linkWidthUpdateHandler),this._initialize(n)}async _initialize(i){await this.setConfig(i),this._initialized=!0}get accessor(){const{linkWidthBy:i,pointSizeBy:t}=this._internalApi.config;return this._config.useLinksData?i:t}async setConfig(i){const t=this._config;let e=!0;if(this._config=n(c,null!=i?i:{}),this._uiConfig.extent=this._config.overrideExtent,this._config.overrideExtent&&(this._uiConfig.enableEvents=(void 0!==this._config.onClick||void 0!==this._config.onMaxClick||void 0!==this._config.onMinClick)&&this._config.enableEvents),!this._config.overrideExtent||this._config.overrideExtent!==t.overrideExtent||this._config.useLinksData!==t.useLinksData){this._config.useLinksData!==t.useLinksData&&this._resetAllSelections();e=!1!==await this._getExtent()}e&&(await this._updateSizeMultiplier(),this._uiConfig.form=this._config.useLinksData?"line":"point",this._config.useLinksData!==t.useLinksData&&this._updateLegendVisibility(),this._legend.setConfig(this._createLegendConfig({...this._config,...this._uiConfig})))}async getConfig(){return this._config}remove(){this._legend.destroy(),this._internalApi.removeEventListener("dataFiltered",this._dataFilteredHandler),this._internalApi.removeEventListener("dataUploaded",this._dataUpdatedHandler),this._internalApi.removeEventListener("pointSizeScaleUpdated",this._pointSizeScaleUpdateHandler),this._internalApi.removeEventListener("linkWidthScaleUpdated",this._linkWidthScaleUpdateHandler),this._internalApi.removeEventListener("pointSizeUpdated",this._pointSizeUpdateHandler),this._internalApi.removeEventListener("linkWidthUpdated",this._linkWidthUpdateHandler)}hide(){this._manuallyHidden=!0,this._legend.hide()}show(){this._manuallyHidden=!1,this._legend.show()}async _update(){this._initialized&&(await this.setConfig(this._config),await this._onSizeUpdated())}_createLegendConfig(i){return{...i,events:{onClick:this._onClick.bind(this),onHover:this._onHover.bind(this),onMaxClick:this._onMaxClick.bind(this),onMinClick:this._onMinClick.bind(this)}}}async _getExtent(){if(this._initialized&&this._internalApi.cosmos){if(this._legend.setLoadingState(),await this._internalApi.configManager.configUpdated(),!this._config.overrideExtent)return this._config.useLinksData?this._getLinksExtent():this._getPointsExtent();this._uiConfig.extentLabels=this._config.extentLabels}}async _getLinksExtent(){var i;const{config:t,public:{linksTableName:e,stats:n}}=this._internalApi,s=null===(i=n.linksSummary)||void 0===i?void 0:i.find((i=>i.column_name===this.accessor));if(!t.linkWidthBy||!s)return void this._legend.setConfig({...this._config,...this._uiConfig,extent:void 0});const[l,o]=await this._calculateExtentValues(e,s);let h=[l,o];if(t.linkWidthByFn){const i=await this._getMappingFunction();i&&(h=h.map((t=>+i(t))))}else h=t.linkWidthRange||a;this._updateUIConfig(l,o,h)}async _getPointsExtent(){var i;const{config:t,public:{pointsTableName:e,stats:n,activePointSizeStrategy:s}}=this._internalApi,a=null===(i=n.pointsSummary)||void 0===i?void 0:i.find((i=>i.column_name===this.accessor));if(s!==d.Degree&&(!t.pointSizeBy||!n.pointsCount&&!a))return void this._legend.setConfig({...this._config,...this._uiConfig,extent:void 0});let o,h,c,_=this._config.enableEvents;if(s===d.Degree)o=await this._internalApi.public.getActivePointSizeFn(),h=this._getPointsDegreeExtent(),_=!1;else{if(!a)return;h=await this._calculateExtentValues(e,a),t.pointSizeByFn&&t.pointSizeStrategy!==d.Auto?o=await this._getMappingFunction():c=s===d.Direct?h:t.pointSizeRange||l}c||(c=h.map((i=>o?+o(i):i))),this._updateUIConfig(h[0],h[1],c,_)}_getPointsDegreeExtent(){const e=this._internalApi.public.pointDegrees;return(null==e?void 0:e.length)?this._config.useQuantiles?[i(e,o),i(e,h)]:t(e):[0,0]}async _calculateExtentValues(i,t){if(this._config.useQuantiles){const t=`\n SELECT \n quantile(${this.accessor}, ${o}) as min_quantile,\n quantile(${this.accessor}, ${h}) as max_quantile\n FROM ${i}\n `,e=await this._internalApi.dbCoordinator.query(t);if(e){const i=e.toArray()[0];return[i.min_quantile,i.max_quantile]}}return[t.min,t.max]}_updateLabel(){var i;const t=this._internalApi.public.activePointSizeStrategy===d.Degree?"connection count":this.accessor;this._uiConfig.label="function"==typeof this._config.label?this._config.label(t):null!==(i=this._config.label)&&void 0!==i?i:t}_updateUIConfig(i,t,e,n){var s;this._updateLabel(),this._originalMaxValue=+t,this._uiConfig.extent=e.filter(Boolean).length?e:void 0,this._uiConfig.extentLabels=null!==(s=this._config.extentLabels)&&void 0!==s?s:[+i,+t],this._uiConfig.showSublabels=void 0!==this._config.showSublabels?this._config.showSublabels:this._config.useQuantiles,this._uiConfig.enableEvents=void 0===n||n}_resetAllSelections(){var i,t,e;this._initialized&&this._internalApi.cosmos&&(!this._isInternalSelection&&this._selected?(null===(i=this._internalApi.selectionClient)||void 0===i||i.publish(void 0),null===(t=this._legend.sizeElements)||void 0===t||t.min.classList.remove(_.selected,_.unselected),null===(e=this._legend.sizeElements)||void 0===e||e.max.classList.remove(_.selected,_.unselected),this._selected=void 0):this._isInternalSelection&&(this._isInternalSelection=!1))}async _getMappingFunction(){return this._config.useLinksData?await this._internalApi.public.getActiveLinkWidthFn():await this._internalApi.public.getActivePointSizeFn()}async _calcVisibleMaxLabel(i,t,e){const n=await this._getMappingFunction();if(n){const s=i/n(1),a=Math.min(Math.abs(e),Math.max(Math.abs(t),Math.abs(s))),l=Math.sign(e)*a;return Number(l.toFixed(0))}return 0}async _updateMaxLabel(){if(this._internalApi.config.pointSizeByFn&&this._uiConfig.extentLabels&&!this._legend.isHidden&&this._uiConfig.sizeMultiplier){const i=await this._calcVisibleMaxLabel(this._internalApi.public.maxPointSize/this._uiConfig.sizeMultiplier,this._uiConfig.extentLabels[0],this._originalMaxValue);this._uiConfig.extentLabels=[this._uiConfig.extentLabels[0],i]}}async _updateSizeMultiplier(){var i,t,e,n;const{config:s}=this._internalApi,a=null!==(i=this._internalApi.public.getZoomLevel())&&void 0!==i?i:1;this._config.useLinksData?this._uiConfig.sizeMultiplier=null!==(t=s.linkWidthScale)&&void 0!==t?t:1:!1!==s.scalePointsOnZoom&&this._config.dynamicPointSize?(this._uiConfig.sizeMultiplier=(null!==(n=s.pointSizeScale)&&void 0!==n?n:1)*a,await this._updateMaxLabel()):this._uiConfig.sizeMultiplier=null!==(e=s.pointSizeScale)&&void 0!==e?e:1}_updateLegendVisibility(){var i,t;if(this._uiConfig.extent){const e=(null!==(t=null===(i=this._uiConfig)||void 0===i?void 0:i.sizeMultiplier)&&void 0!==t?t:1)*this._uiConfig.extent[1];this._config.hideWhenSizeMoreThan&&this._config.hideWhenSizeMoreThan<e?this._legend.hide():this._manuallyHidden||this._legend.show()}}}export{r as CosmographSizeLegend}; | ||
//# sourceMappingURL=index.js.map |
import { TimelineEvents, type TimelineConfigInterface } from '@cosmograph/ui'; | ||
export interface CosmographTimelineConfigInterface { | ||
/** Data column key to access time values for the `CosmographTimeline`. Default: `date` */ | ||
/** Data column key to access time values for the `CosmographTimeline`. Default: `undefined` */ | ||
accessor?: string; | ||
@@ -5,0 +5,0 @@ /** Minimum and maximum extent for the `CosmographHistogram` visualization. Can be used if you don't want histogram range to be automatically calculated from data extent. Default: `undefined` */ |
@@ -1,2 +0,2 @@ | ||
const s={accessor:"date",useLinksData:!1,highlightCrossfiltered:!0};export{s as defaultCosmographTimelineConfig}; | ||
const s={accessor:void 0,useLinksData:!1,highlightCrossfiltered:!0};export{s as defaultCosmographTimelineConfig}; | ||
//# sourceMappingURL=config.js.map |
{ | ||
"name": "@cosmograph/cosmograph", | ||
"version": "2.0.0-beta.16", | ||
"version": "2.0.0-beta.17", | ||
"description": "Cosmograph: The fastest web-based graph visualization library", | ||
@@ -12,8 +12,8 @@ "author": "cosmograph-org", | ||
"@cosmograph/cosmos": "2.0.0-beta.23", | ||
"@cosmograph/ui": "2.0.0-beta.16", | ||
"@duckdb/duckdb-wasm": "^1.29.1-dev68.0", | ||
"@cosmograph/ui": "2.0.0-beta.17", | ||
"@duckdb/duckdb-wasm": "1.29.1-dev115.0", | ||
"@interacta/css-labels": "^0.1.2", | ||
"@uwdata/mosaic-core": "^0.13.0", | ||
"@uwdata/mosaic-sql": "^0.13.0", | ||
"apache-arrow": "^19.0.1", | ||
"apache-arrow": "^17.0.0", | ||
"d3-array": "^3.2.4", | ||
@@ -20,0 +20,0 @@ "d3-brush": "^3.0.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
490265
0.39%3540
0.25%2
-33.33%1
Infinity%+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated