highcharts
Version:
JavaScript charting framework
13 lines • 13.9 kB
JavaScript
/**
* Highcharts JS v12.6.0 (2026-04-13)
* @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";var e,i,s,o={};o.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return o.d(e,{a:e}),e},o.d=(t,e)=>{for(var i in e)o.o(e,i)&&!o.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let l=t.default;var r=o.n(l);let n=t.default.Axis;var a=o.n(n);let h=t.default.Color;var c=o.n(h);let{doc:d,win:p}=r();function f(t,e,i,s={}){let o="function"==typeof t&&t.prototype||t;Object.hasOwnProperty.call(o,"hcEvents")||(o.hcEvents={});let l=o.hcEvents;r().Point&&t instanceof r().Point&&t.series&&t.series.chart&&(t.series.chart.runTrackerClick=!0);let n=t.addEventListener;n&&n.call(t,e,i,!!r().supportsPassiveEvents&&{passive:void 0===s.passive?-1!==e.indexOf("touch"):s.passive,capture:!1}),l[e]||(l[e]=[]);let a={fn:i,order:"number"==typeof s.order?s.order:1/0};return l[e].push(a),l[e].sort((t,e)=>t.order-e.order),function(){!function(t,e,i){function s(e,i){let s=t.removeEventListener;s&&s.call(t,e,i,!1)}function o(i){let o,l;t.nodeName&&(e?(o={})[e]=!0:o=i,b(o,function(t,e){if(i[e])for(l=i[e].length;l--;)s(e,i[e][l].fn)}))}let l="function"==typeof t&&t.prototype||t;if(Object.hasOwnProperty.call(l,"hcEvents")){let t=l.hcEvents;if(e){let l=t[e]||[];i?(t[e]=l.filter(function(t){return i!==t.fn}),s(e,i)):(o(t),t[e]=[])}else o(t),delete l.hcEvents}}(t,e,i)}}function u(t,e){let i;for(i in t||(t={}),e)t[i]=e[i];return t}function g(t){return y(t)&&"number"==typeof t.nodeType}function m(t){let e=Object.prototype.toString.call(t);return"[object Array]"===e||"[object Array Iterator]"===e}function y(t,e){return!!t&&"object"==typeof t&&(!e||!m(t))}function x(t,...e){let i,s=[t,...e],o={},l=function(t,e){return"object"!=typeof t&&(t={}),b(e,function(i,s){if("__proto__"!==s&&"constructor"!==s){let o;!y(i,!0)||(o=i?.constructor,y(i,!0)&&!g(i)&&o?.name&&"Object"!==o.name)||g(i)?t[s]=e[s]:t[s]=l(t[s]||{},i)}}),t};!0===t&&(o=s[1],s=Array.prototype.slice.call(s,2));let r=s.length;for(i=0;i<r;i++)o=l(o,s[i]);return o}function b(t,e,i){for(let s in t)Object.hasOwnProperty.call(t,s)&&e.call(i||t[s],t[s],s,t)}function v(){let t=arguments,e=t.length;for(let i=0;i<e;i++){let e=t[i];if(null!=e)return e}}function C(t,e,i){return/%$/.test(t)?e*parseFloat(t)/100+(i||0):parseFloat(t)}Array.prototype.find;let{parse:A}=c();(e=i||(i={})).initDataClasses=function(t){let e=this.chart,i=this.legendItem=this.legendItem||{},s=this.options,o=t.dataClasses||[],l,r,n=e.options.chart.colorCount,a=0,h;this.dataClasses=r=[],i.labels=[];for(let t=0,i=o.length;t<i;++t)l=x(l=o[t]),r.push(l),(e.styledMode||!l.color)&&("category"===s.dataClassColor?(e.styledMode||(n=(h=e.options.colors||[]).length,l.color=h[a]),l.colorIndex=a,++a===n&&(a=0)):l.color=A(s.minColor).tweenTo(A(s.maxColor),i<2?.5:t/(i-1)))},e.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=A(e[t][1])},e.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)},e.toColor=function(t,e){let i,s,o,l,r,n,a=this.dataClasses,h=this.stops;if(a){for(n=a.length;n--;)if(s=(r=a[n]).from,o=r.to,(void 0===s||t>=s)&&(void 0===o||t<=o)){l=r.color,e&&(e.dataClass=n,e.colorIndex=r.colorIndex);break}}else{for(i=this.normalizedValue(t),n=h.length;n--&&!(i>h[n][0]););s=h[n]||h[n+1],i=1-((o=h[n+1]||s)[0]-i)/(o[0]-s[0]||1),l=s.color.tweenTo(o.color,i)}return l};let I=i,{parse:E}=c();!function(t){let e;function i(){let{userOptions:t}=this;if(this.colorAxis=[],t.colorAxis){var i;t.colorAxis=m(i=t.colorAxis)?i:[i],t.colorAxis.map(t=>new e(this,t))}}function s(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 o(t){t.visible&&t.item.legendColor&&t.item.legendItem.symbol.attr({fill:t.item.legendColor})}function l(t){this.chart.colorAxis?.forEach(e=>{e.update({},t.redraw)})}function r(){(this.chart.colorAxis?.length||this.colorAttribs)&&this.translateColors()}function n(){let t=this.axisTypes;t?-1===t.indexOf("colorAxis")&&t.push("colorAxis"):this.axisTypes=["colorAxis"]}function a(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 h(){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",E(this.start).tweenTo(E(this.end),this.pos),void 0,!0)}function d(){this.elem.attr("stroke",E(this.start).tweenTo(E(this.end),this.pos),void 0,!0)}t.compose=function(t,p,g,m,y){var b;let C,A=p.prototype,I=g.prototype,E=y.prototype;A.collectionsWithUpdate.includes("colorAxis")||(e=t,A.collectionsWithUpdate.push("colorAxis"),A.collectionsWithInit.colorAxis=[A.addColorAxis],f(p,"afterCreateAxes",i),C=(b=p).prototype.createAxis,b.prototype.createAxis=function(t,i){if("colorAxis"!==t)return C.apply(this,arguments);let s=new e(this,x(i.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}),v(i.redraw,!0)&&this.redraw(i.animation),s},I.fillSetter=c,I.strokeSetter=d,f(m,"afterGetAllItems",s),f(m,"afterColorizeItem",o),f(m,"afterUpdate",l),u(E,{optionalAxis:"colorAxis",translateColors:h}),u(E.pointClass.prototype,{setVisible:a}),f(y,"afterTranslate",r,{order:1}),f(y,"bindAxes",n))},t.pointSetVisible=a}(s||(s={}));let L=s,w=t.default.SeriesRegistry;var P=o.n(w);let{defaultOptions:O}=r(),{series:T}=P();O.colorAxis=x(O.xAxis,{lineWidth:0,minPadding:0,maxPadding:0,gridLineColor:"#ffffff",gridLineWidth:1,tickPixelInterval:72,startOnTick:!0,endOnTick:!0,offset:0,marker:{animation:{duration:50},width:.01,color:"#999999"},labels:{distance:8,overflow:"justify",rotation:0},minColor:"#e6e9ff",maxColor:"#0022ff",tickLength:5,title:{margin:5},showInLegend:!0});class S extends a(){static compose(t,e,i,s){L.compose(S,t,e,i,s)}constructor(t,e){super(t,e),this.coll="colorAxis",this.visible=!0,this.init(t,e)}init(t,e){let i=t.options.legend||{},s=e.layout?"vertical"!==e.layout:"vertical"!==i.layout;this.side=e.side||s?2:1,this.reversed=e.reversed,this.opposite=!s,super.init(t,e,"colorAxis"),this.userOptions=e,m(t.userOptions.colorAxis)&&(t.userOptions.colorAxis[this.index]=e),e.dataClasses&&this.initDataClasses(e),this.initStops(),this.horiz=s,this.zoomEnabled=!1}hasData(){return!!(this.tickPositions||[]).length}setTickPositions(){if(!this.dataClasses)return super.setTickPositions()}setOptions(t){let e=this.chart.options.legend||{},i=O.colorAxis,s=x("vertical"!==(t.layout||e.layout||i.layout)?{title:{rotation:0}}:{title:{rotation:90,margin:10}},i,t,{showEmpty:!1,visible:this.chart.options.legend.enabled&&!1!==t.visible});super.setOptions(s),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)||S.defaultLegendLength}getOffset(){let t=this.legendItem?.group,e=this.chart.axisOffset[this.side];if(t){this.axisParent=t,super.getOffset();let i=this.chart.legend;i.allItems.forEach(function(t){t instanceof S&&t.drawLegendSymbol(i,t)}),i.render(),this.chart.getMargins(!0),this.added||(this.added=!0),this.labelLeft=0,this.labelRight=this.width,this.chart.axisOffset[this.side]=e}}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 i=e.legendItem||{},s=t.padding,o=t.options,l=this.options.labels,r=v(o.itemDistance,10),n=this.horiz,{width:a,height:h}=this.getSize(),c=v(o.labelPadding,n?16:30);this.setLegendColor();let d=0,p=0;if(this.options.title?.text&&!this.axisTitle){this.axisGroup||(this.axisParent=i.group,this.createGroups());let t=this.len,e=this.top,s=this.left,o=this.width;this.len=n?a:h,this.top=0,this.left=0,this.width=a,this.addTitle(!0),this.len=t,this.top=e,this.left=s,this.width=o}if(this.axisTitle){let t=this.axisTitle.getBBox();d=t.height,p=t.width}let f=this.options.title||{},u=this.axisTitle?f.margin??0:0,g=n?d+u:0;i.symbol||(i.symbol=this.chart.renderer.symbol("roundedRect").attr({r:o.symbolRadius??3,zIndex:1}).add(i.group)),i.symbol.attr({x:0,y:(t.baseline||0)-11+g,width:a,height:h}),n?(i.labelWidth=Math.max(a+s+r,p||0),i.labelHeight=h+s+c+d+u):(i.labelWidth=a+s+(l.x??l.distance??0)+(this.maxLabelLength||0)+(p||0)+u,i.labelHeight=Math.max(h+s,d||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,i,s,o,l=t.length;for(this.dataMin=1/0,this.dataMax=-1/0;l--;){for(let r of(i=(o=t[l]).colorKey=v(o.options.colorKey,o.colorKey,o.pointValKey,o.zoneAxis,"y"),s=o[i+"Min"]&&o[i+"Max"],[i,"value","y"]))if((e=o.getColumn(r)).length)break;if(s)o.minColorValue=o[i+"Min"],o.maxColorValue=o[i+"Max"];else{let t=T.prototype.getExtremes.call(o,e);o.minColorValue=t.dataMin,o.maxColorValue=t.dataMax}null!=o.minColorValue&&null!=o.maxColorValue&&(this.dataMin=Math.min(this.dataMin,o.minColorValue),this.dataMax=Math.max(this.dataMax,o.maxColorValue)),s||T.prototype.applyExtremes.call(o)}}drawCrosshair(t,e){let i,s=this.legendItem||{},o=e?.plotX,l=e?.plotY,r=this.pos,n=this.len;e&&((i=this.toPixels(e.getNestedProperty(e.series.colorKey)))<r?i=r-2:i>r+n&&(i=r+n+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:this.crosshair.color})))}getPlotLinePath(t){let e=this.left,i=t.translatedValue,s=this.top;return"number"==typeof i&&!isNaN(i)&&i<1/0&&i>-1/0?this.horiz?[["M",i-4,s-6],["L",i+4,s-6],["L",i,s],["Z"]]:[["M",e,i],["L",e-6,i+6],["L",e-6,i-6],["Z"]]: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,i=e.chart,s=e.legendItem&&e.legendItem.labels||[],o=i.options.legend,l=v(o.valueDecimals,-1),n=v(o.valueSuffix,""),a=t=>e.series.reduce((e,i)=>(e.push(...i.points.filter(e=>e.dataClass===t)),e),[]);return s.length||e.dataClasses.forEach((o,h)=>{let c=o.from,p=o.to,{numberFormatter:f}=i,g=!0;t="",void 0===c?t="< ":void 0===p&&(t="> "),void 0!==c&&(t+=f(c,l)+n),void 0!==c&&void 0!==p&&(t+=" - "),void 0!==p&&(t+=f(p,l)+n),s.push(u({chart:i,name:t,options:{},drawLegendSymbol:T.prototype.drawLegendSymbol,visible:!0,isDataClass:!0,setState:t=>{for(let e of a(h))e.setState(t)},setVisible:function(){this.visible=g=e.visible=!g;let t=[];for(let e of a(h))e.setVisible(g),e.hiddenInDataClass=!g,-1===t.indexOf(e.series)&&t.push(e.series);i.legend.colorizeItem(this,g),t.forEach(t=>{!function(t,e,i,s){if(i=i||{},d?.createEvent&&(t.dispatchEvent||t.fireEvent&&t!==r())){let s=d.createEvent("Events");s.initEvent(e,!0,!0),i=u(s,i),t.dispatchEvent?t.dispatchEvent(i):t.fireEvent(e,i)}else if(t.hcEvents){i.target||u(i,{preventDefault:function(){i.defaultPrevented=!0},target:t,type:e});let s=[],o=t,l=!1;for(;o.hcEvents;)Object.hasOwnProperty.call(o,"hcEvents")&&o.hcEvents[e]&&(s.length&&(l=!0),s.unshift.apply(s,o.hcEvents[e])),o=Object.getPrototypeOf(o);l&&s.sort((t,e)=>t.order-e.order),s.forEach(e=>{!1===e.fn.call(t,i,t)&&i.preventDefault()})}}(t,"afterDataClassLegendClick")})}},o))}),s}getSize(){let{chart:t,horiz:e}=this,{height:i,width:s}=this.options,{legend:o}=t.options;return{width:v(null!=s?C(s,t.chartWidth):void 0,o?.symbolWidth,e?S.defaultLegendLength:12),height:v(null!=i?C(i,t.chartHeight):void 0,o?.symbolHeight,e?12:S.defaultLegendLength)}}}S.defaultLegendLength=200,S.keepProps=["legendItem"],u(S.prototype,I),Array.prototype.push.apply(a().keepProps,S.keepProps);let M=r();M.ColorAxis=M.ColorAxis||S,M.ColorAxis.compose(M.Chart,M.Fx,M.Legend,M.Series);let z=r();export{z as default};