1
Vote

Legend shows invisible graphs

description

Hello,
I have noticed a little bug with the legend. If you add some lines in invisible mode they are shown in the legend anyway. In my case there is the following scenario.

TimeChartPlotter Plotter = new TimeChartPlotter();

// some code

((LineGraph)Plotter.Children[0]).Visibility = System.Windows.Visibility.Hidden;
// for updating the legend I use - havent found anything better so far
Plotter.Legend.RemoveFromPlotter();
Plotter.Legend.AddToPlotter(Plotter);




In my opinion the first graph should now not be visible on the legend. I think this issue should be easy to fix. It would be great if you could fix it ;)

One approach would be something like this:



public void PopulateLegend() // in Legend.cs
{
legendItems.Clear();

if (!LegendVisible) return;
if (plotter == null) return;

foreach (var chart in plotter.Children.OfType<DependencyObject>())
{
    var legendItemsBuilder = Legend.GetLegendItemsBuilder(chart);
                    // the && ... is the new part
    if (legendItemsBuilder != null && (chart is UIElement) ? ((UIElement)chart).Visibility == System.Windows.Visibility.Visible :true)
    {
        foreach (var legendItem in legendItemsBuilder((IPlotterElement)chart))
        {
            legendItems.Add(legendItem);
        }
    }
}
UpdateVisibility();
}

Regards

P.S. This is a copy of my post in: http://d3future.codeplex.com/Thread/View.aspx?ThreadId=238220

comments