Beispiel #1
0
        public static IPlotModel GetPlotModel(MeasurementHistory historyData, SensorClass sensorClass, string sensorName)
        {
            var graphDataPoints = new List <GraphData>();

            foreach (var item in historyData.Values.OrderBy(i => i.Timestamp))
            {
                graphDataPoints.Add(new GraphData()
                {
                    Y = double.Parse(item.Value, CultureInfo.InvariantCulture),
                    X = item.Timestamp
                });
            }

            var theme = (ColorThemeEnum)Preferences.Get(ColorTheme.ColorThemePreferenceName, 0);

            var plotModel = new ViewResolvingPlotModel()
            {
                Title = $"{sensorName} ({historyData.Unit})"
            };
            var ls = new AreaSeries()
            {
                DataFieldX = "X", DataFieldY = "Y", ItemsSource = graphDataPoints
            };

            plotModel.Series.Add(ls);

            // If values are all same, use custom min/max values to show graph
            var minValue = GetMinimumValue(graphDataPoints, sensorClass);
            var maxValue = GetMaximumValue(graphDataPoints, sensorClass);

            if (minValue == maxValue)
            {
                minValue = minValue - 5;
                maxValue = maxValue + 5;
            }

            plotModel.Axes.Add(GetLinearAxis(theme, AxisPosition.Left, minValue, maxValue, GetMajorStep(minValue, maxValue, sensorClass)));
            plotModel.Axes.Add(GetLinearAxis(theme, AxisPosition.Right, minValue, maxValue, GetMajorStep(minValue, maxValue, sensorClass)));
            plotModel.Axes.Add(GetDateTimeAxis(theme));

            switch (theme)
            {
            default:
            case ColorThemeEnum.Gray:
                plotModel.TitleColor                    = OxyColors.WhiteSmoke;
                plotModel.PlotAreaBorderColor           = OxyColors.DimGray;
                ((LineSeries)plotModel.Series[0]).Color = OxyColor.Parse("#FF9FA8DA");
                break;

            case ColorThemeEnum.Light:
                plotModel.TitleColor                    = OxyColors.Black;
                plotModel.PlotAreaBorderColor           = OxyColors.Black;
                ((LineSeries)plotModel.Series[0]).Color = OxyColor.Parse("#FF3F51B5");
                break;
            }
            return(plotModel);
        }
Beispiel #2
0
        public static PlotModel GetPlotModel(MeasurementHistory historyData, SensorClass sensorClass, string sensorName)
        {
            var graphDataPoints = new List <GraphData>();

            foreach (var item in historyData.Values.OrderBy(i => i.Timestamp))
            {
                graphDataPoints.Add(new GraphData()
                {
                    Y = double.Parse(item.Value, CultureInfo.InvariantCulture),
                    X = item.Timestamp
                });
            }

            var theme = (ColorThemeEnum)Preferences.Get(ColorTheme.ColorThemePreferenceName, 0);

            var plotModel = new PlotModel()
            {
                Title = $"{sensorName} ({historyData.Unit})"
            };
            var ls = new AreaSeries()
            {
                DataFieldX = "X", DataFieldY = "Y", ItemsSource = graphDataPoints
            };

            plotModel.Series.Add(ls);

            plotModel.Axes.Add(GetLinearAxis(theme, AxisPosition.Left, GetMinimumValue(graphDataPoints, sensorClass), GetMaximumValue(graphDataPoints, sensorClass), GetMajorStep(graphDataPoints, sensorClass)));
            plotModel.Axes.Add(GetLinearAxis(theme, AxisPosition.Right, GetMinimumValue(graphDataPoints, sensorClass), GetMaximumValue(graphDataPoints, sensorClass), GetMajorStep(graphDataPoints, sensorClass)));
            plotModel.Axes.Add(GetDateTimeAxis(theme));

            switch (theme)
            {
            default:
            case ColorThemeEnum.Gray:
                plotModel.TitleColor                    = OxyColors.WhiteSmoke;
                plotModel.PlotAreaBorderColor           = OxyColors.DimGray;
                ((LineSeries)plotModel.Series[0]).Color = OxyColors.LightBlue;
                break;

            case ColorThemeEnum.Green:
                plotModel.TitleColor                    = OxyColors.WhiteSmoke;
                plotModel.PlotAreaBorderColor           = OxyColors.DimGray;
                ((LineSeries)plotModel.Series[0]).Color = OxyColors.LightSkyBlue;
                break;

            case ColorThemeEnum.Light:
                plotModel.TitleColor                    = OxyColors.Black;
                plotModel.PlotAreaBorderColor           = OxyColors.Black;
                ((LineSeries)plotModel.Series[0]).Color = OxyColors.DimGray;
                break;
            }
            return(plotModel);
        }