Search in sources :

Example 1 with VisualizationPlot

use of de.lmu.ifi.dbs.elki.visualization.gui.VisualizationPlot in project elki by elki-project.

the class VisualizePairwiseGainMatrix method showVisualization.

/**
 * Show a single visualization.
 *
 * @param context Visualizer context
 * @param factory Visualizer factory
 * @param task Visualization task
 */
private void showVisualization(VisualizerContext context, SimilarityMatrixVisualizer factory, VisualizationTask task) {
    VisualizationPlot plot = new VisualizationPlot();
    Visualization vis = factory.makeVisualization(context, task, plot, 1.0, 1.0, null);
    plot.getRoot().appendChild(vis.getLayer());
    plot.getRoot().setAttribute(SVGConstants.SVG_WIDTH_ATTRIBUTE, "20cm");
    plot.getRoot().setAttribute(SVGConstants.SVG_HEIGHT_ATTRIBUTE, "20cm");
    plot.getRoot().setAttribute(SVGConstants.SVG_VIEW_BOX_ATTRIBUTE, "0 0 1 1");
    plot.updateStyleElement();
    (new SimpleSVGViewer()).setPlot(plot);
}
Also used : Visualization(de.lmu.ifi.dbs.elki.visualization.visualizers.Visualization) VisualizationPlot(de.lmu.ifi.dbs.elki.visualization.gui.VisualizationPlot) SimpleSVGViewer(de.lmu.ifi.dbs.elki.visualization.gui.SimpleSVGViewer)

Example 2 with VisualizationPlot

use of de.lmu.ifi.dbs.elki.visualization.gui.VisualizationPlot in project elki by elki-project.

the class OverviewPlot method initializePlot.

/**
 * Initialize the SVG plot.
 */
private void initializePlot() {
    plot = new VisualizationPlot();
    {
        // Add a background element:
        CSSClass cls = new CSSClass(this, "background");
        final String bgcol = context.getStyleLibrary().getBackgroundColor(StyleLibrary.PAGE);
        cls.setStatement(SVGConstants.CSS_FILL_PROPERTY, bgcol);
        plot.addCSSClassOrLogError(cls);
        Element background = plot.svgElement(SVGConstants.SVG_RECT_TAG);
        background.setAttribute(SVGConstants.SVG_X_ATTRIBUTE, "0");
        background.setAttribute(SVGConstants.SVG_Y_ATTRIBUTE, "0");
        background.setAttribute(SVGConstants.SVG_WIDTH_ATTRIBUTE, "100%");
        background.setAttribute(SVGConstants.SVG_HEIGHT_ATTRIBUTE, "100%");
        SVGUtil.setCSSClass(background, cls.getName());
        // Don't export a white background:
        if ("white".equals(bgcol)) {
            background.setAttribute(SVGPlot.NO_EXPORT_ATTRIBUTE, SVGPlot.NO_EXPORT_ATTRIBUTE);
        }
        plot.getRoot().appendChild(background);
    }
    {
        // setup the hover CSS classes.
        selcss = new CSSClass(this, "s");
        if (DEBUG_LAYOUT) {
            selcss.setStatement(SVGConstants.CSS_STROKE_PROPERTY, SVGConstants.CSS_RED_VALUE);
            selcss.setStatement(SVGConstants.CSS_STROKE_WIDTH_PROPERTY, .00001 * StyleLibrary.SCALE);
            selcss.setStatement(SVGConstants.CSS_STROKE_OPACITY_PROPERTY, "0.5");
        }
        selcss.setStatement(SVGConstants.CSS_FILL_PROPERTY, SVGConstants.CSS_RED_VALUE);
        selcss.setStatement(SVGConstants.CSS_FILL_OPACITY_PROPERTY, "0");
        selcss.setStatement(SVGConstants.CSS_CURSOR_PROPERTY, SVGConstants.CSS_POINTER_VALUE);
        plot.addCSSClassOrLogError(selcss);
        CSSClass hovcss = new CSSClass(this, "h");
        hovcss.setStatement(SVGConstants.CSS_FILL_OPACITY_PROPERTY, "0.25");
        plot.addCSSClassOrLogError(hovcss);
        // Hover listener.
        hoverer = new CSSHoverClass(hovcss.getName(), null, true);
    }
    // Disable Batik default interactions (zoom, rotate, etc.)
    if (single) {
        plot.setDisableInteractions(true);
    }
    SVGEffects.addShadowFilter(plot);
    SVGEffects.addLightGradient(plot);
}
Also used : Element(org.w3c.dom.Element) CSSHoverClass(de.lmu.ifi.dbs.elki.visualization.batikutil.CSSHoverClass) VisualizationPlot(de.lmu.ifi.dbs.elki.visualization.gui.VisualizationPlot) CSSClass(de.lmu.ifi.dbs.elki.visualization.css.CSSClass)

Example 3 with VisualizationPlot

use of de.lmu.ifi.dbs.elki.visualization.gui.VisualizationPlot in project elki by elki-project.

the class ThumbnailVisualization method doThumbnail.

@Override
public synchronized void doThumbnail() {
    pendingThumbnail = null;
    try {
        VisualizationPlot plot = new VisualizationPlot();
        plot.getRoot().setAttribute(SVGConstants.SVG_VIEW_BOX_ATTRIBUTE, "0 0 " + getWidth() + " " + getHeight());
        // Work on a clone
        Visualization vis = visFactory.makeVisualization(context, task, plot, getWidth(), getHeight(), proj);
        plot.getRoot().appendChild(vis.getLayer());
        plot.updateStyleElement();
        final int tw = (int) (getWidth() * tresolution);
        final int th = (int) (getHeight() * tresolution);
        thumb = plot.makeAWTImage(tw, th);
        thumbid = ThumbnailRegistryEntry.registerImage(thumb);
        // The visualization will not be used anymore.
        vis.destroy();
        svgp.requestRedraw(this.task, this);
    } catch (Exception e) {
        final Logging logger = Logging.getLogger(task.getFactory().getClass());
        if (logger != null && logger.isDebugging()) {
            logger.exception("Thumbnail for " + task.getFactory() + " failed.", e);
        } else {
            LoggingUtil.warning("Thumbnail for " + task.getFactory() + " failed - enable debugging to see details.");
        }
    // TODO: hide the failed image?
    }
}
Also used : Logging(de.lmu.ifi.dbs.elki.logging.Logging) AbstractVisualization(de.lmu.ifi.dbs.elki.visualization.visualizers.AbstractVisualization) Visualization(de.lmu.ifi.dbs.elki.visualization.visualizers.Visualization) VisualizationPlot(de.lmu.ifi.dbs.elki.visualization.gui.VisualizationPlot)

Example 4 with VisualizationPlot

use of de.lmu.ifi.dbs.elki.visualization.gui.VisualizationPlot in project elki by elki-project.

the class ExportVisualizations method processItem.

private void processItem(PlotItem item) {
    // Descend into subitems
    for (Iterator<PlotItem> iter = item.subitems.iterator(); iter.hasNext(); ) {
        processItem(iter.next());
    }
    if (item.taskSize() <= 0) {
        return;
    }
    item.sort();
    final double width = item.w, height = item.h;
    VisualizationPlot svgp = new VisualizationPlot();
    svgp.getRoot().setAttribute(SVGConstants.SVG_WIDTH_ATTRIBUTE, "20cm");
    svgp.getRoot().setAttribute(SVGConstants.SVG_HEIGHT_ATTRIBUTE, (20 * height / width) + "cm");
    svgp.getRoot().setAttribute(SVGConstants.SVG_VIEW_BOX_ATTRIBUTE, "0 0 " + width + " " + height);
    ArrayList<Visualization> layers = new ArrayList<>();
    for (Iterator<VisualizationTask> iter = item.tasks.iterator(); iter.hasNext(); ) {
        VisualizationTask task = iter.next();
        if (task.has(RenderFlag.NO_DETAIL) || task.has(RenderFlag.NO_EXPORT) || !task.isVisible()) {
            continue;
        }
        try {
            Visualization v = task.getFactory().makeVisualization(context, task, svgp, width, height, item.proj);
            layers.add(v);
        } catch (Exception e) {
            if (Logging.getLogger(task.getFactory().getClass()).isDebugging()) {
                LOG.exception("Visualization failed.", e);
            } else {
                LOG.warning("Visualizer " + task.getFactory().getClass().getName() + " failed - enable debugging to see details.");
            }
        }
    }
    if (layers.isEmpty()) {
        return;
    }
    for (Visualization layer : layers) {
        if (layer.getLayer() == null) {
            LOG.warning("NULL layer seen.");
            continue;
        }
        svgp.getRoot().appendChild(layer.getLayer());
    }
    svgp.updateStyleElement();
    String prefix = null;
    prefix = (prefix == null && item.proj != null) ? item.proj.getMenuName() : prefix;
    prefix = (prefix == null && item.tasks.size() > 0) ? item.tasks.get(0).getMenuName() : prefix;
    prefix = (prefix != null ? prefix : "plot");
    // TODO: generate names...
    Integer count = counter.get(prefix);
    counter.put(prefix, count = count == null ? 1 : (count + 1));
    try {
        switch(format) {
            case SVG:
                {
                    File outname = new File(output, prefix + "-" + count + ".svg");
                    svgp.saveAsSVG(outname);
                    break;
                }
            case PNG:
                {
                    File outname = new File(output, prefix + "-" + count + ".png");
                    svgp.saveAsPNG(outname, (int) (iwidth * ratio), iwidth);
                    break;
                }
            case PDF:
                {
                    File outname = new File(output, prefix + "-" + count + ".pdf");
                    svgp.saveAsPDF(outname);
                    break;
                }
            case PS:
                {
                    File outname = new File(output, prefix + "-" + count + ".ps");
                    svgp.saveAsPS(outname);
                    break;
                }
            case EPS:
                {
                    File outname = new File(output, prefix + "-" + count + ".eps");
                    svgp.saveAsEPS(outname);
                    break;
                }
            case JPEG:
                {
                    File outname = new File(output, prefix + "-" + count + ".jpg");
                    svgp.saveAsJPEG(outname, (int) (iwidth * ratio), iwidth);
                    break;
                }
        }
    } catch (Exception e) {
        LOG.warning("Export of visualization failed.", e);
    }
    for (Visualization layer : layers) {
        layer.destroy();
    }
}
Also used : Visualization(de.lmu.ifi.dbs.elki.visualization.visualizers.Visualization) ArrayList(java.util.ArrayList) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException) VisualizationTask(de.lmu.ifi.dbs.elki.visualization.VisualizationTask) PlotItem(de.lmu.ifi.dbs.elki.visualization.gui.overview.PlotItem) VisualizationPlot(de.lmu.ifi.dbs.elki.visualization.gui.VisualizationPlot) File(java.io.File)

Aggregations

VisualizationPlot (de.lmu.ifi.dbs.elki.visualization.gui.VisualizationPlot)4 Visualization (de.lmu.ifi.dbs.elki.visualization.visualizers.Visualization)3 Logging (de.lmu.ifi.dbs.elki.logging.Logging)1 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)1 VisualizationTask (de.lmu.ifi.dbs.elki.visualization.VisualizationTask)1 CSSHoverClass (de.lmu.ifi.dbs.elki.visualization.batikutil.CSSHoverClass)1 CSSClass (de.lmu.ifi.dbs.elki.visualization.css.CSSClass)1 SimpleSVGViewer (de.lmu.ifi.dbs.elki.visualization.gui.SimpleSVGViewer)1 PlotItem (de.lmu.ifi.dbs.elki.visualization.gui.overview.PlotItem)1 AbstractVisualization (de.lmu.ifi.dbs.elki.visualization.visualizers.AbstractVisualization)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Element (org.w3c.dom.Element)1