public AxisLimits2D(AxisLimits2D source) { x1 = source.x1; x2 = source.x2; y1 = source.y1; y2 = source.y2; }
public void ExpandY(AxisLimits2D source) { if (source != null) { ExpandY(source.y1, source.y2); } }
public void ExpandX(AxisLimits2D source) { if (source != null) { ExpandX(source.x1, source.x2); } }
public void Resize(int width, int height, bool useMeasuredStrings = false) { if (useMeasuredStrings && gfxData != null) { // this section was added before display scaling issues (pixel-referenced font sizes) were figured out. // it is probably not needed... string sampleString = "IPjg8.8"; layout.yLabelWidth = (int)GDI.MeasureString(gfxData, sampleString, yLabel.font).Height; layout.y2LabelWidth = (int)GDI.MeasureString(gfxData, sampleString, yLabel.font).Height; // currently y2 isn't supported layout.titleHeight = (int)GDI.MeasureString(gfxData, sampleString, title.font).Height; layout.xLabelHeight = (int)GDI.MeasureString(gfxData, sampleString, xLabel.font).Height; var tickSize = GDI.MeasureString(gfxData, "0.001", ticks.font); layout.yScaleWidth = (int)tickSize.Width; layout.y2ScaleWidth = (int)tickSize.Height; // currently y2 isn't supported layout.xScaleHeight = (int)tickSize.Height; } layout.Update(width, height); if (axes.equalAxes) { var limits = new AxisLimits2D(axes.ToArray()); double xUnitsPerPixel = limits.xSpan / dataSize.Width; double yUnitsPerPixel = limits.ySpan / dataSize.Height; if (yUnitsPerPixel > xUnitsPerPixel) { axes.Zoom(xUnitsPerPixel / yUnitsPerPixel, 1); } else { axes.Zoom(1, yUnitsPerPixel / xUnitsPerPixel); } } }
public void AxisAuto( double horizontalMargin = .1, double verticalMargin = .1, bool xExpandOnly = false, bool yExpandOnly = false, bool autoX = true, bool autoY = true ) { var oldLimits = new AxisLimits2D(axes.ToArray()); var newLimits = new AxisLimits2D(); foreach (var plottable in plottables) { AxisLimits2D plottableLimits = plottable.GetLimits(); if (autoX && !yExpandOnly) { newLimits.ExpandX(plottableLimits); } if (autoY && !xExpandOnly) { newLimits.ExpandY(plottableLimits); } } newLimits.MakeRational(); if (axes.equalAxes) { var xUnitsPerPixel = newLimits.xSpan / (dataSize.Width * (1 - horizontalMargin)); var yUnitsPerPixel = newLimits.ySpan / (dataSize.Height * (1 - verticalMargin)); axes.Set(newLimits); if (yUnitsPerPixel > xUnitsPerPixel) { axes.Zoom((1 - horizontalMargin) * xUnitsPerPixel / yUnitsPerPixel, 1 - verticalMargin); } else { axes.Zoom(1 - horizontalMargin, (1 - verticalMargin) * yUnitsPerPixel / xUnitsPerPixel); } return; } if (xExpandOnly) { oldLimits.ExpandX(newLimits); axes.Set(oldLimits.x1, oldLimits.x2, null, null); axes.Zoom(1 - horizontalMargin, 1); } if (yExpandOnly) { oldLimits.ExpandY(newLimits); axes.Set(null, null, oldLimits.y1, oldLimits.y2); axes.Zoom(1, 1 - verticalMargin); } if ((!xExpandOnly) && (!yExpandOnly)) { axes.Set(newLimits); axes.Zoom(1 - horizontalMargin, 1 - verticalMargin); } if (plottables.Count == 0) { axes.x.hasBeenSet = false; axes.y.hasBeenSet = false; } layout.tighteningOccurred = false; }
public void ExpandXY(AxisLimits2D source) { ExpandX(source.x1, source.x2); ExpandY(source.y1, source.y2); }
public void SetY(AxisLimits2D source) { SetY(source.y1, source.y2); }
public void SetX(AxisLimits2D source) { SetX(source.x1, source.x2); }
public void Set(AxisLimits2D limits) { limits.MakeRational(); Set(limits.x1, limits.x2, limits.y1, limits.y2); }
public override void Render(Settings settings) { double[] proportions = values.Select(x => x / values.Sum()).ToArray(); int outlineWidth = 1; int sliceOutlineWidth = 0; if (explodedChart) { pen.Color = settings.DataBackground.Colour; // TODO: will fail if data background is transparent outlineWidth = 20; sliceOutlineWidth = 1; } AxisLimits2D limits = GetLimits(); double centreX = limits.xCenter; double centreY = limits.yCenter; float diameterPixels = .9f * Math.Min(settings.dataSize.Width, settings.dataSize.Height); string fontName = Fonts.GetSansFontName(); float fontSize = 12; // record label details and draw them after slices to prevent cover-ups double[] labelXs = new double[values.Length]; double[] labelYs = new double[values.Length]; string[] labelStrings = new string[values.Length]; RectangleF boundingRectangle = new RectangleF((float)settings.GetPixelX(centreX) - diameterPixels / 2, (float)settings.GetPixelY(centreY) - diameterPixels / 2, diameterPixels, diameterPixels); double start = -90; for (int i = 0; i < values.Length; i++) { // determine where the slice is to be drawn double sweep = proportions[i] * 360; double sweepOffset = explodedChart ? -1 : 0; double angle = (Math.PI / 180) * ((sweep + 2 * start) / 2); double xOffset = explodedChart ? 3 * Math.Cos(angle) : 0; double yOffset = explodedChart ? 3 * Math.Sin(angle) : 0; // record where and what to label the slice double sliceLabelR = 0.35 * diameterPixels; labelXs[i] = (boundingRectangle.X + diameterPixels / 2 + xOffset + Math.Cos(angle) * sliceLabelR); labelYs[i] = (boundingRectangle.Y + diameterPixels / 2 + yOffset + Math.Sin(angle) * sliceLabelR); string sliceLabelValue = (showValues) ? $"{values[i]}" : ""; string sliceLabelPercentage = (showPercentages) ? $"{proportions[i] * 100:f1}%" : ""; string sliceLabelName = (showLabels) ? groupNames[i] : ""; labelStrings[i] = $"{sliceLabelValue}\n{sliceLabelPercentage}\n{sliceLabelName}".Trim(); brush.Color = colors[i]; settings.gfxData.FillPie(brush, (int)(boundingRectangle.X + xOffset), (int)(boundingRectangle.Y + yOffset), boundingRectangle.Width, boundingRectangle.Height, (float)start, (float)(sweep + sweepOffset)); if (explodedChart) { pen.Width = sliceOutlineWidth; settings.gfxData.DrawPie(pen, (int)(boundingRectangle.X + xOffset), (int)(boundingRectangle.Y + yOffset), boundingRectangle.Width, boundingRectangle.Height, (float)start, (float)(sweep + sweepOffset)); } start += sweep; } brush.Color = Color.White; var font = new Font(fontName, fontSize); for (int i = 0; i < values.Length; i++) { if (!string.IsNullOrWhiteSpace(labelStrings[i])) { settings.gfxData.DrawString(labelStrings[i], font, brush, (float)labelXs[i], (float)labelYs[i], settings.misc.sfCenterCenter); } } pen.Width = outlineWidth; settings.gfxData.DrawEllipse(pen, boundingRectangle.X, boundingRectangle.Y, boundingRectangle.Width, boundingRectangle.Height); }