use of de.lmu.ifi.dbs.elki.visualization.colors.ColorLibrary 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.colors.ColorLibrary in project elki by elki-project.
the class Parallel3DRenderer method prepareColors.
private void prepareColors(final StylingPolicy sp) {
if (colors == null) {
final ColorLibrary cols = shared.stylelib.getColorSet(StyleLibrary.PLOT);
if (sp instanceof ClassStylingPolicy) {
ClassStylingPolicy csp = (ClassStylingPolicy) sp;
final int maxStyle = csp.getMaxStyle();
colors = new float[maxStyle * 3];
for (int c = 0, s = csp.getMinStyle(); s < maxStyle; c += 3, s++) {
Color col = SVGUtil.stringToColor(cols.getColor(s));
colors[c + 0] = col.getRed() / 255.f;
colors[c + 1] = col.getGreen() / 255.f;
colors[c + 2] = col.getBlue() / 255.f;
}
} else {
// Render in black.
colors = new float[] { 0f, 0f, 0f };
}
}
}
use of de.lmu.ifi.dbs.elki.visualization.colors.ColorLibrary in project elki by elki-project.
the class PropertiesBasedStyleLibrary method getColorSet.
@Override
public ColorLibrary getColorSet(String key) {
ColorLibrary cl = getCached(key, COLORSET, ColorLibrary.class);
if (cl == null) {
String[] colors = getPropertyValue(key, COLORSET).split(LIST_SEPARATOR);
cl = new ListBasedColorLibrary(colors, "Default");
setCached(key, COLORSET, cl);
}
return cl;
}
Aggregations