1 /* 2 * This file is part of ELKI: 3 * Environment for Developing KDD-Applications Supported by Index-Structures 4 * 5 * Copyright (C) 2018 6 * ELKI Development Team 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Affero General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Affero General Public License for more details. 17 * 18 * You should have received a copy of the GNU Affero General Public License 19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 package de.lmu.ifi.dbs.elki.visualization.style.marker; 22 23 import org.apache.batik.util.SVGConstants; 24 import org.w3c.dom.Element; 25 26 import de.lmu.ifi.dbs.elki.visualization.colors.ColorLibrary; 27 import de.lmu.ifi.dbs.elki.visualization.style.StyleLibrary; 28 import de.lmu.ifi.dbs.elki.visualization.svg.SVGPlot; 29 import de.lmu.ifi.dbs.elki.visualization.svg.SVGUtil; 30 31 /** 32 * Simple marker library that just draws colored rectangles at the given 33 * coordinates. 34 * 35 * @author Erich Schubert 36 * @since 0.4.0 37 * 38 * @composed - - - ColorLibrary 39 */ 40 public class MinimalMarkers implements MarkerLibrary { 41 /** 42 * Color library 43 */ 44 private ColorLibrary colors; 45 46 /** 47 * Color of "uncolored" dots 48 */ 49 private String dotcolor = "black"; 50 51 /** 52 * Color of "greyed out" dots 53 */ 54 private String greycolor = "gray"; 55 56 /** 57 * Constructor 58 * 59 * @param style Style library to use 60 */ MinimalMarkers(StyleLibrary style)61 public MinimalMarkers(StyleLibrary style) { 62 super(); 63 this.colors = style.getColorSet(StyleLibrary.MARKERPLOT); 64 this.dotcolor = style.getColor(StyleLibrary.MARKERPLOT); 65 this.greycolor = style.getColor(StyleLibrary.PLOTGREY); 66 } 67 68 /** 69 * Use a given marker on the document. 70 */ 71 @Override useMarker(SVGPlot plot, Element parent, double x, double y, int stylenr, double size)72 public Element useMarker(SVGPlot plot, Element parent, double x, double y, int stylenr, double size) { 73 Element marker = plot.svgRect(x - size * .5, y - size * .5, size, size); 74 final String col; 75 if(stylenr == -1) { 76 col = dotcolor; 77 } 78 else if(stylenr == -2) { 79 col = greycolor; 80 } 81 else { 82 col = colors.getColor(stylenr); 83 } 84 SVGUtil.setStyle(marker, SVGConstants.CSS_FILL_PROPERTY + ":" + col); 85 parent.appendChild(marker); 86 return marker; 87 } 88 }