/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { PieChartData data = null; PieChartStyle style = null; if (!DA.GetData <PieChartData>(0, ref data)) { return; } if (!DA.GetData <PieChartStyle>(1, ref style)) { return; } D3jsLib.PieChart.PieChart chart = new D3jsLib.PieChart.PieChart(data, style); DA.SetData(0, chart); }
/// <summary> /// Pie Chart Style /// </summary> /// <param name="HoverColor">Hover over color.</param> /// <param name="Colors">List of optional colors for chart values.</param> /// <param name="Address">Grid Coordinates.</param> /// <param name="Margins">Margins in pixels.</param> /// <param name="Width">Width of chart in pixels.</param> /// <param name="Labels">Boolean value that controls if Labels are displayed.</param> /// <returns name="Style">Pie Chart Style object.</returns> public static PieChartStyle Style( [DefaultArgument("DSCore.Color.ByARGB(1,255,0,0)")] DSCore.Color HoverColor, [DefaultArgumentAttribute("Charts.MiscNodes.GetNull()")] List <DSCore.Color> Colors, [DefaultArgument("Charts.MiscNodes.GetNull()")] GridAddress Address, [DefaultArgument("Charts.MiscNodes.Margins()")] Margins Margins, int Width = 400, bool Labels = true) { PieChartStyle style = new PieChartStyle(); style.Width = Width; style.HoverColor = ChartsUtilities.ColorToHexString(sColor.FromArgb(HoverColor.Alpha, HoverColor.Red, HoverColor.Green, HoverColor.Blue)); style.Labels = Labels; style.Margins = Margins; style.SizeX = (int)System.Math.Ceiling(Width / 100d); style.SizeY = (int)System.Math.Ceiling(Width / 100d); if (Colors != null) { List <string> hexColors = Colors.Select(x => ChartsUtilities.ColorToHexString(sColor.FromArgb(x.Alpha, x.Red, x.Green, x.Blue))).ToList(); style.Colors = new JavaScriptSerializer().Serialize(hexColors); } else { style.Colors = null; } if (Address != null) { style.GridRow = Address.X; style.GridColumn = Address.Y; } else { style.GridRow = 1; style.GridColumn = 1; } return(style); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Color hoverColor = Color.FromArgb(255, 0, 0); List <Color> colors = new List <Color>(); GridAddress address = new GridAddress(1, 1); Margins margins = new Margins(); int width = 400; bool labels = true; DA.GetData <Color>(0, ref hoverColor); DA.GetData <GridAddress>(2, ref address); DA.GetData <Margins>(3, ref margins); DA.GetData <int>(4, ref width); DA.GetData <bool>(5, ref labels); // create style PieChartStyle style = new PieChartStyle(); if (DA.GetDataList <Color>(1, colors)) { List <string> hexColors = colors.Select(x => ChartsUtilities.ColorToHexString(Color.FromArgb(x.A, x.R, x.G, x.B))).ToList(); style.Colors = new JavaScriptSerializer().Serialize(hexColors); } else { style.Colors = null; } style.HoverColor = ChartsUtilities.ColorToHexString(hoverColor); style.GridRow = address.X; style.GridColumn = address.Y; style.Width = width; style.Labels = labels; style.Margins = margins; style.SizeX = (int)Math.Ceiling(width / 100d); style.SizeY = (int)Math.Ceiling(width / 100d); DA.SetData(0, style); }
/// <summary> /// Pie chart /// </summary> /// <param name="Data">Pie Chart data object.</param> /// <param name="Style">Pie Chart Style object.</param> /// <returns name="Chart">Pie Chart object.</returns> public static D3jsLib.PieChart.PieChart Chart(PieChartData Data, PieChartStyle Style) { D3jsLib.PieChart.PieChart chart = new D3jsLib.PieChart.PieChart(Data, Style); return(chart); }