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: Add an AxisVisualizer for this?
try {
SVGSimpleLinearAxis.drawAxis(svgp, layer, yscale, 0, ysize, 0, 0, SVGSimpleLinearAxis.LabelStyle.LEFTHAND, 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, SVGSimpleLinearAxis.LabelStyle.RIGHTHAND, context.getStyleLibrary());
}
}
}
catch(CSSNamingConflict e) {
LoggingUtil.exception("CSS class exception in axis class.", e);
}
double binwidth = histogram.getBinsize();
// Visualizing
if(!curves) {
for(DoubleObjPair<double[]> bin : histogram) {
double lpos = xscale.getScaled(bin.first - binwidth / 2);
double rpos = xscale.getScaled(bin.first + 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 + (off + 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(DoubleObjPair<double[]> bin : histogram) {
left = xscale.getScaled(bin.first - binwidth / 2);
right = xscale.getScaled(bin.first + 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));