Skip to content

Instantly share code, notes, and snippets.

@VisualMelon VisualMelon/testing.cs
Last active Sep 20, 2017

Embed
What would you like to do?
SVG Text Rendering Testing
var model = new PlotModel { Title = "SVG Text Rendering" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A",
    TextPosition = new DataPoint(1080),
    TextVerticalAlignment = VerticalAlignment.Bottom,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A\r\nA",
    TextPosition = new DataPoint(2080),
    TextVerticalAlignment = VerticalAlignment.Bottom,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A\r\nA\r\nA",
    TextPosition = new DataPoint(3080),
    TextVerticalAlignment = VerticalAlignment.Bottom,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A\r\nA\r\nA\r\nA",
    TextPosition = new DataPoint(4080),
    TextVerticalAlignment = VerticalAlignment.Bottom,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A\r\nA\r\nA\r\nA\r\nA",
    TextPosition = new DataPoint(5080),
    TextVerticalAlignment = VerticalAlignment.Bottom,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A",
    TextPosition = new DataPoint(1070),
    TextVerticalAlignment = VerticalAlignment.Top,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A\r\nA",
    TextPosition = new DataPoint(2070),
    TextVerticalAlignment = VerticalAlignment.Top,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A\r\nA\r\nA",
    TextPosition = new DataPoint(3070),
    TextVerticalAlignment = VerticalAlignment.Top,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A\r\nA\r\nA\r\nA",
    TextPosition = new DataPoint(4070),
    TextVerticalAlignment = VerticalAlignment.Top,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A\r\nA\r\nA\r\nA\r\nA",
    TextPosition = new DataPoint(5070),
    TextVerticalAlignment = VerticalAlignment.Top,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "Hello1\r\nHello2\r\nHello3\r\nHello4",
    TextPosition = new DataPoint(8020),
    TextVerticalAlignment = VerticalAlignment.Middle,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "H\r\nHe\r\nHel\r\nHell\r\nHello",
    TextPosition = new DataPoint(8040),
    TextVerticalAlignment = VerticalAlignment.Middle,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "Hello1\r\nBottom\r\nHello3",
    TextPosition = new DataPoint(2040),
    TextRotation = -45,
    TextVerticalAlignment = VerticalAlignment.Bottom,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "Hello1\r\nMiddle\r\nHello3",
    TextPosition = new DataPoint(4040),
    TextRotation = -45,
    TextVerticalAlignment = VerticalAlignment.Middle,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "Hello1\r\nTop\r\nHello3",
    TextPosition = new DataPoint(6040),
    TextRotation = -45,
    TextVerticalAlignment = VerticalAlignment.Top,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "Hello1\r\nBottom\r\nHello3",
    TextPosition = new DataPoint(2020),
    TextRotation = 45,
    TextVerticalAlignment = VerticalAlignment.Bottom,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "Hello1\r\nMiddle\r\nHello3",
    TextPosition = new DataPoint(4020),
    TextRotation = 45,
    TextVerticalAlignment = VerticalAlignment.Middle,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "Hello1\r\nTop\r\nHello3",
    TextPosition = new DataPoint(6020),
    TextRotation = 45,
    TextVerticalAlignment = VerticalAlignment.Top,
});
OxyPlot.WindowsForms.PlotView plotView = new OxyPlot.WindowsForms.PlotView();
plotView.Model = model;
this.Controls.Add(plotView);
plotView.Invalidate();
plotView.Dock = DockStyle.Fill;
this.Refresh();
SvgExporter svgExporter = new SvgExporter();
using (var fs = System.IO.File.Open("test2.svg", System.IO.FileMode.Create))
{
    svgExporter.Export(modelfs);
}
svgExporter = new SvgExporter();
svgExporter.UseVerticalTextAlignmentWorkaround = true;
using (var fs = System.IO.File.Open("test3.svg", System.IO.FileMode.Create))
{
    svgExporter.Export(modelfs);
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.