highcharts
Version:
JavaScript charting framework
29 lines (26 loc) • 9.4 kB
JavaScript
/*
Highcharts JS v8.0.0 (2019-12-10)
ColorAxis module
(c) 2012-2019 Pawel Potaczek
License: www.highcharts.com/license
*/
(function(c){"object"===typeof module&&module.exports?(c["default"]=c,module.exports=c):"function"===typeof define&&define.amd?define("highcharts/modules/color-axis",["highcharts"],function(l){c(l);c.Highcharts=l;return c}):c("undefined"!==typeof Highcharts?Highcharts:void 0)})(function(c){function l(e,g,c,p){e.hasOwnProperty(g)||(e[g]=p.apply(null,c))}c=c?c._modules:{};l(c,"parts-map/ColorSeriesMixin.js",[c["parts/Globals.js"]],function(e){e.colorPointMixin={setVisible:function(e){var c=this,g=e?
"show":"hide";c.visible=c.options.visible=!!e;["graphic","dataLabel"].forEach(function(e){if(c[e])c[e][g]()})}};e.colorSeriesMixin={optionalAxis:"colorAxis",colorAxis:0,translateColors:function(){var e=this,c=this.options.nullColor,p=this.colorAxis,l=this.colorKey;(this.data.length?this.data:this.points).forEach(function(g){var m=g[l];if(m=g.options.color||(g.isNull?c:p&&"undefined"!==typeof m?p.toColor(m,g):g.color||e.color))g.color=m})}}});l(c,"parts-map/ColorAxis.js",[c["parts/Globals.js"],c["parts/Utilities.js"]],
function(e,c){var g=c.erase,p=c.extend,l=c.isNumber,m=c.pick,y=c.splat;c=e.addEvent;var n=e.Axis,t=e.Chart,q=e.Series,z=e.Point,r=e.color,u=e.Legend,A=e.LegendSymbolMixin,B=e.colorPointMixin,x=e.noop,v=e.merge;p(q.prototype,e.colorSeriesMixin);p(z.prototype,B);t.prototype.collectionsWithUpdate.push("colorAxis");t.prototype.collectionsWithInit.colorAxis=[t.prototype.addColorAxis];var w=e.ColorAxis=function(){this.init.apply(this,arguments)};p(w.prototype,n.prototype);p(w.prototype,{defaultColorAxisOptions:{lineWidth:0,
minPadding:0,maxPadding:0,gridLineWidth:1,tickPixelInterval:72,startOnTick:!0,endOnTick:!0,offset:0,marker:{animation:{duration:50},width:.01,color:"#999999"},labels:{overflow:"justify",rotation:0},minColor:"#e6ebf5",maxColor:"#003399",tickLength:5,showInLegend:!0},keepProps:["legendGroup","legendItemHeight","legendItemWidth","legendItem","legendSymbol"].concat(n.prototype.keepProps),init:function(a,b){this.coll="colorAxis";var f=this.buildOptions.call(a,this.defaultColorAxisOptions,b);n.prototype.init.call(this,
a,f);b.dataClasses&&this.initDataClasses(b);this.initStops();this.horiz=!f.opposite;this.zoomEnabled=!1;this.defaultLegendLength=200},initDataClasses:function(a){var b=this.chart,f,d=0,k=b.options.chart.colorCount,c=this.options,h=a.dataClasses.length;this.dataClasses=f=[];this.legendItems=[];a.dataClasses.forEach(function(a,e){a=v(a);f.push(a);if(b.styledMode||!a.color)"category"===c.dataClassColor?(b.styledMode||(e=b.options.colors,k=e.length,a.color=e[d]),a.colorIndex=d,d++,d===k&&(d=0)):a.color=
r(c.minColor).tweenTo(r(c.maxColor),2>h?.5:e/(h-1))})},hasData:function(){return!(!this.tickPositions||!this.tickPositions.length)},setTickPositions:function(){if(!this.dataClasses)return n.prototype.setTickPositions.call(this)},initStops:function(){this.stops=this.options.stops||[[0,this.options.minColor],[1,this.options.maxColor]];this.stops.forEach(function(a){a.color=r(a[1])})},buildOptions:function(a,b){var f=this.options.legend,d=b.layout?"vertical"!==b.layout:"vertical"!==f.layout;return v(a,
{side:d?2:1,reversed:!d},b,{opposite:!d,showEmpty:!1,title:null,visible:f.enabled&&(b?!1!==b.visible:!0)})},setOptions:function(a){n.prototype.setOptions.call(this,a);this.options.crosshair=this.options.marker},setAxisSize:function(){var a=this.legendSymbol,b=this.chart,f=b.options.legend||{},d,k;a?(this.left=f=a.attr("x"),this.top=d=a.attr("y"),this.width=k=a.attr("width"),this.height=a=a.attr("height"),this.right=b.chartWidth-f-k,this.bottom=b.chartHeight-d-a,this.len=this.horiz?k:a,this.pos=this.horiz?
f:d):this.len=(this.horiz?f.symbolWidth:f.symbolHeight)||this.defaultLegendLength},normalizedValue:function(a){this.isLog&&(a=this.val2lin(a));return 1-(this.max-a)/(this.max-this.min||1)},toColor:function(a,b){var f=this.stops,d=this.dataClasses,k;if(d)for(k=d.length;k--;){var c=d[k];var e=c.from;f=c.to;if(("undefined"===typeof e||a>=e)&&("undefined"===typeof f||a<=f)){var g=c.color;b&&(b.dataClass=k,b.colorIndex=c.colorIndex);break}}else{a=this.normalizedValue(a);for(k=f.length;k--&&!(a>f[k][0]););
e=f[k]||f[k+1];f=f[k+1]||e;a=1-(f[0]-a)/(f[0]-e[0]||1);g=e.color.tweenTo(f.color,a)}return g},getOffset:function(){var a=this.legendGroup,b=this.chart.axisOffset[this.side];a&&(this.axisParent=a,n.prototype.getOffset.call(this),this.added||(this.added=!0,this.labelLeft=0,this.labelRight=this.width),this.chart.axisOffset[this.side]=b)},setLegendColor:function(){var a=this.reversed;var b=a?1:0;a=a?0:1;b=this.horiz?[b,0,a,0]:[0,a,0,b];this.legendColor={linearGradient:{x1:b[0],y1:b[1],x2:b[2],y2:b[3]},
stops:this.stops}},drawLegendSymbol:function(a,b){var f=a.padding,d=a.options,c=this.horiz,e=m(d.symbolWidth,c?this.defaultLegendLength:12),h=m(d.symbolHeight,c?12:this.defaultLegendLength),g=m(d.labelPadding,c?16:30);d=m(d.itemDistance,10);this.setLegendColor();b.legendSymbol=this.chart.renderer.rect(0,a.baseline-11,e,h).attr({zIndex:1}).add(b.legendGroup);this.legendItemWidth=e+f+(c?d:g);this.legendItemHeight=h+f+(c?g:0)},setState:function(a){this.series.forEach(function(b){b.setState(a)})},visible:!0,
setVisible:x,getSeriesExtremes:function(){var a=this.series,b=a.length,f;this.dataMin=Infinity;for(this.dataMax=-Infinity;b--;){var d=a[b];var c=d.colorKey=m(d.options.colorKey,d.colorKey,d.pointValKey,d.zoneAxis,"y");var e=d.pointArrayMap;var h=d[c+"Min"]&&d[c+"Max"];if(d[c+"Data"])var g=d[c+"Data"];else if(e){g=[];e=e.indexOf(c);var l=d.yData;if(0<=e&&l)for(f=0;f<l.length;f++)g.push(m(l[f][e],l[f]))}else g=d.yData;h?(d.minColorValue=d[c+"Min"],d.maxColorValue=d[c+"Max"]):(q.prototype.getExtremes.call(d,
g),d.minColorValue=d.dataMin,d.maxColorValue=d.dataMax);"undefined"!==typeof d.minColorValue&&(this.dataMin=Math.min(this.dataMin,d.minColorValue),this.dataMax=Math.max(this.dataMax,d.maxColorValue));h||q.prototype.getExtremes.call(d)}},drawCrosshair:function(a,b){var c=b&&b.plotX,d=b&&b.plotY,e=this.pos,g=this.len;if(b){var h=this.toPixels(b[b.series.colorKey]);h<e?h=e-2:h>e+g&&(h=e+g+2);b.plotX=h;b.plotY=this.len-h;n.prototype.drawCrosshair.call(this,a,b);b.plotX=c;b.plotY=d;this.cross&&!this.cross.addedToColorAxis&&
this.legendGroup&&(this.cross.addClass("highcharts-coloraxis-marker").add(this.legendGroup),this.cross.addedToColorAxis=!0,this.chart.styledMode||this.cross.attr({fill:this.crosshair.color}))}},getPlotLinePath:function(a){var b=a.translatedValue;return l(b)?this.horiz?["M",b-4,this.top-6,"L",b+4,this.top-6,b,this.top,"Z"]:["M",this.left,b,"L",this.left-6,b+6,this.left-6,b-6,"Z"]:n.prototype.getPlotLinePath.apply(this,arguments)},update:function(a,b){var c=this.chart,d=c.legend,e=this.buildOptions.call(c,
{},a);this.series.forEach(function(a){a.isDirtyData=!0});(a.dataClasses&&d.allItems||this.dataClasses)&&this.destroyItems();c.options[this.coll]=v(this.userOptions,e);n.prototype.update.call(this,e,b);this.legendItem&&(this.setLegendColor(),d.colorizeItem(this,!0))},destroyItems:function(){var a=this.chart;this.legendItem?a.legend.destroyItem(this):this.legendItems&&this.legendItems.forEach(function(b){a.legend.destroyItem(b)});a.isDirtyLegend=!0},remove:function(a){this.destroyItems();n.prototype.remove.call(this,
a)},getDataClassLegendSymbols:function(){var a=this,b=this.chart,c=this.legendItems,d=b.options.legend,e=d.valueDecimals,g=d.valueSuffix||"",h;c.length||this.dataClasses.forEach(function(d,f){var k=!0,l=d.from,m=d.to,n=b.numberFormatter;h="";"undefined"===typeof l?h="< ":"undefined"===typeof m&&(h="> ");"undefined"!==typeof l&&(h+=n(l,e)+g);"undefined"!==typeof l&&"undefined"!==typeof m&&(h+=" - ");"undefined"!==typeof m&&(h+=n(m,e)+g);c.push(p({chart:b,name:h,options:{},drawLegendSymbol:A.drawRectangle,
visible:!0,setState:x,isDataClass:!0,setVisible:function(){k=this.visible=!k;a.series.forEach(function(a){a.points.forEach(function(a){a.dataClass===f&&a.setVisible(k)})});b.legend.colorizeItem(this,k)}},d))});return c},beforePadding:!1,name:""});["fill","stroke"].forEach(function(a){e.Fx.prototype[a+"Setter"]=function(){this.elem.attr(a,r(this.start).tweenTo(r(this.end),this.pos),null,!0)}});c(t,"afterGetAxes",function(){var a=this,b=a.options;this.colorAxis=[];b.colorAxis&&(b.colorAxis=y(b.colorAxis),
b.colorAxis.forEach(function(b,c){b.index=c;new w(a,b)}))});c(q,"bindAxes",function(){var a=this.axisTypes;a?-1===a.indexOf("colorAxis")&&a.push("colorAxis"):this.axisTypes=["colorAxis"]});c(u,"afterGetAllItems",function(a){var b=[],c,d;(this.chart.colorAxis||[]).forEach(function(d){(c=d.options)&&c.showInLegend&&(c.dataClasses&&c.visible?b=b.concat(d.getDataClassLegendSymbols()):c.visible&&b.push(d),d.series.forEach(function(b){if(!b.options.showInLegend||c.dataClasses)"point"===b.options.legendType?
b.points.forEach(function(b){g(a.allItems,b)}):g(a.allItems,b)}))});for(d=b.length;d--;)a.allItems.unshift(b[d])});c(u,"afterColorizeItem",function(a){a.visible&&a.item.legendColor&&a.item.legendSymbol.attr({fill:a.item.legendColor})});c(u,"afterUpdate",function(){var a=this.chart.colorAxis;a&&a.forEach(function(a,c,d){a.update({},d)})});c(q,"afterTranslate",function(){(this.chart.colorAxis&&this.chart.colorAxis.length||this.colorAttribs)&&this.translateColors()})});l(c,"masters/modules/coloraxis.src.js",
[],function(){})});
//# sourceMappingURL=coloraxis.js.map