'use strict' ; import type Axis from '../Axis' ; import type PlotBandOptions from './PlotBandOptions' ; import type PlotLineOptions from './PlotLineOptions' ; import type PlotLineOrBand from './PlotLineOrBand' ; import type SVGPath from '../../Renderer/SVG/SVGPath' ; import U from '../../Utilities.js' ; const { erase , extend , isNumber } = U ; declare module '../AxisOptions' { interface AxisOptions { plotBands ? : Array < PlotBandOptions > ; plotLines ? : Array < PlotLineOptions > ; } } namespace PlotLineOrBandAxis { export declare class Composition extends Axis { addPlotBand ( options ) ; addPlotBandOrLine ( options , coll ? ) ; addPlotBandOrLine ( options , coll ? ) ; addPlotLine ( options ) ; getPlotBandPath ( from , to , options ? ) ; removePlotBand ( id ) ; removePlotBandOrLine ( id ) ; removePlotLine ( id ) ; } const composedClasses = [ ] ; let PlotLineOrBandClass ; private export function compose < T extends typeof Axis > ( PlotLineOrBandType , AxisClass ) { if ( ! PlotLineOrBandClass ) { PlotLineOrBandClass = PlotLineOrBandType ; } if ( composedClasses . indexOf ( AxisClass ) === - 1 ) { composedClasses . push ( AxisClass ) ; extend ( AxisClass . prototype , Additions . prototype as any ) ; } return AxisClass as ( T & typeof Composition ) ; } private class Additions { function param { number } from param { number } to param { Highcharts . AxisPlotBandsOptions | Highcharts . AxisPlotLinesOptions } options return { Highcharts . SVGPathArray } public getPlotBandPath ( this , from , to , options = this . options ) { const toPath = this . getPlotLinePath ( { value : to , force : true , acrossPanes : options . acrossPanes } ) , result = [ ] as SVGPath , horiz = this . horiz , outside = ! isNumber ( this . min ) || ! isNumber ( this . max ) || ( from < this . min && to < this . min ) || ( from > this . max && to > this . max ) ; let path = this . getPlotLinePath ( { value : from , force : true , acrossPanes : options . acrossPanes } ) , i , plus = 1 , isFlat ; if ( path && toPath ) { if ( outside ) { isFlat = path . toString ( ) === toPath . toString ( ) ; plus = 0 ; } for ( i = 0 ; i < path . length ; i += 2 ) { const pathStart = path [ i ] , pathEnd = path [ i + 1 ] , toPathStart = toPath [ i ] , toPathEnd = toPath [ i + 1 ] ; if ( ( pathStart [ 0 ] === 'M' || pathStart [ 0 ] === 'L' ) && ( pathEnd [ 0 ] === 'M' || pathEnd [ 0 ] === 'L' ) && ( toPathStart [ 0 ] === 'M' || toPathStart [ 0 ] === 'L' ) && ( toPathEnd [ 0 ] === 'M' || toPathEnd [ 0 ] === 'L' ) ) { if ( horiz && toPathStart [ 1 ] === pathStart [ 1 ] ) { toPathStart [ 1 ] += plus ; toPathEnd [ 1 ] += plus ; } else if ( ! horiz && toPathStart [ 2 ] === pathStart [ 2 ] ) { toPathStart [ 2 ] += plus ; toPathEnd [ 2 ] += plus ; } result . push ( [ 'M' , pathStart [ 1 ] , pathStart [ 2 ] ] , [ 'L' , pathEnd [ 1 ] , pathEnd [ 2 ] ] , [ 'L' , toPathEnd [ 1 ] , toPathEnd [ 2 ] ] , [ 'L' , toPathStart [ 1 ] , toPathStart [ 2 ] ] , [ 'Z' ] ) ; } ( result as any ) . isFlat = isFlat ; } } else { path = null ; } return result ; } sample function param { Highcharts . AxisPlotBandsOptions } options return { Highcharts . PlotLineOrBand | undefined } public addPlotBand ( this , options ) { return this . addPlotBandOrLine ( options , 'plotBands' ) ; } sample function param { Highcharts . AxisPlotLinesOptions } options return { Highcharts . PlotLineOrBand | undefined } public addPlotLine ( this , options ) { return this . addPlotBandOrLine ( options , 'plotLines' ) ; } private function param { Highcharts . AxisPlotBandsOptions | Highcharts . AxisPlotLinesOptions } options public addPlotBandOrLine < T extends PlotBandOptions | PlotLineOptions > ( this , options , coll ? ) { const userOptions = this . userOptions ; let obj = new PlotLineOrBandClass ( this , options ) ; if ( this . visible ) { obj = obj . render ( ) ; } if ( obj ) { if ( ! this . _addedPlotLB ) { this . _addedPlotLB = true ; ( userOptions . plotLines || [ ] ) . concat ( ( userOptions . plotBands as any ) || [ ] ) . forEach ( ( plotLineOptions ) : void => { this . addPlotBandOrLine ( plotLineOptions ) ; } ) ; } if ( coll ) { const updatedOptions = ( userOptions [ coll ] || [ ] ) as Array < T > ; updatedOptions . push ( options ) ; userOptions [ coll ] = updatedOptions ; } this . plotLinesAndBands . push ( obj ) ; } return obj ; } private function public removePlotBandOrLine ( this , id ) { const plotLinesAndBands = this . plotLinesAndBands , options = this . options , userOptions = this . userOptions ; if ( plotLinesAndBands ) { let i = plotLinesAndBands . length ; while ( i -- ) { if ( plotLinesAndBands [ i ] . id === id ) { plotLinesAndBands [ i ] . destroy ( ) ; } } ( [ options . plotLines || [ ] , userOptions . plotLines || [ ] , options . plotBands || [ ] , userOptions . plotBands || [ ] ] ) . forEach ( function ( arr ) : void { i = arr . length ; while ( i -- ) { if ( ( arr [ i ] || { } ) . id === id ) { erase ( arr , arr [ i ] ) ; } } } ) ; } } sample sample function param { string } id public removePlotBand ( this , id ) { this . removePlotBandOrLine ( id ) ; } sample sample function param { string } id public removePlotLine ( this , id ) { this . removePlotBandOrLine ( id ) ; } } } export default PlotLineOrBandAxis ;