import { Glyph } from './glyph' ; import { GlyphType } from './glyph.type' ; import { DotGlyphConfiguration } from './glyph.dot.configuration' ; export class DotGlyph extends Glyph { private preferredRadius = 3.5 ; constructor ( context , color , configuration ) { super ( context , color ) ; this . configuration = configuration ; this . glyphType = GlyphType . Dot ; } public draw ( position , features , progress ? , isPassive ? , isHighlighted ? , animationProgress ? ) { if ( isPassive === undefined ) { isPassive = false ; } if ( isHighlighted === undefined ) { isHighlighted = false ; } progress = ( progress || 1 ) ; let rad = this . dotConfig ( ) . drawAggregate ? position . weight / this . preferredRadius : this . preferredRadius ; if ( rad >= 8 ) { rad = 8 ; } if ( rad <= this . preferredRadius ) { rad = this . preferredRadius ; } const radius = isHighlighted ? rad * 1.3 * progress : rad * progress ; const opacity = 1 - ( ( animationProgress === undefined ) ? 0 : animationProgress ) ; const inverseColorRGB = Glyph . inverseColorRgbFromRgb ( Glyph . hexToRgb ( this . color ( features ) ) ) ; this . context . globalCompositeOperation = isPassive ? 'destination-over' : 'source-over' ; if ( isHighlighted ) { this . context . beginPath ( ) ; this . context . fillStyle = 'rgba(' + inverseColorRGB [ 0 ] + ', ' + inverseColorRGB [ 1 ] + ', ' + inverseColorRGB [ 2 ] + ', ' + opacity + ')' ; if ( animationProgress === undefined ) animationProgress = 1 ; this . context . arc ( position . x , position . y , radius + ( animationProgress * 20 ) , 0 , 2 * Math . PI ) ; this . context . fill ( ) ; } const fillColor = isPassive ? '#ccc' : this . color ( features ) ; this . context . fillStyle = fillColor ; this . context . strokeStyle = fillColor ; this . context . lineWidth = isHighlighted ? 5 : 1 ; this . context . beginPath ( ) ; this . context . arc ( position . x , position . y , radius , 0 , 2 * Math . PI ) ; if ( position . weight === undefined || position . weight === 1 || ! this . dotConfig ( ) . drawAggregate ) { this . context . fill ( ) ; } else { this . context . stroke ( ) ; } } public drawWithLabels ( position , features , progress ? ) { return this . draw ( position , features , progress ) ; } public dotConfig ( ) { return this . configuration as DotGlyphConfiguration ; } }