Example #1
0
        /// <summary>
        /// Adds the label alignment to the specified axis. Not supported in <b>EPPlus</b> library.
        /// </summary>
        /// <param name="axis"><b>Xml</b> node than represent an axis definition.</param>
        /// <param name="model">A <see cref="KnownHorizontalAlignment"/> value from model.</param>
        /// <param name="documentHelper">Target xml document helper.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="axis"/> is <b>null</b>.</exception>
        /// <exception cref="InvalidEnumArgumentException">The value specified is outside the range of valid values.</exception>
        /// <exception cref="InvalidOperationException">If <paramref name="axis"/> is not an axis.</exception>
        public static void AddAxisLabelAlignment(this XmlNode axis, KnownHorizontalAlignment model, IXmlHelper documentHelper)
        {
            SentinelHelper.ArgumentNull(axis, nameof(axis));
            SentinelHelper.IsEnumValid(model);
            SentinelHelper.IsFalse(axis.Name.Contains("catAx") || axis.Name.Contains("valAx") || axis.Name.Contains("dateAx"), "Imposible extraer tipo. el nodo no es de tipo eje");

            var axisType = axis.ExtractAxisType(documentHelper);

            switch (axisType)
            {
            case KnownAxisType.PrimaryCategoryAxis:
            case KnownAxisType.SecondaryCategoryAxis:

                var valAttr = documentHelper.CreateAttribute("val");
                valAttr.Value = model.ToEppLabelAlignmentString();

                var lblAlignXmlNode = documentHelper.CreateOrDefaultAndAppendElementToNode(axis, "c:lblAlgn");
                lblAlignXmlNode.Attributes.Append(valAttr);
                break;

            case KnownAxisType.PrimaryValueAxis:
            case KnownAxisType.SecondaryValueAxis:
                break;
            }
        }
Example #2
0
        /// <summary>
        /// Returns the type of axis than represents specified node. Not supported in <c>EPPlus</c> library.
        /// </summary>
        /// <param name="axis"><c>Xml</c> node than represent an axis definition.</param>
        /// <param name="documentHelper">Target xml document helper.</param>
        /// <returns>
        /// A <see cref="KnownAxisType" /> value.
        /// </returns>
        /// <exception cref="T:System.ArgumentNullException">If <paramref name="axis" /> is <c>null</c>.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="axis" /> is not an axis.</exception>
        public static KnownAxisType ExtractAxisType(this XmlNode axis, IXmlHelper documentHelper)
        {
            SentinelHelper.ArgumentNull(axis, nameof(axis));
            SentinelHelper.IsFalse(axis.Name.Contains("catAx") || axis.Name.Contains("valAx") || axis.Name.Contains("dateAx"), "Imposible extraer tipo. el nodo no es de tipo eje");

            var idElement = documentHelper.GetXmlNode(axis, "c:axId");
            var valueAttr = idElement.Attributes["val"];

            var value = valueAttr.Value;

            switch (value)
            {
            case "2":
                return(KnownAxisType.PrimaryValueAxis);

            case "3":
                return(KnownAxisType.SecondaryCategoryAxis);

            case "4":
                return(KnownAxisType.SecondaryValueAxis);

            default:
                return(KnownAxisType.PrimaryCategoryAxis);
            }
        }
Example #3
0
        /// <summary>
        /// Try to get the item in the specified node if exist is returned in the parameter <paramref name="node"/>, otherwise will contain <c>null</c>, if the operation is performed returns <c>true</c>.
        /// </summary>
        /// <param name="root">The root node of new element.</param>
        /// <param name="name">The element name.</param>
        /// <param name="node">The output node.</param>
        /// <returns>
        /// <c>true</c> if exist; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="T:System.ArgumentNullException">If <paramref name="root" /> is <c>null</c>.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="name" /> is empty.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="name" /> length is less than 3.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="name" /> contains white spaces.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="name" /> has not correct format.</exception>
        public static bool TryGetElementFrom(XmlNode root, string name, out XmlNode node)
        {
            SentinelHelper.ArgumentNull(root);
            SentinelHelper.IsTrue(name.Length <= 3, "El parametro element debe contener al menos tres caracteres");
            SentinelHelper.IsTrue(string.IsNullOrEmpty(name), "El parametro element no puede estar en blanco");
            SentinelHelper.IsFalse(name.Contains(":"), "El formato no es correcto. Se esperaba prefijo:localname");
            SentinelHelper.IsTrue(name.Contains(" "), "El formato no es correcto. No se permiten espacios en el elemento");

            var exist = HasElement(root, name);

            if (exist)
            {
                node = GetXmlNode(root, name);
            }
            else
            {
                var piece     = name.Split(':');
                var prefix    = piece[0];
                var localName = piece[1];

                node = CreateElement(prefix, localName);
            }

            return(exist);
        }
Example #4
0
        /// <summary>
        /// Adds label properties (orientation, alignment, color and font) to the specified axis. Not supported in <b>EPPlus</b> library.
        /// </summary>
        /// <param name="axis"><b>Xml</b> node than represent an axis definition.</param>
        /// <param name="model">Axis from model.</param>
        /// <param name="documentHelper">Target xml document helper.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="axis" /> is <b>null</b>.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="model" /> is <b>null</b>.</exception>
        /// <exception cref="InvalidOperationException">If <paramref name="axis" /> is not an axis.</exception>
        public static void AddAxisLabelProperties(this XmlNode axis, XlsxChartAxisDefinitionLabels model, IXmlHelper documentHelper)
        {
            SentinelHelper.ArgumentNull(axis, nameof(axis));
            SentinelHelper.ArgumentNull(model, nameof(model));
            SentinelHelper.IsFalse(axis.Name.Contains("catAx") || axis.Name.Contains("valAx") || axis.Name.Contains("dateAx"), "Imposible extraer tipo. el nodo no es de tipo eje");

            axis.AddTextPropertiesNode(model, documentHelper);
        }
Example #5
0
        /// <summary>
        /// Adds label properties (orientation, alignment, color and font) to the specified axis. Not supported in <c>EPPlus</c> library.
        /// </summary>
        /// <param name="axis"><c>Xml</c> node than represent an axis definition.</param>
        /// <param name="model">Axis from model.</param>
        /// <exception cref="T:System.ArgumentNullException">If <paramref name="axis" /> is <c>null</c>.</exception>
        /// <exception cref="T:System.ArgumentNullException">If <paramref name="model" /> is <c>null</c>.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="axis" /> is not an axis.</exception>
        public static void AddAxisLabelProperties(this XmlNode axis, AxisDefinitionLabelsModel model)
        {
            SentinelHelper.ArgumentNull(axis);
            SentinelHelper.ArgumentNull(model);
            SentinelHelper.IsFalse(axis.Name.Contains("catAx") || axis.Name.Contains("valAx") || axis.Name.Contains("dateAx"), "Imposible extraer tipo. el nodo no es de tipo eje");

            axis.AddTextPropertiesNode(model);
        }
Example #6
0
        /// <summary>
        /// Create or return an element with the specified name, and adds it to the document in the specified node.
        /// </summary>
        /// <param name="root">The root node of new element.</param>
        /// <param name="name">The name of the new element.</param>
        /// <returns>
        /// Return if it already exists, else it is created and added to the specified node.
        /// </returns>
        /// <exception cref="T:System.ArgumentNullException">If <paramref name="root" /> is <c>null</c>.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="name" /> is empty.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="name" /> length is less than 3.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="name" /> contains white spaces.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="name" /> has not correct format.</exception>
        public static XmlNode CreateOrDefaultAndAppendElementToNode(XmlNode root, string name)
        {
            SentinelHelper.ArgumentNull(root);
            SentinelHelper.IsTrue(name.Length <= 3, "El parametro element debe contener al menos tres caracteres");
            SentinelHelper.IsTrue(string.IsNullOrEmpty(name), "El parametro element no puede estar en blanco");
            SentinelHelper.IsFalse(name.Contains(":"), "El formato no es correcto. Se esperaba prefijo:localname");
            SentinelHelper.IsTrue(name.Contains(" "), "El formato no es correcto. No se permiten espacios en el elemento");

            var piece     = name.Split(':');
            var prefix    = piece[0];
            var localName = piece[1];

            return(CreateOrDefaultAndAppendElementToNode(root, prefix, localName, NamespaceManager.LookupNamespace(prefix)));
        }
Example #7
0
        /// <summary>
        /// Modifies crosses for the specified axis. Supported in <c>EPPlus</c> library but fails.
        /// </summary>
        /// <param name="axis"><c>Xml</c> node than represent an axis definition.</param>
        /// <param name="documentHelper">Target xml document helper.</param>
        /// <exception cref="T:System.ArgumentNullException">If <paramref name="axis" /> is <c>null</c>.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="axis" /> is not an axis.</exception>
        public static void ModifyAxisCrosses(this XmlNode axis, IXmlHelper documentHelper)
        {
            SentinelHelper.ArgumentNull(axis, nameof(axis));
            SentinelHelper.IsFalse(axis.Name.Contains("catAx") || axis.Name.Contains("valAx") || axis.Name.Contains("dateAx"), "Imposible extraer tipo. el nodo no es de tipo eje");

            var axisType = axis.ExtractAxisType(documentHelper);

            if (axisType != KnownAxisType.SecondaryCategoryAxis)
            {
                return;
            }

            var valAttr = documentHelper.CreateAttribute("val");

            valAttr.Value = "max";

            var crossesXmlNode = documentHelper.CreateOrDefaultAndAppendElementToNode(axis, "c:crosses");

            crossesXmlNode.Attributes.Append(valAttr);
        }
Example #8
0
        /// <summary>
        /// Adds major, minor or both grid lines to the specified axis. Not supported in <c>EPPlus</c> library.
        /// </summary>
        /// <param name="axis"><c>Xml</c> node than represent an axis definition.</param>
        /// <param name="model">A <see cref="GridLine"/> value from model.</param>
        /// <param name="documentHelper">Target xml document helper.</param>
        /// <exception cref="T:System.ArgumentNullException">If <paramref name="axis" /> is <c>null</c>.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="axis" /> is not an axis.</exception>
        /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">The value specified is outside the range of valid values.</exception>
        public static void AddAxisGridLinesMode(this XmlNode axis, GridLine model, IXmlHelper documentHelper)
        {
            SentinelHelper.ArgumentNull(axis, nameof(axis));
            SentinelHelper.IsEnumValid(model);
            SentinelHelper.IsFalse(axis.Name.Contains("catAx") || axis.Name.Contains("valAx") || axis.Name.Contains("dateAx"), "Imposible extraer tipo. el nodo no es de tipo eje");

            var existMajorGridLinesNode = documentHelper.TryGetElementFrom(axis, "c:majorGridlines", out var majorGridLinesElement);

            if (existMajorGridLinesNode)
            {
                var parent = majorGridLinesElement.ParentNode;
                parent.RemoveChild(majorGridLinesElement);
            }

            var existMinorGridLinesNode = documentHelper.TryGetElementFrom(axis, "c:minorGridlines", out var minorGridLinesElement);

            if (existMinorGridLinesNode)
            {
                var parent = minorGridLinesElement.ParentNode;
                parent.RemoveChild(minorGridLinesElement);
            }

            switch (model)
            {
            case GridLine.None:
                break;

            case GridLine.Major:
                axis.AppendChild(majorGridLinesElement);
                break;

            case GridLine.Minor:
                axis.AppendChild(minorGridLinesElement);
                break;

            case GridLine.Both:
                axis.AppendChild(majorGridLinesElement);
                axis.AppendChild(minorGridLinesElement);
                break;
            }
        }