Legend shows invisible graphs

Dec 13, 2010 at 6:55 PM

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

Coordinator
Dec 20, 2010 at 11:28 AM
Thanks,
can you please add a issue for me here - http://d3future.codeplex.com/workitem/list/basic
--
Best regards,
Mikhail Brinchuk,
My freelance CV - searching for remote work