예제 #1
0
 private string addLegendEntry(Plot plot)
 {
     if (String.IsNullOrEmpty(plot.LegendEntry))
     {
         return(String.Empty);
     }
     return($"\\addlegendentry{{{_converter.StringToTeX(plot.LegendEntry)}}};\n");
 }
예제 #2
0
        /// <summary>
        ///    This method creates a header for tables.
        /// </summary>
        /// <param name="data">Data view containing data.</param>
        /// <param name="tableNotes">Notes of the table.</param>
        /// <param name="converter">Tex converter.</param>
        /// <param name="relation"></param>
        /// <returns>TEX chunk.</returns>
        private static string header(DataView data, Dictionary <string, char> tableNotes, ITeXConverter converter, DataRelation relation = null)
        {
            // create standard header
            var header = new StringBuilder();

            header.Append("\\rowfont[c]{\\bfseries}\n");
            var newHeader = true;

            foreach (DataColumn col in data.Table.Columns)
            {
                if (col.IsHidden())
                {
                    continue;
                }
                if (relation != null)
                {
                    if (relation.ChildColumns.Contains(col))
                    {
                        continue;
                    }
                }
                if (newHeader)
                {
                    header.AppendFormat("{{{0}}}", converter.StringToTeX(col.Caption));
                    newHeader = false;
                }
                else
                {
                    header.AppendFormat(" {0} {{{1}}}", VALUE_SEPARATOR, converter.StringToTeX(col.Caption));
                }

                header.Append(TNote(col, tableNotes));
                var unit = col.GetUnit();
                if (!String.IsNullOrEmpty(unit))
                {
                    header.AppendFormat(" [{0}]", converter.StringToTeX(unit));
                }
            }
            header.Append(Helper.LineBreak());
            return(header.ToString());
        }
예제 #3
0
        /// <summary>
        /// This creates all table notes.
        /// </summary>
        /// <param name="tableNotes"></param>
        /// <param name="converter"></param>
        /// <returns></returns>
        private static string tableNotes(Dictionary <string, char> tableNotes, ITeXConverter converter)
        {
            var tex = new StringBuilder();

            tex.Append(Helper.Begin(Helper.Environments.flushleft));
            tex.Append(notesRule());
            tex.Append(Helper.Begin(Helper.Environments.tablenotes));

            foreach (var note in tableNotes)
            {
                tex.Append(tableNote(note.Value, converter.StringToTeX(note.Key)));
            }

            tex.Append(Helper.End(Helper.Environments.tablenotes));
            tex.Append(Helper.End(Helper.Environments.flushleft));
            return(tex.ToString());
        }
예제 #4
0
        public override string ToString()
        {
            if (LegendEntries.Length == 0)
            {
                return(String.Empty);
            }
            var text = new StringBuilder();

            text.Append(", ");

            _legendName = Helper.Marker();
            text.AppendFormat("legend to name={0}", _legendName);

            addSeparator(text);
            text.AppendFormat("legend entries={{{0}}}", string.Join(", ", _converter.StringToTeX(LegendEntries)));

            addSeparator(text);
            text.Append(LegendOptions);

            return(text.ToString());
        }
예제 #5
0
        public override string ToString()
        {
            var          optionsString       = new StringBuilder();
            const string FORMAT_STRING       = "{0}={1}\n";
            const string FORMAT_STRING_LABEL = "{0}={{{1}}}\n";

            if (IsEmptyGroupPlot)
            {
                return("group/empty plot");
            }

            optionsString.Append("ylabel near ticks");
            optionsString.Append(Helper.LineFeed());

            if (IsUsedForBoxPlots)
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "boxplot/draw direction", BoxPlotDrawDirection.ToString());
            }

            foreach (var groupLineEntry in GroupLines)
            {
                addSeparator(optionsString);
                optionsString.Append(groupLineEntry);
            }

            addSeparator(optionsString);
            optionsString.AppendFormat(FORMAT_STRING, "axis x line" + (XAxisArrow ? String.Empty : "*"), XAxisPosition);

            addSeparator(optionsString);
            optionsString.AppendFormat(FORMAT_STRING, "axis y line" + (YAxisArrow ? String.Empty : "*"), YAxisPosition);

            if (XAxisIsHidden)
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "hide x axis", "true");
            }
            if (YAxisIsHidden)
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "hide y axis", "true");
            }

            if (!String.IsNullOrEmpty(BackgroundColor))
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "axis background/.style", "{" + String.Format(FORMAT_STRING, "fill", BackgroundColor) + "}");
            }

            if (EnlargeLimits)
            {
                addSeparator(optionsString);
                optionsString.Append("enlargelimits");
                optionsString.Append(Helper.LineFeed());
            }

            if (LegendOptions != null)
            {
                addSeparator(optionsString);
                optionsString.Append(LegendOptions);
                optionsString.Append(Helper.LineFeed());
            }

            addSeparator(optionsString);
            optionsString.AppendFormat(FORMAT_STRING, "xmode", XMode.ToString());
            addSeparator(optionsString);
            optionsString.AppendFormat(FORMAT_STRING, "ymode", YMode.ToString());

            if (!string.IsNullOrEmpty(XLabel))
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING_LABEL, "xlabel", _converter.StringToTeX(XLabel));
            }
            if (!string.IsNullOrEmpty(YLabel))
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING_LABEL, "ylabel", _converter.StringToTeX(YLabel));
            }
            if (!string.IsNullOrEmpty(Title))
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING_LABEL, "title", _converter.StringToTeX(Title));
            }

            //ranges
            if (XMax != null)
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "xmax", ((float)XMax).ToString(CultureInfo.InvariantCulture));
            }
            if (XMin != null)
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "xmin", ((float)XMin).ToString(CultureInfo.InvariantCulture));
            }
            if (YMin != null)
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "ymin", ((float)YMin).ToString(CultureInfo.InvariantCulture));
            }
            if (YMax != null)
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "ymax", ((float)YMax).ToString(CultureInfo.InvariantCulture));
            }

            if (XTicks != null && XTicks.Length > 0)
            {
                addSeparator(optionsString);
                var ticks = string.Join(",", Array.ConvertAll(XTicks, f => f.ToString(CultureInfo.InvariantCulture)));
                optionsString.AppendFormat(FORMAT_STRING_LABEL, "xtick", ticks);
            }
            if (XTickLabels != null && XTickLabels.Length > 0)
            {
                addSeparator(optionsString);
                var tickLabels = $"{{{string.Join("}, {", _converter.StringToTeX(XTickLabels))}}}";
                optionsString.AppendFormat(FORMAT_STRING_LABEL, "xticklabels", tickLabels);
            }
            if (!string.IsNullOrEmpty(XGroupLineOffset))
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "group line offset", XGroupLineOffset);
            }
            if (!string.IsNullOrEmpty(XGroupLineTextOffset))
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "text offset", XGroupLineTextOffset);
            }
            if (XTickLabelsRotateBy % 360 != 0)
            {
                addSeparator(optionsString);
                optionsString.AppendFormat("xticklabel style = {{rotate={0}, anchor=east, yshift={1}}}", XTickLabelsRotateBy % 360, Helper.Length(-6, Helper.MeasurementUnits.pt));
            }
            if (XMinorTicks != null && XMinorTicks.Length > 0)
            {
                addSeparator(optionsString);
                var ticks = string.Join(",", Array.ConvertAll(XMinorTicks, f => f.ToString(CultureInfo.InvariantCulture)));
                optionsString.AppendFormat(FORMAT_STRING_LABEL, "minor xtick", ticks);
            }
            if (YTicks != null && YTicks.Length > 0)
            {
                addSeparator(optionsString);
                var ticks = string.Join(",", Array.ConvertAll(YTicks, f => f.ToString(CultureInfo.InvariantCulture)));
                optionsString.AppendFormat(FORMAT_STRING_LABEL, "ytick", ticks);
            }
            if (YTickLabels != null && YTickLabels.Length > 0)
            {
                addSeparator(optionsString);
                var tickLabels = $"{{{string.Join("}, {", _converter.StringToTeX(YTickLabels))}}}";
                optionsString.AppendFormat(FORMAT_STRING_LABEL, "yticklabels", tickLabels);
            }
            if (YTickLabelsRotateBy % 360 != 0)
            {
                addSeparator(optionsString);
                optionsString.AppendFormat("yticklabel style = {{rotate={0}, anchor=east, xshift={1}}}", XTickLabelsRotateBy % 360, Helper.Length(-6, Helper.MeasurementUnits.pt));
            }
            if (YMinorTicks != null && YMinorTicks.Length > 0)
            {
                addSeparator(optionsString);
                var ticks = string.Join(",", Array.ConvertAll(YMinorTicks, f => f.ToString(CultureInfo.InvariantCulture)));
                optionsString.AppendFormat(FORMAT_STRING, "minor ytick", $"{{{ticks}}}");
            }
            //tick ranges
            if (XTickMax != null)
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "xtickmax", ((float)XTickMax).ToString(CultureInfo.InvariantCulture));
            }
            if (XTickMin != null)
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "xtickmin", ((float)XTickMin).ToString(CultureInfo.InvariantCulture));
            }
            if (YTickMin != null)
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "ytickmin", ((float)YTickMin).ToString(CultureInfo.InvariantCulture));
            }
            if (YTickMax != null)
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "ytickmax", ((float)YTickMax).ToString(CultureInfo.InvariantCulture));
            }

            // minor tick num
            if (MinorXTickNum != null)
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "minor x tick num", MinorXTickNum);
            }
            if (MinorYTickNum != null)
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "minor y tick num", MinorYTickNum);
            }

            if (XMode == AxisMode.log || YMode == AxisMode.log)
            {
                if (LogTicksWithFixedPoint)
                {
                    addSeparator(optionsString);
                    optionsString.Append("log ticks with fixed point");
                }
            }

            // scaled ticks
            addSeparator(optionsString);
            optionsString.AppendFormat(FORMAT_STRING, "scaled x ticks", XScaledTicks ? "true" : "false");

            addSeparator(optionsString);
            optionsString.AppendFormat(FORMAT_STRING, "scaled y ticks", YScaledTicks ? "true" : "false");

            //discontinuities
            addSeparator(optionsString);
            optionsString.AppendFormat(FORMAT_STRING, "axis x discontinuity", XDiscontinuity);
            addSeparator(optionsString);
            optionsString.AppendFormat(FORMAT_STRING, "axis y discontinuity", YDiscontinuity);

            //grid
            if (XMajorGrid)
            {
                addSeparator(optionsString);
                optionsString.Append("xmajorgrids");
            }
            if (YMajorGrid)
            {
                addSeparator(optionsString);
                optionsString.Append("ymajorgrids");
            }
            if (XMinorGrid)
            {
                addSeparator(optionsString);
                optionsString.Append("xminorgrids");
            }
            if (YMinorGrid)
            {
                addSeparator(optionsString);
                optionsString.Append("yminorgrids");
            }

            //dimensions
            if (!String.IsNullOrEmpty(Width))
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "width", Width);
            }
            if (!String.IsNullOrEmpty(Height))
            {
                addSeparator(optionsString);
                optionsString.AppendFormat(FORMAT_STRING, "height", Height);
            }

            return(optionsString.ToString());
        }
예제 #6
0
        private static string createRow(DataRowView row, Dictionary <string, char> tableNotes, ITeXConverter converter, ITeXBuilderRepository builderRepository, DataRelation relation = null, int?level = null)
        {
            var rowLine = new StringBuilder();

            rowLine.Append(setPagebreakDesirability(getPagebreakDesirability(row, level)));

            var columnsCount = 0;

            foreach (DataColumn col in row.DataView.Table.Columns)
            {
                if (col.IsHidden())
                {
                    continue;
                }
                if (relation != null)
                {
                    if (relation.ChildColumns.Contains(col))
                    {
                        continue;
                    }
                }
                columnsCount++;
                if (columnsCount > 1)
                {
                    rowLine.AppendFormat(" {0} ", VALUE_SEPARATOR);
                }
                var colValue = row[col.ColumnName];
                if (colValue == null || colValue == DBNull.Value)
                {
                    continue;
                }
                // datatype specifics
                string value;
                if (col.DataType == typeof(double) || col.DataType == typeof(float))
                {
                    value = converter.StringToTeX(_numericFormatter.Format(Convert.ToDouble(colValue)));
                }
                else if (col.DataType == typeof(DateTime))
                {
                    value = converter.StringToTeX(((DateTime)colValue).ToShortTimeString());
                }
                else if (col.DataType == typeof(Text))
                {
                    value = builderRepository.ChunkFor(colValue);
                }
                else
                {
                    value = converter.StringToTeX(colValue.ToString());
                }
                rowLine.Append(value);
            }
            rowLine.Append(Helper.LineBreak());
            rowLine.Append(phantomline());
            var first = true;

            foreach (DataRelation childrelation in row.DataView.Table.ChildRelations)
            {
                var childView = row.CreateChildView(childrelation);
                if (childView.Count == 0)
                {
                    continue;
                }
                if (first)
                {
                    rowLine.Append(CLine(1, columnsCount));
                    first = false;
                }

                rowLine.Append(multiFirstColumn(columnsCount, ColumnAlignments.c,
                                                createChildTable(childView, tableNotes, childrelation, converter, builderRepository, ref level)));
                rowLine.Append(Helper.LineBreak());
                rowLine.Append(phantomline());
            }
            if (row.DataView.Table.ChildRelations.Count > 0)
            {
                rowLine.Append(CLine(1, columnsCount));
            }

            return(rowLine.ToString());
        }
예제 #7
0
        /// <summary>
        ///    This method creates a nicer header for pivot tables.
        /// </summary>
        /// <param name="pivotData">Data view containing data to pivot.</param>
        /// <param name="tableNotes">Notes of table.</param>
        /// <param name="pivotInfo">Information specifying the pivotation.</param>
        /// <param name="texTranslations">Use defined tex string for naming aggregations within the tex header.</param>
        /// <param name="converter">Tex converter.</param>
        /// <returns>TEX chunk.</returns>
        private static string headerForPivot(DataView pivotData, Dictionary <string, char> tableNotes, PivotInfo pivotInfo, Cache <Aggregate, string> texTranslations, ITeXConverter converter)
        {
            var colFieldNames = pivotInfo.ColumnFields;
            var colValueList  = pivotData.ToTable(true, colFieldNames.ToArray()).AsEnumerable().ToList();

            var header     = new StringBuilder();
            var headerRow  = new StringBuilder();
            var multiplied = pivotInfo.ColumnFields.Count;

            header.Append(HLine());
            for (int i = 0; i < colFieldNames.Count; i++)
            {
                var fieldName  = colFieldNames[i];
                var columnName = $"{{{converter.StringToTeX(fieldName)}}}";
                if (pivotData.Table.Columns.Contains(fieldName))
                {
                    columnName += TNote(pivotData.Table.Columns[fieldName], tableNotes);
                    var unit = pivotData.Table.Columns[fieldName].GetUnit();
                    if (!String.IsNullOrEmpty(unit))
                    {
                        columnName = $"{columnName} [{converter.StringToTeX(unit)}]";
                    }
                }
                if (headerRow.Length > 0)
                {
                    headerRow.Append(multiColumn(pivotInfo.RowFields.Count, ColumnAlignments.r,
                                                 Helper.Bold(columnName)));
                }
                else
                {
                    headerRow.Append(multiFirstColumn(pivotInfo.RowFields.Count, ColumnAlignments.r,
                                                      Helper.Bold(columnName)));
                }
                for (int index = 0; index < colValueList.Count; index++)
                {
                    var colValue  = colValueList[index];
                    var value     = colValue[fieldName].ToString();
                    var multiples = 0;
                    while (multiples < multiplied && (index + multiples + 1) < colValueList.Count &&
                           value == colValueList[index + multiples + 1][fieldName].ToString())
                    {
                        multiples++;
                    }
                    multiplied = multiples;
                    index     += multiples;
                    headerRow.Append(VALUE_SEPARATOR);
                    headerRow.Append(multiColumn(pivotInfo.Aggregates.Count() * pivotInfo.DataFields.Count * (multiples + 1), ColumnAlignments.c,
                                                 converter.StringToTeX(colValue[fieldName].ToString())));
                }

                headerRow.Append(Helper.LineBreak());
                headerRow.Append(HLine());
                header.Append(headerRow);
                headerRow = new StringBuilder();
            }

            headerRow = new StringBuilder();
            foreach (var rowField in pivotInfo.RowFields)
            {
                if (headerRow.Length > 0)
                {
                    headerRow.Append(VALUE_SEPARATOR);
                }
                headerRow.Append(Helper.Bold(converter.StringToTeX(rowField)));
                if (pivotData.Table.Columns.Contains(rowField))
                {
                    headerRow.Append(Helper.Bold(TNote(pivotData.Table.Columns[rowField], tableNotes)));
                    var unit = pivotData.Table.Columns[rowField].GetUnit();
                    if (!String.IsNullOrEmpty(unit))
                    {
                        headerRow.AppendFormat(" [{0}]", converter.StringToTeX(unit));
                    }
                }
            }
            foreach (var colValue in colValueList)
            {
                foreach (var aggregate in pivotInfo.Aggregates)
                {
                    foreach (var datafield in pivotInfo.DataFields)
                    {
                        headerRow.Append(VALUE_SEPARATOR);
                        if (aggregate != null)
                        {
                            var funcName = texTranslations.Contains(aggregate) ? texTranslations[aggregate] : aggregate.Name;
                            headerRow.Append(Helper.Bold(funcName));
                            if (aggregate.DataType == typeof(bool) || aggregate.DataType == typeof(int))
                            {
                                continue;
                            }
                        }
                        if (pivotInfo.DataFields.Count > 1)
                        {
                            var datafieldName = converter.StringToTeX(datafield);
                            datafieldName += TNote(pivotData.Table.Columns[datafield], tableNotes);
                            headerRow.Append(Helper.Bold($"({datafieldName})"));
                        }
                        if (pivotData.Table.Columns.Contains(datafield))
                        {
                            var unit = pivotData.Table.Columns[datafield].GetUnit();
                            if (!String.IsNullOrEmpty(unit))
                            {
                                headerRow.Append(Helper.Bold($" [{converter.StringToTeX(unit)}]"));
                            }
                        }
                    }
                }
            }
            headerRow.Append(Helper.LineBreak());
            header.Append(headerRow);
            header.Append(HLine());

            return(header.ToString());
        }
예제 #8
0
 /// <summary>
 ///    This methods creates a footnote.
 /// </summary>
 /// <remarks>Footnotes unfortunately don't work with tables, as it is considered a bad practice.</remarks>
 /// <param name="footnote">Text for the footnote.</param>
 /// <param name="converter">Indicates whether texts should be converted or not.</param>
 /// <returns>TEX chunk.</returns>
 public static string Footnote(string footnote, ITeXConverter converter)
 {
     return($"\\footnote{{{converter.StringToTeX(footnote)}}}");
 }
예제 #9
0
 /// <summary>
 ///    This method creates a tex chunk for a structure element with a special toctitle.
 /// </summary>
 /// <param name="element">>Structur element.</param>
 /// <param name="name">Name of structure element.</param>
 /// <param name="converter">TEX converter</param>
 /// <param name="toctitle">Name of the structure element used in table of contents. Shorter version of name.</param>
 /// <returns>TEX chunk.</returns>
 internal static string CreateStructureElement(StructureElements element, string name, ITeXConverter converter, string toctitle)
 {
     return($"\\{element}[{converter.StringToTeX(toctitle)}]{{{converter.StringToTeX(name)}}}\n");
 }
예제 #10
0
 /// <summary>
 ///    This method creates a tex chunk for a structure element without a special toctitle.
 /// </summary>
 /// <param name="element">Structur element.</param>
 /// <param name="name">Name of structure element.</param>
 /// <param name="converter">TEX converter</param>
 /// <param name="addToToc">Indicates whether the structure should be nummered and added to table of contents.</param>
 /// <returns>TEX chunk.</returns>
 internal static string CreateStructureElement(StructureElements element, string name, ITeXConverter converter, bool addToToc)
 {
     return($"\\{element}{(addToToc ? String.Empty : NO_TOC_SYMBOL)}{{{converter.StringToTeX(name)}}}\n");
 }