1 34 35 package org.krysalis.jcharts.axisChart; 36 37 38 import org.krysalis.jcharts.chartData.interfaces.IStockChartDataSet; 39 import org.krysalis.jcharts.chartData.interfaces.IDataSeries; 40 import org.krysalis.jcharts.imageMap.CircleMapArea; 41 import org.krysalis.jcharts.properties.StockChartProperties; 42 import org.krysalis.jcharts.properties.DataAxisProperties; 43 import org.krysalis.jcharts.types.StockChartDataType; 44 45 import java.awt.*; 46 import java.awt.geom.Line2D ; 47 48 49 54 abstract class StockChart 55 { 56 57 63 static final void render( AxisChart axisChart, IStockChartDataSet iStockChartDataSet ) 64 { 65 StockChartProperties stockChartProperties=(StockChartProperties) iStockChartDataSet.getChartTypeProperties(); 66 Graphics2D g2d=axisChart.getGraphics2D(); 67 68 DataAxisProperties dataAxisProperties= (DataAxisProperties) axisChart.getAxisProperties().getYAxisProperties(); 69 IDataSeries iDataSeries= (IDataSeries) axisChart.getIAxisDataSeries(); 70 71 72 75 76 Line2D.Float line=new Line2D.Float ( axisChart.getXAxis().getTickStart(), 78 0, 79 axisChart.getXAxis().getTickStart(), 80 0 ); 81 82 83 Line2D.Float openLine=null; 84 if( iStockChartDataSet.hasOpenValues() ) 85 { 86 openLine=new Line2D.Float ( axisChart.getXAxis().getTickStart() - stockChartProperties.getOpenPixelLength() - 1, 87 0, 88 axisChart.getXAxis().getTickStart() - 1, 89 0 ); 90 } 91 92 93 Line2D.Float closeLine=null; 94 if( iStockChartDataSet.hasCloseValues() ) 95 { 96 closeLine=new Line2D.Float ( axisChart.getXAxis().getTickStart() + 1, 97 0, 98 axisChart.getXAxis().getTickStart() + stockChartProperties.getClosePixelLength() + 1, 99 0 ); 100 } 101 102 103 for( int i=0; i < iStockChartDataSet.getNumberOfDataItems(); i++ ) 106 { 107 line.y1= axisChart.getYAxis().computeAxisCoordinate( axisChart.getYAxis().getOrigin(), 108 iStockChartDataSet.getLowValue( i ), 109 axisChart.getYAxis().getScaleCalculator().getMinValue() ); 110 line.y2= axisChart.getYAxis().computeAxisCoordinate( axisChart.getYAxis().getOrigin(), 111 iStockChartDataSet.getHighValue( i ), 112 axisChart.getYAxis().getScaleCalculator().getMinValue() ); 113 114 String label; 115 if( axisChart.getXAxis().getAxisLabelsGroup() != null ) 116 { 117 label = axisChart.getXAxis().getAxisLabelsGroup().getTextTag( i ).getText(); 118 } 119 else 120 { 121 label = null; 122 } 123 124 if( axisChart.getGenerateImageMapFlag() ) 126 { 127 axisChart.getImageMap().addImageMapArea( new CircleMapArea( line.x1, 128 line.y1, 129 iStockChartDataSet.getLowValue( i ), 130 label, 131 iStockChartDataSet.getLegendLabel( StockChartDataType.LOW.getInt() ) ) ); 132 133 axisChart.getImageMap().addImageMapArea( new CircleMapArea( line.x2, 134 line.y2, 135 iStockChartDataSet.getHighValue( i ), 136 label, 137 iStockChartDataSet.getLegendLabel( StockChartDataType.HIGH.getInt() ) ) ); 138 } 139 140 g2d.setPaint( iStockChartDataSet.getPaint( StockChartDataType.HIGH.getInt() ) ); 141 g2d.setStroke( stockChartProperties.getHiLowStroke() ); 142 g2d.draw( line ); 143 144 line.x1+=axisChart.getXAxis().getScalePixelWidth(); 145 line.x2=line.x1; 146 147 if( openLine != null ) 148 { 149 if( iStockChartDataSet.getOpenValue( i ) != Double.NaN ) 150 { 151 openLine.y1= axisChart.getYAxis().computeAxisCoordinate( axisChart.getYAxis().getOrigin(), 152 iStockChartDataSet.getOpenValue( i ), 153 axisChart.getYAxis().getScaleCalculator().getMinValue() ); 154 openLine.y2=openLine.y1; 155 156 g2d.setPaint( iStockChartDataSet.getPaint( StockChartDataType.OPEN.getInt() ) ); 157 g2d.setStroke( stockChartProperties.getOpenStroke() ); 158 g2d.draw( openLine ); 159 160 if( axisChart.getGenerateImageMapFlag() ) 162 { 163 axisChart.getImageMap().addImageMapArea( new CircleMapArea( openLine.x1, 164 openLine.y1, 165 iStockChartDataSet.getOpenValue( i ), 166 label, 167 iStockChartDataSet.getLegendLabel( StockChartDataType.OPEN.getInt() ) ) ); 168 } 169 170 openLine.x1+=axisChart.getXAxis().getScalePixelWidth(); 171 openLine.x2+=axisChart.getXAxis().getScalePixelWidth(); 172 } 173 } 174 175 if( closeLine != null ) 176 { 177 if( iStockChartDataSet.getOpenValue( i ) != Double.NaN ) 178 { 179 closeLine.y1= axisChart.getYAxis().computeAxisCoordinate( axisChart.getYAxis().getOrigin(), 180 iStockChartDataSet.getCloseValue( i ), 181 axisChart.getYAxis().getScaleCalculator().getMinValue() ); 182 closeLine.y2=closeLine.y1; 183 184 g2d.setPaint( iStockChartDataSet.getPaint( StockChartDataType.CLOSE.getInt() ) ); 185 g2d.setStroke( stockChartProperties.getCloseStroke() ); 186 g2d.draw( closeLine ); 187 188 if( axisChart.getGenerateImageMapFlag() ) 190 { 191 axisChart.getImageMap().addImageMapArea( new CircleMapArea( closeLine.x2, 192 closeLine.y2, 193 iStockChartDataSet.getCloseValue( i ), 194 label, 195 iStockChartDataSet.getLegendLabel( StockChartDataType.CLOSE.getInt() ) ) ); 196 } 197 198 closeLine.x1+=axisChart.getXAxis().getScalePixelWidth(); 199 closeLine.x2+=axisChart.getXAxis().getScalePixelWidth(); 200 } 201 } 202 } 203 } 204 205 } 206 | Popular Tags |