Legal Terms and Copyright Notice
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
*
* Copyright © 2010, Oracle and/or its affiliates. All rights reserved.
* Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
* Other names may be trademarks of their respective owners.
*
* This file is available and licensed under the following license:
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice,
trademark notice, this list of conditions, and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
trademark notice, this list of conditions, and the following disclaimer in
the documentation and/or other materials provided with the distribution.
* * Neither the name of Oracle nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package bulletgraph;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
/**
* @author Vaibhav
*/
/* Class Bullet - For one Instance of Bullet in Bullet Graph */
public class Bullet extends CustomNode {
/*expected and achieved */
public var expected = 0.0;
public var achieved = 0.0;
/* range for performace */
public var below = 0.0;
public var avg = 0.0;
public var good = 0.0;
/* timeline variation */
public var len = 0.0;
/* Main and SubText */
public var txt: String;
public var subtxt: String;
public var startdelay: Duration;
public var endtime: Duration;
/* animate the achieved bar */
public var t1 = Timeline {
repeatCount: 1
keyFrames: [
KeyFrame {
time: startdelay
canSkip: true
values: [
len => 0
]
} //close KeyFrame
KeyFrame {
time: endtime
canSkip: true
values: [
len => //Convert actual value to correct # of pixels
240 * achieved / good tween Interpolator.LINEAR
]
}
]
}
init {
t1.playFromStart();
}
public override function create(): Node {
return Group {
content: [
Rectangle { //Create 'average' portion of bar
cache: true
opacity: 0.4
x: 100 + 240 * below / good,
y: 50
width: 240 * avg / good - 240 * below / good,
height: 35
fill: LinearGradient {
startX: 0.0
startY: 0.0
endX: 0.0
endY: 1.0
stops: [
Stop {
color: Color.SILVER
offset: 0.0
},
Stop {
color: Color.LIGHTGRAY
offset: 0.5
},
Stop {
color: Color.SILVER
offset: 1.0
},
]
}
}
Rectangle { //Create 'poor' portion of bar
cache: true
opacity: 1.0
x: 100,
y: 50
width: 240 * below / good,
height: 35
fill: LinearGradient {
startX: 0.0
startY: 0.0
endX: 0.0
endY: 1.0
stops: [
Stop {
color: Color.SILVER
offset: 0.0
},
Stop {
color: Color.DARKGREY
offset: 0.5
},
Stop {
color: Color.SILVER
offset: 1.0
},
]
}
}
/* Create bar that underlies entire length and also displays 'good' portion */
Rectangle {
cache: true
opacity: 0.4
x: 100,
y: 50
width: 240,
height: 35
fill: LinearGradient {
startX: 0.0
startY: 0.0
endX: 0.0
endY: 1.0
stops: [
Stop {
color: Color.SILVER
offset: 0.0
},
Stop {
color: Color.LIGHTGRAY
offset: 0.5
},
Stop {
color: Color.SILVER
offset: 1.0
},
]
}
stroke: Color.GRAY
},
Rectangle { // bar for actual values
cache: true
opacity: 1
x: 100,
y: 63
width: bind len,
height: 10
fill: LinearGradient {
startX: 0.0
startY: 0.0
endX: 0.0
endY: 1.0
stops: [
Stop {
color: Color.YELLOWGREEN
offset: 0.0
},
Stop {
color: Color.GREEN
offset: 1.0
},
]
}
}
// vertical line for predicted value
Rectangle {
cache: true
x: 100 + 240 * expected / good,
y: 50
width: 3,
height: 36
fill: Color.BLACK
},
Text { //Text label to left of bar
fill: Color.GRAY
font: Font {
size: 13
name: "Arial Bold"
}
x: 35,
y: 72
content: txt
}
Text { //Text sublabel to left of bar
fill: Color.GRAY
font: Font {
size: 8
name: "Arial Bold"
}
x: 60,
y: 80
content: subtxt
}
/* Tick marks and labels */
Group {
cache: true
content: for(i in [0..4]) { [
Line {
startX: 340 - i * (240 / 4)
startY: 90
endX: 340 - i * (240 / 4)
endY: 95
strokeWidth: 1
stroke: Color.BLACK
},
Text {
font: Font {
size: 11
name: "Arial Bold"
}
x: 95 + i * (240 / 4),
y: 110
content: "{(i)*good/4}"
}
]
}
}
]
};
}
}