public string GetAxisName(CSLineID id) { if (id.Is3DIdentifier) { throw new ArgumentException(nameof(id) + " is a 3D identifier, but here a 2D identifier is expected"); } if (id.UsePhysicalValueOtherFirst) { bool isX = id.ParallelAxisNumber == 0 ^ _isXYInterchanged; return(string.Format("{0}={1}", isX ? "X" : "Y", id.PhysicalValueOtherFirst)); } else // logical values { if (id.LogicalValueOtherFirst == 0 || id.LogicalValueOtherFirst == 1) { return(GetAxisName_Logical0Or1(id)); } else { if (id.LogicalValueOtherFirst <= 0.5) { var id1 = id.WithLogicalValueOtherFirst(0); var basename = GetAxisName_Logical0Or1(id1); return(string.Format("{0} ({1}% offset)", basename, id.LogicalValueOtherFirst * 100)); } else // id.LogicalValueOtherFirst>0.5) { var id1 = id.WithLogicalValueOtherFirst(1); var basename = GetAxisName_Logical0Or1(id1); return(string.Format("{0} ({1}% offset)", basename, (id.LogicalValueOtherFirst - 1) * 100)); } } } }
/// <summary>Gets the name of the axis side.</summary> /// <param name="id">The axis identifier.</param> /// <param name="side">The axis side.</param> /// <returns>The name of the axis side for the axis line given by the identifier.</returns> public override string GetAxisSideName(CSLineID id, CSAxisSide side) { bool isX = id.ParallelAxisNumber == 0; isX ^= _isXYInterchanged; bool isUp = side == CSAxisSide.FirstUp; isUp ^= isX ? _isXreverse : _isYreverse; bool isOuterLine = (id.LogicalValueOtherFirst == 0 || id.LogicalValueOtherFirst == 1); if (isOuterLine) { isUp ^= (0 == id.LogicalValueOtherFirst); } if (isOuterLine) { return(_axisNamesOuterLines[isX ? 0 : 1, isUp ? 0 : 1]); } else { return(_axisNamesNormal[isX ? 0 : 1, isUp ? 0 : 1]); } }
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)); }
public void EhView_DeleteAxis() { if (!ApplyCurrentController(false, false)) { return; } if (_listOfAxes.Count <= 1) { return; } var axisID = _currentAxisID; if (true == Current.Gui.YesNoMessageBox("Are you sure that you want to delete this axis?", "Confirmation", false)) { if (true == _doc.AxisStyles.Remove(axisID)) { _axisControl.Remove(axisID); var axisItem = _listOfAxes.First(x => axisID != (CSLineID)(x.Tag)); axisItem.IsSelected = true; _currentAxisID = (CSLineID)(axisItem.Tag); _listOfAxes.RemoveWhere(x => axisID == (CSLineID)(x.Tag)); SetSecondaryChoiceToAxes(); SetCurrentTabController(false); } } }
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()); }
public void FixupInternalDataStructures(IPlotArea layer, Func <CSLineID, CSAxisInformation> GetAxisStyleInformation) { // 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 = _styleID.WithLogicalValueOtherFirst(logicalValue); } if (_styleID.UsePhysicalValueOtherSecond) { // then update the logical value of this identifier double logicalValue = layer.Scales[_styleID.AxisNumberOtherSecond].PhysicalVariantToNormal(_styleID.PhysicalValueOtherSecond); _styleID = _styleID.WithLogicalValueOtherSecond(logicalValue); } CachedAxisInformation = GetAxisStyleInformation(_styleID); if (null != _customTickSpacing) { CSLineID styleID = _cachedAxisInfo.Identifier; Scale scale = layer.Scales[styleID.ParallelAxisNumber]; Altaxo.Data.AltaxoVariant org = scale.OrgAsVariant, end = scale.EndAsVariant; _customTickSpacing.PreProcessScaleBoundaries(ref org, ref end, false, false); _customTickSpacing.FinalProcessScaleBoundaries(org, end, scale); } if (null != _axisTitle) { _axisTitle.SetParentSize(layer.Size, false); } }
public AxisStyle(CSLineID id, bool isAxisLineEnabled, bool areMajorTicksEnabled, bool areMinorTicksEnabled, string axisTitleOrNull, Altaxo.Main.Properties.IReadOnlyPropertyBag context) { _styleID = id; if (isAxisLineEnabled) { ShowAxisLine(context); } if (areMajorTicksEnabled) { ShowMajorLabels(context); } if (areMinorTicksEnabled) { ShowMinorLabels(context); } if (null != axisTitleOrNull) { ShowTitle(context); _axisTitle.Text = axisTitleOrNull; } }
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; } }
public bool Apply() { // read axis title _doc.TitleText = m_View.AxisTitle; if (null != _axisLineStyleController) { if (!_axisLineStyleController.Apply()) { return(false); } else { _doc.AxisLineStyle = (AxisLineStyle)_axisLineStyleController.ModelObject; } } _doc.ShowMajorLabels = m_View.ShowMajorLabels; _doc.ShowMinorLabels = m_View.ShowMinorLabels; // if we have offset applying, create a brand new AxisStyle instance double offset = m_View.PositionOffset / 100; if (0 != offset) { AxisStyle newDoc = new AxisStyle(CSLineID.FromIDandFirstLogicalOffset(_doc.StyleID, offset)); newDoc.CopyWithoutIdFrom(_doc); _doc = newDoc; } return(true); // all ok }
public override string GetAxisSideName(CSLineID id, CSAxisSide side) { var v = GetUntransformedAxisSideVector(id, side); var tv = VectorTransformation.Transform(v); var name = GetAxisSideNameFromVector(tv); return(name); }
public string GetAxisLineName(CSLineID id) { var v = GetUntransformedAxisLineVector(id); var tv = VectorTransformation.Transform(v); var name = GetAxisLineName(tv); return(name); }
private string GetAxisName_Logical0Or1(CSLineID id) { bool isHorizontal = (id.ParallelAxisNumber == 0) ^ _isXYInterchanged; bool isLogical0 = (id.LogicalValueOtherFirst == 0) ^ ((id.ParallelAxisNumber == 1 && _isXreverse) || (id.ParallelAxisNumber == 0 && _isYreverse)); return(_axisNamesOuterLines[isHorizontal ? 0 : 1, isLogical0 ? 0 : 1]); }
public static bool ShowDialog(XYPlotLayer layer, string currentPage, CSLineID currentEdge) { LayerController ctrl = new LayerController(layer, currentPage, currentEdge); LayerControl view = new LayerControl(); ctrl.View = view; return(Current.Gui.ShowDialog(ctrl, layer.Name, 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); }
private XYPlotLayerController(XYPlotLayer layer, string currentPage, int axisScaleIdx, CSLineID id, UseDocument useDocumentCopy) { _useDocumentCopy = useDocumentCopy == UseDocument.Copy; _currentAxisID = id; _currentScale = axisScaleIdx; _currentPageName = currentPage; InitializeDocument(layer); }
public CSAxisSide GetPreferredLabelSide(CSLineID id) { var u_axisVector = GetUntransformedAxisLineVector(id); var t_axisVector = VectorTransformation.Transform(u_axisVector); var t_labelSide = GetPreferredLabelSide(t_axisVector); var u_labelSide = VectorTransformation.InverseTransform(t_labelSide); return(GetAxisSide(id, u_labelSide)); }
public CSAxisInformation GetAxisStyleInformation(CSLineID lineId) { var result = _underlyingArea.CoordinateSystem.GetAxisStyleInformation(lineId).WithIdentifier(new CSLineID(lineId.ParallelAxisNumber, _org)); result = result.WithLogicalValuesForAxisOrgAndEnd( LogicalValueAxisOrg: _org[_scaleNumber], LogicalValueAxisEnd: _end[_scaleNumber]); 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); }
public AxisStyle AxisStyleEnsured(CSLineID id) { AxisStyle prop = this[id]; if (prop == null) { prop = new AxisStyle(id); prop.CachedAxisInformation = _cachedCoordinateSystem.GetAxisStyleInformation(id); Add(prop); } return(prop); }
public void EhView_CreateOrMoveAxis(bool moveAxis) { if (!ApplyCurrentController(false, false)) { return; } var creationArgs = new AxisCreationArguments(); creationArgs.InitializeAxisInformationList(_doc.CoordinateSystem, _doc.AxisStyles); creationArgs.TemplateStyle = _currentAxisID; creationArgs.MoveAxis = moveAxis; if (!Current.Gui.ShowDialog(ref creationArgs, "Create/move axis", false)) { return; } if (_axisControl.ContainsKey(creationArgs.CurrentStyle)) { return; // the axis is already present } var oldIdentity = creationArgs.TemplateStyle; var newIdentity = creationArgs.CurrentStyle; var newAxisInfo = _doc.CoordinateSystem.GetAxisStyleInformation(newIdentity); AxisCreationArguments.AddAxis(_doc.AxisStyles, creationArgs); // add the new axis to the document _axisControl.Add(newIdentity, new AxisStyleControllerConditionalGlue(newAxisInfo, _doc.AxisStyles)); SetSecondaryChoiceToUnique(); _listOfAxes.ClearSelectionsAll(); _listOfAxes.Add(new SelectableListNode(newAxisInfo.NameOfAxisStyle, newIdentity, true)); if (creationArgs.MoveAxis && _axisControl.ContainsKey(oldIdentity)) { _axisControl.Remove(oldIdentity); for (int i = _listOfAxes.Count - 1; i >= 0; --i) { if (((CSLineID)_listOfAxes[i].Tag) == oldIdentity) { _listOfAxes.RemoveAt(i); break; } } } _currentAxisID = newIdentity; SetSecondaryChoiceToAxes(); SetCurrentTabController(false); }
/// <summary> /// Creates the axis style with ShowAxisLine = true and ShowMajorLabels = true /// </summary> /// <param name="id">The axis style identifier.</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(CSLineID id, IReadOnlyPropertyBag context) { AxisStyle prop = this[id]; if (prop == null) { prop = new AxisStyle(id, true, true, false, null, context) { CachedAxisInformation = _cachedCoordinateSystem.GetAxisStyleInformation(id) }; Add(prop); } return(prop); }
private XYPlotLayerController(XYZPlotLayer layer, string currentPage, int axisScaleIdx, CSLineID id, UseDocument useDocumentCopy) { if (!id.Is3DIdentifier) { throw new ArgumentException(nameof(id) + " has to be a 3D identifier!"); } _useDocumentCopy = useDocumentCopy == UseDocument.Copy; _currentAxisID = id; _currentScale = axisScaleIdx; _currentPageName = currentPage; InitializeDocument(layer); }
/// <summary> /// Get a line along the axis designated by the argument id from the logical values r0 to r1. /// </summary> /// <param name="path">Graphics path.</param> /// <param name="id">Axis to draw the isoline along.</param> /// <param name="r0">Start point of the isoline. The logical value of the other coordinate.</param> /// <param name="r1">End point of the isoline. The logical value of the other coordinate.</param> public virtual void GetIsolineFromTo(CSLineID id, double r0, double r1, out IPolylineD3D path) { if (id.ParallelAxisNumber == 0) { path = GetIsoline(new Logical3D(r0, id.LogicalValueOtherFirst, id.LogicalValueOtherSecond), new Logical3D(r1, id.LogicalValueOtherFirst, id.LogicalValueOtherSecond)); } else if (id.ParallelAxisNumber == 1) { path = GetIsoline(new Logical3D(id.LogicalValueOtherFirst, r0, id.LogicalValueOtherSecond), new Logical3D(id.LogicalValueOtherFirst, r1, id.LogicalValueOtherSecond)); } else { path = GetIsoline(new Logical3D(id.LogicalValueOtherFirst, id.LogicalValueOtherSecond, r0), new Logical3D(id.LogicalValueOtherFirst, id.LogicalValueOtherSecond, r1)); } }
/// <summary> /// Get a line along the axis designated by the argument id from the logical values r0 to r1. /// </summary> /// <param name="g">Graphics context.</param> /// <param name="pen">The pen required to draw the line.</param> /// <param name="id">Axis to draw the isoline along.</param> /// <param name="r0">Start point of the isoline. The logical value of the other coordinate.</param> /// <param name="r1">End point of the isoline. The logical value of the other coordinate.</param> public virtual void DrawIsolineFromTo(Graphics g, Pen pen, CSLineID id, double r0, double r1) { if (id.ParallelAxisNumber == 0) { DrawIsoline(g, pen, new Logical3D(r0, id.LogicalValueOtherFirst, id.LogicalValueOtherSecond), new Logical3D(r1, id.LogicalValueOtherFirst, id.LogicalValueOtherSecond)); } else if (id.ParallelAxisNumber == 1) { DrawIsoline(g, pen, new Logical3D(id.LogicalValueOtherFirst, r0, id.LogicalValueOtherSecond), new Logical3D(id.LogicalValueOtherFirst, r1, id.LogicalValueOtherSecond)); } else { DrawIsoline(g, pen, new Logical3D(id.LogicalValueOtherFirst, id.LogicalValueOtherSecond, r0), new Logical3D(id.LogicalValueOtherFirst, id.LogicalValueOtherSecond, r1)); } }
public AxisStyle this[CSLineID id] { get { foreach (AxisStyle p in _axisStyles) { if (p.StyleID == id) { return(p); } } return(null); } }
/// <summary> /// Get a line along the axis designated by the argument id from the logical values r0 to r1. /// </summary> /// <param name="path">Graphics path.</param> /// <param name="id">Axis to draw the isoline along.</param> /// <param name="r0">Start point of the isoline. The logical value of the other coordinate.</param> /// <param name="r1">End point of the isoline. The logical value of the other coordinate.</param> public virtual void GetIsolineFromTo(GraphicsPath path, CSLineID id, double r0, double r1) { if (id.ParallelAxisNumber == 0) { GetIsoline(path, new Logical3D(r0, id.LogicalValueOtherFirst, id.LogicalValueOtherSecond), new Logical3D(r1, id.LogicalValueOtherFirst, id.LogicalValueOtherSecond)); } else if (id.ParallelAxisNumber == 1) { GetIsoline(path, new Logical3D(id.LogicalValueOtherFirst, r0, id.LogicalValueOtherSecond), new Logical3D(id.LogicalValueOtherFirst, r1, id.LogicalValueOtherSecond)); } else { GetIsoline(path, new Logical3D(id.LogicalValueOtherFirst, id.LogicalValueOtherSecond, r0), new Logical3D(id.LogicalValueOtherFirst, id.LogicalValueOtherSecond, r1)); } }
public override bool Apply(bool disposeController) { _doc.MoveAxis = _view.MoveAxis; if (_view.UsePhysicalValue) { _doc.CurrentStyle = CSLineID.FromPhysicalVariant(_doc.TemplateStyle.ParallelAxisNumber, _view.AxisPositionPhysicalValue); } else { _doc.CurrentStyle = new CSLineID(_doc.TemplateStyle.ParallelAxisNumber, _view.AxisPositionLogicalValue); } return(ApplyEnd(true, disposeController)); }
/// <summary> /// Creates the axis style with ShowAxisLine = true and ShowMajorLabels = true /// </summary> /// <param name="id">The axis style identifier.</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(CSLineID id) { AxisStyle prop = this[id]; if (prop == null) { prop = new AxisStyle(id); prop.CachedAxisInformation = _cachedCoordinateSystem.GetAxisStyleInformation(id); prop.ShowAxisLine = true; prop.ShowMajorLabels = true; Add(prop); } return(prop); }
/// <summary>Gets the name of the axis side.</summary> /// <param name="id">The axis identifier.</param> /// <param name="side">The axis side.</param> /// <returns>The name of the axis side for the axis line given by the identifier.</returns> public override string GetAxisSideName(CSLineID id, CSAxisSide side) { bool isHorizontal = id.ParallelAxisNumber == 0 ^ _isXYInterchanged; bool isOuterLine = (id.LogicalValueOtherFirst == 0 || id.LogicalValueOtherFirst == 1); if (isOuterLine) { bool isPointingOutwards = (id.LogicalValueOtherFirst == 0 && side == CSAxisSide.FirstDown) || (id.LogicalValueOtherFirst == 1 && side == CSAxisSide.FirstUp); return(_axisSideNamesOuterLines[isHorizontal ? 0 : 1, isPointingOutwards ? 0 : 1]); } else { bool isRight = ((id.ParallelAxisNumber == 0 && _isYreverse) || (id.ParallelAxisNumber == 1 && _isXreverse)) ^ (side == CSAxisSide.FirstUp); return(_axisSideNamesNormal[isHorizontal ? 0 : 1, isRight ? 0 : 1]); } }
LayerController(XYPlotLayer layer, string currentPage, int axisScaleIdx, CSLineID id) { _originalDoc = layer; _doc = (XYPlotLayer)layer.Clone(); _docSuspendLock = _doc.BeginUpdate(); SetCoordinateSystemDependentObjects(id); _currentScale = axisScaleIdx; _currentAxisID = id; _currentPlaneID = CSPlaneID.Front; _currentPageName = currentPage; if (null != View) { SetViewElements(); } }
/// <summary> /// Changes the style identifier. /// </summary> /// <param name="newIdentifier">The new identifier.</param> /// <param name="GetNewAxisSideFromOldAxisSide">Functions that uses the old axis side as parameter1, and returns the corresponding axis side of the new coordinate system, or null if no such side could be found.</param> /// <exception cref="System.ArgumentNullException"></exception> public void ChangeStyleIdentifier(CSLineID newIdentifier, Func<CSAxisSide, CSAxisSide?> GetNewAxisSideFromOldAxisSide) { if (null == newIdentifier) throw new ArgumentNullException(nameof(newIdentifier)); _styleID = newIdentifier; if (null != _axisLineStyle) _axisLineStyle.ChangeTickPositionsWhenChangingCoordinateSystem(GetNewAxisSideFromOldAxisSide); if (null != _majorLabelStyle && _majorLabelStyle.LabelSide.HasValue) _majorLabelStyle.LabelSide = GetNewAxisSideFromOldAxisSide(_majorLabelStyle.LabelSide.Value); if (null != _minorLabelStyle && _minorLabelStyle.LabelSide.HasValue) { _minorLabelStyle.LabelSide = GetNewAxisSideFromOldAxisSide(_minorLabelStyle.LabelSide.Value); } }
public AxisStyle(CSLineID id) { _styleID = id; }
public bool ContainsAxisStyle(CSLineID id) { ScaleStyle scalestyle = _styles[id.ParallelAxisNumber]; return scalestyle.ContainsAxisStyle(id); }
/// <summary> /// This will return an axis style with the given id. If not present, this axis style will be created, added to the collection, and returned. /// </summary> /// <param name="id"></param> /// <returns></returns> public AxisStyle AxisStyleEnsured(CSLineID id) { ScaleStyle scaleStyle = _styles[id.ParallelAxisNumber]; return scaleStyle.AxisStyleEnsured(id); }
public void RemoveAxisStyle(CSLineID id) { int idx = -1; for (int i = 0; i < _axisStyles.Count; i++) { if (_axisStyles[i].StyleID == id) { idx = i; break; } } if (idx > 0) _axisStyles.RemoveAt(idx); }
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); }
public CSAxisInformation GetAxisStyleInformation(CSLineID lineId) { var result = _underlyingArea.CoordinateSystem.GetAxisStyleInformation(lineId).WithIdentifier(new CSLineID(lineId.ParallelAxisNumber, _org)); result = result.WithLogicalValuesForAxisOrgAndEnd( LogicalValueAxisOrg: _org[_scaleNumber], LogicalValueAxisEnd: _end[_scaleNumber]); return result; }
/// <summary>Gets the name of the axis side.</summary> /// <param name="id">The axis identifier.</param> /// <param name="side">The axis side.</param> /// <returns>The name of the axis side for the axis line given by the identifier.</returns> public abstract string GetAxisSideName(CSLineID id, CSAxisSide side);
public string GetAxisName(CSLineID id) { if (id.Is3DIdentifier) throw new ArgumentException(nameof(id) + " is a 3D identifier, but here a 2D identifier is expected"); if (id.UsePhysicalValueOtherFirst) { bool isX = id.ParallelAxisNumber == 0 ^ _isXYInterchanged; return string.Format("{0}={1}", isX ? "X" : "Y", id.PhysicalValueOtherFirst); } else // logical values { if (id.LogicalValueOtherFirst == 0 || id.LogicalValueOtherFirst == 1) { return GetAxisName_Logical0Or1(id); } else { if (id.LogicalValueOtherFirst <= 0.5) { var id1 = id.WithLogicalValueOtherFirst(0); var basename = GetAxisName_Logical0Or1(id1); return string.Format("{0} ({1}% offset)", basename, id.LogicalValueOtherFirst * 100); } else // id.LogicalValueOtherFirst>0.5) { var id1 = id.WithLogicalValueOtherFirst(1); var basename = GetAxisName_Logical0Or1(id1); return string.Format("{0} ({1}% offset)", basename, (id.LogicalValueOtherFirst - 1) * 100); } } } }
public bool ContainsAxisStyle(CSLineID id) { return null != AxisStyle(id); }
private void SetAxisTitleString(CSLineID id, string value) { AxisStyle style = _axisStyles[id]; string oldtitle = (style == null || style.Title == null) ? null : style.Title.Text; string newtitle = (value == null || value == String.Empty) ? null : value; if (newtitle != oldtitle) { if (newtitle == null) { if (style != null) style.Title = null; } else if (_axisStyles.AxisStyleEnsured(id).Title != null) { _axisStyles[id].Title.Text = newtitle; } else { TextGraphic tg = new TextGraphic(); CSAxisInformation info = CoordinateSystem.GetAxisStyleInformation(id); // find out the position and orientation of the item double rx0 = 0, rx1 = 1, ry0 = 0, ry1 = 1; if (id.ParallelAxisNumber == 0) ry0 = ry1 = id.LogicalValueOtherFirst; else rx0 = rx1 = id.LogicalValueOtherFirst; PointF normDirection; Logical3D tdirection = CoordinateSystem.GetLogicalDirection(info.Identifier.ParallelAxisNumber, info.PreferedLabelSide); PointF location = CoordinateSystem.GetNormalizedDirection(new Logical3D(rx0, ry0), new Logical3D(rx1, ry1), 0.5, tdirection, out normDirection); double angle = Math.Atan2(normDirection.Y, normDirection.X) * 180 / Math.PI; float distance = 0; AxisStyle axisStyle = _axisStyles[id]; if (null != axisStyle.AxisLineStyle) distance += axisStyle.AxisLineStyle.GetOuterDistance(info.PreferedLabelSide); float labelFontSize = 0; if (axisStyle.ShowMajorLabels) labelFontSize = Math.Max(labelFontSize, axisStyle.MajorLabelStyle.FontSize); if (axisStyle.ShowMinorLabels) labelFontSize = Math.Max(labelFontSize, axisStyle.MinorLabelStyle.FontSize); const float scaleFontWidth = 4; const float scaleFontHeight = 1.5f; if (-45<= angle && angle <= 45) { //case EdgeType.Right: tg.Rotation = 90; tg.XAnchor = XAnchorPositionType.Center; tg.YAnchor = YAnchorPositionType.Top; distance += scaleFontWidth * labelFontSize; } else if (-135 <= angle && angle <= -45) { //case Top: tg.Rotation = 0; tg.XAnchor = XAnchorPositionType.Center; tg.YAnchor = YAnchorPositionType.Bottom; distance += scaleFontHeight * labelFontSize; } else if (45 <= angle && angle <= 135) { //case EdgeType.Bottom: tg.Rotation = 0; tg.XAnchor = XAnchorPositionType.Center; tg.YAnchor = YAnchorPositionType.Top; distance += scaleFontHeight * labelFontSize; } else { //case EdgeType.Left: tg.Rotation = 90; tg.XAnchor = XAnchorPositionType.Center; tg.YAnchor = YAnchorPositionType.Bottom; distance += scaleFontWidth * labelFontSize; } tg.Position = new PointF(location.X + distance * normDirection.X, location.Y + distance * normDirection.Y); tg.Text = newtitle; _axisStyles.AxisStyleEnsured(id).Title = tg; } } }
private string GetAxisName_Logical0Or1(CSLineID id) { bool isHorizontal = (id.ParallelAxisNumber == 0) ^ _isXYInterchanged; bool isLogical0 = (id.LogicalValueOtherFirst == 0) ^ ((id.ParallelAxisNumber == 1 && _isXreverse) || (id.ParallelAxisNumber == 0 && _isYreverse)); return _axisNamesOuterLines[isHorizontal ? 0 : 1, isLogical0 ? 0 : 1]; }
public AxisStyle AxisStyleEnsured(CSLineID id) { AxisStyle prop = AxisStyle(id); if (prop == null) { prop = new AxisStyle(id); // prop.CachedAxisInformation = _cachedCoordinateSystem.GetAxisStyleInformation(id); AddAxisStyle(prop); } return prop; }
/// <summary>Gets the name of the axis side.</summary> /// <param name="id">The axis identifier.</param> /// <param name="side">The axis side.</param> /// <returns>The name of the axis side for the axis line given by the identifier.</returns> public override string GetAxisSideName(CSLineID id, CSAxisSide side) { bool isX = id.ParallelAxisNumber == 0; isX ^= _isXYInterchanged; bool isUp = side == CSAxisSide.FirstUp; isUp ^= isX ? _isXreverse : _isYreverse; bool isOuterLine = (id.LogicalValueOtherFirst == 0 || id.LogicalValueOtherFirst == 1); if (isOuterLine) isUp ^= (0 == id.LogicalValueOtherFirst); if (isOuterLine) return _axisNamesOuterLines[isX ? 0 : 1, isUp ? 0 : 1]; else return _axisNamesNormal[isX ? 0 : 1, isUp ? 0 : 1]; }
public AxisStyle AxisStyle(CSLineID id) { foreach (AxisStyle p in _axisStyles) if (p.StyleID == id) return p; return null; }
/// <summary> /// Find the axis style with the given id. If found, returns the index of this style, or -1 otherwise. /// </summary> /// <param name="id">The id to find.</param> /// <returns>Index of the style, or -1 if not found.</returns> public int IndexOfAxisStyle(CSLineID id) { if (id == null) return -1; if (_axisStyleInformation == null || _axisStyleInformation.Count == 0) UpdateAxisInfo(); for (int i = 0; i < _axisStyleInformation.Count; i++) if (_axisStyleInformation[i].Identifier == id) return i; return -1; }
public void RemoveAxisStyle(CSLineID id) { ScaleStyle scaleStyle = _styles[id.ParallelAxisNumber]; scaleStyle.RemoveAxisStyle(id); }
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; }
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; }
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; }
/// <summary>Gets the name of the axis side.</summary> /// <param name="id">The axis identifier.</param> /// <param name="side">The axis side.</param> /// <returns>The name of the axis side for the axis line given by the identifier.</returns> public override string GetAxisSideName(CSLineID id, CSAxisSide side) { return _axisNamesNormal[id.ParallelAxisNumber, (int)side]; }
public 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 void FixupInternalDataStructures(IPlotArea layer, Func<CSLineID, CSAxisInformation> GetAxisStyleInformation) { // 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 = _styleID.WithLogicalValueOtherFirst(logicalValue); } if (_styleID.UsePhysicalValueOtherSecond) { // then update the logical value of this identifier double logicalValue = layer.Scales[_styleID.AxisNumberOtherSecond].PhysicalVariantToNormal(_styleID.PhysicalValueOtherSecond); _styleID = _styleID.WithLogicalValueOtherSecond(logicalValue); } CachedAxisInformation = GetAxisStyleInformation(_styleID); if (null != _customTickSpacing) { CSLineID styleID = _cachedAxisInfo.Identifier; Scale scale = layer.Scales[styleID.ParallelAxisNumber]; Altaxo.Data.AltaxoVariant org = scale.OrgAsVariant, end = scale.EndAsVariant; _customTickSpacing.PreProcessScaleBoundaries(ref org, ref end, false, false); _customTickSpacing.FinalProcessScaleBoundaries(org, end, scale); } if (null != _axisTitle) _axisTitle.SetParentSize(layer.Size, false); }
private string GetAxisTitleString(CSLineID id) { return _axisStyles[id] != null && _axisStyles[id].Title != null ? _axisStyles[id].Title.Text : null; }
/// <summary>Gets the name of the axis side.</summary> /// <param name="id">The axis identifier.</param> /// <param name="side">The axis side.</param> /// <returns>The name of the axis side for the axis line given by the identifier.</returns> public override string GetAxisSideName(CSLineID id, CSAxisSide side) { bool isHorizontal = id.ParallelAxisNumber == 0 ^ _isXYInterchanged; bool isOuterLine = (id.LogicalValueOtherFirst == 0 || id.LogicalValueOtherFirst == 1); if (isOuterLine) { bool isPointingOutwards = (id.LogicalValueOtherFirst == 0 && side == CSAxisSide.FirstDown) || (id.LogicalValueOtherFirst == 1 && side == CSAxisSide.FirstUp); return _axisSideNamesOuterLines[isHorizontal ? 0 : 1, isPointingOutwards ? 0 : 1]; } else { bool isRight = ((id.ParallelAxisNumber == 0 && _isYreverse) || (id.ParallelAxisNumber == 1 && _isXreverse)) ^ (side == CSAxisSide.FirstUp); return _axisSideNamesNormal[isHorizontal ? 0 : 1, isRight ? 0 : 1]; } }