public void Black_is_transformed_to_first_color()
        {
            Color c1 = Color.FromArgb(unchecked ((int)0xFF_FF_FF_00));
            Color c2 = Color.FromArgb(unchecked ((int)0xFF_00_FF_00));


            var transformation = new ColorSchemeTransformation(c1.ToHsv(), c2.ToHsv());
            var sourceColor    = Color.FromArgb(unchecked ((int)0xFF_00_00_00));
            var transformed    = transformation.TransformColor(sourceColor);

            Assert.That(transformed.ToArgb(), Is.EqualTo(unchecked ((int)0xFF_FF_FF_00)));
        }
        public void Black_is_transformed_to_first_color_In_byte_array()
        {
            Color c1 = Color.FromArgb(unchecked ((int)0xFF_FF_FF_00));
            Color c2 = Color.FromArgb(unchecked ((int)0xFF_00_FF_00));


            var transformation = new ColorSchemeTransformation(c1.ToHsv(), c2.ToHsv());
            var rgbValues      = new byte[] { 0x00, 0x00, 0x00, 0xFF };

            transformation.Transform(rgbValues, 0);

            var expectedTransformed = new byte[] { 0xFF, 0xFF, 0x00, 0xFF };

            Assert.That(rgbValues, Is.EquivalentTo(expectedTransformed));
        }
        public void Brightness_adaptation_Interpolates_hue_saturation_and_value(
            [Values(0f, 0.5f, 1f)] float v,
            [Values(90f)] float c1h,
            [Values(-30f, 30f)] float dh)
        {
            HsvColor c1 = new HsvColor(c1h, 1f, 1f);
            HsvColor c2 = new HsvColor(c1h + dh, 1f, 1f);

            var transformation = new ColorSchemeTransformation(c1, c2);

            var sourceColor = new HsvColor(0, 0, v);
            var resultColor = transformation.Transform(sourceColor);

            Assert.That(resultColor.H, Is.EqualTo(c1.H + v * (c2.H - c1.H)).Within(0.01f));
            Assert.That(resultColor.S, Is.EqualTo(c1.S + v * (c2.S - c1.S)).Within(0.01f));
            Assert.That(resultColor.V, Is.EqualTo(c1.V + v * (c2.V - c1.V)).Within(0.01f));
        }
Exemple #4
0
        private void populateData(
            List <string> arguments,
            List <string> series,
            List <List <object[]> > seriesValues,
            IList <object[]> argumentTotals,
            IList <object[]> seriesTotals,
            ReportSettings settings)
        {
            _chart = createChart();

            var colorTransformation = new ColorSchemeTransformation(null);

            var originalPalette = ChartPalettes.OriginalByName[_chart.Palette];
            var palette         = ChartPalettes.ByName[_chart.Palette];

            for (int i = 0; i < palette.Length; i++)
            {
                palette[i] = colorTransformation.TransformColor(originalPalette[i]);
            }

            var summaryFields = settings.SummaryFields;

            var metadata = ChartTypeMetadata.ByType[settings.ChartType];

            if (metadata.CanDisplayMultipleSeries)
            {
                _chart.Legends.Add(createLegend());
            }

            ChartArea area = null;

            Series[]        seriesList             = null;
            string[]        seriesSummaryLegend    = null;
            List <string>[] argumentSummaryLegends = null;

            for (int k = 0; k < summaryFields.Count; k++)
            {
                string summaryFieldAlias    = _fields.ByName[summaryFields[k]].Alias;
                string summaryFunctionAlias = Aggregates.Alias[settings.SummaryFunctions[k]];

                if (k == 0 || !metadata.CanDisplayMultipleSeries)
                {
                    area = createArea();
                    _chart.ChartAreas.Add(area);

                    if (metadata.SwitchValueAxes)
                    {
                        area.AxisX.IsReversed = true;
                    }

                    if (metadata.IsPieChart)
                    {
                        area.Area3DStyle.Enable3D    = true;
                        area.Area3DStyle.Inclination = 30;
                    }

                    seriesSummaryLegend = new string[series.Count];

                    argumentSummaryLegends = new List <string> [arguments.Count];
                    for (int i = 0; i < arguments.Count; i++)
                    {
                        argumentSummaryLegends[i] = new List <string>();
                    }

                    if (metadata.CanDisplayMultipleSeries)
                    {
                        seriesList = new Series[series.Count * summaryFields.Count];
                    }
                    else
                    {
                        seriesList = new Series[1];
                    }

                    for (int j = 0; j < seriesList.Length; j++)
                    {
                        var chartSeries = new Series
                        {
                            ChartType = settings.ChartType,
                            ChartArea = area.Name,

                            LabelForeColor = SystemColors.WindowText,
                            BorderColor    = SystemColors.ActiveBorder,
                            MarkerColor    = SystemColors.ActiveBorder
                        };

                        chartSeries.Font = chartSeries.Font.ByDpi();

                        if (settings.LabelDataElement == DataElement.None)
                        {
                            chartSeries.IsValueShownAsLabel = false;
                        }
                        else
                        {
                            chartSeries.LabelFormat = @"0.##";
                            chartSeries.EmptyPointStyle.LabelFormat = @"#";
                            chartSeries.IsValueShownAsLabel         = true;
                        }

                        seriesList[j] = chartSeries;

                        if (metadata.IsPieChart)
                        {
                            chartSeries[@"PieLabelStyle"] = @"Outside";
                            chartSeries[@"PieLineColor"]  = @"Gray";
                        }

                        chartSeries[@"PyramidValueType"] = @"Surface";

                        _chart.Series.Add(chartSeries);

                        chartSeries.IsVisibleInLegend = settings.ShowSeriesTotal && metadata.CanDisplayMultipleSeries;
                    }
                }


                if (metadata.CanDisplayMultipleSeries && metadata.SupportStackedGroups)
                {
                    for (int j = 0; j < series.Count; j++)
                    {
                        var chartSeries = seriesList[k * series.Count + j];
                        chartSeries[@"StackedGroupName"] = summaryFieldAlias;
                    }
                }

                for (int i = 0; i < arguments.Count; i++)
                {
                    for (int j = 0; j < series.Count; j++)
                    {
                        Series chartSeries;
                        if (metadata.CanDisplayMultipleSeries)
                        {
                            chartSeries = seriesList[k * series.Count + j];
                        }
                        else
                        {
                            chartSeries = seriesList[0];
                        }

                        var yValue = seriesValues[j][i][k];

                        chartSeries.Points.AddXY(arguments[i], yValue);

                        var point = chartSeries.Points[chartSeries.Points.Count - 1];

                        if (yValue == null || Convert.ToSingle(yValue) < 0.009f)
                        {
                            point.IsEmpty = true;
                        }
                        else if (settings.LabelDataElement == DataElement.SummaryField)
                        {
                            point.Label = $"{yValue:0.##}: {summaryFieldAlias}";
                        }
                        else if (settings.LabelDataElement == DataElement.Series)
                        {
                            point.Label = $"{yValue:0.##}: {series[j]}";
                        }
                        else if (settings.LabelDataElement == DataElement.Argument)
                        {
                            point.Label = $"{yValue:0.##}: {arguments[i]}";
                        }
                        else if (settings.LabelDataElement == DataElement.SeriesAndArgument)
                        {
                            point.Label = $"{yValue:0.##}: {arguments[i]}, {series[j]}";
                        }
                        else if (settings.LabelDataElement == DataElement.Values)
                        {
                            point.Label = $"{yValue:0.##}";
                        }
                        else
                        {
                            point.Label = null;
                        }

                        if (series.Count > 1)
                        {
                            point.Color = palette[j % palette.Length];
                        }
                        else if (!metadata.RequireAxes)
                        {
                            point.Color = palette[i % palette.Length];
                        }
                        else if (summaryFields.Count > 1)
                        {
                            point.Color = palette[k % palette.Length];
                        }
                    }
                }

                if (settings.ShowSeriesTotal)
                {
                    for (int j = 0; j < series.Count; j++)
                    {
                        string legend;

                        bool   seriesSet = settings.SeriesFields.Count > 1 || settings.SeriesFields[0] != string.Empty;
                        string seriesName;
                        if (seriesSet)
                        {
                            seriesName = series[j];
                        }
                        else
                        {
                            seriesName = $"{summaryFunctionAlias} {summaryFieldAlias}";
                        }

                        if (settings.ExplainTotal && seriesSet)
                        {
                            legend = $"{seriesName}: {seriesTotals[j][k]}, {summaryFunctionAlias} {summaryFieldAlias}";
                        }
                        else
                        {
                            legend = $"{seriesName}: {seriesTotals[j][k]}";
                        }

                        if (metadata.CanDisplayMultipleSeries)
                        {
                            seriesList[k * series.Count + j].LegendText = legend;
                        }
                        else
                        {
                            seriesSummaryLegend[j] = legend;
                        }
                    }
                }

                if (settings.ShowArgumentTotal)
                {
                    for (int i = 0; i < arguments.Count; i++)
                    {
                        string legend;

                        if (settings.ExplainTotal)
                        {
                            legend = $"{arguments[i]}: {argumentTotals[i][k]}, {summaryFunctionAlias} {summaryFieldAlias}";
                        }
                        else
                        {
                            legend = $"{arguments[i]}: {argumentTotals[i][k]}";
                        }

                        argumentSummaryLegends[i].Add(legend);
                    }
                }

                if ((settings.ShowSeriesTotal || settings.ShowArgumentTotal) && !metadata.CanDisplayMultipleSeries)
                {
                    var legend = createLegend();

                    legend.DockedToChartArea       = area.Name;
                    legend.IsDockedInsideChartArea = false;

                    if (settings.ShowSeriesTotal)
                    {
                        for (int j = 0; j < seriesSummaryLegend.Length; j++)
                        {
                            string seriesLegend = seriesSummaryLegend[j];
                            legend.CustomItems.Add(palette[j % palette.Length], seriesLegend);
                        }
                    }

                    if (settings.ShowArgumentTotal)
                    {
                        for (int i = 0; i < argumentSummaryLegends.Length; i++)
                        {
                            var argumentLegend = argumentSummaryLegends[i];
                            legend.CustomItems.Add(SystemColors.ActiveBorder, argumentLegend[0]);
                        }
                    }

                    _chart.Legends.Add(legend);
                }
            }

            if (metadata.CanDisplayMultipleSeries && settings.ShowArgumentTotal)
            {
                var argumentSummaries = argumentSummaryLegends
                                        .Select(legends => string.Join("\r\n", legends))
                                        .ToArray();

                for (int k = 0; k < summaryFields.Count; k++)
                {
                    for (int j = 0; j < series.Count; j++)
                    {
                        var chartSeries = _chart.Series[k * series.Count + j];

                        for (int i = 0; i < chartSeries.Points.Count; i++)
                        {
                            chartSeries.Points[i].AxisLabel = argumentSummaries[i];
                        }
                    }
                }
            }

            setupScrollbar(metadata);
        }
Exemple #5
0
        private void populateDataNPlot(
            List <string> arguments,
            List <string> series,
            List <List <object[]> > seriesValues,
            IList <object[]> argumentTotals,
            IList <object[]> seriesTotals,
            ReportSettings settings)
        {
            var chart = new PlotSurface2D
            {
                BackColor     = SystemColors.Control,
                ForeColor     = SystemColors.ControlText,
                PlotBackColor = SystemColors.Window,
                TitleColor    = SystemColors.ControlText,
                SmoothingMode = SmoothingMode.HighQuality,
                Font          = Font
            };

            replaceChart(chart);
            if (arguments.Count == 0)
            {
                return;
            }

            var colorTransformation = new ColorSchemeTransformation(null)
            {
                IgnoreSaturation = true,
                AsBackground     = true,
            };

            var palette = _palette
                          .Select(colorTransformation.TransformColor)
                          .ToArray();

            var summaryFields = settings.SummaryFields;

            chart.Legend = new Legend
            {
                BackgroundColor = SystemColors.Window,
                TextColor       = SystemColors.WindowText,
                BorderColor     = SystemColors.ActiveBorder
            };

            chart.Legend.Font = chart.Legend.Font.ByDpi();
            chart.Add(new Grid
            {
                VerticalGridType   = Grid.GridType.Fine,
                HorizontalGridType = Grid.GridType.None,
                MinorGridPen       = new Pen(SystemColors.GrayText)
                {
                    DashPattern = new[] { 1f, 5f }
                },
                MajorGridPen = new Pen(SystemColors.GrayText)
            });

            var seriesSummaryLegend    = new string[series.Count];
            var argumentSummaryLegends = new List <string> [arguments.Count];

            for (int i = 0; i < arguments.Count; i++)
            {
                argumentSummaryLegends[i] = new List <string>();
            }

            var seriesList = new HistogramPlot[series.Count * summaryFields.Count];

            float totalBarWidth = 0.75f;
            float barWidth      = totalBarWidth / summaryFields.Count;

            double minY = double.MaxValue;
            double maxY = double.MinValue;

            var dataLabels = new List <TextItem>();

            for (int k = 0; k < summaryFields.Count; k++)
            {
                float barOffset = (barWidth - totalBarWidth) * 0.5f + k * barWidth;

                string summaryFieldAlias    = _fields.ByName[summaryFields[k]].Alias;
                string summaryFunctionAlias = Aggregates.Alias[settings.SummaryFunctions[k]];

                var stackedYValues = new double[arguments.Count];
                minY = Math.Min(0d, minY);
                maxY = Math.Max(0d, maxY);

                for (int j = 0; j < series.Count; j++)
                {
                    int n = k * series.Count + j;

                    Color color       = palette[n % palette.Length];
                    var   chartSeries = new HistogramPlot
                    {
                        Filled         = true,
                        RectangleBrush = new RectangleBrushes.Solid(color),
                        BaseWidth      = barWidth,
                        BaseOffset     = barOffset,
                        Color          = color,
                    };

                    seriesList[n] = chartSeries;
                    chart.Add(chartSeries);
                    chartSeries.ShowInLegend = settings.ShowSeriesTotal;

                    chartSeries.Label = series[j];
                    var yValues = Enumerable.Range(0, arguments.Count)
                                  .Select(i => Convert.ToDouble(seriesValues[j][i][k] ?? 0))
                                  .ToList();

                    chartSeries.DataSource = yValues;
                    for (int i = 0; i < arguments.Count; i++)
                    {
                        stackedYValues[i] += yValues[i];
                    }

                    minY = Math.Min(minY, stackedYValues.Min());
                    maxY = Math.Max(maxY, stackedYValues.Max());

                    if (j > 0)
                    {
                        chartSeries.StackedTo(seriesList[n - 1]);
                    }

                    for (int i = 0; i < arguments.Count; i++)
                    {
                        double yValue = yValues[i];
                        if (yValue < 0.009)
                        {
                            continue;
                        }

                        string text;
                        switch (settings.LabelDataElement)
                        {
                        case DataElement.SummaryField:
                            text = $"{yValue:0.##}: {summaryFieldAlias}";
                            break;

                        case DataElement.Series:
                            text = $"{yValue:0.##}: {series[j]}";
                            break;

                        case DataElement.Argument:
                            text = $"{yValue:0.##}: {arguments[i]}";
                            break;

                        case DataElement.SeriesAndArgument:
                            text = $"{yValue:0.##}: {arguments[i]}, {series[j]}";
                            break;

                        case DataElement.Values:
                            text = $"{yValue:0.##}";
                            break;

                        default:
                            continue;
                        }

                        var labelY = stackedYValues[i] - yValue * 0.5;
                        dataLabels.Add(new TextItem(
                                           new PointD(i + barOffset - 0.5f * barWidth + 0.05, labelY),
                                           text)
                        {
                            TextColor = SystemColors.ControlText,
                        });
                    }
                }

                // if (settings.ShowSeriesTotal)
                //  for (int j = 0; j < series.Count; j++)
                //  {
                //      string legend;
                //
                //      bool seriesSet = settings.SeriesFields.Count > 1 || settings.SeriesFields[0] != string.Empty;
                //      string seriesName;
                //      if (seriesSet)
                //          seriesName = series[j];
                //      else
                //          seriesName = $"{summaryFunctionAlias} {summaryFieldAlias}";
                //
                //      if (settings.ExplainTotal && seriesSet)
                //          legend = $"{seriesName}: {seriesTotals[j][k]}, {summaryFunctionAlias} {summaryFieldAlias}";
                //      else
                //          legend = $"{seriesName}: {seriesTotals[j][k]}";
                //
                //      if (metadata.CanDisplayMultipleSeries)
                //          seriesList[k * series.Count + j].LegendText = legend;
                //      else
                //          seriesSummaryLegend[j] = legend;
                //  }
                //
                // if (settings.ShowArgumentTotal)
                //  for (int i = 0; i < arguments.Count; i++)
                //  {
                //      string legend;
                //
                //      if (settings.ExplainTotal)
                //          legend = $"{arguments[i]}: {argumentTotals[i][k]}, {summaryFunctionAlias} {summaryFieldAlias}";
                //      else
                //          legend = $"{arguments[i]}: {argumentTotals[i][k]}";
                //
                //      argumentSummaryLegends[i].Add(legend);
                //  }
            }

            int largeTickStep = getLargeTickStep(maxY);

            chart.YAxis1 = new LinearAxis
            {
                WorldMin           = minY,
                WorldMax           = maxY + 0.5,
                LargeTickStep      = largeTickStep,
                NumberOfSmallTicks = Math.Min(4, largeTickStep - 1),
                TickTextFont       = Font,
                Color         = SystemColors.WindowText,
                LabelColor    = SystemColors.WindowText,
                TickTextColor = SystemColors.WindowText,
            };
            var la = new LabelAxis
            {
                WorldMin           = -0.5,
                WorldMax           = arguments.Count - 0.5,
                TickTextFont       = Font,
                Color              = SystemColors.WindowText,
                LabelColor         = SystemColors.WindowText,
                TickTextColor      = SystemColors.WindowText,
                TickTextNextToAxis = false,
                TicksLabelAngle    = 10f
            };

            chart.XAxis1 = la;
            if (settings.ShowArgumentTotal)
            {
                var argumentSummaries = argumentSummaryLegends
                                        .Select(legends => string.Join("\n", legends))
                                        .ToArray();
                for (int i = 0; i < arguments.Count; i++)
                {
                    la.AddLabel((arguments[i] + '\n' + argumentSummaries[i]).TrimEnd(), i);
                }
            }
            else
            {
                for (int i = 0; i < arguments.Count; i++)
                {
                    la.AddLabel(arguments[i], i);
                }
            }

            foreach (TextItem label in dataLabels)
            {
                chart.Add(label);
            }
        }