public override void Paint(Graphics g, IPaintContext paintContext) { var layer = Altaxo.Main.AbsoluteDocumentPath.GetRootNodeImplementing<XYPlotLayer>(this); if (null == layer) { PaintErrorInvalidLayerType(g, paintContext); return; } Logical3D rBegin; layer.CoordinateSystem.LayerToLogicalCoordinates(X, Y, out rBegin); Logical3D rEnd = rBegin; switch (_scaleSpanType) { case FloatingScaleSpanType.IsLogicalValue: rEnd[_scaleNumber] = rBegin[_scaleNumber] + _scaleSpanValue; break; case FloatingScaleSpanType.IsPhysicalEndOrgDifference: { var physValue = layer.Scales[_scaleNumber].NormalToPhysicalVariant(rBegin[this._scaleNumber]); physValue += _scaleSpanValue; // to be replaced by the scale span var logValue = layer.Scales[_scaleNumber].PhysicalVariantToNormal(physValue); rEnd[_scaleNumber] = logValue; } break; case FloatingScaleSpanType.IsPhysicalEndOrgRatio: { var physValue = layer.Scales[_scaleNumber].NormalToPhysicalVariant(rBegin[this._scaleNumber]); physValue *= _scaleSpanValue; // to be replaced by the scale span var logValue = layer.Scales[_scaleNumber].PhysicalVariantToNormal(physValue); rEnd[_scaleNumber] = logValue; } break; } // axis style var csLineId = new CSLineID(_scaleNumber, rBegin); if (_axisStyle.StyleID != csLineId) { var propertyContext = this.GetPropertyContext(); var axStyle = new AxisStyle(new CSLineID(_scaleNumber, rBegin), false, false, false, null, propertyContext); axStyle.CopyWithoutIdFrom(_axisStyle); _axisStyle = axStyle; } var privScale = new ScaleSegment(layer.Scales[_scaleNumber], rBegin[_scaleNumber], rEnd[_scaleNumber], _scaleSegmentType); _tickSpacing.FinalProcessScaleBoundaries(privScale.OrgAsVariant, privScale.EndAsVariant, privScale); privScale.TickSpacing = _tickSpacing; var privLayer = new LayerSegment(layer, privScale, rBegin, rEnd, _scaleNumber); if (_background == null) { _axisStyle.Paint(g, paintContext, privLayer, privLayer.GetAxisStyleInformation); } else { // if we have a background, we paint in a dummy bitmap in order to measure all items // the real painting is done later on after painting the background. using (var bmp = new Bitmap(4, 4)) { using (Graphics gg = Graphics.FromImage(bmp)) { _axisStyle.Paint(gg, paintContext, privLayer, privLayer.GetAxisStyleInformation); } } } _cachedPath = _axisStyle.AxisLineStyle.GetObjectPath(privLayer, true); // calculate size information RectangleD2D bounds1 = _cachedPath.GetBounds(); if (_axisStyle.AreMinorLabelsEnabled) { var path = _axisStyle.MinorLabelStyle.GetSelectionPath(); if (path.PointCount > 0) { _cachedPath.AddPath(path, false); RectangleD2D bounds2 = path.GetBounds(); bounds1.ExpandToInclude(bounds2); } } if (_axisStyle.AreMajorLabelsEnabled) { var path = _axisStyle.MajorLabelStyle.GetSelectionPath(); if (path.PointCount > 0) { _cachedPath.AddPath(path, false); RectangleD2D bounds2 = path.GetBounds(); bounds1.ExpandToInclude(bounds2); } } ((ItemLocationDirectAutoSize)_location).SetSizeInAutoSizeMode(bounds1.Size); //this._leftTop = bounds1.Location - this.GetPosition(); //throw new NotImplementedException("debug the previous statement"); if (_background != null) { bounds1.Expand(_backgroundPadding); _background.Draw(g, bounds1); _axisStyle.Paint(g, paintContext, privLayer, privLayer.GetAxisStyleInformation); } }
public override void FixupInternalDataStructures() { base.FixupInternalDataStructures(); var layer = Main.AbsoluteDocumentPath.GetRootNodeImplementing <XYPlotLayer>(this); if (null == layer) { _cachedLayerSegment = null; _cachedScale?.Dispose(); _cachedScale = null; return; } layer.CoordinateSystem.LayerToLogicalCoordinates(X, Y, out var rBegin); Logical3D rEnd = rBegin; switch (_scaleSpanType) { case FloatingScaleSpanType.IsLogicalValue: rEnd[_scaleNumber] = rBegin[_scaleNumber] + _scaleSpanValue; break; case FloatingScaleSpanType.IsPhysicalEndOrgDifference: { var physValue = layer.Scales[_scaleNumber].NormalToPhysicalVariant(rBegin[_scaleNumber]); physValue += _scaleSpanValue; // to be replaced by the scale span var logValue = layer.Scales[_scaleNumber].PhysicalVariantToNormal(physValue); rEnd[_scaleNumber] = logValue; } break; case FloatingScaleSpanType.IsPhysicalEndOrgRatio: { var physValue = layer.Scales[_scaleNumber].NormalToPhysicalVariant(rBegin[_scaleNumber]); physValue *= _scaleSpanValue; // to be replaced by the scale span var logValue = layer.Scales[_scaleNumber].PhysicalVariantToNormal(physValue); rEnd[_scaleNumber] = logValue; } break; } // axis style var csLineId = new CSLineID(_scaleNumber, rBegin); if (_axisStyle.StyleID != csLineId) { var propertyContext = this.GetPropertyContext(); var axStyle = new AxisStyle(new CSLineID(_scaleNumber, rBegin), false, false, false, null, propertyContext); axStyle.CopyWithoutIdFrom(_axisStyle); _axisStyle = axStyle; } _cachedScale?.Dispose(); _cachedScale = new ScaleSegment(layer.Scales[_scaleNumber], rBegin[_scaleNumber], rEnd[_scaleNumber], _scaleSegmentType); _tickSpacing.FinalProcessScaleBoundaries(_cachedScale.OrgAsVariant, _cachedScale.EndAsVariant, _cachedScale); _cachedScale.TickSpacing = _tickSpacing; _cachedLayerSegment = new LayerSegment(layer, _cachedScale, rBegin, rEnd, _scaleNumber); _axisStyle.FixupInternalDataStructures(_cachedLayerSegment, _cachedLayerSegment.GetAxisStyleInformation); // we use here special AxisStyleInformation not provided by the underlying CS, but by the layer segment }