]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.trend/src/org/simantics/trend/impl/ViewRenderingProfile.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.trend / src / org / simantics / trend / impl / ViewRenderingProfile.java
diff --git a/bundles/org.simantics.trend/src/org/simantics/trend/impl/ViewRenderingProfile.java b/bundles/org.simantics.trend/src/org/simantics/trend/impl/ViewRenderingProfile.java
new file mode 100644 (file)
index 0000000..1d6a9d8
--- /dev/null
@@ -0,0 +1,52 @@
+package org.simantics.trend.impl;\r
+\r
+import java.awt.Color;\r
+\r
+import org.simantics.trend.configuration.ViewProfile;\r
+\r
+/**\r
+ * Internal caching class for chart rendering related data that only needs to be\r
+ * recreated when the rendered TrendSpec changes, not on every rendered frame.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ */\r
+class ViewRenderingProfile {\r
+\r
+    public Color backgroundColor1 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_BOTTOM;\r
+    public Color backgroundColor2 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_TOP;;\r
+    public Color gridColor = Plot.GRID_LINE_COLOR;\r
+\r
+    public ViewRenderingProfile read(ViewProfile p) {\r
+        if (p.backgroundColor != null) {\r
+            float[] bg = p.backgroundColor;\r
+            int len = bg.length;\r
+            if (len >= 6) {\r
+                backgroundColor1 = toColor(bg, 0);\r
+                backgroundColor2 = toColor(bg, 3);\r
+            } else if (len >= 3) {\r
+                backgroundColor1 = toColor(bg, 0);\r
+                backgroundColor2 = null;\r
+            }\r
+        } else {\r
+            backgroundColor1 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_BOTTOM;\r
+            backgroundColor2 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_TOP;\r
+        }\r
+\r
+        if (p.gridColor != null && p.gridColor.length >= 3) {\r
+            gridColor = toColor(p.gridColor, 0);\r
+        } else {\r
+            gridColor = Plot.GRID_LINE_COLOR;\r
+        }\r
+\r
+        return this;\r
+    }\r
+\r
+    private static Color toColor(float[] array, int offset) {\r
+        return new Color(clamp(array[offset]), clamp(array[offset+1]), clamp(array[offset+2]));\r
+    }\r
+\r
+    private static float clamp(float v) {\r
+        return Math.max(0, Math.min(v, 1));\r
+    }\r
+\r
+}\r