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
            }
        }