package com.cloudera.flume.reporter.charts.google;
import java.util.List;
import com.cloudera.flume.reporter.history.TimelineChartGen;
import com.cloudera.util.Pair;
final String title;
final int height, width;
this.title = title;
this.height = height;
this.width = width;
}
this(title, 300, 300);
}
this(null, 300, 300);
}
return "chs=" + width + "x" + height;
}
@Override
public String
generate(List<Pair<Long, Long>> history) {
String title = "";
if (this.title != null) {
title = "&chtt=" + this.title;
}
String data = timeline(history);
return "<img src=\"" + GoogleHistogramChartGen.BASE_URL + size() + title + data
+ "\" />";
}
private String
timeline(List<Pair<Long, Long>> h) {
StringBuilder data = new StringBuilder();
long max = 0;
long sum = 0;
long cnt = h.size();
if (cnt == 0) {
return "";
}
for (Pair<Long, Long> p : h) {
max = p.getRight() > max ? p.getRight() : max;
cnt++;
sum += p.getRight();
if (data.length() == 0) {
data.append(p.getRight());
} else {
data.append("," + p.getRight());
}
}
String limits = "&chds=0," + (max * 3 / 2);
String axis = "&chxt=y,x&chxl=0:|0|" + (max * 3 / 2) + "|1:|0|" + cnt;
String charttype = "&cht=bvg";
if (cnt > 10) {
charttype = "&cht=lc";
}
return charttype + "&chd=t:" + data.toString() + limits + axis;
}
}