Example #1
0
        public IEnumerable <KeyValuePair <string, int> > GetContentVisitChartDataForUserDashboard(int userId, ContentType contentType)
        {
            var chartData = VisitBiz.GetContentVisitChartDataForUserDashboard(userId, contentType);

            ChartDataHelper.FillBlankDays <ChartData>(chartData);
            return(chartData.Select(data => new KeyValuePair <string, int>(data.Date.ToPersianDate("MMDD"), data.Value)));
        }
        //[HttpGet]
        //public ActionResult GetAuthorTotalBlogPostsChartData()
        //{
        //    var result = AppStatisticsService.GetAuthorTotalBlogPostsChartData(User).ToList();
        //    return GetChartData(result);
        //}

        private ActionResult GetChartData(List <ChartData> result)
        {
            ChartDataHelper.FillBlankDays(result);
            var chartData = result.Select(cd => new { Date = cd.Date.ToNumericPersianDateString(), Visits = cd.Value });

            return(Json(chartData, JsonRequestBehavior.AllowGet));
        }
Example #3
0
        protected override void SetSeriesStyle(ChartAreaData data, AreaSeries series)
        {
            ChartAreaStyle style = data.Style;

            series.Fill            = ChartDataHelper.Convert(style.FillColor);
            series.Color           = ChartDataHelper.Convert(style.StrokeColor);
            series.StrokeThickness = style.StrokeThickness;
        }
        protected override void SetSeriesStyle(ChartLineData data, LineSeries series)
        {
            ChartLineStyle style = data.Style;

            series.Color           = ChartDataHelper.Convert(style.Color);
            series.StrokeThickness = style.Width;
            series.LineStyle       = ChartDataHelper.Convert(style.DashStyle);
        }
Example #5
0
        public void Convert_ValidChartPointSymbol_ReturnsExpectedMarkerType(ChartPointSymbol chartPointSymbol,
                                                                            MarkerType expectedMarkerType)
        {
            // Call
            MarkerType markerType = ChartDataHelper.Convert(chartPointSymbol);

            // Assert
            Assert.AreEqual(expectedMarkerType, markerType);
        }
Example #6
0
        public void Convert_ValidChartLineDashStyle_ReturnsExpectedLineStyle(ChartLineDashStyle chartLineDashStyle,
                                                                             LineStyle expectedLineStyle)
        {
            // Call
            LineStyle lineStyle = ChartDataHelper.Convert(chartLineDashStyle);

            // Assert
            Assert.AreEqual(expectedLineStyle, lineStyle);
        }
        public void PointArray()
        {
            var dataSource      = new[] { new Point(2, 3), new Point(4, 5), new Point(6, 7) };
            var chartDataSource = ChartDataHelper.CreateChartDataSource(dataSource, null, null, null, null, null, null);

            Assert.AreEqual(3, chartDataSource.Count);
            Assert.AreEqual(new DataPoint(new Point(2, 3), null), chartDataSource[0]);
            Assert.AreEqual(new DataPoint(new Point(4, 5), null), chartDataSource[1]);
            Assert.AreEqual(new DataPoint(new Point(6, 7), null), chartDataSource[2]);
        }
        /// <summary>
        /// Converts all general properties of <see cref="RowChartData"/>
        /// from <paramref name="data"/> to <paramref name="series"/>.
        /// </summary>
        /// <param name="data">The row chart data to convert the general properties from.</param>
        /// <param name="series">The series to convert the general properties to.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="data"/>
        /// or <paramref name="series"/> is <c>null</c>.</exception>
        public static void ConvertSeriesProperties(RowChartData data, ColumnSeries series)
        {
            ValidateParameters(data, series);

            series.Title = data.Name;

            if (data.Color.HasValue)
            {
                series.FillColor = ChartDataHelper.Convert(data.Color.Value);
            }
        }
Example #9
0
        protected override void SetSeriesStyle(ChartPointData data, LineSeries series)
        {
            series.LineStyle = LineStyle.None;
            ChartPointStyle style = data.Style;

            series.MarkerFill            = ChartDataHelper.Convert(style.Color);
            series.MarkerSize            = style.Size;
            series.MarkerType            = ChartDataHelper.Convert(style.Symbol);
            series.MarkerStroke          = ChartDataHelper.Convert(style.StrokeColor);
            series.MarkerStrokeThickness = style.StrokeThickness;
        }
        public void DataPointCollection()
        {
            var dataSource = new DataPointCollection {
                new DataPoint(2, 3, null), new DataPoint(4, 5, null), new DataPoint(6, 7, null)
            };
            var chartDataSource = ChartDataHelper.CreateChartDataSource(dataSource, null, null, null, null, null, null);

            Assert.AreEqual(3, chartDataSource.Count);
            Assert.AreEqual(new DataPoint(new Point(2, 3), null), chartDataSource[0]);
            Assert.AreEqual(new DataPoint(new Point(4, 5), null), chartDataSource[1]);
            Assert.AreEqual(new DataPoint(new Point(6, 7), null), chartDataSource[2]);
        }
        public void ObservableCollectionOfPoints()
        {
            var dataSource = new ObservableCollection <Point> {
                new Point(2, 3), new Point(4, 5), new Point(6, 7)
            };
            var chartDataSource = ChartDataHelper.CreateChartDataSource(dataSource, null, null, null, null, null, null);

            Assert.AreEqual(3, chartDataSource.Count);
            Assert.AreEqual(new DataPoint(new Point(2, 3), null), chartDataSource[0]);
            Assert.AreEqual(new DataPoint(new Point(4, 5), null), chartDataSource[1]);
            Assert.AreEqual(new DataPoint(new Point(6, 7), null), chartDataSource[2]);
        }
Example #12
0
        public void Convert_Color_ReturnsOxyColor(KnownColor knownColor)
        {
            // Setup
            Color color = Color.FromKnownColor(knownColor);

            // Call
            OxyColor oxyColor = ChartDataHelper.Convert(color);

            // Assert
            OxyColor originalColor = OxyColor.FromArgb(color.A, color.R, color.G, color.B);

            Assert.AreEqual(originalColor, oxyColor);
        }
Example #13
0
        public void Convert_InvalidChartLineDashStyle_ThrowsInvalidEnumArgumentException()
        {
            // Setup
            const int invalidValue = 100;

            // Call
            TestDelegate call = () => ChartDataHelper.Convert((ChartLineDashStyle)invalidValue);

            // Assert
            string expectedMessage = $"The value of argument 'dashStyle' ({invalidValue}) is invalid for Enum type '{nameof(ChartLineDashStyle)}'.";
            string parameterName   = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <InvalidEnumArgumentException>(call, expectedMessage).ParamName;

            Assert.AreEqual("dashStyle", parameterName);
        }
        public void DateSourceWithTextLabelsForXAndY()
        {
            var xLabels = new List <TextLabel>
            {
                new TextLabel(1.0, "x1"),
                new TextLabel(2.0, "x2"),
                new TextLabel(3.0, "x3"),
                new TextLabel(4.0, "x4"),
            };
            var yLabels = new List <TextLabel>
            {
                new TextLabel(1.0, "y1"),
                new TextLabel(2.0, "y2"),
                new TextLabel(3.0, "y3"),
                new TextLabel(4.0, "y4"),
            };
            var dataSource = new List <CustomObjectWithStrings>
            {
                new CustomObjectWithStrings {
                    X = "x1", Y = "3", Text = "Text 1"
                },
                new CustomObjectWithStrings {
                    X = "x2", Y = "y1", Text = "Text 2"
                },
                new CustomObjectWithStrings {
                    X = "x3", Y = "y4", Text = "Text 3"
                },
                new CustomObjectWithStrings {
                    X = "x4", Y = "y3", Text = "Text 4"
                },
            };

            var chartDataSource = ChartDataHelper.CreateChartDataSource(dataSource, new PropertyPath("X"), new PropertyPath("Y"), null, CultureInfo.InvariantCulture, xLabels, yLabels);

            Assert.AreEqual(4, xLabels.Count);
            Assert.AreEqual(4, yLabels.Count);
            Assert.AreEqual(4, chartDataSource.Count);
            Assert.AreEqual(new DataPoint(new Point(1, 3), dataSource[0]), chartDataSource[0]);
            Assert.AreEqual(new DataPoint(new Point(2, 1), dataSource[1]), chartDataSource[1]);
            Assert.AreEqual(new DataPoint(new Point(3, 4), dataSource[2]), chartDataSource[2]);
            Assert.AreEqual(new DataPoint(new Point(4, 3), dataSource[3]), chartDataSource[3]);
        }
        public void CompositeDataSource()
        {
            var xValues = new List <CustomObjectWithStrings>
            {
                new CustomObjectWithStrings {
                    X = "2.00000", Text = "Text 1"
                },
                new CustomObjectWithStrings {
                    X = "04", Text = "Text 2"
                },
                new CustomObjectWithStrings {
                    X = "+6.0", Text = "Text 3"
                },
            };
            var yValues = new List <CustomObjectWithXY>
            {
                new CustomObjectWithXY {
                    MyY = 3, Text = "Text 1"
                },
                new CustomObjectWithXY {
                    MyY = 5, Text = "Text 2"
                },
                new CustomObjectWithXY {
                    MyY = 7, Text = "Text 3"
                },
            };
            var dataSource = new CompositeDataSource
            {
                XValues = xValues,
                YValues = yValues,
            };
            var chartDataSource = ChartDataHelper.CreateChartDataSource(dataSource, new PropertyPath("X"), new PropertyPath("MyY"), null, CultureInfo.InvariantCulture, null, null);

            Assert.AreEqual(3, chartDataSource.Count);
            Assert.AreEqual(new Point(2, 3), chartDataSource[0].Point);
            Assert.AreEqual(new Point(4, 5), chartDataSource[1].Point);
            Assert.AreEqual(new Point(6, 7), chartDataSource[2].Point);
            Assert.AreEqual(new CompositeData(xValues[0], yValues[0]), chartDataSource[0].DataContext);
            Assert.AreEqual(new CompositeData(xValues[1], yValues[1]), chartDataSource[1].DataContext);
            Assert.AreEqual(new CompositeData(xValues[2], yValues[2]), chartDataSource[2].DataContext);
        }
        public void DateSourceWithDateTimeStrings()
        {
            var dataSource = new List <CustomObjectWithStrings>
            {
                new CustomObjectWithStrings {
                    X = new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString(), Y = new DateTime(2002, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString(), Text = "Text 1"
                },
                new CustomObjectWithStrings {
                    X = new DateTime(2003, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString(), Y = new DateTime(2004, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString(), Text = "Text 2"
                },
                new CustomObjectWithStrings {
                    X = new DateTime(2005, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString(), Y = new DateTime(2006, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString(), Text = "Text 3"
                },
            };
            var chartDataSource = ChartDataHelper.CreateChartDataSource(dataSource, new PropertyPath("X"), new PropertyPath("Y"), null, null, null, null);

            Assert.AreEqual(3, chartDataSource.Count);
            Assert.AreEqual(new DataPoint(new Point(new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks, new DateTime(2002, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks), dataSource[0]), chartDataSource[0]);
            Assert.AreEqual(new DataPoint(new Point(new DateTime(2003, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks, new DateTime(2004, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks), dataSource[1]), chartDataSource[1]);
            Assert.AreEqual(new DataPoint(new Point(new DateTime(2005, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks, new DateTime(2006, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks), dataSource[2]), chartDataSource[2]);
        }
        public void XYValuePath()
        {
            var dataSource = new List <CustomObjectWithPoint>
            {
                new CustomObjectWithPoint {
                    MyPoint = new Point(2, 3), Text = "Text 1"
                },
                new CustomObjectWithPoint {
                    MyPoint = new Point(4, 5), Text = "Text 2"
                },
                new CustomObjectWithPoint {
                    MyPoint = new Point(6, 7), Text = "Text 3"
                },
            };
            var chartDataSource = ChartDataHelper.CreateChartDataSource(dataSource, null, null, new PropertyPath("MyPoint"), null, null, null);

            Assert.AreEqual(3, chartDataSource.Count);
            Assert.AreEqual(new DataPoint(new Point(2, 3), dataSource[0]), chartDataSource[0]);
            Assert.AreEqual(new DataPoint(new Point(4, 5), dataSource[1]), chartDataSource[1]);
            Assert.AreEqual(new DataPoint(new Point(6, 7), dataSource[2]), chartDataSource[2]);
        }
        public void XValuePathAndYValuePath()
        {
            var dataSource = new List <CustomObjectWithXY>
            {
                new CustomObjectWithXY {
                    MyX = 2, MyY = 3, Text = "Text 1"
                },
                new CustomObjectWithXY {
                    MyX = 4, MyY = 5, Text = "Text 2"
                },
                new CustomObjectWithXY {
                    MyX = 6, MyY = 7, Text = "Text 3"
                },
            };
            var chartDataSource = ChartDataHelper.CreateChartDataSource(dataSource, new PropertyPath("MyX"), new PropertyPath("MyY"), null, null, null, null);

            Assert.AreEqual(3, chartDataSource.Count);
            Assert.AreEqual(new DataPoint(new Point(2, 3), dataSource[0]), chartDataSource[0]);
            Assert.AreEqual(new DataPoint(new Point(4, 5), dataSource[1]), chartDataSource[1]);
            Assert.AreEqual(new DataPoint(new Point(6, 7), dataSource[2]), chartDataSource[2]);
        }
        public void DateSourceWithDoubleStringsGerman()
        {
            var dataSource = new List <CustomObjectWithStrings>
            {
                new CustomObjectWithStrings {
                    X = "2,00000", Y = "3,0", Text = "Text 1"
                },
                new CustomObjectWithStrings {
                    X = "0.004", Y = "5", Text = "Text 2"
                },
                new CustomObjectWithStrings {
                    X = "+6,0", Y = "7e0", Text = "Text 3"
                },
            };
            var chartDataSource = ChartDataHelper.CreateChartDataSource(dataSource, new PropertyPath("X"), new PropertyPath("Y"), null, new CultureInfo("de-AT"), null, null);

            Assert.AreEqual(3, chartDataSource.Count);
            Assert.AreEqual(new DataPoint(new Point(2, 3), dataSource[0]), chartDataSource[0]);
            Assert.AreEqual(new DataPoint(new Point(4, 5), dataSource[1]), chartDataSource[1]);
            Assert.AreEqual(new DataPoint(new Point(6, 7), dataSource[2]), chartDataSource[2]);
        }
        public void DateSourceWithTextLabelsForY()
        {
            var textLabels = new List <TextLabel>
            {
                new TextLabel(2.0, "Label2"),
                new TextLabel(4.0, "Label4"),
            };
            var dataSource = new List <CustomObjectWithStrings>
            {
                new CustomObjectWithStrings {
                    X = "1", Y = "3", Text = "Text 1"
                },
                new CustomObjectWithStrings {
                    X = "2", Y = "Label2", Text = "Text 2"
                },
                new CustomObjectWithStrings {
                    X = "4", Y = "Label4", Text = "Text 3"
                },
                new CustomObjectWithStrings {
                    X = "5", Y = "Label5", Text = "Text 4"
                },
            };

            var chartDataSource = ChartDataHelper.CreateChartDataSource(dataSource, new PropertyPath("X"), new PropertyPath("Y"), null, CultureInfo.InvariantCulture, null, textLabels);

            Assert.AreEqual(3, textLabels.Count);
            Assert.AreEqual(new TextLabel(2.0, "Label2"), textLabels[0]);
            Assert.AreEqual(new TextLabel(4.0, "Label4"), textLabels[1]);
            Assert.AreEqual(new TextLabel(5.0, "Label5"), textLabels[2]);

            Assert.AreEqual(4, chartDataSource.Count);
            Assert.AreEqual(new DataPoint(new Point(1, 3), dataSource[0]), chartDataSource[0]);
            Assert.AreEqual(new DataPoint(new Point(2, 2), dataSource[1]), chartDataSource[1]);
            Assert.AreEqual(new DataPoint(new Point(4, 4), dataSource[2]), chartDataSource[2]);
            Assert.AreEqual(new DataPoint(new Point(5, 5), dataSource[3]), chartDataSource[3]);
        }
 public void InvalidDataSource()
 {
     ChartDataHelper.CreateChartDataSource(new double[] { 1, 2, 3 }, null, null, null, null, null, null);
 }
        public void NullDataSource()
        {
            var chartDataSource = ChartDataHelper.CreateChartDataSource(null, null, null, null, null, null, null);

            Assert.AreEqual(0, chartDataSource.Count);
        }