object[] GetItems(Renderer2D rend, AxisCanvas ax) { if (rend != null) { if (rend.Inverted) { if (ax == _ay) { return(rend.ItemNames); } } else if (ax == _ax) { return(rend.ItemNames); } } return(null); }
internal RenderContext(IRenderer renderer, IDataSeriesInfo ds, int npts) { _cur = new Point(); _prev = new Point(); _curView = new Point(); _bounds = new Rect(); _stacked = new List <double>(); _excludeHoles = true; _pts = new List <Point>(); _rect = Extensions.EmptyRect; _clipBounds = Extensions.EmptyRect; _rendrerer = renderer; _ds = ds; _pts.Capacity = npts; if (_ds != null) { _names = _ds.GetDataNames(); } Chart visual = renderer.Visual as Chart; Chart = visual; BaseRenderer renderer2 = renderer as BaseRenderer; _isStacked = (renderer2 != null) && renderer2.IsStacked; hasNan = renderer2._dataInfo.hasNaN; DataSeries series = ds as DataSeries; if (series != null) { Renderer2D rendererd = renderer as Renderer2D; if ((((byte)(series.Display & SeriesDisplay.ShowNaNGap)) != 0) && (rendererd != null)) { _excludeHoles = false; } if (rendererd != null) { string axisX = series.AxisX; string axisY = series.AxisY; bool flag = !string.IsNullOrEmpty(axisX); bool flag2 = !string.IsNullOrEmpty(axisY); if (visual != null) { ChartViewport2D viewElement = visual.View.Viewport; if (viewElement != null) { if (flag || flag2) { foreach (Axis axis in viewElement.Axes) { if (flag && (axis.AxisName == axisX)) { _ax = axis; hasNan = true; } if (flag2 && (axis.AxisName == axisY)) { _ay = axis; hasNan = true; } } } _defax = viewElement._ax; _defay = viewElement._ay; } } } } if (visual.View != null) { ChartView view = visual.View; if (_ax != null) { XReversed = _ax.ReversedInternal; } else if (visual.View.AxisX != null) { XReversed = visual.View.AxisX.Reversed; } if (_ay != null) { YReversed = _ay.ReversedInternal; } else if (visual.View.AxisY != null) { YReversed = visual.View.AxisY.Reversed; } Axis axis2 = visual.View.GetAxisX(series); if ((axis2 != null) && !double.IsNaN(axis2.LogBase)) { hasNan = true; } Axis axis3 = visual.View.GetAxisY(series); if ((axis3 != null) && !double.IsNaN(axis3.LogBase)) { hasNan = true; } if ((renderer2 != null) && renderer2.Inverted) { if ((axis2 != null) && (axis2.PlotAreaIndex != 0)) { ClusterPlotAreaIndex = axis2.PlotAreaIndex; } } else if ((axis3 != null) && (axis3.PlotAreaIndex != 0)) { ClusterPlotAreaIndex = axis3.PlotAreaIndex; } } }
void PrepareAxes() { Renderer2D renderer = _view.Renderer as Renderer2D; int num = _axes.Count; for (int i = 0; i < num; i++) { Axis axis = _axes[i]; if ((axis != _ax) && (axis != _ay)) { Point min = new Point(double.NaN, double.NaN); Point max = new Point(double.NaN, double.NaN); if (renderer != null) { foreach (DataSeries series in renderer.Series) { bool flag = series.AxisX == axis.AxisName; bool flag2 = series.AxisY == axis.AxisName; if (flag || flag2) { series.GetMinMax(ref min, ref max); } } if (renderer.Inverted) { double x = min.X; min.X = min.Y; min.Y = x; x = max.X; max.X = max.Y; max.Y = x; } } switch (axis.AxisType) { case AxisType.X: axis.SetLimitsAux(min.X, max.X); break; case AxisType.Y: axis.SetLimitsAux(min.Y, max.Y); break; } } axis.RoundLimits(); if (axis.Axis.IsDependent) { double scale = 1.0; double num5 = 0.0; Func <double, double> dependentAxisConverter = axis.Axis.DependentAxisConverter; if (axis.AxisType == AxisType.X) { if (dependentAxisConverter != null) { double num6 = dependentAxisConverter(_ax.Min0); double num7 = dependentAxisConverter(_ax.Max0); if (num6 <= num7) { axis.Min0 = axis._min = num6; axis.Max0 = axis._max = num7; } else { axis.Min0 = axis._min = num7; axis.Max0 = axis._max = num6; } } else { axis.Min0 = axis._min = _ax.Min0; axis.Max0 = axis._max = _ax.Max0; } num5 = _ax.Axis.Value; scale = _ax.Axis.Scale; } else if (axis.AxisType == AxisType.Y) { if (dependentAxisConverter != null) { double num8 = dependentAxisConverter(_ay.Min0); double num9 = dependentAxisConverter(_ay.Max0); if (num8 <= num9) { axis.Min0 = axis._min = num8; axis.Max0 = axis._max = num9; } else { axis.Min0 = axis._min = num9; axis.Max0 = axis._max = num8; } } else { axis.Min0 = axis._min = _ay.Min0; axis.Max0 = axis._max = _ay.Max0; } num5 = _ay.Axis.Value; scale = _ay.Axis.Scale; } if (scale < 1.0) { double num10 = (axis.Max0 - axis.Min0) * scale; axis._min = axis.Min0 + (num5 * ((axis.Max0 - axis.Min0) - num10)); axis._max = axis._min + num10; } } axis.ClearLabelsAndTicks(); } }
void PerformPlotAreaLayout() { List <AreaDef> list = new List <AreaDef>(); List <AreaDef> list2 = new List <AreaDef>(); int num = _view.Axes.Count; for (int i = 0; i < num; i++) { Axis axis = _view.Axes[i]; if (axis.AxisType == AxisType.X) { while (list.Count <= axis.PlotAreaIndex) { list.Add(new AreaDef()); } list[axis.PlotAreaIndex].Axes.Add(axis); } else if (axis.AxisType == AxisType.Y) { while (list2.Count <= axis.PlotAreaIndex) { list2.Add(new AreaDef()); } list2[axis.PlotAreaIndex].Axes.Add(axis); } } int ncols = list.Count; int nrows = list2.Count; Renderer2D renderer = _view.Renderer as Renderer2D; Size size = new Size(CurrentSize.Width, 0.3 * CurrentSize.Height); Size size2 = new Size(CurrentSize.Height, 0.3 * CurrentSize.Width); double left = 0.0; double top = 0.0; double width = CurrentSize.Width; double height = CurrentSize.Height; for (int j = 0; j < ncols; j++) { AreaDef def = list[j]; def.Right = CurrentSize.Width; def.Bottom = CurrentSize.Height; for (int num10 = 0; num10 < def.Axes.Count; num10++) { AxisCanvas iax = def.Axes[num10].iax as AxisCanvas; Size size3 = iax.GetSize(GetItems(renderer, iax), false); if (size3.Height > size.Height) { size3.Height = size.Height; } size3.Width = size.Width; iax.DesiredSize = size3; if (j == 0) { def.Left = Math.Max(def.Left, iax.AnnoSize.Width * 0.5); } if (j == (ncols - 1)) { def.Right = Math.Min(def.Right, CurrentSize.Width - (iax.AnnoSize.Width * 0.5)); } if (iax.IsNear) { def.Bottom -= size3.Height; } else if (iax.IsFar) { def.Top += size3.Height; } } } for (int k = 0; k < nrows; k++) { AreaDef def2 = list2[k]; def2.Right = CurrentSize.Width; def2.Bottom = CurrentSize.Height; for (int num12 = 0; num12 < def2.Axes.Count; num12++) { AxisCanvas ax = def2.Axes[num12].iax as AxisCanvas; Size size4 = ax.GetSize(GetItems(renderer, ax), false); if (size4.Height > size2.Height) { size4.Height = size2.Height; } size4.Width = size2.Width; ax.DesiredSize = size4; if (k == 0) { def2.Top = Math.Max(def2.Top, ax.AnnoSize.Width * 0.5); } if (k == (nrows - 1)) { def2.Bottom = Math.Min(def2.Bottom, CurrentSize.Height - (ax.AnnoSize.Width * 0.5)); } if (ax.IsNear) { def2.Left += size4.Height; } else if (ax.IsFar) { def2.Right -= size4.Height; } } } double num13 = 0.0; double num14 = 0.0; double num15 = CurrentSize.Width; double num16 = CurrentSize.Height; for (int m = 0; m < ncols; m++) { AreaDef def3 = list[m]; num13 = Math.Max(num13, def3.Left); num14 = Math.Max(num14, def3.Top); num15 = Math.Min(num15, def3.Right); num16 = Math.Min(num16, def3.Bottom); } for (int n = 0; n < nrows; n++) { AreaDef def4 = list2[n]; num13 = Math.Max(num13, def4.Left); num14 = Math.Max(num14, def4.Top); num15 = Math.Min(num15, def4.Right); num16 = Math.Min(num16, def4.Bottom); } double w = 0.0; double h = 0.0; AdjustMargins(ref left, ref width, ref top, ref height, ref w, ref h, ref num13, ref num15, ref num14, ref num16); _plot = _plot0 = new Rect(left, top, w, h); double x = left; double[] numArray = _view.PlotAreas.CalculateWidths(w, ncols); int num22 = InternalChildren.Count - 1; for (int num23 = 0; num23 < ncols; num23++) { num16 = height; num14 = top; AreaDef def5 = list[num23]; double num24 = numArray[num23]; for (int num25 = 0; num25 < def5.Axes.Count; num25++) { AxisCanvas canvas3 = def5.Axes[num25].iax as AxisCanvas; canvas3._plot = new Rect(x, _plot0.Top, num24, _plot0.Height); Rect r = new Rect(); if (canvas3.IsNear) { r = new Rect(x, num16, num24, canvas3.DesiredSize.Height); num16 += canvas3.DesiredSize.Height; } else if (canvas3.IsFar) { r = new Rect(x, num14 - canvas3.DesiredSize.Height, num24, canvas3.DesiredSize.Height); num14 -= canvas3.DesiredSize.Height; } canvas3.Layout(r); if (((canvas3 == _ax) && (renderer != null)) && !renderer.Inverted) { canvas3.CreateLabels(renderer.ItemNames); } else { canvas3.CreateLabels(null); } canvas3.CreateAnnosAndTicks(false); } foreach (PlotArea area in _view.PlotAreas) { if (area.Column == num23) { area.SetPlotX(x, num24); } } x += num24; } double y = height; double[] numArray2 = _view.PlotAreas.CalculateHeights(h, nrows); for (int num27 = 0; num27 < nrows; num27++) { num13 = left; num15 = width; AreaDef def6 = list2[num27]; double num28 = numArray2[num27]; y -= num28; for (int num29 = 0; num29 < def6.Axes.Count; num29++) { AxisCanvas canvas4 = def6.Axes[num29].iax as AxisCanvas; canvas4._plot = new Rect(_plot0.Left, y, _plot0.Width, num28); Rect rect2 = new Rect(); if (canvas4.IsNear) { rect2 = new Rect(num13 - canvas4.DesiredSize.Height, y, num28, canvas4.DesiredSize.Height); num13 -= canvas4.DesiredSize.Height; } else if (canvas4.IsFar) { rect2 = new Rect(num15, y, num28, canvas4.DesiredSize.Height); num15 += canvas4.DesiredSize.Height; } canvas4.Layout(rect2); if (((canvas4 == _ay) && (renderer != null)) && renderer.Inverted) { canvas4.CreateLabels(renderer.ItemNames); } else { canvas4.CreateLabels(null); } canvas4.CreateAnnosAndTicks(false); } foreach (PlotArea area2 in _view.PlotAreas) { if (area2.Row == num27) { area2.SetPlotY(y, num28); } } } using (IEnumerator <PlotArea> enumerator = _view.PlotAreas.GetEnumerator()) { while (enumerator.MoveNext()) { UIElement uIElement = enumerator.Current.UIElement; if ((uIElement != null) && !InternalChildren.Contains(uIElement)) { InternalChildren.Insert(num22++, uIElement); } } } }
internal void Refresh() { if (CurrentSize.Width == 0 || CurrentSize.Height == 0) { return; } _ax.Axis = _view.AxisX; _ay.Axis = _view.AxisY; List <string> list = new List <string>(); foreach (Axis axis in _axes) { if ((axis.PositionInternal & AxisPosition.OverData) > AxisPosition.Near) { Canvas.SetZIndex(axis, 1); } else { Canvas.SetZIndex(axis, 0); } ((IAxis)axis).ClearLabels(); axis.ResetLimits(); axis.Chart = _view.Chart; if (((axis != _ax) && (axis != _ay)) && !string.IsNullOrEmpty(axis.AxisName)) { list.Add(axis.AxisName); } } if (_view.Renderer != null) { IView2DRenderer renderer = _view.Renderer as IView2DRenderer; if (renderer == null) { return; } _ast = renderer.Axis; Size sz = new Size(CurrentSize.Width, CurrentSize.Height); Renderer2D rendererd = renderer as Renderer2D; if (rendererd != null) { rendererd.ValidAuxAxes = list.ToArray(); if (_plot.Width > 0.0) { sz.Width = _plot.Width; } if (_plot.Height > 0.0) { sz.Height = _plot.Height; } } Rect rect = renderer.Measure(sz); if (rect.Width > 0.0) { _ax.SetLimits(rect.X, rect.X + rect.Width); } if (rect.Height > 0.0) { _ay.SetLimits(rect.Y, rect.Y + rect.Height); } } switch (_ast) { case AxisStyle.None: if ((base.Width > 10.0) && (base.Height > 10.0)) { _plot = new Rect(5.0, 5.0, base.Width - 10.0, base.Height - 10.0); } using (List <Axis> .Enumerator enumerator3 = _axes.GetEnumerator()) { while (enumerator3.MoveNext()) { enumerator3.Current.Visibility = Utils.VisHidden; } } break; case AxisStyle.Cartesian: UpdateLayoutCartesian(); break; case AxisStyle.Radar: using (List <Axis> .Enumerator enumerator2 = _axes.GetEnumerator()) { while (enumerator2.MoveNext()) { enumerator2.Current.Visibility = Visibility.Collapsed; } } UpdateLayoutRadar(); break; } Shape plotShape = _view.PlotShape; if (plotShape != null) { Canvas.SetLeft(plotShape, _view.PlotRect.Left); Canvas.SetTop(plotShape, _view.PlotRect.Top); plotShape.Width = _view.PlotRect.Width; plotShape.Height = _view.PlotRect.Height; if (_ast == AxisStyle.None) { plotShape.Visibility = Visibility.Collapsed; } else { plotShape.Visibility = Visibility.Visible; } } if (_view.Chart.UpdateCount <= 0 && _view.Renderer != null) { CreateDataObjects(); _view.Renderer.Dirty = false; } }
void UpdateLayoutCartesian() { PrepareAxes(); if (_view.HasPlotAreas) { PerformPlotAreaLayout(); return; } int num = _axes.Count; PlotArea area = _view.UpdateMainPlotArea(); Renderer2D renderer = _view.Renderer as Renderer2D; double xLeft = 0.0; double xTop = 0.0; double yLeft = 0.0; double yTop = 0.0; double width = CurrentSize.Width; double height = CurrentSize.Height; double right = CurrentSize.Width; double bottom = CurrentSize.Height; for (int i = 0; i < num; i++) { Axis ax = _axes[i]; double origin = ax.Axis.Origin; if (ax.AxisType == AxisType.X) { Size size = new Size(CurrentSize.Width, 0.3 * CurrentSize.Height); Size size3 = ax.GetSize(GetItems(renderer, ax), false); if (size3.Height > size.Height) { size3.Height = size.Height; } size3.Width = size.Width; ax.DesiredSize = size3; bool flag2 = (!double.IsNaN(origin) && (origin <= _ay.Max0)) && (origin >= _ay.Min0); if (ax.IsNear) { xLeft = Math.Max(xLeft, ax.AnnoSize.Width * 0.5); width = Math.Min(width, CurrentSize.Width - (ax.AnnoSize.Width * 0.5)); if (flag2) { double num12 = ConvertY(origin, xTop, bottom); bottom -= Math.Max((double)0.0, (double)((num12 + size3.Height) - bottom)); } else { bottom -= size3.Height; } } else if (ax.IsFar) { xLeft = Math.Max(xLeft, ax.AnnoSize.Width * 0.5); width = Math.Min(width, CurrentSize.Width - (ax.AnnoSize.Width * 0.5)); if (flag2) { double num13 = ConvertY(origin, xTop, bottom); xTop += Math.Max((double)0.0, (double)(xTop - (num13 - size3.Height))); } else { xTop += size3.Height; } } } else if (ax.AxisType == AxisType.Y) { Size size2 = new Size(CurrentSize.Height, 0.3 * CurrentSize.Width); Size size4 = ax.GetSize(GetItems(renderer, ax), false); if (size4.Height > size2.Height) { size4.Height = size2.Height; } size4.Width = size2.Width; ax.DesiredSize = size4; bool flag3 = (!double.IsNaN(origin) && (origin <= _ax.Max0)) && (origin >= _ax.Min0); if (ax.IsNear) { yTop = Math.Max(yTop, ax.AnnoSize.Width * 0.5); height = Math.Min(height, CurrentSize.Height - (ax.AnnoSize.Width * 0.5)); if (flag3) { double num14 = ConvertX(origin, yLeft, right); yLeft += Math.Max((double)0.0, (double)(yLeft - (num14 - size4.Height))); } else { yLeft += size4.Height; } } else if (ax.IsFar) { yTop = Math.Max(yTop, ax.AnnoSize.Width * 0.5); height = Math.Min(height, CurrentSize.Height - (ax.AnnoSize.Width * 0.5)); if (flag3) { double num15 = ConvertX(origin, yLeft, right); right -= Math.Max((double)0.0, (double)((num15 + size4.Height) - right)); } else { right -= size4.Height; } } } } double w = 0.0; double h = 0.0; AdjustMargins(ref xLeft, ref width, ref yTop, ref height, ref w, ref h, ref yLeft, ref right, ref xTop, ref bottom); _plot = _plot0 = new Rect(xLeft, yTop, w, h); if (area != null) { area.SetPlotX(_plot.X, _plot.Width); area.SetPlotY(_plot.Y, _plot.Height); UIElement uIElement = area.UIElement; if ((uIElement != null) && !InternalChildren.Contains(uIElement)) { InternalChildren.Insert(0, uIElement); } } for (int j = 0; j < num; j++) { Axis axis2 = _axes[j]; axis2._plot = _plot0; double d = axis2.Axis.Origin; if (axis2.AxisType == AxisType.X) { Rect r = new Rect(); if ((double.IsNaN(d) || (d > _ay.Max0)) || (d < _ay.Min0)) { if (axis2.IsNear) { r = new Rect(xLeft, bottom, w, axis2.DesiredSize.Height); bottom += axis2.DesiredSize.Height; } else if (axis2.IsFar) { r = new Rect(xLeft, xTop - axis2.DesiredSize.Height, w, axis2.DesiredSize.Height); xTop -= axis2.DesiredSize.Height; } } else { double y = ConvertY(d, _plot.Top, _plot.Bottom); if (axis2.IsNear) { r = new Rect(xLeft, y, w, axis2.DesiredSize.Height); bottom += Math.Max((double)0.0, (double)(r.Bottom - _plot.Bottom)); } else if (axis2.IsFar) { r = new Rect(xLeft, y - axis2.DesiredSize.Height, w, axis2.DesiredSize.Height); xTop -= Math.Max((double)0.0, (double)(_plot.Top - r.Top)); } } axis2.Layout(r); } else if (axis2.AxisType == AxisType.Y) { Rect rect2 = new Rect(); if ((double.IsNaN(d) || (d > _ax.Max0)) || (d < _ax.Min0)) { if (axis2.IsNear) { rect2 = new Rect(yLeft - axis2.DesiredSize.Height, yTop, h, axis2.DesiredSize.Height); yLeft -= axis2.DesiredSize.Height; } else if (axis2.IsFar) { rect2 = new Rect(right, yTop, h, axis2.DesiredSize.Height); right += axis2.DesiredSize.Height; } } else { double x = ConvertX(d, _plot.Left, _plot.Right); if (axis2.IsNear) { rect2 = new Rect(x - axis2.DesiredSize.Height, yTop, h, axis2.DesiredSize.Height); yLeft -= axis2.DesiredSize.Height; } else if (axis2.IsFar) { rect2 = new Rect(x, yTop, h, axis2.DesiredSize.Height); right += axis2.DesiredSize.Height; } } axis2.Layout(rect2); } if (((axis2 == _ax) && (renderer != null)) && !renderer.Inverted) { axis2.CreateLabels(renderer.ItemNames); } else if (((axis2 == _ay) && (renderer != null)) && renderer.Inverted) { axis2.CreateLabels(renderer.ItemNames); } else { axis2.CreateLabels(null); } axis2.CreateAnnosAndTicks(false); } }