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