Пример #1
0
 public PointsSeriesAndAdditionalData(ChartSeriesViewModel seriesViewModel, SeriesAdditionalData additionalData, XyDataSeries <DateTime, double> dataSeries, FastLineRenderableSeries renderSeries)
 {
     SeriesVm     = seriesViewModel;
     Metadata     = additionalData;
     DataSeries   = dataSeries;
     RenderSeries = renderSeries;
 }
Пример #2
0
        public void LogDiscreteParameter(string parameterName, bool?value)
        {
            _uiNotifier.Notify(() => {
                if (value.HasValue)
                {
                    if (!_logs.ContainsKey(parameterName))
                    {
                        var dataSeries = new XyDataSeries <DateTime, double> {
                            SeriesName = parameterName
                        };

                        var color = _colors.First(c => _usedColors.All(uc => uc != c));
                        _usedColors.Add(color);
                        var renderSeries = new FastLineRenderableSeries {
                            DataSeries = dataSeries, SeriesColor = color
                        };

                        var vm       = new ChartSeriesViewModel(dataSeries, renderSeries);
                        var metadata = new SeriesAdditionalData(vm);

                        DiscreteSeries.Add(vm);
                        DiscreteSeriesAdditionalData.Add(metadata);

                        _logs.Add(parameterName, new PointsSeriesAndAdditionalData(vm, metadata, dataSeries, renderSeries));
                    }
                    _logs[parameterName].DataSeries.Append(DateTime.Now, value.Value ? 1.0 : 0.0);
                    _updatable?.Update();
                }
            });
        }
        public void CategorySeriesCreatesCategoryXAxisForString()
        {
            var dataSource = new NullPowerShellDataSource();

            dataSource.Data.Add(new SolidPSObjectBase(new PSObject(new { Label = "Test", Value = 123 })));
            ChartSeriesViewModel viewModel = new ChartSeriesViewModel
            {
                LabelMemberPath     = "Label",
                ValueMemberPath     = "Value",
                DataSource          = dataSource,
                EnableConfigureAxes = true
            };
            var axis = viewModel.XAxis;

            Assert.NotNull(axis);
            Assert.Equal(ChartAxisType.CategoryX, axis.AxisType);
        }
        public void ScatterSeriesCreatesNumericXAxisForInteger()
        {
            var dataSource = new NullPowerShellDataSource();

            dataSource.Data.Add(new SolidPSObjectBase(new PSObject(new { Label = 5, Value = 123 })));
            ChartSeriesViewModel viewModel = new ChartSeriesViewModel
            {
                SeriesType          = ChartSeriesType.Scatter,
                XMemberPath         = "Label",
                YMemberPath         = "Value",
                DataSource          = dataSource,
                EnableConfigureAxes = true
            };
            var axis = viewModel.XAxis;

            Assert.NotNull(axis);
            Assert.Equal(ChartAxisType.NumericX, axis.AxisType);
        }
        public void ScatterSeriesThrowsWhenXAxisIsString()
        {
            var dataSource = new NullPowerShellDataSource();

            dataSource.Data.Add(new SolidPSObjectBase(new PSObject(new { Label = "ASDF", Value = 123 })));
            Assert.Throws <Exceptions.InvalidChartAxisTypeException>(() =>
            {
                ChartSeriesViewModel
                viewModel = new ChartSeriesViewModel
                {
                    SeriesType =
                        ChartSeriesType
                        .Scatter,
                    XMemberPath =
                        "Label",
                    YMemberPath =
                        "Value",
                    DataSource =
                        dataSource,
                    EnableConfigureAxes = true
                };
            }
                                                                     );
        }
        private Series ConvertSeries(ChartSeriesViewModel series)
        {
            Series newSeries   = null;
            var    valueSeries = series.GetScaleForProperty(series.ValueMemberPath);
            var    labelSeries = series.GetScaleForProperty(series.LabelMemberPath);


            switch (series.SeriesType)
            {
            case (ChartSeriesType.Column):
            {
                newSeries = new ColumnSeries
                {
                    ValueField  = series.ValueMemberPath,
                    ItemsSource = series.DataSource.Data,
                    FillColor   = valueSeries.Color.ToOxyColor(),
                    StrokeColor = valueSeries.Color.ToOxyColor(),
                    YAxisKey    = valueSeries.Name,
                    XAxisKey    = labelSeries.Name,
                };

                break;
            }

            case (ChartSeriesType.Line):
            {
                newSeries = new LineSeries
                {
                    ItemsSource = series.DataSource.Data,
                    DataFieldX  = series.XMemberPath,
                    DataFieldY  = series.YMemberPath,
                    MarkerType  = MarkerType.Circle,
                    Color       = valueSeries.Color.ToOxyColor(),
                    MarkerFill  = valueSeries.Color.ToOxyColor(),
                    YAxisKey    = valueSeries.Name,
                    XAxisKey    = labelSeries.Name,
                };
                break;
            }

            case (ChartSeriesType.Spline):
            {
                newSeries = new LineSeries
                {
                    ItemsSource = series.DataSource.Data,
                    DataFieldX  = series.XMemberPath,
                    DataFieldY  = series.YMemberPath,
                    MarkerType  = MarkerType.Circle,
                    Color       = valueSeries.Color.ToOxyColor(),
                    MarkerFill  = valueSeries.Color.ToOxyColor(),
                    Smooth      = true,
                    YAxisKey    = valueSeries.Name,
                    XAxisKey    = labelSeries.Name,
                };
                break;
            }

            case (ChartSeriesType.Area):
            {
                newSeries = new AreaSeries
                {
                    ItemsSource = series.DataSource.Data,
                    DataFieldX  = series.XMemberPath,
                    DataFieldY  = series.YMemberPath,
                    Color       = valueSeries.Color.ToOxyColor(),
                    Fill        = valueSeries.Color.ToOxyColor(),
                    MarkerFill  = valueSeries.Color.ToOxyColor(),
                    YAxisKey    = valueSeries.Name,
                    XAxisKey    = labelSeries.Name,
                };
                break;
            }

            case (ChartSeriesType.SplineArea):
            {
                newSeries = new AreaSeries
                {
                    ItemsSource = series.DataSource.Data,
                    DataFieldX  = series.XMemberPath,
                    DataFieldY  = series.YMemberPath,
                    Color       = valueSeries.Color.ToOxyColor(),
                    Fill        = valueSeries.Color.ToOxyColor(),
                    MarkerFill  = valueSeries.Color.ToOxyColor(),
                    Smooth      = true,
                    YAxisKey    = valueSeries.Name,
                    XAxisKey    = labelSeries.Name,
                };
                break;
            }

            case (ChartSeriesType.Bubble):
            {
                newSeries = new ScatterSeries
                {
                    ItemsSource   = series.DataSource.Data,
                    DataFieldX    = series.XMemberPath,
                    DataFieldY    = series.YMemberPath,
                    DataFieldSize = series.RadiusMemberPath,
                    MarkerFill    = valueSeries.Color.ToOxyColor(),
                    MarkerType    = MarkerType.Circle,
                    YAxisKey      = valueSeries.Name,
                    XAxisKey      = labelSeries.Name,
                };
                break;
            }

            case (ChartSeriesType.StepLine):
            {
                newSeries = new StairStepSeries
                {
                    ItemsSource = series.DataSource.Data,
                    DataFieldX  = series.XMemberPath,
                    DataFieldY  = series.YMemberPath,
                    Color       = valueSeries.Color.ToOxyColor(),
                    YAxisKey    = valueSeries.Name,
                    XAxisKey    = labelSeries.Name,
                };
                break;
            }

            default:
            {
                return(null);
            }
            }

            newSeries.Title = series.Name;

            return(newSeries);
        }
Пример #7
0
        public ActionResult ChartData(int groupId)
        {
            if (!Request.IsAjaxRequest())
            {
                return(null);
            }

            var academicPlan = UnitOfWork.Repository <Domain.Models.AcademicPlan>()
                               .GetQ(filter: x => x.ProgramOfEducation.Groups.Any(g => g.GroupId == groupId))
                               .OrderByDescending(d => d.UploadedAt)
                               .FirstOrDefault();

            if (academicPlan == null)
            {
                return(new HttpStatusCodeResult(404));
            }

            var courseSchedule = academicPlan.CourseSchedules
                                 .SingleOrDefault(x => x.CourseNumber == UserProfile.EducationYear.YearStart - academicPlan.ProgramOfEducation.YearStart + 1);

            if (courseSchedule == null)
            {
                return(new HttpStatusCodeResult(404, "Учебный план загружен некорректно."));
            }

            var chartSeries = new List <ChartSeriesViewModel>();

            // Вычисляем периоды в графике обучения
            int startWeek = 1;

            for (int currentWeek = 1; currentWeek <= courseSchedule.Schedule.Length - 1; currentWeek++)
            {
                var currentAbbr = courseSchedule.Schedule[currentWeek - 1];
                var nextAbbr    = courseSchedule.Schedule[currentWeek];
                if (currentAbbr != nextAbbr || currentWeek == courseSchedule.Schedule.Length - 1)
                {
                    var series = chartSeries.SingleOrDefault(x => x.name == currentAbbr + "");
                    if (series == null)
                    {
                        var scheduleType = ScheduleHelpers.ScheduleTypeByAbbr(currentAbbr);
                        series = new ChartSeriesViewModel
                        {
                            name       = scheduleType["Name"],
                            color      = scheduleType["Color"],
                            pointWidth = 12,
                            pointRange = 24 * 3600 * 1000
                        };
                        chartSeries.Add(series);
                    }

                    if (series.data == null)
                    {
                        series.data = new List <ChartIntervalViewModel>();
                    }

                    // Т.к. индексация массива начинается с 0, чтобы перейти к последней неделе
                    if (currentWeek == courseSchedule.Schedule.Length - 1)
                    {
                        currentWeek++;
                    }

                    var low  = ScheduleHelpers.DateOfLesson(UserProfile.EducationYear.DateStart, startWeek, 1);
                    var high = ScheduleHelpers.DateOfLesson(UserProfile.EducationYear.DateStart, currentWeek, 7).AddDays(1).AddSeconds(-1);

                    var interval = new ChartIntervalViewModel
                    {
                        x        = 0,
                        low      = (long)(low - new DateTime(1970, 1, 1)).TotalMilliseconds,
                        high     = (long)(high - new DateTime(1970, 1, 1)).TotalMilliseconds,
                        lowWeek  = startWeek,
                        highWeek = currentWeek
                    };
                    series.data.Add(interval);

                    startWeek   = currentWeek + 1;
                    currentAbbr = nextAbbr;
                }
            }

            return(Json(
                       new
            {
                educationYear = UserProfile.EducationYear.YearStart + "/" + UserProfile.EducationYear.YearEnd,
                chartSeries = chartSeries
            }));
        }