public JsDate f(JsArgs args) {
DaySummary d = args.getObject();
return d.jsDate;
}
}).range(0, w);
final PVLinearScale y = PV.Scale.linear(days, new JsDoubleFunction() {
public double f(JsArgs args) {
DaySummary d = args.getObject();
return d.low;
}
}, new JsDoubleFunction() {
public double f(JsArgs args) {
DaySummary d = args.getObject();
return d.high;
}
}).range(0, h).nice();
PVPanel vis = getPVPanel().width(w).height(h).margin(10).left(30);
/* Dates. */
vis.add(PV.Rule).data(x.ticks()).left(x).strokeStyle("#eee")
.anchor(BOTTOM).add(PV.Label).text(x.tickFormat());
/* Prices. */
vis.add(PV.Rule).data(y.ticks(7)).bottom(y).left(-10).right(-10)
.strokeStyle(new JsStringFunction() {
public String f(JsArgs args) {
double d = args.getDouble();
return d % 10 != 0 ? "#ccc" : "#333";
}
}).anchor(LEFT).add(PV.Label).textStyle(new JsStringFunction() {
public String f(JsArgs args) {
double d = args.getDouble();
return d % 10 != 0 ? "#999" : "#333";
}
}).text(y.tickFormat());
/* Candlestick. */
vis.add(PV.Rule).data(days).left(new JsDoubleFunction() {
public double f(JsArgs args) {
DaySummary d = args.getObject();
return x.fd(d.jsDate);
}
}).bottom(new JsDoubleFunction() {
public double f(JsArgs args) {
DaySummary d = args.getObject();
return y.fd(Math.min(d.high, d.low));
}
}).height(new JsDoubleFunction() {
public double f(JsArgs args) {
DaySummary d = args.getObject();
return Math.abs(y.fd(d.high) - y.fd(d.low));
}
}).strokeStyle(new JsStringFunction() {
public String f(JsArgs args) {
DaySummary d = args.getObject();
return d.open < d.close ? "#ae1325" : "#06982d";
}
}).add(PV.Rule).bottom(new JsDoubleFunction() {
public double f(JsArgs args) {
DaySummary d = args.getObject();
return y.fd(Math.min(d.open, d.close));
}
}).height(new JsDoubleFunction() {
public double f(JsArgs args) {
DaySummary d = args.getObject();
return Math.abs(y.fd(d.open) - y.fd(d.close));
}
}).lineWidth(10);