diag = proj.fastProjectScaledToRenderSpace(diag);
// compute angle to diagonal line, used for axis labeling.
double diaga = Math.atan2(diag[1] - orig[1], diag[0] - orig[0]);
double alfontsize = 1.1 * context.getStyleLibrary().getTextSize(StyleLibrary.AXIS_LABEL);
CSSClass alcls = new CSSClass(AxisVisualization.class, "unmanaged");
alcls.setStatement(SVGConstants.CSS_FONT_SIZE_PROPERTY, SVGUtil.fmt(alfontsize));
alcls.setStatement(SVGConstants.CSS_FILL_PROPERTY, context.getStyleLibrary().getTextColor(StyleLibrary.AXIS_LABEL));
alcls.setStatement(SVGConstants.CSS_FONT_FAMILY_PROPERTY, context.getStyleLibrary().getFontFamily(StyleLibrary.AXIS_LABEL));
// draw axes
for(int d = 0; d < dim; d++) {
double[] v = new double[dim];
v[d] = 1;
// projected endpoint of axis
double[] ax = proj.fastProjectScaledToRenderSpace(v);
boolean righthand = false;
double axa = Math.atan2(ax[1] - orig[1], ax[0] - orig[0]);
if(axa > diaga || (diaga > 0 && axa > diaga + Math.PI)) {
righthand = true;
}
// System.err.println(ax.get(0) + " "+ ax.get(1)+
// " "+(axa*180/Math.PI)+" "+(diaga*180/Math.PI));
if(ax[0] != orig[0] || ax[1] != orig[1]) {
try {
SVGSimpleLinearAxis.drawAxis(svgp, layer, proj.getScale(d), orig[0], orig[1], ax[0], ax[1], righthand ? SVGSimpleLinearAxis.LabelStyle.RIGHTHAND : SVGSimpleLinearAxis.LabelStyle.LEFTHAND, context.getStyleLibrary());
// TODO: move axis labeling into drawAxis function.
double offx = (righthand ? 1 : -1) * 0.02 * Projection.SCALE;
double offy = (righthand ? 1 : -1) * 0.02 * Projection.SCALE;
Element label = svgp.svgText(ax[0] + offx, ax[1] + offy, DatabaseUtil.getColumnLabel(rel, d + 1));
SVGUtil.setAtt(label, SVGConstants.SVG_STYLE_ATTRIBUTE, alcls.inlineCSS());
SVGUtil.setAtt(label, SVGConstants.SVG_TEXT_ANCHOR_ATTRIBUTE, righthand ? SVGConstants.SVG_START_VALUE : SVGConstants.SVG_END_VALUE);
layer.appendChild(label);
}
catch(CSSNamingConflict e) {
throw new RuntimeException("Conflict in CSS naming for axes.", e);