Search in sources :

Example 6 with StyleLibrary

use of de.lmu.ifi.dbs.elki.visualization.style.StyleLibrary in project elki by elki-project.

the class AbstractTooltipVisualization method fullRedraw.

@Override
public void fullRedraw() {
    setupCanvas();
    setupCSS(svgp);
    final StyleLibrary style = context.getStyleLibrary();
    double dotsize = style.getLineWidth(StyleLibrary.PLOT);
    for (DBIDIter id = sample.getSample().iter(); id.valid(); id.advance()) {
        double[] v = proj.fastProjectDataToRenderSpace(rel.get(id));
        if (v[0] != v[0] || v[1] != v[1]) {
            // NaN!
            continue;
        }
        Element tooltip = makeTooltip(id, v[0], v[1], dotsize);
        SVGUtil.addCSSClass(tooltip, TOOLTIP_HIDDEN);
        // sensitive area.
        Element area = svgp.svgRect(v[0] - dotsize, v[1] - dotsize, 2 * dotsize, 2 * dotsize);
        SVGUtil.addCSSClass(area, TOOLTIP_AREA);
        EventTarget targ = (EventTarget) area;
        targ.addEventListener(SVGConstants.SVG_MOUSEOVER_EVENT_TYPE, hoverer, false);
        targ.addEventListener(SVGConstants.SVG_MOUSEOUT_EVENT_TYPE, hoverer, false);
        targ.addEventListener(SVGConstants.SVG_CLICK_EVENT_TYPE, hoverer, false);
        // NOTE: do not change the sequence in which these are inserted!
        layer.appendChild(area);
        layer.appendChild(tooltip);
    }
}
Also used : Element(org.w3c.dom.Element) StyleLibrary(de.lmu.ifi.dbs.elki.visualization.style.StyleLibrary) EventTarget(org.w3c.dom.events.EventTarget) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 7 with StyleLibrary

use of de.lmu.ifi.dbs.elki.visualization.style.StyleLibrary in project elki by elki-project.

the class EvaluationVisualization method makeVisualization.

@Override
public Visualization makeVisualization(VisualizerContext context, VisualizationTask task, VisualizationPlot plot, double width, double height, Projection proj) {
    // TODO: make a utility class to wrap SVGPlot + parent layer + ypos.
    // TODO: use CSSClass and StyleLibrary
    // Skip space before first header
    double ypos = -.5;
    Element parent = plot.svgElement(SVGConstants.SVG_G_TAG);
    Object o = task.getResult();
    EvaluationResult sr = null;
    if (o instanceof EvaluationResult) {
        sr = (EvaluationResult) o;
    } else if (o instanceof Class && EvaluationResult.class.isAssignableFrom((Class<?>) o)) {
        // Use cluster evaluation of current style instead.
        StylingPolicy spol = context.getStylingPolicy();
        if (spol instanceof ClusterStylingPolicy) {
            ClusterStylingPolicy cpol = (ClusterStylingPolicy) spol;
            // will be a subtype, actually!
            @SuppressWarnings("unchecked") Class<EvaluationResult> c = (Class<EvaluationResult>) o;
            for (It<EvaluationResult> it = VisualizationTree.findNewResults(context, cpol.getClustering()).filter(c); it.valid(); it.advance()) {
                // may end up displaying the wrong evaluation.
                if (context.getHierarchy().iterAncestors(it.get()).find(cpol.getClustering())) {
                    sr = it.get();
                    break;
                }
            }
        }
    }
    if (sr == null) {
        // Failed.
        return new StaticVisualizationInstance(context, task, plot, width, height, parent);
    }
    for (String header : sr.getHeaderLines()) {
        ypos = addHeader(plot, parent, ypos, header);
    }
    for (EvaluationResult.MeasurementGroup g : sr) {
        ypos = addHeader(plot, parent, ypos, g.getName());
        for (EvaluationResult.Measurement m : g) {
            ypos = addBarChart(plot, parent, ypos, m.getName(), m.getVal(), m.getMin(), m.getMax(), m.getExp(), m.lowerIsBetter());
        }
    }
    // scale vis
    double cols = 10;
    final StyleLibrary style = context.getStyleLibrary();
    final double margin = style.getSize(StyleLibrary.MARGIN);
    final String transform = SVGUtil.makeMarginTransform(width, height, cols, ypos, margin / StyleLibrary.SCALE);
    SVGUtil.setAtt(parent, SVGConstants.SVG_TRANSFORM_ATTRIBUTE, transform);
    return new StaticVisualizationInstance(context, task, plot, width, height, parent);
}
Also used : Element(org.w3c.dom.Element) It(de.lmu.ifi.dbs.elki.utilities.datastructures.iterator.It) StyleLibrary(de.lmu.ifi.dbs.elki.visualization.style.StyleLibrary) StaticVisualizationInstance(de.lmu.ifi.dbs.elki.visualization.visualizers.StaticVisualizationInstance) EvaluationResult(de.lmu.ifi.dbs.elki.result.EvaluationResult) ClusterStylingPolicy(de.lmu.ifi.dbs.elki.visualization.style.ClusterStylingPolicy) StylingPolicy(de.lmu.ifi.dbs.elki.visualization.style.StylingPolicy) ClusterStylingPolicy(de.lmu.ifi.dbs.elki.visualization.style.ClusterStylingPolicy)

Example 8 with StyleLibrary

use of de.lmu.ifi.dbs.elki.visualization.style.StyleLibrary in project elki by elki-project.

the class XYPlotVisualization method setupCSS.

/**
 * Setup the CSS classes for the plot.
 *
 * @param svgp Plot
 * @param plot Plot to render
 */
private void setupCSS(VisualizerContext context, SVGPlot svgp, XYPlot plot) {
    StyleLibrary style = context.getStyleLibrary();
    for (XYPlot.Curve curve : plot) {
        CSSClass csscls = new CSSClass(this, SERIESID + curve.getColor());
        // csscls.setStatement(SVGConstants.SVG_STROKE_WIDTH_ATTRIBUTE, "0.2%");
        csscls.setStatement(SVGConstants.SVG_FILL_ATTRIBUTE, SVGConstants.SVG_NONE_VALUE);
        style.lines().formatCSSClass(csscls, curve.getColor(), style.getLineWidth(StyleLibrary.XYCURVE));
        svgp.addCSSClassOrLogError(csscls);
    }
    // Axis label
    CSSClass label = new CSSClass(this, CSS_AXIS_LABEL);
    label.setStatement(SVGConstants.CSS_FILL_PROPERTY, style.getTextColor(StyleLibrary.XYCURVE));
    label.setStatement(SVGConstants.CSS_FONT_FAMILY_PROPERTY, style.getFontFamily(StyleLibrary.XYCURVE));
    label.setStatement(SVGConstants.CSS_FONT_SIZE_PROPERTY, style.getTextSize(StyleLibrary.XYCURVE));
    label.setStatement(SVGConstants.CSS_TEXT_ANCHOR_PROPERTY, SVGConstants.CSS_MIDDLE_VALUE);
    svgp.addCSSClassOrLogError(label);
    svgp.updateStyleElement();
}
Also used : XYPlot(de.lmu.ifi.dbs.elki.math.geometry.XYPlot) StyleLibrary(de.lmu.ifi.dbs.elki.visualization.style.StyleLibrary) CSSClass(de.lmu.ifi.dbs.elki.visualization.css.CSSClass)

Aggregations

StyleLibrary (de.lmu.ifi.dbs.elki.visualization.style.StyleLibrary)8 Element (org.w3c.dom.Element)6 StaticVisualizationInstance (de.lmu.ifi.dbs.elki.visualization.visualizers.StaticVisualizationInstance)5 CSSClass (de.lmu.ifi.dbs.elki.visualization.css.CSSClass)4 LinearScale (de.lmu.ifi.dbs.elki.math.scales.LinearScale)3 CSSNamingConflict (de.lmu.ifi.dbs.elki.visualization.css.CSSClassManager.CSSNamingConflict)3 SVGPath (de.lmu.ifi.dbs.elki.visualization.svg.SVGPath)3 XYPlot (de.lmu.ifi.dbs.elki.math.geometry.XYPlot)2 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)1 PRCurve (de.lmu.ifi.dbs.elki.evaluation.outlier.OutlierPrecisionRecallCurve.PRCurve)1 ROCResult (de.lmu.ifi.dbs.elki.evaluation.outlier.OutlierROCCurve.ROCResult)1 DoubleMinMax (de.lmu.ifi.dbs.elki.math.DoubleMinMax)1 XYCurve (de.lmu.ifi.dbs.elki.math.geometry.XYCurve)1 EvaluationResult (de.lmu.ifi.dbs.elki.result.EvaluationResult)1 HistogramResult (de.lmu.ifi.dbs.elki.result.HistogramResult)1 It (de.lmu.ifi.dbs.elki.utilities.datastructures.iterator.It)1 ColorLibrary (de.lmu.ifi.dbs.elki.visualization.colors.ColorLibrary)1 ClusterStylingPolicy (de.lmu.ifi.dbs.elki.visualization.style.ClusterStylingPolicy)1 StylingPolicy (de.lmu.ifi.dbs.elki.visualization.style.StylingPolicy)1 EventTarget (org.w3c.dom.events.EventTarget)1