public Element build ( SVGPlot svgp , double x , double y , double width , double height ) { Element barchart = svgp . svgElement ( SVGConstants . SVG_G_TAG ) ; // TODO: use style library for colors! Element bar = svgp . svgRect ( x , y , width , height ) ; bar . setAttribute ( SVGConstants . SVG_FILL_ATTRIBUTE , "#a0a0a0" ) ; bar . setAttribute ( SVGConstants . SVG_STROKE_ATTRIBUTE , "#a0a0a0" ) ; bar . setAttribute ( SVGConstants . SVG_STROKE_WIDTH_ATTRIBUTE , String . valueOf ( height * 0.01 ) ) ; barchart . appendChild ( bar ) ; if ( val >= min && val <= max && min < max ) { final double frame = 0.02 * height ; double fpos = ( val - min ) / ( max - min ) * ( width - 2 * frame ) ; Element chart ; if ( reversed ) { chart = svgp . svgRect ( x + frame + fpos , y + frame , width - fpos - 2 * frame , height - 2 * frame ) ; } else { chart = svgp . svgRect ( x + frame , y + frame , fpos , height - 2 * frame ) ; } chart . setAttribute ( SVGConstants . SVG_FILL_ATTRIBUTE , "#d4e4f1" ) ; chart . setAttribute ( SVGConstants . SVG_STROKE_ATTRIBUTE , "#a0a0a0" ) ; chart . setAttribute ( SVGConstants . SVG_STROKE_WIDTH_ATTRIBUTE , String . valueOf ( height * 0.01 ) ) ; barchart . appendChild ( chart ) ; } // Draw the values: if ( format != null ) { String num = Double . isNaN ( val ) ? "NaN" : format . format ( val ) ; Element lbl = svgp . svgText ( x + 0.05 * width , y + 0.75 * height , num ) ; lbl . setAttribute ( SVGConstants . SVG_STYLE_ATTRIBUTE , "font-size: " + 0.75 * height + "; font-weight: bold" ) ; barchart . appendChild ( lbl ) ; } // Draw the label if ( label != null ) { Element lbl = svgp . svgText ( x + 1.05 * width , y + 0.75 * height , label ) ; lbl . setAttribute ( SVGConstants . SVG_STYLE_ATTRIBUTE , "font-size: " + 0.75 * height + "; font-weight: normal" ) ; barchart . appendChild ( lbl ) ; } return barchart ; }
Build the actual element