/// <summary> /// Updates the axes, if required. /// </summary> private void UpdateAxes() { XAxis1.Update(); YAxis1.Update(); XAxis2.Update(); YAxis2.Update(); }
/// <summary> /// Set padding around the data area by defining the minimum size and padding for all axes /// </summary> public void Layout(float?left = null, float?right = null, float?bottom = null, float?top = null, float?padding = 5) { YAxis.ConfigureLayout(padding, left); YAxis2.ConfigureLayout(padding, right); XAxis.ConfigureLayout(padding, bottom); XAxis2.ConfigureLayout(padding, top); }
private bool cached = false; // at least 1 axis has been cached /// <summary> /// Cache the current axes /// </summary> public void CacheAxes() { if (!cached) { if (XAxis1 != null) { xAxis1Cache = (Axis)XAxis1.Clone(); cached = true; } if (XAxis2 != null) { xAxis2Cache = (Axis)XAxis2.Clone(); cached = true; } if (YAxis1 != null) { yAxis1Cache = (Axis)YAxis1.Clone(); cached = true; } if (YAxis2 != null) { yAxis2Cache = (Axis)YAxis2.Clone(); cached = true; } } }
/// <summary> /// Add a colorbar initialized with settings from a heatmap /// </summary> /// <param name="heatmap">A heatmap-containing plottable to connect with this colorbar</param> /// <param name="space">The size of the right axis will be set to this number of pixels to make room for the colorbar</param> /// <returns>the colorbar that was just created</returns> public Colorbar AddColorbar(IHasColormap heatmap, int space = 100) { var cb = new Colorbar(heatmap); Add(cb); YAxis2.SetSizeLimit(min: space); return(cb); }
/// <summary> /// Translate all PlotSurface Y-Axes by shiftProportion /// </summary> public void TranslateYAxes(double shiftProportion) { if (YAxis1 != null) { YAxis1.TranslateRange(shiftProportion); } if (YAxis2 != null) { YAxis2.TranslateRange(shiftProportion); } }
/// <summary> /// Customize styling options for the right axis (YAxis2) /// </summary> public void YLabel2(string label = null, string fontName = null, float?fontSize = null, Color?color = null, bool?bold = null) { YAxis2.Title.Label = label; YAxis2.Title.Font.Name = string.IsNullOrWhiteSpace(fontName) ? YAxis2.Title.Font.Name : fontName; YAxis2.Title.Font.Size = fontSize ?? YAxis2.Title.Font.Size; YAxis2.Configure(color: color); YAxis2.Title.Font.Bold = bold ?? YAxis2.Title.Font.Bold; YAxis2.Title.IsVisible = true; YAxis2.Ticks.MajorTickEnable = true; YAxis2.Ticks.MinorTickEnable = true; YAxis2.Ticks.MajorLabelEnable = true; }
/// <summary> /// Configure color and visibility of the frame that outlines the data area (lines along the edges of the primary axes) /// </summary> public void Frame(bool?visible = true, Color?color = null, bool?left = true, bool?right = true, bool?bottom = true, bool?top = true) { var primaryAxes = new Renderable.Axis[] { XAxis, XAxis2, YAxis, YAxis2 }; foreach (var axis in primaryAxes) { axis.ConfigureLine(visible, color); } YAxis.ConfigureLine(visible: left); YAxis2.ConfigureLine(visible: right); XAxis.ConfigureLine(visible: bottom); XAxis2.ConfigureLine(visible: top); }
void DetermineAxesToDraw(out Axis xAxis_1, out Axis xAxis_2, out Axis yAxis_1, out Axis yAxis_2) { xAxis_1 = XAxis1; xAxis_2 = XAxis2; yAxis_1 = YAxis1; yAxis_2 = YAxis2; if (XAxis1 == null) { if (XAxis2 == null) { throw new XwPlotException("Error: No X-Axis specified"); } xAxis_1 = (Axis)XAxis2.Clone(); xAxis_1.HideTickText = true; xAxis_1.TicksAngle = -Math.PI / 2; } if (XAxis2 == null) { // don't need to check if XAxis1 == null, as case already handled above. xAxis_2 = (Axis)XAxis1.Clone(); xAxis_2.HideTickText = true; xAxis_2.TicksAngle = Math.PI / 2.0; } if (YAxis1 == null) { if (YAxis2 == null) { throw new XwPlotException("Error: No Y-Axis specified"); } yAxis_1 = (Axis)YAxis2.Clone(); yAxis_1.HideTickText = true; yAxis_1.TicksAngle = Math.PI / 2.0; } if (YAxis2 == null) { // don't need to check if YAxis1 == null, as case already handled above. yAxis_2 = (Axis)YAxis1.Clone(); yAxis_2.HideTickText = true; yAxis_2.TicksAngle = -Math.PI / 2.0; } }
/// <summary> /// Add a colorbar to display a colormap beside the data area /// </summary> /// <param name="colormap">Colormap to display in this colorbar</param> /// <param name="space">The size of the right axis will be set to this number of pixels to make room for the colorbar</param> /// <param name="rightSide">If false the colorbar will be displayed on the left edge of the plot.</param> /// <returns>the colorbar that was just created</returns> public Colorbar AddColorbar(Drawing.Colormap colormap = null, int space = 100, bool rightSide = true) { var cb = new Colorbar(colormap); if (rightSide) { cb.Edge = Renderable.Edge.Right; YAxis2.SetSizeLimit(min: space); } else { cb.Edge = Renderable.Edge.Left; YAxis.SetSizeLimit(min: space); } Add(cb); return(cb); }
protected override void OnMouseUp(MouseEventArgs e) { if (e.Button == MouseButtons.Left && allowSelection_) { endPoint_.X = e.X; endPoint_.Y = e.Y; // terminate mouse action mouseActionInitiated_ = false; if (endPoint_ != unset_) { DrawRubberBand(startPoint_, endPoint_); } Point minPoint = new Point(0, 0); minPoint.X = Math.Min(startPoint_.X, endPoint_.X); minPoint.Y = Math.Min(startPoint_.Y, endPoint_.Y); Point maxPoint = new Point(0, 0); maxPoint.X = Math.Max(startPoint_.X, endPoint_.X); maxPoint.Y = Math.Max(startPoint_.Y, endPoint_.Y); Rectangle r = ps_.PlotAreaBoundingBoxCache; if (minPoint != maxPoint && (r.Contains(minPoint) || r.Contains(maxPoint))) { if (xAxis1Cache_ == null) { xAxis1Cache_ = (Axis)XAxis1.Clone(); xAxis2Cache_ = (Axis)XAxis2.Clone(); yAxis1Cache_ = (Axis)YAxis1.Clone(); yAxis2Cache_ = (Axis)YAxis2.Clone(); } // TODO: these bugger up if min/max point reversed. // think this implies can't have axes directed wrong way. // check out later. // middle wheel will be controlling zoom in future. left mouse may // be drag => stack zoom out not long term solution, so just make // zoom out go right out at this stage. if (XAxis1 != null) { double tempMin = PhysicalXAxis1Cache.PhysicalToWorld(minPoint, true); XAxis1.WorldMax = PhysicalXAxis1Cache.PhysicalToWorld(maxPoint, true); XAxis1.WorldMin = tempMin; } if (XAxis2 != null) { double tempMin = PhysicalXAxis2Cache.PhysicalToWorld(minPoint, true); XAxis2.WorldMax = PhysicalXAxis2Cache.PhysicalToWorld(maxPoint, true); XAxis2.WorldMin = tempMin; } if (YAxis1 != null) { double tempMin = PhysicalYAxis1Cache.PhysicalToWorld(maxPoint, true); YAxis1.WorldMax = PhysicalYAxis1Cache.PhysicalToWorld(minPoint, true); YAxis1.WorldMin = tempMin; } if (YAxis2 != null) { double tempMin = PhysicalYAxis2Cache.PhysicalToWorld(maxPoint, true); YAxis2.WorldMax = PhysicalYAxis2Cache.PhysicalToWorld(minPoint, true); YAxis2.WorldMin = tempMin; } // reset the start/end points startPoint_ = unset_; endPoint_ = unset_; Refresh(); } } else if (e.Button == MouseButtons.Right) { if (xAxis1Cache_ != null) { XAxis1 = xAxis1Cache_; XAxis2 = xAxis2Cache_; YAxis1 = yAxis1Cache_; YAxis2 = yAxis2Cache_; xAxis1Cache_ = null; xAxis2Cache_ = null; yAxis1Cache_ = null; yAxis2Cache_ = null; } Refresh(); } // don't fail to call the base method! base.OnMouseUp(e); }
/// <summary> /// Customize styling options for the right axis (YAxis2) label /// </summary> public void YLabel2(string label = null, string fontName = null, float?fontSize = null, Color?color = null, bool?bold = null) => YAxis2.ConfigureAxisLabel(true, label, color, fontSize, bold, fontName);
void UpdateAxes(bool recalculateAll) { if (drawables.Count != xAxisPositions.Count || drawables.Count != yAxisPositions.Count) { throw new XwPlotException("plots and axis position arrays our of sync"); } int position = 0; // if we're not recalculating axes using all iplots then set // position to last one in list. if (!recalculateAll) { position = drawables.Count - 1; if (position < 0) { position = 0; } } if (recalculateAll) { XAxis1 = null; YAxis1 = null; XAxis2 = null; YAxis2 = null; } for (int i = position; i < drawables.Count; ++i) { // only update axes if this drawable is an IPlot. if (!(drawables[i] is IPlot)) { continue; } IPlot p = (IPlot)drawables[i]; XAxisPosition xap = (XAxisPosition)xAxisPositions[i]; YAxisPosition yap = (YAxisPosition)yAxisPositions[i]; if (xap == XAxisPosition.Bottom) { if (XAxis1 == null) { XAxis1 = p.SuggestXAxis(); if (XAxis1 != null) { XAxis1.TicksAngle = -Math.PI / 2.0; } } else { XAxis1.LUB(p.SuggestXAxis()); } if (XAxis1 != null) { XAxis1.MinPhysicalLargeTickStep = 50; if (AutoScaleAutoGeneratedAxes) { XAxis1.AutoScaleText = true; XAxis1.AutoScaleTicks = true; XAxis1.TicksIndependentOfPhysicalExtent = true; } else { XAxis1.AutoScaleText = false; XAxis1.AutoScaleTicks = false; XAxis1.TicksIndependentOfPhysicalExtent = false; } } } if (xap == XAxisPosition.Top) { if (XAxis2 == null) { XAxis2 = p.SuggestXAxis(); if (XAxis2 != null) { XAxis2.TicksAngle = Math.PI / 2.0; } } else { XAxis2.LUB(p.SuggestXAxis()); } if (XAxis2 != null) { XAxis2.MinPhysicalLargeTickStep = 50; if (AutoScaleAutoGeneratedAxes) { XAxis2.AutoScaleText = true; XAxis2.AutoScaleTicks = true; XAxis2.TicksIndependentOfPhysicalExtent = true; } else { XAxis2.AutoScaleText = false; XAxis2.AutoScaleTicks = false; XAxis2.TicksIndependentOfPhysicalExtent = false; } } } if (yap == YAxisPosition.Left) { if (YAxis1 == null) { YAxis1 = p.SuggestYAxis(); if (YAxis1 != null) { YAxis1.TicksAngle = Math.PI / 2.0; } } else { YAxis1.LUB(p.SuggestYAxis()); } if (YAxis1 != null) { if (AutoScaleAutoGeneratedAxes) { YAxis1.AutoScaleText = true; YAxis1.AutoScaleTicks = true; YAxis1.TicksIndependentOfPhysicalExtent = true; } else { YAxis1.AutoScaleText = false; YAxis1.AutoScaleTicks = false; YAxis1.TicksIndependentOfPhysicalExtent = false; } } } if (yap == YAxisPosition.Right) { if (YAxis2 == null) { YAxis2 = p.SuggestYAxis(); if (YAxis2 != null) { YAxis2.TicksAngle = -Math.PI / 2.0; } } else { YAxis2.LUB(p.SuggestYAxis()); } if (YAxis2 != null) { if (AutoScaleAutoGeneratedAxes) { YAxis2.AutoScaleText = true; YAxis2.AutoScaleTicks = true; YAxis2.TicksIndependentOfPhysicalExtent = true; } else { YAxis2.AutoScaleText = false; YAxis2.AutoScaleTicks = false; YAxis2.TicksIndependentOfPhysicalExtent = false; } } } } }