示例#1
0
 /// <summary>
 /// Creates a default linear axis with org=0 and end=1.
 /// </summary>
 public LinearScale()
 {
     _dataBounds = new FiniteNumericalBoundaries
     {
         ParentObject = this
     };
 }
示例#2
0
        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++;
                }
            }
        }
示例#3
0
 /// <summary>
 /// Creates a default logarithmic axis with org=1 and end=10.
 /// </summary>
 public Log10Scale()
 {
     _rescaling = new LogarithmicScaleRescaleConditions()
     {
         ParentObject = this
     };
     _dataBounds = new PositiveFiniteNumericalBoundaries()
     {
         ParentObject = this
     };
 }
示例#4
0
        /// <summary>
        /// Copy constructor.
        /// </summary>
        /// <param name="from">The axis to copy from.</param>
        public Log10Scale(Log10Scale from)
        {
            this.IsLinked = from.IsLinked;

            this._dataBounds             = null == from._dataBounds ? new PositiveFiniteNumericalBoundaries() : (NumericalBoundaries)from._dataBounds.Clone();
            _dataBounds.BoundaryChanged += new BoundaryChangedHandler(this.OnBoundariesChanged);
            this._decadesPerMajorTick    = from._decadesPerMajorTick;
            this._log10End = from._log10End;
            this._log10Org = from._log10Org;

            this._rescaling = null == from.Rescaling ? new LogarithmicAxisRescaleConditions() : (LogarithmicAxisRescaleConditions)from.Rescaling.Clone();
        }
示例#5
0
        /// <summary>
        /// This routine ensures that the plot item updates all its cached data and send the appropriate
        /// events if something has changed. Called before the layer paint routine paints the axes because
        /// it must be ensured that the axes are scaled correctly before the plots are painted.
        /// </summary>
        /// <param name="layer">The plot layer.</param>
        /// <param name="plotData">The plot data which are here used to determine the bounds of the independent data column.</param>
        public void PrepareScales(IPlotArea layer, XYZMeshedColumnPlotData plotData)
        {
            NumericalBoundaries pb = _scale.DataBounds;

            plotData.SetVBoundsFromTemplate(pb); // ensure that the right v-boundary type is set
            using (var suspendToken = pb.SuspendGetToken())
            {
                pb.Reset();
                plotData.MergeVBoundsInto(pb);
                suspendToken.Resume();
            }
        }
示例#6
0
 /// <summary>
 /// This routine ensures that the plot item updates all its cached data and send the appropriate
 /// events if something has changed. Called before the layer paint routine paints the axes because
 /// it must be ensured that the axes are scaled correctly before the plots are painted.
 /// </summary>
 /// <param name="layer">The plot layer.</param>
 /// <param name="plotData">The plot data.</param>
 public void PrepareScales(IPlotArea layer, XYZMeshedColumnPlotData plotData)
 {
     if (_colorScale != null)
     {
         // in case we use our own scale for coloring, we need to calculate the data bounds
         NumericalBoundaries pb = _colorScale.DataBounds;
         plotData.SetVBoundsFromTemplate(pb); // ensure that the right v-boundary type is set
         using (var suspendToken = pb.SuspendGetToken())
         {
             pb.Reset();
             plotData.MergeVBoundsInto(pb);
             suspendToken.Resume();
         }
     }
 }
        public void SetVBoundsFromTemplate(IPhysicalBoundaries val)
        {
            if (null == m_vBoundaries || val.GetType() != m_vBoundaries.GetType())
            {
                if (null != m_vBoundaries)
                {
                    m_vBoundaries.BoundaryChanged -= new BoundaryChangedHandler(this.OnVBoundariesChangedEventHandler);
                }
                m_vBoundaries = (NumericalBoundaries)val.Clone();
                m_vBoundaries.BoundaryChanged += new BoundaryChangedHandler(this.OnVBoundariesChangedEventHandler);
                this.m_bCachedDataValid        = false;

                OnChanged();
            }
        }
示例#8
0
 protected override IEnumerable <Main.DocumentNodeAndName> GetDocumentNodeChildrenWithName()
 {
     if (null != _dataBounds)
     {
         yield return(new Main.DocumentNodeAndName(_dataBounds, () => _dataBounds = null, "DataBounds"));
     }
     if (null != _rescaling)
     {
         yield return(new Main.DocumentNodeAndName(_rescaling, () => _rescaling = null, "Rescaling"));
     }
     if (null != _tickSpacing)
     {
         yield return(new Main.DocumentNodeAndName(_tickSpacing, () => _tickSpacing = null, "TickSpacing"));
     }
 }
示例#9
0
 /// <summary>
 /// Creates a default logarithmic axis with org=1 and end=10.
 /// </summary>
 public Log10Scale()
 {
     _dataBounds = new PositiveFiniteNumericalBoundaries()
     {
         ParentObject = this
     };
     _rescaling = new LogarithmicScaleRescaleConditions()
     {
         ParentObject = this
     };
     _tickSpacing = new Ticks.Log10TickSpacing()
     {
         ParentObject = this
     };
     UpdateTicksAndOrgEndUsingRescalingObject();
 }
示例#10
0
 /// <summary>
 /// Creates a default cumulative probability scale.
 /// </summary>
 public CumulativeProbabilityScale()
 {
     _dataBounds = new CumulativeProbabilityBoundaries()
     {
         ParentObject = this
     };
     _rescaling = new CumulativeProbabilityScaleRescaleConditions()
     {
         ParentObject = this
     };
     _tickSpacing = new Ticks.CumulativeProbabilityTickSpacing()
     {
         ParentObject = this
     };
     UpdateTicksAndOrgEndUsingRescalingObject();
 }
示例#11
0
 /// <summary>
 /// Creates a default linear axis with org=0 and end=1.
 /// </summary>
 public LinearScale()
 {
     _dataBounds = new FiniteNumericalBoundaries()
     {
         ParentObject = this
     };
     _rescaling = new LinearScaleRescaleConditions()
     {
         ParentObject = this
     };
     _tickSpacing = new Ticks.LinearTickSpacing()
     {
         ParentObject = this
     };
     UpdateTicksAndOrgEndUsingRescalingObject();
 }
示例#12
0
 /// <summary>
 /// Creates a default linear axis with org=0 and end=1.
 /// </summary>
 public InverseScale()
 {
     _dataBounds = new InverseNumericalBoundaries()
     {
         ParentObject = this
     };
     _rescaling = new InverseScaleRescaleConditions()
     {
         ParentObject = this
     };
     _tickSpacing = new Ticks.InverseTickSpacing()
     {
         ParentObject = this
     };
     UpdateTicksAndOrgEndUsingRescalingObject();
 }
示例#13
0
        /// <summary>
        /// Copy constructor.
        /// </summary>
        /// <param name="from">A other linear axis from which to copy from.</param>
        public LinearScale(LinearScale from)
        {
            this.IsLinked = from.IsLinked;

            this._cachedAxisEnd          = from._cachedAxisEnd;
            this._axisEndByMajor         = from._axisEndByMajor;
            this._cachedAxisOrg          = from._cachedAxisOrg;
            this._axisOrgByMajor         = from._axisOrgByMajor;
            this._cachedAxisSpan         = from._cachedAxisSpan;
            this._baseEnd                = from._baseEnd;
            this._baseOrg                = from._baseOrg;
            this._dataBounds             = null == from._dataBounds ? new FiniteNumericalBoundaries() : (NumericalBoundaries)from._dataBounds.Clone();
            _dataBounds.BoundaryChanged += new BoundaryChangedHandler(this.OnBoundariesChanged);
            this._majorSpan              = from._majorSpan;
            this._minorTicks             = from._minorTicks;
            this._cachedOneByAxisSpan    = from._cachedOneByAxisSpan;

            this._rescaling = null == from.Rescaling ? new NumericAxisRescaleConditions() : (NumericAxisRescaleConditions)from.Rescaling.Clone();
        }
示例#14
0
        /// <summary>
        /// Copy constructor.
        /// </summary>
        /// <param name="from">The axis to copy from.</param>
        public Log10Scale(Log10Scale from)
        {
            IsLinked = from.IsLinked;

            _dataBounds = null == from._dataBounds ? new PositiveFiniteNumericalBoundaries()
            {
                ParentObject = this
            } : (NumericalBoundaries)from._dataBounds.Clone();
            _dataBounds.ParentObject = this;

            _decadesPerMajorTick = from._decadesPerMajorTick;
            _log10End            = from._log10End;
            _log10Org            = from._log10Org;

            _rescaling = null == from.Rescaling ? new LogarithmicScaleRescaleConditions()
            {
                ParentObject = this
            } : (LogarithmicScaleRescaleConditions)from.Rescaling.Clone();
            _rescaling.ParentObject = this;
        }
示例#15
0
        /// <summary>
        /// Copy constructor.
        /// </summary>
        /// <param name="from">A other linear axis from which to copy from.</param>
        public LinearScale(LinearScale from)
        {
            IsLinked = from.IsLinked;

            _cachedAxisEnd           = from._cachedAxisEnd;
            _axisEndByMajor          = from._axisEndByMajor;
            _cachedAxisOrg           = from._cachedAxisOrg;
            _axisOrgByMajor          = from._axisOrgByMajor;
            _cachedAxisSpan          = from._cachedAxisSpan;
            _baseEnd                 = from._baseEnd;
            _baseOrg                 = from._baseOrg;
            _dataBounds              = null == from._dataBounds ? new FiniteNumericalBoundaries() : (NumericalBoundaries)from._dataBounds.Clone();
            _dataBounds.ParentObject = this;
            _majorSpan               = from._majorSpan;
            _minorTicks              = from._minorTicks;
            _cachedOneByAxisSpan     = from._cachedOneByAxisSpan;

            _rescaling = null == from.Rescaling ? new LinearScaleRescaleConditions() : (LinearScaleRescaleConditions)from.Rescaling.Clone();
            _rescaling.ParentObject = this;
        }
        /// <summary>
        /// Paint the density image in the layer.
        /// </summary>
        /// <param name="gfrx">The graphics context painting in.</param>
        /// <param name="gl">The layer painting in.</param>
        /// <param name="plotObject">The data to plot.</param>
        public void Paint(Graphics gfrx, IPlotArea gl, object plotObject) // plots the curve with the choosen style
        {
            if (!(plotObject is XYZMeshedColumnPlotData))
            {
                return; // we cannot plot any other than a TwoDimMeshDataAssociation now
            }
            XYZMeshedColumnPlotData myPlotAssociation = (XYZMeshedColumnPlotData)plotObject;

            Altaxo.Data.INumericColumn xColumn = myPlotAssociation.XColumn as Altaxo.Data.INumericColumn;
            Altaxo.Data.INumericColumn yColumn = myPlotAssociation.YColumn as Altaxo.Data.INumericColumn;

            if (null == xColumn || null == yColumn)
            {
                return; // this plotitem is only for x and y double columns
            }
            //double layerWidth = gl.Size.Width;
            //double layerHeight = gl.Size.Height;

            int cols = myPlotAssociation.ColumnCount;
            int rows = myPlotAssociation.RowCount;


            if (cols <= 0 || rows <= 0)
            {
                return; // we cannot show a picture if one length is zero
            }
            // there is a need for rebuilding the bitmap only if the data are invalid for some reason
            if (!m_bCachedDataValid)
            {
                System.Diagnostics.Trace.WriteLine("DensityImagePlotStyle.Paint, calculate image data...");

                // look if the image has the right dimensions
                if (null == m_Image || m_Image.Width != cols || m_Image.Height != rows)
                {
                    if (null != m_Image)
                    {
                        m_Image.Dispose();
                    }

                    // please notice: the horizontal direction of the image is related to the row index!!! (this will turn the image in relation to the table)
                    // and the vertical direction of the image is related to the column index
                    m_Image = new System.Drawing.Bitmap(rows, cols, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                }

                // now we can fill the image with our data

                NumericalBoundaries pb = m_ScalingStyle == ScalingStyle.Logarithmic ? (NumericalBoundaries) new PositiveFiniteNumericalBoundaries() :  (NumericalBoundaries) new FiniteNumericalBoundaries();
                myPlotAssociation.SetVBoundsFromTemplate(pb); // ensure that the right v-boundary type is set
                myPlotAssociation.MergeVBoundsInto(pb);

                double vmin       = double.IsNaN(this.m_RangeFrom) ? pb.LowerBound : Math.Max(pb.LowerBound, this.m_RangeFrom);
                double vmax       = double.IsNaN(this.m_RangeTo) ? pb.UpperBound : Math.Min(pb.UpperBound, this.m_RangeTo);
                double lowerBound = vmin;
                double upperBound = vmax;

                if (this.m_ScalingStyle == ScalingStyle.Logarithmic)
                {
                    // Ensure that min and max >0
                    vmin = lowerBound = Math.Max(lowerBound, double.Epsilon);
                    vmax = upperBound = Math.Max(lowerBound, upperBound); // lowerBound is ok, to ensure that upperBound>=lowerBound

                    vmin = Math.Log(vmin);
                    vmax = vmax > 0 ? Math.Log(vmax) : vmin;
                }

                // double vmid = (vmin+vmax)*0.5;
                double vscal = vmax <= vmin ? 1 : 255.0 / (vmax - vmin);

                int r, g, b;

                for (int i = 0; i < cols; i++)
                {
                    Altaxo.Data.INumericColumn col = myPlotAssociation.DataColumns[i] as Altaxo.Data.INumericColumn;
                    if (null == col)
                    {
                        continue;
                    }

                    for (int j = 0; j < rows; j++)
                    {
                        double val = col[j];
                        if (double.IsNaN(val))
                        {
                            m_Image.SetPixel(j, cols - i - 1, m_ColorInvalid); // invalid pixels are transparent
                        }
                        else if (val < lowerBound)
                        {
                            m_Image.SetPixel(j, cols - i - 1, m_ColorBelow); // below the lower bound
                        }
                        else if (val > upperBound)
                        {
                            m_Image.SetPixel(j, cols - i - 1, m_ColorAbove); // above the upper bound
                        }
                        else // a valid value
                        {
                            double relval;
                            // calculate a relative value between 0 and 255 from the borders and the scaling style
                            if (this.m_ScalingStyle == ScalingStyle.Logarithmic)
                            {
                                relval = (Math.Log(val) - vmin) * vscal;
                            }
                            else // ScalingStyle is linear
                            {
                                relval = (val - vmin) * vscal;
                            }


                            r = ((int)(Math.Abs(relval))) % 256;
                            g = ((int)(Math.Abs(relval + relval))) % 256;
                            b = ((int)(Math.Abs(255 - relval))) % 256;
                            m_Image.SetPixel(j, cols - i - 1, System.Drawing.Color.FromArgb(r, g, b));
                        }
                    } // for all pixel of a column
                }     // for all columns


                m_bCachedDataValid = true; // now the bitmap is valid
            }


            double x_rel_left  = gl.XAxis.PhysicalVariantToNormal(xColumn[0]);
            double x_rel_right = gl.XAxis.PhysicalVariantToNormal(xColumn[rows - 1]);

            double y_rel_bottom = gl.YAxis.PhysicalVariantToNormal(yColumn[0]);
            double y_rel_top    = gl.YAxis.PhysicalVariantToNormal(yColumn[cols - 1]);

            double xleft, xright, ytop, ybottom;

            if (gl.CoordinateSystem.LogicalToLayerCoordinates(new Logical3D(x_rel_left, y_rel_top), out xleft, out ytop) &&
                gl.CoordinateSystem.LogicalToLayerCoordinates(new Logical3D(x_rel_right, y_rel_bottom), out xright, out ybottom))
            {
                GraphicsState savedGraphicsState = gfrx.Save();

                if (this.m_ClipToLayer)
                {
                    gfrx.Clip = gl.CoordinateSystem.GetRegion();
                }

                gfrx.DrawImage(m_Image, (float)xleft, (float)ytop, (float)(xright - xleft), (float)(ybottom - ytop));

                gfrx.Restore(savedGraphicsState);
            }
        }
示例#17
0
 /// <summary>
 /// Creates a default linear axis with org=0 and end=1.
 /// </summary>
 public LinearScale()
 {
     _dataBounds = new FiniteNumericalBoundaries();
     _dataBounds.BoundaryChanged += new BoundaryChangedHandler(this.OnBoundariesChanged);
 }
示例#18
0
 /// <summary>
 /// Creates a default logarithmic axis with org=1 and end=10.
 /// </summary>
 public Log10Scale()
 {
     _dataBounds = new PositiveFiniteNumericalBoundaries();
     _dataBounds.BoundaryChanged += new BoundaryChangedHandler(this.OnBoundariesChanged);
 }