X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.trend%2Fsrc%2Forg%2Fsimantics%2Ftrend%2Fimpl%2FViewRenderingProfile.java;fp=bundles%2Forg.simantics.trend%2Fsrc%2Forg%2Fsimantics%2Ftrend%2Fimpl%2FViewRenderingProfile.java;h=1d6a9d8b6ddf1a61a79bc106f9cd3f0b2d203c67;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git 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 index 000000000..1d6a9d8b6 --- /dev/null +++ b/bundles/org.simantics.trend/src/org/simantics/trend/impl/ViewRenderingProfile.java @@ -0,0 +1,52 @@ +package org.simantics.trend.impl; + +import java.awt.Color; + +import org.simantics.trend.configuration.ViewProfile; + +/** + * Internal caching class for chart rendering related data that only needs to be + * recreated when the rendered TrendSpec changes, not on every rendered frame. + * + * @author Tuukka Lehtonen + */ +class ViewRenderingProfile { + + public Color backgroundColor1 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_BOTTOM; + public Color backgroundColor2 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_TOP;; + public Color gridColor = Plot.GRID_LINE_COLOR; + + public ViewRenderingProfile read(ViewProfile p) { + if (p.backgroundColor != null) { + float[] bg = p.backgroundColor; + int len = bg.length; + if (len >= 6) { + backgroundColor1 = toColor(bg, 0); + backgroundColor2 = toColor(bg, 3); + } else if (len >= 3) { + backgroundColor1 = toColor(bg, 0); + backgroundColor2 = null; + } + } else { + backgroundColor1 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_BOTTOM; + backgroundColor2 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_TOP; + } + + if (p.gridColor != null && p.gridColor.length >= 3) { + gridColor = toColor(p.gridColor, 0); + } else { + gridColor = Plot.GRID_LINE_COLOR; + } + + return this; + } + + private static Color toColor(float[] array, int offset) { + return new Color(clamp(array[offset]), clamp(array[offset+1]), clamp(array[offset+2])); + } + + private static float clamp(float v) { + return Math.max(0, Math.min(v, 1)); + } + +}