Example #1
0
        /// <summary>
        /// Apply plot group styles forward, from the first to the last item.
        /// The function is called recursively for child PlotItemCollections, but only up in the hierarchy.
        /// This function therefore has no influence on items down in hierarchie, i.e. parental PlotItemCollections.
        /// </summary>
        /// <param name="parentGroupStyles">The parent plot group style collection.</param>
        /// <remarks>The application is used for example:
        /// <para>BarGraph: to calculate the exact position of each plot item.</para>
        /// <para>Color: To step forward through the available colors and apply each color to another PlotItem.</para>
        /// </remarks>

        protected void ApplyGroupStylesForward_HierarchyUpOnly(PlotGroupStyleCollection parentGroupStyles)
        {
            bool transferFromParentStyles =
                parentGroupStyles != null &&
                parentGroupStyles.Count != 0 &&
                parentGroupStyles.DistributeToChildGroups &&
                _plotGroupStyles.InheritFromParentGroups;

            // if TransferFromParentStyles was choosen, transfer some of the plot group settings of the parental plot group styles to the local styles
            if (transferFromParentStyles)
            {
                PlotGroupStyleCollection.TransferFromTo(parentGroupStyles, _plotGroupStyles);
            }

            // Announce the local plot group styles the begin of the application stage
            _plotGroupStyles.BeginApply();

            // for each PlotItem in this collection, announce the application, using the local plot group style collection
            // after each item, announce an application step (of stepwidth 1) to the plot group styles, so that the properties (like color etc.) can be stepped forward
            int last = _plotItems.Count - 1;

            for (int i = 0; i <= last; i++)
            {
                IGPlotItem pi = _plotItems[i];
                if (pi is PlotItemCollection)
                {
                    var pic = (PlotItemCollection)pi;
                    pic.ApplyGroupStylesForward_HierarchyUpOnly(_plotGroupStyles);
                    _plotGroupStyles.StepIfForeignSteppingFalse(1, ((PlotItemCollection)pi)._plotGroupStyles);
                }
                else
                {
                    pi.ApplyGroupStyles(_plotGroupStyles);
                    _plotGroupStyles.Step(1);
                }
            }
            // after application of PlotGroupStyles to all the plot items is done, announce the end of application,
            _plotGroupStyles.EndApply();

            if (transferFromParentStyles)
            {
                PlotGroupStyleCollection.TransferFromToIfBothSteppingEnabled(_plotGroupStyles, parentGroupStyles);
                parentGroupStyles.SetAllToApplied(); // to indicate that we have applied this styles and so to enable stepping
            }
        }
        /// <summary>
        /// Apply styles forward, but only up in the hierarchy.
        /// </summary>
        /// <param name="parentstyles">The parent group style collection.</param>
        protected void ApplyStylesForward_HierarchyUpOnly(PlotGroupStyleCollection parentstyles)
        {
            bool transferFromParentStyles =
                parentstyles != null &&
                parentstyles.Count != 0 &&
                parentstyles.DistributeToChildGroups &&
                this._styles.InheritFromParentGroups;

            if (transferFromParentStyles)
            {
                PlotGroupStyleCollection.TransferFromTo(parentstyles, _styles);
            }

            _styles.BeginApply();

            // now distibute the styles from the first item down to the last item
            int last = _plotItems.Count - 1;

            for (int i = 0; i <= last; i++)
            {
                IGPlotItem pi = _plotItems[i];
                if (pi is PlotItemCollection)
                {
                    PlotItemCollection pic = (PlotItemCollection)pi;
                    pic.ApplyStylesForward_HierarchyUpOnly(_styles);
                    _styles.StepIfForeignSteppingFalse(1, ((PlotItemCollection)pi)._styles);
                }
                else
                {
                    pi.ApplyStyles(_styles);
                    _styles.Step(1);
                }
            }
            _styles.EndApply();

            if (transferFromParentStyles)
            {
                PlotGroupStyleCollection.TransferFromToIfBothSteppingEnabled(_styles, parentstyles);
                parentstyles.SetAllToApplied(); // to indicate that we have applied this styles and so to enable stepping
            }
        }
        /// <summary>
        /// Apply styles backward from the last item to the first, but only upwards in the hierarchy.
        /// </summary>
        /// <param name="styles"></param>
        protected void ApplyStylesBackward_HierarchyUpOnly(PlotGroupStyleCollection styles)
        {
            bool transferToLocalStyles =
                styles != null &&
                styles.Count != 0 &&
                styles.DistributeToChildGroups &&
                this._styles.InheritFromParentGroups;

            if (!transferToLocalStyles)
            {
                return;
            }

            PlotGroupStyleCollection.TransferFromTo(styles, _styles);

            _styles.BeginApply();
            // now distibute the styles from the first item down to the last item
            int last = _plotItems.Count - 1;

            for (int i = last; i >= 0; i--)
            {
                IGPlotItem pi = _plotItems[i];
                if (pi is PlotItemCollection)
                {
                    _styles.Step(-1);
                    ((PlotItemCollection)pi).ApplyStylesBackward_HierarchyUpOnly(_styles);
                }
                else
                {
                    pi.ApplyStyles(_styles);
                    _styles.Step(-1);
                }
            }
            _styles.EndApply();

            PlotGroupStyleCollection.TransferFromToIfBothSteppingEnabled(_styles, styles);
        }