in dotnet/WinForms/VisualLayerIntegration/VisualLayerIntegration/BarGraphUtility/BarGraph.cs [94:147]
public BarGraph(Compositor compositor, IntPtr hwnd, string title, string xAxisLabel, // required parameters
string yAxisLabel, float width, float height, double dpiX, double dpiY, float[] data,// required parameters
bool AnimationsOn = true, GraphBarStyle graphBarStyle = GraphBarStyle.Single, // optional parameters
List<Windows.UI.Color> barColors = null)
{
this.compositor = compositor;
this.hwnd = hwnd;
this.graphWidth = (float)(width * dpiX / 96.0);
this.graphHeight = (float)(height * dpiY / 96.0);
this.graphData = data;
Title = title;
XAxisLabel = xAxisLabel;
YAxisLabel = yAxisLabel;
this.graphBarStyle = graphBarStyle;
if (barColors != null)
{
graphBarColors = barColors;
}
else
{
graphBarColors = new List<Windows.UI.Color>() { Colors.Blue };
}
// Configure options for text.
var Factory2D = new SharpDX.Direct2D1.Factory();
var properties = new HwndRenderTargetProperties();
properties.Hwnd = this.hwnd;
properties.PixelSize = new SharpDX.Size2((int)(width * dpiX / 96.0), (int)(width * dpiY / 96.0));
properties.PresentOptions = PresentOptions.None;
textRenderTarget = new WindowRenderTarget(Factory2D, new RenderTargetProperties(new PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied)), properties);
textRenderTarget.DotsPerInch = new Size2F((float)dpiX, (float)dpiY);
textRenderTarget.Resize(new Size2((int)(width * dpiX / 96.0), (int)(width * dpiY / 96.0)));
// Generate graph structure.
var graphRoot = GenerateGraphStructure();
GraphRoot = graphRoot;
BarRoot = this.compositor.CreateContainerVisual();
GraphRoot.Children.InsertAtBottom(BarRoot);
// If data has been provided, initialize bars and animations; otherwise, leave graph empty.
if (graphData.Length > 0)
{
barValueMap = new Hashtable();
var bars = CreateBars(graphData);
AddBarsToTree(bars);
}
}