public CSAxisInformation( CSLineID Identifier, string NameOfAxisStyle, string NameOfFirstDownSide, string NameOfFirstUpSide, string NameOfSecondDownSide, string NameOfSecondUpSide, CSAxisSide PreferredLabelSide, CSAxisSide PreferredTickSide, bool IsShownByDefault, bool HasTicksByDefault, bool HasLabelsByDefault, bool HasTitleByDefault ) { _identifier = Identifier; _nameOfAxisStyle = NameOfAxisStyle; _nameOfFirstDownSide = NameOfFirstDownSide; _nameOfFirstUpSide = NameOfFirstUpSide; _nameOfSecondDownSide = NameOfSecondDownSide; _nameOfSecondUpSide = NameOfSecondUpSide; _preferedLabelSide = PreferredLabelSide; _preferedTickSide = PreferredTickSide; _isShownByDefault = IsShownByDefault; _hasTicksByDefault = HasTicksByDefault; _hasLabelsByDefault = HasLabelsByDefault; _hasTitleByDefault = HasTitleByDefault; }
private void ShowAxisLine(bool hasTicksByDefault, CSAxisSide preferredTickSide, IReadOnlyPropertyBag context) { if (_axisLineStyle == null) { AxisLineStyle = new AxisLineStyle(hasTicksByDefault, preferredTickSide, context); } }
public void SetDefaultValues() { switch (_identifier.ParallelAxisNumber) { case 0: _nameOfAxisStyle = "X-Axis"; break; case 1: _nameOfAxisStyle = "Y-Axis"; break; case 2: _nameOfAxisStyle = "Z-Axis"; break; default: _nameOfAxisStyle = "Axis" + _identifier.ParallelAxisNumber.ToString(); break; } _nameOfAxisStyle += string.Format(" (at L={0})", _identifier.LogicalValueOtherFirst.ToString()); _nameOfFirstDownSide = "FirstDown"; _nameOfFirstUpSide = "FirstUp"; _nameOfSecondDownSide = null; _nameOfSecondUpSide = null; _preferedLabelSide = CSAxisSide.FirstDown; }
/// <summary> /// Creates a default axis style. /// </summary> public AxisLineStyle(bool showTicks, CSAxisSide preferredTickSide, Main.Properties.IReadOnlyPropertyBag context) { double penWidth = GraphDocument.GetDefaultPenWidth(context); double majorTickLength = GraphDocument.GetDefaultMajorTickLength(context); var color = GraphDocument.GetDefaultForeColor(context); _axisPen = new PenX3D(color, penWidth); _majorTickPen = new PenX3D(color, penWidth); _minorTickPen = new PenX3D(color, penWidth); _majorTickLength = majorTickLength; _minorTickLength = majorTickLength / 2; if (showTicks) { _showFirstUpMajorTicks = preferredTickSide == CSAxisSide.FirstUp; _showFirstDownMajorTicks = preferredTickSide == CSAxisSide.FirstDown; _showSecondUpMajorTicks = preferredTickSide == CSAxisSide.SecondUp; _showSecondDownMajorTicks = preferredTickSide == CSAxisSide.SecondDown; _showFirstUpMinorTicks = preferredTickSide == CSAxisSide.FirstUp; _showFirstDownMinorTicks = preferredTickSide == CSAxisSide.FirstDown; _showSecondUpMinorTicks = preferredTickSide == CSAxisSide.SecondUp; _showSecondDownMinorTicks = preferredTickSide == CSAxisSide.SecondDown; } }
/// <summary> /// Returns the used space from the middle line of the axis /// to the last outer object (either the outer major thicks or half /// of the axis thickness) /// </summary> /// <param name="side">The side of the axis at which the outer distance is returned.</param> public double GetOuterDistance(CSAxisSide side) { double retVal = 0; if (CSAxisSide.FirstUp == side) { retVal = _axisPen.Thickness1 / 2; // half of the axis thickness retVal = System.Math.Max(retVal, _showFirstUpMajorTicks ? _majorTickLength : 0); retVal = System.Math.Max(retVal, _showFirstUpMinorTicks ? _minorTickLength : 0); } else if (CSAxisSide.FirstDown == side) { retVal = _axisPen.Thickness1 / 2; // half of the axis thickness retVal = System.Math.Max(retVal, _showFirstDownMajorTicks ? _majorTickLength : 0); retVal = System.Math.Max(retVal, _showFirstDownMinorTicks ? _minorTickLength : 0); } else if (CSAxisSide.SecondUp == side) { retVal = _axisPen.Thickness2 / 2; // half of the axis thickness retVal = System.Math.Max(retVal, _showSecondUpMajorTicks ? _majorTickLength : 0); retVal = System.Math.Max(retVal, _showSecondUpMinorTicks ? _minorTickLength : 0); } else if (CSAxisSide.SecondDown == side) { retVal = _axisPen.Thickness2 / 2; // half of the axis thickness retVal = System.Math.Max(retVal, _showSecondDownMajorTicks ? _majorTickLength : 0); retVal = System.Math.Max(retVal, _showSecondDownMinorTicks ? _minorTickLength : 0); } else { retVal = 0; } return(retVal); }
/// <summary>Gets the name of the axis side.</summary> /// <param name="id">The axis identifier.</param> /// <param name="side">The axis side.</param> /// <returns>The name of the axis side for the axis line given by the identifier.</returns> public override string GetAxisSideName(CSLineID id, CSAxisSide side) { bool isX = id.ParallelAxisNumber == 0; isX ^= _isXYInterchanged; bool isUp = side == CSAxisSide.FirstUp; isUp ^= isX ? _isXreverse : _isYreverse; bool isOuterLine = (id.LogicalValueOtherFirst == 0 || id.LogicalValueOtherFirst == 1); if (isOuterLine) { isUp ^= (0 == id.LogicalValueOtherFirst); } if (isOuterLine) { return(_axisNamesOuterLines[isX ? 0 : 1, isUp ? 0 : 1]); } else { return(_axisNamesNormal[isX ? 0 : 1, isUp ? 0 : 1]); } }
/// <summary> /// This is a private constructor that sets not only the identifier, but also default values. The second argument is ignored, but is essential /// to distinguish this contructor from the constructor that sets no default values. /// </summary> /// <param name="identifier">The identifier.</param> /// <param name="idIgnored">Ignored argument</param> private CSAxisInformation(CSLineID identifier, CSLineID idIgnored) { _identifier = identifier; switch (_identifier.ParallelAxisNumber) { case 0: _nameOfAxisStyle = "X-Axis"; break; case 1: _nameOfAxisStyle = "Y-Axis"; break; case 2: _nameOfAxisStyle = "Z-Axis"; break; default: _nameOfAxisStyle = "Axis" + _identifier.ParallelAxisNumber.ToString(); break; } // Axis name if (_identifier.Is3DIdentifier) { _nameOfAxisStyle += string.Format(" (at {0}={1}; {2}={3})", _identifier.UsePhysicalValueOtherFirst ? "P1" : "L1", _identifier.UsePhysicalValueOtherFirst ? _identifier.PhysicalValueOtherFirst.ToString() : _identifier.LogicalValueOtherFirst.ToString(), _identifier.UsePhysicalValueOtherSecond ? "P2" : "L2", _identifier.UsePhysicalValueOtherSecond ? _identifier.PhysicalValueOtherSecond.ToString() : _identifier.LogicalValueOtherSecond.ToString()); } else { if (_identifier.UsePhysicalValueOtherFirst) { _nameOfAxisStyle = string.Format("{0}={1}", _identifier.ParallelAxisNumber == 0 ? "Y" : "X", _identifier.PhysicalValueOtherFirst); } else { _nameOfAxisStyle += string.Format(" (at L={0})", _identifier.LogicalValueOtherFirst.ToString()); } } // Axis sides _nameOfFirstDownSide = "FirstDown"; _nameOfFirstUpSide = "FirstUp"; if (_identifier.Is3DIdentifier) { _nameOfSecondDownSide = "SecondDown"; _nameOfSecondUpSide = "SecondUp"; } else { _nameOfSecondDownSide = null; _nameOfSecondUpSide = null; } // preferred label side _preferedLabelSide = CSAxisSide.FirstDown; }
public override string GetAxisSideName(CSLineID id, CSAxisSide side) { var v = GetUntransformedAxisSideVector(id, side); var tv = VectorTransformation.Transform(v); var name = GetAxisSideNameFromVector(tv); return(name); }
public void ShowMinorLabels(CSAxisSide preferredLabelSide, Altaxo.Main.Properties.IReadOnlyPropertyBag context) { if (_minorLabelStyle == null) { MinorLabelStyle = new AxisLabelStyle(preferredLabelSide, context) { CachedAxisInformation = _cachedAxisInfo } } ; }
public void CopyWithoutIdentifierFrom(CSAxisInformation from) { this._nameOfAxisStyle = from._nameOfAxisStyle; this._nameOfFirstDownSide = from._nameOfFirstDownSide; this._nameOfFirstUpSide = from._nameOfFirstUpSide; this._nameOfSecondDownSide = from._nameOfSecondDownSide; this._nameOfSecondUpSide = from._nameOfSecondUpSide; this._preferedLabelSide = from._preferedLabelSide; this._isShownByDefault = from._isShownByDefault; this._hasTitleByDefault = from._hasTitleByDefault; }
public CSAxisInformation( CSLineID Identifier, string NameOfAxisStyle, string NameOfFirstDownSide, string NameOfFirstUpSide, CSAxisSide PreferredLabelSide ) { _identifier = Identifier; _nameOfAxisStyle = NameOfAxisStyle; _nameOfFirstDownSide = NameOfFirstDownSide; _nameOfFirstUpSide = NameOfFirstUpSide; _preferedLabelSide = PreferredLabelSide; }
/// <summary>Gets the name of the axis side.</summary> /// <param name="id">The axis identifier.</param> /// <param name="side">The axis side.</param> /// <returns>The name of the axis side for the axis line given by the identifier.</returns> public override string GetAxisSideName(CSLineID id, CSAxisSide side) { bool isHorizontal = id.ParallelAxisNumber == 0 ^ _isXYInterchanged; bool isOuterLine = (id.LogicalValueOtherFirst == 0 || id.LogicalValueOtherFirst == 1); if (isOuterLine) { bool isPointingOutwards = (id.LogicalValueOtherFirst == 0 && side == CSAxisSide.FirstDown) || (id.LogicalValueOtherFirst == 1 && side == CSAxisSide.FirstUp); return(_axisSideNamesOuterLines[isHorizontal ? 0 : 1, isPointingOutwards ? 0 : 1]); } else { bool isRight = ((id.ParallelAxisNumber == 0 && _isYreverse) || (id.ParallelAxisNumber == 1 && _isXreverse)) ^ (side == CSAxisSide.FirstUp); return(_axisSideNamesNormal[isHorizontal ? 0 : 1, isRight ? 0 : 1]); } }
/// <summary> /// Gets the logical direction to the sides of an axis. /// </summary> /// <param name="parallelAxisNumber">Number of the axis (0: X, 1: Y, 2: Z).</param> /// <param name="side">Designates the sides of the axis.</param> /// <returns>The logical direction to the given side. The returned vector is normalized.</returns> public Logical3D GetLogicalDirection(int parallelAxisNumber, CSAxisSide side) { switch (side) { default: case CSAxisSide.FirstDown: return(0 == parallelAxisNumber ? new Logical3D(0, -1, 0) : new Logical3D(-1, 0, 0)); case CSAxisSide.FirstUp: return(0 == parallelAxisNumber ? new Logical3D(0, 1, 0) : new Logical3D(1, 0, 0)); case CSAxisSide.SecondDown: return(2 == parallelAxisNumber ? new Logical3D(0, -1, 0) : new Logical3D(0, 0, -1)); case CSAxisSide.SecondUp: return(2 == parallelAxisNumber ? new Logical3D(0, 1, 0) : new Logical3D(0, 0, 1)); } }
public CSAxisInformation( CSLineID Identifier, string NameOfAxisStyle, string NameOfFirstDownSide, string NameOfFirstUpSide, CSAxisSide PreferredLabelSide, bool IsShownByDefault, bool HasTitleByDefault ) { _identifier = Identifier; _nameOfAxisStyle = NameOfAxisStyle; _nameOfFirstDownSide = NameOfFirstDownSide; _nameOfFirstUpSide = NameOfFirstUpSide; _preferedLabelSide = PreferredLabelSide; _isShownByDefault = IsShownByDefault; _hasTitleByDefault = HasTitleByDefault; }
/// <summary> /// Returns the used space from the middle line of the axis /// to the last outer object (either the outer major thicks or half /// of the axis thickness) /// </summary> /// <param name="side">The side of the axis at which the outer distance is returned.</param> public float GetOuterDistance(CSAxisSide side) { float retVal = _axisPen.Width / 2; // half of the axis thickness if (CSAxisSide.FirstUp == side) { retVal = System.Math.Max(retVal, _showFirstUpMajorTicks ? _majorTickLength : 0); retVal = System.Math.Max(retVal, _showFirstUpMinorTicks ? _minorTickLength : 0); } else if (CSAxisSide.FirstDown == side) { retVal = System.Math.Max(retVal, _showFirstDownMajorTicks ? _majorTickLength : 0); retVal = System.Math.Max(retVal, _showFirstDownMinorTicks ? _minorTickLength : 0); } else { retVal = 0; } return(retVal); }
/// <summary> /// Returns the used space from the middle line of the axis /// to the last outer object (either the outer major thicks or half /// of the axis thickness) /// </summary> /// <param name="side">The side of the axis at which the outer distance is returned.</param> public float GetOuterDistance(CSAxisSide side) { float retVal = _axisPen.Width/2; // half of the axis thickness if (CSAxisSide.FirstUp == side) { retVal = System.Math.Max(retVal, _showFirstUpMajorTicks ? _majorTickLength : 0); retVal = System.Math.Max(retVal, _showFirstUpMinorTicks ? _minorTickLength : 0); } else if (CSAxisSide.FirstDown == side) { retVal = System.Math.Max(retVal, _showFirstDownMajorTicks ? _majorTickLength : 0); retVal = System.Math.Max(retVal, _showFirstDownMinorTicks ? _minorTickLength : 0); } else { retVal = 0; } return retVal; }
/// <summary>Gets the name of the axis side.</summary> /// <param name="id">The axis identifier.</param> /// <param name="side">The axis side.</param> /// <returns>The name of the axis side for the axis line given by the identifier.</returns> public override string GetAxisSideName(CSLineID id, CSAxisSide side) { bool isX = id.ParallelAxisNumber == 0; isX ^= _isXYInterchanged; bool isUp = side == CSAxisSide.FirstUp; isUp ^= isX ? _isXreverse : _isYreverse; bool isOuterLine = (id.LogicalValueOtherFirst == 0 || id.LogicalValueOtherFirst == 1); if (isOuterLine) isUp ^= (0 == id.LogicalValueOtherFirst); if (isOuterLine) return _axisNamesOuterLines[isX ? 0 : 1, isUp ? 0 : 1]; else return _axisNamesNormal[isX ? 0 : 1, isUp ? 0 : 1]; }
/// <summary>Gets the name of the axis side.</summary> /// <param name="id">The axis identifier.</param> /// <param name="side">The axis side.</param> /// <returns>The name of the axis side for the axis line given by the identifier.</returns> public override string GetAxisSideName(CSLineID id, CSAxisSide side) { return _axisNamesNormal[id.ParallelAxisNumber, (int)side]; }
/// <summary> /// This is a private constructor that sets not only the identifier, but also default values. The second argument is ignored, but is essential /// to distinguish this contructor from the constructor that sets no default values. /// </summary> /// <param name="identifier">The identifier.</param> /// <param name="idIgnored">Ignored argument</param> private CSAxisInformation(CSLineID identifier, CSLineID idIgnored) { _identifier = identifier; switch (_identifier.ParallelAxisNumber) { case 0: _nameOfAxisStyle = "X-Axis"; break; case 1: _nameOfAxisStyle = "Y-Axis"; break; case 2: _nameOfAxisStyle = "Z-Axis"; break; default: _nameOfAxisStyle = "Axis" + _identifier.ParallelAxisNumber.ToString(); break; } // Axis name if (_identifier.Is3DIdentifier) { _nameOfAxisStyle += string.Format(" (at {0}={1}; {2}={3})", _identifier.UsePhysicalValueOtherFirst ? "P1" : "L1", _identifier.UsePhysicalValueOtherFirst ? _identifier.PhysicalValueOtherFirst.ToString() : _identifier.LogicalValueOtherFirst.ToString(), _identifier.UsePhysicalValueOtherSecond ? "P2" : "L2", _identifier.UsePhysicalValueOtherSecond ? _identifier.PhysicalValueOtherSecond.ToString() : _identifier.LogicalValueOtherSecond.ToString()); } else { if (_identifier.UsePhysicalValueOtherFirst) _nameOfAxisStyle = string.Format("{0}={1}", _identifier.ParallelAxisNumber == 0 ? "Y" : "X", _identifier.PhysicalValueOtherFirst); else _nameOfAxisStyle += string.Format(" (at L={0})", _identifier.LogicalValueOtherFirst.ToString()); } // Axis sides _nameOfFirstDownSide = "FirstDown"; _nameOfFirstUpSide = "FirstUp"; if (_identifier.Is3DIdentifier) { _nameOfSecondDownSide = "SecondDown"; _nameOfSecondUpSide = "SecondUp"; } else { _nameOfSecondDownSide = null; _nameOfSecondUpSide = null; } // preferred label side _preferedLabelSide = CSAxisSide.FirstDown; }
/// <summary> /// Gets the transformed axis side vector, i.e. the vector that points out of the plane of the axis side. /// </summary> /// <param name="id">The axis identifier.</param> /// <param name="side">The side identifier.</param> /// <returns>The vector corresponding to the axis side.</returns> /// <exception cref="System.NotImplementedException"> /// </exception> private VectorD3D GetTransformedAxisSideVector(CSLineID id, CSAxisSide side) { return(VectorTransformation.Transform(GetUntransformedAxisSideVector(id, side))); }
/// <summary>Gets the name of the axis side.</summary> /// <param name="id">The axis identifier.</param> /// <param name="side">The axis side.</param> /// <returns>The name of the axis side for the axis line given by the identifier.</returns> public abstract string GetAxisSideName(CSLineID id, CSAxisSide side);
/// <summary> /// Try to change the showing variables (e.g. <see cref="_showFirstDownMajorTicks"/>) when changing coordinate system, so that /// it is tried to keep the positions of the shown major and minor ticks. /// </summary> /// <param name="GetNewAxisSideFromOldAxisSide">The get new axis side from old axis side.</param> public void ChangeTickPositionsWhenChangingCoordinateSystem(Func <CSAxisSide, CSAxisSide?> GetNewAxisSideFromOldAxisSide) { // store old _show variables into temporary storage var oldShown = new bool[] { _showFirstUpMajorTicks, _showFirstDownMajorTicks, _showSecondUpMajorTicks, _showSecondDownMajorTicks, _showFirstUpMinorTicks, _showFirstDownMinorTicks, _showSecondUpMinorTicks, _showSecondDownMinorTicks }; var sides = new CSAxisSide[] { CSAxisSide.FirstUp, CSAxisSide.FirstDown, CSAxisSide.SecondUp, CSAxisSide.SecondDown, }; var sideDict = new Dictionary <CSAxisSide, int>(); for (int i = 0; i < sides.Length; ++i) { sideDict.Add(sides[i], i); } var newShown = (bool[])oldShown.Clone(); // Calculate new show variables // Major labels first for (int i = 0; i < 4; ++i) { var newAxisSide = GetNewAxisSideFromOldAxisSide(sides[i]); if (newAxisSide.HasValue) { int newIndex = sideDict[newAxisSide.Value]; newShown[newIndex] = oldShown[i]; } } // then minor labels for (int i = 0; i < 4; ++i) { var newAxisSide = GetNewAxisSideFromOldAxisSide(sides[i]); if (newAxisSide.HasValue) { int newIndex = 4 + sideDict[newAxisSide.Value]; newShown[newIndex] = oldShown[4 + i]; } } // bring _show variables from array back to members _showFirstUpMajorTicks = newShown[0]; _showFirstDownMajorTicks = newShown[1]; _showSecondUpMajorTicks = newShown[2]; _showSecondDownMajorTicks = newShown[3]; _showFirstUpMinorTicks = newShown[4]; _showFirstDownMinorTicks = newShown[5]; _showSecondUpMinorTicks = newShown[6]; _showSecondDownMinorTicks = newShown[7]; }
/// <summary> /// Paints the axis style labels. /// </summary> /// <param name="g">Graphics environment.</param> /// <param name="coordSyst">The coordinate system. Used to get the path along the axis.</param> /// <param name="scale">Scale.</param> /// <param name="tickSpacing">If not <c>null</c>, this parameter provides a custom tick spacing that is used instead of the default tick spacing of the scale.</param> /// <param name="styleInfo">Information about begin of axis, end of axis.</param> /// <param name="outerDistance">Distance between axis and labels.</param> /// <param name="useMinorTicks">If true, minor ticks are shown.</param> public virtual void Paint(Graphics g, G2DCoordinateSystem coordSyst, Scale scale, TickSpacing tickSpacing, CSAxisInformation styleInfo, double outerDistance, bool useMinorTicks) { _cachedAxisStyleInfo = styleInfo; CSLineID styleID = styleInfo.Identifier; Scale raxis = scale; TickSpacing ticking = tickSpacing; _enclosingPath.Reset(); _enclosingPath.FillMode = FillMode.Winding; // with Winding also overlapping rectangles are selected var helperPath = new GraphicsPath(); var math = new Matrix(); Logical3D r0 = styleID.GetLogicalPoint(styleInfo.LogicalValueAxisOrg); Logical3D r1 = styleID.GetLogicalPoint(styleInfo.LogicalValueAxisEnd); Logical3D outer; var dist_x = outerDistance; // Distance from axis tick point to label var dist_y = outerDistance; // y distance from axis tick point to label // dist_x += this._font.SizeInPoints/3; // add some space to the horizontal direction in order to separate the chars a little from the ticks // next statement is necessary to have a consistent string length both // on 0 degree rotated text and rotated text // without this statement, the text is fitted to the pixel grid, which // leads to "steps" during scaling g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; double[] relpositions; AltaxoVariant[] ticks; if (useMinorTicks) { relpositions = ticking.GetMinorTicksNormal(raxis); ticks = ticking.GetMinorTicksAsVariant(); } else { relpositions = ticking.GetMajorTicksNormal(raxis); ticks = ticking.GetMajorTicksAsVariant(); } if (!_suppressedLabels.IsEmpty) { var filteredTicks = new List <AltaxoVariant>(); var filteredRelPositions = new List <double>(); for (int i = 0; i < ticks.Length; i++) { if (_suppressedLabels.ByValues.Contains(ticks[i])) { continue; } if (_suppressedLabels.ByNumbers.Contains(i)) { continue; } if (_suppressedLabels.ByNumbers.Contains(i - ticks.Length)) { continue; } filteredTicks.Add(ticks[i]); filteredRelPositions.Add(relpositions[i]); } ticks = filteredTicks.ToArray(); relpositions = filteredRelPositions.ToArray(); } IMeasuredLabelItem[] labels = _labelFormatting.GetMeasuredItems(g, _font, _stringFormat, ticks); double emSize = _font.Size; CSAxisSide labelSide = null != _labelSide ? _labelSide.Value : styleInfo.PreferredLabelSide; for (int i = 0; i < ticks.Length; i++) { double r = relpositions[i]; if (!Altaxo.Calc.RMath.IsInIntervalCC(r, -1000, 1000)) { continue; } outer = coordSyst.GetLogicalDirection(styleID.ParallelAxisNumber, labelSide); PointD2D tickorg = coordSyst.GetNormalizedDirection(r0, r1, r, outer, out var outVector); PointD2D tickend = tickorg + outVector * outerDistance; PointD2D msize = labels[i].Size; PointD2D morg = tickend; if (_automaticRotationShift) { double alpha = _rotation * Math.PI / 180 - Math.Atan2(outVector.Y, outVector.X); double shift = msize.Y * 0.5 * Math.Abs(Math.Sin(alpha)) + (msize.X + _font.Size / 2) * 0.5 * Math.Abs(Math.Cos(alpha)); morg = morg + outVector * shift; } else { morg = morg.WithXPlus(outVector.X * _font.Size / 3); } var mrect = new RectangleD2D(morg, msize); if (_automaticRotationShift) { AdjustRectangle(ref mrect, StringAlignment.Center, StringAlignment.Center); } else { AdjustRectangle(ref mrect, _horizontalAlignment, _verticalAlignment); } math.Reset(); math.Translate((float)morg.X, (float)morg.Y); if (_rotation != 0) { math.Rotate((float)-_rotation); } math.Translate((float)(mrect.X - morg.X + emSize * _xOffset), (float)(mrect.Y - morg.Y + emSize * _yOffset)); System.Drawing.Drawing2D.GraphicsState gs = g.Save(); g.MultiplyTransform(math); if (_backgroundStyle != null) { _backgroundStyle.Draw(g, new RectangleD2D(PointD2D.Empty, msize)); } _brush.SetEnvironment(new RectangleD2D(PointD2D.Empty, msize), BrushX.GetEffectiveMaximumResolution(g, 1)); labels[i].Draw(g, _brush, new PointF(0, 0)); g.Restore(gs); // Restore the graphics state helperPath.Reset(); helperPath.AddRectangle(new RectangleF(PointF.Empty, (SizeF)msize)); helperPath.Transform(math); _enclosingPath.AddPath(helperPath, true); } }
public void ShowMinorLabels(CSAxisSide preferredLabelSide, Altaxo.Main.Properties.IReadOnlyPropertyBag context) { if (_minorLabelStyle == null) MinorLabelStyle = new AxisLabelStyle(preferredLabelSide, context) { CachedAxisInformation = _cachedAxisInfo }; }
/// <summary>Gets the name of the axis side.</summary> /// <param name="id">The axis identifier.</param> /// <param name="side">The axis side.</param> /// <returns>The name of the axis side for the axis line given by the identifier.</returns> public override string GetAxisSideName(CSLineID id, CSAxisSide side) { bool isHorizontal = id.ParallelAxisNumber == 0 ^ _isXYInterchanged; bool isOuterLine = (id.LogicalValueOtherFirst == 0 || id.LogicalValueOtherFirst == 1); if (isOuterLine) { bool isPointingOutwards = (id.LogicalValueOtherFirst == 0 && side == CSAxisSide.FirstDown) || (id.LogicalValueOtherFirst == 1 && side == CSAxisSide.FirstUp); return _axisSideNamesOuterLines[isHorizontal ? 0 : 1, isPointingOutwards ? 0 : 1]; } else { bool isRight = ((id.ParallelAxisNumber == 0 && _isYreverse) || (id.ParallelAxisNumber == 1 && _isXreverse)) ^ (side == CSAxisSide.FirstUp); return _axisSideNamesNormal[isHorizontal ? 0 : 1, isRight ? 0 : 1]; } }
public void SetDefaultValues() { switch (_identifier.ParallelAxisNumber) { case 0: _nameOfAxisStyle = "X-Axis"; break; case 1: _nameOfAxisStyle = "Y-Axis"; break; case 2: _nameOfAxisStyle = "Z-Axis"; break; default: _nameOfAxisStyle = "Axis" + _identifier.ParallelAxisNumber.ToString(); break; } _nameOfAxisStyle += string.Format(" (at L={0})",_identifier.LogicalValueOtherFirst.ToString()); _nameOfFirstDownSide = "FirstDown"; _nameOfFirstUpSide = "FirstUp"; _nameOfSecondDownSide = null; _nameOfSecondUpSide = null; _preferedLabelSide = CSAxisSide.FirstDown; }
/// <summary> /// Try to change the showing variables (e.g. <see cref="_showFirstDownMajorTicks"/>) when changing coordinate system, so that /// it is tried to keep the positions of the shown major and minor ticks. /// </summary> /// <param name="GetNewAxisSideFromOldAxisSide">The get new axis side from old axis side.</param> public void ChangeTickPositionsWhenChangingCoordinateSystem(Func<CSAxisSide, CSAxisSide?> GetNewAxisSideFromOldAxisSide) { // store old _show variables into temporary storage var oldShown = new bool[] { _showFirstUpMajorTicks, _showFirstDownMajorTicks, _showSecondUpMajorTicks, _showSecondDownMajorTicks, _showFirstUpMinorTicks, _showFirstDownMinorTicks, _showSecondUpMinorTicks, _showSecondDownMinorTicks }; var sides = new CSAxisSide[] { CSAxisSide.FirstUp, CSAxisSide.FirstDown, CSAxisSide.SecondUp, CSAxisSide.SecondDown, }; var sideDict = new Dictionary<CSAxisSide, int>(); for (int i = 0; i < sides.Length; ++i) sideDict.Add(sides[i], i); var newShown = (bool[])oldShown.Clone(); // Calculate new show variables // Major labels first for (int i = 0; i < 4; ++i) { var newAxisSide = GetNewAxisSideFromOldAxisSide(sides[i]); if (newAxisSide.HasValue) { int newIndex = sideDict[newAxisSide.Value]; newShown[newIndex] = oldShown[i]; } } // then minor labels for (int i = 0; i < 4; ++i) { var newAxisSide = GetNewAxisSideFromOldAxisSide(sides[i]); if (newAxisSide.HasValue) { int newIndex = 4 + sideDict[newAxisSide.Value]; newShown[newIndex] = oldShown[4 + i]; } } // bring _show variables from array back to members _showFirstUpMajorTicks = newShown[0]; _showFirstDownMajorTicks = newShown[1]; _showSecondUpMajorTicks = newShown[2]; _showSecondDownMajorTicks = newShown[3]; _showFirstUpMinorTicks = newShown[4]; _showFirstDownMinorTicks = newShown[5]; _showSecondUpMinorTicks = newShown[6]; _showSecondDownMinorTicks = newShown[7]; }
/// <summary> /// Finds the corresponding new axis side when changing the coordinate system. /// </summary> /// <param name="oldCoordinateSystem">The old coordinate system system.</param> /// <param name="oldLineID">The old line identifier of the axis.</param> /// <param name="oldAxisSide">The old axis side.</param> /// <param name="newCoordinateSystem">The new coordinate system.</param> /// <param name="newLineID">The new line identifier of the axis (in the new coordinate system).</param> /// <returns>The new axis side. The new axis side as vector in the new coordinate system has the same direction as the old axis side vector in the old coordinate system. /// The return value is null if no axis side with the same direction could be found (this is the case for instance when exchanging x and y axis).</returns> public static CSAxisSide?FindCorrespondingAxisSideWhenChangingCoordinateSystem(G3DCartesicCoordinateSystem oldCoordinateSystem, CSLineID oldLineID, CSAxisSide oldAxisSide, G3DCartesicCoordinateSystem newCoordinateSystem, CSLineID newLineID) { var t_oldAxisSide = oldCoordinateSystem.GetTransformedAxisSideVector(oldLineID, oldAxisSide); var u_newAxisSide = newCoordinateSystem.VectorTransformation.InverseTransform(t_oldAxisSide); try { return(GetAxisSide(newLineID, u_newAxisSide)); } catch (Exception) { return(null); } }
/// <summary> /// Returns the used space from the middle line of the axis /// to the last outer object (either the outer major thicks or half /// of the axis thickness) /// </summary> /// <param name="side">The side of the axis at which the outer distance is returned.</param> public double GetOuterDistance(CSAxisSide side) { double retVal = 0; if (CSAxisSide.FirstUp == side) { retVal = _axisPen.Thickness1 / 2; // half of the axis thickness retVal = System.Math.Max(retVal, _showFirstUpMajorTicks ? _majorTickLength : 0); retVal = System.Math.Max(retVal, _showFirstUpMinorTicks ? _minorTickLength : 0); } else if (CSAxisSide.FirstDown == side) { retVal = _axisPen.Thickness1 / 2; // half of the axis thickness retVal = System.Math.Max(retVal, _showFirstDownMajorTicks ? _majorTickLength : 0); retVal = System.Math.Max(retVal, _showFirstDownMinorTicks ? _minorTickLength : 0); } else if (CSAxisSide.SecondUp == side) { retVal = _axisPen.Thickness2 / 2; // half of the axis thickness retVal = System.Math.Max(retVal, _showSecondUpMajorTicks ? _majorTickLength : 0); retVal = System.Math.Max(retVal, _showSecondUpMinorTicks ? _minorTickLength : 0); } else if (CSAxisSide.SecondDown == side) { retVal = _axisPen.Thickness2 / 2; // half of the axis thickness retVal = System.Math.Max(retVal, _showSecondDownMajorTicks ? _majorTickLength : 0); retVal = System.Math.Max(retVal, _showSecondDownMinorTicks ? _minorTickLength : 0); } else { retVal = 0; } return retVal; }
/// <summary> /// Gets the untransformed axis side vector, the the vector that points out of the plane of the axis side. /// </summary> /// <param name="id">The axis identifier.</param> /// <param name="side">The side identifier.</param> /// <returns>The vector corresponding to the axis side.</returns> /// <exception cref="System.NotImplementedException"> /// </exception> private static VectorD3D GetUntransformedAxisSideVector(CSLineID id, CSAxisSide side) { VectorD3D r = VectorD3D.Empty; switch (id.ParallelAxisNumber) { case 0: // parallel axis is X { switch (side) { case CSAxisSide.FirstDown: r = new VectorD3D(0, -1, 0); // "front"; break; case CSAxisSide.FirstUp: r = new VectorD3D(0, 1, 0); // "back"; break; case CSAxisSide.SecondDown: r = new VectorD3D(0, 0, -1); //"down"; break; case CSAxisSide.SecondUp: r = new VectorD3D(0, 0, 1); // "up"; break; default: throw new NotImplementedException(); } } break; case 1: // parallel axis is Y { switch (side) { case CSAxisSide.FirstDown: r = new VectorD3D(-1, 0, 0); // "left"; break; case CSAxisSide.FirstUp: r = new VectorD3D(1, 0, 0); // "right"; break; case CSAxisSide.SecondDown: r = new VectorD3D(0, 0, -1); // "down"; break; case CSAxisSide.SecondUp: r = new VectorD3D(0, 0, 1); // "up"; break; default: throw new NotImplementedException(); } } break; case 2: // parallel axis is Z { switch (side) { case CSAxisSide.FirstDown: r = new VectorD3D(-1, 0, 0); // "left"; break; case CSAxisSide.FirstUp: r = new VectorD3D(1, 0, 0); // "right"; break; case CSAxisSide.SecondDown: r = new VectorD3D(0, -1, 0); // "front"; break; case CSAxisSide.SecondUp: r = new VectorD3D(0, 1, 0); // "back"; break; default: throw new NotImplementedException(); } } break; default: throw new NotImplementedException(); } return(r); }
private void ShowAxisLine(bool hasTicksByDefault, CSAxisSide preferredTickSide, IReadOnlyPropertyBag context) { if (_axisLineStyle == null) AxisLineStyle = new AxisLineStyle(hasTicksByDefault, preferredTickSide, context); }
/// <summary> /// Paints the axis style labels. /// </summary> /// <param name="g">Graphics environment.</param> /// <param name="coordSyst">The coordinate system. Used to get the path along the axis.</param> /// <param name="scale">Scale.</param> /// <param name="tickSpacing">If not <c>null</c>, this parameter provides a custom tick spacing that is used instead of the default tick spacing of the scale.</param> /// <param name="styleInfo">Information about begin of axis, end of axis.</param> /// <param name="outerDistance">Distance between axis and labels.</param> /// <param name="useMinorTicks">If true, minor ticks are shown.</param> public virtual void Paint(IGraphicsContext3D g, G3DCoordinateSystem coordSyst, Scale scale, TickSpacing tickSpacing, CSAxisInformation styleInfo, double outerDistance, bool useMinorTicks) { _cachedAxisStyleInfo = styleInfo; CSLineID styleID = styleInfo.Identifier; Scale raxis = scale; TickSpacing ticking = tickSpacing; var math = Matrix4x3.Identity; Logical3D r0 = styleID.GetLogicalPoint(styleInfo.LogicalValueAxisOrg); Logical3D r1 = styleID.GetLogicalPoint(styleInfo.LogicalValueAxisEnd); Logical3D outer; double[] relpositions; AltaxoVariant[] ticks; if (useMinorTicks) { relpositions = ticking.GetMinorTicksNormal(raxis); ticks = ticking.GetMinorTicksAsVariant(); } else { relpositions = ticking.GetMajorTicksNormal(raxis); ticks = ticking.GetMajorTicksAsVariant(); } if (!_suppressedLabels.IsEmpty) { var filteredTicks = new List <AltaxoVariant>(); var filteredRelPositions = new List <double>(); for (int i = 0; i < ticks.Length; i++) { if (_suppressedLabels.ByValues.Contains(ticks[i])) { continue; } if (_suppressedLabels.ByNumbers.Contains(i)) { continue; } if (_suppressedLabels.ByNumbers.Contains(i - ticks.Length)) { continue; } filteredTicks.Add(ticks[i]); filteredRelPositions.Add(relpositions[i]); } ticks = filteredTicks.ToArray(); relpositions = filteredRelPositions.ToArray(); } IMeasuredLabelItem[] labels = _labelFormatting.GetMeasuredItems(g, _font, ticks); double emSize = _font.Size; CSAxisSide labelSide = null != _labelSide ? _labelSide.Value : styleInfo.PreferredLabelSide; var labelOutlines = new RectangularObjectOutline[ticks.Length]; for (int i = 0; i < ticks.Length; i++) { double r = relpositions[i]; if (!Altaxo.Calc.RMath.IsInIntervalCC(r, -1000, 1000)) { continue; } outer = coordSyst.GetLogicalDirection(styleID.ParallelAxisNumber, labelSide); PointD3D tickorg = coordSyst.GetPositionAndNormalizedDirection(r0, r1, r, outer, out var outVector); PointD3D tickend = tickorg + outVector * outerDistance; var msize = labels[i].Size; var morg = tickend; if (_automaticRotationShift) { // if this option is choosen, we have to find a shift value that shifts the center of the text outwards so that the bounding box of the text will not cross the plane that is // defined by the tickend point and the normal vector outVector // Assume that the text is now centered x, y, and z around the point tickend (but here we use origin instead tickend) math = Matrix4x3.NewRotation(_rotationX, _rotationY, _rotationZ); // we have to find all points with negative distance to the plane spanned by tickend and the vector outVector (but again instead of tickend we use origin) var msizePad = msize + new VectorD3D( (_font.Size * 1) / 3, // whereas above and below text no padding is neccessary, it is optically nicer to have left and right padding of the string by 1/6 of font size. 0, (_font.Size * 1) / 3 // same padding applies to z ); var crect = new RectangleD3D((PointD3D)(-0.5 * msizePad), msizePad); // our text centered around origin double shift = 0; foreach (PointD3D p in crect.Vertices) { PointD3D ps = math.Transform(p); double distance = Math3D.GetDistancePointToPlane(ps, PointD3D.Empty, outVector); if (-distance > shift) { shift = -distance; // only negative distances will count here } } morg += outVector * shift; } else { morg = morg.WithXPlus(outVector.X * _font.Size / 3); } var mrect = new RectangleD3D(morg, msize); if (_automaticRotationShift) { mrect = AdjustRectangle(mrect, Alignment.Center, Alignment.Center, Alignment.Center); } else { mrect = AdjustRectangle(mrect, _alignmentX, _alignmentY, _alignmentZ); } math = Matrix4x3.Identity; math.TranslatePrepend(morg.X, morg.Y, morg.Z); if (_rotationZ != 0) { math.RotationZDegreePrepend(_rotationZ); } if (_rotationY != 0) { math.RotationYDegreePrepend(_rotationY); } if (_rotationX != 0) { math.RotationXDegreePrepend(_rotationX); } math.TranslatePrepend((mrect.X - morg.X + emSize * _offsetX), (mrect.Y - morg.Y + emSize * _offsetY), (mrect.Z - morg.Z + emSize * _offsetZ)); var gs = g.SaveGraphicsState(); g.PrependTransform(math); if (_backgroundStyle != null) { var itemRectangle = new RectangleD3D(PointD3D.Empty, msize); _backgroundStyle.Measure(itemRectangle); _backgroundStyle.Draw(g, itemRectangle); } labels[i].Draw(g, _brush, PointD3D.Empty); labelOutlines[i] = new RectangularObjectOutline(new RectangleD3D(PointD3D.Empty, msize), math); g.RestoreGraphicsState(gs); // Restore the graphics state } _cachedLabelOutlines = labelOutlines; }
/// <summary> /// Gets the logical direction to the sides of an axis. /// </summary> /// <param name="parallelAxisNumber">Number of the axis (0: X, 1: Y, 2: Z).</param> /// <param name="side">Designates the sides of the axis.</param> /// <returns>The logical direction to the given side. The returned vector is normalized.</returns> public Logical3D GetLogicalDirection(int parallelAxisNumber, CSAxisSide side) { switch (side) { default: case CSAxisSide.FirstDown: return 0 == parallelAxisNumber ? new Logical3D(0, -1, 0) : new Logical3D(-1, 0, 0); case CSAxisSide.FirstUp: return 0 == parallelAxisNumber ? new Logical3D(0, 1, 0) : new Logical3D(1, 0, 0); case CSAxisSide.SecondDown: return 2 == parallelAxisNumber ? new Logical3D(0, -1, 0) : new Logical3D(0, 0, -1); case CSAxisSide.SecondUp: return 2 == parallelAxisNumber ? new Logical3D(0, 1, 0) : new Logical3D(0, 0, 1); } }
/// <summary>Gets the name of the axis side.</summary> /// <param name="id">The axis identifier.</param> /// <param name="side">The axis side.</param> /// <returns>The name of the axis side for the axis line given by the identifier.</returns> public override string GetAxisSideName(CSLineID id, CSAxisSide side) { return(_axisNamesNormal[id.ParallelAxisNumber, (int)side]); }
public AxisLabelStyle(CSAxisSide? labelSide, Altaxo.Main.Properties.IReadOnlyPropertyBag context) { if (null == context) context = PropertyExtensions.GetPropertyContextOfProject(); _labelSide = labelSide; _font = GraphDocument.GetDefaultFont(context); var foreColor = GraphDocument.GetDefaultForeColor(context); _brush = Materials.GetSolidMaterial(foreColor); _automaticRotationShift = true; _rotationX = 90; _suppressedLabels = new SuppressedTicks() { ParentObject = this }; _labelFormatting = new LabelFormatting.NumericLabelFormattingAuto() { ParentObject = this }; }