for(double val : bin.second) {
minmax.put(val);
}
}
LinearScale yscale = new LinearScale(0, minmax.getMax());
LinearScale xscale = new LinearScale(histogram.getCoverMinimum(), histogram.getCoverMaximum());
// Axis. TODO: Use AxisVisualizer for this?
try {
SVGSimpleLinearAxis.drawAxis(svgp, layer, yscale, 0, ysize, 0, 0, true, false, context.getStyleLibrary());
// draw axes that are non-trivial
final int dimensionality = DatabaseUtil.dimensionality(relation);
double orig = proj.fastProjectScaledToRender(new Vector(dimensionality));
for(int d = 0; d < dimensionality; d++) {
Vector v = new Vector(dimensionality);
v.set(d, 1);
// projected endpoint of axis
double ax = proj.fastProjectScaledToRender(v);
if(ax != orig) {
final double left = (orig / Projection.SCALE + 0.5) * xsize;
final double right = (ax / Projection.SCALE + 0.5) * xsize;
SVGSimpleLinearAxis.drawAxis(svgp, layer, proj.getScale(d), left, ysize, right, ysize, true, true, context.getStyleLibrary());
}
}
}
catch(CSSNamingConflict e) {
LoggingUtil.exception("CSS class exception in axis class.", e);
}
double binwidth = histogram.getBinsize();
// Visualizing
if(!curves) {
for(Pair<Double, double[]> bin : histogram) {
double lpos = xscale.getScaled(bin.getFirst() - binwidth / 2);
double rpos = xscale.getScaled(bin.getFirst() + binwidth / 2);
double stack = 0.0;
final int start = numc > 0 ? 1 : 0;
for(int key = start; key < cols; key++) {
double val = yscale.getScaled(bin.getSecond()[key]);
Element row = SVGUtil.svgRect(svgp.getDocument(), xsize * lpos, ysize * (1 - (val + stack)), xsize * (rpos - lpos), ysize * val);
stack = stack + val;
SVGUtil.addCSSClass(row, BIN + (key - 1));
layer.appendChild(row);
}
}
}
else {
double left = xscale.getScaled(histogram.getCoverMinimum());
double right = left;
SVGPath[] paths = new SVGPath[cols];
double[] lasty = new double[cols];
for(int i = 0; i < cols; i++) {
paths[i] = new SVGPath(xsize * left, ysize * 1);
lasty[i] = 0;
}
// draw histogram lines
for(Pair<Double, double[]> bin : histogram) {
left = xscale.getScaled(bin.getFirst() - binwidth / 2);
right = xscale.getScaled(bin.getFirst() + binwidth / 2);
for(int i = 0; i < cols; i++) {
double val = yscale.getScaled(bin.getSecond()[i]);
if(lasty[i] != val) {
paths[i].lineTo(xsize * left, ysize * (1 - lasty[i]));
paths[i].lineTo(xsize * left, ysize * (1 - val));