}
@Override
public Visualization makeVisualization(VisualizationTask task) {
VisualizerContext context = task.getContext();
SVGPlot svgp = task.getPlot();
IterableResult<DoubleDoublePair> curve = task.getResult();
setupCSS(context, svgp);
double scale = StyleLibrary.SCALE;
final double sizex = scale;
final double sizey = scale * task.getHeight() / task.getWidth();
final double margin = context.getStyleLibrary().getSize(StyleLibrary.MARGIN);
Element layer = SVGUtil.svgElement(svgp.getDocument(), SVGConstants.SVG_G_TAG);
final String transform = SVGUtil.makeMarginTransform(task.getWidth(), task.getHeight(), sizex, sizey, margin);
SVGUtil.setAtt(layer, SVGConstants.SVG_TRANSFORM_ATTRIBUTE, transform);
// determine scaling
DoubleMinMax minmaxx = new DoubleMinMax();
DoubleMinMax minmaxy = new DoubleMinMax();
for(DoubleDoublePair pair : curve) {
minmaxx.put(pair.first);
minmaxy.put(pair.second);
}
LinearScale scalex = new LinearScale(minmaxx.getMin(), minmaxx.getMax());
LinearScale scaley = new LinearScale(minmaxy.getMin(), minmaxy.getMax());
// plot the line
SVGPath path = new SVGPath();
for(DoubleDoublePair pair : curve) {
final double x = scalex.getScaled(pair.first);
final double y = 1 - scaley.getScaled(pair.second);
path.drawTo(sizex * x, sizey * y);
}
Element line = path.makeElement(svgp);
line.setAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE, SERIESID);
// add axes
try {
SVGSimpleLinearAxis.drawAxis(svgp, layer, scalex, 0, sizey, sizex, sizey, true, true, context.getStyleLibrary());
SVGSimpleLinearAxis.drawAxis(svgp, layer, scaley, 0, sizey, 0, 0, true, false, context.getStyleLibrary());
}
catch(CSSNamingConflict e) {
LoggingUtil.exception(e);
}
// Add AUC value when found
if(curve instanceof ROCResult) {
Collection<String> header = ((ROCResult) curve).getHeader();
for(String str : header) {
String[] parts = str.split(":\\s*");
if(parts[0].equals(ComputeROCCurve.ROCAUC_LABEL) && parts.length == 2) {
double rocauc = Double.parseDouble(parts[1]);
StyleLibrary style = context.getStyleLibrary();
CSSClass cls = new CSSClass(svgp, "unmanaged");
String lt = "ROC AUC: " + FormatUtil.NF8.format(rocauc);
double fontsize = style.getTextSize("curve.labels");
cls.setStatement(SVGConstants.CSS_FONT_SIZE_PROPERTY, SVGUtil.fmt(fontsize));
cls.setStatement(SVGConstants.CSS_FILL_PROPERTY, style.getTextColor("curve.labels"));
cls.setStatement(SVGConstants.CSS_FONT_FAMILY_PROPERTY, style.getFontFamily("curve.labels"));
if(rocauc <= 0.5) {
Element auclbl = svgp.svgText(sizex * 0.95, sizey * 0.95, lt);
SVGUtil.setAtt(auclbl, SVGConstants.SVG_STYLE_ATTRIBUTE, cls.inlineCSS());
// SVGUtil.setAtt(auclbl, SVGConstants.SVG_TEXT_ANCHOR_ATTRIBUTE,
// SVGConstants.SVG_START_VALUE);
layer.appendChild(auclbl);
}
else {
Element auclbl = svgp.svgText(sizex * 0.95, sizey * 0.95, lt);
SVGUtil.setAtt(auclbl, SVGConstants.SVG_STYLE_ATTRIBUTE, cls.inlineCSS());
SVGUtil.setAtt(auclbl, SVGConstants.SVG_TEXT_ANCHOR_ATTRIBUTE, SVGConstants.SVG_END_VALUE);
layer.appendChild(auclbl);
}
}