UNPKG

highcharts

Version:
13 lines 12.3 kB
/** * Highcharts JS v13.0.1 (2026-08-17) * @module highcharts/modules/color-axis * @requires highcharts * * ColorAxis module * * (c) 2012-2026 Highsoft AS * Author: Paweł Potaczek * * A commercial license may be required depending on use, * see www.highcharts.com/license */import*as t from"../highcharts.js";let e={};e.n=t=>{let i=t&&t.__esModule?()=>t.default:()=>t;return e.d(i,{a:i}),i},e.d=(t,i)=>{if(Array.isArray(i))for(var s=0;s<i.length;){var o=i[s++],l=i[s++];e.o(t,o)?0===l&&s++:0===l?Object.defineProperty(t,o,{enumerable:!0,value:i[s++]}):Object.defineProperty(t,o,{enumerable:!0,get:l})}else for(var o in i)e.o(i,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:i[o]})},e.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let i=t.default;var s,o,l,r=e.n(i);let a=t.default.Axis;var h=e.n(a);let n=t.default.Color;var d=e.n(n);let{parse:c}=d();(s=o||(o={})).initDataClasses=function(t){let e=this.chart,s=this.legendItem=this.legendItem||{},o=this.options,l=t.dataClasses||[],r,a,h=e.options.chart.colorCount,n=0,d;this.dataClasses=a=[],s.labels=[];for(let t=0,s=l.length;t<s;++t)r=l[t],r=(0,i.merge)(r),a.push(r),(e.styledMode||!r.color)&&("category"===o.dataClassColor?(e.styledMode||(h=(d=e.options.colors||[]).length,r.color=d[n]),r.colorIndex=n,++n===h&&(n=0)):r.color=c(o.minColor).tweenTo(c(o.maxColor),s<2?.5:t/(s-1)))},s.initStops=function(){let t=this.options,e=this.stops=t.stops||[[0,t.minColor||""],[1,t.maxColor||""]];for(let t=0,i=e.length;t<i;++t)e[t].color=c(e[t][1])},s.normalizedValue=function(t){let e=this.max||0,i=this.min||0;return this.logarithmic&&(t=this.logarithmic.log2lin(t)),1-(e-t)/(e-i||1)},s.toColor=function(t,e){let i,s,o,l,r,a,h=this.dataClasses,n=this.stops;if(h){for(a=h.length;a--;)if(s=(r=h[a]).from,o=r.to,(void 0===s||t>=s)&&(void 0===o||t<=o)){l=r.color,e&&(e.dataClass=a,e.colorIndex=r.colorIndex);break}}else{for(i=this.normalizedValue(t),a=n.length;a--&&!(i>n[a][0]););s=n[a]||n[a+1],i=1-((o=n[a+1]||s)[0]-i)/(o[0]-s[0]||1),l=s.color.tweenTo(o.color,i)}return l};let p=o,{parse:g}=d();!function(t){let e;function s(){let{userOptions:t}=this;this.colorAxis=[],t.colorAxis&&(t.colorAxis=(0,i.splat)(t.colorAxis),t.colorAxis.map(t=>new e(this,t)))}function o(t){let e=this.chart.colorAxis||[],i=e=>{let i=t.allItems.indexOf(e);-1!==i&&(this.destroyItem(t.allItems[i]),t.allItems.splice(i,1))},s=[],o,l;for(e.forEach(function(t){o=t.options,o?.showInLegend&&(o.dataClasses&&o.visible?s=s.concat(t.getDataClassLegendSymbols()):o.visible&&s.push(t),t.series.forEach(function(t){(!t.options.showInLegend||o.dataClasses)&&("point"===t.options.legendType?t.points.forEach(function(t){i(t)}):i(t))}))}),l=s.length;l--;)t.allItems.unshift(s[l])}function l(t){t.visible&&t.item.legendColor&&t.item.legendItem.symbol.attr({fill:t.item.legendColor})}function r(t){this.chart.colorAxis?.forEach(e=>{e.update({},t.redraw)})}function a(){(this.chart.colorAxis?.length||this.colorAttribs)&&this.translateColors()}function h(){let t=this.axisTypes;t?-1===t.indexOf("colorAxis")&&t.push("colorAxis"):this.axisTypes=["colorAxis"]}function n(t){let e=this,i=t?"show":"hide";e.visible=e.options.visible=!!t,["graphic","dataLabel"].forEach(function(t){e[t]&&e[t][i]()}),this.series.buildKDTree()}function d(){let t=this,e=this.getPointsCollection(),i=this.options.nullColor,s=this.colorAxis,o=this.colorKey;e.forEach(e=>{let l=e.getNestedProperty(o),r=e.options.color||(e.isNull||null===e.value?i:s&&void 0!==l?s.toColor(l,e):e.color||t.color);r&&e.color!==r&&(e.color=r,"point"===t.options.legendType&&e.legendItem&&e.legendItem.label&&t.chart.legend.colorizeItem(e,e.visible))})}function c(){this.elem.attr("fill",g(this.start).tweenTo(g(this.end),this.pos),void 0,!0)}function p(){this.elem.attr("stroke",g(this.start).tweenTo(g(this.end),this.pos),void 0,!0)}t.compose=function(t,g,f,u,m){var x;let y,b=g.prototype,C=f.prototype,v=m.prototype;b.collectionsWithUpdate.includes("colorAxis")||(e=t,b.collectionsWithUpdate.push("colorAxis"),b.collectionsWithInit.colorAxis=[b.addColorAxis],(0,i.addEvent)(g,"afterCreateAxes",s),y=(x=g).prototype.createAxis,x.prototype.createAxis=function(t,s){if("colorAxis"!==t)return y.apply(this,arguments);let o=new e(this,(0,i.merge)(s.axis,{index:this[t].length,isX:!1}));return this.isDirtyLegend=!0,this.axes.forEach(t=>{t.series=[]}),this.series.forEach(t=>{t.bindAxes(),t.isDirtyData=!0}),(0,i.pick)(s.redraw,!0)&&this.redraw(s.animation),o},C.fillSetter=c,C.strokeSetter=p,(0,i.addEvent)(u,"afterGetAllItems",o),(0,i.addEvent)(u,"afterColorizeItem",l),(0,i.addEvent)(u,"afterUpdate",r),(0,i.extend)(v,{optionalAxis:"colorAxis",translateColors:d}),(0,i.extend)(v.pointClass.prototype,{setVisible:n}),(0,i.addEvent)(m,"afterTranslate",a,{order:1}),(0,i.addEvent)(m,"bindAxes",h))},t.pointSetVisible=n}(l||(l={}));let f=l,u=t.default.SeriesRegistry;var m=e.n(u);let{defaultOptions:x}=r(),{series:y}=m();x.colorAxis=(0,i.merge)(x.xAxis,{lineWidth:0,minPadding:0,maxPadding:0,gridLineColor:"var(--highcharts-background-color)",gridLineWidth:1,tickPixelInterval:72,startOnTick:!0,endOnTick:!0,offset:0,marker:{animation:{duration:50},clip:!1,lineColor:"var(--highcharts-neutral-color-40)",lineWidth:0,color:"var(--highcharts-neutral-color-40)",width:.01},labels:{distance:8,overflow:"justify",rotation:0},minColor:"var(--highcharts-highlight-color-10)",maxColor:"var(--highcharts-highlight-color-100)",tickLength:5,title:{margin:5},showInLegend:!0});class b extends h(){static compose(t,e,i,s){f.compose(b,t,e,i,s)}constructor(t,e){super(t,e),this.clippable=!1,this.coll="colorAxis",this.visible=!0,this.init(t,e)}init(t,e){let s=t.options.legend||{},o=e.layout?"vertical"!==e.layout:"vertical"!==s.layout;this.side=e.side||o?2:1,this.reversed=e.reversed,this.opposite=!o,super.init(t,e,"colorAxis"),this.userOptions=e,(0,i.isArray)(t.userOptions.colorAxis)&&(t.userOptions.colorAxis[this.index]=e),e.dataClasses&&this.initDataClasses(e),this.initStops(),this.horiz=o,this.zoomEnabled=!1}hasData(){return!!(this.tickPositions||[]).length}setTickPositions(){if(!this.dataClasses)return super.setTickPositions()}setOptions(t){let e=this.chart.options.legend||{},s=x.colorAxis,o=t.layout||e.layout||s.layout,l=(0,i.merge)("vertical"!==o?{title:{rotation:0}}:{title:{rotation:90,margin:10}},s,t,{showEmpty:!1,visible:this.chart.options.legend.enabled&&!1!==t.visible});super.setOptions(l),this.options.crosshair=this.options.marker}setAxisSize(){let t=this.chart,e=this.legendItem?.symbol,{width:i,height:s}=this.getSize();e&&(this.left=+e.attr("x"),this.top=+e.attr("y"),this.width=i=+e.attr("width"),this.height=s=+e.attr("height"),this.right=t.chartWidth-this.left-i,this.bottom=t.chartHeight-this.top-s,this.pos=this.horiz?this.left:this.top),this.len=(this.horiz?i:s)||b.defaultLegendLength}getOffset(){let t=this.chart,e=this.legendItem?.group,i=t.axisOffset[this.side],{clipOffset:s,legend:o}=t;e&&(this.axisParent=e,super.getOffset(),o.allItems.forEach(function(t){t instanceof b&&t.drawLegendSymbol(o,t)}),o.render(),t.getMargins(!0),this.added||(this.added=!0),this.labelLeft=0,this.labelRight=this.width,t.axisOffset[this.side]=i,t.clipOffset=s)}setLegendColor(){let t=this.horiz,e=this.reversed,i=+!!e,s=+!e,o=t?[i,0,s,0]:[0,s,0,i];this.legendColor={linearGradient:{x1:o[0],y1:o[1],x2:o[2],y2:o[3]},stops:this.stops}}drawLegendSymbol(t,e){let s=e.legendItem||{},o=t.padding,l=t.options,r=this.options.labels,a=(0,i.pick)(l.itemDistance,10),h=this.horiz,{width:n,height:d}=this.getSize(),c=(0,i.pick)(l.labelPadding,h?16:30);this.setLegendColor();let p=0,g=0;if(this.options.title?.text&&!this.axisTitle){this.axisGroup||(this.axisParent=s.group,this.createGroups());let t=this.len,e=this.top,i=this.left,o=this.width;this.len=h?n:d,this.top=0,this.left=0,this.width=n,this.addTitle(!0),this.len=t,this.top=e,this.left=i,this.width=o}if(this.axisTitle){let t=this.axisTitle.getBBox();p=t.height,g=t.width}let f=this.options.title||{},u=this.axisTitle?f.margin??0:0,m=h?p+u:0;s.symbol||(s.symbol=this.chart.renderer.symbol("roundedRect").attr({r:l.symbolRadius??3,zIndex:1}).add(s.group)),s.symbol.attr({x:0,y:(t.baseline||0)-11+m,width:n,height:d}),h?(s.labelWidth=Math.max(n+o+a,g||0),s.labelHeight=d+o+c+p+u):(s.labelWidth=n+o+(r.x??r.distance??0)+(this.maxLabelLength||0)+(g||0)+u,s.labelHeight=Math.max(d+o,p||0))}getTitlePosition(t){let e=super.getTitlePosition(t),i=this.options.title?.margin??0;if(this.horiz&&t)e.y=this.top-i;else if(!this.horiz&&t){let t=this.options.labels||{},s=t.x??t.distance??0;e.x=this.left+this.width+s+(this.maxLabelLength||0)+i}return e}setState(t){this.series.forEach(function(e){e.setState(t)})}setVisible(){}getSeriesExtremes(){let t=this.series,e,s,o,l,r=t.length;for(this.dataMin=1/0,this.dataMax=-1/0;r--;){for(let a of(s=(l=t[r]).colorKey=(0,i.pick)(l.options.colorKey,l.colorKey,l.pointValKey,l.zoneAxis,"y"),o=l[s+"Min"]&&l[s+"Max"],[s,"value","y"]))if((e=l.getColumn(a)).length)break;if(o)l.minColorValue=l[s+"Min"],l.maxColorValue=l[s+"Max"];else{let t=y.prototype.getExtremes.call(l,e);l.minColorValue=t.dataMin,l.maxColorValue=t.dataMax}(0,i.defined)(l.minColorValue)&&(0,i.defined)(l.maxColorValue)&&(this.dataMin=Math.min(this.dataMin,l.minColorValue),this.dataMax=Math.max(this.dataMax,l.maxColorValue)),o||y.prototype.applyExtremes.call(l)}}drawCrosshair(t,e){let i,s=this.legendItem||{},o=e?.plotX,l=e?.plotY,r=this.pos,a=this.len,h=this.options.marker||{};e&&((i=this.toPixels(e.getNestedProperty(e.series.colorKey)))<r?i=r-2:i>r+a&&(i=r+a+2),e.plotX=i,e.plotY=this.len-i,super.drawCrosshair(t,e),e.plotX=o,e.plotY=l,this.cross&&!this.cross.addedToColorAxis&&s.group&&(this.cross.addClass("highcharts-coloraxis-marker").add(s.group),this.cross.addedToColorAxis=!0,this.chart.styledMode||"object"!=typeof this.crosshair||this.cross.attr({fill:h.color,stroke:h.lineColor,"stroke-width":h.lineWidth})))}getPlotLinePath(t){let e=this.left,s=t.translatedValue,{symbol:o}=this.options.marker||{},l=this.top;if((0,i.isNumber)(s)){if(o){let t=this.height,i=s-t/2,r=l;return this.horiz||(t=this.width,i=e,r=s-t/2),this.chart.renderer.symbols[o](i,r,t,t)}return this.horiz?[["M",s-4,l-6],["L",s+4,l-6],["L",s,l],["Z"]]:[["M",e,s],["L",e-6,s+6],["L",e-6,s-6],["Z"]]}return super.getPlotLinePath(t)}update(t,e){let i=this.chart.legend;this.series.forEach(t=>{t.isDirtyData=!0}),(t.dataClasses&&i.allItems||this.dataClasses)&&this.destroyItems(),super.update(t,e),this.legendItem?.label&&(this.setLegendColor(),i.colorizeItem(this,!0))}destroyItems(){let t=this.chart,e=this.legendItem||{};if(e.label)t.legend.destroyItem(this);else if(e.labels)for(let i of e.labels)t.legend.destroyItem(i);t.isDirtyLegend=!0}destroy(){this.chart.isDirtyLegend=!0,this.destroyItems(),super.destroy(...[].slice.call(arguments))}remove(t){this.destroyItems(),super.remove(t)}getDataClassLegendSymbols(){let t,e=this,s=e.chart,o=e.legendItem&&e.legendItem.labels||[],l=s.options.legend,r=(0,i.pick)(l.valueDecimals,-1),a=(0,i.pick)(l.valueSuffix,""),h=t=>e.series.reduce((e,i)=>(e.push(...i.points.filter(e=>e.dataClass===t)),e),[]);return o.length||e.dataClasses.forEach((l,n)=>{let d=l.from,c=l.to,{numberFormatter:p}=s,g=!0;t="",void 0===d?t="< ":void 0===c&&(t="> "),void 0!==d&&(t+=p(d,r)+a),void 0!==d&&void 0!==c&&(t+=" - "),void 0!==c&&(t+=p(c,r)+a),o.push((0,i.extend)({chart:s,name:t,options:{},drawLegendSymbol:y.prototype.drawLegendSymbol,visible:!0,isDataClass:!0,setState:t=>{for(let e of h(n))e.setState(t)},setVisible:function(){this.visible=g=e.visible=!g;let t=[];for(let e of h(n))e.setVisible(g),e.hiddenInDataClass=!g,-1===t.indexOf(e.series)&&t.push(e.series);s.legend.colorizeItem(this,g),t.forEach(t=>{(0,i.fireEvent)(t,"afterDataClassLegendClick")})}},l))}),o}getSize(){let{chart:t,horiz:e}=this,{height:s,width:o}=this.options,{legend:l}=t.options;return{width:(0,i.pick)((0,i.defined)(o)?(0,i.relativeLength)(o,t.chartWidth):void 0,l?.symbolWidth,e?b.defaultLegendLength:12),height:(0,i.pick)((0,i.defined)(s)?(0,i.relativeLength)(s,t.chartHeight):void 0,l?.symbolHeight,e?12:b.defaultLegendLength)}}}b.defaultLegendLength=200,b.keepProps=["legendItem"],(0,i.extend)(b.prototype,p),Array.prototype.push.apply(h().keepProps,b.keepProps);let C=r();C.ColorAxis=C.ColorAxis||b,C.ColorAxis.compose(C.Chart,C.Fx,C.Legend,C.Series);let v=r();export{v as default};