'use strict' ; import type SVGPath from './SVGPath' ; import type SymbolOptions from './SymbolOptions' ; import type { SymbolTypeRegistry } from './SymbolType' ; import U from '../../Utilities.js' ; const { defined , isNumber , pick } = U ; function arc ( x , y , w , h , options ? ) { const arc = [ ] ; if ( options ) { const start = options . start || 0 , rx = pick ( options . r , w ) , ry = pick ( options . r , h || w ) , proximity = 0.001 , fullCircle = ( Math . abs ( ( options . end || 0 ) - start - 2 * Math . PI ) < proximity ) , end = ( options . end || 0 ) - proximity , innerRadius = options . innerR , open = pick ( options . open , fullCircle ) , cosStart = Math . cos ( start ) , sinStart = Math . sin ( start ) , cosEnd = Math . cos ( end ) , sinEnd = Math . sin ( end ) , longArc = pick ( options . longArc , end - start - Math . PI < proximity ? 0 : 1 ) ; arc . push ( [ 'M' , x + rx * cosStart , y + ry * sinStart ] , [ 'A' , rx , ry , 0 , longArc , pick ( options . clockwise , 1 ) , x + rx * cosEnd , y + ry * sinEnd ] ) ; if ( defined ( innerRadius ) ) { arc . push ( open ? [ 'M' , x + innerRadius * cosEnd , y + innerRadius * sinEnd ] : [ 'L' , x + innerRadius * cosEnd , y + innerRadius * sinEnd ] , [ 'A' , innerRadius , innerRadius , 0 , longArc , defined ( options . clockwise ) ? 1 - options . clockwise : 0 , x + innerRadius * cosStart , y + innerRadius * sinStart ] ) ; } if ( ! open ) { arc . push ( [ 'Z' ] ) ; } } return arc ; } /**
 * Callout shape used for default tooltips, also used for rounded
 * rectangles in VML
 */ function callout ( x , y , w , h , options ? ) { const arrowLength = 6 , halfDistance = 6 , r = Math . min ( ( options && options . r ) || 0 , w , h ) , safeDistance = r + halfDistance , anchorX = options && options . anchorX , anchorY = options && options . anchorY || 0 ; const path = roundedRect ( x , y , w , h , { r } ) ; if ( ! isNumber ( anchorX ) ) { return path ; } if ( x + anchorX >= w ) { if ( anchorY > y + safeDistance && anchorY < y + h - safeDistance ) { path . splice ( 3 , 1 , [ 'L' , x + w , anchorY - halfDistance ] , [ 'L' , x + w + arrowLength , anchorY ] , [ 'L' , x + w , anchorY + halfDistance ] , [ 'L' , x + w , y + h - r ] ) ; } else { path . splice ( 3 , 1 , [ 'L' , x + w , h / 2 ] , [ 'L' , anchorX , anchorY ] , [ 'L' , x + w , h / 2 ] , [ 'L' , x + w , y + h - r ] ) ; } } else if ( x + anchorX <= 0 ) { if ( anchorY > y + safeDistance && anchorY < y + h - safeDistance ) { path . splice ( 7 , 1 , [ 'L' , x , anchorY + halfDistance ] , [ 'L' , x - arrowLength , anchorY ] , [ 'L' , x , anchorY - halfDistance ] , [ 'L' , x , y + r ] ) ; } else { path . splice ( 7 , 1 , [ 'L' , x , h / 2 ] , [ 'L' , anchorX , anchorY ] , [ 'L' , x , h / 2 ] , [ 'L' , x , y + r ] ) ; } } else if ( anchorY && anchorY > h && anchorX > x + safeDistance && anchorX < x + w - safeDistance ) { path . splice ( 5 , 1 , [ 'L' , anchorX + halfDistance , y + h ] , [ 'L' , anchorX , y + h + arrowLength ] , [ 'L' , anchorX - halfDistance , y + h ] , [ 'L' , x + r , y + h ] ) ; } else if ( anchorY && anchorY < 0 && anchorX > x + safeDistance && anchorX < x + w - safeDistance ) { path . splice ( 1 , 1 , [ 'L' , anchorX - halfDistance , y ] , [ 'L' , anchorX , y - arrowLength ] , [ 'L' , anchorX + halfDistance , y ] , [ 'L' , w - r , y ] ) ; } return path ; } function circle ( x , y , w , h ) { return arc ( x + w / 2 , y + h / 2 , w / 2 , h / 2 , { start : Math . PI * 0.5 , end : Math . PI * 2.5 , open : false } ) ; } function diamond ( x , y , w , h ) { return [ [ 'M' , x + w / 2 , y ] , [ 'L' , x + w , y + h / 2 ] , [ 'L' , x + w / 2 , y + h ] , [ 'L' , x , y + h / 2 ] , [ 'Z' ] ] ; } function rect ( x , y , w , h , options ? ) { if ( options && options . r ) { return roundedRect ( x , y , w , h , options ) ; } return [ [ 'M' , x , y ] , [ 'L' , x + w , y ] , [ 'L' , x + w , y + h ] , [ 'L' , x , y + h ] , [ 'Z' ] ] ; } function roundedRect ( x , y , w , h , options ? ) { const r = ( options && options . r ) || 0 ; return [ [ 'M' , x + r , y ] , [ 'L' , x + w - r , y ] , [ 'C' , x + w , y , x + w , y , x + w , y + r ] , [ 'L' , x + w , y + h - r ] , [ 'C' , x + w , y + h , x + w , y + h , x + w - r , y + h ] , [ 'L' , x + r , y + h ] , [ 'C' , x , y + h , x , y + h , x , y + h - r ] , [ 'L' , x , y + r ] , [ 'C' , x , y , x , y , x + r , y ] ] ; } function triangle ( x , y , w , h ) { return [ [ 'M' , x + w / 2 , y ] , [ 'L' , x + w , y + h ] , [ 'L' , x , y + h ] , [ 'Z' ] ] ; } function triangleDown ( x , y , w , h ) { return [ [ 'M' , x , y ] , [ 'L' , x + w , y ] , [ 'L' , x + w / 2 , y + h ] , [ 'Z' ] ] ; } declare module './SymbolType' { interface SymbolTypeRegistry { arc : typeof arc ; callout : typeof callout ; circle : typeof circle ; diamond : typeof diamond ; rect : typeof rect ; roundedRect : typeof roundedRect ; square : typeof rect ; triangle : typeof triangle ; 'triangle-down' : typeof triangleDown ; } } const Symbols = { arc , callout , circle , diamond , rect , roundedRect , square : rect , triangle , 'triangle-down' : triangleDown } as SymbolTypeRegistry ; export default Symbols ;