Esempio n. 1
0
		public void T001_MajorTicksSpacedOne()
		{
			var scale = new LinearScale();
			var s = (LinearTickSpacing)scale.TickSpacing;

			s.OrgGrace = 0;
			s.EndGrace = 0;
			s.ZeroLever = 0;

			for (int tmt = 4; tmt <= 16; ++tmt)
			{
				s.TargetNumberOfMajorTicks = tmt;
				s.TargetNumberOfMinorTicks = 1;

				s.FinalProcessScaleBoundaries(0, tmt - 1, scale);

				var majorTicks = s.GetMajorTicks();

				Assert.IsNotNull(majorTicks);
				Assert.AreEqual(tmt, majorTicks.Length);

				for (int i = 0; i <= tmt - 1; ++i)
					Assert.AreEqual(majorTicks[i], i);
			}
		}
Esempio n. 2
0
            public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                LinearScale s = null != o ? (LinearScale)o : new LinearScale();

                s._baseOrg = (double)info.GetDouble("BaseOrg");
                s._baseEnd = (double)info.GetDouble("BaseEnd");

                s._majorSpan  = (double)info.GetDouble("MajorSpan");
                s._minorTicks = (int)info.GetInt32("MinorTicks");

                s._axisOrgByMajor = (double)info.GetDouble("OrgByMajor");
                s._axisEndByMajor = (double)info.GetDouble("EndByMajor");

                bool AxisOrgFixed = (bool)info.GetBoolean("OrgFixed");
                bool AxisEndFixed = (bool)info.GetBoolean("EndFixed");

                s._dataBounds = (FiniteNumericalBoundaries)info.GetValue("Bounds", s);

                s.SetCachedValues();
                // restore the event chain
                s._dataBounds.BoundaryChanged += new BoundaryChangedHandler(s.OnBoundariesChanged);

                s._rescaling = new NumericAxisRescaleConditions();
                s._rescaling.SetOrgAndEnd(AxisOrgFixed ? BoundaryRescaling.Fixed : BoundaryRescaling.Auto, s.Org, AxisEndFixed ? BoundaryRescaling.Fixed:BoundaryRescaling.Auto, s.End);

                return(s);
            }
Esempio n. 3
0
 public LinkedScale()
 {
     Scale     = new LinearScale();
     _isLinked = false;
     _linkOrgA = 0;
     _linkOrgB = 1;
     _linkEndA = 0;
     _linkEndB = 1;
 }
Esempio n. 4
0
        public ScaleCollection(int numberOfScales)
        {
            if (numberOfScales <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(numberOfScales) + " must be >= 1");
            }

            _scales = new Scale[numberOfScales];
            for (int i = 0; i < numberOfScales; ++i)
            {
                this[i] = new LinearScale();
            }
        }
Esempio n. 5
0
            public void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info)
            {
                LinearScale s = (LinearScale)obj;

                info.AddValue("BaseOrg", s._baseOrg);
                info.AddValue("BaseEnd", s._baseEnd);
                info.AddValue("MajorSpan", s._majorSpan);
                info.AddValue("MinorTicks", s._minorTicks);
                info.AddValue("OrgByMajor", s._axisOrgByMajor);
                info.AddValue("EndByMajor", s._axisEndByMajor);

                // info.AddValue("OrgFixed",s.m_AxisOrgFixed);
                // info.AddValue("EndFixed",s.m_AxisEndFixed);

                info.AddValue("Bounds", s._dataBounds);
            }
Esempio n. 6
0
            public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                LinearScale s = (LinearScale)o ?? new LinearScale(info);

                s._cachedAxisOrg       = info.GetDouble("Org");
                s._cachedAxisEnd       = info.GetDouble("End");
                s._cachedAxisSpan      = s._cachedAxisEnd - s._cachedAxisOrg;
                s._cachedOneByAxisSpan = 1 / s._cachedAxisSpan;

                s.ChildSetMember(ref s._rescaling, (NumericScaleRescaleConditions)info.GetValue("Rescaling", s));

                s.ChildSetMember(ref s._dataBounds, (FiniteNumericalBoundaries)info.GetValue("Bounds", s));

                s.ChildSetMember(ref s._tickSpacing, new Ticks.LinearTickSpacing());

                s.EhChildChanged(s._dataBounds, EventArgs.Empty); // for this old version, rescaling is not fully serialized, thus we have to simulate a DataBoundChanged event to get _rescaling updated, and finally _tickSpacing updated

                return(s);
            }
Esempio n. 7
0
            public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                LinearScale s = (LinearScale)o ?? new LinearScale(info);

                s._cachedAxisOrg       = info.GetDouble("Org");
                s._cachedAxisEnd       = info.GetDouble("End");
                s._cachedAxisSpan      = s._cachedAxisEnd - s._cachedAxisOrg;
                s._cachedOneByAxisSpan = 1 / s._cachedAxisSpan;

                s.ChildSetMember(ref s._dataBounds, (FiniteNumericalBoundaries)info.GetValue("Bounds", s));

                s.ChildSetMember(ref s._rescaling, (NumericScaleRescaleConditions)info.GetValue("Rescaling", s));

                s.ChildSetMember(ref s._tickSpacing, (Ticks.TickSpacing)info.GetValue("TickSpacing", s));

                s.UpdateTicksAndOrgEndUsingRescalingObject();

                return(s);
            }
Esempio n. 8
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();
        }
Esempio n. 9
0
		private void SetupOldAxis(int idx, Altaxo.Graph.Scales.Deprecated.Scale axis, bool isLinked, double orgA, double orgB, double endA, double endB)
		{
			Scale transScale = null;
			if (axis is Altaxo.Graph.Scales.Deprecated.TextScale)
				transScale = new TextScale();
			else if (axis is Altaxo.Graph.Scales.Deprecated.DateTimeScale)
				transScale = new DateTimeScale();
			else if (axis is Altaxo.Graph.Scales.Deprecated.Log10Scale)
				transScale = new Log10Scale();
			else if (axis is Altaxo.Graph.Scales.Deprecated.AngularScale)
				transScale = (axis as Altaxo.Graph.Scales.Deprecated.AngularScale).UseDegrees ? (Scale)new AngularDegreeScale() : (Scale)new AngularRadianScale();
			else if (axis is Altaxo.Graph.Scales.Deprecated.LinearScale)
				transScale = new LinearScale();
			else
				throw new ArgumentException("Axis type unknown");

			if (transScale.RescalingObject is IUnboundNumericScaleRescaleConditions)
				(transScale.RescalingObject as IUnboundNumericScaleRescaleConditions).SetUserParameters(BoundaryRescaling.AutoTempFixed, BoundariesRelativeTo.Absolute, axis.OrgAsVariant, BoundaryRescaling.AutoTempFixed, BoundariesRelativeTo.Absolute, axis.EndAsVariant);

			if (transScale.RescalingObject is Altaxo.Graph.Scales.Rescaling.NumericScaleRescaleConditions &&
				axis.RescalingObject is Altaxo.Graph.Scales.Rescaling.NumericScaleRescaleConditions)
			{
				((Altaxo.Graph.Scales.Rescaling.NumericScaleRescaleConditions)transScale.RescalingObject).CopyFrom((Altaxo.Graph.Scales.Rescaling.NumericScaleRescaleConditions)axis.RescalingObject);
			}

			if (isLinked)
			{
#pragma warning disable CS0618 // Type or member is obsolete
				LinkedScale ls = new LinkedScale(transScale, idx);
#pragma warning restore CS0618 // Type or member is obsolete
				ls.SetLinkParameter(orgA, orgB, endA, endB);
				transScale = ls;
			}

			_scales[idx] = transScale;
		}
Esempio n. 10
0
		public void T002_TestZeroLever()
		{
			var scale = new LinearScale();
			var s = (LinearTickSpacing)scale.TickSpacing;

			s.OrgGrace = 0;
			s.EndGrace = 0;
			s.ZeroLever = 0;

			Altaxo.Data.AltaxoVariant org, end;

			s.ZeroLever = 0.25;

			for (int i = 0; i < 50; ++i)
			{
				org = i;
				end = i + 100; // Span now is 100

				s.PreProcessScaleBoundaries(ref org, ref end, true, true);
				Assert.AreEqual(i <= 25 ? 0 : i, org.ToDouble());

				Assert.AreEqual(i + 100, end.ToDouble());
			}
		}
Esempio n. 11
0
		/// <summary>
		/// Copy constructor.
		/// </summary>
		/// <param name="from">A other linear axis from which to copy from.</param>
		public LinearScale(LinearScale from)
		{
			CopyFrom(from);
		}
Esempio n. 12
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="from">A other linear axis from which to copy from.</param>
 public LinearScale(LinearScale from)
 {
     CopyFrom(from);
 }
Esempio n. 13
0
 public LinkedScale()
 {
   Scale = new LinearScale();
   _isLinked = false;
   _linkOrgA = 0;
   _linkOrgB = 1;
   _linkEndA = 0;
   _linkEndB = 1;
 }
Esempio n. 14
0
			public DensityLegendArea(PointD2D size, bool isXYInterchanged, bool isXReversed, Scale scale, TickSpacing tickSpacing)
			{
				_size = size;
				_scales = new ScaleCollection() { ParentObject = this };
				_scales[0] = scale; scale.TickSpacing = tickSpacing;
				_scales[1] = new LinearScale() { TickSpacing = new NoTickSpacing() };
				_coordinateSystem = new Altaxo.Graph.Gdi.CS.G2DCartesicCoordinateSystem() { ParentObject = this };
				_coordinateSystem.IsXYInterchanged = isXYInterchanged;
				_coordinateSystem.IsXReverse = isXReversed;
				_coordinateSystem.UpdateAreaSize(_size);
			}
Esempio n. 15
0
		public override void Paint(System.Drawing.Graphics g, IPaintContext paintContext)
		{
			if (null == _cachedArea)
				return;

			bool orientationIsVertical = IsOrientationVertical;
			bool scaleIsReversed = IsScaleReversed;

			int pixelH = orientationIsVertical ? _bitmapPixelsAcross : _bitmapPixelsAlong;
			int pixelV = orientationIsVertical ? _bitmapPixelsAlong : _bitmapPixelsAcross;

			if (null == _bitmap || _bitmap.Width != pixelH || _bitmap.Height != pixelV)
			{
				if (null != _bitmap)
					_bitmap.Dispose();

				_bitmap = new Bitmap(pixelH, pixelV, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
			}

			Data.AltaxoVariant porg;
			Data.AltaxoVariant pend;
			NumericalScale originalZScale;
			Plot.IColorProvider colorProvider;

			if (null != PlotItem)
			{
				porg = PlotItem.Style.Scale.OrgAsVariant;
				pend = PlotItem.Style.Scale.EndAsVariant;
				originalZScale = PlotItem.Style.Scale;
				colorProvider = PlotItem.Style.ColorProvider;
			}
			else
			{
				porg = 0;
				pend = 1;
				originalZScale = new LinearScale();
				colorProvider = new Plot.ColorProvider.ColorProviderBGRY();
			}

			var legendScale = (NumericalScale)ScaleWithTicks;
			var legendTickSpacing = ScaleWithTicks.TickSpacing;

			// Fill the bitmap

			for (int i = 0; i < _bitmapPixelsAlong; i++)
			{
				double r = (scaleIsReversed ^ orientationIsVertical) ? 1 - i / (double)(_bitmapPixelsAlong - 1) : i / (double)(_bitmapPixelsAlong - 1);
				double l = originalZScale.PhysicalToNormal(legendScale.NormalToPhysical(r));
				var color = colorProvider.GetColor(l);
				if (orientationIsVertical)
				{
					for (int j = 0; j < _bitmapPixelsAcross; j++)
						_bitmap.SetPixel(j, i, color);
				}
				else
				{
					for (int j = 0; j < _bitmapPixelsAcross; j++)
						_bitmap.SetPixel(i, j, color);
				}
			}

			var graphicsState = g.Save();
			TransformGraphics(g);

			{
				// Three tricks are neccessary to get the color legend (which is the bitmap) drawn smooth and uniformly:
				// Everything other than this will result in distorted image, or soft (unsharp) edges
				var graphicsState2 = g.Save(); // Of course, save the graphics state so we can make our tricks undone afterwards
				g.InterpolationMode = InterpolationMode.Default; // Trick1: Set the interpolation mode, whatever it was before, back to default
				g.PixelOffsetMode = PixelOffsetMode.Default;  // Trick2: Set the PixelOffsetMode, whatever it was before, back to default

				g.DrawImage(_bitmap,
					new RectangleF(0, 0, (float)Size.X, (float)Size.Y),
					new Rectangle(0, 0, pixelH - 1, pixelV - 1), GraphicsUnit.Pixel); // Trick3: Paint both in X and Y direction one pixel less than the source bitmap acually has, this prevents soft edges

				g.Restore(graphicsState2); // make our tricks undone here
			}
			_axisStyles.Paint(g, paintContext, _cachedArea);

			g.Restore(graphicsState);
		}
Esempio n. 16
0
    public virtual void CopyFrom(LinearScale from)
    {
      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;
      if(null!=_dataBounds)
        _dataBounds.BoundaryChanged -= new BoundaryChangedHandler(this.OnBoundariesChanged);
      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();
    }