21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javafx.scene.chart; 27 28 import java.util.ArrayList; 29 import java.util.Iterator; 30 import java.util.List; 31 32 import javafx.animation.FadeTransition; 33 import javafx.animation.ParallelTransition; 34 import javafx.beans.NamedArg; 35 import javafx.collections.FXCollections; 36 import javafx.collections.ObservableList; 37 import javafx.scene.Node; 38 import javafx.scene.layout.StackPane; 39 import javafx.scene.shape.Ellipse; 40 import javafx.util.Duration; 41 42 import com.sun.javafx.charts.Legend.LegendItem; 43 44 /** 45 * Chart type that plots bubbles for the data points in a series. The extra value property of Data is used to represent 46 * the radius of the bubble it should be a java.lang.Number. 47 * @since JavaFX 2.0 48 */ 49 public class BubbleChart<X,Y> extends XYChart<X,Y> { 50 51 // -------------- CONSTRUCTORS ---------------------------------------------- 52 53 /** 54 * Construct a new BubbleChart with the given axis. BubbleChart does not use a Category Axis. 55 * Both X and Y axes should be of type NumberAxis. 56 * 57 * @param xAxis The x axis to use 58 * @param yAxis The y axis to use 59 */ 60 public BubbleChart(@NamedArg("xAxis") Axis<X> xAxis, @NamedArg("yAxis") Axis<Y> yAxis) { 216 removeSeriesFromDisplay(series); 217 } 218 219 } 220 221 /** 222 * Create a Bubble for a given data item if it doesn't already have a node 223 * 224 * 225 * @param series 226 * @param seriesIndex The index of the series containing the item 227 * @param item The data item to create node for 228 * @param itemIndex The index of the data item in the series 229 * @return Node used for given data item 230 */ 231 private Node createBubble(Series<X, Y> series, int seriesIndex, final Data<X,Y> item, int itemIndex) { 232 Node bubble = item.getNode(); 233 // check if bubble has already been created 234 if (bubble == null) { 235 bubble = new StackPane(); 236 item.setNode(bubble); 237 } 238 // set bubble styles 239 bubble.getStyleClass().setAll("chart-bubble", "series" + seriesIndex, "data" + itemIndex, 240 series.defaultColorStyleClass); 241 return bubble; 242 } 243 244 /** 245 * This is called when the range has been invalidated and we need to update it. If the axis are auto 246 * ranging then we compile a list of all data that the given axis has to plot and call invalidateRange() on the 247 * axis passing it that data. 248 */ 249 @Override protected void updateAxisRange() { 250 // For bubble chart we need to override this method as we need to let the axis know that they need to be able 251 // to cover the whole area occupied by the bubble not just its center data value 252 final Axis<X> xa = getXAxis(); 253 final Axis<Y> ya = getYAxis(); 254 List<X> xData = null; 255 List<Y> yData = null; | 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javafx.scene.chart; 27 28 import java.util.ArrayList; 29 import java.util.Iterator; 30 import java.util.List; 31 32 import javafx.animation.FadeTransition; 33 import javafx.animation.ParallelTransition; 34 import javafx.beans.NamedArg; 35 import javafx.collections.FXCollections; 36 import javafx.collections.ObservableList; 37 import javafx.scene.Node; 38 import javafx.scene.layout.StackPane; 39 import javafx.scene.shape.Ellipse; 40 import javafx.util.Duration; 41 import javafx.scene.AccessibleRole; 42 import javafx.application.Platform; 43 44 import com.sun.javafx.charts.Legend.LegendItem; 45 46 /** 47 * Chart type that plots bubbles for the data points in a series. The extra value property of Data is used to represent 48 * the radius of the bubble it should be a java.lang.Number. 49 * @since JavaFX 2.0 50 */ 51 public class BubbleChart<X,Y> extends XYChart<X,Y> { 52 53 // -------------- CONSTRUCTORS ---------------------------------------------- 54 55 /** 56 * Construct a new BubbleChart with the given axis. BubbleChart does not use a Category Axis. 57 * Both X and Y axes should be of type NumberAxis. 58 * 59 * @param xAxis The x axis to use 60 * @param yAxis The y axis to use 61 */ 62 public BubbleChart(@NamedArg("xAxis") Axis<X> xAxis, @NamedArg("yAxis") Axis<Y> yAxis) { 218 removeSeriesFromDisplay(series); 219 } 220 221 } 222 223 /** 224 * Create a Bubble for a given data item if it doesn't already have a node 225 * 226 * 227 * @param series 228 * @param seriesIndex The index of the series containing the item 229 * @param item The data item to create node for 230 * @param itemIndex The index of the data item in the series 231 * @return Node used for given data item 232 */ 233 private Node createBubble(Series<X, Y> series, int seriesIndex, final Data<X,Y> item, int itemIndex) { 234 Node bubble = item.getNode(); 235 // check if bubble has already been created 236 if (bubble == null) { 237 bubble = new StackPane(); 238 bubble.setAccessibleRole(AccessibleRole.TEXT); 239 bubble.setAccessibleRoleDescription("Bubble"); 240 bubble.focusTraversableProperty().bind(Platform.accessibilityActiveProperty()); 241 item.setNode(bubble); 242 } 243 // set bubble styles 244 bubble.getStyleClass().setAll("chart-bubble", "series" + seriesIndex, "data" + itemIndex, 245 series.defaultColorStyleClass); 246 return bubble; 247 } 248 249 /** 250 * This is called when the range has been invalidated and we need to update it. If the axis are auto 251 * ranging then we compile a list of all data that the given axis has to plot and call invalidateRange() on the 252 * axis passing it that data. 253 */ 254 @Override protected void updateAxisRange() { 255 // For bubble chart we need to override this method as we need to let the axis know that they need to be able 256 // to cover the whole area occupied by the bubble not just its center data value 257 final Axis<X> xa = getXAxis(); 258 final Axis<Y> ya = getYAxis(); 259 List<X> xData = null; 260 List<Y> yData = null; |