Пример #1
0
        private static void adjustAxisDimensionForGroupPlots(GroupPlot groupPlot)
        {
            var axisOptions = groupPlot.AxisOptions;
            var landscape   = groupPlot.Landscape;
            var columns     = groupPlot.GroupOptions.Columns;
            var rows        = groupPlot.GroupOptions.Rows;

            const float percentageHeigt = 70F; // reserve some space for groupings and captions
            const float percentageWidth = 100F;

            var isLegendBeside = false;

            if (groupPlot.GroupOptions.GroupLegendOptions.LegendOptions != null)
            {
                isLegendBeside = getIsLegendBeside(groupPlot.GroupOptions.GroupLegendOptions.LegendOptions.LegendPosition);
            }

            var factor = isLegendBeside ? 0.6 : 1;

            if (landscape)
            {
                axisOptions.Height = Helper.GetLengthInPercentageOfTextHeight(percentageWidth / rows);
                axisOptions.Width  = Helper.GetLengthInPercentageOfTextWidth(percentageHeigt / columns);
            }
            else
            {
                axisOptions.Height = Helper.GetLengthInPercentageOfTextHeight(percentageHeigt / rows);
                axisOptions.Width  = Helper.GetLengthInPercentageOfTextWidth(percentageWidth * factor / columns);
            }
        }
Пример #2
0
        /// <summary>
        /// This method creates a figure.
        /// </summary>
        /// <remarks>A figure environment will be placed somewhere according to position settings.
        /// It is an floating environment.</remarks>
        /// <param name="caption">Text for figure caption.</param>
        /// <param name="groupPlot">GroupPlot settings needed for generation.</param>
        /// <param name="converter">TEX converter.</param>
        internal static string GroupPlotFigure(string caption, GroupPlot groupPlot, ITeXConverter converter)
        {
            var allPlots = new List <PGFPlots.Plot>();

            foreach (var groupedPlot in groupPlot.GroupedPlots)
            {
                allPlots.AddRange(groupedPlot.Plots);
            }

            if (groupPlot.GroupOptions.GroupLegendOptions != null)
            {
                var maxLegendEntry = Enumerable.Max <string>(groupPlot.GroupOptions.GroupLegendOptions.LegendEntries, l => l.Length);

                if (String.IsNullOrEmpty(groupPlot.GroupOptions.GroupLegendOptions.LegendOptions.TextWidth))
                {
                    groupPlot.GroupOptions.GroupLegendOptions.LegendOptions.TextWidth = getLegendWidth(groupPlot.GroupOptions.GroupLegendOptions.LegendOptions.LegendPosition,
                                                                                                       groupPlot.Landscape, maxLegendEntry);
                }
            }

            adjustAxisDimensionForGroupPlots(groupPlot);

            var pictureText = new PlotWriter(groupPlot.Colors, converter).PictureGroupPlot(groupPlot.GroupedPlots,
                                                                                           groupPlot.AxisOptions,
                                                                                           groupPlot.GroupOptions);

            return(plotFigure(caption, groupPlot, pictureText));
        }
Пример #3
0
        private static GroupPlot getGroupPlot(List <Color> colors, LegendOptions.LegendPositions legendPosition, int columns)
        {
            var axisOptionsForGroup = getAxisOptionsForGroup();

            var plotOptions1 = getBoxPlotOptions(15F, 20F, 25F, 30F, 35F, 1F, Color.Blue.Name);
            var plotOptions2 = getBoxPlotOptions(26F, 31F, 34F, 41F, 44F, 1F, Color.Red.Name);
            var plotOptions3 = getBoxPlotOptions(18F, 22F, 27F, 32F, 38F, 2F, Color.Blue.Name);
            var plotOptions4 = getBoxPlotOptions(27F, 31F, 35F, 39F, 47F, 2F, Color.Red.Name);

            var coordinates = new List <Coordinate> {
                new Coordinate(0F, 5F)
            };
            var boxplot1 = new Plot(coordinates, plotOptions1);
            var boxplot2 = new Plot(coordinates, plotOptions2);
            var boxplot3 = new Plot(new List <Coordinate>(), plotOptions3);
            var boxplot4 = new Plot(new List <Coordinate>(), plotOptions4);

            var groupOptions = getGroupOptions(legendPosition, columns);

            var groupedPlots = new List <IBasePlot>();
            var plots        = new List <Plot> {
                boxplot1, boxplot2, boxplot3, boxplot4
            };
            var axisOptionsForPlotWithoutGroupLines = getAxisOptionsForPlot();
            var axisOptionsForPlot = getAxisOptionsForPlot();

            axisOptionsForPlot.GroupLines.Add(new AxisOptions.GroupLine(1F, 2F, "All", 1));
            axisOptionsForPlot.GroupLines.Add(new AxisOptions.GroupLine(1F, 2F, "Total", 2));

            var groupedPlot1 = new BasePlot(new AxisOptions(NoConverter.Instance)
            {
                IsEmptyGroupPlot = true
            }, new List <Plot>());
            var groupedPlot2 = new BasePlot(axisOptionsForPlotWithoutGroupLines, plots);
            var groupedPlot3 = new BasePlot(axisOptionsForPlot, plots);

            groupedPlots.Add(groupedPlot1);
            groupedPlots.Add(groupedPlot2);
            groupedPlots.Add(groupedPlot3);
            groupedPlots.Add(groupedPlot3);

            var plotItem = new GroupPlot(colors,
                                         axisOptionsForGroup,
                                         groupOptions,
                                         groupedPlots,
                                         new Text("Test Figure With Grouped Plots"))
            {
                Position = FigureWriter.FigurePositions.H
            };

            return(plotItem);
        }
Пример #4
0
        /// <summary>
        ///    This method is needed for grouped plot to get a legend with all lengend entries once for the whole group.
        /// </summary>
        /// <remarks>
        ///    In PGFPlots a legend can be placed outside of a plot with the legend to name feature.
        ///    When grouped plots do not all have the same number of plots used for legends only first plots are used for the
        ///    legend.
        ///    Therefor all plots get marked as not to be used for the legend.
        ///    For each pane dummy plots are generated which just are used for the legend creation.
        /// </remarks>
        private void updateLegendPlots(GroupPlot groupPlot, string[] legendEntries)
        {
            var legendPlots = getLegendPlots(groupPlot, legendEntries);

            foreach (var pane in groupPlot.GroupedPlots)
            {
                foreach (var plot in pane.Plots)
                {
                    plot.LegendEntry          = string.Empty;
                    plot.Options.ShowInLegend = false;
                }

                pane.InsertPlots(0, legendPlots);
            }
        }
Пример #5
0
        private void purgeMultipleSameAxisTitles(GroupPlot groupPlot)
        {
            var groupedPlots = groupPlot.GroupedPlots.ToList();

            if (!groupedPlots.Any())
            {
                return;
            }
            var title = groupedPlots.First().AxisOptions.YLabel;

            if (groupedPlots.Any(a => a.AxisOptions.YLabel != title))
            {
                return;
            }
            groupedPlots.Each(a => a.AxisOptions.YLabel = String.Empty);
            var index = (int)((groupedPlots.Count - 0.5) / 2);

            groupedPlots[index].AxisOptions.YLabel = title;
        }
Пример #6
0
        private static IEnumerable <TEXPlot> getLegendPlots(GroupPlot groupPlot, string[] legendEntries)
        {
            var legendPlots = new Dictionary <string, TEXPlot>();

            foreach (var entry in legendEntries)
            {
                foreach (var pane in groupPlot.GroupedPlots)
                {
                    var plot = pane.Plots.FirstOrDefault(x => x.LegendEntry == entry && x.Options.ShowInLegend);
                    if (plot == null)
                    {
                        continue;
                    }
                    if (!legendPlots.Keys.Contains(entry))
                    {
                        legendPlots.Add(entry, createLegendPlotBasedOn(plot));
                    }
                }
            }
            return(legendPlots.Values);
        }