Example #1
0
        private void updateSquares(IEnumerable <T1> newList)
        {
            int yCategoriesCount = yCategories.Count();
            int xCategoriesCount = xCategories.Count();

            division = new Division[yCategoriesCount, xCategoriesCount];

            for (int y = 0; y < yCategoriesCount; y++)
            {
                for (int x = 0; x < xCategoriesCount; x++)
                {
                    XCategory xCategory = xCategories.Skip(x).First();
                    YCategory yCategory = yCategories.Skip(y).First();

                    int valuesInRect = newList.Count(v => categorizer(v, xCategory, yCategory));

                    division[y, x] = new Division {
                        rectangle = new Rectangle()
                        {
                            size = squareSize,
                            pos  = getPosForSquare(x, y)
                        },
                        intensity = valuesInRect
                    };
                }
            }
            List <Division> divisionList = division.Cast <Division>().ToList();

            int maxIntensity   = divisionList.Any() ? divisionList.Max(d => d.intensity) : 0;
            int minIntensity   = divisionList.Any() ? divisionList.Min(d => d.intensity) : 0;
            int intensityRange = maxIntensity - minIntensity;

            if (intensityRange != 0)
            {
                divisionList.ForEach(d => {
                    float relativeIntensity = (d.intensity - minIntensity) / (float)intensityRange;

                    d.rectangle.color = Tools.mixColors(colorSmall, colorLarge, relativeIntensity, 10);
                });
            }


            drawables = divisionList.Select(d => d.rectangle).Concat <IDrawable>(labels);
        }
Example #2
0
        public static void CreateEntry(WikiEntry entry)
        {
            foreach (var item in entry.Categories)
            {
                string categoryId = "";

                // Category exists
                if (XCategories.Any(c => c.Attribute("Text").Value == item.Text))
                {
                    continue;
                }
                else
                {
                    // Generate new Category
                    categoryId = (Convert.ToInt32(XCategories.Last().Attribute("Id").Value) + 1).ToString();

                    XCategory.Add(
                        new XElement("Category",
                                     new XAttribute("Id", categoryId),
                                     new XAttribute("Text", item.Text))
                        );
                }
            }

            foreach (var item in entry.Tags)
            {
                string tagId = "";

                // Tag exists
                if (XTags.Any(c => c.Attribute("Text").Value == item.Text))
                {
                    continue;
                }
                else
                {
                    // Generate new Tag
                    tagId = (Convert.ToInt32(XTags.Last().Attribute("Id").Value) + 1).ToString();
                    XTag.Add
                    (
                        new XElement("Tag",
                                     new XAttribute("Id", tagId),
                                     new XAttribute("Text", item.Text))
                    );
                }
            }

            XElement wikiEntry =
                new XElement("WikiEntry",
                             new XAttribute("Id", Guid.NewGuid()),
                             new XAttribute("CreatedBy", "*****@*****.**"),
                             new XAttribute("CreatedAt", DateTimeOffset.UtcNow.ToString()),
                             new XAttribute("UpdatedBy", "*****@*****.**"),
                             new XAttribute("UpdatedAt", DateTimeOffset.UtcNow.ToString()),
                             new XAttribute("CategoryIds", string.Join(",", from x in entry.Categories select x.Id)),
                             new XAttribute("TagIds", string.Join(",", from x in entry.Tags select x.Id)),
                             new XElement("Title", entry.Title),
                             new XElement("Content", new XCData(entry.Content))
                             );

            XWikiEntries.Add(wikiEntry);
            xDoc.Save(file);
        }