Code: Select all
public class TimeSeriesRollingIntradayGraph extends TChart {
private IntradayTradeStorage mIntradayTradeStorage;
private Line mSparkline;
private Line mPreviousClose;
public TimeSeriesRollingIntradayGraph(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
this.getZoom().setAllow(false);
this.getPanning().setAllow(ScrollMode.NONE);
this.getPanel().setColor(Color.WHITE);
this.getPanel().setBevelOuter(BevelStyle.NONE);
this.getPanel().setMarginLeft(0);
this.getPanel().setMarginRight(0);
this.getPanel().setMarginTop(0);
this.getPanel().setMarginBottom(0);
this.getPanel().setVisible(false);
this.getAspect().setView3D(false);
this.getLegend().setVisible(false);
this.getFooter().setVisible(false);
this.getHeader().setVisible(false);
this.getAxes().setVisible(false);
this.getAxes().getBottom().setAutomaticMinimum(false);
this.getAxes().getBottom().setAutomaticMaximum(false);
this.getAxes().getLeft().setMinimumOffset(2);
this.getAxes().getLeft().setMaximumOffset(2);
this.getAxes().getBottom().setMinimumOffset(2);
this.getAxes().getBottom().setMaximumOffset(2);
Walls walls = this.getWalls();
walls.setVisible(false);
this.setWalls(walls);
this.mSparkline = new Line();
mSparkline.setColor(Color.DARK_GRAY);
mSparkline.getLinePen().setWidth(2);
this.addSeries(mSparkline);
DashStyle previousCloseLineStyle = DashStyle.DASH;
previousCloseLineStyle.setDashWidth(3);
this.mPreviousClose = new Line();
mPreviousClose.setColor(Color.lightGray);
mPreviousClose.getLinePen().setStyle(previousCloseLineStyle);
mPreviousClose.getLinePen().setWidth(1);
this.addSeries(mPreviousClose);
}
public IntradayTradeStorage getIntradayTradeStorage() {
return mIntradayTradeStorage;
}
public void setIntradayTrades(IntradayTradeStorage anIntradayTradeStorage) {
mSparkline.clear();
this.mIntradayTradeStorage = anIntradayTradeStorage;
if (anIntradayTradeStorage != null) {
Instrument instrument = anIntradayTradeStorage.getInstrument();
Feed feed = instrument.getFeed();
Date exchangeStartTime = feed.getStartTime();
Date exchangeEndTime = feed.getEndTime();
if (exchangeStartTime != null && exchangeEndTime != null) {
this.getAxes().getBottom().setMinimum(exchangeStartTime.getTime());
this.getAxes().getBottom().setMaximum(exchangeEndTime.getTime());
}
for (IntradayTrade intradayTrade : anIntradayTradeStorage.getIntradayTrades()) {
double x = intradayTrade.getDate().getTime();
double y = intradayTrade.getLast().doubleValue();
mSparkline.add(x, y);
}
}
}
public void setPreviousClose(Double previousClose) {
mPreviousClose.clear();
if (previousClose != null) {
mPreviousClose.add(this.getAxes().getBottom().getMinimum(), previousClose.doubleValue());
mPreviousClose.add(this.getAxes().getBottom().getMaximum(), previousClose.doubleValue());
}
}
}