private void CreatePageOfGraphs(string sim, Graph[] graphs) { if (!panel.Cache.ContainsKey(sim)) { panel.Cache.Add(sim, new Dictionary <int, List <SeriesDefinition> >()); } IStorageReader storage = GetStorage(); GraphPage graphPage = new GraphPage(); // Configure graphs by applying user overrides. for (int i = 0; i < graphs.Length; i++) { if (graphs[i] != null && graphs[i].Enabled) { graphPage.Graphs.Add(ConfigureGraph(graphs[i], sim)); } if (cts.Token.IsCancellationRequested) { return; } } // If any sims in this tab are missing from the cache, then populate // the cache via the GraphPage instance. if (panel.Cache[sim].Count != graphs.Length) { // Read data from storage. IReadOnlyList <GraphPage.GraphDefinitionMap> definitions = graphPage.GetAllSeriesDefinitions(panel, storage, new List <string>() { sim }).ToList(); // Now populate the cache for this simulation. The definitions // should - in theory - be the same length as the graphs array. for (int i = 0; i < graphs.Length; i++) { GraphPage.GraphDefinitionMap definition = definitions[i]; panel.Cache[sim][i] = definition.SeriesDefinitions; if (cts.Token.IsCancellationRequested) { return; } } } // Finally, add the graphs to the tab. GraphTab tab = new GraphTab(sim, this.presenter); for (int i = 0; i < graphPage.Graphs.Count; i++) { tab.AddGraph(graphPage.Graphs[i], panel.Cache[sim][i]); } this.graphs.Add(tab); view.AddTab(tab, panel.NumCols); }
private GraphPage.GraphDefinitionMap FindMatchingDefinition(IReadOnlyList <GraphPage.GraphDefinitionMap> allDefinitions, Graph graph) { GraphPage.GraphDefinitionMap match = allDefinitions.FirstOrDefault(m => m.Graph == graph); if (match == null) { throw new KeyNotFoundException($"Graph {graph.Name} not found. Programming error..."); } return(match); }