Example #1
0
        public static void CreateUngPiratUptakeMap()
        {
            string svg = string.Empty;
            string legendTemplate = string.Empty;

            using (
                StreamReader reader = new StreamReader("content/se-up-uptake-municipalities-template.svg",
                                                       Encoding.Default))
            {
                svg = reader.ReadToEnd();
            }

            using (
                StreamReader reader = new StreamReader("content/se-up-uptakemap-legend-template.txt", Encoding.Default))
            {
                legendTemplate = reader.ReadToEnd();
            }

            Organizations effectiveOrgs = new Organizations();
            Organizations possibleOrgs = Organization.FromIdentity(2).GetTree();

            foreach (Organization org in possibleOrgs)
            {
                if (org.AcceptsMembers && org.AutoAssignNewMembers)
                {
                    effectiveOrgs.Add(org);
                }
            }

            string legend = string.Empty;

            effectiveOrgs.Sort();

            Dictionary<int, string> colorLookup = new Dictionary<int, string>();
            int position = 0;
            float curLight = .35f;
            float curSaturation = 1f;

            foreach (Organization org in effectiveOrgs)
            {
                curLight += .25f;
                if (curLight > .85f)
                {
                    curLight = .35f;
                }
                else if (curLight > .8f)
                {
                    curLight = .75f;
                }

                curSaturation = 1.45f - curSaturation;


                Color color = ColorFromAhsb(128, (float) position*360/(float) effectiveOrgs.Count, curSaturation,
                                            curLight);

                if (org.CatchAll)
                {
                    color = Color.FromArgb(240, 240, 240);
                }

                string colorString = String.Format("#{0:x2}{1:x2}{2:x2}", color.R, color.G, color.B);
                colorLookup[org.Identity] = colorString;

                string orgLegend = legendTemplate.
                    Replace("%%NAME%%", Encoding.Default.GetString(Encoding.UTF8.GetBytes(org.NameShort))).
                    Replace("%%YPOS%%", (position*17).ToString()).
                    Replace("%%COLOR%%", colorString).
                    Replace("%%GROUPID%%", "org" + org.Identity.ToString());

                legend += orgLegend;

                position++;
            }

            Mappery mappery = new Mappery();
            mappery.OrgColorLookup = colorLookup; // Ugly way to transfer data to delegate

            svg = svg.Replace("<!--%%LEGEND%%-->", legend);

            Regex regex =
                new Regex("(?<start>\\<path.+?fill:)(?<color>.+?)(?<middle>;.+?id=\\\")(?<id>.+?)(?<end>\\\".+?/\\>)",
                          RegexOptions.Singleline);

            MatchEvaluator matchEvaluator = new MatchEvaluator(mappery.UPUptakeLookupReplacer);

            Persistence.Key["OrgUptakeMap-2"] = regex.Replace(svg, matchEvaluator);
        }
Example #2
0
        public static void CreateUngPiratUptakeMap()
        {
            string svg            = string.Empty;
            string legendTemplate = string.Empty;

            using (
                StreamReader reader = new StreamReader("content/se-up-uptake-municipalities-template.svg",
                                                       Encoding.Default))
            {
                svg = reader.ReadToEnd();
            }

            using (
                StreamReader reader = new StreamReader("content/se-up-uptakemap-legend-template.txt", Encoding.Default))
            {
                legendTemplate = reader.ReadToEnd();
            }

            Organizations effectiveOrgs = new Organizations();
            Organizations possibleOrgs  = Organization.FromIdentity(2).GetTree();

            foreach (Organization org in possibleOrgs)
            {
                if (org.AcceptsMembers && org.AutoAssignNewMembers)
                {
                    effectiveOrgs.Add(org);
                }
            }

            string legend = string.Empty;

            effectiveOrgs.Sort();

            Dictionary <int, string> colorLookup = new Dictionary <int, string>();
            int   position      = 0;
            float curLight      = .35f;
            float curSaturation = 1f;

            foreach (Organization org in effectiveOrgs)
            {
                curLight += .25f;
                if (curLight > .85f)
                {
                    curLight = .35f;
                }
                else if (curLight > .8f)
                {
                    curLight = .75f;
                }

                curSaturation = 1.45f - curSaturation;


                Color color = ColorFromAhsb(128, (float)position * 360 / (float)effectiveOrgs.Count, curSaturation,
                                            curLight);

                if (org.CatchAll)
                {
                    color = Color.FromArgb(240, 240, 240);
                }

                string colorString = String.Format("#{0:x2}{1:x2}{2:x2}", color.R, color.G, color.B);
                colorLookup[org.Identity] = colorString;

                string orgLegend = legendTemplate.
                                   Replace("%%NAME%%", Encoding.Default.GetString(Encoding.UTF8.GetBytes(org.NameShort))).
                                   Replace("%%YPOS%%", (position * 17).ToString()).
                                   Replace("%%COLOR%%", colorString).
                                   Replace("%%GROUPID%%", "org" + org.Identity.ToString());

                legend += orgLegend;

                position++;
            }

            Mappery mappery = new Mappery();

            mappery.OrgColorLookup = colorLookup; // Ugly way to transfer data to delegate

            svg = svg.Replace("<!--%%LEGEND%%-->", legend);

            Regex regex =
                new Regex("(?<start>\\<path.+?fill:)(?<color>.+?)(?<middle>;.+?id=\\\")(?<id>.+?)(?<end>\\\".+?/\\>)",
                          RegexOptions.Singleline);

            MatchEvaluator matchEvaluator = new MatchEvaluator(mappery.UPUptakeLookupReplacer);

            Persistence.Key["OrgUptakeMap-2"] = regex.Replace(svg, matchEvaluator);
        }