Esempio n. 1
0
        private Brush GetItemBrush(int index)
        {
            ResourceDictionaryCollection usedPalette = this.DefaultPalette;

            if (this.Palette != null)
            {
                usedPalette = this.Palette;
            }

            if (usedPalette != null)
            {
                // returns the color from palette with the given index
                // for indexes large than the number of color in the palette we will start at the beginning
                int paletteIndex  = index % usedPalette.Count;
                var resDictionary = usedPalette[paletteIndex];
                try
                {
                    foreach (var entry in resDictionary.Values)
                    {
                        if (entry is Brush)
                        {
                            return(entry as Brush);
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
            return(new SolidColorBrush(Colors.Red));
        }
Esempio n. 2
0
        /// <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)
        {
            object        ChartObject  = null;
            List <double> listContents = new List <double>();
            List <string> names        = new List <string>();
            bool          Legend       = true;
            bool          Title        = true;

            List <System.Drawing.Color> Col = new List <System.Drawing.Color>();

            System.Drawing.Color fgCol = System.Drawing.Color.Transparent;

            //Get the Chart object and assign it
            if (!DA.GetData <object>("Chart to modify", ref ChartObject))
            {
                return;
            }
            var ChartElem = HUI_Util.GetUIElement <ChartBase>(ChartObject);

            bool hasLegend = DA.GetData <bool>("Legend", ref Legend);
            bool hasTitle  = DA.GetData <bool>("Title", ref Title);
            bool hasColors = DA.GetDataList <System.Drawing.Color>("Colors", Col);

            if (hasColors)
            {
                ResourceDictionaryCollection Palette = new ResourceDictionaryCollection();
                Palette = createResourceDictionary(Col);

                System.Windows.Media.Brush BorderBrush = new SolidColorBrush(HUI_Util.ToMediaColor(Col[0]));
                ChartElem.BorderBrush = BorderBrush;
                ChartElem.Palette     = Palette;
            }

            if (hasLegend)
            {
                Visibility LegendVis = Visibility.Hidden;
                if (Legend)
                {
                    LegendVis = Visibility.Visible;
                }
                ChartElem.ChartLegendVisibility = LegendVis;
            }
            if (hasTitle)
            {
                Visibility TitleVis = Visibility.Hidden;
                if (Title)
                {
                    TitleVis = Visibility.Visible;
                }
                ChartElem.ChartTitleVisibility = TitleVis;
            }
        }
Esempio n. 3
0
        public static void AddColor(ResourceDictionaryCollection palette,
                                    Color color)
        {
            var style = new Style(typeof(Control));

            style.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(color)));
            style.Setters.Add(new Setter(Control.BorderThicknessProperty, "0"));
            style.Setters.Add(new Setter(Control.BorderBrushProperty, new SolidColorBrush(Color.FromArgb(255, 255, 255, 255))));

            var dictionary = new ResourceDictionary();

            dictionary.Add("DataPointStyle", style);

            palette.Add(dictionary);
        }
Esempio n. 4
0
        private void setPalette()
        {
            this.mcChart.Palette.Clear();

            pieSeriesPalette = new System.Windows.Controls.DataVisualization.ResourceDictionaryCollection();
            foreach (Brush brush in brushes)
            {
                System.Windows.ResourceDictionary pieDataPointStyles = new ResourceDictionary();
                Style stylePie = new Style(typeof(PieDataPoint));
                stylePie.Setters.Add(new Setter(PieDataPoint.TemplateProperty, (ControlTemplate)FindResource("MyPieDataPointTemplate")));
                stylePie.Setters.Add(new Setter(PieDataPoint.BackgroundProperty, brush));
                pieDataPointStyles.Add("DataPointStyle", stylePie);
                pieSeriesPalette.Add(pieDataPointStyles);
            }

            this.mcChart.Palette = pieSeriesPalette;
        }
Esempio n. 5
0
        private int InitializeChartPalette(out string errorMsg)
        {
            int retVal = Constants.Failure;

            errorMsg = string.Empty;

            try
            {
                ResourceDictionaryCollection rdCollection = new ResourceDictionaryCollection();
                if (PaletteCollection != null)
                {
                    PaletteCollection.Clear();
                    PaletteCollection = null;
                }

                // Create a color palette entry for each data point
                foreach (Element el in SelectedMolecule.Composition)
                {
                    ResourceDictionary rd = new ResourceDictionary();
                    Style dataPointStyle  = new Style(typeof(Control));
                    dataPointStyle.Setters.Add(new Setter(Control.BackgroundProperty, el.Brush));
                    dataPointStyle.Setters.Add(new Setter(Control.TemplateProperty, App.Current.Resources["PieDataPointControlTemplate"] as ControlTemplate));
                    dataPointStyle.Setters.Add(new Setter(DataPoint.DependentValueStringFormatProperty, "{0:0.00}"));
                    rd.Add("DataPointStyle", dataPointStyle);
                    Style dataShapeStyle = new Style(typeof(Shape));
                    dataShapeStyle.Setters.Add(new Setter(Shape.StrokeProperty, el.Brush));
                    dataShapeStyle.Setters.Add(new Setter(Shape.StrokeThicknessProperty, 2));
                    dataShapeStyle.Setters.Add(new Setter(Shape.StrokeMiterLimitProperty, 1));
                    dataShapeStyle.Setters.Add(new Setter(Shape.FillProperty, el.Brush));
                    rd.Add("DataShapeStyle", dataShapeStyle);
                    rdCollection.Add(rd);
                }
                PaletteCollection = rdCollection;
                retVal            = Constants.Success;
            }
            catch (Exception ex)
            {
                retVal   = Constants.Failure;
                errorMsg = string.Format("An unexpected error occurred: {0}", ex.Message);
            }

            return(retVal);
        }
Esempio n. 6
0
        private ResourceDictionaryCollection createResourceDictionary(List <System.Drawing.Color> col)
        {
            ResourceDictionaryCollection palette = new ResourceDictionaryCollection();


            for (int i = 0; i < col.Count; i++)
            {
                ResourceDictionary   PalleteColors = new ResourceDictionary();
                System.Drawing.Color color         = col[i];
                SolidColorBrush      active        = new SolidColorBrush(System.Windows.Media.Color.FromRgb(color.R, color.G, color.B));
                string name = "brush" + i;
                PalleteColors.Add(name, active);
                palette.Add(PalleteColors);
            }



            return(palette);
        }
Esempio n. 7
0
        void Page_Loaded(object sender, RoutedEventArgs e)
        {
            RotateTransform rotateTransform = new RotateTransform();

            rotateTransform.Angle = 0.90;

            _rotateStyle.Setters.Add(new Setter(CategoryAxis.RenderTransformProperty, rotateTransform));

            if (App.Current.Resources.Contains("chartTitle"))
            {
                _chartTitle = App.Current.Resources["chartTitle"].ToString();
                Chart.Title = _chartTitle;
            }
            if (App.Current.Resources.Contains("independentLabel"))
            {
                _independentLabel = App.Current.Resources["independentLabel"].ToString();
            }

            if (App.Current.Resources.Contains("dependentLabel"))
            {
                _dependentLabel = App.Current.Resources["dependentLabel"].ToString();
            }

            if (App.Current.Resources.Contains("chartLineSeries"))
            {
                _chartLineSeries = App.Current.Resources["chartLineSeries"].ToString();
                _chartLineSeries = _chartLineSeries.Replace(Statics.Comma, ",");
            }

            if (App.Current.Resources.Contains("chartType"))
            {
                _chartType = App.Current.Resources["chartType"].ToString();
                List <object> objectList = new List <object>();

                if (ProcessSeriesData(ref objectList, _chartType, _chartLineSeries, ref _failOverMessage))
                {
                    try
                    {
                        switch (_chartType.ToUpper().Replace(" ", ""))
                        {
                        case Statics.Area:
                            foreach (object line in objectList)
                            {
                                Chart.Series.Add(line as AreaSeries);
                            }
                            break;

                        case Statics.Bar:

                            foreach (object columnSeries in objectList)
                            {
                                #region REM rotate label candidate
                                //if (independentValue.GetType() == Type.GetType("System.String"))
                                //{
                                //    //Style style = new Style(typeof(CategoryAxis));
                                //    //RotateTransform rotateTransform = new RotateTransform();
                                //    //rotateTransform.Angle = 0.90;

                                //    //style.Setters.Add(new Setter(CategoryAxis.RenderTransformProperty, rotateTransform));

                                //    //((ColumnSeries)series).IndependentAxis = new CategoryAxis
                                //    //{
                                //    //    Title = _independentLabel,
                                //    //    Orientation = AxisOrientation.X,
                                //    //    AxisLabelStyle = _rotateStyle
                                //    //};

                                //    ((ColumnSeries)series).IndependentAxis = new CategoryAxis
                                //    {
                                //        Title = _independentLabel,
                                //        Orientation = AxisOrientation.X
                                //    };
                                //}
                                //else if (independentValue.GetType() == Type.GetType("System.DateTime"))
                                //{
                                //    ((ColumnSeries)series).IndependentAxis = new DateTimeAxis
                                //    {
                                //        Title = _independentLabel,
                                //        Orientation = AxisOrientation.X
                                //    };
                                //}
                                //else
                                //{
                                //    ((ColumnSeries)series).IndependentAxis = new LinearAxis
                                //    {
                                //        Title = _independentLabel,
                                //        Orientation = AxisOrientation.X
                                //    };
                                //}
                                #endregion
                                Chart.Series.Add(columnSeries as ColumnSeries);
                            }
                            #region REM rotate label candidate
                            //((ColumnSeries)objectList[0] as ColumnSeries).DependentRangeAxis = new LinearAxis
                            //{
                            //    Title = _dependentLabel,
                            //    ShowGridLines = true,
                            //    Orientation = AxisOrientation.Y
                            //};
                            #endregion
                            break;

                        case Statics.Bubble:
                            foreach (object line in objectList)
                            {
                                Chart.Series.Add(line as BubbleSeries);
                            }
                            break;

                        case Statics.RotatedBar:
                            foreach (object line in objectList)
                            {
                                Chart.Series.Add(line as BarSeries);
                            }
                            break;

                        case Statics.Histogram:
                            foreach (object line in objectList)
                            {
                                System.Windows.Controls.DataVisualization.ResourceDictionaryCollection pallete = new ResourceDictionaryCollection();
                                ResourceDictionary rd = new ResourceDictionary();
                                Style style           = new Style();
                                style.TargetType = typeof(ColumnDataPoint);

                                style.Setters.Clear();
                                //style.Setters.Add(new Setter() { Property = ColumnDataPoint.BackgroundProperty, Value = new SolidColorBrush(Colors.Orange) });
                                style.Setters.Add(new Setter()
                                {
                                    Property = ColumnDataPoint.MarginProperty, Value = new Thickness(0)
                                });
                                style.Setters.Add(new Setter()
                                {
                                    Property = ColumnDataPoint.PaddingProperty, Value = new Thickness(0, 0, 0, 0)
                                });
                                style.Setters.Add(new Setter()
                                {
                                    Property = ColumnDataPoint.MinWidthProperty, Value = 256
                                });

                                rd.Clear();
                                rd.Add("DataPointStyle", style);
                                pallete.Clear();
                                pallete.Add(rd);
                                Chart.Palette = pallete;

                                Chart.Series.Add(line as ColumnSeries);
                            }
                            break;

                        case Statics.Line:
                            foreach (object line in objectList)
                            {
                                Chart.Series.Add(line as LineSeries);
                            }
                            break;

                        case Statics.Pie:
                            foreach (object column in objectList)
                            {
                                Chart.Series.Add(column as PieSeries);
                            }
                            break;

                        case Statics.Scatter:
                            foreach (object line in objectList)
                            {
                                Chart.Series.Add(line as ScatterSeries);
                            }
                            break;

                        case Statics.Stacked:
                            foreach (object line in objectList)
                            {
                                Chart.Series.Add(line as StackedBarSeries);
                            }
                            break;

                        default:
                            _failOverMessage = "The specified graph type supplied in the input parameters (initParams) could not be parsed or is not supported.";
                            break;
                        }
                    }
                    catch (Exception exception)
                    {
                        _failOverMessage = exception.Message;
                    }
                }
                else
                {
                    if (_failOverMessage == string.Empty)
                    {
                        _failOverMessage = "The input parameters (initParams) could not be parsed.";
                    }
                }

                if (_failOverMessage.Length > 0)
                {
                    Chart.Visibility     = Visibility.Collapsed;
                    FailOverMessage.Text = _failOverMessage;
                }
            }
        }