Exemple #1
0
        public void MergeYBoundsInto(IPlotArea layer, IPhysicalBoundaries pb, PlotItemCollection coll)
        {
            var pbclone = (IPhysicalBoundaries)pb.Clone(); // before we can use CanUseStyle, we have to give physical y boundaries template

            CoordinateTransformingStyleBase.MergeYBoundsInto(pbclone, coll);
            if (!CanUseStyle(layer, coll, out var plotDataList))
            {
                pb.Add(pbclone);
                return;
            }

            // we put zero into the y-Boundaries, since the addition starts with that value
            pb.Add(new AltaxoVariant(0.0));

            AltaxoVariant[] ySumArray = null;

            int idx = -1;

            foreach (IGPlotItem pi in coll)
            {
                if (pi is G2DPlotItem)
                {
                    idx++;

                    var gpi = (G2DPlotItem)pi;
                    Processed2DPlotData pdata = plotDataList[gpi];

                    if (null != pdata)
                    {
                        // Note: we can not use AddUp function here, since
                        // when we have positive/negative items, the intermediate bounds
                        // might be wider than the bounds of the end result

                        if (ySumArray == null)
                        {
                            ySumArray = new AltaxoVariant[pdata.RangeList.PlotPointCount];

                            int j = -1;
                            foreach (int originalIndex in pdata.RangeList.OriginalRowIndices())
                            {
                                j++;
                                ySumArray[j] = pdata.GetYPhysical(originalIndex);
                                pb.Add(ySumArray[j]);
                            }
                        }
                        else // this is not the first item
                        {
                            int j = -1;
                            foreach (int originalIndex in pdata.RangeList.OriginalRowIndices())
                            {
                                j++;
                                ySumArray[j] += pdata.GetYPhysical(originalIndex);
                                pb.Add(ySumArray[j]);
                            }
                        }
                    }
                }
            }
        }
        public void MergeXBoundsInto(IPlotArea layer, IPhysicalBoundaries pb, PlotItemCollection coll)
        {
            if (!(pb is NumericalBoundaries))
            {
                CoordinateTransformingStyleBase.MergeXBoundsInto(pb, coll);
                return;
            }

            NumericalBoundaries xbounds = (NumericalBoundaries)pb.Clone();

            xbounds.Reset();

            int nItems = 0;

            foreach (IGPlotItem pi in coll)
            {
                if (pi is IXBoundsHolder)
                {
                    IXBoundsHolder xbpi = (IXBoundsHolder)pi;
                    xbpi.MergeXBoundsInto(xbounds);
                }
                if (pi is G2DPlotItem)
                {
                    nItems++;
                }
            }


            if (nItems == 0)
            {
                _xinc = 0;
            }
            else
            {
                _xinc = (xbounds.UpperBound - xbounds.LowerBound) / nItems;
            }

            int idx = 0;

            foreach (IGPlotItem pi in coll)
            {
                if (pi is IXBoundsHolder)
                {
                    IXBoundsHolder xbpi = (IXBoundsHolder)pi;
                    xbounds.Reset();
                    xbpi.MergeXBoundsInto(xbounds);
                    xbounds.Shift(_xinc * idx);
                    pb.Add(xbounds);
                }
                if (pi is G2DPlotItem)
                {
                    idx++;
                }
            }
        }
        public void MergeYBoundsInto(IPlotArea layer, IPhysicalBoundaries pb, PlotItemCollection coll)
        {
            var pbclone = (IPhysicalBoundaries)pb.Clone(); // before we can use CanUseStyle, we have to give physical y boundaries template

            CoordinateTransformingStyleBase.MergeYBoundsInto(pbclone, coll);
            if (!CanUseStyle(layer, coll, out var plotDataList))
            {
                pb.Add(pbclone);
                return;
            }

            pb.Add(0);
            pb.Add(100);
        }
 public void MergeXBoundsInto(IPlotArea layer, IPhysicalBoundaries pb, PlotItemCollection coll)
 {
     CoordinateTransformingStyleBase.MergeXBoundsInto(pb, coll);
 }
        public void Paint(System.Drawing.Graphics g, IPlotArea layer, PlotItemCollection coll)
        {
            Dictionary <G2DPlotItem, Processed2DPlotData> plotDataDict;

            if (!CanUseStyle(layer, coll, out plotDataDict))
            {
                CoordinateTransformingStyleBase.Paint(g, layer, coll);
                return;
            }

            AltaxoVariant[] ysumArray = null;
            foreach (IGPlotItem pi in coll)
            {
                if (pi is G2DPlotItem)
                {
                    G2DPlotItem         gpi   = pi as G2DPlotItem;
                    Processed2DPlotData pdata = plotDataDict[gpi];
                    ysumArray = AbsoluteStackTransform.AddUp(ysumArray, pdata);
                }
            }



            // now plot the data - the summed up y is in yArray
            AltaxoVariant[]     yArray           = null;
            Processed2DPlotData previousItemData = null;

            foreach (IGPlotItem pi in coll)
            {
                if (pi is G2DPlotItem)
                {
                    G2DPlotItem         gpi   = pi as G2DPlotItem;
                    Processed2DPlotData pdata = plotDataDict[gpi];
                    yArray = AbsoluteStackTransform.AddUp(yArray, pdata);
                    AltaxoVariant[] localArray = new AltaxoVariant[yArray.Length];

                    int j = -1;
                    foreach (int originalIndex in pdata.RangeList.OriginalRowIndices())
                    {
                        j++;
                        AltaxoVariant y = 100 * yArray[j] / ysumArray[j];
                        localArray[j] = y;

                        Logical3D rel = new Logical3D(
                            layer.XAxis.PhysicalVariantToNormal(pdata.GetXPhysical(originalIndex)),
                            layer.YAxis.PhysicalVariantToNormal(y));

                        double xabs, yabs;
                        layer.CoordinateSystem.LogicalToLayerCoordinates(rel, out xabs, out yabs);
                        pdata.PlotPointsInAbsoluteLayerCoordinates[j] = new System.Drawing.PointF((float)xabs, (float)yabs);
                    }
                    // we have also to exchange the accessor for the physical y value and replace it by our own one
                    pdata.YPhysicalAccessor = new IndexedPhysicalValueAccessor(delegate(int i) { return(localArray[i]); });
                    pdata.PreviousItemData  = previousItemData;
                    previousItemData        = pdata;
                }
            }

            for (int i = coll.Count - 1; i >= 0; --i)
            {
                IGPlotItem pi = coll[i];
                if (pi is G2DPlotItem)
                {
                    G2DPlotItem         gpi   = pi as G2DPlotItem;
                    Processed2DPlotData pdata = plotDataDict[gpi];
                    gpi.Paint(g, layer, pdata);
                }
                else
                {
                    pi.Paint(g, layer);
                }
            }
        }
Exemple #6
0
        public void Paint(System.Drawing.Graphics g, IPlotArea layer, PlotItemCollection coll)
        {
            Dictionary <G2DPlotItem, Processed2DPlotData> plotDataDict;

            if (!CanUseStyle(layer, coll, out plotDataDict))
            {
                CoordinateTransformingStyleBase.Paint(g, layer, coll);
                return;
            }

            AltaxoVariant[] yArray = null;
            // First, add up all items since we start always with the last item
            int idx = -1;
            Processed2DPlotData previousItemData = null;

            foreach (IGPlotItem pi in coll)
            {
                if (pi is G2DPlotItem)
                {
                    idx++;

                    G2DPlotItem         gpi   = pi as G2DPlotItem;
                    Processed2DPlotData pdata = plotDataDict[gpi];
                    yArray = AddUp(yArray, pdata);

                    if (idx > 0) // this is not the first item
                    {
                        int j = -1;
                        foreach (int originalIndex in pdata.RangeList.OriginalRowIndices())
                        {
                            j++;
                            Logical3D rel = new Logical3D(
                                layer.XAxis.PhysicalVariantToNormal(pdata.GetXPhysical(originalIndex)),
                                layer.YAxis.PhysicalVariantToNormal(yArray[j]));

                            double xabs, yabs;
                            layer.CoordinateSystem.LogicalToLayerCoordinates(rel, out xabs, out yabs);
                            pdata.PlotPointsInAbsoluteLayerCoordinates[j] = new System.Drawing.PointF((float)xabs, (float)yabs);
                        }
                    }

                    // we have also to exchange the accessor for the physical y value and replace it by our own one
                    AltaxoVariant[] localArray = (AltaxoVariant[])yArray.Clone();
                    pdata.YPhysicalAccessor = new IndexedPhysicalValueAccessor(delegate(int i) { return(localArray[i]); });
                    pdata.PreviousItemData  = previousItemData;
                    previousItemData        = pdata;
                }
            }

            for (int i = coll.Count - 1; i >= 0; --i)
            {
                IGPlotItem pi = coll[i];
                if (pi is G2DPlotItem)
                {
                    G2DPlotItem         gpi   = pi as G2DPlotItem;
                    Processed2DPlotData pdata = plotDataDict[gpi];
                    gpi.Paint(g, layer, pdata);
                }
                else
                {
                    pi.Paint(g, layer);
                }
            }
        }