use of de.lmu.ifi.dbs.elki.visualization.visualizers.StaticVisualizationInstance in project elki by elki-project.
the class HistogramVisualization method makeVisualization.
@Override
public Visualization makeVisualization(VisualizerContext context, VisualizationTask task, VisualizationPlot plot, double width, double height, Projection proj) {
HistogramResult curve = task.getResult();
final StyleLibrary style = context.getStyleLibrary();
final double sizex = StyleLibrary.SCALE;
final double sizey = StyleLibrary.SCALE * height / width;
final double margin = style.getSize(StyleLibrary.MARGIN);
Element layer = SVGUtil.svgElement(plot.getDocument(), SVGConstants.SVG_G_TAG);
final String transform = SVGUtil.makeMarginTransform(width, height, sizex, sizey, margin);
SVGUtil.setAtt(layer, SVGConstants.SVG_TRANSFORM_ATTRIBUTE, transform);
// find maximum, determine step size
int dim = -1;
DoubleMinMax xminmax = new DoubleMinMax();
DoubleMinMax yminmax = new DoubleMinMax();
for (double[] point : curve) {
xminmax.put(point[0]);
dim = dim < point.length ? point.length : dim;
for (int i = 1; i < point.length; i++) {
yminmax.put(point[i]);
}
}
// Minimum should always start at 0 for histograms
yminmax.put(0.0);
// remove one dimension which are the x values.
dim = dim - 1;
int size = curve.size();
double range = xminmax.getMax() - xminmax.getMin();
double binwidth = range / (size - 1);
LinearScale xscale = new LinearScale(xminmax.getMin() - binwidth * .49999, xminmax.getMax() + binwidth * .49999);
LinearScale yscale = new LinearScale(yminmax.getMin(), yminmax.getMax());
SVGPath[] path = new SVGPath[dim];
for (int i = 0; i < dim; i++) {
path[i] = new SVGPath(sizex * xscale.getScaled(xminmax.getMin() - binwidth * .5), sizey);
}
// draw curves.
for (double[] point : curve) {
for (int d = 0; d < dim; d++) {
path[d].lineTo(sizex * (xscale.getScaled(point[0] - binwidth * .5)), sizey * (1 - yscale.getScaled(point[d + 1])));
path[d].lineTo(sizex * (xscale.getScaled(point[0] + binwidth * .5)), sizey * (1 - yscale.getScaled(point[d + 1])));
}
}
// close all histograms
for (int i = 0; i < dim; i++) {
path[i].lineTo(sizex * xscale.getScaled(xminmax.getMax() + binwidth * .5), sizey);
}
// add axes
try {
SVGSimpleLinearAxis.drawAxis(plot, layer, yscale, 0, sizey, 0, 0, SVGSimpleLinearAxis.LabelStyle.LEFTHAND, style);
SVGSimpleLinearAxis.drawAxis(plot, layer, xscale, 0, sizey, sizex, sizey, SVGSimpleLinearAxis.LabelStyle.RIGHTHAND, style);
} catch (CSSNamingConflict e) {
LoggingUtil.exception(e);
}
// Setup line styles and insert lines.
ColorLibrary cl = style.getColorSet(StyleLibrary.PLOT);
for (int d = 0; d < dim; d++) {
CSSClass csscls = new CSSClass(this, SERIESID + "_" + d);
csscls.setStatement(SVGConstants.SVG_FILL_ATTRIBUTE, SVGConstants.SVG_NONE_VALUE);
csscls.setStatement(SVGConstants.SVG_STROKE_ATTRIBUTE, cl.getColor(d));
csscls.setStatement(SVGConstants.SVG_STROKE_WIDTH_ATTRIBUTE, style.getLineWidth(StyleLibrary.PLOT));
plot.addCSSClassOrLogError(csscls);
Element line = path[d].makeElement(plot);
line.setAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE, csscls.getName());
layer.appendChild(line);
}
return new StaticVisualizationInstance(context, task, plot, width, height, layer);
}
use of de.lmu.ifi.dbs.elki.visualization.visualizers.StaticVisualizationInstance in project elki by elki-project.
the class SettingsVisualization method makeVisualization.
@Override
public Visualization makeVisualization(VisualizerContext context, VisualizationTask task, VisualizationPlot plot, double width, double height, Projection proj) {
SettingsResult sr = task.getResult();
Collection<TrackedParameter> settings = sr.getSettings();
Element layer = plot.svgElement(SVGConstants.SVG_G_TAG);
// FIXME: use CSSClass and StyleLibrary
int i = 0;
Object last = null;
for (TrackedParameter setting : settings) {
if (setting.getOwner() != last && setting.getOwner() != null) {
String name;
try {
if (setting.getOwner() instanceof Class) {
name = ((Class<?>) setting.getOwner()).getName();
} else {
name = setting.getOwner().getClass().getName();
}
if (ClassParameter.class.isInstance(setting.getOwner())) {
name = ((ClassParameter<?>) setting.getOwner()).getValue().getName();
}
} catch (NullPointerException e) {
name = "[null]";
}
Element object = plot.svgText(0, i + 0.7, name);
object.setAttribute(SVGConstants.SVG_STYLE_ATTRIBUTE, "font-size: 0.6; font-weight: bold");
layer.appendChild(object);
i++;
last = setting.getOwner();
}
// get name and value
String name = setting.getParameter().getOptionID().getName();
String value = "[unset]";
try {
if (setting.getParameter().isDefined()) {
value = setting.getParameter().getValueAsString();
}
} catch (NullPointerException e) {
value = "[null]";
}
Element label = plot.svgText(0, i + 0.7, name);
label.setAttribute(SVGConstants.SVG_STYLE_ATTRIBUTE, "font-size: 0.6");
layer.appendChild(label);
Element vale = plot.svgText(7.5, i + 0.7, value);
vale.setAttribute(SVGConstants.SVG_STYLE_ATTRIBUTE, "font-size: 0.6");
layer.appendChild(vale);
// only advance once, since we want these two to be in the same line.
i++;
}
int cols = Math.max(30, (int) (i * height / width));
int rows = i;
final double margin = context.getStyleLibrary().getSize(StyleLibrary.MARGIN);
final String transform = SVGUtil.makeMarginTransform(width, height, cols, rows, margin / StyleLibrary.SCALE);
SVGUtil.setAtt(layer, SVGConstants.SVG_TRANSFORM_ATTRIBUTE, transform);
return new StaticVisualizationInstance(context, task, plot, width, height, layer);
}
use of de.lmu.ifi.dbs.elki.visualization.visualizers.StaticVisualizationInstance in project elki by elki-project.
the class XYPlotVisualization method makeVisualization.
@Override
public Visualization makeVisualization(VisualizerContext context, VisualizationTask task, VisualizationPlot plot, double width, double height, Projection proj) {
XYPlot xyplot = task.getResult();
setupCSS(context, plot, xyplot);
final StyleLibrary style = context.getStyleLibrary();
final double sizex = StyleLibrary.SCALE;
final double sizey = StyleLibrary.SCALE * height / width;
final double margin = style.getSize(StyleLibrary.MARGIN);
Element layer = SVGUtil.svgElement(plot.getDocument(), SVGConstants.SVG_G_TAG);
final String transform = SVGUtil.makeMarginTransform(width, height, sizex, sizey, margin);
SVGUtil.setAtt(layer, SVGConstants.SVG_TRANSFORM_ATTRIBUTE, transform);
// determine scaling
LinearScale scalex = new LinearScale(xyplot.getMinx(), xyplot.getMaxx());
LinearScale scaley = new LinearScale(xyplot.getMiny(), xyplot.getMaxy());
for (XYPlot.Curve curve : xyplot) {
// plot the line
SVGPath path = new SVGPath();
for (XYPlot.Curve.Itr iterator = curve.iterator(); iterator.valid(); iterator.advance()) {
final double x = scalex.getScaled(iterator.getX());
final double y = 1 - scaley.getScaled(iterator.getY());
path.drawTo(sizex * x, sizey * y);
}
Element line = path.makeElement(plot);
line.setAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE, SERIESID + curve.getColor());
layer.appendChild(line);
}
// add axes
try {
SVGSimpleLinearAxis.drawAxis(plot, layer, scaley, 0, sizey, 0, 0, SVGSimpleLinearAxis.LabelStyle.LEFTHAND, style);
SVGSimpleLinearAxis.drawAxis(plot, layer, scalex, 0, sizey, sizex, sizey, SVGSimpleLinearAxis.LabelStyle.RIGHTHAND, style);
} catch (CSSNamingConflict e) {
LoggingUtil.exception(e);
}
// Add axis labels
{
Element labelx = plot.svgText(sizex * .5, sizey + margin * .9, xyplot.getLabelx());
SVGUtil.setCSSClass(labelx, CSS_AXIS_LABEL);
layer.appendChild(labelx);
Element labely = plot.svgText(margin * -.8, sizey * .5, xyplot.getLabely());
SVGUtil.setCSSClass(labely, CSS_AXIS_LABEL);
SVGUtil.setAtt(labely, SVGConstants.SVG_TRANSFORM_ATTRIBUTE, "rotate(-90," + FormatUtil.NF6.format(margin * -.8) + "," + FormatUtil.NF6.format(sizey * .5) + ")");
layer.appendChild(labely);
}
return new StaticVisualizationInstance(context, task, plot, width, height, layer);
}
use of de.lmu.ifi.dbs.elki.visualization.visualizers.StaticVisualizationInstance in project elki by elki-project.
the class LabelVisualization method makeVisualization.
@Override
public Visualization makeVisualization(VisualizerContext context, VisualizationTask task, VisualizationPlot plot, double width, double height, Projection proj) {
CSSClass cls = new CSSClass(plot, "unmanaged");
StyleLibrary style = context.getStyleLibrary();
double fontsize = style.getTextSize("overview.labels") / StyleLibrary.SCALE;
cls.setStatement(SVGConstants.CSS_FONT_SIZE_PROPERTY, SVGUtil.fmt(fontsize));
cls.setStatement(SVGConstants.CSS_FILL_PROPERTY, style.getTextColor("overview.labels"));
cls.setStatement(SVGConstants.CSS_FONT_FAMILY_PROPERTY, style.getFontFamily("overview.labels"));
Element layer;
if (!rotated) {
layer = plot.svgText(width * .5, height * .5 + .35 * fontsize, this.label);
SVGUtil.setAtt(layer, SVGConstants.SVG_STYLE_ATTRIBUTE, cls.inlineCSS());
SVGUtil.setAtt(layer, SVGConstants.SVG_TEXT_ANCHOR_ATTRIBUTE, SVGConstants.SVG_MIDDLE_VALUE);
} else {
layer = plot.svgText(height * -.5, width * .5 + .35 * fontsize, this.label);
SVGUtil.setAtt(layer, SVGConstants.SVG_STYLE_ATTRIBUTE, cls.inlineCSS());
SVGUtil.setAtt(layer, SVGConstants.SVG_TEXT_ANCHOR_ATTRIBUTE, SVGConstants.SVG_MIDDLE_VALUE);
SVGUtil.setAtt(layer, SVGConstants.SVG_TRANSFORM_ATTRIBUTE, "rotate(-90)");
}
return new StaticVisualizationInstance(context, task, plot, width, height, layer);
}
use of de.lmu.ifi.dbs.elki.visualization.visualizers.StaticVisualizationInstance in project elki by elki-project.
the class XYCurveVisualization method makeVisualization.
@Override
public Visualization makeVisualization(VisualizerContext context, VisualizationTask task, VisualizationPlot plot, double width, double height, Projection proj) {
XYCurve curve = task.getResult();
setupCSS(context, plot);
final StyleLibrary style = context.getStyleLibrary();
final double sizex = StyleLibrary.SCALE;
final double sizey = StyleLibrary.SCALE * height / width;
final double margin = style.getSize(StyleLibrary.MARGIN);
Element layer = SVGUtil.svgElement(plot.getDocument(), SVGConstants.SVG_G_TAG);
final String transform = SVGUtil.makeMarginTransform(width, height, sizex, sizey, margin);
SVGUtil.setAtt(layer, SVGConstants.SVG_TRANSFORM_ATTRIBUTE, transform);
// determine scaling
LinearScale scalex = new LinearScale(curve.getMinx(), curve.getMaxx());
LinearScale scaley = new LinearScale(curve.getMiny(), curve.getMaxy());
// plot the line
SVGPath path = new SVGPath();
for (XYCurve.Itr iterator = curve.iterator(); iterator.valid(); iterator.advance()) {
final double x = scalex.getScaled(iterator.getX());
final double y = 1 - scaley.getScaled(iterator.getY());
path.drawTo(sizex * x, sizey * y);
}
Element line = path.makeElement(plot);
line.setAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE, SERIESID);
// add axes
try {
SVGSimpleLinearAxis.drawAxis(plot, layer, scaley, 0, sizey, 0, 0, SVGSimpleLinearAxis.LabelStyle.LEFTHAND, style);
SVGSimpleLinearAxis.drawAxis(plot, layer, scalex, 0, sizey, sizex, sizey, SVGSimpleLinearAxis.LabelStyle.RIGHTHAND, style);
} catch (CSSNamingConflict e) {
LoggingUtil.exception(e);
}
// Add axis labels
{
Element labelx = plot.svgText(sizex * .5, sizey + margin * .9, curve.getLabelx());
SVGUtil.setCSSClass(labelx, CSS_AXIS_LABEL);
layer.appendChild(labelx);
Element labely = plot.svgText(margin * -.8, sizey * .5, curve.getLabely());
SVGUtil.setCSSClass(labely, CSS_AXIS_LABEL);
SVGUtil.setAtt(labely, SVGConstants.SVG_TRANSFORM_ATTRIBUTE, "rotate(-90," + FormatUtil.NF6.format(margin * -.8) + "," + FormatUtil.NF6.format(sizey * .5) + ")");
layer.appendChild(labely);
}
// Add AUC value when found
if (curve instanceof ROCResult) {
double rocauc = ((ROCResult) curve).getAUC();
String lt = OutlierROCCurve.ROCAUC_LABEL + ": " + FormatUtil.NF.format(rocauc);
if (rocauc <= 0.5) {
Element auclbl = plot.svgText(sizex * 0.5, sizey * 0.10, lt);
SVGUtil.setCSSClass(auclbl, CSS_AXIS_LABEL);
layer.appendChild(auclbl);
} else {
Element auclbl = plot.svgText(sizex * 0.5, sizey * 0.95, lt);
SVGUtil.setCSSClass(auclbl, CSS_AXIS_LABEL);
layer.appendChild(auclbl);
}
}
if (curve instanceof PRCurve) {
double prauc = ((PRCurve) curve).getAUC();
String lt = OutlierPrecisionRecallCurve.PRAUC_LABEL + ": " + FormatUtil.NF.format(prauc);
if (prauc <= 0.5) {
Element auclbl = plot.svgText(sizex * 0.5, sizey * 0.10, lt);
SVGUtil.setCSSClass(auclbl, CSS_AXIS_LABEL);
layer.appendChild(auclbl);
} else {
Element auclbl = plot.svgText(sizex * 0.5, sizey * 0.95, lt);
SVGUtil.setCSSClass(auclbl, CSS_AXIS_LABEL);
layer.appendChild(auclbl);
}
}
layer.appendChild(line);
return new StaticVisualizationInstance(context, task, plot, width, height, layer);
}
Aggregations