package binky.ofc2plugin.charts.elements;
import java.util.LinkedList;
import java.util.List;
import org.json.simple.JSONObject;
import binky.ofc2plugin.charts.json.OFCNumber;
public class ElementPie extends Element {
private List<String> coloursHex = new LinkedList<String>();
private int startAngle = 0;
private int stroke = 1;
private AnimateType animate = AnimateType.Fade;
private List<JSONObject> pieValues = new LinkedList<JSONObject>();
public enum AnimateType {
Fade("Fade"), Bounce("bounce");
private String displayName;
AnimateType(String displayName) {
this.displayName = displayName;
}
public String getName() {
return name();
}
public String getDisplayName() {
return displayName;
}
}
public ElementPie() {
super.elementName = PIE_NAME;
}
public List<String> getColoursHex() {
return coloursHex;
}
public void setColoursHex(List<String> coloursHex) {
this.coloursHex = coloursHex;
}
public int getStartAngle() {
return startAngle;
}
public void setStartAngle(int startAngle) {
this.startAngle = startAngle;
}
public int getStroke() {
return stroke;
}
public void setStroke(int stroke) {
this.stroke = stroke;
}
@SuppressWarnings("unchecked")
@Override
public JSONObject encode() {
JSONObject me = new JSONObject();
me.put("type", elementName);
me.put("alpha", super.getAlpha());
me.put("colour", super.getColourHex());
me.put("font-size", super.getFontSizePx());
me.put("colours", this.coloursHex);
me.put("stroke", this.stroke);
List<JSONObject> animates = new LinkedList<JSONObject>();
//hack to get the animations in - will make this configurable
JSONObject animateJson = new JSONObject();
animateJson.put("type", this.animate.getDisplayName());
JSONObject animateJsonMOver = new JSONObject();
animateJsonMOver.put("type", AnimateType.Bounce.getDisplayName());
animateJsonMOver.put("distance", 5);
animates.add( animateJson);
animates.add(animateJsonMOver);
me.put("animate", animates);
me.put("values", pieValues);
return me;
}
@SuppressWarnings("unchecked")
public void addPieValue(String label, Number value) {
JSONObject v= new JSONObject();
v.put("value", new OFCNumber(value));
v.put("label",label);
this.pieValues.add(v);
}
}