/// <summary>
 /// Update legend VM.
 /// </summary>
 /// <param name="ic2sc">Context.</param>
 public override void UpdateLegend(ICategory2StyleContext ic2sc)
 {
     if (_legend == null)
     {
         return;
     }
     _legend.Fill    = CreateBrush(ic2sc);
     _legend.Minimum = ic2sc.ValueExtents.Minimum;
     _legend.Maximum = ic2sc.ValueExtents.Maximum;
 }
        Legend EnsureLegend(ICategory2StyleContext ic2sc, string title, Style pathstyle)
        {
            var brush = CreateBrush(ic2sc);

            if (_legend != null)
            {
                _legend.Fill = brush;
                return(_legend);
            }
            _legend = new LegendValueRange()
            {
                Title = title, Minimum = ic2sc.ValueExtents.Minimum, Maximum = ic2sc.ValueExtents.Maximum, Fill = brush, Stroke = pathstyle.Find <Brush>(Path.StrokeProperty)
            };
            return(_legend);
        }
 /// <summary>
 /// Establish the legend for this style generator.
 /// </summary>
 /// <param name="ic2sc">Context.</param>
 /// <param name="title">Series title.</param>
 /// <param name="pathstyle">Use for other style properties as required.</param>
 /// <returns>Cached list enumerator.</returns>
 public override IEnumerable <LegendBase> LegendFor(ICategory2StyleContext ic2sc, string title, Style pathstyle)
 {
     if (_legend == null)
     {
         _legend = new List <LegendBase>();
         foreach (var ex in Entries)
         {
             var leg = new LegendValueRange()
             {
                 Title = ex.Title, Minimum = ex.Minimum, Maximum = ex.Maximum, Fill = ex.Color, Stroke = BasedOn.Find <Brush>(Path.StrokeProperty)
             };
             _legend.Add(leg);
         }
     }
     return(_legend);
 }
        /// <summary>
        /// Produce a style for the given context.
        /// </summary>
        /// <param name="ic2sc">Context.</param>
        /// <returns>Style or NULL.</returns>
        public override Style For(ICategory2StyleContext ic2sc)
        {
            if (BasedOn == null)
            {
                return(null);
            }
            var match = Entries.SingleOrDefault(xx => xx.Compare(ic2sc.Values[0]));

            if (match == null)
            {
                return(null);
            }
            var style = BasedOn.Override(Path.FillProperty, match.Color);

            return(style);
        }
        Brush CreateBrush(ICategory2StyleContext ic2sc)
        {
            var gsc = new GradientStopCollection();

            InfoFor(ic2sc.ValueExtents.Minimum, ic2sc.ValueExtents.Maximum, ic2sc.ValueExtents.Minimum, out int red, out int green, out int blue);
            gsc.Add(new GradientStop()
            {
                Color = Color.FromArgb(Alpha, (byte)red, (byte)green, (byte)blue), Offset = 1
            });
            InfoFor(ic2sc.ValueExtents.Minimum, ic2sc.ValueExtents.Maximum, ic2sc.ValueExtents.Maximum, out red, out green, out blue);
            gsc.Add(new GradientStop()
            {
                Color = Color.FromArgb(Alpha, (byte)red, (byte)green, (byte)blue), Offset = 0
            });
            return(new LinearGradientBrush(gsc, 90));
        }
        /// <summary>
        /// Create a style or NULL.
        /// </summary>
        /// <param name="ic2sc">Item context.</param>
        /// <returns>Style or NULL.</returns>
        public override Style For(ICategory2StyleContext ic2sc)
        {
            if (BasedOn == null)
            {
                return(null);
            }
            InfoFor(ic2sc.ValueExtents.Minimum, ic2sc.ValueExtents.Maximum, ic2sc.Values[0], out int red, out int green, out int blue);
            string skey = $"r{red}_g{green}_b{blue}";

            if (StyleMap.TryGetValue(skey, out Style stx))
            {
                return(stx);
            }
            var brush = BrushFor(red, green, blue);
            var style = BasedOn.Override(Path.FillProperty, brush);

            StyleMap.Add(skey, style);
            return(style);
        }
 /// <summary>
 /// Nothing to update; NOT dependent on value range.
 /// </summary>
 /// <param name="ic2sc"></param>
 public override void UpdateLegend(ICategory2StyleContext ic2sc)
 {
 }
 /// <summary>
 /// Generate the legend VM (with initial values).
 /// </summary>
 /// <param name="ic2sc">Context.</param>
 /// <param name="title">Series title.</param>
 /// <param name="pathstyle">Use for other style elements.</param>
 /// <returns>New instance, but with STABLE entries.</returns>
 public override IEnumerable <LegendBase> LegendFor(ICategory2StyleContext ic2sc, string title, Style pathstyle)
 {
     return(new LegendBase[] { EnsureLegend(ic2sc, title, pathstyle) });
 }
 /// <summary>
 /// Update legend VM.
 /// </summary>
 /// <param name="ic2sc">Context.</param>
 public abstract void UpdateLegend(ICategory2StyleContext ic2sc);
 /// <summary>
 /// Generate the legend VM (with initial values).
 /// </summary>
 /// <param name="ic2sc">Context.</param>
 /// <param name="title">Series title.</param>
 /// <param name="pathstyle">Use for other style elements.</param>
 /// <returns>New instance, but with STABLE entries.</returns>
 public abstract IEnumerable <LegendBase> LegendFor(ICategory2StyleContext ic2sc, string title, Style pathstyle);
 /// <summary>
 /// Provide a style or NULL to revert.
 /// </summary>
 /// <param name="ic2sc">Value context.</param>
 /// <returns>Style or NULL.</returns>
 public abstract Style For(ICategory2StyleContext ic2sc);