// Make a row of bars in the X direction. private void MakeBars(double xmin, double ymin, double zmin, double dx, double gap, double[] values, string[] frontLabels, string[] topLabels, Brush[] barBrushes, Brush[] bgBrushes, Brush[] fgBrushes, FontFamily ff, Model3DGroup group) { double x = xmin; double fontSize = 0.4; for (int i = 0; i < values.Length; i++) { // Make the bar. MeshGeometry3D barMesh = new MeshGeometry3D(); Point3D corner = new Point3D(x, ymin, zmin); barMesh.AddBox(corner, D3.XVector(dx), D3.YVector(YScale * values[i]), D3.ZVector(dx)); group.Children.Add(barMesh.MakeModel(barBrushes[i])); // Display the front label. const double textWid = 1.8; MakeLabel(frontLabels[i], new Point3D(x + dx, ymin, textWid + zmin + dx + gap), D3.ZVector(-textWid), D3.XVector(-dx), bgBrushes[i], fgBrushes[i], fontSize, ff, HorizontalAlignment.Left, VerticalAlignment.Center, group); // Display the top label. MakeLabel(topLabels[i], new Point3D(x, ymin + YScale * values[i], zmin - 0.1), D3.XVector(dx), D3.YVector(dx), Brushes.Transparent, fgBrushes[i], fontSize, ff, HorizontalAlignment.Center, VerticalAlignment.Bottom, group); x += dx + gap; } }
// Define the model. private void DefineModel(Model3DGroup group) { // Axes. //MeshExtensions.AddAxes(group); // General positioning parameters. Point3D origin = new Point3D(0, -1, 0); double barDx = 1; double barGap = 0.25; // Load the data. double[] values = LoadData(); int numValues = values.Length; string[] frontLabels = { " Sofa", " Bathroom", " Dresser", " Fridge or\n Freezer", " Outside", " Other" }; string[] topLabels = new string[numValues]; for (int i = 0; i < numValues; i++) { topLabels[i] = values[i].ToString("P0"); } Brush[] barBrushes = { Brushes.Red, Brushes.Green, Brushes.Blue, Brushes.Yellow, Brushes.Orange, Brushes.Fuchsia, }; Brush[] bgBrushes = { Brushes.HotPink, Brushes.LightGreen, Brushes.LightBlue, new SolidColorBrush(Color.FromArgb(255, 255, 255, 100)), new SolidColorBrush(Color.FromArgb(255, 255, 220, 100)), new SolidColorBrush(Color.FromArgb(255, 255, 128, 255)), }; Brush[] fgBrushes = { Brushes.Black, Brushes.Black, Brushes.Black, Brushes.Black, Brushes.Black, Brushes.Black, }; // See how big the bars will be. double wid = numValues * barDx + (numValues - 1) * barGap; double hgt = values.Max() * YScale; double barXmin = origin.X - wid / 2; double barXmax = barXmin + wid; double barYmin = origin.Y; double barYmax = barYmin + hgt; double barZmin = origin.Z - barDx / 2; double barZmax = barZmin + barDx; // Bars. FontFamily ff = new FontFamily("Franklin Gothic Demi"); MakeBars(barXmin, barYmin, barZmin, barDx, barGap, values, frontLabels, topLabels, barBrushes, bgBrushes, fgBrushes, ff, group); // Title. double fontSize = 0.75; MakeLabel("Where's My", new Point3D(barXmin, barYmax - 1, barZmin - 0.1), D3.XVector(wid), D3.YVector(1), Brushes.Transparent, Brushes.DarkBlue, fontSize, ff, HorizontalAlignment.Center, VerticalAlignment.Center, group); MakeLabel("Remote?", new Point3D(barXmin, barYmax - 0.75 - 1, barZmin - 0.1), D3.XVector(wid), D3.YVector(1), Brushes.Transparent, Brushes.DarkBlue, fontSize, ff, HorizontalAlignment.Center, VerticalAlignment.Center, group); }