1 package org.simantics.trend.impl;
5 import org.simantics.trend.configuration.ViewProfile;
8 * Internal caching class for chart rendering related data that only needs to be
9 * recreated when the rendered TrendSpec changes, not on every rendered frame.
11 * @author Tuukka Lehtonen
13 class ViewRenderingProfile {
15 public Color backgroundColor1 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_BOTTOM;
16 public Color backgroundColor2 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_TOP;;
17 public Color gridColor = Plot.GRID_LINE_COLOR;
19 public ViewRenderingProfile read(ViewProfile p) {
20 if (p.backgroundColor != null) {
21 float[] bg = p.backgroundColor;
24 backgroundColor1 = toColor(bg, 0);
25 backgroundColor2 = toColor(bg, 3);
26 } else if (len >= 3) {
27 backgroundColor1 = toColor(bg, 0);
28 backgroundColor2 = null;
31 backgroundColor1 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_BOTTOM;
32 backgroundColor2 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_TOP;
35 if (p.gridColor != null && p.gridColor.length >= 3) {
36 gridColor = toColor(p.gridColor, 0);
38 gridColor = Plot.GRID_LINE_COLOR;
44 private static Color toColor(float[] array, int offset) {
45 return new Color(clamp(array[offset]), clamp(array[offset+1]), clamp(array[offset+2]));
48 private static float clamp(float v) {
49 return Math.max(0, Math.min(v, 1));