import * as d3 from 'd3' ; import { GlyphType } from './glyph.type' ; import { GlyphConfiguration } from './glyph.configuration' ; import { FlowerGlyphConfiguration } from './glyph.flower.configuration' ; export abstract class Glyph { private _configuration : GlyphConfiguration ; public context : any ; color : any ; glyphType : GlyphType = GlyphType . Flower ; static rgbToString ( rgb ) { return 'rgb(' + rgb [ 0 ] + ', ' + rgb [ 1 ] + ', ' + rgb [ 2 ] + ')' ; } static inverseColorRgbFromRgb ( rgb ) { return rgb . map ( ( colorPartial ) => { return 255 - colorPartial ; } ) ; } static hexToRgb ( hex ) { const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i . exec ( hex ) ; return result ? [ parseInt ( result [ 1 ] , 16 ) , parseInt ( result [ 2 ] , 16 ) , parseInt ( result [ 3 ] , 16 ) ] : [ 0xFF , 0xFF , 0xFF ] ; } constructor ( context , color ) { this . color = color ; this . context = context ; this . _configuration = new FlowerGlyphConfiguration ; } abstract draw ( position , features , progress ? , isPassive ? , isHighlighted ? , animation ? ) ; abstract drawWithLabels ( datum , features , progress ? , isPassive ? , labels ? ) ; getCurrentScale ( linear , radius ) { return linear ? d3 . scaleLinear ( ) . clamp ( true ) . domain ( [ 0.1 , 100 ] ) . range ( [ 0 , radius ] ) : d3 . scaleLog ( ) . clamp ( true ) . domain ( [ 0.1 , 100 ] ) . range ( [ 0 , radius ] ) ; } get configuration ( ) { return this . _configuration ; } set configuration ( value ) { this . _configuration = value ; } }