public override ChartBase GetChart(Visualization viz) { ChartBase chart = null; switch (viz) { case Visualization.None: break; case Visualization.Table: break; case Visualization.LineSingleRegimen: case Visualization.LineSingleTumor: case Visualization.LineMultiTumorMultiRegimen: chart = new IRLineChartGroup(viz); break; case Visualization.StackedBar: chart = new IRStackedBarChart(); break; case Visualization.Pie: chart = new IRPieChartGroup(); break; default: break; } return(chart); }
/// <summary> /// Export GearChart data to .csv file. /// </summary> /// <remarks>NOTE: This is specific to Gear Chart and may not work properly for other track types.</remarks> public static void ExportGearTracks(ChartBase chart, string name) { ChartDataSeries rawSeries = null, estimateSeries = null; foreach (ChartDataSeries series in chart.DataSeries) { if (series.LineColor == Color.Blue) { estimateSeries = series; } else if (series.LineColor == Color.Red) { rawSeries = series; } } try { Cursor.Current = Cursors.WaitCursor; System.IO.StreamWriter writer = new System.IO.StreamWriter(name); // Write Header if (estimateSeries != null && rawSeries != null) { writer.WriteLine(chart.XAxis.Label + ", Raw, Estimate"); foreach (PointF item in rawSeries.Points.Values) { // Write data float x = item.X; writer.WriteLine(item.X + ", " + item.Y + ", " + estimateSeries.GetYValueAtX(ref x)); } } else if (rawSeries != null) { writer.WriteLine(chart.XAxis.Label + ", Raw"); foreach (PointF item in rawSeries.Points.Values) { // Write data writer.WriteLine(item.X + ", " + item.Y + ", "); } } else { writer.WriteLine(chart.XAxis.Label + ", Estimate"); foreach (PointF item in estimateSeries.Points.Values) { // Write data writer.WriteLine(item.X + ", " + item.Y); } } writer.Close(); MessageDialog.Show(CommonResources.Text.MessageExportComplete, Resources.Strings.GearSelection, MessageBoxButtons.OK); } catch { } finally { Cursor.Current = Cursors.Default; } }
public static List<LimitData> BuildStaticLclLimit(ChartBase dataContext, bool calculatedCLs) { var list = new List<LimitData>(); if (calculatedCLs) { var category = 1; for (var i = 0; i < dataContext.DataSource.Count; i++) { list.Add(new LimitData(category, dataContext.LCL)); category++; } } else { var category = 1; for (var i = 0; i < dataContext.DataSource.Count; i++) { list.Add(new LimitData(category, dataContext.ParentPanel.CustomLCL)); category++; } } return list; }
public DataPointGroup(ChartBase parentChart, string caption, bool showcaption) { ParentChart = parentChart; Caption = caption; ShowCaption = showcaption; DataPoints = new ObservableCollection <DataPoint>(); DataPoints.CollectionChanged += Items_CollectionChanged; }
private void buttonParameters_Click(object sender, RibbonControlEventArgs e) { Excel.Chart chart = Globals.ThisAddIn.Application.ActiveChart; if (chart != null && Globals.ThisAddIn.Charts.Select(c => c.Chart).Contains(chart)) { ChartBase ch = Globals.ThisAddIn.Charts.Where(c => c.Chart == chart).First(); TreemapChart treemap = (TreemapChart)ch; } }
public DataPointGroup(ChartBase parentChart, string caption, bool showcaption) { ParentChart = parentChart; Caption = caption; ShowCaption = showcaption; DataPoints = new ObservableCollection<DataPoint>(); DataPoints.CollectionChanged += Items_CollectionChanged; }
public void DrawChart <T>(ContentControl view, ChartBase chartBase) where T : ChartViewModelBase { var viewModel = view.DataContext as T; if (viewModel != null && chartBase != null) { viewModel.ChartInstance = chartBase; viewModel.FillChartData(); } }
public void Chart(Chart c, Row row, ChartBase cb) { System.Drawing.Image im = cb.Image(r); PutImage(im, im.Width, im.Height); if (InTable(c)) { tw.Write(@"\cell"); } }
ChartBase RunChartBuild(Report rpt, Row row) { // Get the matrix that defines the data; _ChartMatrix.SetMyData(rpt, GetMyData(rpt)); // set the data in the matrix int maxColumns; int maxRows; MatrixCellEntry[,] matrix = _ChartMatrix.RunBuild(rpt, out maxRows, out maxColumns); // Build the Chart bitmap, along with data regions ChartBase cb = null; switch (_Type) { case ChartTypeEnum.Column: cb = new ChartColumn(rpt, row, this, matrix, _showTooltips, _showTooltipsX, _ToolTipYFormat, _ToolTipXFormat); break; case ChartTypeEnum.Line: case ChartTypeEnum.Area: // handled by line cb = new ChartLine(rpt, row, this, matrix, _showTooltips, _showTooltipsX, _ToolTipYFormat, _ToolTipXFormat); break; case ChartTypeEnum.Bar: cb = new ChartBar(rpt, row, this, matrix, _showTooltips, _showTooltipsX, _ToolTipYFormat, _ToolTipXFormat); break; case ChartTypeEnum.Pie: case ChartTypeEnum.Doughnut: // handled by pie cb = new ChartPie(rpt, row, this, matrix, _showTooltips, _showTooltipsX, _ToolTipYFormat, _ToolTipXFormat); break; case ChartTypeEnum.Bubble: case ChartTypeEnum.Scatter: cb = new ChartBubble(rpt, row, this, matrix, _showTooltips, _showTooltipsX, _ToolTipYFormat, _ToolTipXFormat); break; case ChartTypeEnum.Map: cb = new ChartMap(rpt, row, this, matrix, _showTooltips, _showTooltipsX, _ToolTipYFormat, _ToolTipXFormat); break; case ChartTypeEnum.Stock: default: cb = new ChartColumn(rpt, row, this, matrix, _showTooltips, _showTooltipsX, _ToolTipYFormat, _ToolTipXFormat); break; } return(cb); }
//fuction public override void CalculateResult(DataTable i_Table) { ChangeTypesFor3D(); if (i_Table != null) { Webb.Collections.Int32Collection rows = new Int32Collection(); Webb.Data.DBFilter dbFilter = this.Filter.Copy(); if (this.ExControl != null && this.ExControl.Report != null) { rows = this.ExControl.Report.Filter.GetFilteredRows(i_Table); //2009-5-25 11:02:57@Simon Add this Code dbFilter.Add(this.ExControl.Report.Filter); } if (this.DenominatorFilter == null) { if (this.Repeat) { this.DenominatorFilter = dbFilter; } else if (this.ExControl != null && this.ExControl.Report != null && this.ExControl.Report.OneValuePerPage) { this.DenominatorFilter = dbFilter; } else { this.DenominatorFilter = new Webb.Data.DBFilter(); } } rows = this.OneValueScFilter.Filter.GetFilteredRows(i_Table, rows); rows = this.RepeatFilter.Filter.GetFilteredRows(i_Table, rows); //Added this code at 2008-12-26 12:22:40@Simon this.Filter = AdvFilterConvertor.GetAdvFilter(DataProvider.VideoPlayBackManager.AdvReportFilters, this.Filter); //2009-4-29 11:37:37@Simon Add UpdateAdvFilter rows = this.Filter.GetFilteredRows(i_Table, rows); this._Chart = this.Settings.CreateChart(i_Table, rows); } else { this._Chart = this.Settings.CreateChart(null, null); } }
private void C_PBPreview_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { ChartBase chart = null; if (this._DesignerForm != null && this._DesignerForm.ExControlView is WebbChartExView) { //12-16-2008@Scott WebbChartExView chartView = this._DesignerForm.ExControlView as WebbChartExView; System.Data.DataTable table = chartView.ExControl.GetDataSource(); if (table == null) { chart = Setting.CreateChart(View.ExControl.GetDataSource(), null); } else { Webb.Collections.Int32Collection rows = chartView.Filter.GetFilteredRows(table); if (chartView.ExControl != null) { if (chartView.ExControl.Report != null) { rows = chartView.ExControl.Report.Filter.GetFilteredRows(table, rows); //2009-5-25 11:02:57@Simon Add this Code } } chart = Setting.CreateChart(View.ExControl.GetDataSource(), rows); } } else { chart = Setting.CreateChart(View.ExControl.GetDataSource(), null); } if (chart != null) { chart.Draw(e.Graphics, this.C_PBPreview.ClientRectangle); } }
override internal void Run(IPresent ip, Row row) { Report rpt = ip.Report(); _ChartMatrix.RunReset(rpt); Rows _Data = GetFilteredData(ip.Report(), row); SetMyData(ip.Report(), _Data); if (!AnyRows(ip, _Data)) // if no rows, return { return; } // Build the Chart bitmap, along with data regions ChartBase cb = null; try { cb = RunChartBuild(rpt, row); ip.Chart(this, row, cb); } catch (Exception ex) { rpt.rl.LogError(8, string.Format("Exception in Chart handling.\n{0}\n{1}", ex.Message, ex.StackTrace)); } finally { if (cb != null) { cb.Dispose(); } } return; }
public void RefreshPage() { // Clear Chart ChartBase chart = detailPaneChart.Chart; detailPaneChart.ChartDataClear(); gearSelection = new NumericTimeDataSeries(); if (activity != null) { // Get Gear Track (raw data) gearSelection = GearUtils.GetRawGearTrack(activity); if (chartType == ChartBasis.Gear_Time) { gearSelection = GearUtils.RemovePausedTimesInTrack(gearSelection, activity); } if (gearSelection.Count != 0) { // Smooth data series float min, max; gearSelection = ZoneFiveSoftware.Common.Data.Algorithm.NumericTimeDataSeries.Smooth(gearSelection, Constants.GearTrackSmoothing, out max, out min); //gearSelection = ZoneFiveSoftware.Common.Data.Algorithm.NumericTimeDataSeries.Smooth(gearSelection, 10, out max, out min); //********************************************* // Initialize variables for activity grade impact, and full category impact ChartDataSeries rawGears = new ChartDataSeries(chart, chart.YAxis); // ChartDataSeries rawGears = PopulateDataSeries(gearSelection, rawGears, ChartType, activity); rawGears.ChartType = ChartDataSeries.Type.Line; rawGears.LineColor = Color.Red; rawGears.ValueAxis = chart.YAxis; if (Options.Instance.ShowRawGearData) { detailPaneChart.ChartDataAdd(rawGears); } // Guess gears string equipmentId = Options.Instance.GetGearEquipmentId(activity); List <SprocketCombo> gearRatios = Options.Instance.GetSprocketCombos(equipmentId); INumericTimeDataSeries gearGuess = GearUtils.GuessGears(gearSelection, gearRatios); ChartDataSeries guessSeries = new ChartDataSeries(chart, chart.YAxis); if (Options.Instance.ShowEstGearData) { detailPaneChart.ChartDataAdd(guessSeries); } // ChartDataSeries guessSeries = PopulateDataSeries(gearGuess, guessSeries, ChartType, activity); guessSeries.ChartType = ChartDataSeries.Type.Line; guessSeries.LineColor = Color.Blue; guessSeries.ValueAxis = chart.YAxis; chart.YAxis.LabelColor = rawGears.LineColor; //ExportDataSeriesToCSV(guessSeries); //ExportDataSeriesToCSV(rawGears); if (Options.Instance.GearChartType == ChartBasis.Gear_Time) { chart.XAxis.Formatter = new Formatter.SecondsToTime(); chart.XAxis.Label = CommonResources.Text.LabelTime; } else { chart.XAxis.Formatter = new Formatter.General(); chart.XAxis.Label = CommonResources.Text.LabelDistance + " (" + activity.Category.DistanceUnits + ")"; } Options.Instance.ShowZonesInChart = false; chart.YAxis.Label = "m/Rev (ratio)"; // TODO: Localize this string } } chart.AutozoomToData(true); chart.Focus(); // Update Tree RefreshTree(); }
protected virtual void OnEnable() { chartBase = (ChartBase)target; }
/// <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) { System.Drawing.Color fgCol = System.Drawing.Color.Transparent; System.Drawing.Color bgCol = System.Drawing.Color.Transparent; double fontSize = -1; object elem = null; if (!DA.GetData <object>("Elements to Adjust", ref elem)) { return; } var hasfgCol = DA.GetData <System.Drawing.Color>("Foreground", ref fgCol); var hasbgCol = DA.GetData <System.Drawing.Color>("Background", ref bgCol); var hasFontSize = DA.GetData <double>("Font Size", ref fontSize); //Get the "FrameworkElement" (basic UI element) from an object FrameworkElement f = HUI_Util.GetUIElement <FrameworkElement>(elem); //try a few casts to see if it's a container Grid g = f as Grid; Panel panel = f as Panel; Selector selector = f as Selector; ScrollViewer sv = f as ScrollViewer; ChartBase cb = f as ChartBase; Expander exp = f as Expander; if (exp != null) { if (hasfgCol) { exp.Foreground = new SolidColorBrush(HUI_Util.ToMediaColor(fgCol)); } if (hasbgCol) { exp.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol)); } if (!hasFontSize) { return; } var header = exp.Header; TextBlock myHeader = null; if (header is string) { myHeader = new TextBlock(); myHeader.Text = header as string; } else { myHeader = exp.Header as TextBlock; } myHeader.FontSize = fontSize; exp.Header = myHeader; return; } // var ChartElem = HUI_Util.GetUIElement<ChartBase>(ChartObject); if (g != null) { foreach (UIElement child in g.Children) { ColorTextElement(child, fgCol, bgCol, fontSize); } g.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol)); } //if it's a panel color its children if (panel != null) { foreach (UIElement child in panel.Children) { ColorTextElement(child, fgCol, bgCol, fontSize); } panel.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol)); } //if it's a selector, color its items else if (selector != null) { foreach (UIElement child in selector.Items) { ColorTextElement(child, fgCol, bgCol, fontSize); } } //if it's an itemscontrol, color its items else if (sv != null) { ItemsControl ic = sv.Content as ItemsControl; if (ic != null) { foreach (var item in ic.Items) { UIElement uie = item as UIElement; if (uie != null) { ColorTextElement(uie, fgCol, bgCol, fontSize); } } } } else //otherwise assume it's just a root level element { ColorTextElement(f, fgCol, bgCol, fontSize); } }
public void Chart(Chart c, Row r, ChartBase cb) { }
public DataPoint(ChartBase parentChart) { ParentChart = parentChart; }
public void AddElement(ChartBase chart) { this.elements.Add(chart); //Y_Axis.SetRange(chart.GetMinValue(), chart.GetMaxValue()); // X_Axis.SetRange(0,chart.GetValueCount()); X_Axis.Steps = 1; }
/// <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) { var Collection = new ObservableCollection <ChartItem>(); string Title = ""; string SubTitle = ""; List <string> Clustertitle = new List <string>(); GH_Structure <GH_Number> treeValues = new GH_Structure <GH_Number>(); //GH_Structure<GH_String> treeNames = new GH_Structure<GH_String>(); List <string> names = new List <string>(); int chartType = 0; //get GH input data bool hasTitle = DA.GetData <string>("Title", ref Title); DA.GetData <string>("SubTitle", ref SubTitle); DA.GetDataList <string>("ClusterTitle", Clustertitle); DA.GetDataTree <GH_Number>("Data", out treeValues); //DA.GetDataTree<GH_String>("Names", out treeNames); DA.GetDataList <string>("Names", names); DA.GetData <int>("Chart Type", ref chartType); ChartBase ChartElem = null; switch (chartType) { case 0: var ColumnCluster = new ClusteredColumnChart(); ChartElem = ColumnCluster; break; case 1: var BarCluster = new ClusteredBarChart(); ChartElem = BarCluster; break; case 2: var ColumnStack = new StackedColumnChart(); ChartElem = ColumnStack; break; case 3: var BarStack = new StackedBarChart(); ChartElem = BarStack; break; case 4: var pieElem = new PieChart(); ChartElem = pieElem; break; default: var defaultElem = new ClusteredBarChart(); ChartElem = defaultElem; break; } //Give the chart its name ChartElem.ChartTitle = Title; ChartElem.ChartSubTitle = SubTitle; // MultiChartModel mcm = new MultiChartModel(); // mcm.Series = new ObservableCollection<SeriesModel>(); for (int i = 0; i < treeValues.Branches.Count; i++) { //package the data into a custom chart model and series List <double> listDouble = treeValues[i].ConvertAll(x => x.Value); SeriesModel vm = new SeriesModel(names.ToList(), listDouble, Clustertitle[i]); ChartSeries series = new ChartSeries(); //We have to set the series data context rather than the whole chart series.DataContext = vm; series.SeriesTitle = Clustertitle[i]; series.DisplayMember = "Category"; series.ValueMember = "Number"; Binding seriesBinding = new Binding(); seriesBinding.Source = vm; seriesBinding.Path = new PropertyPath("Chart"); BindingOperations.SetBinding(series, ChartSeries.ItemsSourceProperty, seriesBinding); ChartElem.Series.Add(series); //Pass data to the chart // mcm.Series.Add(vm); } //Binding seriesSetBinding = new Binding(); //seriesSetBinding.Source = mcm; //seriesSetBinding.Path = new PropertyPath("Series"); //BindingOperations.SetBinding(ChartElem, ChartBase.SeriesSourceProperty, seriesSetBinding); ////Send Data to GH output DA.SetData("MultiChart", new UIElement_Goo(ChartElem, "Chart Elem", InstanceGuid, DA.Iteration)); // DA.SetData("Test","listNames"); }
static public object GetElementValue(UIElement u) { switch (u.GetType().ToString()) { case "System.Windows.Controls.Slider": Slider s = u as Slider; return(s.Value); case "System.Windows.Controls.Button": Button b = u as Button; return((System.Windows.Input.Mouse.LeftButton == System.Windows.Input.MouseButtonState.Pressed) && b.IsMouseOver); case "HumanUI.TrueOnlyButton": TrueOnlyButton tob = u as TrueOnlyButton; return((System.Windows.Input.Mouse.LeftButton == System.Windows.Input.MouseButtonState.Pressed) && tob.IsMouseOver); case "HumanUI.HUI_RhPickButton": HUI_RhPickButton rpb = u as HUI_RhPickButton; return(rpb.objIDs); case "System.Windows.Controls.Label": Label l = u as Label; return(l.Content); case "System.Windows.Controls.ListBox": ListBox lb = u as ListBox; TextBlock lab = lb.SelectedItem as TextBlock; if (lab != null) { return(lab.Text); } else { return(null); } case "System.Windows.Controls.ScrollViewer": ScrollViewer sv = u as ScrollViewer; ItemsControl ic = sv.Content as ItemsControl; List <bool> checkeds = new List <bool>(); var cbs = from cbx in ic.Items.OfType <CheckBox>() select cbx; foreach (CheckBox chex in cbs) { checkeds.Add(chex.IsChecked == true); } return(checkeds); case "System.Windows.Controls.TextBox": TextBox tb = u as TextBox; return(tb.Text); case "System.Windows.Controls.ComboBox": ComboBox cb = u as ComboBox; TextBlock cbi = cb.SelectedItem as TextBlock; if (cbi != null) { return(cbi.Text); } else { return(null); } case "Xceed.Wpf.Toolkit.ColorPicker": ColorPicker colP = u as ColorPicker; //return cbi.Content; return(HUI_Util.ToSysColor(colP.SelectedColor)); case "System.Windows.Controls.ListView": ListView v = u as ListView; var cbxs = from cbx in v.Items.OfType <CheckBox>() select cbx; List <string> checkedVals = new List <string>(); foreach (CheckBox chex in cbxs) { if (chex.IsChecked == true) { checkedVals.Add(chex.Content.ToString()); } } return(String.Join(",", checkedVals)); case "System.Windows.Controls.CheckBox": CheckBox chb = u as CheckBox; return(chb.IsChecked); case "System.Windows.Controls.RadioButton": RadioButton rb = u as RadioButton; return(rb.IsChecked); case "System.Windows.Controls.Image": Image img = u as Image; return(img.Source.ToString()); case "System.Windows.Controls.Expander": Expander exp = u as Expander; return(exp.IsExpanded); case "System.Windows.Controls.TabControl": TabControl tc = u as TabControl; TabItem ti = tc.SelectedItem as TabItem; if (ti == null) { ti = tc.Items[0] as TabItem; } return(ti.Header.ToString()); case "MahApps.Metro.Controls.ToggleSwitch": ToggleSwitch ts = u as ToggleSwitch; return(ts.IsChecked); case "MahApps.Metro.Controls.RangeSlider": RangeSlider rs = u as RangeSlider; return(new Interval(rs.LowerValue, rs.UpperValue)); case "De.TorstenMandelkow.MetroChart.ChartBase": case "De.TorstenMandelkow.MetroChart.PieChart": case "De.TorstenMandelkow.MetroChart.ClusteredBarChart": case "De.TorstenMandelkow.MetroChart.ClusteredColumnChart": case "De.TorstenMandelkow.MetroChart.DoughnutChart": case "De.TorstenMandelkow.MetroChart.RadialGaugeChart": case "De.TorstenMandelkow.MetroChart.StackedBarChart": case "De.TorstenMandelkow.MetroChart.StackedColumnChart": ChartBase chart = u as ChartBase; ChartItem selectedItem = chart.SelectedItem as ChartItem; if (selectedItem != null) { string response = ""; if (!String.IsNullOrEmpty(selectedItem.ClusterCategory)) { response += selectedItem.ClusterCategory + ": "; } response += selectedItem.Category; return(response); } else { return(null); } case "System.Windows.Controls.DataGrid": DataGrid datagrid = u as DataGrid; var SelectedItem = datagrid.SelectedItem; //System.Data.DataView dv = datagrid.ItemsSource as System.Data.DataView; List <string> result = new List <string>(); try { System.Data.DataRowView drv = SelectedItem as System.Data.DataRowView; result = drv.Row.ItemArray.Cast <string>().ToList(); result.RemoveAt(0); } catch { } return(result); case "HumanUI.MDSliderElement": MDSliderElement mds = u as MDSliderElement; return(mds.SliderPoint); case "HumanUI.GraphMapperElement": GraphMapperElement gme = u as GraphMapperElement; return(gme.GetCurve().ToNurbsCurve()); case "HumanUI.HUI_GradientEditor": HUI_GradientEditor hge = u as HUI_GradientEditor; return(hge.Gradient.ToString()); case "HumanUI.FilePicker": FilePicker fp = u as FilePicker; return(fp.Path); case "HumanUI.ClickableShapeGrid": ClickableShapeGrid csg = u as ClickableShapeGrid; return(csg.SelectedStates); default: return(null); } }
private void AllOther(HttpContext context) { Granularity granularity = Granularity.Day; int estPoints = GetRangeDays(); int maxPoints = imageWidth / POINT_SPACE; int step = 1; int maxSteps = imageWidth / LABLE_SPACE; if (estPoints > maxPoints) { estPoints = GetRangeMonths(); granularity = Granularity.Month; } if (estPoints > maxPoints) { estPoints = GetRangeYears(); granularity = Granularity.Year; } while (estPoints > maxSteps) { estPoints = estPoints / 2; step++; } StatisticResult result = null; switch (statisticsType) { case StatisticsType.CountCommunityMembers: result = Statistics.GetObjectCountCommunityMembers(dateFrom, dateTo, groupBy, granularity, parentObjectID, include); break; case StatisticsType.CountProfileFriends: result = Statistics.GetObjectCountProfileFriends(dateFrom, dateTo, groupBy, granularity, parentObjectID, include); break; case StatisticsType.TotalObjectsCount: result = Statistics.GetObjectCountCommunityTotal(parentObjectID, groupBy).Results[0]; break; case StatisticsType.CreationObjects: if (!ignoreCommunity && parentObjectID.HasValue) { if (parentObjectType == Helper.GetObjectTypeNumericID("Community")) { result = Statistics.GetObjectCreationCommunityObjects(dateFrom, dateTo, groupBy, granularity, parentObjectID, include); } else if (parentObjectType == Helper.GetObjectTypeNumericID("ProfileCommunity")) { result = Statistics.GetObjectCreationProfileObjects(dateFrom, dateTo, groupBy, granularity, parentObjectID, include); } else { result = Statistics.GetObjectCreationObjects(dateFrom, dateTo, groupBy, granularity, include); } } else { result = Statistics.GetObjectCreationObjects(dateFrom, dateTo, groupBy, granularity, include); } break; } if (result == null || result.Series.Count < 1) { context.Response.ContentType = "text/plain"; context.Response.StatusCode = 501; context.Response.AddHeader("IDS", string.Concat(chartId, "|", errorId)); context.Response.Write(language.GetString("MessageStatisticNoData")); return; } List <string> colors = GetColors(result.Series.Count); DateTime minDate = DateTime.MaxValue; DateTime maxDate = DateTime.MinValue; DateTime lastDate = DateTime.MinValue; Graph graph = new Graph(); graph.Bgcolor = "#FFFFFF"; if (!string.IsNullOrEmpty(result.LabelX)) { Legend xLegend = new Legend(); xLegend.Text = result.LabelX; xLegend.Style = "color: #444444; font-size: 12px;"; graph.X_Legend = xLegend; } if (!string.IsNullOrEmpty(result.LabelY)) { Legend yLegend = new Legend(); yLegend.Text = result.LabelY; yLegend.Style = "color: #444444; font-size: 12px;"; graph.Y_Legend = yLegend; } XAxis xAxis = new XAxis(); xAxis.Colour = "#444444"; xAxis.GridColour = "#CCCCCC"; xAxis.Steps = step; graph.X_Axis = xAxis; YAxis yAxis = new YAxis(); yAxis.Colour = "#444444"; yAxis.GridColour = "#CCCCCC"; int y = result.MaxY - result.MinY; yAxis.Steps = y / 5; graph.Y_Axis = yAxis; string toolTip = language.GetString("LableStatisticCalls"); for (int i = 0; i < result.Series.Count; i++) { ChartBase chart = null; switch (chartType) { case ChartType.Bar: chart = new Bar(); break; case ChartType.Line: chart = new Line(); break; case ChartType.Column: chart = new HBar(); break; case ChartType.Pie: chart = new Pie(); break; } chart.Colour = colors[i]; //chart.Text = result.Series[i].Label.ToLowerInvariant(); chart.Text = result.Series[i].Label; if (statisticsType == StatisticsType.PageView) { chart.Tooltip = string.Format("#val# {0} ({1})", toolTip, chart.Text); } else { chart.Tooltip = string.Format("#val#"); } chart.Fontsize = 9; for (int j = 0; j < result.Series[i].Values.Count; j++) { StatisticValue value = result.Series[i].Values[j]; string xLabel = string.Empty; if (value is StatisticValueDateTimeInt) { StatisticValueDateTimeInt valueDateTime = (StatisticValueDateTimeInt)value; if (lastDate == DateTime.MinValue) { lastDate = valueDateTime.X; } if (valueDateTime.X > maxDate) { maxDate = valueDateTime.X; } if (valueDateTime.X < minDate) { minDate = valueDateTime.X; } if (j % xAxis.Steps == 0) { if (granularity == Granularity.Year) { xLabel = valueDateTime.X.ToString("yyyy"); } else if (granularity == Granularity.Month) { if (lastDate.Year != valueDateTime.X.Year || valueDateTime.X.Month == 1) { lastDate = valueDateTime.X; xLabel = valueDateTime.X.ToString("MMM. yy"); } else { xLabel = valueDateTime.X.ToString("MMM."); } } else if (granularity == Granularity.Day) { if (lastDate.Year != valueDateTime.X.Year || lastDate.Month != valueDateTime.X.Month || valueDateTime.X.Day == 1) { lastDate = valueDateTime.X; xLabel = valueDateTime.X.ToString("d.M."); } else { xLabel = valueDateTime.X.ToString("d."); } } } } else if (value is StatisticValueStringInt) { xLabel = ((StatisticValueStringInt)value).X; } var val = chart.NewValue(xLabel, value.Y); chart.Values.Add(val); } graph.Title = new Title(GetTitle(granularity)); graph.AddElement(chart); } //context.Response.ContentType = "application/json"; context.Response.ContentType = "text/plain"; context.Response.AddHeader("IDS", string.Concat(chartId, "|", errorId)); context.Response.Write(graph.ToString()); }
override internal void RunPage(Pages pgs, Row row) { Report rpt = pgs.Report; if (IsHidden(pgs.Report, row)) { return; } _ChartMatrix.RunReset(rpt); Rows _Data = GetFilteredData(rpt, row); SetMyData(rpt, _Data); SetPagePositionBegin(pgs); if (!AnyRowsPage(pgs, _Data)) // if no rows return { return; // nothing left to do } // Build the Chart bitmap, along with data regions Page p = pgs.CurrentPage; ChartBase cb = null; try { cb = RunChartBuild(rpt, row); // Build the chart if (!_isHYNEsWonderfulVector.EvaluateBoolean(rpt, row)) //AJM GJL 14082008 'Classic' Rendering { System.Drawing.Image im = cb.Image(rpt); // Grab the image int height = im.Height; // save height and width int width = im.Width; MemoryStream ostrm = new MemoryStream(); /* The following is a new image saving logic which will allow for higher * quality images using JPEG with 100% quality * 06122007AJM */ System.Drawing.Imaging.ImageCodecInfo[] info; info = ImageCodecInfo.GetImageEncoders(); EncoderParameters encoderParameters; encoderParameters = new EncoderParameters(1); // 20022008 AJM GJL - Centralised class with global encoder settings encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, ImageQualityManager.ChartImageQuality); System.Drawing.Imaging.ImageCodecInfo codec = null; for (int i = 0; i < info.Length; i++) { if (info[i].FormatDescription == "JPEG") { codec = info[i]; break; } } im.Save(ostrm, codec, encoderParameters); // 06122007AJM The follow has been replaced with the code above //im.Save(ostrm, info); // generate a jpeg TODO: get png to work with pdf byte[] ba = ostrm.ToArray(); ostrm.Close(); PageImage pi = new PageImage(IMAGEFORMAT, ba, width, height); // Create an image RunPageRegionBegin(pgs); SetPagePositionAndStyle(rpt, pi, row); pi.SI.BackgroundImage = null; // chart already has the background image if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty()) { // force page break if it doesn't fit on the page pgs.NextOrNew(); pgs.CurrentPage.YOffset = OwnerReport.TopOfPage; if (this.YParents != null) { pi.Y = 0; } } p = pgs.CurrentPage; p.AddObject(pi); // Put image onto the current page RunPageRegionEnd(pgs); if (!this.PageBreakAtEnd && !IsTableOrMatrixCell(rpt)) { float newY = pi.Y + pi.H; p.YOffset += newY; // bump the y location } SetPagePositionEnd(pgs, pi.Y + pi.H); } else //Ultimate Rendering - Vector //AJM GJL 14082008 { System.Drawing.Imaging.Metafile im = cb.Image(rpt); // Grab the image //im could still be saved to a bitmap at this point //if we were to offer a choice of raster or vector, it would probably //be easiest to draw the chart to the EMF and then save as bitmap if needed int height = im.Height; // save height and width int width = im.Width; byte[] ba = cb._aStream.ToArray(); cb._aStream.Close(); PageImage pi = new PageImage(ImageFormat.Wmf, ba, width, height); RunPageRegionBegin(pgs); SetPagePositionAndStyle(rpt, pi, row); pi.SI.BackgroundImage = null; // chart already has the background image if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty()) { // force page break if it doesn't fit on the page pgs.NextOrNew(); pgs.CurrentPage.YOffset = OwnerReport.TopOfPage; if (this.YParents != null) { pi.Y = 0; } } p = pgs.CurrentPage; //GJL 25072008 - Charts now draw in EMFplus format and not in bitmap. Still using the "PageImage" for the positioning //paging etc, but we don't add it to the page. // ****************************************************************************************************************** // New EMF Processing... we want to add the EMF Components to the page and not the actual EMF... EMF emf = new EMF(pi.X, pi.Y, width, height); emf.ProcessEMF(ba); //Process takes the bytearray of EMFplus data and breaks it down into lines,ellipses,text,rectangles //etc... There are still a lot of GDI+ functions I haven't got to (and some I have no intention of getting to!). foreach (PageItem emfItem in emf.PageItems) { p.AddObject(emfItem); } // ****************************************************************************************************************** //p.AddObject(pi); RunPageRegionEnd(pgs); pi.Y += p.YOffset; if (!this.PageBreakAtEnd && !IsTableOrMatrixCell(rpt)) { float newY = pi.Y + pi.H; p.YOffset += newY; // bump the y location } SetPagePositionEnd(pgs, pi.Y + pi.H); //our emf size seems to be bigger than the jpeg... } } catch (Exception ex) { rpt.rl.LogError(8, string.Format("Exception in Chart handling.\n{0}\n{1}", ex.Message, ex.StackTrace)); } finally { if (cb != null) { cb.Dispose(); } } return; }
/// <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) { var Collection = new ObservableCollection <ChartItem>(); string Title = ""; string SubTitle = ""; List <double> listContents = new List <double>(); List <string> names = new List <string>(); int chartType = 0; //get GH input data DA.GetDataList <double>("Data", listContents); DA.GetDataList <string>("Names", names); bool hasTitle = DA.GetData <string>("Title", ref Title); bool hasSubTitle = DA.GetData <string>("SubTitle", ref SubTitle); DA.GetData <int>("Chart Type", ref chartType); ChartBase ChartElem = null; switch (chartType) { case 0: var pieElem = new PieChart(); ChartElem = pieElem; break; case 1: var barElem = new ClusteredBarChart(); ChartElem = barElem; break; case 2: var columnElem = new ClusteredColumnChart(); ChartElem = columnElem; break; case 3: var doughnutElem = new DoughnutChart(); ChartElem = doughnutElem; break; case 4: var gaugeElem = new RadialGaugeChart(); ChartElem = gaugeElem; break; default: var defaultElem = new PieChart(); ChartElem = defaultElem; break; } //Create the chart and give it a name ChartElem.ChartTitle = Title; ChartElem.ChartTitleVisibility = hasTitle ? Visibility.Visible : Visibility.Collapsed; ChartElem.ChartSubTitle = SubTitle; //package the data into a custom chart model and series SeriesModel vm = new SeriesModel(names.ToList(), listContents.ToList()); ChartElem.DataContext = vm; ChartSeries series = new ChartSeries(); series.SeriesTitle = " "; series.DisplayMember = "Category"; series.ValueMember = "Number"; //set up the data binding for the series - this is useful so it can be reset later without redrawing the whole Chart Binding seriesBinding = new Binding(); seriesBinding.Source = vm; seriesBinding.Path = new PropertyPath("Chart"); BindingOperations.SetBinding(series, ChartSeries.ItemsSourceProperty, seriesBinding); // series.ItemsSource = vm.Chart; //Pass data to the chart ChartElem.Series.Add(series); ChartElem.ToolTipFormat = "{}Caption: {0}, Value: '{1}', Series: '{2}', Percentage: {3:P2}"; ChartElem.MinWidth = 10; ChartElem.MinHeight = 10; DA.SetData("Chart", new UIElement_Goo(ChartElem, "Chart Elem", InstanceGuid, DA.Iteration)); }
private void UpdateControlLimits(ChartBase dataContext) { if (dataContext.UseCustomCLs) { UCL = dataContext.ParentPanel.CustomUCL; LCL = dataContext.ParentPanel.CustomLCL; Mean = (UCL + LCL) / 2; if (_meanSeries == null) _meanSeries = PChart.Find(x => x.Name == "meanSeries") as LineSeries; if (_meanSeries != null) _meanSeries.ValueBinding = new PropertyNameDataPointBinding("CustomMean"); DynamicUclData = PerSampleControlLimitsHelper.BuildStaticUclLimit(dataContext, false); DynamicLclData = PerSampleControlLimitsHelper.BuildStaticLclLimit(dataContext, false); OnPropertyChanged("DynamicUclData"); OnPropertyChanged("DynamicLclData"); } else { UCL = dataContext.UCL; Mean = dataContext.Mean; LCL = dataContext.LCL; if (_meanSeries == null) _meanSeries = PChart.Find(x => x.Name == "meanSeries") as LineSeries; if (_meanSeries != null) _meanSeries.ValueBinding = new PropertyNameDataPointBinding("Mean"); if (dataContext.AverageLimits) { DynamicUclData = PerSampleControlLimitsHelper.BuildStaticUclLimit(dataContext, true); DynamicLclData = PerSampleControlLimitsHelper.BuildStaticLclLimit(dataContext, true); } else { DynamicUclData = PerSampleControlLimitsHelper.BuildUclLimits(dataContext.DataSource); DynamicLclData = PerSampleControlLimitsHelper.BuildLclLimits(dataContext.DataSource); } OnPropertyChanged("DynamicUclData"); OnPropertyChanged("DynamicLclData"); } dataContext.UpdateChartBoundaries(); UpdateDataPointTemplates(this); }
void RemoveEvents(UIElement u) { switch (u.GetType().ToString()) { case "System.Windows.Controls.Slider": Slider s = u as Slider; s.ValueChanged -= ExpireThis; return; case "System.Windows.Controls.Button": Button b = u as Button; b.PreviewMouseDown -= ExpireThis; b.PreviewMouseUp -= ExpireThis; return; case "System.Windows.Controls.DataGrid": DataGrid datagrid = u as DataGrid; datagrid.SelectedCellsChanged -= ExpireThis; return; case "HumanUI.TrueOnlyButton": TrueOnlyButton tob = u as TrueOnlyButton; tob.PreviewMouseDown -= ExpireThis; return; case "HumanUI.HUI_RhPickButton": HUI_RhPickButton rpb = u as HUI_RhPickButton; rpb.PickCompleted -= ExpireThis; return; case "HumanUI.MDSliderElement": MDSliderElement mds = u as MDSliderElement; mds.PropertyChanged -= ExpireThis; return; case "HumanUI.GraphMapperElement": GraphMapperElement gme = u as GraphMapperElement; gme.PropertyChanged -= ExpireThis; return; case "HumanUI.HUI_GradientEditor": HUI_GradientEditor hge = u as HUI_GradientEditor; hge.PropertyChanged -= ExpireThis; return; case "HumanUI.FilePicker": FilePicker fp = u as FilePicker; fp.PropertyChanged -= ExpireThis; return; case "HumanUI.ClickableShapeGrid": ClickableShapeGrid csg = u as ClickableShapeGrid; switch (csg.clickMode) { case ClickableShapeGrid.ClickMode.ButtonMode: csg.MouseUp -= ExpireThis; csg.MouseDown -= ExpireThis; return; case ClickableShapeGrid.ClickMode.PickerMode: case ClickableShapeGrid.ClickMode.ToggleMode: csg.MouseUp -= ExpireThis; return; case ClickableShapeGrid.ClickMode.None: default: return; } case "System.Windows.Controls.Label": Label l = u as Label; return; case "System.Windows.Controls.ListBox": ListBox lb = u as ListBox; lb.SelectionChanged -= ExpireThis; return; case "System.Windows.Controls.ScrollViewer": ScrollViewer sv = u as ScrollViewer; ItemsControl ic = sv.Content as ItemsControl; ((INotifyCollectionChanged)ic.Items).CollectionChanged -= ExpireThis; List <bool> checkeds = new List <bool>(); var cbs = from cbx in ic.Items.OfType <CheckBox>() select cbx; foreach (CheckBox chex in cbs) { chex.Checked -= ExpireThis; chex.Unchecked -= ExpireThis; } return; case "System.Windows.Controls.ComboBox": ComboBox cb = u as ComboBox; cb.SelectionChanged -= ExpireThis; return; case "System.Windows.Controls.TextBox": TextBox tb = u as TextBox; Panel p = tb.Parent as Panel; List <Button> btns = p.Children.OfType <Button>().ToList <Button>(); foreach (Button btn0 in btns) { btn0.Click -= ExpireThis; } tb.TextChanged -= ExpireThis; return; case "Xceed.Wpf.Toolkit.ColorPicker": ColorPicker cp = u as ColorPicker; cp.SelectedColorChanged -= ExpireThis; return; case "System.Windows.Controls.CheckBox": CheckBox chb = u as CheckBox; chb.Checked -= ExpireThis; chb.Unchecked -= ExpireThis; return; case "System.Windows.Controls.RadioButton": RadioButton rb = u as RadioButton; rb.Checked -= ExpireThis; rb.Unchecked -= ExpireThis; return; case "System.Windows.Controls.Image": return; case "System.Windows.Controls.Expander": Expander exp = u as Expander; exp.Expanded -= ExpireThis; exp.Collapsed -= ExpireThis; return; case "System.Windows.Controls.TabControl": TabControl tc = u as TabControl; tc.SelectionChanged -= ExpireThis; return; case "MahApps.Metro.Controls.ToggleSwitch": ToggleSwitch ts = u as ToggleSwitch; ts.IsCheckedChanged -= ExpireThis; return; case "MahApps.Metro.Controls.RangeSlider": RangeSlider rs = u as RangeSlider; rs.RangeSelectionChanged -= ExpireThis; return; case "De.TorstenMandelkow.MetroChart.ChartBase": case "De.TorstenMandelkow.MetroChart.PieChart": case "De.TorstenMandelkow.MetroChart.ClusteredBarChart": case "De.TorstenMandelkow.MetroChart.ClusteredColumnChart": case "De.TorstenMandelkow.MetroChart.DoughnutChart": case "De.TorstenMandelkow.MetroChart.RadialGaugeChart": case "De.TorstenMandelkow.MetroChart.StackedBarChart": case "De.TorstenMandelkow.MetroChart.StackedColumnChart": ChartBase chart = u as ChartBase; chart.MouseUp -= ExpireThis; return; default: return; } }
private void UpdateControlLimits(ChartBase dataContext) { if (dataContext.UseCustomCLs) { UCL = dataContext.ParentPanel.CustomUCL; LCL = dataContext.ParentPanel.CustomLCL; Mean = (UCL + LCL) / 2; if (_uclSeries == null) _uclSeries = RChart.Find(x => x.Name == "uclSeries") as LineSeries; if (_uclSeries != null) _uclSeries.ValueBinding = new PropertyNameDataPointBinding("CustomUCL"); if (_meanSeries == null) _meanSeries = RChart.Find(x => x.Name == "meanSeries") as LineSeries; if (_meanSeries != null) _meanSeries.ValueBinding = new PropertyNameDataPointBinding("CustomMean"); if (_lclSeries == null) _lclSeries = RChart.Find(x => x.Name == "lclSeries") as LineSeries; if (_lclSeries != null) _lclSeries.ValueBinding = new PropertyNameDataPointBinding("CustomLCL"); } else { UCL = dataContext.UCL; Mean = dataContext.Mean; LCL = dataContext.LCL; if (_uclSeries == null) _uclSeries = RChart.Find(x => x.Name == "uclSeries") as LineSeries; if (_uclSeries != null) _uclSeries.ValueBinding = new PropertyNameDataPointBinding("UCL"); if (_meanSeries == null) _meanSeries = RChart.Find(x => x.Name == "meanSeries") as LineSeries; if (_meanSeries != null) _meanSeries.ValueBinding = new PropertyNameDataPointBinding("Mean"); if (_lclSeries == null) _lclSeries = RChart.Find(x => x.Name == "lclSeries") as LineSeries; if (_lclSeries != null) _lclSeries.ValueBinding = new PropertyNameDataPointBinding("LCL"); } dataContext.UpdateChartBoundaries(); UpdateDataPointTemplates(this); }
public MainWindow() { this.DataContext = vm; InitializeComponent(); int numPins = 20; // programmatically create the chart series so we don't copy-and-paste for (int i = 0; i < numPins; i++) { channelGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); var tb = new TextBlock() { Text = i.ToString(), HorizontalAlignment = HorizontalAlignment.Left }; TextOptions.SetTextFormattingMode(tb, TextFormattingMode.Ideal); var vb = new Viewbox() { Width = 70, StretchDirection = StretchDirection.Both, Stretch = Stretch.Uniform }; vb.Child = tb; var toggle = new HorizontalToggleSwitch() { }; var toggleBinding = new Binding(); toggleBinding.Source = DataContext; toggleBinding.Path = new PropertyPath("ChannelEnabled[" + i + "]"); toggleBinding.Mode = BindingMode.TwoWay; BindingOperations.SetBinding(toggle, ToggleSwitchBase.IsCheckedProperty, toggleBinding); var sp = new StackPanel() { Orientation = Orientation.Horizontal }; sp.Children.Add(vb); sp.Children.Add(toggle); channelGrid.Children.Add(sp); Grid.SetRow(sp, i); var row = new ChartRowDefinition(); row.BorderThickness = 5; row.BorderStroke = new SolidColorBrush(Color.FromArgb(0xff, 0x6C, 0x6C, 0x6C)); chart.RowDefinitions.Add(row); var series = new FastLineSeries(); var binding = new Binding(); binding.Source = DataContext; binding.Path = new PropertyPath("Data"); binding.Mode = BindingMode.OneWay; binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; BindingOperations.SetBinding(series, ChartSeriesBase.ItemsSourceProperty, binding); series.XBindingPath = "TimestampOffset"; series.YBindingPath = "Values[" + i + "]"; var axis = new NumericalAxis(); axis.TickLineSize = 0; axis.LabelFormat = " "; axis.ShowGridLines = false; axis.Minimum = 0; axis.Maximum = 3.3; axis.PlotOffset = 10; series.YAxis = axis; chart.Series.Add(series); ChartBase.SetRow(axis, numPins - 1 - i); // rows start from the bottom } channelGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(35, GridUnitType.Pixel) }); }
private void UpdateControlLimits(ChartBase dataContext) { if (dataContext.DataSource == null || dataContext.DataSource.Count == 0) { UclData = null; OnPropertyChanged("UclData"); MeanData = null; OnPropertyChanged("MeanData"); LclData = null; OnPropertyChanged("LclData"); LslData = null; OnPropertyChanged("LslData"); UslData = null; OnPropertyChanged("UslData"); dataContext.BellCurveData = null; return; } if (dataContext.UseCustomCLs) { UCL = dataContext.ParentPanel.CustomUCL; LCL = dataContext.ParentPanel.CustomLCL; Mean = (UCL + LCL) / 2; UclData = PerSampleControlLimitsHelper.BuildHistogramControlLimit(UCL); OnPropertyChanged("UclData"); MeanData = PerSampleControlLimitsHelper.BuildHistogramControlLimit(Mean); OnPropertyChanged("MeanData"); LclData = PerSampleControlLimitsHelper.BuildHistogramControlLimit(LCL); OnPropertyChanged("LclData"); } else { UCL = dataContext.UCL; Mean = dataContext.Mean; LCL = dataContext.LCL; UclData = PerSampleControlLimitsHelper.BuildHistogramControlLimit(UCL); OnPropertyChanged("UclData"); MeanData = PerSampleControlLimitsHelper.BuildHistogramControlLimit(Mean); OnPropertyChanged("MeanData"); LclData = PerSampleControlLimitsHelper.BuildHistogramControlLimit(LCL); OnPropertyChanged("LclData"); } var minimum = dataContext.MinXValue; var maximum = dataContext.MaxXValue; var chartIndex = dataContext.ParentPanel.Charts.IndexOf(dataContext); UpdateLevelValuesCommand.BeginExecute(dataContext.ParentPanel, chartIndex, false, (sender, result) => { if (result.Error == null && result.Object != null) { if (!minimum.Equals(result.Object.Panel.Charts[chartIndex].MinXValue) || !maximum.Equals(result.Object.Panel.Charts[chartIndex].MaxXValue)) { dataContext.DataSource = result.Object.Panel.Charts[chartIndex].DataSource; dataContext.BellCurveData = result.Object.Panel.Charts[chartIndex].BellCurveData; dataContext.MinXValue = result.Object.Panel.Charts[chartIndex].MinXValue; dataContext.MaxXValue = result.Object.Panel.Charts[chartIndex].MaxXValue; dataContext.XStep = result.Object.Panel.Charts[chartIndex].XStep; dataContext.Sigma = result.Object.Panel.Charts[chartIndex].Sigma; dataContext.ParentPanel.Exponent = result.Object.Panel.Charts[chartIndex].ParentPanel.Exponent; AdjustLabelsAndTicks(HistogramChart, result.Object.Panel.Charts[chartIndex]); } } }); dataContext.UpdateChartBoundaries(); }
/// <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) { System.Drawing.Color?fgCol = null; System.Drawing.Color?bgCol = null; double fontSize = -1; object elem = null; if (!DA.GetData("Elements to Adjust", ref elem)) { return; } var hasfgCol = DA.GetData("Foreground", ref fgCol); var hasbgCol = DA.GetData("Background", ref bgCol); var hasFontSize = DA.GetData("Font Size", ref fontSize); //Get the "FrameworkElement" (basic UI element) from an object FrameworkElement f = HUI_Util.GetUIElement <FrameworkElement>(elem); Selector selector = f as Selector; ScrollViewer sv = f as ScrollViewer; ChartBase cb = f as ChartBase; if (f is Expander exp) { if (hasfgCol) { exp.Foreground = new SolidColorBrush(HUI_Util.ToMediaColor(fgCol.Value)); } if (hasbgCol) { exp.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol.Value)); } if (!hasFontSize) { return; } var header = exp.Header; TextBlock myHeader = null; if (header is string headString) { myHeader = new TextBlock(); myHeader.Text = headString; } else { myHeader = exp.Header as TextBlock; } myHeader.FontSize = fontSize; exp.Header = myHeader; return; } // var ChartElem = HUI_Util.GetUIElement<ChartBase>(ChartObject); if (f is Grid g) { foreach (UIElement child in g.Children) { ColorTextElement(child, fgCol, bgCol, fontSize); } if (hasbgCol) { g.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol.Value)); } } //if it's a panel color its children if (f is Panel panel) { foreach (UIElement child in panel.Children) { ColorTextElement(child, fgCol, bgCol, fontSize); } if (hasbgCol) { panel.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol.Value)); } } if (f is TabControl tabControl) { if (hasbgCol) { tabControl.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol.Value)); } } //if it's a selector, color its items else if (selector != null) { foreach (UIElement child in selector.Items) { ColorTextElement(child, fgCol, bgCol, fontSize); } } //if it's an itemscontrol, color its items else if (sv != null) { if (sv.Content is ItemsControl ic) { foreach (var item in ic.Items) { if (item is UIElement uie) { ColorTextElement(uie, fgCol, bgCol, fontSize); } } } } //otherwise assume it's just a root level element else { ColorTextElement(f, fgCol, bgCol, fontSize); } }
private int CalculateLabelInterval(ChartBase dataContext) { var placeholders = "#"; for (var i = 1; i < dataContext.ParentPanel.Exponent; i++) { placeholders += "#"; } LabelFormat = string.Concat("0.", placeholders); OnPropertyChanged("LabelFormat"); var graphArea = HistogramChart.Find(x => x.Name == "adornerContainer"); if (graphArea == null) return Math.Max(Convert.ToInt32(Math.Log(dataContext.DataSource.Count * dataContext.DataSource.Average(x => Math.Round(Convert.ToDouble(x.CategoryValue.LabelValue, CultureInfo.InvariantCulture), dataContext.ParentPanel.Exponent) .ToString().Length) / 10, Math.E)), 1); var availableWidth = graphArea.ActualWidth; var averageLabelWidth = (dataContext.DataSource.Average(x => x.CategoryValue.LabelValue.ToString().Length)) * 10; var howManyLabels = availableWidth / averageLabelWidth; return (int) Math.Ceiling(dataContext.DataSource.Count / howManyLabels); }
private void UpdateControlLimits(ChartBase dataContext) { Mean = dataContext.Mean; if (_meanSeries == null) _meanSeries = RunChart.Find(x => x.Name == "meanSeries") as LineSeries; if (_meanSeries != null) _meanSeries.ValueBinding = new PropertyNameDataPointBinding("Mean"); dataContext.UpdateChartBoundaries(); UpdateDataPointTemplates(this); }
private void AdjustLabelsAndTicks(RadChartBase chart, ChartBase dataContext) { if (_axis == null) _axis = chart.Find(x => x.Name == "horizontalLinearAxis") as LinearAxis; if (_axis != null) { var labelInterval = CalculateLabelInterval(dataContext); _axis.LabelInterval = labelInterval; if (_tickParent == null) { var ticks = chart.FindAll(x => x.Tag != null && x.Tag.ToString() == "Tick"); if (ticks != null && ticks.Any()) _tickParent = ticks[0].Parent as Canvas; } if (_tickParent != null) { var ticks = _tickParent.Children.Where(x => x is Rectangle && ((Rectangle)x).Tag.Equals("Tick")); var cn = 0; foreach (FrameworkElement element in ticks) { var styleModified = element.Style.Clone(); if (cn % labelInterval == 0) { styleModified.Setters.Add(new Setter(Rectangle.FillProperty, new SolidColorBrush(Color.FromArgb(0xFF, 0x33, 0x33, 0x33)))); styleModified.Setters.RemoveAt(1); } else { styleModified.Setters.Add(new Setter(Rectangle.FillProperty, new SolidColorBrush(Colors.Transparent))); styleModified.Setters.RemoveAt(1); } element.Style = styleModified; cn++; } _oldNumberOfTicks = ticks.Count(); } } }
void RemoveEvents(UIElement u) { switch (u.GetType().ToString()) { case "System.Windows.Controls.Slider": Slider s = u as Slider; s.ValueChanged -= ExpireThis; return; case "System.Windows.Controls.Button": Button b = u as Button; b.PreviewMouseDown -= ExpireThis; b.PreviewMouseUp -= ExpireThis; return; case "HumanUI.TrueOnlyButton": TrueOnlyButton tob = u as TrueOnlyButton; tob.PreviewMouseDown -= ExpireThis; return; case "HumanUI.MDSliderElement": MDSliderElement mds = u as MDSliderElement; mds.PropertyChanged -= ExpireThis; return; case "System.Windows.Controls.Label": Label l = u as Label; return; case "System.Windows.Controls.ListBox": ListBox lb = u as ListBox; lb.SelectionChanged -= ExpireThis; return; case "System.Windows.Controls.ScrollViewer": ScrollViewer sv = u as ScrollViewer; ItemsControl ic = sv.Content as ItemsControl; ((INotifyCollectionChanged)ic.Items).CollectionChanged -= ExpireThis; List <bool> checkeds = new List <bool>(); var cbs = from cbx in ic.Items.OfType <CheckBox>() select cbx; foreach (CheckBox chex in cbs) { chex.Checked -= ExpireThis; chex.Unchecked -= ExpireThis; } return; case "System.Windows.Controls.ComboBox": ComboBox cb = u as ComboBox; cb.SelectionChanged -= ExpireThis; return; case "System.Windows.Controls.TextBox": TextBox tb = u as TextBox; Panel p = tb.Parent as Panel; List <Button> btns = p.Children.OfType <Button>().ToList <Button>(); foreach (Button btn0 in btns) { btn0.Click -= ExpireThis; } tb.TextChanged -= ExpireThis; return; case "Xceed.Wpf.Toolkit.ColorPicker": ColorPicker cp = u as ColorPicker; cp.SelectedColorChanged -= ExpireThis; return; case "System.Windows.Controls.CheckBox": CheckBox chb = u as CheckBox; chb.Checked -= ExpireThis; chb.Unchecked -= ExpireThis; return; case "System.Windows.Controls.RadioButton": RadioButton rb = u as RadioButton; rb.Checked -= ExpireThis; rb.Unchecked -= ExpireThis; return; case "System.Windows.Controls.Image": return; case "System.Windows.Controls.TabControl": TabControl tc = u as TabControl; tc.SelectionChanged -= ExpireThis; return; case "De.TorstenMandelkow.MetroChart.ChartBase": case "De.TorstenMandelkow.MetroChart.PieChart": case "De.TorstenMandelkow.MetroChart.ClusteredBarChart": case "De.TorstenMandelkow.MetroChart.ClusteredColumnChart": case "De.TorstenMandelkow.MetroChart.DoughnutChart": case "De.TorstenMandelkow.MetroChart.RadialGaugeChart": case "De.TorstenMandelkow.MetroChart.StackedBarChart": case "De.TorstenMandelkow.MetroChart.StackedColumnChart": ChartBase chart = u as ChartBase; chart.MouseUp -= ExpireThis; return; default: return; } }
//color a UIElement. Runs through a list of possible types it recognizes and tries to color/format appropriately. private static void ColorTextElement(UIElement f, System.Drawing.Color fgCol, System.Drawing.Color bgCol, double fontSize) { Brush backgroundBrush = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol)); Brush foregroundBrush = new SolidColorBrush(HUI_Util.ToMediaColor(fgCol)); //Try graoh ChartBase ChartB = f as ChartBase; if (ChartB != null) { ChartB.Foreground = foregroundBrush; ChartB.Background = backgroundBrush; if (fontSize > 0) { ChartB.FontSize = fontSize; } } //Try Label Label l = f as Label; if (l != null) { l.Foreground = foregroundBrush; if (bgCol != System.Drawing.Color.Transparent) { l.Background = backgroundBrush; } if (fontSize > 0) { l.FontSize = fontSize; } return; } // Try textbox TextBox tb = f as TextBox; if (tb != null) { tb.Foreground = foregroundBrush; if (bgCol != System.Drawing.Color.Transparent) { tb.Background = backgroundBrush; } if (fontSize > 0) { tb.FontSize = fontSize; } return; } //Try Textblock TextBlock textblock = f as TextBlock; if (textblock != null) { textblock.Foreground = foregroundBrush; if (bgCol != System.Drawing.Color.Transparent) { textblock.Background = backgroundBrush; } if (fontSize > 0) { textblock.FontSize = fontSize; } return; } //Try Button Button b = f as Button; if (b != null) { b.Foreground = foregroundBrush; if (bgCol != System.Drawing.Color.Transparent) { b.Background = backgroundBrush; } if (fontSize > 0) { b.FontSize = fontSize; } return; } //Try Checkbox CheckBox cb = f as CheckBox; if (cb != null) { cb.Foreground = foregroundBrush; if (bgCol != System.Drawing.Color.Transparent) { cb.Background = backgroundBrush; } if (fontSize > 0) { cb.FontSize = fontSize; } return; } //Try RadioButton RadioButton rb = f as RadioButton; if (rb != null) { rb.Foreground = foregroundBrush; if (bgCol != System.Drawing.Color.Transparent) { rb.Background = backgroundBrush; } if (fontSize > 0) { rb.FontSize = fontSize; } return; } }