Java Magazine, May/June 2018
ORACLE COM JAVAMAGAZINE MAY JUNE 2018 44 design patterns is randomized which helps visually indicate when each data set has been completely rendered Because the colors are random sometimes subsequent renders will look similar and other times not An interesting upgrade to this example would be to connect the color scheme to a JavaFX GUI control to allow the user to manipulate the colorations Recall the issue discussed earlier regarding transforming the data to screen space Typically with data visualization scenarios the numeric range of the data will not be in a numeric range that is workable for screen coordinates For example many data sets are normalized to a range of less than 10 and often have negative values To avoid using hardcoded scaling values determine the minimum maximum and range of the data coordinates and transform them to the screen and therefore Canvas coordinates using a method such as the following and the data maxima and minima I defined earlier private double transformXToScreen double x return x totalMinX canvas getWidth radius totalRangeX radius For coordinate transformations of graphical renderings I recommend simplifying your rendering code by separating the coordinate transformations into separate methods for both the x and y axes Placing these calculations in a separate method makes it easier to debug and profile the applications performance First Approach In the consumer Task I will investigate two small alternative patterns for retrieving and rendering the data each defined in separate methods The first approach which follows is a simple polling strategy that would look similar to a queue based implementation private int drawNext_ SimplePolling int size pointQueue size GraphicsContext g canvas getGraphicsContext2D
You must have JavaScript enabled to view digital editions.