public void ViewRelation(Comunity comunity, int max, RelationIndexType type) { if (comunityDic == null) { CreateComunityDic(); } foreach (var item in comunityDic.Values) { item.NewBrush(Colors.White, 1); } comunity.NewBrush(Colors.Red, 0.8); foreach (var item in comunity.Relations.OrderByDescending(n => n.GetIndex(type)).Take(max)) { if (comunityDic.ContainsKey(item.ItemId)) { comunityDic[item.ItemId].NewBrush(Colors.Orange, 0.5); } } }
public static ClusterTable Create(System.IO.StreamReader sr) { Dictionary<string, Category> categoryDic = new Dictionary<string, Category>(); Dictionary<string, List<Layer>> layerListDic = new Dictionary<string, List<Layer>>(); List<Comunity> comunityList = new List<Comunity>(); foreach (var item in TSVFile.ReadLines(sr)) { Comunity comunity = new Comunity() { Id = item.GetIntValue("Community_Id"), // ImageUrl = item.GetValue("Image_Url"), // Index = item.GetDoubleValue("Index"), Name = item.GetValue("Community_Name") }; string categoryStr = item.GetValue("帰属系"); string layer = item.GetValue("レイヤー"); Category category = null; if (categoryDic.ContainsKey(categoryStr)) { category = categoryDic[categoryStr]; } else { categoryDic.Add(categoryStr, new Category() { KeyName = categoryStr, Name = item.GetValue("系名", string.Empty) }); category = categoryDic[categoryStr]; category.CategoryAttributeList = new List<CategoryAttribute>(); foreach (var item2 in item.GetValue("系指標", string.Empty).Split(',')) { var array = item2.Split(':'); if (array.Length == 1) { category.CategoryAttributeList.Add(new CategoryAttribute() { Name = string.Empty, Value = array[0] }); } else { category.CategoryAttributeList.Add(new CategoryAttribute() { Name = array[0], Value = array[1] }); } } } if (category.Layer.ContainsKey(layer)) { category.Layer[layer].Comunities.Add(comunity); } else { category.Layer.Add(layer, new Layer() { Name = layer, Category = category }); category.Layer[layer].Comunities.Add(comunity); } } var clusterTable = new ClusterTable(); clusterTable.Categories = new System.Collections.ObjectModel.ObservableCollection<Category>(); clusterTable.LayerGroup = new List<LayerGroup>(); clusterTable.CategoryAttributeGroup = new System.Collections.ObjectModel.ObservableCollection<CategoryAttributeGroup>(); List<string> layerNameList = new List<string>(); List<string> categoryAttributeNameList = new List<string>(); foreach (var item in categoryDic) { foreach (var item2 in item.Value.Layer) { layerNameList.Add(item2.Value.Name); } foreach (var item2 in item.Value.CategoryAttributeList) { categoryAttributeNameList.Add(item2.Name); } } layerNameList = layerNameList.Distinct().OrderBy(n => n).ToList(); categoryAttributeNameList = categoryAttributeNameList.Distinct().ToList(); Dictionary<string, CategoryAttributeGroup> categoryAttributeGroupDic = new Dictionary<string, CategoryAttributeGroup>(); foreach (var item in categoryDic) { clusterTable.Categories.Add(item.Value); foreach (var item2 in layerNameList) { if (layerListDic.ContainsKey(item2)) { layerListDic[item2].Add(item.Value.GetLayer(item2)); } else { layerListDic.Add(item2, new List<Layer>() { item.Value.GetLayer(item2) }); } } foreach (var item2 in categoryAttributeNameList) { var attribute = item.Value.CategoryAttributeList.Where(n => n.Name == item2).FirstOrDefault(); if (attribute != null) { if (categoryAttributeGroupDic.ContainsKey(item2)) { categoryAttributeGroupDic[item2].Items.Add(attribute); } else { categoryAttributeGroupDic.Add(item2, new CategoryAttributeGroup() { Name = item2, Items = new System.Collections.ObjectModel.ObservableCollection<CategoryAttribute>() }); categoryAttributeGroupDic[item2].Items.Add(attribute); } } else { attribute = new CategoryAttribute(); if (categoryAttributeGroupDic.ContainsKey(item2)) { categoryAttributeGroupDic[item2].Items.Add(attribute); } else { categoryAttributeGroupDic.Add(item2, new CategoryAttributeGroup() { Name = item2, Items = new System.Collections.ObjectModel.ObservableCollection<CategoryAttribute>() }); categoryAttributeGroupDic[item2].Items.Add(attribute); } } } } foreach (var item2 in categoryAttributeGroupDic.Values) { clusterTable.CategoryAttributeGroup.Add(item2); } foreach (var item in layerNameList) { var lg = new LayerGroup() { Name = item, Items = new System.Collections.ObjectModel.ObservableCollection<Layer>() }; clusterTable.LayerGroup.Add(lg); foreach (var item2 in categoryDic.Values) { lg.Items.Add(item2.Layer[item]); } } comunityList.Clear(); foreach (var item in layerListDic.Values) { foreach (var item2 in item) { comunityList.AddRange(item2.Comunities); } } return clusterTable; }