]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.trend/src/org/simantics/trend/impl/ViewRenderingProfile.java
Render last known value in time series chart hairline value tip
[simantics/platform.git] / bundles / org.simantics.trend / src / org / simantics / trend / impl / ViewRenderingProfile.java
1 package org.simantics.trend.impl;
2
3 import java.awt.Color;
4
5 import org.simantics.trend.configuration.ViewProfile;
6
7 /**
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.
10  * 
11  * @author Tuukka Lehtonen
12  */
13 class ViewRenderingProfile {
14
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;
18
19     public ViewRenderingProfile read(ViewProfile p) {
20         if (p.backgroundColor != null) {
21             float[] bg = p.backgroundColor;
22             int len = bg.length;
23             if (len >= 6) {
24                 backgroundColor1 = toColor(bg, 0);
25                 backgroundColor2 = toColor(bg, 3);
26             } else if (len >= 3) {
27                 backgroundColor1 = toColor(bg, 0);
28                 backgroundColor2 = null;
29             }
30         } else {
31             backgroundColor1 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_BOTTOM;
32             backgroundColor2 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_TOP;
33         }
34
35         if (p.gridColor != null && p.gridColor.length >= 3) {
36             gridColor = toColor(p.gridColor, 0);
37         } else {
38             gridColor = Plot.GRID_LINE_COLOR;
39         }
40
41         return this;
42     }
43
44     private static Color toColor(float[] array, int offset) {
45         return new Color(clamp(array[offset]), clamp(array[offset+1]), clamp(array[offset+2]));
46     }
47
48     private static float clamp(float v) {
49         return Math.max(0, Math.min(v, 1));
50     }
51
52 }