public AxisStyle(CSAxisInformation info, bool isAxisLineEnabled, bool areMajorTicksEnabled, bool areMinorTicksEnabled, string axisTitleOrNull, Altaxo.Main.Properties.IReadOnlyPropertyBag context) { _styleID = info.Identifier; if (isAxisLineEnabled) { ShowAxisLine(info.HasTicksByDefault, info.PreferredTickSide, context); } if (info.HasLabelsByDefault) { ShowMajorLabels(info.PreferredLabelSide, context); } if (info.HasLabelsByDefault && areMinorTicksEnabled) { ShowMinorLabels(info.PreferredLabelSide, context); } if (null != axisTitleOrNull) { ShowTitle(context); _axisTitle.Text = axisTitleOrNull; } }
private void SetCoordinateSystemDependentObjects(CSLineID id) { // Scales _listOfScales = new SelectableListNodeList { new SelectableListNode("Z-Scale", 0, false) }; // Axes // collect the AxisStyleIdentifier from the actual layer and also all possible AxisStyleIdentifier _axisControl = new Dictionary <CSLineID, AxisStyleControllerConditionalGlue>(); _listOfAxes = new SelectableListNodeList(); foreach (CSLineID ids in _doc.CoordinateSystem.GetJoinedAxisStyleIdentifier(_doc.AxisStyles.AxisStyleIDs, new CSLineID[] { id })) { CSAxisInformation info = _doc.CoordinateSystem.GetAxisStyleInformation(ids); var axisInfo = new AxisStyleControllerConditionalGlue(info, _doc.AxisStyles); _axisControl.Add(info.Identifier, axisInfo); _listOfAxes.Add(new SelectableListNode(info.NameOfAxisStyle, info.Identifier, false)); } // Planes _listOfPlanes = new SelectableListNodeList(); _currentPlaneID = CSPlaneID.Front; _listOfPlanes.Add(new SelectableListNode("Front", _currentPlaneID, true)); }
private IList <CSAxisInformation> GetAxisStyleInformations() { var axisStyleInformations = new List <CSAxisInformation>(); for (int axisnumber = 0; axisnumber <= 2; ++axisnumber) { for (int firstother = 0; firstother <= 1; ++firstother) { for (int secondother = 0; secondother <= 1; ++secondother) { var lineId = new CSLineID(axisnumber, firstother, secondother); var item = new CSAxisInformation( Identifier: lineId, NameOfAxisStyle: GetAxisLineName(lineId), NameOfFirstDownSide: GetAxisSideName(lineId, CSAxisSide.FirstDown), NameOfFirstUpSide: GetAxisSideName(lineId, CSAxisSide.FirstUp), NameOfSecondDownSide: GetAxisSideName(lineId, CSAxisSide.SecondDown), NameOfSecondUpSide: GetAxisSideName(lineId, CSAxisSide.SecondUp), PreferredLabelSide: GetPreferredLabelSide(lineId), PreferredTickSide: GetPreferredLabelSide(lineId), IsShownByDefault: true, // lineId.LogicalValueOtherFirst :: 0 && lineId.LogicalValueOtherSecond :: 0. HasTicksByDefault: true, HasLabelsByDefault: GetHasLabelsByDefault(lineId), HasTitleByDefault: GetHasLabelsByDefault(lineId)); axisStyleInformations.Add(item); } } } return(axisStyleInformations.AsReadOnly()); }
/// <summary> /// Copy operation. /// </summary> /// <param name="obj">The AxisStyle to copy from</param> public bool CopyFrom(object obj) { if (object.ReferenceEquals(this, obj)) { return(true); } var from = obj as AxisLineStyle; if (null == from) { return(false); } using (var suspendToken = SuspendGetToken()) { ChildCopyToMember(ref _axisPen, from._axisPen); _axisPosition = from._axisPosition; _showFirstDownMajorTicks = from._showFirstDownMajorTicks; _showFirstDownMinorTicks = from._showFirstDownMinorTicks; _showFirstUpMajorTicks = from._showFirstUpMajorTicks; _showFirstUpMinorTicks = from._showFirstUpMinorTicks; _majorTickLength = from._majorTickLength; ChildCopyToMember(ref _majorTickPen, from._majorTickPen); _minorTickLength = from._minorTickLength; ChildCopyToMember(ref _minorTickPen, from._minorTickPen); _cachedAxisStyleInfo = from._cachedAxisStyleInfo; EhSelfChanged(EventArgs.Empty); suspendToken.Resume(); } return(true); }
public CSAxisInformation GetAxisStyleInformation(CSLineID styleID) { if (_axisStyleInformation == null || _axisStyleInformation.Count == 0) { UpdateAxisInfo(); } // search for the same axis first, then for the style with the nearest logical value double minDistance = double.MaxValue; CSAxisInformation nearestInfo = null; foreach (CSAxisInformation info in this._axisStyleInformation) { if (styleID.ParallelAxisNumber == info.Identifier.ParallelAxisNumber) { if (styleID == info.Identifier) { minDistance = 0; nearestInfo = info; break; } double dist = Math.Abs(styleID.LogicalValueOtherFirst - info.Identifier.LogicalValueOtherFirst); if (styleID.Is3DIdentifier && info.Identifier.Is3DIdentifier) { dist += Math.Abs(styleID.LogicalValueOtherSecond - info.Identifier.LogicalValueOtherSecond); } if (dist < minDistance) { minDistance = dist; nearestInfo = info; if (0 == minDistance) { break; // it can not be smaller than 0 } } } } CSAxisInformation result = new CSAxisInformation(styleID); if (nearestInfo == null) { result.SetDefaultValues(); } else { result.CopyWithoutIdentifierFrom(nearestInfo); if (minDistance != 0) { result.NameOfAxisStyle += string.Format(" ({0}% offs.)", minDistance * 100); } } return(result); }
public CSPlaneInformation GetPlaneInformation(CSPlaneID planeID) { CSLineID lineID = (CSLineID)planeID; CSAxisInformation lineInfo = GetAxisStyleInformation(lineID); CSPlaneInformation result = new CSPlaneInformation(planeID); result.Name = lineInfo.NameOfAxisStyle; return(result); }
/// <summary> /// Creates the axis style with ShowAxisLine = true and ShowMajorLabels = true /// </summary> /// <param name="info">The axis information.</param> /// <param name="context">Property context used to determine default values, e.g. for the pen width or symbol size.</param> /// <returns>The newly created axis style, if it was not in the collection before. Returns the unchanged axis style, if it was present already in the collection.</returns> public AxisStyle CreateDefault(CSAxisInformation info, IReadOnlyPropertyBag context) { AxisStyle prop = this[info.Identifier]; if (prop == null) { prop = new AxisStyle(info, true, info.HasTicksByDefault, false, null, context) { CachedAxisInformation = _cachedCoordinateSystem.GetAxisStyleInformation(info.Identifier) }; Add(prop); } return(prop); }
public bool CopyFrom(object obj) { var from = obj as AxisStyle; if (null == from) { return(false); } if (!object.ReferenceEquals(this, from)) { _styleID = from._styleID; // immutable _cachedAxisInfo = from._cachedAxisInfo; // attention - have to appear _before_ CopyWithoutIdFrom, since the _cachedAxisInfo is used when cloning AxisLineStyle! CopyWithoutIdFrom(from); } return(true); }
void SetCoordinateSystemDependentObjects(CSLineID id) { // collect the AxisStyleIdentifier from the actual layer and also all possible AxisStyleIdentifier _axisStyleIds = new Dictionary <CSLineID, CSAxisInformation>(); _axisStyleInfoSortedByName = new List <CSAxisInformation>(); foreach (CSLineID ids in _doc.CoordinateSystem.GetJoinedAxisStyleIdentifier(_doc.AxisStyles.AxisStyleIDs, new CSLineID[] { id })) { CSAxisInformation info = _doc.CoordinateSystem.GetAxisStyleInformation(ids); _axisStyleIds.Add(info.Identifier, info); _axisStyleInfoSortedByName.Add(info); } _planeIdentifier = new List <CSPlaneID>(); _planeIdentifier.Add(CSPlaneID.Front); _axisScaleController = new AxisScaleController[2]; _GridStyleController = new Dictionary <CSPlaneID, IMVCANController>(); _TitleFormatController = new Dictionary <CSLineID, IMVCANController>(); _MajorLabelController = new Dictionary <CSLineID, IMVCANController>(); _MinorLabelController = new Dictionary <CSLineID, IMVCANController>(); _enableAxisStyle = new Dictionary <CSLineID, bool>(); _enableMajorLabels = new Dictionary <CSLineID, bool>(); _enableMinorLabels = new Dictionary <CSLineID, bool>(); foreach (CSLineID ident in _axisStyleIds.Keys) { AxisStyle prop = _doc.AxisStyles[ident]; if (prop == null) { _enableAxisStyle.Add(ident, false); _enableMajorLabels.Add(ident, false); _enableMinorLabels.Add(ident, false); } else { _enableAxisStyle.Add(ident, true); _enableMajorLabels.Add(ident, prop.ShowMajorLabels); _enableMinorLabels.Add(ident, prop.ShowMinorLabels); } } }
private void SetCoordinateSystemDependentObjects(CSLineID id) { // Scales _axisScaleController = new ScaleWithTicksController[_doc.Scales.Count]; _listOfScales = new SelectableListNodeList(); if (_doc.Scales.Count > 0) { _listOfScales.Add(new SelectableListNode("X-Scale", 0, false)); } if (_doc.Scales.Count > 1) { _listOfScales.Add(new SelectableListNode("Y-Scale", 1, false)); } if (_doc.Scales.Count > 2) { _listOfScales.Add(new SelectableListNode("Z-Scale", 2, false)); } // collect the AxisStyleIdentifier from the actual layer and also all possible AxisStyleIdentifier _axisControl = new Dictionary <CSLineID, AxisStyleControllerConditionalGlue>(); _listOfAxes = new SelectableListNodeList(); foreach (CSLineID ids in _doc.CoordinateSystem.GetJoinedAxisStyleIdentifier(_doc.AxisStyles.AxisStyleIDs, new CSLineID[] { id })) { CSAxisInformation info = _doc.CoordinateSystem.GetAxisStyleInformation(ids); var axisInfo = new AxisStyleControllerConditionalGlue(info, _doc.AxisStyles); _axisControl.Add(info.Identifier, axisInfo); _listOfAxes.Add(new SelectableListNode(info.NameOfAxisStyle, info.Identifier, false)); } // Planes _listOfPlanes = new SelectableListNodeList(); _currentPlaneID = CSPlaneID.Back3D; _listOfPlanes.Add(new SelectableListNode("Left", CSPlaneID.Left3D, true)); _listOfPlanes.Add(new SelectableListNode("Front", CSPlaneID.Front3D, true)); _listOfPlanes.Add(new SelectableListNode("Right", CSPlaneID.Right3D, true)); _listOfPlanes.Add(new SelectableListNode("Back", CSPlaneID.Back3D, true)); _listOfPlanes.Add(new SelectableListNode("Top", CSPlaneID.Top3D, true)); _listOfPlanes.Add(new SelectableListNode("Bottom", CSPlaneID.Bottom3D, true)); _GridStyleController = new Dictionary <CSPlaneID, IMVCANController>(); }
public void Paint(Graphics g, XYPlotLayer layer) { // update the logical values of the physical axes before if (_styleID.UsePhysicalValueOtherFirst) { // then update the logical value of this identifier double logicalValue = layer.Scales(_styleID.AxisNumberOtherFirst).PhysicalVariantToNormal(_styleID.PhysicalValueOtherFirst); _styleID.LogicalValueOtherFirst = logicalValue; } if (_styleID.UsePhysicalValueOtherSecond) { // then update the logical value of this identifier double logicalValue = layer.Scales(_styleID.AxisNumberOtherSecond).PhysicalVariantToNormal(_styleID.PhysicalValueOtherSecond); _styleID.LogicalValueOtherSecond = logicalValue; } int axisnumber = _styleID.ParallelAxisNumber; CSAxisInformation styleinfo = layer.CoordinateSystem.GetAxisStyleInformation(_styleID); _cachedAxisInfo = styleinfo; if (ShowAxisLine) { _axisLineStyle.Paint(g, layer, styleinfo); } if (ShowMajorLabels) { this._majorLabelStyle.Paint(g, layer, styleinfo, _axisLineStyle, false); } if (ShowMinorLabels) { this._minorLabelStyle.Paint(g, layer, styleinfo, _axisLineStyle, true); } if (ShowTitle) { _axisTitle.Paint(g, layer); } }
/// <summary> /// Copy operation. /// </summary> /// <param name="from">The AxisStyle to copy from</param> public void CopyFrom(AxisLineStyle from) { if (_axisPen != null) { WireEventChain(false); } this._axisPen = null == from._axisPen ? null : (PenX)from._axisPen.Clone(); this._axisPosition = from._axisPosition; this._showFirstDownMajorTicks = from._showFirstDownMajorTicks; this._showFirstDownMinorTicks = from._showFirstDownMinorTicks; this._showFirstUpMajorTicks = from._showFirstUpMajorTicks; this._showFirstUpMinorTicks = from._showFirstUpMinorTicks; this._majorTickLength = from._majorTickLength; this._majorTickPen = null == from._majorTickPen ? null : (PenX)from._majorTickPen; this._minorTickLength = from._minorTickLength; this._minorTickPen = (null == from._minorTickPen) ? null : (PenX)from._minorTickPen; this._cachedAxisStyleInfo = from._cachedAxisStyleInfo; this._parent = from._parent; // Rewire the event chain WireEventChain(true); }
/// <summary> /// Abstract paint function for the AbstractXYAxisLabelStyle. /// </summary> /// <param name="g">The graphics context.</param> /// <param name="layer">The layer the lables belongs to.</param> /// <param name="styleInfo">The information which identifies the axis styles.</param> /// <param name="axisstyle">The axis style the axis is formatted with.</param> /// <param name="useMinorTicks">If true, the minor ticks where used instead of the (default) major ticks.</param> public abstract void Paint(Graphics g, XYPlotLayer layer, CSAxisInformation styleInfo, AxisLineStyle axisstyle, bool useMinorTicks);
protected override void UpdateAxisInfo() { int horzAx; int vertAx; bool vertRev; bool horzRev; if (_isXYInterchanged) { horzAx = 1; vertAx = 0; vertRev = _isXreverse; horzRev = _isYreverse; } else { horzAx = 0; vertAx = 1; vertRev = _isYreverse; horzRev = _isXreverse; } if (null != _axisStyleInformation) _axisStyleInformation.Clear(); else _axisStyleInformation = new List<CSAxisInformation>(); CSAxisInformation info; // Right info = new CSAxisInformation( Identifier: new CSLineID(vertAx, 0), NameOfAxisStyle: "RightDirection", NameOfFirstUpSide: horzRev ? "Below" : "Above", NameOfFirstDownSide: horzRev ? "Above" : "Below", PreferredLabelSide: horzRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown, IsShownByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // Left info = new CSAxisInformation( Identifier: new CSLineID(vertAx, 0.5), NameOfAxisStyle: "LeftDirection", NameOfFirstUpSide: horzRev ? "Above" : "Below", NameOfFirstDownSide: horzRev ? "Below" : "Above", PreferredLabelSide: horzRev ? CSAxisSide.FirstDown : CSAxisSide.FirstUp); _axisStyleInformation.Add(info); // Top info = new CSAxisInformation( Identifier: new CSLineID(vertAx, horzRev ? 0.75 : 0.25), NameOfAxisStyle: "TopDirection", NameOfFirstUpSide: horzRev ? "Right" : "Left", NameOfFirstDownSide: horzRev ? "Left" : "Right", PreferredLabelSide: horzRev ? CSAxisSide.FirstDown : CSAxisSide.FirstUp); _axisStyleInformation.Add(info); // Bottom info = new CSAxisInformation( Identifier: new CSLineID(vertAx, horzRev ? 0.25 : 0.75), NameOfAxisStyle: "BottomDirection", NameOfFirstUpSide: horzRev ? "Left" : "Right", NameOfFirstDownSide: horzRev ? "Right" : "Left", PreferredLabelSide: horzRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown); _axisStyleInformation.Add(info); // Outer circle info = new CSAxisInformation( Identifier: new CSLineID(horzAx, vertRev ? 0 : 1), NameOfAxisStyle: "OuterCircle", NameOfFirstDownSide: vertRev ? "Outer" : "Inner", NameOfFirstUpSide: vertRev ? "Inner" : "Outer", PreferredLabelSide: vertRev ? CSAxisSide.FirstDown : CSAxisSide.FirstUp, IsShownByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // Inner circle info = new CSAxisInformation( Identifier: new CSLineID(horzAx, vertRev ? 1 : 0), NameOfAxisStyle: "Inner circle", NameOfFirstDownSide: vertRev ? "Inner" : "Outer", NameOfFirstUpSide: vertRev ? "Outer" : "Inner", PreferredLabelSide: vertRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown); _axisStyleInformation.Add(info); }
/// <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); } }
protected override void UpdateAxisInfo() { int horzAx = 0; int vertAx = 1; int deptAx = 2; if (null == _axisStyleInformation) { _axisStyleInformation = new List <CSAxisInformation>(); } else { _axisStyleInformation.Clear(); } CSAxisInformation info; // BottomFront info = new CSAxisInformation( Identifier: new CSLineID(horzAx, 0, 0), NameOfAxisStyle: "BottomFront", NameOfFirstDownSide: "Below", NameOfFirstUpSide: "Above", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // TopFront info = new CSAxisInformation( Identifier: new CSLineID(horzAx, 1, 0), NameOfAxisStyle: "TopFront", NameOfFirstDownSide: "Below", NameOfFirstUpSide: "Above", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstUp, PreferredTickSide: CSAxisSide.FirstUp, IsShownByDefault: true, HasTicksByDefault: false, HasLabelsByDefault: false, HasTitleByDefault: false); _axisStyleInformation.Add(info); // LeftFront info = new CSAxisInformation( Identifier: new CSLineID(vertAx, 0, 0), NameOfAxisStyle: "LeftFront", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // RightFront info = new CSAxisInformation( Identifier: new CSLineID(vertAx, 1, 0), NameOfAxisStyle: "RightFront", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstUp, PreferredTickSide: CSAxisSide.FirstUp, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: true ); _axisStyleInformation.Add(info); // BottomBack info = new CSAxisInformation( new CSLineID(horzAx, 0, 1), NameOfAxisStyle: "BottomBack", NameOfFirstDownSide: "Below", NameOfFirstUpSide: "Above", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // TopBack info = new CSAxisInformation( Identifier: new CSLineID(horzAx, 1, 1), NameOfAxisStyle: "TopBack", NameOfFirstDownSide: "Below", NameOfFirstUpSide: "Above", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstUp, PreferredTickSide: CSAxisSide.FirstUp, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: true ); _axisStyleInformation.Add(info); // LeftBack info = new CSAxisInformation( new CSLineID(vertAx, 0, 1), NameOfAxisStyle: "LeftBack", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // RightBack info = new CSAxisInformation( Identifier: new CSLineID(vertAx, 1, 1), NameOfAxisStyle: "RightBack", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstUp, PreferredTickSide: CSAxisSide.FirstUp, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: false ); _axisStyleInformation.Add(info); // BottomLeft info = new CSAxisInformation( Identifier: new CSLineID(deptAx, 0, 0), NameOfAxisStyle: "BottomLeft", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Below", NameOfSecondUpSide: "Above", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // TopLeft info = new CSAxisInformation( Identifier: new CSLineID(deptAx, 0, 1), NameOfAxisStyle: "TopLeft", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Below", NameOfSecondUpSide: "Above", PreferredLabelSide: CSAxisSide.FirstUp, PreferredTickSide: CSAxisSide.FirstUp, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: false ); _axisStyleInformation.Add(info); // BottomRight info = new CSAxisInformation( Identifier: new CSLineID(deptAx, 1, 0), NameOfAxisStyle: "BottomRight", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Below", NameOfSecondUpSide: "Above", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // TopRight info = new CSAxisInformation( Identifier: new CSLineID(deptAx, 1, 1), NameOfAxisStyle: "TopRight", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Below", NameOfSecondUpSide: "Above", PreferredLabelSide: CSAxisSide.FirstUp, PreferredTickSide: CSAxisSide.FirstUp, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: false ); _axisStyleInformation.Add(info); // XAxis: Y=0, Z=0 info = new CSAxisInformation( Identifier: CSLineID.FromPhysicalValue(horzAx, 0), NameOfAxisStyle: "YZ:0", NameOfFirstUpSide: "Above", NameOfFirstDownSide: "Below", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: false, HasTicksByDefault: false, HasLabelsByDefault: false, HasTitleByDefault: false ); _axisStyleInformation.Add(info); // YAxis: X=0, Z=0 info = new CSAxisInformation( Identifier: CSLineID.FromPhysicalValue(vertAx, 0), NameOfAxisStyle: "XZ:0", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: false, HasTicksByDefault: false, HasLabelsByDefault: false, HasTitleByDefault: false ); _axisStyleInformation.Add(info); // ZAxis: X=0,Y=0 info = new CSAxisInformation( CSLineID.FromPhysicalValue(deptAx, 0), NameOfAxisStyle: "XY:0", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: false, HasTicksByDefault: false, HasLabelsByDefault: false, HasTitleByDefault: false); _axisStyleInformation.Add(info); }
protected override void UpdateAxisInfo() { int horzAx = 0; int vertAx = 1; int deptAx = 2; if (null == _axisStyleInformation) { _axisStyleInformation = new List <CSAxisInformation>(); } else { _axisStyleInformation.Clear(); } CSAxisInformation info; // BottomFront info = new CSAxisInformation(new CSLineID(horzAx, 0, 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "BottomFront"; info.NameOfFirstDownSide = "Below"; info.NameOfFirstUpSide = "Above"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstDown; info.IsShownByDefault = true; info.HasTitleByDefault = true; // TopFront info = new CSAxisInformation(new CSLineID(horzAx, 1, 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "TopFront"; info.NameOfFirstDownSide = "Below"; info.NameOfFirstUpSide = "Above"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstUp; info.IsShownByDefault = true; // LeftFront info = new CSAxisInformation(new CSLineID(vertAx, 0, 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "LeftFront"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstDown; info.IsShownByDefault = true; info.HasTitleByDefault = true; // RightFront info = new CSAxisInformation(new CSLineID(vertAx, 1, 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "RightFront"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstUp; info.IsShownByDefault = true; // BottomBack info = new CSAxisInformation(new CSLineID(horzAx, 0, 1)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "BottomBack"; info.NameOfFirstDownSide = "Below"; info.NameOfFirstUpSide = "Above"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstDown; info.IsShownByDefault = true; info.HasTitleByDefault = true; // TopBack info = new CSAxisInformation(new CSLineID(horzAx, 1, 1)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "TopBack"; info.NameOfFirstDownSide = "Below"; info.NameOfFirstUpSide = "Above"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstUp; info.IsShownByDefault = true; // LeftBack info = new CSAxisInformation(new CSLineID(vertAx, 0, 1)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "LeftBack"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstDown; info.IsShownByDefault = true; info.HasTitleByDefault = true; // RightBack info = new CSAxisInformation(new CSLineID(vertAx, 1, 1)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "RightBack"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstUp; info.IsShownByDefault = true; // BottomLeft info = new CSAxisInformation(new CSLineID(deptAx, 0, 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "BottomLeft"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Below"; info.NameOfSecondUpSide = "Above"; info.PreferedLabelSide = CSAxisSide.FirstDown; info.IsShownByDefault = true; info.HasTitleByDefault = true; // TopLeft info = new CSAxisInformation(new CSLineID(deptAx, 0, 1)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "TopLeft"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Below"; info.NameOfSecondUpSide = "Above"; info.PreferedLabelSide = CSAxisSide.FirstUp; info.IsShownByDefault = true; // BottomRight info = new CSAxisInformation(new CSLineID(deptAx, 1, 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "BottomRight"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Below"; info.NameOfSecondUpSide = "Above"; info.PreferedLabelSide = CSAxisSide.FirstDown; info.IsShownByDefault = true; info.HasTitleByDefault = true; // TopRight info = new CSAxisInformation(new CSLineID(deptAx, 1, 1)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "TopRight"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Below"; info.NameOfSecondUpSide = "Above"; info.PreferedLabelSide = CSAxisSide.FirstUp; info.IsShownByDefault = true; // XAxis: Y=0, Z=0 info = new CSAxisInformation(CSLineID.FromPhysicalValue(horzAx, 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "YZ=0"; info.NameOfFirstUpSide = "Above"; info.NameOfFirstDownSide = "Below"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstDown; // YAxis: X=0, Z=0 info = new CSAxisInformation(CSLineID.FromPhysicalValue(vertAx, 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "XZ=0"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstDown; // ZAxis: X=0,Y=0 info = new CSAxisInformation(CSLineID.FromPhysicalValue(deptAx, 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "XY=0"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstDown; }
protected override void UpdateAxisInfo() { int horzAx; int vertAx; bool vertRev; bool horzRev; if (_isXYInterchanged) { horzAx = 1; vertAx = 0; vertRev = _isXreverse; horzRev = _isYreverse; } else { horzAx = 0; vertAx = 1; vertRev = _isYreverse; horzRev = _isXreverse; } if (null != _axisStyleInformation) _axisStyleInformation.Clear(); else _axisStyleInformation = new List<CSAxisInformation>(); CSAxisInformation info; // Right info = new CSAxisInformation(new CSLineID(vertAx, 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "RightDirection"; info.NameOfFirstUpSide = horzRev ? "Below" : "Above"; info.NameOfFirstDownSide = horzRev ? "Above" : "Below"; info.PreferedLabelSide = horzRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown; info.IsShownByDefault = true; info.HasTitleByDefault = true; // Left info = new CSAxisInformation(new CSLineID(vertAx, 0.5)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "LeftDirection"; info.NameOfFirstUpSide = horzRev ? "Above" : "Below"; info.NameOfFirstDownSide = horzRev ? "Below" : "Above"; info.PreferedLabelSide = horzRev ? CSAxisSide.FirstDown : CSAxisSide.FirstUp; // Top info = new CSAxisInformation(new CSLineID(vertAx, horzRev ? 0.75 : 0.25)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "TopDirection"; info.NameOfFirstUpSide = horzRev ? "Right" : "Left"; info.NameOfFirstDownSide = horzRev ? "Left" : "Right"; info.PreferedLabelSide = horzRev ? CSAxisSide.FirstDown : CSAxisSide.FirstUp; // Bottom info = new CSAxisInformation(new CSLineID(vertAx, horzRev ? 0.25 : 0.75)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "BottomDirection"; info.NameOfFirstUpSide = horzRev ? "Left" : "Right"; info.NameOfFirstDownSide = horzRev ? "Right" : "Left"; info.PreferedLabelSide = horzRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown; // Outer circle info = new CSAxisInformation(new CSLineID(horzAx, vertRev ? 0 : 1)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "OuterCircle"; info.NameOfFirstDownSide = vertRev ? "Outer" : "Inner"; info.NameOfFirstUpSide = vertRev ? "Inner" : "Outer"; info.PreferedLabelSide = vertRev ? CSAxisSide.FirstDown : CSAxisSide.FirstUp; info.IsShownByDefault = true; info.HasTitleByDefault = true; // Inner circle info = new CSAxisInformation(new CSLineID(horzAx, vertRev ? 1 : 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "Inner circle"; info.NameOfFirstDownSide = vertRev ? "Inner" : "Outer"; info.NameOfFirstUpSide = vertRev ? "Outer" : "Inner"; info.PreferedLabelSide = vertRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown; }
private GraphicsPath _enclosingPath = new GraphicsPath(); // with Winding also overlapping rectangles are selected public override void Paint(Graphics g, XYPlotLayer layer, CSAxisInformation styleInfo, AxisLineStyle axisstyle, bool useMinorTicks) { _cachedStyleID = styleInfo.Identifier; CSLineID styleID = styleInfo.Identifier; Scale raxis = styleID.ParallelAxisNumber==0 ? layer.XAxis : layer.YAxis; _enclosingPath.Reset(); _enclosingPath.FillMode = FillMode.Winding; // with Winding also overlapping rectangles are selected GraphicsPath helperPath = new GraphicsPath(); Matrix math = new Matrix(); Logical3D r0 = _cachedStyleID.Begin; Logical3D r1 = _cachedStyleID.End; SizeF layerSize = layer.Size; PointF outVector; Logical3D outer; float outerDistance = null==axisstyle? 0 : axisstyle.GetOuterDistance(styleInfo.PreferedLabelSide); float dist_x = outerDistance; // Distance from axis tick point to label float 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 = raxis.GetMinorTicksNormal(); ticks = raxis.GetMinorTicksAsVariant(); } else { relpositions = raxis.GetMajorTicksNormal(); ticks = raxis.GetMajorTicksAsVariant(); } IMeasuredLabelItem[] labels = _labelFormatting.GetMeasuredItems(g,_font,_stringFormat,ticks); float emSize = _font.SizeInPoints; for(int i=0;i<ticks.Length;i++) { double r = relpositions[i]; outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, styleInfo.PreferedLabelSide); PointF tickorg = layer.CoordinateSystem.GetNormalizedDirection(r0, r1, r, outer, out outVector); PointF tickend = tickorg; tickend.X += outVector.X * outerDistance; tickend.Y += outVector.Y * outerDistance; SizeF msize = labels[i].Size; PointF morg = tickend; if (_automaticRotationShift) { double alpha = _rotation * Math.PI / 180 - Math.Atan2(outVector.Y, outVector.X); double shift = msize.Height * 0.5 * Math.Abs(Math.Sin(alpha)) + (msize.Width + _font.SizeInPoints / 2) * 0.5 * Math.Abs(Math.Cos(alpha)); morg.X += (float)(outVector.X * shift); morg.Y += (float)(outVector.Y * shift); } else { morg.X += (float)(outVector.X * _font.SizeInPoints/3); } RectangleF mrect = new RectangleF(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 (this._rotation != 0) { math.Rotate((float)-this._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(this._backgroundStyle!=null) _backgroundStyle.Draw(g,new RectangleF(PointF.Empty,msize)); _brush.Rectangle = new RectangleF(PointF.Empty, msize); labels[i].Draw(g,_brush,new PointF(0,0)); g.Restore(gs); // Restore the graphics state helperPath.Reset(); helperPath.AddRectangle(new RectangleF(PointF.Empty, msize)); helperPath.Transform(math); _enclosingPath.AddPath(helperPath,true); } }
void CopyFrom(AxisStyle from) { this._styleID = from._styleID.Clone(); CopyWithoutIdFrom(from); this._cachedAxisInfo = from._cachedAxisInfo; }
/// <summary> /// Copy operation. /// </summary> /// <param name="obj">The AxisStyle to copy from</param> public bool CopyFrom(object obj) { if (object.ReferenceEquals(this, obj)) return true; var from = obj as AxisLineStyle; if (null == from) return false; using (var suspendToken = SuspendGetToken()) { ChildCopyToMember(ref _axisPen, from._axisPen); this._axisPosition = from._axisPosition; this._showFirstDownMajorTicks = from._showFirstDownMajorTicks; this._showFirstDownMinorTicks = from._showFirstDownMinorTicks; this._showFirstUpMajorTicks = from._showFirstUpMajorTicks; this._showFirstUpMinorTicks = from._showFirstUpMinorTicks; this._majorTickLength = from._majorTickLength; ChildCopyToMember(ref _majorTickPen, from._majorTickPen); this._minorTickLength = from._minorTickLength; ChildCopyToMember(ref _minorTickPen, from._minorTickPen); this._cachedAxisStyleInfo = from._cachedAxisStyleInfo; EhSelfChanged(EventArgs.Empty); suspendToken.Resume(); } return true; }
/// <summary> /// Paint the axis in the Graphics context. /// </summary> /// <param name="g">The graphics context painting to.</param> /// <param name="layer">The layer the axis belongs to.</param> /// <param name="styleInfo">The axis information of the axis to paint.</param> /// <param name="customTickSpacing">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> public void Paint(Graphics g, IPlotArea layer, CSAxisInformation styleInfo, TickSpacing customTickSpacing) { CSLineID styleID = styleInfo.Identifier; _cachedAxisStyleInfo = styleInfo; Scale axis = layer.Scales[styleID.ParallelAxisNumber]; TickSpacing ticking = null != customTickSpacing ? customTickSpacing : layer.Scales[styleID.ParallelAxisNumber].TickSpacing; Logical3D r0 = styleID.GetLogicalPoint(styleInfo.LogicalValueAxisOrg); Logical3D r1 = styleID.GetLogicalPoint(styleInfo.LogicalValueAxisEnd); layer.CoordinateSystem.DrawIsoline(g, _axisPen, r0, r1); Logical3D outer; // now the major ticks PointD2D outVector; double[] majorticks = ticking.GetMajorTicksNormal(axis); for (int i = 0; i < majorticks.Length; i++) { double r = majorticks[i]; if (_showFirstUpMajorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstUp); var tickorg = layer.CoordinateSystem.GetNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _majorTickLength; g.DrawLine(_majorTickPen, (PointF)tickorg, (PointF)tickend); } if (_showFirstDownMajorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstDown); var tickorg = layer.CoordinateSystem.GetNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _majorTickLength; g.DrawLine(_majorTickPen, (PointF)tickorg, (PointF)tickend); } } // now the major ticks double[] minorticks = ticking.GetMinorTicksNormal(axis); for (int i = 0; i < minorticks.Length; i++) { double r = minorticks[i]; if (_showFirstUpMinorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstUp); var tickorg = layer.CoordinateSystem.GetNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _minorTickLength; g.DrawLine(_minorTickPen, (PointF)tickorg, (PointF)tickend); } if (_showFirstDownMinorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstDown); var tickorg = layer.CoordinateSystem.GetNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _minorTickLength; g.DrawLine(_minorTickPen, (PointF)tickorg, (PointF)tickend); } } }
protected override void UpdateAxisInfo() { int horzAx = 0; int vertAx = 1; int deptAx = 2; if (null == _axisStyleInformation) _axisStyleInformation = new List<CSAxisInformation>(); else _axisStyleInformation.Clear(); CSAxisInformation info; // BottomFront info = new CSAxisInformation( Identifier: new CSLineID(horzAx, 0, 0), NameOfAxisStyle: "BottomFront", NameOfFirstDownSide: "Below", NameOfFirstUpSide: "Above", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // TopFront info = new CSAxisInformation( Identifier: new CSLineID(horzAx, 1, 0), NameOfAxisStyle: "TopFront", NameOfFirstDownSide: "Below", NameOfFirstUpSide: "Above", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstUp, PreferredTickSide: CSAxisSide.FirstUp, IsShownByDefault: true, HasTicksByDefault: false, HasLabelsByDefault: false, HasTitleByDefault: false); _axisStyleInformation.Add(info); // LeftFront info = new CSAxisInformation( Identifier: new CSLineID(vertAx, 0, 0), NameOfAxisStyle: "LeftFront", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // RightFront info = new CSAxisInformation( Identifier: new CSLineID(vertAx, 1, 0), NameOfAxisStyle: "RightFront", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstUp, PreferredTickSide: CSAxisSide.FirstUp, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: true ); _axisStyleInformation.Add(info); // BottomBack info = new CSAxisInformation( new CSLineID(horzAx, 0, 1), NameOfAxisStyle: "BottomBack", NameOfFirstDownSide: "Below", NameOfFirstUpSide: "Above", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // TopBack info = new CSAxisInformation( Identifier: new CSLineID(horzAx, 1, 1), NameOfAxisStyle: "TopBack", NameOfFirstDownSide: "Below", NameOfFirstUpSide: "Above", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstUp, PreferredTickSide: CSAxisSide.FirstUp, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: true ); _axisStyleInformation.Add(info); // LeftBack info = new CSAxisInformation( new CSLineID(vertAx, 0, 1), NameOfAxisStyle: "LeftBack", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // RightBack info = new CSAxisInformation( Identifier: new CSLineID(vertAx, 1, 1), NameOfAxisStyle: "RightBack", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstUp, PreferredTickSide: CSAxisSide.FirstUp, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: false ); _axisStyleInformation.Add(info); // BottomLeft info = new CSAxisInformation( Identifier: new CSLineID(deptAx, 0, 0), NameOfAxisStyle: "BottomLeft", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Below", NameOfSecondUpSide: "Above", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // TopLeft info = new CSAxisInformation( Identifier: new CSLineID(deptAx, 0, 1), NameOfAxisStyle: "TopLeft", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Below", NameOfSecondUpSide: "Above", PreferredLabelSide: CSAxisSide.FirstUp, PreferredTickSide: CSAxisSide.FirstUp, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: false ); _axisStyleInformation.Add(info); // BottomRight info = new CSAxisInformation( Identifier: new CSLineID(deptAx, 1, 0), NameOfAxisStyle: "BottomRight", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Below", NameOfSecondUpSide: "Above", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // TopRight info = new CSAxisInformation( Identifier: new CSLineID(deptAx, 1, 1), NameOfAxisStyle: "TopRight", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Below", NameOfSecondUpSide: "Above", PreferredLabelSide: CSAxisSide.FirstUp, PreferredTickSide: CSAxisSide.FirstUp, IsShownByDefault: true, HasTicksByDefault: true, HasLabelsByDefault: true, HasTitleByDefault: false ); _axisStyleInformation.Add(info); // XAxis: Y=0, Z=0 info = new CSAxisInformation( Identifier: CSLineID.FromPhysicalValue(horzAx, 0), NameOfAxisStyle: "YZ:0", NameOfFirstUpSide: "Above", NameOfFirstDownSide: "Below", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: false, HasTicksByDefault: false, HasLabelsByDefault: false, HasTitleByDefault: false ); _axisStyleInformation.Add(info); // YAxis: X=0, Z=0 info = new CSAxisInformation( Identifier: CSLineID.FromPhysicalValue(vertAx, 0), NameOfAxisStyle: "XZ:0", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: false, HasTicksByDefault: false, HasLabelsByDefault: false, HasTitleByDefault: false ); _axisStyleInformation.Add(info); // ZAxis: X=0,Y=0 info = new CSAxisInformation( CSLineID.FromPhysicalValue(deptAx, 0), NameOfAxisStyle: "XY:0", NameOfFirstDownSide: "Left", NameOfFirstUpSide: "Right", NameOfSecondDownSide: "Before", NameOfSecondUpSide: "Behind", PreferredLabelSide: CSAxisSide.FirstDown, PreferredTickSide: CSAxisSide.FirstDown, IsShownByDefault: false, HasTicksByDefault: false, HasLabelsByDefault: false, HasTitleByDefault: false); _axisStyleInformation.Add(info); }
public CSAxisInformation GetAxisStyleInformation(CSLineID styleID) { // search for the same axis first, then for the style with the nearest logical value double minDistance = double.MaxValue; CSAxisInformation nearestInfo = null; if (!styleID.UsePhysicalValueOtherFirst) { foreach (CSAxisInformation info in AxisStyles) { if (styleID.ParallelAxisNumber == info.Identifier.ParallelAxisNumber) { if (styleID == info.Identifier) { minDistance = 0; nearestInfo = info; break; } double dist = Math.Abs(styleID.LogicalValueOtherFirst - info.Identifier.LogicalValueOtherFirst); if (styleID.Is3DIdentifier && info.Identifier.Is3DIdentifier) { dist += Math.Abs(styleID.LogicalValueOtherSecond - info.Identifier.LogicalValueOtherSecond); } if (dist < minDistance) { minDistance = dist; nearestInfo = info; if (0 == minDistance) { break; // it can not be smaller than 0 } } } } } CSAxisInformation result; if (nearestInfo == null) { result = CSAxisInformation.NewWithDefaultValues(styleID); } else { result = nearestInfo.WithIdentifier(styleID); if (minDistance != 0) { result = result.WithNameOfAxisStyle(result.NameOfAxisStyle + string.Format(" ({0}% offs.)", minDistance * 100)); } } result = result.WithNamesForFirstUpAndDownSides( GetAxisSideName(result.Identifier, CSAxisSide.FirstUp), GetAxisSideName(result.Identifier, CSAxisSide.FirstDown)); if (Is3D) { result = result.WithNamesForSecondUpAndDownSides( GetAxisSideName(result.Identifier, CSAxisSide.SecondUp), GetAxisSideName(result.Identifier, CSAxisSide.SecondDown)); } return(result); }
/// <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); VectorD3D outVector; 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) { List<AltaxoVariant> filteredTicks = new List<AltaxoVariant>(); List<double> 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 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 (this._rotationZ != 0) math.RotationZDegreePrepend(this._rotationZ); if (this._rotationY != 0) math.RotationYDegreePrepend(this._rotationY); if (this._rotationX != 0) math.RotationXDegreePrepend(this._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 (this._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> /// Paint the axis in the Graphics context. /// </summary> /// <param name="g">The graphics context painting to.</param> /// <param name="layer">The layer the axis belongs to.</param> /// <param name="styleInfo">The axis information of the axis to paint.</param> public void Paint(Graphics g, XYPlotLayer layer, CSAxisInformation styleInfo) { CSLineID styleID = styleInfo.Identifier; _cachedAxisStyleInfo = styleInfo.Clone(); Scale axis = styleID.ParallelAxisNumber == 0 ? layer.XAxis : layer.YAxis; Logical3D r0 = styleID.Begin; Logical3D r1 = styleID.End; layer.CoordinateSystem.DrawIsoline(g, _axisPen, r0, r1); Logical3D outer; // now the major ticks PointF outVector; double[] majorticks = axis.GetMajorTicksNormal(); for(int i=0;i<majorticks.Length;i++) { double r = majorticks[i]; if(_showFirstUpMajorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber,CSAxisSide.FirstUp); PointF tickorg = layer.CoordinateSystem.GetNormalizedDirection(r0, r1, r, outer, out outVector); PointF tickend = tickorg; tickend.X += outVector.X * _majorTickLength; tickend.Y += outVector.Y * _majorTickLength; g.DrawLine(_majorTickPen,tickorg,tickend); } if(_showFirstDownMajorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstDown); PointF tickorg = layer.CoordinateSystem.GetNormalizedDirection(r0, r1, r, outer, out outVector); PointF tickend = tickorg; tickend.X += outVector.X * _majorTickLength; tickend.Y += outVector.Y * _majorTickLength; g.DrawLine(_majorTickPen,tickorg,tickend); } } // now the major ticks double[] minorticks = axis.GetMinorTicksNormal(); for(int i=0;i<minorticks.Length;i++) { double r = minorticks[i]; if(_showFirstUpMinorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstUp); PointF tickorg = layer.CoordinateSystem.GetNormalizedDirection(r0, r1, r, outer, out outVector); PointF tickend = tickorg; tickend.X += outVector.X * _minorTickLength; tickend.Y += outVector.Y * _minorTickLength; g.DrawLine(_minorTickPen,tickorg,tickend); } if(_showFirstDownMinorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstDown); PointF tickorg = layer.CoordinateSystem.GetNormalizedDirection(r0, r1, r, outer, out outVector); PointF tickend = tickorg; tickend.X += outVector.X * _minorTickLength; tickend.Y += outVector.Y * _minorTickLength; g.DrawLine(_minorTickPen,tickorg,tickend); } } }
public virtual bool CopyFrom(object obj) { if (object.ReferenceEquals(this, obj)) return true; var from = obj as AxisLabelStyle; if (null == from) return false; using (var suspendToken = SuspendGetToken()) { _cachedAxisStyleInfo = from._cachedAxisStyleInfo; _font = from._font; CopyHelper.Copy(ref _stringFormat, from._stringFormat); _horizontalAlignment = from._horizontalAlignment; _verticalAlignment = from._verticalAlignment; ChildCopyToMember(ref _brush, from._brush); _automaticRotationShift = from._automaticRotationShift; _xOffset = from._xOffset; _yOffset = from._yOffset; _rotation = from._rotation; ChildCopyToMember(ref _backgroundStyle, from._backgroundStyle); ChildCopyToMember(ref _labelFormatting, from._labelFormatting); _labelSide = from._labelSide; _prefixText = from._prefixText; _postfixText = from._postfixText; ChildCopyToMember(ref _suppressedLabels, from._suppressedLabels); EhSelfChanged(EventArgs.Empty); suspendToken.Resume(); } return true; }
private GraphicsPath _enclosingPath = new GraphicsPath(); // with Winding also overlapping rectangles are selected /// <summary>Predicts the side, where the label will be shown using the given axis information.</summary> /// <param name="axisInformation">The axis information.</param> /// <returns>The side of the axis where the label will be shown.</returns> public virtual CSAxisSide PredictLabelSide(CSAxisInformation axisInformation) { return null != _labelSide ? _labelSide.Value : axisInformation.PreferredLabelSide; }
/// <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> /// 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 GraphicsPath helperPath = new GraphicsPath(); Matrix math = new Matrix(); Logical3D r0 = styleID.GetLogicalPoint(styleInfo.LogicalValueAxisOrg); Logical3D r1 = styleID.GetLogicalPoint(styleInfo.LogicalValueAxisEnd); PointD2D outVector; 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) { List<AltaxoVariant> filteredTicks = new List<AltaxoVariant>(); List<double> 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 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); } RectangleD2D 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 (this._rotation != 0) { math.Rotate((float)-this._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 (this._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 AxisStyleControllerConditionalGlue(CSAxisInformation axisInfo, AxisStyleCollection axisStyleCollection) { _doc = axisStyleCollection; AxisInformation = axisInfo; InternalInitialize(); }
public bool CopyFrom(object obj) { var from = obj as AxisStyle; if (null == from) return false; if (!object.ReferenceEquals(this, from)) { this._styleID = from._styleID; // immutable this._cachedAxisInfo = from._cachedAxisInfo; // attention - have to appear _before_ CopyWithoutIdFrom, since the _cachedAxisInfo is used when cloning AxisLineStyle! CopyWithoutIdFrom(from); } return true; }
private GraphicsPath _enclosingPath = new GraphicsPath(); // with Winding also overlapping rectangles are selected /// <summary>Predicts the side, where the label will be shown using the given axis information.</summary> /// <param name="axisInformation">The axis information.</param> /// <returns>The side of the axis where the label will be shown.</returns> public virtual CSAxisSide PredictLabelSide(CSAxisInformation axisInformation) { return(null != _labelSide ? _labelSide.Value : axisInformation.PreferredLabelSide); }
protected override void UpdateAxisInfo() { int horzAx; int vertAx; bool vertRev; bool horzRev; if (_isXYInterchanged) { horzAx = 1; vertAx = 0; vertRev = _isXreverse; horzRev = _isYreverse; } else { horzAx = 0; vertAx = 1; vertRev = _isYreverse; horzRev = _isXreverse; } if (null != _axisStyleInformation) { _axisStyleInformation.Clear(); } else { _axisStyleInformation = new List <CSAxisInformation>(); } CSAxisInformation info; // Right info = new CSAxisInformation( Identifier: new CSLineID(vertAx, 0), NameOfAxisStyle: "RightDirection", NameOfFirstUpSide: horzRev ? "Below" : "Above", NameOfFirstDownSide: horzRev ? "Above" : "Below", PreferredLabelSide: horzRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown, IsShownByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // Left info = new CSAxisInformation( Identifier: new CSLineID(vertAx, 0.5), NameOfAxisStyle: "LeftDirection", NameOfFirstUpSide: horzRev ? "Above" : "Below", NameOfFirstDownSide: horzRev ? "Below" : "Above", PreferredLabelSide: horzRev ? CSAxisSide.FirstDown : CSAxisSide.FirstUp); _axisStyleInformation.Add(info); // Top info = new CSAxisInformation( Identifier: new CSLineID(vertAx, horzRev ? 0.75 : 0.25), NameOfAxisStyle: "TopDirection", NameOfFirstUpSide: horzRev ? "Right" : "Left", NameOfFirstDownSide: horzRev ? "Left" : "Right", PreferredLabelSide: horzRev ? CSAxisSide.FirstDown : CSAxisSide.FirstUp); _axisStyleInformation.Add(info); // Bottom info = new CSAxisInformation( Identifier: new CSLineID(vertAx, horzRev ? 0.25 : 0.75), NameOfAxisStyle: "BottomDirection", NameOfFirstUpSide: horzRev ? "Left" : "Right", NameOfFirstDownSide: horzRev ? "Right" : "Left", PreferredLabelSide: horzRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown); _axisStyleInformation.Add(info); // Outer circle info = new CSAxisInformation( Identifier: new CSLineID(horzAx, vertRev ? 0 : 1), NameOfAxisStyle: "OuterCircle", NameOfFirstDownSide: vertRev ? "Outer" : "Inner", NameOfFirstUpSide: vertRev ? "Inner" : "Outer", PreferredLabelSide: vertRev ? CSAxisSide.FirstDown : CSAxisSide.FirstUp, IsShownByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // Inner circle info = new CSAxisInformation( Identifier: new CSLineID(horzAx, vertRev ? 1 : 0), NameOfAxisStyle: "Inner circle", NameOfFirstDownSide: vertRev ? "Inner" : "Outer", NameOfFirstUpSide: vertRev ? "Outer" : "Inner", PreferredLabelSide: vertRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown); _axisStyleInformation.Add(info); }
public virtual bool CopyFrom(object obj) { if (object.ReferenceEquals(this, obj)) return true; var from = obj as AxisLabelStyle; if (null == from) return false; using (var suspendToken = SuspendGetToken()) { _cachedAxisStyleInfo = from._cachedAxisStyleInfo; _font = from._font; _alignmentX = from._alignmentX; _alignmentY = from._alignmentY; _alignmentZ = from._alignmentZ; _brush = from._brush; _automaticRotationShift = from._automaticRotationShift; _offsetX = from._offsetX; _offsetY = from._offsetY; _offsetZ = from._offsetZ; _rotationX = from._rotationX; _rotationY = from._rotationY; _rotationZ = from._rotationZ; ChildCopyToMember(ref _backgroundStyle, from._backgroundStyle); ChildCopyToMember(ref _labelFormatting, from._labelFormatting); _labelSide = from._labelSide; _prefixText = from._prefixText; _postfixText = from._postfixText; ChildCopyToMember(ref _suppressedLabels, from._suppressedLabels); EhSelfChanged(EventArgs.Empty); suspendToken.Resume(); } return true; }
public CSAxisInformation GetAxisStyleInformation(CSLineID styleID) { if (_axisStyleInformation == null || _axisStyleInformation.Count == 0) UpdateAxisInfo(); // search for the same axis first, then for the style with the nearest logical value double minDistance = double.MaxValue; CSAxisInformation nearestInfo = null; foreach (CSAxisInformation info in this._axisStyleInformation) { if (styleID.ParallelAxisNumber == info.Identifier.ParallelAxisNumber) { if (styleID == info.Identifier) { minDistance = 0; nearestInfo = info; break; } double dist = Math.Abs(styleID.LogicalValueOtherFirst - info.Identifier.LogicalValueOtherFirst); if(styleID.Is3DIdentifier && info.Identifier.Is3DIdentifier) dist += Math.Abs(styleID.LogicalValueOtherSecond - info.Identifier.LogicalValueOtherSecond); if (dist < minDistance) { minDistance = dist; nearestInfo = info; if (0 == minDistance) break; // it can not be smaller than 0 } } } CSAxisInformation result = new CSAxisInformation(styleID); if (nearestInfo == null) { result.SetDefaultValues(); } else { result.CopyWithoutIdentifierFrom(nearestInfo); if(minDistance!=0) result.NameOfAxisStyle += string.Format(" ({0}% offs.)",minDistance*100); } return result; }
protected override void UpdateAxisInfo() { int horzAx=0; int vertAx=1; int deptAx=2; if (null == _axisStyleInformation) _axisStyleInformation = new List<CSAxisInformation>(); else _axisStyleInformation.Clear(); CSAxisInformation info; // BottomFront info = new CSAxisInformation(new CSLineID(horzAx, 0, 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "BottomFront"; info.NameOfFirstDownSide = "Below"; info.NameOfFirstUpSide = "Above"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstDown; info.IsShownByDefault = true; info.HasTitleByDefault = true; // TopFront info = new CSAxisInformation(new CSLineID(horzAx, 1 , 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "TopFront"; info.NameOfFirstDownSide = "Below"; info.NameOfFirstUpSide = "Above"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstUp; info.IsShownByDefault = true; // LeftFront info = new CSAxisInformation(new CSLineID(vertAx,0,0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "LeftFront"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstDown; info.IsShownByDefault = true; info.HasTitleByDefault = true; // RightFront info = new CSAxisInformation(new CSLineID(vertAx, 1 , 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "RightFront"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstUp; info.IsShownByDefault = true; // BottomBack info = new CSAxisInformation(new CSLineID(horzAx, 0, 1)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "BottomBack"; info.NameOfFirstDownSide = "Below"; info.NameOfFirstUpSide = "Above"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstDown; info.IsShownByDefault = true; info.HasTitleByDefault = true; // TopBack info = new CSAxisInformation(new CSLineID(horzAx, 1, 1)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "TopBack"; info.NameOfFirstDownSide = "Below"; info.NameOfFirstUpSide = "Above"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstUp; info.IsShownByDefault = true; // LeftBack info = new CSAxisInformation(new CSLineID(vertAx, 0, 1)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "LeftBack"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstDown; info.IsShownByDefault = true; info.HasTitleByDefault = true; // RightBack info = new CSAxisInformation(new CSLineID(vertAx, 1, 1)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "RightBack"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstUp; info.IsShownByDefault = true; // BottomLeft info = new CSAxisInformation(new CSLineID(deptAx, 0, 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "BottomLeft"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Below"; info.NameOfSecondUpSide = "Above"; info.PreferedLabelSide = CSAxisSide.FirstDown; info.IsShownByDefault = true; info.HasTitleByDefault = true; // TopLeft info = new CSAxisInformation(new CSLineID(deptAx, 0, 1)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "TopLeft"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Below"; info.NameOfSecondUpSide = "Above"; info.PreferedLabelSide = CSAxisSide.FirstUp; info.IsShownByDefault = true; // BottomRight info = new CSAxisInformation(new CSLineID(deptAx, 1, 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "BottomRight"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Below"; info.NameOfSecondUpSide = "Above"; info.PreferedLabelSide = CSAxisSide.FirstDown; info.IsShownByDefault = true; info.HasTitleByDefault = true; // TopRight info = new CSAxisInformation(new CSLineID(deptAx, 1, 1)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "TopRight"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Below"; info.NameOfSecondUpSide = "Above"; info.PreferedLabelSide = CSAxisSide.FirstUp; info.IsShownByDefault = true; // XAxis: Y=0, Z=0 info = new CSAxisInformation(CSLineID.FromPhysicalValue(horzAx, 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "YZ=0"; info.NameOfFirstUpSide = "Above"; info.NameOfFirstDownSide = "Below"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstDown; // YAxis: X=0, Z=0 info = new CSAxisInformation(CSLineID.FromPhysicalValue(vertAx, 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "XZ=0"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstDown; // ZAxis: X=0,Y=0 info = new CSAxisInformation(CSLineID.FromPhysicalValue(deptAx, 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "XY=0"; info.NameOfFirstDownSide = "Left"; info.NameOfFirstUpSide = "Right"; info.NameOfSecondDownSide = "Before"; info.NameOfSecondUpSide = "Behind"; info.PreferedLabelSide = CSAxisSide.FirstDown; }
protected override void UpdateAxisInfo() { int horzAx; int vertAx; bool vertRev; bool horzRev; if (_isXYInterchanged) { horzAx = 1; vertAx = 0; vertRev = _isXreverse; horzRev = _isYreverse; } else { horzAx = 0; vertAx = 1; vertRev = _isYreverse; horzRev = _isXreverse; } if (null != _axisStyleInformation) { _axisStyleInformation.Clear(); } else { _axisStyleInformation = new List <CSAxisInformation>(); } CSAxisInformation info; // Right info = new CSAxisInformation(new CSLineID(vertAx, 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "RightDirection"; info.NameOfFirstUpSide = horzRev ? "Below" : "Above"; info.NameOfFirstDownSide = horzRev ? "Above" : "Below"; info.PreferedLabelSide = horzRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown; info.IsShownByDefault = true; info.HasTitleByDefault = true; // Left info = new CSAxisInformation(new CSLineID(vertAx, 0.5)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "LeftDirection"; info.NameOfFirstUpSide = horzRev ? "Above" : "Below"; info.NameOfFirstDownSide = horzRev ? "Below" : "Above"; info.PreferedLabelSide = horzRev ? CSAxisSide.FirstDown : CSAxisSide.FirstUp; // Top info = new CSAxisInformation(new CSLineID(vertAx, horzRev ? 0.75 : 0.25)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "TopDirection"; info.NameOfFirstUpSide = horzRev ? "Right" : "Left"; info.NameOfFirstDownSide = horzRev ? "Left" : "Right"; info.PreferedLabelSide = horzRev ? CSAxisSide.FirstDown : CSAxisSide.FirstUp; // Bottom info = new CSAxisInformation(new CSLineID(vertAx, horzRev ? 0.25 : 0.75)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "BottomDirection"; info.NameOfFirstUpSide = horzRev ? "Left" : "Right"; info.NameOfFirstDownSide = horzRev ? "Right" : "Left"; info.PreferedLabelSide = horzRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown; // Outer circle info = new CSAxisInformation(new CSLineID(horzAx, vertRev ? 0 : 1)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "OuterCircle"; info.NameOfFirstDownSide = vertRev ? "Outer" : "Inner"; info.NameOfFirstUpSide = vertRev ? "Inner" : "Outer"; info.PreferedLabelSide = vertRev ? CSAxisSide.FirstDown : CSAxisSide.FirstUp; info.IsShownByDefault = true; info.HasTitleByDefault = true; // Inner circle info = new CSAxisInformation(new CSLineID(horzAx, vertRev ? 1 : 0)); _axisStyleInformation.Add(info); info.NameOfAxisStyle = "Inner circle"; info.NameOfFirstDownSide = vertRev ? "Inner" : "Outer"; info.NameOfFirstUpSide = vertRev ? "Outer" : "Inner"; info.PreferedLabelSide = vertRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown; }
protected override void UpdateAxisInfo() { int horzAx; int vertAx; bool vertRev; bool horzRev; if (_isXYInterchanged) { horzAx = 1; vertAx = 0; vertRev = _isXreverse; horzRev = _isYreverse; } else { horzAx = 0; vertAx = 1; vertRev = _isYreverse; horzRev = _isXreverse; } if (null == _axisStyleInformation) { _axisStyleInformation = new List <CSAxisInformation>(); } else { _axisStyleInformation.Clear(); } CSAxisInformation info; CSLineID lineID; // Left lineID = new CSLineID(vertAx, horzRev ? 1 : 0); info = new CSAxisInformation( Identifier: lineID, NameOfAxisStyle: GetAxisName(lineID), NameOfFirstDownSide: GetAxisSideName(lineID, CSAxisSide.FirstDown), NameOfFirstUpSide: GetAxisSideName(lineID, CSAxisSide.FirstUp), PreferredLabelSide: horzRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown, IsShownByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // Right lineID = new CSLineID(vertAx, horzRev ? 0 : 1); info = new CSAxisInformation( Identifier: lineID, NameOfAxisStyle: GetAxisName(lineID), NameOfFirstDownSide: GetAxisSideName(lineID, CSAxisSide.FirstDown), NameOfFirstUpSide: GetAxisSideName(lineID, CSAxisSide.FirstUp), PreferredLabelSide: horzRev ? CSAxisSide.FirstDown : CSAxisSide.FirstUp, IsShownByDefault: false, HasTitleByDefault: false); _axisStyleInformation.Add(info); // Bottom lineID = new CSLineID(horzAx, vertRev ? 1 : 0); info = new CSAxisInformation( Identifier: lineID, NameOfAxisStyle: GetAxisName(lineID), NameOfFirstDownSide: GetAxisSideName(lineID, CSAxisSide.FirstDown), NameOfFirstUpSide: GetAxisSideName(lineID, CSAxisSide.FirstUp), PreferredLabelSide: vertRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown, IsShownByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // Top lineID = new CSLineID(horzAx, vertRev ? 0 : 1); info = new CSAxisInformation( Identifier: lineID, NameOfAxisStyle: GetAxisName(lineID), NameOfFirstDownSide: GetAxisSideName(lineID, CSAxisSide.FirstDown), NameOfFirstUpSide: GetAxisSideName(lineID, CSAxisSide.FirstUp), PreferredLabelSide: vertRev ? CSAxisSide.FirstDown : CSAxisSide.FirstUp, IsShownByDefault: false, HasTitleByDefault: false); _axisStyleInformation.Add(info); // Y=0 lineID = CSLineID.FromPhysicalValue(horzAx, 0); info = new CSAxisInformation( Identifier: lineID, NameOfAxisStyle: GetAxisName(lineID), NameOfFirstDownSide: GetAxisSideName(lineID, CSAxisSide.FirstDown), NameOfFirstUpSide: GetAxisSideName(lineID, CSAxisSide.FirstUp), PreferredLabelSide: vertRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown, IsShownByDefault: false, HasTitleByDefault: false); _axisStyleInformation.Add(info); // X=0 lineID = CSLineID.FromPhysicalValue(vertAx, 0); info = new CSAxisInformation( Identifier: lineID, NameOfAxisStyle: GetAxisName(lineID), NameOfFirstDownSide: GetAxisSideName(lineID, CSAxisSide.FirstDown), NameOfFirstUpSide: GetAxisSideName(lineID, CSAxisSide.FirstUp), PreferredLabelSide: horzRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown, IsShownByDefault: false, HasTitleByDefault: false); _axisStyleInformation.Add(info); }
/// <summary> /// Copy operation. /// </summary> /// <param name="from">The AxisStyle to copy from</param> public void CopyFrom(AxisLineStyle from) { if (_axisPen != null) WireEventChain(false); this._axisPen = null == from._axisPen ? null : (PenX)from._axisPen.Clone(); this._axisPosition = from._axisPosition; this._showFirstDownMajorTicks = from._showFirstDownMajorTicks; this._showFirstDownMinorTicks = from._showFirstDownMinorTicks; this._showFirstUpMajorTicks = from._showFirstUpMajorTicks; this._showFirstUpMinorTicks = from._showFirstUpMinorTicks; this._majorTickLength = from._majorTickLength; this._majorTickPen = null==from._majorTickPen ? null : (PenX)from._majorTickPen; this._minorTickLength = from._minorTickLength; this._minorTickPen = (null==from._minorTickPen) ? null : (PenX)from._minorTickPen; this._cachedAxisStyleInfo = from._cachedAxisStyleInfo; this._parent = from._parent; // Rewire the event chain WireEventChain(true); }
/// <summary> /// Paint the axis in the Graphics context. /// </summary> /// <param name="g">The graphics context painting to.</param> /// <param name="layer">The layer the axis belongs to.</param> /// <param name="styleInfo">The axis information of the axis to paint.</param> /// <param name="customTickSpacing">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> public void Paint(IGraphicsContext3D g, IPlotArea layer, CSAxisInformation styleInfo, TickSpacing customTickSpacing) { CSLineID styleID = styleInfo.Identifier; _cachedAxisStyleInfo = styleInfo; Scale axis = layer.Scales[styleID.ParallelAxisNumber]; TickSpacing ticking = null != customTickSpacing ? customTickSpacing : layer.Scales[styleID.ParallelAxisNumber].TickSpacing; Logical3D r0 = styleID.GetLogicalPoint(styleInfo.LogicalValueAxisOrg); Logical3D r1 = styleID.GetLogicalPoint(styleInfo.LogicalValueAxisEnd); var sweepPath = layer.CoordinateSystem.GetIsoline(r0, r1); g.DrawLine(_axisPen, sweepPath); _cachedMainLinePointsUsedForHitTesting = sweepPath.Points.ToArray(); var majorTickLinesUsedForHitTesting = new List<LineD3D>(); var minorTickLinesUsedForHitTesting = new List<LineD3D>(); Logical3D outer; // now the major ticks VectorD3D outVector; double[] majorticks = ticking.GetMajorTicksNormal(axis); for (int i = 0; i < majorticks.Length; i++) { double r = majorticks[i]; if (_showFirstUpMajorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstUp); var tickorg = layer.CoordinateSystem.GetPositionAndNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _majorTickLength; g.DrawLine(_majorTickPen, tickorg, tickend); majorTickLinesUsedForHitTesting.Add(new LineD3D(tickorg, tickend)); } if (_showFirstDownMajorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstDown); var tickorg = layer.CoordinateSystem.GetPositionAndNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _majorTickLength; g.DrawLine(_majorTickPen, tickorg, tickend); majorTickLinesUsedForHitTesting.Add(new LineD3D(tickorg, tickend)); } if (_showSecondUpMajorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.SecondUp); var tickorg = layer.CoordinateSystem.GetPositionAndNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _majorTickLength; g.DrawLine(_majorTickPen, tickorg, tickend); majorTickLinesUsedForHitTesting.Add(new LineD3D(tickorg, tickend)); } if (_showSecondDownMajorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.SecondDown); var tickorg = layer.CoordinateSystem.GetPositionAndNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _majorTickLength; g.DrawLine(_majorTickPen, tickorg, tickend); majorTickLinesUsedForHitTesting.Add(new LineD3D(tickorg, tickend)); } } // now the major ticks double[] minorticks = ticking.GetMinorTicksNormal(axis); for (int i = 0; i < minorticks.Length; i++) { double r = minorticks[i]; if (_showFirstUpMinorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstUp); var tickorg = layer.CoordinateSystem.GetPositionAndNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _minorTickLength; g.DrawLine(_minorTickPen, tickorg, tickend); minorTickLinesUsedForHitTesting.Add(new LineD3D(tickorg, tickend)); } if (_showFirstDownMinorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstDown); var tickorg = layer.CoordinateSystem.GetPositionAndNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _minorTickLength; g.DrawLine(_minorTickPen, tickorg, tickend); minorTickLinesUsedForHitTesting.Add(new LineD3D(tickorg, tickend)); } if (_showSecondUpMinorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.SecondUp); var tickorg = layer.CoordinateSystem.GetPositionAndNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _minorTickLength; g.DrawLine(_minorTickPen, tickorg, tickend); minorTickLinesUsedForHitTesting.Add(new LineD3D(tickorg, tickend)); } if (_showSecondDownMinorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.SecondDown); var tickorg = layer.CoordinateSystem.GetPositionAndNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _minorTickLength; g.DrawLine(_minorTickPen, tickorg, tickend); minorTickLinesUsedForHitTesting.Add(new LineD3D(tickorg, tickend)); } } _cachedMajorTickLinesUsedForHitTesting = majorTickLinesUsedForHitTesting.ToArray(); _cachedMinorTickLinesUsedForHitTesting = minorTickLinesUsedForHitTesting.ToArray(); }
/// <summary> /// Paint the axis in the Graphics context. /// </summary> /// <param name="g">The graphics context painting to.</param> /// <param name="layer">The layer the axis belongs to.</param> /// <param name="styleInfo">The axis information of the axis to paint.</param> /// <param name="customTickSpacing">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> public void Paint(IGraphicsContext3D g, IPlotArea layer, CSAxisInformation styleInfo, TickSpacing customTickSpacing) { CSLineID styleID = styleInfo.Identifier; _cachedAxisStyleInfo = styleInfo; Scale axis = layer.Scales[styleID.ParallelAxisNumber]; TickSpacing ticking = null != customTickSpacing ? customTickSpacing : layer.Scales[styleID.ParallelAxisNumber].TickSpacing; Logical3D r0 = styleID.GetLogicalPoint(styleInfo.LogicalValueAxisOrg); Logical3D r1 = styleID.GetLogicalPoint(styleInfo.LogicalValueAxisEnd); var sweepPath = layer.CoordinateSystem.GetIsoline(r0, r1); g.DrawLine(_axisPen, sweepPath); _cachedMainLinePointsUsedForHitTesting = sweepPath.Points.ToArray(); var majorTickLinesUsedForHitTesting = new List <LineD3D>(); var minorTickLinesUsedForHitTesting = new List <LineD3D>(); Logical3D outer; // now the major ticks VectorD3D outVector; double[] majorticks = ticking.GetMajorTicksNormal(axis); for (int i = 0; i < majorticks.Length; i++) { double r = majorticks[i]; if (_showFirstUpMajorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstUp); var tickorg = layer.CoordinateSystem.GetPositionAndNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _majorTickLength; g.DrawLine(_majorTickPen, tickorg, tickend); majorTickLinesUsedForHitTesting.Add(new LineD3D(tickorg, tickend)); } if (_showFirstDownMajorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstDown); var tickorg = layer.CoordinateSystem.GetPositionAndNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _majorTickLength; g.DrawLine(_majorTickPen, tickorg, tickend); majorTickLinesUsedForHitTesting.Add(new LineD3D(tickorg, tickend)); } if (_showSecondUpMajorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.SecondUp); var tickorg = layer.CoordinateSystem.GetPositionAndNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _majorTickLength; g.DrawLine(_majorTickPen, tickorg, tickend); majorTickLinesUsedForHitTesting.Add(new LineD3D(tickorg, tickend)); } if (_showSecondDownMajorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.SecondDown); var tickorg = layer.CoordinateSystem.GetPositionAndNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _majorTickLength; g.DrawLine(_majorTickPen, tickorg, tickend); majorTickLinesUsedForHitTesting.Add(new LineD3D(tickorg, tickend)); } } // now the major ticks double[] minorticks = ticking.GetMinorTicksNormal(axis); for (int i = 0; i < minorticks.Length; i++) { double r = minorticks[i]; if (_showFirstUpMinorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstUp); var tickorg = layer.CoordinateSystem.GetPositionAndNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _minorTickLength; g.DrawLine(_minorTickPen, tickorg, tickend); minorTickLinesUsedForHitTesting.Add(new LineD3D(tickorg, tickend)); } if (_showFirstDownMinorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstDown); var tickorg = layer.CoordinateSystem.GetPositionAndNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _minorTickLength; g.DrawLine(_minorTickPen, tickorg, tickend); minorTickLinesUsedForHitTesting.Add(new LineD3D(tickorg, tickend)); } if (_showSecondUpMinorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.SecondUp); var tickorg = layer.CoordinateSystem.GetPositionAndNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _minorTickLength; g.DrawLine(_minorTickPen, tickorg, tickend); minorTickLinesUsedForHitTesting.Add(new LineD3D(tickorg, tickend)); } if (_showSecondDownMinorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.SecondDown); var tickorg = layer.CoordinateSystem.GetPositionAndNormalizedDirection(r0, r1, r, outer, out outVector); var tickend = tickorg + outVector * _minorTickLength; g.DrawLine(_minorTickPen, tickorg, tickend); minorTickLinesUsedForHitTesting.Add(new LineD3D(tickorg, tickend)); } } _cachedMajorTickLinesUsedForHitTesting = majorTickLinesUsedForHitTesting.ToArray(); _cachedMinorTickLinesUsedForHitTesting = minorTickLinesUsedForHitTesting.ToArray(); }
/// <summary> /// Paint the axis in the Graphics context. /// </summary> /// <param name="g">The graphics context painting to.</param> /// <param name="layer">The layer the axis belongs to.</param> /// <param name="styleInfo">The axis information of the axis to paint.</param> public void Paint(Graphics g, XYPlotLayer layer, CSAxisInformation styleInfo) { CSLineID styleID = styleInfo.Identifier; _cachedAxisStyleInfo = styleInfo.Clone(); Scale axis = styleID.ParallelAxisNumber == 0 ? layer.XAxis : layer.YAxis; Logical3D r0 = styleID.Begin; Logical3D r1 = styleID.End; layer.CoordinateSystem.DrawIsoline(g, _axisPen, r0, r1); Logical3D outer; // now the major ticks PointF outVector; double[] majorticks = axis.GetMajorTicksNormal(); for (int i = 0; i < majorticks.Length; i++) { double r = majorticks[i]; if (_showFirstUpMajorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstUp); PointF tickorg = layer.CoordinateSystem.GetNormalizedDirection(r0, r1, r, outer, out outVector); PointF tickend = tickorg; tickend.X += outVector.X * _majorTickLength; tickend.Y += outVector.Y * _majorTickLength; g.DrawLine(_majorTickPen, tickorg, tickend); } if (_showFirstDownMajorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstDown); PointF tickorg = layer.CoordinateSystem.GetNormalizedDirection(r0, r1, r, outer, out outVector); PointF tickend = tickorg; tickend.X += outVector.X * _majorTickLength; tickend.Y += outVector.Y * _majorTickLength; g.DrawLine(_majorTickPen, tickorg, tickend); } } // now the major ticks double[] minorticks = axis.GetMinorTicksNormal(); for (int i = 0; i < minorticks.Length; i++) { double r = minorticks[i]; if (_showFirstUpMinorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstUp); PointF tickorg = layer.CoordinateSystem.GetNormalizedDirection(r0, r1, r, outer, out outVector); PointF tickend = tickorg; tickend.X += outVector.X * _minorTickLength; tickend.Y += outVector.Y * _minorTickLength; g.DrawLine(_minorTickPen, tickorg, tickend); } if (_showFirstDownMinorTicks) { outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, CSAxisSide.FirstDown); PointF tickorg = layer.CoordinateSystem.GetNormalizedDirection(r0, r1, r, outer, out outVector); PointF tickend = tickorg; tickend.X += outVector.X * _minorTickLength; tickend.Y += outVector.Y * _minorTickLength; g.DrawLine(_minorTickPen, tickorg, tickend); } } }
public void Paint(Graphics g, XYPlotLayer layer) { // update the logical values of the physical axes before if (_styleID.UsePhysicalValueOtherFirst) { // then update the logical value of this identifier double logicalValue = layer.Scales(_styleID.AxisNumberOtherFirst).PhysicalVariantToNormal(_styleID.PhysicalValueOtherFirst); _styleID.LogicalValueOtherFirst = logicalValue; } if (_styleID.UsePhysicalValueOtherSecond) { // then update the logical value of this identifier double logicalValue = layer.Scales(_styleID.AxisNumberOtherSecond).PhysicalVariantToNormal(_styleID.PhysicalValueOtherSecond); _styleID.LogicalValueOtherSecond = logicalValue; } int axisnumber = _styleID.ParallelAxisNumber; CSAxisInformation styleinfo = layer.CoordinateSystem.GetAxisStyleInformation(_styleID); _cachedAxisInfo = styleinfo; if (ShowAxisLine) _axisLineStyle.Paint(g, layer, styleinfo); if (ShowMajorLabels) this._majorLabelStyle.Paint(g, layer, styleinfo, _axisLineStyle, false); if (ShowMinorLabels) this._minorLabelStyle.Paint(g, layer, styleinfo, _axisLineStyle, true); if (ShowTitle) _axisTitle.Paint(g, layer); }
public CSAxisInformation GetAxisStyleInformation(CSLineID styleID) { if (_axisStyleInformation == null || _axisStyleInformation.Count == 0) UpdateAxisInfo(); // search for the same axis first, then for the style with the nearest logical value double minDistance = double.MaxValue; CSAxisInformation nearestInfo = null; if (!styleID.UsePhysicalValueOtherFirst) { foreach (CSAxisInformation info in this._axisStyleInformation) { if (styleID.ParallelAxisNumber == info.Identifier.ParallelAxisNumber) { if (styleID == info.Identifier) { minDistance = 0; nearestInfo = info; break; } double dist = Math.Abs(styleID.LogicalValueOtherFirst - info.Identifier.LogicalValueOtherFirst); if (styleID.Is3DIdentifier && info.Identifier.Is3DIdentifier) dist += Math.Abs(styleID.LogicalValueOtherSecond - info.Identifier.LogicalValueOtherSecond); if (dist < minDistance) { minDistance = dist; nearestInfo = info; if (0 == minDistance) break; // it can not be smaller than 0 } } } } CSAxisInformation result = new CSAxisInformation(styleID); if (nearestInfo == null) { result = CSAxisInformation.NewWithDefaultValues(styleID); } else { result = nearestInfo.WithIdentifier(styleID); if (minDistance != 0) { result = result.WithNameOfAxisStyle(result.NameOfAxisStyle + string.Format(" ({0}% offs.)", minDistance * 100)); } } result = result.WithNamesForFirstUpAndDownSides( GetAxisSideName(result.Identifier, CSAxisSide.FirstUp), GetAxisSideName(result.Identifier, CSAxisSide.FirstDown)); if (Is3D) { result = result.WithNamesForSecondUpAndDownSides( GetAxisSideName(result.Identifier, CSAxisSide.SecondUp), GetAxisSideName(result.Identifier, CSAxisSide.SecondDown)); } return result; }
protected override void UpdateAxisInfo() { int horzAx; int vertAx; bool vertRev; bool horzRev; if (_isXYInterchanged) { horzAx = 1; vertAx = 0; vertRev = _isXreverse; horzRev = _isYreverse; } else { horzAx = 0; vertAx = 1; vertRev = _isYreverse; horzRev = _isXreverse; } if (null == _axisStyleInformation) _axisStyleInformation = new List<CSAxisInformation>(); else _axisStyleInformation.Clear(); CSAxisInformation info; CSLineID lineID; // Left lineID = new CSLineID(vertAx, horzRev ? 1 : 0); info = new CSAxisInformation( Identifier: lineID, NameOfAxisStyle: GetAxisName(lineID), NameOfFirstDownSide: GetAxisSideName(lineID, CSAxisSide.FirstDown), NameOfFirstUpSide: GetAxisSideName(lineID, CSAxisSide.FirstUp), PreferredLabelSide: horzRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown, IsShownByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // Right lineID = new CSLineID(vertAx, horzRev ? 0 : 1); info = new CSAxisInformation( Identifier: lineID, NameOfAxisStyle: GetAxisName(lineID), NameOfFirstDownSide: GetAxisSideName(lineID, CSAxisSide.FirstDown), NameOfFirstUpSide: GetAxisSideName(lineID, CSAxisSide.FirstUp), PreferredLabelSide: horzRev ? CSAxisSide.FirstDown : CSAxisSide.FirstUp, IsShownByDefault: false, HasTitleByDefault: false); _axisStyleInformation.Add(info); // Bottom lineID = new CSLineID(horzAx, vertRev ? 1 : 0); info = new CSAxisInformation( Identifier: lineID, NameOfAxisStyle: GetAxisName(lineID), NameOfFirstDownSide: GetAxisSideName(lineID, CSAxisSide.FirstDown), NameOfFirstUpSide: GetAxisSideName(lineID, CSAxisSide.FirstUp), PreferredLabelSide: vertRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown, IsShownByDefault: true, HasTitleByDefault: true); _axisStyleInformation.Add(info); // Top lineID = new CSLineID(horzAx, vertRev ? 0 : 1); info = new CSAxisInformation( Identifier: lineID, NameOfAxisStyle: GetAxisName(lineID), NameOfFirstDownSide: GetAxisSideName(lineID, CSAxisSide.FirstDown), NameOfFirstUpSide: GetAxisSideName(lineID, CSAxisSide.FirstUp), PreferredLabelSide: vertRev ? CSAxisSide.FirstDown : CSAxisSide.FirstUp, IsShownByDefault: false, HasTitleByDefault: false); _axisStyleInformation.Add(info); // Y=0 lineID = CSLineID.FromPhysicalValue(horzAx, 0); info = new CSAxisInformation( Identifier: lineID, NameOfAxisStyle: GetAxisName(lineID), NameOfFirstDownSide: GetAxisSideName(lineID, CSAxisSide.FirstDown), NameOfFirstUpSide: GetAxisSideName(lineID, CSAxisSide.FirstUp), PreferredLabelSide: vertRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown, IsShownByDefault: false, HasTitleByDefault: false); _axisStyleInformation.Add(info); // X=0 lineID = CSLineID.FromPhysicalValue(vertAx, 0); info = new CSAxisInformation( Identifier: lineID, NameOfAxisStyle: GetAxisName(lineID), NameOfFirstDownSide: GetAxisSideName(lineID, CSAxisSide.FirstDown), NameOfFirstUpSide: GetAxisSideName(lineID, CSAxisSide.FirstUp), PreferredLabelSide: horzRev ? CSAxisSide.FirstUp : CSAxisSide.FirstDown, IsShownByDefault: false, HasTitleByDefault: false); _axisStyleInformation.Add(info); }
private GraphicsPath _enclosingPath = new GraphicsPath(); // with Winding also overlapping rectangles are selected public override void Paint(Graphics g, XYPlotLayer layer, CSAxisInformation styleInfo, AxisLineStyle axisstyle, bool useMinorTicks) { _cachedStyleID = styleInfo.Identifier; CSLineID styleID = styleInfo.Identifier; Scale raxis = styleID.ParallelAxisNumber == 0 ? layer.XAxis : layer.YAxis; _enclosingPath.Reset(); _enclosingPath.FillMode = FillMode.Winding; // with Winding also overlapping rectangles are selected GraphicsPath helperPath = new GraphicsPath(); Matrix math = new Matrix(); Logical3D r0 = _cachedStyleID.Begin; Logical3D r1 = _cachedStyleID.End; SizeF layerSize = layer.Size; PointF outVector; Logical3D outer; float outerDistance = null == axisstyle? 0 : axisstyle.GetOuterDistance(styleInfo.PreferedLabelSide); float dist_x = outerDistance; // Distance from axis tick point to label float 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 = raxis.GetMinorTicksNormal(); ticks = raxis.GetMinorTicksAsVariant(); } else { relpositions = raxis.GetMajorTicksNormal(); ticks = raxis.GetMajorTicksAsVariant(); } IMeasuredLabelItem[] labels = _labelFormatting.GetMeasuredItems(g, _font, _stringFormat, ticks); float emSize = _font.SizeInPoints; for (int i = 0; i < ticks.Length; i++) { double r = relpositions[i]; outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, styleInfo.PreferedLabelSide); PointF tickorg = layer.CoordinateSystem.GetNormalizedDirection(r0, r1, r, outer, out outVector); PointF tickend = tickorg; tickend.X += outVector.X * outerDistance; tickend.Y += outVector.Y * outerDistance; SizeF msize = labels[i].Size; PointF morg = tickend; if (_automaticRotationShift) { double alpha = _rotation * Math.PI / 180 - Math.Atan2(outVector.Y, outVector.X); double shift = msize.Height * 0.5 * Math.Abs(Math.Sin(alpha)) + (msize.Width + _font.SizeInPoints / 2) * 0.5 * Math.Abs(Math.Cos(alpha)); morg.X += (float)(outVector.X * shift); morg.Y += (float)(outVector.Y * shift); } else { morg.X += (float)(outVector.X * _font.SizeInPoints / 3); } RectangleF mrect = new RectangleF(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 (this._rotation != 0) { math.Rotate((float)-this._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 (this._backgroundStyle != null) { _backgroundStyle.Draw(g, new RectangleF(PointF.Empty, msize)); } _brush.Rectangle = new RectangleF(PointF.Empty, msize); labels[i].Draw(g, _brush, new PointF(0, 0)); g.Restore(gs); // Restore the graphics state helperPath.Reset(); helperPath.AddRectangle(new RectangleF(PointF.Empty, msize)); helperPath.Transform(math); _enclosingPath.AddPath(helperPath, true); } }