using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using ChartForgeX.Core;
using ChartForgeX.Primitives;
using ChartForgeX.Rendering;
using ChartForgeX.Themes;
using ChartForgeX.Topology;
using ChartForgeX.Typography;
using ChartForgeX.VisualArtifacts;
using ChartForgeX.VisualBlocks;
var mode = VisualThemeMode.Light;
var theme = VisualTheme.Graphite();
var model = ScatterMarkerShapesRecipe.Create("compact-options", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
new VisualFrame("Processing time by workload", "Nine marker shapes with source labels", showLegend: false, showSurface: false));
var prepared = model.Prepare(context);
File.WriteAllText("visual.svg", prepared.ToSvg());
File.WriteAllBytes("visual.png", prepared.ToPng());
File.WriteAllText("visual.html", prepared.ToArtifact("example", VisualArtifactKind.Chart).ToHtmlPage());
/// Shows the available scatter marker shapes with captions.
public static class ScatterMarkerShapesRecipe {
/// Creates the selected example without choosing a renderer or export backend.
public static Chart Create(string variant = "options", VisualThemeMode mode = VisualThemeMode.Light) {
if (variant is not ("options" or "compact-options")) throw new ArgumentOutOfRangeException(nameof(variant));
return MarkerShapes().WithValueFormat(ChartValueFormat.Number("0.##", CultureInfo.InvariantCulture));
}
private static Chart MarkerShapes() {
var chart = Chart.Create().WithXAxis("Sample position").WithYAxis("Example level");
var shapes = Enum.GetValues();
for (var index = 0; index < shapes.Length; index++) {
var shape = shapes[index];
var sample = ChartSeries.CreateScatter(new ChartSeriesId("marker-" + shape.ToString().ToLowerInvariant()), shape.ToString(),
new[] { new ChartPoint(index % 3 + 1, index / 3 + 1) });
sample.WithPointLabel(0, shape.ToString()).WithDataLabels()
.ConfigureMarkers(markers => { markers.Shape = shape; markers.Radius = 8; markers.StrokeWidth = 1; });
chart.AddSeries(sample);
}
chart.Options.XAxis.WithBounds(0, 4);
chart.Options.YAxis.WithBounds(0, 4);
return chart;
}
}