Javafx Shapes 2 ("DataViz")
Actual Arrivals |
The Data
By challenge i mean it made me see the advantages of Streams (java 8),i will just show an example of the query i used to calculate the sum of the year quarters,
Optional<Double> sum=lines.stream()
.filter(word->word.contains("1991") && word.contains("Departures") && word.contains("Actual"))
.map(word->word.split(",")[3]) //column 3 Visitors on Holiday
.map(word->Double.valueOf(word))
.reduce(Double::sum);
calculate the width of the CubicCurve
MAX_VAL=3732600
MAX_WIDTH=20;
double d=Math.sqrt(Math.pow(MAX_WIDTH,2) * sum.orElse(0.0) / MAX_VAL);
NB: sum.orElse(0.0) its important to use this and not sum.get(),some years return "No value present" cause no actual data present. 2004,1999,2009.
The Visuals
Drawing the circle i just used a method in a previous post,every label is given an year ID "label.setId("1991").
The CubicCurve ControlX1,ControlX2,ControlY1,ControlY2 are at the center of the circle ,the startX,startY on MouseClicked gets Node(Circle) LayoutX and LayoutY and the endX,endY i use the lookup method.
Node n=root.lookup("#"+year);//looking for a label with id year
cubicCurve.setEndX(n.getLayoutX());
cubicCurve.setEndY(n.getLayoutY());
The angle i decided to add Circles instead of labels were 12 and 348,and skipping angle 0 and 336 for spacing,the two circles have ids visitor_on_holiday and visitor_on_business ,using the lookup method you can easily find any Node in the AnchorPane.
Not too much coding cause i feel nothing new here apart from the neat Stream query above,the rest are somewhere in my previous posts.
The Results
Actual Departure On Transit and Others |
Actual Departure |
Preliminary Departure Holiday |
Preliminary Departure Business |
Comments
Post a Comment