'use strict' ; import type FormatUtilities from '../../FormatUtilities' ; import type { PlotBandLabelOptions , PlotBandOptions } from './PlotBandOptions' ; import type { PlotLineLabelOptions , PlotLineOptions } from './PlotLineOptions' ; import type SVGAttributes from '../../Renderer/SVG/SVGAttributes' ; import type SVGElement from '../../Renderer/SVG/SVGElement' ; import type SVGPath from '../../Renderer/SVG/SVGPath' ; import Axis from '../Axis.js' ; import { Palette } from '../../Color/Palettes.js' ; import PlotLineOrBandAxis from './PlotLineOrBandAxis.js' ; import U from '../../Utilities.js' ; const { arrayMax , arrayMin , defined , destroyObjectProperties , erase , fireEvent , merge , objectEach , pick } = U ; class name param { Highcharts . Axis } axis param { Highcharts . AxisPlotLinesOptions | Highcharts . AxisPlotBandsOptions } options class PlotLineOrBand { public static compose < T extends typeof Axis > ( AxisClass ) { return PlotLineOrBandAxis . compose ( PlotLineOrBand , AxisClass ) ; } public constructor ( axis , options ? ) { this . axis = axis ; if ( options ) { this . options = options ; this . id = options . id ; } } public axis : PlotLineOrBandAxis . Composition ; public id ? : string ; public isActive ? : boolean ; public eventsAdded ? : boolean ; public label ? : SVGElement ; public options ? : ( PlotBandOptions | PlotLineOptions ) ; public svgElem ? : SVGElement ; private function public render ( ) { fireEvent ( this , 'render' ) ; const plotLine = this , axis = plotLine . axis , horiz = axis . horiz , log = axis . logarithmic , options = plotLine . options as ( PlotBandOptions | PlotLineOptions ) , color = options . color , zIndex = pick ( options . zIndex , 0 ) , events = options . events , groupAttribs = { } , renderer = axis . chart . renderer ; let optionsLabel = options . label , label = plotLine . label , to = ( options as any ) . to , from = ( options as any ) . from , value = ( options as any ) . value , svgElem = plotLine . svgElem , path = [ ] as SVGPath , group ; const isBand = defined ( from ) && defined ( to ) , isLine = defined ( value ) , isNew = ! svgElem , attribs = { 'class' : 'highcharts-plot-' + ( isBand ? 'band ' : 'line ' ) + ( options . className || '' ) } ; let groupName = isBand ? 'bands' : 'lines' ; if ( log ) { from = log . log2lin ( from ) ; to = log . log2lin ( to ) ; value = log . log2lin ( value ) ; } if ( ! axis . chart . styledMode ) { if ( isLine ) { attribs . stroke = color || Palette . neutralColor40 ; attribs [ 'stroke-width' ] = pick ( ( options as PlotLineOptions ) . width , 1 ) ; if ( ( options as PlotLineOptions ) . dashStyle ) { attribs . dashstyle = ( options as PlotLineOptions ) . dashStyle ; } } else if ( isBand ) { attribs . fill = color || Palette . highlightColor10 ; if ( ( options as PlotBandOptions ) . borderWidth ) { attribs . stroke = ( options as PlotBandOptions ) . borderColor ; attribs [ 'stroke-width' ] = ( options as PlotBandOptions ) . borderWidth ; } } } groupAttribs . zIndex = zIndex ; groupName += '-' + zIndex ; group = axis . plotLinesAndBandsGroups [ groupName ] ; if ( ! group ) { axis . plotLinesAndBandsGroups [ groupName ] = group = renderer . g ( 'plot-' + groupName ) . attr ( groupAttribs ) . add ( ) ; } if ( isNew ) { name type { Highcharts . SVGElement } plotLine . svgElem = svgElem = renderer . path ( ) . attr ( attribs ) . add ( group ) ; } if ( isLine ) { path = axis . getPlotLinePath ( { value : value , lineWidth : ( svgElem as any ) . strokeWidth ( ) , acrossPanes : options . acrossPanes } ) as any ; } else if ( isBand ) { path = axis . getPlotBandPath ( from , to , options ) ; } else { return ; } if ( ! plotLine . eventsAdded && events ) { objectEach ( events , function ( event , eventType ) : void { ( svgElem as any ) . on ( eventType , function ( e ) : void { events [ eventType ] . apply ( plotLine , [ e ] ) ; } ) ; } ) ; plotLine . eventsAdded = true ; } if ( ( isNew || ! ( svgElem as any ) . d ) && path && path . length ) { ( svgElem as any ) . attr ( { d : path } ) ; } else if ( svgElem ) { if ( path ) { svgElem . show ( true ) ; svgElem . animate ( { d : path } ) ; } else if ( svgElem . d ) { svgElem . hide ( ) ; if ( label ) { plotLine . label = label = label . destroy ( ) ; } } } if ( optionsLabel && ( defined ( optionsLabel . text ) || defined ( optionsLabel . formatter ) ) && path && path . length && axis . width > 0 && axis . height > 0 && ! ( path as any ) . isFlat ) { optionsLabel = merge ( { align : horiz && isBand && 'center' , x : horiz ? ! isBand && 4 : 10 , verticalAlign : ! horiz && isBand && 'middle' , y : horiz ? isBand ? 16 : 10 : isBand ? 6 : - 4 , rotation : horiz && ! isBand && 90 } as PlotLineLabelOptions , optionsLabel ) ; this . renderLabel ( optionsLabel , path , isBand , zIndex ) ; } else if ( label ) { label . hide ( ) ; } return plotLine as any ; } private function public renderLabel ( optionsLabel , path , isBand ? , zIndex ? ) { const plotLine = this , axis = plotLine . axis , renderer = axis . chart . renderer ; let label = plotLine . label ; if ( ! label ) { name type { Highcharts . SVGElement } plotLine . label = label = renderer . text ( this . getLabelText ( optionsLabel ) , 0 , 0 , optionsLabel . useHTML ) . attr ( { align : optionsLabel . textAlign || optionsLabel . align , rotation : optionsLabel . rotation , 'class' : 'highcharts-plot-' + ( isBand ? 'band' : 'line' ) + '-label ' + ( ( optionsLabel as any ) . className || '' ) , zIndex } ) . add ( ) ; if ( ! axis . chart . styledMode ) { label . css ( merge ( { textOverflow : 'ellipsis' } , optionsLabel . style ) ) ; } } const xBounds = ( path as any ) . xBounds || [ path [ 0 ] [ 1 ] , path [ 1 ] [ 1 ] , ( isBand ? path [ 2 ] [ 1 ] : path [ 0 ] [ 1 ] ) ] ; const yBounds = ( path as any ) . yBounds || [ path [ 0 ] [ 2 ] , path [ 1 ] [ 2 ] , ( isBand ? path [ 2 ] [ 2 ] : path [ 0 ] [ 2 ] ) ] ; const x = arrayMin ( xBounds ) ; const y = arrayMin ( yBounds ) ; label . align ( optionsLabel , false , { x , y , width : arrayMax ( xBounds ) - x , height : arrayMax ( yBounds ) - y } ) ; if ( ! label . alignValue || label . alignValue === 'left' ) { label . css ( { width : ( label . rotation === 90 ? axis . height - ( label . alignAttr . y - axis . top ) : axis . width - ( label . alignAttr . x - axis . left ) ) + 'px' } ) ; } label . show ( true ) ; } private function public getLabelText ( optionsLabel ) { return defined ( optionsLabel . formatter ) ? ( optionsLabel . formatter as FormatUtilities . FormatterCallback < PlotLineOrBand > ) . call ( this as any ) : optionsLabel . text ; } function public destroy ( ) { erase ( this . axis . plotLinesAndBands , this ) ; delete this . axis ; destroyObjectProperties ( this ) ; } } namespace PlotLineOrBand { export type Axis = PlotLineOrBandAxis . Composition ; } export default PlotLineOrBand ; typedef { Highcharts . XAxisPlotBandsOptions | Highcharts . YAxisPlotBandsOptions | Highcharts . ZAxisPlotBandsOptions } Highcharts . AxisPlotBandsOptions typedef { Highcharts . XAxisPlotBandsLabelOptions | Highcharts . YAxisPlotBandsLabelOptions | Highcharts . ZAxisPlotBandsLabelOptions } Highcharts . AxisPlotBandsLabelOptions typedef { Highcharts . XAxisPlotLinesOptions | Highcharts . YAxisPlotLinesOptions | Highcharts . ZAxisPlotLinesOptions } Highcharts . AxisPlotLinesOptions typedef { Highcharts . XAxisPlotLinesLabelOptions | Highcharts . YAxisPlotLinesLabelOptions | Highcharts . ZAxisPlotLinesLabelOptions } Highcharts . AxisPlotLinesLabelOptions ( '' ) ; productdesc type { Array < * > } product apioption since product type { boolean } default apioption type { Highcharts . ColorString } apioption type { number } default apioption type { string } since apioption sample sample type { Highcharts . ColorString | Highcharts . GradientColorObject | Highcharts . PatternObject } default apioption sample since apioption type { Highcharts . EventCallbackFunction < Highcharts . PlotLineOrBand > } apioption type { Highcharts . EventCallbackFunction < Highcharts . PlotLineOrBand > } apioption type { Highcharts . EventCallbackFunction < Highcharts . PlotLineOrBand > } apioption type { Highcharts . EventCallbackFunction < Highcharts . PlotLineOrBand > } apioption sample sample sample type { number } apioption sample sample type { string } apioption sample sample sample type { number } apioption sample sample sample type { number } since apioption product apioption sample sample type { Highcharts . AlignValue } default since apioption sample type { number } default since apioption sample type { Highcharts . CSSObject } since apioption type { string } since apioption sample type { Highcharts . AlignValue } since apioption type { boolean } default since apioption sample sample type { Highcharts . VerticalAlignValue } default since apioption sample sample type { number } since apioption sample sample type { number } since apioption type { Array < * > } product sample sample apioption sample since product type { boolean } default apioption type { string } since apioption sample sample type { Highcharts . ColorString } default apioption sample sample type { Highcharts . DashStyleValue } default since apioption sample since apioption type { Highcharts . EventCallbackFunction < Highcharts . PlotLineOrBand > } apioption type { Highcharts . EventCallbackFunction < Highcharts . PlotLineOrBand > } apioption type { Highcharts . EventCallbackFunction < Highcharts . PlotLineOrBand > } apioption type { Highcharts . EventCallbackFunction < Highcharts . PlotLineOrBand > } apioption sample type { string } apioption sample sample type { number } apioption sample sample type { number } default apioption sample sample sample type { number } since apioption apioption sample sample type { Highcharts . AlignValue } default since apioption sample type { Highcharts . FormatterCallbackFunction < Highcharts . PlotLineOrBand > } apioption sample type { number } since apioption sample type { Highcharts . CSSObject } since apioption type { string } since apioption sample type { Highcharts . AlignValue } since apioption type { boolean } default since apioption sample type { Highcharts . VerticalAlignValue } default default since apioption sample sample type { number } since apioption sample sample type { number } since apioption type { Array < * > } extends xAxis . plotBands apioption sample type { number | string } since product apioption sample type { number | string } default since product apioption sample type { number | string } default since product apioption type { Array < * > } extends xAxis . plotLines apioption ( '' ) ;