Ejemplo n.º 1
0
 /// <summary>
 /// Called when the value of the LegendItemStyle property changes.
 /// </summary>
 /// <param name="oldValue">Old value.</param>
 /// <param name="newValue">New value.</param>
 protected virtual void OnLegendItemStylePropertyChanged(Style oldValue, Style newValue)
 {
     foreach (LegendItem legendItem in LegendItems.OfType <LegendItem>())
     {
         legendItem.SetStyle(newValue);
     }
 }
Ejemplo n.º 2
0
        public void Draw(double mapScale)
        {
            LegendItems.Clear();
            if (featureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Count > 0)
            {
                Style style = featureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles[0];

                if (style is CustomDotDensityStyle)
                {
                    LegendItems.Add(new DotDensityLegendItem(5));
                    LegendItems.Add(new DotDensityLegendItem(10));
                    LegendItems.Add(new DotDensityLegendItem(20));
                    LegendItems.Add(new DotDensityLegendItem(40));
                }
                else if (style is PieZedGraphStyle)
                {
                    PieZedGraphStyle zedGraphStyle = (PieZedGraphStyle)style;

                    foreach (KeyValuePair <string, GeoColor> item in zedGraphStyle.PieSlices)
                    {
                        AreaStyle          fillStyle  = new AreaStyle(new GeoSolidBrush(item.Value));
                        PieChartLegendItem legendItem = new PieChartLegendItem(fillStyle, item.Key);
                        this.LegendItems.Add(legendItem);
                    }
                }
                else if (style is ValueCircleStyle)
                {
                    LegendItems.Add(new ValueCircleLegendItem(80));
                    LegendItems.Add(new ValueCircleLegendItem(16));
                    LegendItems.Add(new ValueCircleLegendItem(32));
                    LegendItems.Add(new ValueCircleLegendItem(64));
                    LegendItems.Add(new ValueCircleLegendItem(1280));
                }
                else if (style is ClassBreakStyle)
                {
                    ClassBreakStyle thematicStyle = (ClassBreakStyle)style;

                    for (int i = 0; i < thematicStyle.ClassBreaks.Count; i++)
                    {
                        ThematicLegendItem thematicLegendItem;
                        if (i < thematicStyle.ClassBreaks.Count - 1)
                        {
                            thematicLegendItem = new ThematicLegendItem(thematicStyle.ClassBreaks[i], thematicStyle.ClassBreaks[i + 1]);
                        }
                        else
                        {
                            thematicLegendItem = new ThematicLegendItem(thematicStyle.ClassBreaks[i], null);
                        }
                        LegendItems.Add(thematicLegendItem);
                    }
                }

                foreach (var legendItem in LegendItems)
                {
                    legendItem.Draw(style);
                }
            }
        }
        /// <summary>
        /// Removes data point's legend item when the data point is removed.
        /// </summary>
        /// <param name="dataPoint">The data point to remove.</param>
        protected override void RemoveDataPoint(DataPoint dataPoint)
        {
            base.RemoveDataPoint(dataPoint);
            if (dataPoint != null)
            {
                LegendItem legendItem = _dataPointLegendItems[dataPoint];
                _dataPointLegendItems.Remove(dataPoint);

                LegendItems.Remove(legendItem);
                UpdateLegendItemIndexes();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the FunctionSeries class.
        /// </summary>
        public FunctionSeries()
        {
            LegendItem = new LegendItem();
            LegendItems.Add(LegendItem);
            Clip         = ClipGeometry = new RectangleGeometry();
            SizeChanged += OnSizeChanged;

            // Explicitly load the default template since the samples project
            // is an application and does not have a generic.xaml file.
            Template  = XamlReader.Load(DefaultTemplate) as ControlTemplate;
            LineBrush = new SolidColorBrush(Colors.Purple);
        }
 /// <summary>
 /// Common logic for entering the chart.
 /// </summary>
 /// <param name="icelc">The context.</param>
 /// <param name="cc">The component entering chart.</param>
 protected void ComponentEnter(IChartEnterLeaveContext icelc, ChartComponent cc)
 {
     // pre-load resources
     if (cc is IRequireChartTheme irct)
     {
         if (Theme == null)
         {
             Report(new ChartValidationResult("Chart", $"The {nameof(Theme)} property is NULL, chart elements may not be visible", new[] { cc.NameOrType(), nameof(Theme) }));
         }
         else
         {
             irct.Theme = Theme;
         }
     }
     // invoke IREL
     if (cc is IRequireEnterLeave irel)
     {
         irel.Enter(icelc);
     }
     // for now anything can provide legend items
     if (cc is IProvideLegend ipl)
     {
         foreach (var li in ipl.LegendItems)
         {
             LegendItems.Add(li);
         }
     }
     if (cc is IProvideLegendDynamic ipld)
     {
         // attach the event
         ipld.LegendChanged -= Ipld_LegendChanged;
         ipld.LegendChanged += Ipld_LegendChanged;
     }
     // axis and DSRP are mutually-exclusive
     if (cc is IChartAxis ica)
     {
         Axes.Add(ica);
     }
     if (cc is IProvideDataSourceRenderer ipdsr)
     {
         Register(ipdsr.Renderer);
     }
     else if (cc is IDataSourceRenderer idsr)
     {
         Register(idsr);
     }
     foreach (var px in AllPhases)
     {
         px.Enter(cc);
     }
 }
Ejemplo n.º 6
0
        public LegendAdornmentLayerViewModel()
            : this(new LegendAdornmentLayer {
            Name = LegendHelper.GenerateLegendName()
        })
        {
            var legendItemViewModel = new LegendItemViewModel();

            legendItemViewModel.Text                     = GisEditor.LanguageManager.GetStringResource("PreferenceWindowTitleText");
            legendItemViewModel.LegendItemType           = LegendItemType.Header;
            legendItemViewModel.TextLeftPadding          = 10;
            legendItemViewModel.NotifiedGeoFont          = new GeoFontViewModel();
            legendItemViewModel.NotifiedGeoFont.FontSize = 10;
            LegendItems.Add(legendItemViewModel);
        }
        internal override void Attach(LegendTree legendTree)
        {
            if (legendTree == null)
            {
                return;
            }

            base.Attach(legendTree);

            LayerItemsOptions = legendTree.LayerItemsOptions;

            LayerItems.ForEach(item => item.Attach(legendTree));
            LegendItems.ForEach(item => item.Attach(legendTree));
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     Creates a legend item for each data point.
        /// </summary>
        /// <param name="dataPoint">The data point added.</param>
        protected override void AddDataPoint(DataPoint dataPoint)
        {
            base.AddDataPoint(dataPoint);
            var pieDataPoint = (PieDataPoint)dataPoint;

            int        index      = ActiveDataPoints.IndexOf(dataPoint) + 1;
            LegendItem legendItem = CreatePieLegendItem(dataPoint, index);

            // Grab a style enumerator if we don't have one already.
            if (_resourceDictionaryEnumerator == null)
            {
                _resourceDictionaryEnumerator = GetResourceDictionaryWithTargetType(this, typeof(PieDataPoint), true);
            }

            if (_resourceDictionaryEnumerator.MoveNext())
            {
                ResourceDictionary paletteResources =
#if SILVERLIGHT
                    _resourceDictionaryEnumerator.Current.ShallowCopy();
#else
                    _resourceDictionaryEnumerator.Current;
#endif
                pieDataPoint.PaletteResources = paletteResources;
                pieDataPoint.Resources.MergedDictionaries.Add(paletteResources);
            }
            else
            {
                pieDataPoint.PaletteResources = null;
            }
            pieDataPoint.ActualDataPointStyle = DataPointStyle ?? pieDataPoint.Resources[DataPointStyleName] as Style;
            pieDataPoint.SetBinding(StyleProperty,
                                    new Binding(PieDataPoint.ActualDataPointStyleName)
            {
                Source = pieDataPoint
            });
            pieDataPoint.ActualLegendItemStyle = LegendItemStyle ??
                                                 (pieDataPoint.Resources[LegendItemStyleName] as Style);
            legendItem.SetBinding(StyleProperty, new Binding(ActualLegendItemStyleName)
            {
                Source = pieDataPoint
            });

            _dataPointLegendItems[dataPoint] = legendItem;
            LegendItems.Add(legendItem);
            UpdateLegendItemIndexes();
        }
 /// <summary>
 /// Manage dynamic legend updates.
 /// </summary>
 /// <param name="sender">Component sending update.</param>
 /// <param name="ldea">Current state of legend.</param>
 private void Ipld_LegendChanged(ChartComponent sender, LegendDynamicEventArgs ldea)
 {
     foreach (var prev in ldea.PreviousItems)
     {
         if (!ldea.CurrentItems.Contains(prev))
         {
             LegendItems.Remove(prev);
         }
     }
     foreach (var curr in ldea.CurrentItems)
     {
         if (!LegendItems.Contains(curr))
         {
             LegendItems.Add(curr);
         }
     }
 }
Ejemplo n.º 10
0
        public void Refresh(FeatureLayer displayLayer, WinformsMap map)
        {
            FeatureLayer = displayLayer;
            Draw(map.CurrentScale);

            Controls.Clear();

            Label LegendTitleLabel = new Label();

            LegendTitleLabel.AutoSize  = true;
            LegendTitleLabel.TextAlign = ContentAlignment.MiddleLeft;
            LegendTitleLabel.Location  = new Point(5, 15);
            LegendTitleLabel.Text      = Title;
            LegendTitleLabel.Font      = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
            Size textSize      = TextRenderer.MeasureText(LegendTitleLabel.Text, LegendTitleLabel.Font);
            int  maxPanelWidth = LegendTitleLabel.Location.X + textSize.Width;

            Controls.Add(LegendTitleLabel);

            int legendItemHeight = 55;

            foreach (var item in LegendItems.Where(i => i.Image != null && !string.IsNullOrEmpty(i.Title)))
            {
                PictureBox ItemImagePicture = new PictureBox();
                ItemImagePicture.Location = new Point(10, legendItemHeight);
                ItemImagePicture.Size     = item.Image.Size;
                ItemImagePicture.Image    = item.Image;

                Label TextLabel = new Label();
                TextLabel.AutoSize = true;
                TextLabel.Text     = item.Title;
                TextLabel.Location = new Point(ItemImagePicture.Location.X + ItemImagePicture.Width + 10, legendItemHeight + ItemImagePicture.Height / 2 - 6);

                textSize          = TextRenderer.MeasureText(TextLabel.Text, TextLabel.Font);
                maxPanelWidth     = maxPanelWidth < TextLabel.Location.X + textSize.Width ? TextLabel.Location.X + textSize.Width : maxPanelWidth;
                legendItemHeight += ItemImagePicture.Height + 5;

                Controls.Add(ItemImagePicture);
                Controls.Add(TextLabel);
            }

            Location = new Point(Location.X, map.Height + map.Top - legendItemHeight - 9);
            Height   = legendItemHeight + 10;
            Width    = maxPanelWidth + 20;
        }
        /// <summary>
        /// Creates a legend item for each data point.
        /// </summary>
        /// <param name="dataPoint">The data point added.</param>
        protected override void AddDataPoint(DataPoint dataPoint)
        {
            base.AddDataPoint(dataPoint);

            int   index = ActiveDataPoints.IndexOf(dataPoint) + 1;
            Style style = NextStyle(typeof(PieDataPoint), true);

            if (dataPoint.Style == null)
            {
                dataPoint.Style = style;
            }

            LegendItem legendItem = CreatePieLegendItem(dataPoint, index);

            _dataPointLegendItems[dataPoint] = legendItem;
            LegendItems.Add(legendItem);
            UpdateLegendItemIndexes();
        }
Ejemplo n.º 12
0
        protected void ItemOnItemSelected(object sender, EventArgs e)
        {
            ItemViewModel viewModel = (ItemViewModel)sender;

            SelectedLegendItem = null;

            if (viewModel.IsSelected == false)
            {
                return;
            }

            SelectedLegendItem = viewModel;

            foreach (ItemViewModel itemViewModel in LegendItems.Where(x => !ReferenceEquals(x, viewModel)))
            {
                itemViewModel.IsSelected = false;
            }
        }
 /// <summary>
 /// Common logic for leaving the chart.
 /// SHOULD be strict dual of ComponentEnter sequence.
 /// </summary>
 /// <param name="icelc">The context.</param>
 /// <param name="cc">The component leaving chart.</param>
 protected void ComponentLeave(IChartEnterLeaveContext icelc, ChartComponent cc)
 {
     foreach (var px in AllPhases)
     {
         px.Leave(cc);
     }
     if (cc is IProvideDataSourceRenderer ipdsr)
     {
         Unregister(ipdsr.Renderer);
     }
     else if (cc is IDataSourceRenderer idsr)
     {
         Unregister(idsr);
     }
     if (cc is IChartAxis ica)
     {
         Axes.Remove(ica);
     }
     if (cc is IProvideLegendDynamic ipld)
     {
         // detach the event
         ipld.LegendChanged -= Ipld_LegendChanged;
     }
     if (cc is IProvideLegend ipl)
     {
         foreach (var li in ipl.LegendItems)
         {
             LegendItems.Remove(li);
         }
     }
     if (cc is IRequireEnterLeave irel)
     {
         irel.Leave(icelc);
     }
     if (cc is IRequireChartTheme irct)
     {
         irct.Theme = null;
     }
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates a legend item for each data point.
        /// </summary>
        /// <param name="dataPoint">The data point added.</param>
        protected override void AddDataPoint(DataPoint dataPoint)
        {
            base.AddDataPoint(dataPoint);

            int index = ActiveDataPoints.IndexOf(dataPoint) + 1;

            // Grab a style enumerator if we don't have one already.
            if (_styleEnumerator == null)
            {
                _styleEnumerator = this.GetStylesWithTargetType(typeof(PieDataPoint), true);
            }

            if (_styleEnumerator.MoveNext())
            {
                Style style = _styleEnumerator.Current;
                dataPoint.SetStyle(style);
            }

            LegendItem legendItem = CreatePieLegendItem(dataPoint, index);

            _dataPointLegendItems[dataPoint] = legendItem;
            LegendItems.Add(legendItem);
            UpdateLegendItemIndexes();
        }
 internal override void Detach()
 {
     LayerItems.ForEach(item => item.Detach());
     LegendItems.ForEach(item => item.Detach());
     base.Detach();
 }
Ejemplo n.º 16
0
 public int GetLegendNumber()
 {
     return(LegendItems.Count());
 }