Ejemplo n.º 1
0
        public ActionResult Index()
        {
            string[] colors = new string[] {
                "#8D38C9",
                "#00FFFF",
                "#FF00FF",
                "#008000",
                "#FFFF00",
                "#0000FF",
                "#FF0000"
            };

            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.Load(Server.MapPath("~/Areas/Draw_Basic/Content/Australia.xml"));

            List <object>         info    = new List <object>();
            List <AbstractSprite> sprites = new List <AbstractSprite>();

            int i = 0;

            foreach (System.Xml.XmlNode state in doc.SelectNodes("states/state"))
            {
                PathSprite sprite = new PathSprite
                {
                    Path        = state.SelectSingleNode("path").InnerText,
                    FillStyle   = "#808080",
                    StrokeStyle = "#000",
                    LineWidth   = 1,
                    Linejoin    = StrokeLinejoin.Round
                                  //Cursor = "pointer"
                };

                //sprite.Listeners.MouseOver.Handler = string.Format("onMouseOver(this, {0}, {1});", JSON.Serialize(colors[i]), i);
                //sprite.Listeners.MouseOut.Handler = "onMouseOut(this);";

                sprites.Add(sprite);
                i++;

                info.Add(new
                {
                    state = state.SelectSingleNode("name").InnerText,
                    desc  = state.SelectSingleNode("description").InnerText
                });
            }

            ViewData["mapInfo"] = info;

            return(View(sprites));
        }
        public ActionResult Index()
        {
            string[] colors = new string[] {
                        "#8D38C9",
                        "#00FFFF",
                        "#FF00FF",
                        "#008000",
                        "#FFFF00",
                        "#0000FF",
                        "#FF0000"
                };

            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.Load(Server.MapPath("~/Areas/Draw_Basic/Content/Australia.xml"));

            List<object> info = new List<object>();
            List<AbstractSprite> sprites = new List<AbstractSprite>();

            int i = 0;
            foreach (System.Xml.XmlNode state in doc.SelectNodes("states/state"))
            {
                PathSprite sprite = new PathSprite
                {
                    Path = state.SelectSingleNode("path").InnerText,
                    FillStyle = "#808080",
                    StrokeStyle = "#000",
                    LineWidth = 1,
                    Linejoin = StrokeLinejoin.Round
                    //Cursor = "pointer"
                };

                //sprite.Listeners.MouseOver.Handler = string.Format("onMouseOver(this, {0}, {1});", JSON.Serialize(colors[i]), i);
                //sprite.Listeners.MouseOut.Handler = "onMouseOut(this);";

                sprites.Add(sprite);
                i++;

                info.Add(new
                {
                    state = state.SelectSingleNode("name").InnerText,
                    desc = state.SelectSingleNode("description").InnerText
                });
            }

            ViewData["mapInfo"] = info;

            return View(sprites);
        }
        private DrawContainer Draw(List<int> labels, List<int> data)
        {
            DrawContainer draw = new DrawContainer
            {
                ID = "Draw1",
                Border = false
            };

            int width = 800;
            int height = 250;
            int leftgutter = 30;
            int bottomgutter = 20;
            int topgutter = 20;
            double colorhue = 0.6;
            string color = System.Drawing.ColorTranslator.ToHtml(this.ColorFromHSB(colorhue, 0.5, 0.5));

            double x = (width - leftgutter) / (labels.Count * 1.0);
            int max = data.Max();
            double y = (height - bottomgutter - topgutter) / (max * 1.0);

            draw.Items.Add(this.GridPath(leftgutter + y * 0.5 + 0.5, topgutter + 0.5, width - leftgutter - x, height - topgutter - bottomgutter, 10, 10, "#000"));

            PathSprite pathSprite = new PathSprite
            {
                StrokeStyle = color,
                LineWidth = 4,
                Linejoin = StrokeLinejoin.Round
            };
            draw.Items.Add(pathSprite);

            PathSprite bgpSprite = new PathSprite
            {
                StrokeStyle = "none",
                GlobalAlpha = 0.3,
                FillStyle = color
            };

            draw.Items.Add(bgpSprite);

            List<string> p = new List<string>();
            List<string> bgpp = new List<string>();

            for (int i = 0; i < labels.Count; i++)
            {
                int yc = Convert.ToInt32(Math.Round(height - bottomgutter - y * data[i]));
                int xc = Convert.ToInt32(Math.Round(leftgutter - 10 + x * (i + 0.5)));
                int heightCraph = height - bottomgutter;
                draw.Items.Add(new TextSprite
                {
                    X = Convert.ToInt32(xc),
                    Y = height - 6,
                    Text = labels[i].ToString(),
                    FillStyle = "#000",
                    Font = "12px Helvetica, Arial"
                });

                if (i == 0)
                {
                    p.AddRange(new string[]{"M", JSON.Serialize(xc), JSON.Serialize(yc),
                                            "C", JSON.Serialize(xc), JSON.Serialize(yc)});

                    bgpp.AddRange(new string[]{"M", JSON.Serialize(leftgutter - 10 + x * 0.5), JSON.Serialize(height - bottomgutter),
                                               "L", JSON.Serialize(xc), JSON.Serialize(yc),
                                               "C", JSON.Serialize(xc), JSON.Serialize(yc)});
                }

                if (i > 0 && i < (labels.Count - 1))
                {
                    double Y0 = Math.Round(height - bottomgutter - y * data[i - 1]);
                    double X0 = Math.Round(leftgutter + x * (i - 0.5));
                    double Y2 = Math.Round(height - bottomgutter - y * data[i + 1]);
                    double X2 = Math.Round(leftgutter + x * (i + 1.5));
                    double[] a = this.GetAnchors(X0, Y0, xc, yc, X2, Y2);

                    p.AddRange(new string[] { JSON.Serialize(a[0]), JSON.Serialize(a[1]), JSON.Serialize(xc), JSON.Serialize(yc), JSON.Serialize(a[2]), JSON.Serialize(a[3]) });
                    bgpp.AddRange(new string[] { JSON.Serialize(a[0]), JSON.Serialize(a[1]), JSON.Serialize(xc), JSON.Serialize(yc), JSON.Serialize(a[2]), JSON.Serialize(a[3]) });
                }

                draw.Items.Add(new CircleSprite
                {
                    SpriteID = "dot_" + i,
                    CX = Convert.ToInt32(xc),
                    CY = Convert.ToInt32(yc),
                    Radius = 4,
                    FillStyle = "#333",
                    StrokeStyle = color,
                    LineWidth = 2
                });

                AbstractSprite rect = new RectSprite
                {
                    X = Convert.ToInt32(leftgutter + x * i),
                    Y = 0,
                    Width = Convert.ToInt32(xc),
                    Height = heightCraph,
                    StrokeStyle = "none",
                    FillStyle = "#fff",
                    GlobalAlpha = 0
                };

                //rect.Listeners.MouseOver.Handler = string.Format("onMouseOver(this, {0}, {1}, {2});", data[i], labels[i], i);
                //rect.Listeners.MouseOut.Handler = string.Format("onMouseOut(this, {0});", i);

                draw.Items.Add(rect);

                if (i == (labels.Count - 1))
                {
                    p.AddRange(new string[] { JSON.Serialize(xc), JSON.Serialize(yc), JSON.Serialize(xc), JSON.Serialize(yc) });
                    bgpp.AddRange(new string[] { JSON.Serialize(xc), JSON.Serialize(yc), JSON.Serialize(xc), JSON.Serialize(yc), "L", JSON.Serialize(xc), JSON.Serialize(height - bottomgutter), "z" });
                    pathSprite.Path = string.Join(" ", p);
                    bgpSprite.Path = string.Join(" ", bgpp);
                }
            }

            draw.Width = width;
            draw.Height = height;

            return draw;
        }
        private DrawContainer Draw(List <int> labels, List <int> data)
        {
            DrawContainer draw = new DrawContainer
            {
                ID     = "Draw1",
                Border = false
            };

            int    width        = 800;
            int    height       = 250;
            int    leftgutter   = 30;
            int    bottomgutter = 20;
            int    topgutter    = 20;
            double colorhue     = 0.6;
            string color        = System.Drawing.ColorTranslator.ToHtml(this.ColorFromHSB(colorhue, 0.5, 0.5));

            double x   = (width - leftgutter) / (labels.Count * 1.0);
            int    max = data.Max();
            double y   = (height - bottomgutter - topgutter) / (max * 1.0);

            draw.Items.Add(this.GridPath(leftgutter + y * 0.5 + 0.5, topgutter + 0.5, width - leftgutter - x, height - topgutter - bottomgutter, 10, 10, "#000"));

            PathSprite pathSprite = new PathSprite
            {
                StrokeStyle = color,
                LineWidth   = 4,
                Linejoin    = StrokeLinejoin.Round
            };

            draw.Items.Add(pathSprite);

            PathSprite bgpSprite = new PathSprite
            {
                StrokeStyle = "none",
                GlobalAlpha = 0.3,
                FillStyle   = color
            };

            draw.Items.Add(bgpSprite);

            List <string> p    = new List <string>();
            List <string> bgpp = new List <string>();

            for (int i = 0; i < labels.Count; i++)
            {
                int yc          = Convert.ToInt32(Math.Round(height - bottomgutter - y * data[i]));
                int xc          = Convert.ToInt32(Math.Round(leftgutter - 10 + x * (i + 0.5)));
                int heightCraph = height - bottomgutter;
                draw.Items.Add(new TextSprite
                {
                    X         = Convert.ToInt32(xc),
                    Y         = height - 6,
                    Text      = labels[i].ToString(),
                    FillStyle = "#000",
                    Font      = "12px Helvetica, Arial"
                });

                if (i == 0)
                {
                    p.AddRange(new string[] { "M", JSON.Serialize(xc), JSON.Serialize(yc),
                                              "C", JSON.Serialize(xc), JSON.Serialize(yc) });

                    bgpp.AddRange(new string[] { "M", JSON.Serialize(leftgutter - 10 + x * 0.5), JSON.Serialize(height - bottomgutter),
                                                 "L", JSON.Serialize(xc), JSON.Serialize(yc),
                                                 "C", JSON.Serialize(xc), JSON.Serialize(yc) });
                }

                if (i > 0 && i < (labels.Count - 1))
                {
                    double   Y0 = Math.Round(height - bottomgutter - y * data[i - 1]);
                    double   X0 = Math.Round(leftgutter + x * (i - 0.5));
                    double   Y2 = Math.Round(height - bottomgutter - y * data[i + 1]);
                    double   X2 = Math.Round(leftgutter + x * (i + 1.5));
                    double[] a  = this.GetAnchors(X0, Y0, xc, yc, X2, Y2);

                    p.AddRange(new string[] { JSON.Serialize(a[0]), JSON.Serialize(a[1]), JSON.Serialize(xc), JSON.Serialize(yc), JSON.Serialize(a[2]), JSON.Serialize(a[3]) });
                    bgpp.AddRange(new string[] { JSON.Serialize(a[0]), JSON.Serialize(a[1]), JSON.Serialize(xc), JSON.Serialize(yc), JSON.Serialize(a[2]), JSON.Serialize(a[3]) });
                }

                draw.Items.Add(new CircleSprite
                {
                    SpriteID    = "dot_" + i,
                    CX          = Convert.ToInt32(xc),
                    CY          = Convert.ToInt32(yc),
                    Radius      = 4,
                    FillStyle   = "#333",
                    StrokeStyle = color,
                    LineWidth   = 2
                });

                AbstractSprite rect = new RectSprite
                {
                    X           = Convert.ToInt32(leftgutter + x * i),
                    Y           = 0,
                    Width       = Convert.ToInt32(xc),
                    Height      = heightCraph,
                    StrokeStyle = "none",
                    FillStyle   = "#fff",
                    GlobalAlpha = 0
                };

                //rect.Listeners.MouseOver.Handler = string.Format("onMouseOver(this, {0}, {1}, {2});", data[i], labels[i], i);
                //rect.Listeners.MouseOut.Handler = string.Format("onMouseOut(this, {0});", i);

                draw.Items.Add(rect);

                if (i == (labels.Count - 1))
                {
                    p.AddRange(new string[] { JSON.Serialize(xc), JSON.Serialize(yc), JSON.Serialize(xc), JSON.Serialize(yc) });
                    bgpp.AddRange(new string[] { JSON.Serialize(xc), JSON.Serialize(yc), JSON.Serialize(xc), JSON.Serialize(yc), "L", JSON.Serialize(xc), JSON.Serialize(height - bottomgutter), "z" });
                    pathSprite.Path = string.Join(" ", p);
                    bgpSprite.Path  = string.Join(" ", bgpp);
                }
            }

            draw.Width  = width;
            draw.Height = height;

            return(draw);
        }