UNPKG

realmap

Version:

Wooritech map chart component library

8 lines (6 loc) 4.56 kB
/** * RealMap Feature v1.0.11 * Copyright (C) 2023-2025 WooriTech Inc. * All Rights Reserved. */ import{extend as e,DataPointLabel as t,FeatureSeriesType as o,ValueSeries as r,isObject as s,copyObj as i,ColorRanger as a,Color as l,ValuePoint as n,SeriesView as h,PointViewPool as d,SeriesAnimation as c,PointElement as _}from"./index.mjs";class u extends n{_readObject(e,t){super._readObject(e,t),this.center=t.center,this.value=t.value}}class p extends t{}p.defaults=e(t.defaults,{hoverColor:"white"});class m extends r{get areaCount(){return this._map.areaCount}get detail(){return this._detail}get color(){return this._colorObj}getValueRange(){return{min:this._minValue,max:this._maxValue}}_createLabel(e){return new p(e)}_doApply(e){s(e.detail)?this._detail||(this._detail=new m(this.chart)):e.hasOwnProperty("detail")&&(this._detail=null),super._doApply(e)}needMapScale(){return!0}getRangedColor(e){var t;if(!isNaN(e.value)){const o=this._colorRanger||(null===(t=this.chart.getColorScale(this._op.colorScale))||void 0===t?void 0:t.getRanger());return null==o?void 0:o.getColor(this._minValue,this._maxValue,e.value,this._colorObj)}}followTooltipPointer(){return!0}getLegendSources(e,t){return this._points.count>0&&super.getLegendSources(e,t)}_createPoint(e){return new u(e)}_prepareRender(){super._prepareRender()}_doPrepareRender(e,t){super._doPrepareRender(e,t);const o=this._visPoints,{min:r,max:l}=this._calcMinMax(o);if(this._minValue=r,this._maxValue=l,s(t.colorRange)){const e=i(t.colorRange);isNaN(e.minValue)&&(e.minValue=r),isNaN(e.maxValue)&&(e.maxValue=l),this._colorRanger=new a(e)}else this._colorRanger=null}_doLoadPoints(e){this._useMapData&&(e=this._map._internalAreas().map((e=>({id:e.id,name:e.name})))),super._doLoadPoints(e),this._map}setCalcedColor(e,t){super.setCalcedColor(e,t),this._colorObj=new l(this._calcedColor),this._color=this._colorObj?this._colorObj.toString():null}getColorScale(){return this._op.colorScale}}m.type=o,m.defaults=e(r.defaults,{selectable:!1,detailZoom:250});const g="rm-map-series-id-";class v extends _{static idClass(e){return g+e.id}static getId(e){for(const t of Array.from(e.classList))if(t.startsWith(g))return t.substring(17)}constructor(e){super(e)}render(e,t,o){const r=this.model,s=!this.point||this.point.isNull;e!==r&&this.setPath((this.model=e).path),o&&(this.setBoolData("null",s),s&&t&&this.internalSetStyleOrClass(t),this.dom.classList.add(v.idClass(e)))}reset(){this.model=null}}class f extends h{constructor(e){super(e,"rm-feature-series"),this._areas={},this._areaPool=new d(this._pointContainer,v)}get hoverArea(){return this._hoverArea}set hoverArea(e){var t,o;const r=this._hoverArea;if(e!==r){const i=this.model;if(r&&(r.setBoolData(h.DATA_HOVER,!1),r.point&&(null===(t=this._labelContainer.get(r.point,0))||void 0===t||t._text.setBoolData(h.DATA_HOVER,!1))),e&&!e.point&&(e=void 0),this._hoverArea=e,e){const t=this.model.options,r=document.querySelector(".rm-root");let i=t.hoverColor,a=this.model.pointLabel.options.hoverColor;!i&&s(t.hoverStyle)&&(i=t.hoverStyle.fill),r.style.setProperty("--map-series-hover-fill",i||""),r.style.setProperty("--map-series-hover-label-fill",a||""),e.setBoolData(h.DATA_HOVER,!0),e.point&&(null===(o=this._labelContainer.get(e.point,0))||void 0===o||o._text.setBoolData(h.DATA_HOVER,!0))}e!=r&&i.chart._hoverAreaChanged(i,null==e?void 0:e.model,null==r?void 0:r.model)}}areaOfDom(e){let t=e;for(;t;){if(t.classList.contains("rm-point")){const e=v.getId(t);if(e)return this._areas[e];break}t=t.parentElement}}_getPointPool(){return this._areaPool}_setModelColor(e){this._pointContainer.setFill(e)}_setPointColor(e,t){e.setFill(t)}_doPrepeare(e,t,o){this._second;const r=t.options.bringToFront?[]:null;this._areaPool.prepare(t.areaCount,((e,t)=>{})),r&&r.length!==t.areaCount&&r.forEach((e=>{e.parent.moveToLast(e)}))}_doRender(e,t){this.$_layoutAreas(e,t)}_doReset(){this._areaPool.forEach((e=>{e.visible&&e.reset()}))}_doPointerMoved(e,t,o){const r=this.areaOfDom(o);return this.hoverArea=r,!0}_doPointClicked(e){this.model.chart._areaClicked(this.model,e.model)}_runShowEffect(e){e&&c.grow(this)}_doViewRateChanged(e){this.$_layoutAreas(this.width,this.height)}$_layoutAreas(e,t){const o=this.chart(),r=this._second;o.isDirty,o.body;const s=this.model;s.options,o.getProjection(r),this._areas={},s.pointLabel,this._labelViews(),this._scale,this._areaPool.forEach(((e,t)=>{}))}}function C(e){(function(e){return e.Series&&e.SeriesView})(e)&&(e.Series.register(m),e.SeriesView.register([m,f]))}export{m as FeatureSeries,C as default};