plotter.setZeroLevel(currentZeroCoordinate);
// Create the rendering graphs
List<Graph> graphs = new ArrayList<Graph>();
for (int g = 0; g < widget.getNumGraphs(); g++) {
Graph graph = new Graph();
double fillalpha = 0;
double alpha = 0;
// Set Fill color
List<Integer> fillcolors = getFillColors(g);
if (fillcolors != null && fillcolors.size() == 4) {
fillalpha = fillcolors.get(3) / 255.0;
graph.setFillColor("rgba(" + fillcolors.get(0) + ","
+ fillcolors.get(1) + "," + fillcolors.get(2) + ","
+ fillalpha + ")");
} else {
VConsole.error("Could not plot graph " + g
+ " since fill color is missing");
continue;
}
// Set color
List<Integer> colors = getColors(g);
if (colors != null && colors.size() == 4) {
alpha = colors.get(3) / 255.0;
graph.setColor("rgba(" + colors.get(0) + "," + colors.get(1)
+ "," + colors.get(2) + "," + alpha + ")");
} else {
VConsole.error("Could not plot graph " + g
+ " since color is missing");
continue;
}
if (fillalpha == 0 && alpha == 0) {
// Graph is invisible, ignore drawing it
continue;
}
// Set line thickness
graph.setLineThickness(getLineThickness(g));
// Set line caps
graph.setLinecaps(getLineCaps(g));
// Normalize values
List<Float> normalizedValues = pointValues.get(g);
// Add points to graph
List<Date> dates = pointDates.get(g);
if (dates != null && dates.size() > 0) {
Date startDate = dates.get(0);
Long timeFromStart = startDate.getTime() - startTime;
float lastX = 0;
int lastWidth = 0;
for (int i = 0; i < normalizedValues.size(); i++) {
Float value = normalizedValues.get(i);
Date date = dates.get(i);
timeFromStart = date.getTime() - startTime;
float y = currentZeroCoordinate - value * yUnit;
float x = timeFromStart * xUnit;
Point p;
if (normalizedValues.size() == 1) {
/*
* Special behaviour for a graph with one point since we
* cannot calculate the width for it
*/
p = new Point(Math.round(x), Math.round(y), graph, 1,
value);
lastWidth = 1;
} else if (i == 0) {
/*
* Setting width for the first point to zero
*/
Date d = dates.get(1);
timeFromStart = d.getTime() - startTime;
lastWidth = 0;
p = new Point(Math.round(x), Math.round(y), graph,
lastWidth, value);
} else {
/*
* Other points calculate backwards
*/
if (getPlotMode() == PlotMode.BAR) {
// MT 22.3.2013: I have no idea why some points are
// ignored. Without this bars get totally messed,
// but without essential points may be dropped in
// lines (no 1 priority)
int diff = Math.round(x - lastX);
if (diff > 2) {
lastWidth = diff;
p = new Point(Math.round(x), Math.round(y),
graph, lastWidth, value);
} else {
p = null;
}
} else {
p = new Point(Math.round(x), Math.round(y), graph,
lastWidth, value);
}
}
if (p != null) {
graph.addPoint(p);
lastX = x;
}
}
}