Пример #1
1
        public LinesModule()
        {
            Get["/examples/w3schools/lines/1"] = _ =>
            {
                var svg = new Svg(500,210);

                svg
                    .Line(0, 0, 200, 200)
                    .WithStroke(255, 0, 0)
                    .WithStrokeWidth(2);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Пример #2
0
        public GoogleAuthProvider(IAppSettings appSettings)
            : base(appSettings, Realm, Name)
        {
            VerifyAccessTokenAsync = OnVerifyAccessTokenAsync;
            this.AuthorizeUrl      = appSettings.Get($"oauth.{Name}.AuthorizeUrl", DefaultAuthorizeUrl);
            this.AccessTokenUrl    = appSettings.Get($"oauth.{Name}.AccessTokenUrl", DefaultAccessTokenUrl);
            this.UserProfileUrl    = appSettings.Get($"oauth.{Name}.UserProfileUrl", DefaultUserProfileUrl);
            this.VerifyTokenUrl    = appSettings.Get($"oauth.{Name}.VerifyTokenUrl", DefaultVerifyTokenUrl);

            if (this.Scopes == null || this.Scopes.Length == 0)
            {
                this.Scopes = new[] {
                    "https://www.googleapis.com/auth/userinfo.profile",
                    "https://www.googleapis.com/auth/userinfo.email"
                };
            }

            Icon    = Svg.ImageSvg("<svg xmlns='http://www.w3.org/2000/svg' fill='currentColor' viewBox='0 0 24 24'><path d='M11.99 13.9v-3.72h9.36c.14.63.25 1.22.25 2.05c0 5.71-3.83 9.77-9.6 9.77c-5.52 0-10-4.48-10-10S6.48 2 12 2c2.7 0 4.96.99 6.69 2.61l-2.84 2.76c-.72-.68-1.98-1.48-3.85-1.48c-3.31 0-6.01 2.75-6.01 6.12s2.7 6.12 6.01 6.12c3.83 0 5.24-2.65 5.5-4.22h-5.51v-.01z' fill='currentColor' /></svg>");
            NavItem = new NavItem {
                Href      = "/auth/" + Name,
                Label     = "Sign In with Google",
                Id        = "btn-" + Name,
                ClassName = "btn-social btn-google",
                IconClass = "fab svg-google",
            };
        }
Пример #3
0
        public DiscordAuthProvider(IAppSettings appSettings)
            : base(appSettings, Realm, Name, "ClientId", "ClientSecret")
        {
            AuthorizeUrl   = appSettings.Get($"oauth.{Name}.AuthorizeUrl", DefaultAuthorizeUrl);
            AccessTokenUrl = appSettings.Get($"oauth.{Name}.AccessTokenUrl", DefaultAccessTokenUrl);
            UserProfileUrl = appSettings.Get($"oauth.{Name}.UserProfileUrl", DefaultUserProfileUrl);

            if (Scopes == null || Scopes.Length == 0)
            {
                Scopes = new[]
                {
                    "identify",
                    "email"
                };
            }

            Icon    = Svg.ImageSvg("<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M14.82 4.26a10.14 10.14 0 0 0-.53 1.1a14.66 14.66 0 0 0-4.58 0a10.14 10.14 0 0 0-.53-1.1a16 16 0 0 0-4.13 1.3a17.33 17.33 0 0 0-3 11.59a16.6 16.6 0 0 0 5.07 2.59A12.89 12.89 0 0 0 8.23 18a9.65 9.65 0 0 1-1.71-.83a3.39 3.39 0 0 0 .42-.33a11.66 11.66 0 0 0 10.12 0q.21.18.42.33a10.84 10.84 0 0 1-1.71.84a12.41 12.41 0 0 0 1.08 1.78a16.44 16.44 0 0 0 5.06-2.59a17.22 17.22 0 0 0-3-11.59a16.09 16.09 0 0 0-4.09-1.35zM8.68 14.81a1.94 1.94 0 0 1-1.8-2a1.93 1.93 0 0 1 1.8-2a1.93 1.93 0 0 1 1.8 2a1.93 1.93 0 0 1-1.8 2zm6.64 0a1.94 1.94 0 0 1-1.8-2a1.93 1.93 0 0 1 1.8-2a1.92 1.92 0 0 1 1.8 2a1.92 1.92 0 0 1-1.8 2z' fill='currentColor'/></svg>");
            NavItem = new NavItem
            {
                Href      = "/auth/" + Name,
                Label     = "Sign In with Discord",
                Id        = "btn-" + Name,
                ClassName = "btn-social btn-discord",
                IconClass = "fab fa-discord",
            };
        }
Пример #4
0
        public RadialGradientsModule()
        {
            Get["/examples/w3schools/radial-gradients/1"] = _ =>
            {
                var svg = new Svg(500, 150);

                var grad1 = svg.Defs.AddRadialGradient("50%", "50%", "50%", "50%", "50%")
                            .AddStop("0%", "rgb(255,255,255)", 0)
                            .AddStop("100%", "rgb(0,0,255)", 1);

                svg.Ellipse(200, 70, 85, 55).WithFill(grad1);

                return(Response.AsSvg(svg));
            };

            Get["/examples/w3schools/radial-gradients/2"] = _ =>
            {
                var svg = new Svg(500, 150);

                var grad2 = svg.Defs.AddRadialGradient("20%", "30%", "30%", "50%", "50%")
                            .AddStop("0%", "rgb(0,0,255)", 0)
                            .AddStop("100%", "rgb(0,0,255)", 1);

                svg.Ellipse(200, 70, 85, 55).WithFill(grad2);

                return(Response.AsSvg(svg));
            };
        }
Пример #5
0
        protected override void GeneratePattern()
        {
            var square_size = HexVal(0, 1).MapTo(0, 15, 10, 60);
            var tile        = BuildOctagonShape(square_size);

            Svg.Width  = square_size * 6;
            Svg.Height = square_size * 6;

            var i = 0;

            for (var y = 0; y <= 5; y++)
            {
                for (var x = 0; x <= 5; x++)
                {
                    var val     = HexVal(i, 1);
                    var opacity = Opacity(val);
                    var fill    = FillColor(val);

                    Svg.PolyLine(tile, new Dictionary <string, object>
                    {
                        { "fill", fill },
                        { "fill-opacity", opacity },
                        { "stroke", Options["stroke_color"] },
                        { "stroke-opacity", Options["stroke_opacity"] },
                        { "transform", string.Format("translate({0}, {1})", x * square_size, y * square_size) }
                    });

                    i++;
                }
            }
        }
Пример #6
0
        public void Configure(IAppHost appHost)
        {
            appHost.CustomErrorHttpHandlers[HttpStatusCode.NotFound]  = new SharpPageHandler("/notfound");
            appHost.CustomErrorHttpHandlers[HttpStatusCode.Forbidden] = new SharpPageHandler("/forbidden");

            Svg.Load(appHost.RootDirectory.GetDirectory("/assets/svg"));
            Svg.CssFillColor["svg-icons"] = "#2f495e";

            View.NavItems.AddRange(new List <NavItem>
            {
                new NavItem {
                    Href = "/", Label = "Home", Exact = true
                },
                new NavItem {
                    Href = "/about", Label = "About"
                },
                new NavItem {
                    Href = "/login", Label = "Sign In", Hide = "auth"
                },
                new NavItem {
                    Href = "/profile", Label = "Profile", Show = "auth"
                },
                new NavItem {
                    Href = "/admin", Label = "Admin", Show = "role:Admin"
                },
            });
        }
Пример #7
0
        public LinkedInAuthProvider(IAppSettings appSettings)
            : base(appSettings, Realm, Name)
        {
            this.AuthorizeUrl   = appSettings.Get($"oauth.{Name}.AuthorizeUrl", DefaultAuthorizeUrl);
            this.AccessTokenUrl = appSettings.Get($"oauth.{Name}.AccessTokenUrl", DefaultAccessTokenUrl);

            //Fields available at: http://developer.linkedin.com/documents/profile-fields
            this.UserProfileUrl = appSettings.Get($"oauth.{Name}.UserProfileUrl", DefaultUserProfileUrl);

            if (this.Scopes == null || this.Scopes.Length == 0)
            {
                this.Scopes = new[] {
                    "r_emailaddress",
                    "r_basicprofile"
                };
            }

            Icon    = Svg.ImageSvg("<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><g fill='none'><path fill-rule='evenodd' clip-rule='evenodd' d='M1 2.838A1.838 1.838 0 0 1 2.838 1H21.16A1.837 1.837 0 0 1 23 2.838V21.16A1.838 1.838 0 0 1 21.161 23H2.838A1.838 1.838 0 0 1 1 21.161V2.838zm8.708 6.55h2.979v1.496c.43-.86 1.53-1.634 3.183-1.634c3.169 0 3.92 1.713 3.92 4.856v5.822h-3.207v-5.106c0-1.79-.43-2.8-1.522-2.8c-1.515 0-2.145 1.089-2.145 2.8v5.106H9.708V9.388zm-5.5 10.403h3.208V9.25H4.208v10.54zM7.875 5.812a2.063 2.063 0 1 1-4.125 0a2.063 2.063 0 0 1 4.125 0z' fill='currentColor'/></g></svg>");
            NavItem = new NavItem {
                Href      = "/auth/" + Name,
                Label     = "Sign In with LinkedIn",
                Id        = "btn-" + Name,
                ClassName = "btn-social btn-linkedin",
                IconClass = "fab svg-linkedin",
            };
        }
Пример #8
0
        public int Delete(string svgId)
        {
            Svg        svg        = GetSvgById(svgId);
            SvgBinding svgBinding = GetSvgBindingBySvgId(svgId);
            int        count      = 0;

            using (DbContextTransaction trans = _db.Database.BeginTransaction())
            {
                try
                {
                    if (svg != null)
                    {
                        _db.Svg.Remove(svg);
                        count += _db.SaveChanges();
                    }

                    if (svgBinding != null)
                    {
                        _db.SvgBinding.Remove(svgBinding);
                        count += _db.SaveChanges();
                    }

                    trans.Commit();
                }
                catch (Exception e)
                {
                    trans.Rollback();
                }
            }

            return(count);
        }
        private void draw_inner_mosaic_tile(double x, double y, double triangle_size, int[] vals)
        {
            var triangle = build_right_triangle_shape(triangle_size);
            var opacity  = Opacity(vals[0]);
            var fill     = FillColor(vals[0]);
            var styles   = new Dictionary <string, object> {
                { "stroke", Options["stroke_color"] },
                { "stroke-opacity", Options["stroke_opacity"] },
                { "fill-opacity", opacity },
                { "fill", fill }
            };

            Svg.PolyLine(triangle, styles.Merge(Transform("translate({0}, {1}) scale(-1, 1)", x + triangle_size, y)));
            Svg.PolyLine(triangle, styles.Merge(Transform("translate({0}, {1}) scale(1, -1)", x + triangle_size, y + triangle_size * 2)));

            opacity = Opacity(vals[1]);
            fill    = FillColor(vals[1]);
            styles  = new Dictionary <string, object> {
                { "stroke", Options["stroke_color"] },
                { "stroke-opacity", Options["stroke_opacity"] },
                { "fill-opacity", opacity },
                { "fill", fill }
            };
            Svg.PolyLine(triangle, styles.Merge(Transform("translate({0}, {1}) scale(-1, -1)", x + triangle_size, y + triangle_size * 2)));
            Svg.PolyLine(triangle, styles.Merge(Transform("translate({0}, {1}) scale(1, 1)", x + triangle_size, y)));
        }
Пример #10
0
        public void Configure(IAppHost appHost)
        {
            // if wwwroot/ is empty, build Client App with 'npm run build'
            var svgDir = appHost.RootDirectory.GetDirectory("/svg");

            if (svgDir != null)
            {
                Svg.Load(svgDir);
            }

            View.NavItems.AddRange(new List <NavItem>
            {
                new NavItem {
                    Href = "/", Label = "Home", Exact = true
                },
                new NavItem {
                    Href = "/about", Label = "About"
                },
                new NavItem {
                    Href = "/signin", Label = "Sign In", Hide = "auth"
                },
                new NavItem {
                    Href = "/profile", Label = "Profile", Show = "auth"
                },
                new NavItem {
                    Href = "/admin", Label = "Admin", Show = "role:Admin"
                },
            });
        }
Пример #11
0
 private void BuildPlusShape(double square_size, Dictionary <string, object> args = null)
 {
     Svg.BeginGroup(args)
     .Rect(square_size, 0, square_size, square_size * 3)
     .Rect(0, square_size, square_size * 3, square_size)
     .EndGroup();
 }
Пример #12
0
        public PolylinesModule()
        {
            Get["/examples/w3schools/polylines/1"] = _ =>
            {
                var svg = new Svg(500, 200);

                svg
                .Polyline(20, 20, 40, 25, 60, 40, 80, 120, 120, 140, 200, 180)
                .WithFill("none")
                .WithStroke("black")
                .WithStrokeWidth(3);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/polylines/2"] = _ =>
            {
                var svg = new Svg(500, 180);

                svg
                .Polyline(0, 40, 40, 40, 40, 80, 80, 80, 80, 120, 120, 120, 120, 160)
                .WithFill("white")
                .WithStroke("red")
                .WithStrokeWidth(4);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };
        }
Пример #13
0
        internal static string ToIconValue(this object icon)
        {
            if (icon.IsUsed())
            {
                var value = Convert.ToInt32(icon);

                if (icon.GetType() == typeof(FlatIcon))
                {
                    return(Flat.Get((FlatIcon)value));
                }
                else if (icon.GetType() == typeof(Flat2Icon))
                {
                    return(Flat2.Get((Flat2Icon)value));
                }
                else if (icon.GetType() == typeof(FontawesomeIcon))
                {
                    return(Fontawesome.Get((FontawesomeIcon)value));
                }
                else if (icon.GetType() == typeof(LineawesomeIcon))
                {
                    return(Lineawesome.Get((LineawesomeIcon)value));
                }
                else if (icon.GetType() == typeof(SocIcon))
                {
                    return(Soc.Get((SocIcon)value));
                }
                else if (icon.GetType() == typeof(SvgIcon))
                {
                    return(Svg.Get((SvgIcon)value));
                }
            }

            return("");
        }
Пример #14
0
        protected override void GeneratePattern()
        {
            var square_size = HexVal(0, 1).MapTo(0, 15, 10, 60);

            Svg.Width  = square_size * 6;
            Svg.Height = square_size * 6;

            var i = 0;

            for (var y = 0; y <= 5; y++)
            {
                for (var x = 0; x <= 5; x++)
                {
                    var val     = HexVal(i, 1);
                    var opacity = Opacity(val);
                    var fill    = FillColor(val);

                    Svg.Rect(x * square_size, y * square_size, square_size, square_size, new Dictionary <string, object> {
                        { "fill", fill },
                        { "fill-opacity", opacity },
                        { "stroke", Options["stroke_color"] },
                        { "stroke-opacity", Options["stroke_opacity"] }
                    });

                    i++;
                }
            }
        }
Пример #15
0
        public void Execute()
        {
            // Load the SVG
            var svg = Svg.Load(options.SvgPath);

            // Save the SVG
            var outPath = Path.Join("OUTPUT", Path.GetFileName(options.SvgPath));

            FileHelpers.SaveSvg(svg, outPath);

            // Optionally, print the SVG to the console
            if (options.Echo)
            {
                Svg.Save(svg, Console.Out);

                Console.WriteLine();
            }

            // Create the HTML wrapper, unless requested otherwise.
            string htmlPath = null;

            if (!options.NoHtml)
            {
                htmlPath = Path.Join("OUTPUT", Path.GetFileNameWithoutExtension(outPath) + ".html");

                FileHelpers.WriteHtmlWrapper(htmlPath, options.SvgPath, outPath);
            }

            // Optionally, open the HTML wrapper (or SVG) in the default browser
            // TODO
        }
Пример #16
0
        public int Update(Svg svg)
        {
            _db.Entry(svg).State = System.Data.Entity.EntityState.Modified;

            _db.Entry(svg).Property(s => s.SvgName).IsModified = true;
            return(_db.SaveChanges());
        }
Пример #17
0
        public void TestCase()
        {
            var fileData    = FileHelper.GetManifestResource(this.GetType().Assembly, "machine.svg");
            var fileService = Svg.FromData(fileData);

            Console.WriteLine("");
        }
Пример #18
0
        public void CanLoadSample(string samplePath)
        {
            // Arrange
            string content;
            var    assembly = Assembly.GetExecutingAssembly();
            var    cleaned  = samplePath.Replace("-", "_").Replace("/", ".");
            var    path     = "SwishSvg.Tests.Samples." + cleaned;

            using (var stream = assembly.GetManifestResourceStream(path))
            {
                stream.Should().NotBeNull($"{path} should exist");

                using (var reader = new StreamReader(stream))
                {
                    content = reader.ReadToEnd();
                }
            }

            // Act
            var svg = Svg.FromString <SvgSvgElement>(content);

            // Assert
            VerifyNoUnknownElements(svg, "svg");
            VerifyNoExtraAttributes(svg, "svg");
        }
Пример #19
0
        public RadialGradientsModule()
        {
            Get["/examples/w3schools/radial-gradients/1"] = _ =>
            {
                var svg = new Svg(500, 150);

                var grad1 = svg.Defs.AddRadialGradient("50%", "50%", "50%", "50%", "50%")
                    .AddStop("0%", "rgb(255,255,255)", 0)
                    .AddStop("100%", "rgb(0,0,255)", 1);

                svg.Ellipse(200, 70, 85, 55).WithFill(grad1);

                return Response.AsSvg(svg);
            };

            Get["/examples/w3schools/radial-gradients/2"] = _ =>
            {
                var svg = new Svg(500, 150);

                var grad2 = svg.Defs.AddRadialGradient("20%", "30%", "30%", "50%", "50%")
                    .AddStop("0%", "rgb(0,0,255)", 0)
                    .AddStop("100%", "rgb(0,0,255)", 1);

                svg.Ellipse(200, 70, 85, 55).WithFill(grad2);

                return Response.AsSvg(svg);
            };
        }
Пример #20
0
        public void CanLoadRectAttributes()
        {
            // Arrange
            var x      = new SvgLength(6.2f, SvgUnit.Inch);
            var y      = new SvgLength(316, SvgUnit.User);
            var width  = new SvgLength(22, SvgUnit.Em);
            var height = new SvgLength(23, SvgUnit.Centimeter);
            var rx     = new SvgLength(54, SvgUnit.Inch);
            var ry     = new SvgLength(45, SvgUnit.Inch);

            var xml = ElementBuilder.Create("rect")
                      .AddAttribute("x", x.ToString())
                      .AddAttribute("y", y.ToString())
                      .AddAttribute("width", width.ToString())
                      .AddAttribute("height", height.ToString())
                      .AddAttribute("rx", rx.ToString())
                      .AddAttribute("ry", ry.ToString());

            // Act
            var rect = Svg.FromString <SvgRectElement>(xml.ToString());

            // Assert
            rect.X.Should().Be(x);
            rect.Y.Should().Be(y);
            rect.Width.Should().Be(width);
            rect.Height.Should().Be(height);
            rect.RX.Should().Be(rx);
            rect.RY.Should().Be(ry);
        }
Пример #21
0
    public void Configure(IWebHostBuilder builder) => builder
    //.ConfigureServices(services => services.AddSingleton<ICacheClient>(new MemoryCacheClient()))
    .ConfigureAppHost(appHost =>
    {
        var appSettings = appHost.AppSettings;
        appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
                                            new IAuthProvider[] {
            new JwtAuthProvider(appSettings)
            {
                AuthKeyBase64 = appSettings.GetString("AuthKeyBase64") ?? "cARl12kvS/Ra4moVBIaVsrWwTpXYuZ0mZf/gNLUhDW5=",
            },
            new CredentialsAuthProvider(appSettings),             /* Sign In with Username / Password credentials */
            new FacebookAuthProvider(appSettings),                /* Create App https://developers.facebook.com/apps */
            new GoogleAuthProvider(appSettings),                  /* Create App https://console.developers.google.com/apis/credentials */
            new MicrosoftGraphAuthProvider(appSettings),          /* Create App https://apps.dev.microsoft.com */
        })
        {
            // IncludeDefaultLogin = false
            ProfileImages = new PersistentImagesHandler("/auth-profiles", Svg.GetStaticContent(Svg.Icons.Female),
                                                        appHost.VirtualFiles, "/App_Data/auth-profiles")
        });

        appHost.Plugins.Add(new RegistrationFeature());     //Enable /register Service

        //override the default registration validation with your own custom implementation
        appHost.RegisterAs <CustomRegistrationValidator, IValidator <Register> >();
    });
Пример #22
0
        public PolylinesModule()
        {
            Get["/examples/w3schools/polylines/1"] = _ =>
            {
                var svg = new Svg(500,200);

                svg
                    .Polyline(20, 20, 40, 25, 60, 40, 80, 120, 120, 140, 200, 180)
                    .WithFill("none")
                    .WithStroke("black")
                    .WithStrokeWidth(3);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/polylines/2"] = _ =>
            {
                var svg = new Svg(500,180);

                svg
                    .Polyline(0, 40, 40, 40, 40, 80, 80, 80, 80, 120, 120, 120, 120, 160)
                    .WithFill("white")
                    .WithStroke("red")
                    .WithStrokeWidth(4);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Пример #23
0
        public IEnumerable <XElement> GetSvgPaths()
        {
            Kurve.Curves.Curve curve = optimizer.GetCurve(specification);

            IEnumerable <string> curveCommands = Enumerables.Concatenate
                                                 (
                Enumerables.Create(Svg.MoveTo(curve.GetPoint(0))),
                from positions in Scalars.GetIntermediateValuesSymmetric(0, 1, SegmentCount + 1).GetRanges()
                let controlPoint1 = curve.GetPoint(positions.Item1) + (1.0 / (3 * SegmentCount)) * curve.GetVelocity(positions.Item1)
                                    let controlPoint2 = curve.GetPoint(positions.Item2) - (1.0 / (3 * SegmentCount)) * curve.GetVelocity(positions.Item2)
                                                        let point2 = curve.GetPoint(positions.Item2)
                                                                     select Svg.CurveTo(controlPoint1, controlPoint2, point2)
                                                 );

            yield return(Svg.PathShape(curveCommands, null, Colors.Black, 2));

            IEnumerable <string> curvatureMarkersCommands =
                (
                    from positions in Scalars.GetIntermediateValuesSymmetric(0, 1, SegmentCount + 1).GetRanges()
                    let position = Enumerables.Average(positions.Item1, positions.Item2)
                                   let curvatureVector = CurvatureMarkersFactor * curve.GetCurvature(position) * curve.GetNormalVector(position)
                                                         select Svg.Line(curve.GetPoint(position), curve.GetPoint(position) + curvatureVector)
                );

            yield return(Svg.PathShape(curvatureMarkersCommands, null, Colors.Blue, 0.5));

            foreach (PointCurveSpecification pointCurveSpecification in specification.BasicSpecification.CurveSpecifications.OfType <PointCurveSpecification>())
            {
                Vector2Double point = curve.GetPoint(pointCurveSpecification.Position);

                yield return(Svg.CircleShape(point, 10, Colors.Red, null, 0));
            }
            foreach (DirectionCurveSpecification directionCurveSpecification in specification.BasicSpecification.CurveSpecifications.OfType <DirectionCurveSpecification>())
            {
                Vector2Double directionVector = curve.GetDirectionVector(directionCurveSpecification.Position);
                Vector2Double start           = curve.GetPoint(directionCurveSpecification.Position) - 1000 * directionVector;
                Vector2Double end             = curve.GetPoint(directionCurveSpecification.Position) + 1000 * directionVector;

                yield return(Svg.LineShape(start, end, null, Colors.Green, 2));
            }
            foreach (CurvatureCurveSpecification curvatureCurveSpecification in specification.BasicSpecification.CurveSpecifications.OfType <CurvatureCurveSpecification>())
            {
                if (curvatureCurveSpecification.Curvature == 0)
                {
                    Vector2Double directionVector = curve.GetDirectionVector(curvatureCurveSpecification.Position);
                    Vector2Double start           = curve.GetPoint(curvatureCurveSpecification.Position) - 1000 * directionVector;
                    Vector2Double end             = curve.GetPoint(curvatureCurveSpecification.Position) + 1000 * directionVector;

                    yield return(Svg.LineShape(start, end, null, Colors.Blue, 2));
                }
                else
                {
                    Vector2Double center = curve.GetPoint(curvatureCurveSpecification.Position) - (1.0 / curvatureCurveSpecification.Curvature) * curve.GetNormalVector(curvatureCurveSpecification.Position);
                    double        radius = 1.0 / curvatureCurveSpecification.Curvature.Absolute();

                    yield return(Svg.CircleShape(center, radius, null, Colors.Blue, 2));
                }
            }
        }
Пример #24
0
        public void Can_parse_svg_datauri()
        {
            var dataUri = Svg.GetDataUri(Svg.Icons.Male);
            var content = StaticContent.CreateFromDataUri(dataUri);

            Assert.That(content.MimeType, Is.EqualTo("image/svg+xml"));
            Assert.That(content.Data.FromUtf8().ToString(), Is.EqualTo(Svg.GetImage(Svg.Icons.Male)));
        }
        public void Configure(IAppHost appHost)
        {
            appHost.CustomErrorHttpHandlers[HttpStatusCode.NotFound] = new RazorHandler("/notfound");
            appHost.CustomErrorHttpHandlers[HttpStatusCode.Forbidden] = new RazorHandler("/forbidden");

            Svg.Load(appHost.RootDirectory.GetDirectory("/assets/svg"));
            Svg.CssFillColor["svg-icons"] = "#343a40";
        }
Пример #26
0
 public void Configure(IWebHostBuilder builder) => builder
 .ConfigureAppHost(appHost => {
     // if wwwroot/ is empty, build Client App with 'npm run build'
     var svgDir = appHost.RootDirectory.GetDirectory("/svg") ?? appHost.ContentRootDirectory.GetDirectory("/public/svg");
     if (svgDir != null)
     {
         Svg.Load(svgDir);
     }
 });
Пример #27
0
        public void WriteToFile(Svg svg, string path)
        {
            var sb = new StringBuilder("<svg>");

            sb.Append(string.Join(Environment.NewLine, svg.Elements.Select(e => e.Content)));
            sb.Append("</svg>");

            File.WriteAllText(path, sb.ToString());
        }
Пример #28
0
        public PolygonsModule()
        {
            Get["/examples/w3schools/polygons/1"] = _ =>
            {
                var svg = new Svg(500, 210);

                svg
                .Polygon(200, 10, 250, 190, 160, 210)
                .WithFill("lime")
                .WithStroke("purple")
                .WithStrokeWidth(1);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/polygons/2"] = _ =>
            {
                var svg = new Svg(500, 250);

                svg
                .Polygon(220, 10, 300, 210, 170, 250, 123, 234)
                .WithFill("lime")
                .WithStroke("purple")
                .WithStrokeWidth(1);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/polygons/3"] = _ =>
            {
                var svg = new Svg(500, 210);

                svg
                .Polygon(100, 10, 40, 198, 190, 78, 10, 78, 160, 198)
                .WithFill("lime")
                .WithStroke("purple")
                .WithStrokeWidth(5)
                .WithFillRule(FillRule.NonZero);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/polygons/4"] = _ =>
            {
                var svg = new Svg(500, 210);

                svg
                .Polygon(100, 10, 40, 198, 190, 78, 10, 78, 160, 198)
                .WithFill("lime")
                .WithStroke("purple")
                .WithStrokeWidth(5)
                .WithFillRule(FillRule.EvenOdd);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };
        }
Пример #29
0
        public RectanglesModule()
        {
            Get["/examples/w3schools/rectangles/1"] = _ =>
            {
                var svg = new Svg(400, 110);

                svg
                .Rectangle(0, 0, 300, 100)
                .WithFill(0, 0, 255)
                .WithStrokeWidth(3)
                .WithStroke(0, 0, 0);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/rectangles/2"] = _ =>
            {
                var svg = new Svg(400, 180);

                svg.Rectangle(50, 20, 150, 150)
                .WithFill("blue")
                .WithStroke("pink")
                .WithStrokeWidth(5)
                .WithFillOpacity(0.1)
                .WithStrokeOpacity(0.9);

                return(Response.AsText(svg.ToString()).WithContentType("image/svg+xml"));
            };

            Get["/examples/w3schools/rectangles/3"] = _ =>
            {
                var svg = new Svg(400, 180);

                svg.Rectangle(50, 20, 150, 150)
                .WithFill("blue")
                .WithStroke("pink")
                .WithStrokeWidth(5)
                .WithOpacity(0.5);

                return(Response.AsText(svg.ToString()).WithContentType("image/svg+xml"));
            };

            Get["/examples/w3schools/rectangles/4"] = _ =>
            {
                var svg = new Svg(400, 180);

                svg.Rectangle(50, 20, 150, 150)
                .WithRoundedCorners(20, 20)
                .WithFill("red")
                .WithStroke("black")
                .WithStrokeWidth(5)
                .WithOpacity(0.5);

                return(Response.AsText(svg.ToString()).WithContentType("image/svg+xml"));
            };
        }
Пример #30
0
        // http://localhost:5000/auth/[email protected]&&password=!Abc1234
        // Configure your AppHost with the necessary configuration and dependencies your App needs
        public override void Configure(Container container)
        {
            // enable server-side rendering, see: https://sharpscript.net
            Plugins.Add(new SharpPagesFeature());

            if (Config.DebugMode)
            {
                Plugins.Add(new HotReloadFeature());
            }

            Plugins.Add(new RazorFormat()); // enable ServiceStack.Razor

            SetConfig(new HostConfig
            {
                AddRedirectParamsToQueryString = true,
                DebugMode = AppSettings.Get(nameof(HostConfig.DebugMode), false),
//                UseSameSiteCookies = true, // prevents OAuth providers which use Sessions like Twitter from working
                UseSecureCookies = true,
            });

            var cache = container.Resolve <ICacheClient>();

            Plugins.Add(new ValidationFeature());

//            Svg.CssFillColor["svg-auth"] = "#ccc";
            Svg.CssFillColor["svg-icons"] = "#e33";

            this.CustomErrorHttpHandlers[HttpStatusCode.NotFound]  = new RazorHandler("/notfound");
            this.CustomErrorHttpHandlers[HttpStatusCode.Forbidden] = new SharpPageHandler("/forbidden");

            Svg.Load(RootDirectory.GetDirectory("/assets/svg"));

            Plugins.Add(new PostmanFeature());

            var nativeTypesFeature = GetPlugin <NativeTypesFeature>();

            nativeTypesFeature
            .ExportAttribute <BindableAttribute>(attr => {
                var metaAttr = nativeTypesFeature.GetGenerator().ToMetadataAttribute(attr);
                return(metaAttr);
            });


//            TypeScriptGenerator.TypeFilter = (type, args) => {
//                if (type == "ResponseBase`1" && args[0] == "Dictionary<String,List`1>")
//                    return "ResponseBase<Map<string,Array<any>>>";
//                return null;
//            };

//            TypeScriptGenerator.DeclarationTypeFilter = (type, args) => {
//                return null;
//            };


            //GetPlugin<SvgFeature>().ValidateFn = req => Config.DebugMode; // only allow in DebugMode
        }
Пример #31
0
        public PolygonsModule()
        {
            Get["/examples/w3schools/polygons/1"] = _ =>
            {
                var svg = new Svg(500,210);

                svg
                    .Polygon(200, 10, 250, 190, 160, 210)
                    .WithFill("lime")
                    .WithStroke("purple")
                    .WithStrokeWidth(1);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/polygons/2"] = _ =>
            {
                var svg = new Svg(500,250);

                svg
                    .Polygon(220, 10, 300, 210, 170, 250, 123, 234)
                    .WithFill("lime")
                    .WithStroke("purple")
                    .WithStrokeWidth(1);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/polygons/3"] = _ =>
            {
                var svg = new Svg(500,210);

                svg
                    .Polygon(100, 10, 40, 198, 190, 78, 10, 78, 160, 198)
                    .WithFill("lime")
                    .WithStroke("purple")
                    .WithStrokeWidth(5)
                    .WithFillRule(FillRule.NonZero);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/polygons/4"] = _ =>
            {
                var svg = new Svg(500, 210);

                svg
                    .Polygon(100, 10, 40, 198, 190, 78, 10, 78, 160, 198)
                    .WithFill("lime")
                    .WithStroke("purple")
                    .WithStrokeWidth(5)
                    .WithFillRule(FillRule.EvenOdd);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Пример #32
0
        public RectanglesModule()
        {
            Get["/examples/w3schools/rectangles/1"] = _ =>
            {
                var svg = new Svg(400, 110);

                svg
                    .Rectangle(0, 0, 300, 100)
                    .WithFill(0, 0, 255)
                    .WithStrokeWidth(3)
                    .WithStroke(0, 0, 0);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/rectangles/2"] = _ =>
            {
                var svg = new Svg(400, 180);

                svg.Rectangle(50, 20, 150, 150)
                    .WithFill("blue")
                    .WithStroke("pink")
                    .WithStrokeWidth(5)
                    .WithFillOpacity(0.1)
                    .WithStrokeOpacity(0.9);

                return Response.AsText(svg.ToString()).WithContentType("image/svg+xml");
            };

            Get["/examples/w3schools/rectangles/3"] = _ =>
            {
                var svg = new Svg(400, 180);

                svg.Rectangle(50, 20, 150, 150)
                    .WithFill("blue")
                    .WithStroke("pink")
                    .WithStrokeWidth(5)
                    .WithOpacity(0.5);

                return Response.AsText(svg.ToString()).WithContentType("image/svg+xml");
            };

            Get["/examples/w3schools/rectangles/4"] = _ =>
            {
                var svg = new Svg(400, 180);

                svg.Rectangle(50, 20, 150, 150)
                    .WithRoundedCorners(20, 20)
                    .WithFill("red")
                    .WithStroke("black")
                    .WithStrokeWidth(5)
                    .WithOpacity(0.5);

                return Response.AsText(svg.ToString()).WithContentType("image/svg+xml");
            };
        }
Пример #33
0
        protected override void GeneratePattern()
        {
            var block_size  = HexVal(0, 1).MapTo(0, 15, 4, 12);
            var square_size = block_size * 7;

            Svg.Width  = (square_size + block_size) * 6 + block_size * 6;
            Svg.Height = (square_size + block_size) * 6 + block_size * 6;

            var i = 0;

            for (var y = 0; y <= 5; y++)
            {
                for (var x = 0; x <= 5; x++)
                {
                    var val     = HexVal(i, 1);
                    var opacity = Opacity(val);
                    var fill    = FillColor(val);

                    var styles = new Dictionary <string, object> {
                        { "fill", "none" },
                        { "stroke", fill },
                        {
                            "style", new Dictionary <string, object> {
                                { "opacity", opacity },
                                { "stroke-width", block_size + "px" }
                            }
                        }
                    };

                    Svg.Rect(x * square_size + x * block_size * 2 + block_size / 2,
                             y * square_size + y * block_size * 2 + block_size / 2,
                             square_size, square_size, styles);

                    val     = HexVal(39 - i, 1);
                    opacity = Opacity(val);
                    fill    = FillColor(val);

                    styles = new Dictionary <string, object> {
                        { "fill", "none" },
                        { "stroke", fill },
                        {
                            "style", new Dictionary <string, object> {
                                { "opacity", opacity },
                                { "stroke-width", block_size + "px" }
                            }
                        }
                    };

                    Svg.Rect(x * square_size + x * block_size * 2 + block_size / 2 + block_size * 2,
                             y * square_size + y * block_size * 2 + block_size / 2 + block_size * 2,
                             block_size * 3, block_size * 3, styles);

                    i++;
                }
            }
        }
Пример #34
0
        public void Configure(IAppHost appHost)
        {
            // if wwwroot/ is empty, build Client App with 'npm run build'
            var svgDir = appHost.RootDirectory.GetDirectory("/assets/svg") ?? appHost.ContentRootDirectory.GetDirectory("/src/assets/svg");

            if (svgDir != null)
            {
                Svg.Load(svgDir);
            }
        }
Пример #35
0
        static void Main()
        {
            var      svg  = new Svg(1000, 800);
            SvgGroup grid = Templates.Grid(0, 0, svg.Width, svg.Height, 10, 8);

            grid.SetFill(Color.Aqua);
            grid.SetStroke(Color.Black);
            svg.AddElement(grid);
            svg.SaveAs("grid.svg");
        }
Пример #36
0
        public LinearGradientsModule()
        {
            Get["/examples/w3schools/linear-gradients/1"] = _ =>
            {
                var svg = new Svg(400, 150);

                var grad1 = svg.Defs
                    .AddLinearGradient("0%", "0%", "100%", "0%")
                    .AddStop("0%", "rgb(255,255,0)", 1)
                    .AddStop("100%", "rgb(255,0,0)", 1);

                svg.Ellipse(200, 70, 85, 55)
                    .WithFill(grad1);

                return Response.AsSvg(svg);
            };

            Get["/examples/w3schools/linear-gradients/2"] = _ =>
            {
                var svg = new Svg(400, 150);

                var grad2 = svg.Defs.AddLinearGradient("0%", "0%", "0%", "100%")
                    .AddStop("0%", "rgb(255,255,0)", 1)
                    .AddStop("100%", "rgb(255,0,0)", 1);

                svg.Ellipse(200, 70, 85, 55)
                    .WithFill(grad2);

                return Response.AsSvg(svg);
            };

            Get["/examples/w3schools/linear-gradients/3"] = _ =>
            {
                var svg = new Svg(400, 150);

                var grad1 = svg.Defs.AddLinearGradient("0%", "0%", "100%", "0%")
                    .AddStop("0%", "rgb(255,255,0)", 1)
                    .AddStop("100%", "rgb(255,0,0)", 1);

                svg.Ellipse(200, 70, 85, 55)
                    .WithFill(grad1);
                svg.Text(150, 86, "SVG")
                    .WithFill("#ffffff")
                    .WithFontSize(45)
                    .WithFontFamily("Verdana");

                return Response.AsSvg(svg);
            };
        }
Пример #37
0
        public CirclesModule()
        {
            Get["/examples/w3schools/circles/1"] = _ =>
            {
                var svg = new Svg(100, 100);

                svg
                    .Circle(50, 50, 40)
                    .WithStroke("black")
                    .WithStrokeWidth(3)
                    .WithFill("red");

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Пример #38
0
        public TextModule()
        {
            Get["/examples/w3schools/text/1"] = _ =>
            {
                var svg = new Svg(200, 30);

                svg
                    .Text(0, 15, "I love SVG!")
                    .WithFill("red")
                    .WithFontSize(12);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/text/2"] = _ => {
                var svg = new Svg(200, 60);

                svg
                    .Text(0, 15, "I love SVG!")
                    .WithFill("red")
                    .WithFontSize(12)
                    .WithTransformRotate(30, 20, 40);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/text/3"] = _ => {
                var svg = new Svg(200, 90);

                var text = svg
                    .Text(10, 20, "Several lines:")
                    .WithFill("red")
                    .WithFontSize(12);
                text.AddSpan(10, 45, "First line.");
                text.AddSpan(10, 70, "Second line.");

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/text/4"] = _ => {
                var svg = new Svg(200,30);

                var anchor = svg.Anchor("http://www.w3schools.com/svg", "_blank");
                anchor.Text(0, 15, "I love SVG!").WithFill("red");

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Пример #39
0
        public BlurEffectsModule()
        {
            Get["/examples/w3schools/blur-effects/1"] = _ =>
            {
                var svg = new Svg(110, 110);

                var f1 = svg.Defs.AddFilter();
                f1.GaussianBlur(15, FilterInput.SourceGraphic);

                svg
                    .Rectangle(0, 0, 90, 90)
                    .WithStroke("green")
                    .WithStrokeWidth(3)
                    .WithFill("yellow")
                    .WithFilter(f1);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Пример #40
0
        public VerticalChartLabelsModule()
        {
            Get["/examples/charts/vertical-bar-charts/vertical-chart-labels/multi-line-group-labels"] = _ =>
            {
                var svg = new Svg(400, 200);

                var chart = svg.VerticalBarChart(DataSources.GetIndustriesData())
                    .WithDataLabelFormat("{0}%")
                    .ShowDataLabelOutsideItem()
                    .WithPointColorGenerator(new StackBasedDataPointColorGenerator(new[]
                    {
                        "#6666ff",
                        "orange"
                    }))
                    .WithStroke("black")
                    .WithStrokeWidth(2)
                    .WithPadding(10)
                    .WithGroupLabelAutoLineSplit(8);

                return Response.AsSvg(svg);
            };
        }
Пример #41
0
        public EllipsesModule()
        {
            Get["/examples/w3schools/ellipses/1"] = _ =>
            {
                var svg = new Svg(500, 140);

                svg
                    .Ellipse(200, 80, 100, 50)
                    .WithFill("yellow")
                    .WithStroke("purple")
                    .WithStrokeWidth(2);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/ellipses/2"] = _ =>
            {
                var svg = new Svg(500, 150);

                svg.Ellipse(240, 100, 220, 30).WithFill("purple");
                svg.Ellipse(220, 70, 190, 20).WithFill("lime");
                svg.Ellipse(210, 45, 170, 15).WithFill("yellow");

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/ellipses/3"] = _ =>
            {
                var svg = new Svg(500, 150);

                svg.Ellipse(250, 50, 220, 30).WithFill("yellow");
                svg.Ellipse(220, 50, 190, 20).WithFill("white");

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Пример #42
0
        public ExamplesModule()
        {
            Get["/examples/w3schools/examples/1"] = _ =>
            {
                var svg = new Svg(120, 120);

                var filter = svg.Defs.AddFilter();
                filter.GaussianBlur(5);
                filter.Offset(5, 5);

                svg.Rectangle(0, 0, 90, 90).WithFill("grey").WithFilter(filter);
                svg.Rectangle(0, 0, 90, 90).WithFill("yellow").WithStroke("black");

                return Response.AsSvg(svg);
            };

            var decalSvg = new Svg(400, 200);
            decalSvg.Rectangle(1, 1, 198, 118).WithFill("#cccccc");
            var svgDecal = decalSvg.Group();
            svgDecal.Path("M50,90 C0,90 0,30 50,30 L150,30 C200,30 200,90 150,90 z")
                .WithFill("none")
                .WithStroke("#D90000")
                .WithStrokeWidth(10);
            svgDecal.Text(52, 76, "SVG")
                .WithFill("#FFFFFF")
                .WithStroke("black")
                .WithFontSize(45)
                .WithFontFamily("Verdana");

            Get["/examples/w3schools/examples/2"] = _ =>
            {
                var myFilter = decalSvg.Defs.AddFilter(0, 0, 200, 120)
                    .WithFilterUnits(FilterUnits.UserSpaceOnUse);
                myFilter.GaussianBlur(4, FilterInput.SourceAlpha, "blur");
                myFilter.Offset(4, 4, "blur", "offsetBlur");

                svgDecal.WithFilter(myFilter);

                return Response.AsSvg(decalSvg);
            };

            Get["/examples/w3schools/examples/3"] = _ =>
            {
                var myFilter = decalSvg.Defs.AddFilter(0, 0, 200, 120)
                    .WithFilterUnits(FilterUnits.UserSpaceOnUse);
                myFilter.GaussianBlur(4, FilterInput.SourceAlpha, "blur");
                myFilter.Offset(4, 4, "blur", "offsetBlur");
                myFilter.SpecularLighting(5, .75, 20, "#bbbbbb", "blur", "specOut")
                    .AddPointLight(-5000, -10000, 20000);

                svgDecal.WithFilter(myFilter);

                return Response.AsSvg(decalSvg);
            };

            Get["/examples/w3schools/examples/4"] = _ =>
            {
                var myFilter = decalSvg.Defs.AddFilter(0, 0, 200, 120)
                    .WithFilterUnits(FilterUnits.UserSpaceOnUse);
                myFilter.GaussianBlur(4, FilterInput.SourceAlpha, "blur");
                myFilter.Offset(4, 4, "blur", "offsetBlur");
                myFilter.SpecularLighting(5, .75, 20, "#bbbbbb", "blur", "specOut")
                    .AddPointLight(-5000, -10000, 20000);
                myFilter.Composite("specOut", FilterInput.SourceAlpha, CompositeOperator.In, "specOut");

                svgDecal.WithFilter(myFilter);

                return Response.AsSvg(decalSvg);
            };
        }
Пример #43
0
 public void SetBoundable(Svg.ISvgBoundable boundable)
 {
     _boundables.Push(boundable);
 }
Пример #44
0
        public MultiLineTextModule()
        {
            Get["examples/text/multi-line-text/howl"] = _ =>
            {
                var svg = new Svg(600, 160);

                svg.WithBackgroundFill("#ddd");

                var howl = @"I saw the best minds of my generation destroyed by madness, starving hysterical naked,
            dragging themselves through the negro streets at dawn looking for an angry fix,
            Angel-headed hipsters burning for the ancient heavenly connection
            to the starry dynamo in the machinery of night
            - Howl, Allen Ginsberg";

                svg.MultiLineText(20,20, howl);

                return Response.AsSvg(svg);
            };

            Get["examples/text/multi-line-text/haiku"] = _ =>
            {
                var svg = new Svg(400, 100);

                svg.WithBackgroundFill("#dde");

                var haiku = @"the first cold shower
            even the monkey seems to want
            a little coat of straw";

                svg.MultiLineText((svg.Width ?? 0)/2, 20, haiku)
                    .WithTextAnchor(TextAnchor.Middle)
                    .WithFontStyle(FontStyle.Italic)
                    .WithFontFamily(FontFamilies.Helvetica);

                return Response.AsSvg(svg);
            };

            Get["examples/text/multi-line-text/ulysses"] = _ =>
            {
                var svg = new Svg(250, 700);

                svg.WithBackgroundFill("#333");

                var text = @"Stately, plump Buck Mulligan came from the stairhead, bearing a bowl of lather on which a mirror and a razor lay crossed. A yellow dressinggown, ungirdled, was sustained gently behind him by the mild morning air.";

                svg.MultiLineText(140, 0, text)
                    .WithAutoLineSplit(10)
                    .WithFontFamily(FontFamilies.Helvetica)
                    .WithFill("gold")
                    .WithTransformRotate(10);

                return Response.AsSvg(svg);
            };

            Get["examples/text/multi-line-text/show-origin"] = _ =>
            {
                var svg = new Svg(400, 200);

                svg.WithBackgroundFill("#ddd");

                var text = @"FALSTAFF: Come, thou shalt go to the wars in a
            gown. We will have away thy cold; and I will
            take such order that thy friends shall ring for
            thee. Is here all?";

                svg.MultiLineText(30, 30, text);
                svg.Circle(30, 30, 2).WithFill("red");

                return Response.AsSvg(svg);
            };

            Get["examples/text/multi-line-text/element-line-height"] = _ =>
            {
                var svg = new Svg(550, 250);

                svg.WithBackgroundFill("#ddd");

                var text = @"No one would have believed, in the last years of the nineteenth century, that human affairs were being watched keenly and closely by intelligences greater than man’s and yet as mortal as his own; that as men busied themselves about their affairs they were scrutinized and studied, perhaps almost as narrowly as a man with a microscope might scrutinize the transient creatures that swarm and multiply in a drop of water.";

                var textElement = svg.MultiLineText(30, 40, text)
                    .WithAutoLineSplit(60);
                svg.Line((textElement.X ?? 0) - 14, (textElement.Y ?? 0), (textElement.X ?? 0) - 14, (textElement.Y ?? 0) + (textElement.Height ?? 0))
                    .WithStroke("brown")
                    .WithStrokeLinecap(StrokeLinecap.Round)
                    .WithStrokeWidth(3);

                return Response.AsSvg(svg);
            };
        }
Пример #45
0
 public VPathGroupSVGGenerator(Svg.SvgDocument svg)
 {
     _Svg = svg;
 }
Пример #46
0
        public PathsModule()
        {
            Get["/examples/w3schools/paths/1"] = _ =>
            {
                var svg = new Svg(400, 210);

                svg.Path()
                    .MoveTo(150, 0)
                    .LineTo(75, 200)
                    .LineTo(225, 200)
                    .ClosePath();

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/paths/2"] = _ =>
            {
                var svg = new Svg(450, 400);

                svg.Path()
                    .MoveTo(100, 350)
                    .LineToRelative(150, -300)
                    .ClosePath()
                    .WithStroke("red")
                    .WithStrokeWidth(3)
                    .WithFill("none");
                svg.Path()
                    .MoveTo(250, 50)
                    .LineToRelative(150, 300)
                    .ClosePath()
                    .WithStroke("red")
                    .WithStrokeWidth(3)
                    .WithFill("none");
                svg.Path()
                    .MoveTo(175, 200)
                    .LineToRelative(150, 0)
                    .ClosePath()
                    .WithStroke("green")
                    .WithStrokeWidth(3)
                    .WithFill("none");

                svg.Path()
                    .MoveTo(100, 350)
                    .QuadraticBezierRelative(150, -300, 300, 000)
                    .WithStroke("blue")
                    .WithStrokeWidth(5)
                    .WithFill("none");

                // Mark relevant points
                var relevantPoints = svg.Group()
                    .WithStrokeWidth(3)
                    .WithFill("black");
                relevantPoints.Circle(100, 350, 3);
                relevantPoints.Circle(250, 50, 3);
                relevantPoints.Circle(400, 350, 3);

                // Label the points
                var labels = svg.Group()
                    .WithFontSize(30)
                    .WithFontFamily("sans-serif")
                    .WithFill("black")
                    .WithStroke("none")
                    .WithTextAnchor(TextAnchor.Middle);
                labels.Text(100, 350, "A").WithDx(-30);
                labels.Text(250, 50, "B").WithDy(-10);
                labels.Text(400, 350, "C").WithDx(30);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Пример #47
0
        public GridLegendsModule()
        {
            Get["/examples/charts/grid-legends/standalone-legend"] = _ =>
            {
                var svg = new Svg(400, 3*GridLegend.ItemHeight);

                svg.GridLegend(0, 0)
                    .AddLegendItem(0, 0, "#990000", "Liberal")
                    .AddLegendItem(1, 0, "#000099", "Conservative")
                    .AddLegendItem(0, 1, "#009999", "Bloc Quebecois")
                    .AddLegendItem(1, 1, "#999900", "NDP")
                    .AddLegendItem(2, 0, "#999999", "Other");

                return Response.AsSvg(svg);
            };

            Get["/examples/charts/grid-legends/legend-under-chart"] = _ =>
            {
                var svg = new Svg(400, 400);

                var data = new BarChartData(new double[]
                {
                    133, 98, 54, 19, 4
                });
                var chart = svg.VerticalBarChart(data)
                    .WithDataLabelFormat("{0}")
                    .AlwaysShowDataLabel()
                    .ShowDataLabelOutsideItem()
                    .WithPointColorGenerator(new GroupBasedDataPointColorGenerator(new[]
                    {
                        "#990000", "#000099", "#009999", "#999900", "#999999"
                    }))
                    // bottom gutter for legend
                    .WithBottomGutter(3*GridLegend.ItemHeight + 8);
                chart.GridLegend((chart.X ?? 0) + (chart.Width ?? 0)/2 - GridLegend.ItemWidth, (chart.Y ?? 0) + (chart.Height ?? 0) - 3*GridLegend.ItemHeight + 8)
                    .AddLegendItem(0, 0, "#990000", "Liberal")
                    .AddLegendItem(1, 0, "#000099", "Conservative")
                    .AddLegendItem(0, 1, "#009999", "Bloc Quebecois")
                    .AddLegendItem(1, 1, "#999900", "NDP")
                    .AddLegendItem(2, 0, "#999999", "Other");

                return Response.AsSvg(svg);
            };

            Get["/examples/charts/grid-legends/legend-embedded-in-chart"] = _ =>
            {
                var svg = new Svg(400, 200)
                    .WithBackgroundFill("#eee");

                var data = new BarChartData(new double[]
                {
                    133, 98, 54, 19, 4
                });
                var chart = svg.VerticalBarChart(data)
                    .WithDataLabelFormat("{0}")
                    .AlwaysShowDataLabel()
                    .ShowDataLabelOutsideItem()
                    .WithPointColorGenerator(new GroupBasedDataPointColorGenerator(new[]
                    {
                        "#990000", "#000099", "#009999", "#999900", "#999999"
                    }))
                    .WithGutter(20);
                chart.GridLegend((chart.Width ?? 0) - GridLegend.ItemWidth*2 - 10, 10)
                    .AddLegendItem(0, 0, "#990000", "Liberal")
                    .AddLegendItem(1, 0, "#000099", "Conservative")
                    .AddLegendItem(0, 1, "#009999", "Bloc Quebecois")
                    .AddLegendItem(1, 1, "#999900", "NDP")
                    .AddLegendItem(2, 0, "#999999", "Other");

                return Response.AsSvg(svg);
            };
        }
Пример #48
0
        public StrokingModule()
        {
            Get["/examples/w3schools/stroking/1"] = _ =>
            {
                var svg = new Svg(300, 80);

                var group = svg
                    .Group()
                    .WithFill("none");
                group
                    .Path()
                    .WithStroke("red")
                    .MoveTo(5, 20)
                    .LineToRelative(215, 0);
                group
                    .Path()
                    .WithStroke("blue")
                    .MoveTo(5, 40)
                    .LineToRelative(215, 0);
                group
                    .Path()
                    .WithStroke("black")
                    .MoveTo(5, 60)
                    .LineToRelative(215, 0);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/stroking/2"] = _ =>
            {
                var svg = new Svg(300, 80);

                var group = svg
                    .Group()
                    .WithFill("none")
                    .WithStroke("black");
                group
                    .Path()
                    .WithStrokeWidth(2)
                    .MoveTo(5, 20)
                    .LineToRelative(215, 0);
                group
                    .Path()
                    .WithStrokeWidth(4)
                    .MoveTo(5, 40)
                    .LineToRelative(215, 0);
                group
                    .Path()
                    .WithStrokeWidth(6)
                    .MoveTo(5, 60)
                    .LineToRelative(215, 0);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/stroking/3"] = _ =>
            {
                var svg = new Svg(300, 80);

                var group = svg
                    .Group()
                    .WithFill("none")
                    .WithStroke("black")
                    .WithStrokeWidth(6);
                group
                    .Path()
                    .WithStrokeLinecap(StrokeLinecap.Butt)
                    .MoveTo(5, 20)
                    .LineToRelative(215, 0);
                group
                    .Path()
                    .WithStrokeLinecap(StrokeLinecap.Round)
                    .MoveTo(5, 40)
                    .LineToRelative(215, 0);
                group
                    .Path()
                    .WithStrokeLinecap(StrokeLinecap.Square)
                    .MoveTo(5, 60)
                    .LineToRelative(215, 0);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/stroking/4"] = _ =>
            {
                var svg = new Svg(300, 80);

                var group = svg
                    .Group()
                    .WithFill("none")
                    .WithStroke("black")
                    .WithStrokeWidth(4);
                group
                    .Path()
                    .WithStrokeDasharray(5, 5)
                    .MoveTo(5, 20)
                    .LineToRelative(215, 0);
                group
                    .Path()
                    .WithStrokeDasharray(10,10)
                    .MoveTo(5, 40)
                    .LineToRelative(215, 0);
                group
                    .Path()
                    .WithStrokeDasharray(20,10,5,5,5,10)
                    .MoveTo(5, 60)
                    .LineToRelative(215, 0);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Пример #49
0
        public DropShadowsModule()
        {
            Get["/examples/w3schools/drop-shadows/1"] = _ =>
            {
                var svg = new Svg(140, 140);

                var f1 = svg.Defs.AddFilter()
                    .WithWidth("200%")
                    .WithHeight("200%");
                f1.Offset(20, 20, FilterInput.SourceGraphic, "offOut");
                f1.Blend("offOut", FilterInput.SourceGraphic, BlendMode.Normal);

                svg
                    .Rectangle(0, 0, 90, 90)
                    .WithStroke("green")
                    .WithStrokeWidth(3)
                    .WithFill("yellow")
                    .WithFilter(f1);

                return Response.AsSvg(svg);
            };

            Get["/examples/w3schools/drop-shadows/2"] = _ =>
            {
                var svg = new Svg(140, 140);

                var f1 = svg.Defs.AddFilter()
                    .WithWidth("200%")
                    .WithHeight("200%");
                f1.Offset(20, 20, FilterInput.SourceGraphic, "offOut");
                f1.GaussianBlur(10, "offOut", "blurOut");
                f1.Blend(FilterInput.SourceGraphic, "blurOut", BlendMode.Normal);

                svg
                    .Rectangle(0, 0, 90, 90)
                    .WithStroke("green")
                    .WithStrokeWidth(3)
                    .WithFill("yellow")
                    .WithFilter(f1);

                return Response.AsSvg(svg);
            };

            Get["/examples/w3schools/drop-shadows/3"] = _ =>
            {
                var svg = new Svg(140, 140);

                var f1 = svg.Defs.AddFilter()
                    .WithWidth("200%")
                    .WithHeight("200%");
                f1.Offset(20, 20, FilterInput.SourceAlpha, "offOut");
                f1.GaussianBlur(10, "offOut", "blurOut");
                f1.Blend(FilterInput.SourceGraphic, "blurOut", BlendMode.Normal);

                svg
                    .Rectangle(0, 0, 90, 90)
                    .WithStroke("green")
                    .WithStrokeWidth(3)
                    .WithFill("yellow")
                    .WithFilter(f1);

                return Response.AsSvg(svg);
            };

            Get["/examples/w3schools/drop-shadows/4"] = _ =>
            {
                var svg = new Svg(140, 140);

                var f1 = svg.Defs.AddFilter()
                    .WithWidth("200%")
                    .WithHeight("200%");
                f1.Offset(20, 20, FilterInput.SourceGraphic, "offOut");
                f1.ColorMatrix(resultName: "matrixOut", filterInput: "offOut", matrix: @"
            0.2,    0,      0,      0,  0,
            0,      0.2,    0,      0,  0,
            0,      0,      0.2,    0,  0,
            0,      0,      0,      1,  0
            ");
                f1.GaussianBlur(resultName: "blurOut", filterInput: "matrixOut", standardDeviation: 10);
                f1.Blend(FilterInput.SourceGraphic, "blurOut", BlendMode.Normal);

                svg
                    .Rectangle(0, 0, 90, 90)
                    .WithStroke("green")
                    .WithStrokeWidth(3)
                    .WithFill("yellow")
                    .WithFilter(f1);

                return Response.AsSvg(svg);
            };
        }
Пример #50
0
        public SimpleChartsModule()
        {
            Get["/examples/charts/vertical-bar-charts/simple-charts/1"] = _ =>
            {
                var svg = new Svg(200, 150);

                var data = new BarChartData(new double[]
                {
                    50, 25, 5
                });
                var chart = svg.VerticalBarChart(data)
                    .WithDataLabelFormat("{0}%")
                    .ShowDataLabelOutsideItem();

                return Response.AsSvg(svg);
            };

            Get["/examples/charts/vertical-bar-charts/simple-charts/2"] = _ =>
            {
                var svg = new Svg();

                var data = new BarChartData(new[]
                {
                    new BarChartGroupData(new[]
                    {
                        new BarChartStackData(new double[] {36, 35, 12}),
                        new BarChartStackData(new double[] {29, 4, 35}),
                        new BarChartStackData(new double[] {19, 11})
                    }),
                    new BarChartGroupData(new[]
                    {
                        new BarChartStackData(new double[] {18}),
                        new BarChartStackData(new double[] {8, 31, 22}),
                        new BarChartStackData(new double[] {2, 4, 28}),
                    }),
                    new BarChartGroupData(new[]
                    {
                        new BarChartStackData(new double[] {21, 13, 36}),
                        new BarChartStackData(new double[] {19, 9}),
                        new BarChartStackData(new double[] {34}),
                    }),
                });
                var chart = svg.VerticalBarChart(data);

                return Response.AsSvg(svg);
            };

            Get["/examples/charts/vertical-bar-charts/simple-charts/3"] = _ =>
            {
                var svg = new Svg();

                var data = new BarChartData(new[]
                {
                    new BarChartGroupData(new[]
                    {
                        new BarChartStackData(new double[] {36, 35, 12}, "Stack 1"),
                        new BarChartStackData(new double[] {29, 4, 35}, "Stack 2"),
                        new BarChartStackData(new double[] {19, 11}, "Stack 3")
                    }, "Group 1"),
                    new BarChartGroupData(new[]
                    {
                        new BarChartStackData(new double[] {18}, "Stack 4"),
                        new BarChartStackData(new double[] {8, 31, 22}, "Stack 5"),
                        new BarChartStackData(new double[] {2, 4, 28}, "Stack 6"),
                    }, "Group 2"),
                    new BarChartGroupData(new[]
                    {
                        new BarChartStackData(new double[] {21, 13, 36}, "Stack 7"),
                        new BarChartStackData(new double[] {19, 9}, "Stack 8"),
                        new BarChartStackData(new double[] {34}, "Stack 9"),
                    }, "Group 3"),
                });
                var chart = svg.VerticalBarChart(data)
                    .WithDataLabelFormat("{0}%");

                return Response.AsSvg(svg);
            };

            Get["/examples/charts/vertical-bar-charts/simple-charts/4"] = _ =>
            {
                var svg = new Svg();

                var data = new BarChartData(new double[]
                {
                    50, 25, 5
                });
                var chart = svg.VerticalBarChart(data)
                    .WithDataLabelFormat("{0}%")
                    .ShowDataLabelOutsideItem()
                    .WithGutter(40)
                    .WithFill("#dddddd")
                    .WithPadding(40)
                    .WithDrawableFill("#cccccc")
                    .WithStroke("black")
                    .WithStrokeWidth(2);

                return Response.AsSvg(svg);
            };

            Get["/examples/charts/vertical-bar-charts/simple-charts/stack-based-color-generator"] = _ =>
            {
                var svg = new Svg(600, 200);

                var chart = svg.VerticalBarChart(DataSources.GetIndustriesData())
                    .WithDataLabelFormat("{0}%")
                    .ShowDataLabelOutsideItem()
                    .WithPointColorGenerator(new StackBasedDataPointColorGenerator(new[]
                    {
                        "#6666ff",
                        "orange"
                    }))
                    .WithStroke("black")
                    .WithStrokeWidth(2)
                    .WithPadding(10);

                return Response.AsSvg(svg);
            };

            Get["/examples/charts/vertical-bar-charts/simple-charts/always-show-labels-above-data-points"] = _ =>
            {
                var svg = new Svg(600, 200);

                var chart = svg.VerticalBarChart(DataSources.GetIndustriesData())
                    .WithDataLabelFormat("{0}%")
                    .AlwaysShowDataLabel()
                    .WithPointColorGenerator(new StackBasedDataPointColorGenerator(new[]
                    {
                        "#6666ff",
                        "orange"
                    }))
                    .WithStroke("black")
                    .WithStrokeWidth(2)
                    .WithPadding(10);

                return Response.AsSvg(svg);
            };

            Get["/examples/charts/vertical-bar-charts/simple-charts/7"] = _ =>
            {
                var svg = new Svg();

                var data = new BarChartData(new[]
                {
                    new BarChartGroupData(new[]
                    {
                        new BarChartStackData(new double[] {36, 35, 12}, "Stack 1"),
                        new BarChartStackData(new double[] {29, 4, 35}, "Stack 2"),
                        new BarChartStackData(new double[] {19, 11}, "Stack 3")
                    }, "Group 1"),
                    new BarChartGroupData(new[]
                    {
                        new BarChartStackData(new double[] {18}, "Stack 4"),
                        new BarChartStackData(new double[] {8, 31, 22}, "Stack 5"),
                        new BarChartStackData(new double[] {2, 4, 28}, "Stack 6"),
                    }, "Group 2"),
                    new BarChartGroupData(new[]
                    {
                        new BarChartStackData(new double[] {21, 13, 36}, "Stack 7"),
                        new BarChartStackData(new double[] {19, 9}, "Stack 8"),
                        new BarChartStackData(new double[] {34}, "Stack 9"),
                    }, "Group 3"),
                });
                var chart = svg.VerticalBarChart(data)
                    .WithDataLabelFormat("{0}%")
                    .WithPointColorGenerator(new PointBasedDataPointColorGenerator(new[]
                    {
                        "#617073",
                        "#7A93AC",
                        "#92BCEA",
                        "#AFB3F7"
                    }));

                return Response.AsSvg(svg);
            };

            Get["/examples/charts/vertical-bar-charts/simple-charts/8"] = _ =>
            {
                var svg = new Svg();

                var data = new BarChartData(new[]
                {
                    new BarChartGroupData(new[]
                    {
                        new BarChartStackData(new double[] {36, 35, 12}, "Stack 1"),
                        new BarChartStackData(new double[] {29, 4, 35}, "Stack 2"),
                        new BarChartStackData(new double[] {19, 11}, "Stack 3")
                    }, "Group 1"),
                    new BarChartGroupData(new[]
                    {
                        new BarChartStackData(new double[] {18}, "Stack 4"),
                        new BarChartStackData(new double[] {8, 31, 22}, "Stack 5"),
                        new BarChartStackData(new double[] {2, 4, 28}, "Stack 6"),
                    }, "Group 2"),
                    new BarChartGroupData(new[]
                    {
                        new BarChartStackData(new double[] {21, 13, 36}, "Stack 7"),
                        new BarChartStackData(new double[] {19, 9}, "Stack 8"),
                        new BarChartStackData(new double[] {34}, "Stack 9"),
                    }, "Group 3"),
                });
                var chart = svg.VerticalBarChart(data)
                    .WithDataLabelFormat("{0}%")
                    .WithPointColorGenerator(new PointBasedDataPointColorGenerator(new[]
                    {
                        "#171A21",
                        "#617073",
                        "#7A93AC",
                        "#92BCEA",
                        "#AFB3F7"
                    }))
                    .WithPointLabelColorGenerator(new PointBasedDataPointColorGenerator(new[]
                    {
                        "#fff",
                        "#fff",
                        "#000",
                        "#000",
                        "#000",
                    }));

                return Response.AsSvg(svg);
            };

            Get["/examples/charts/vertical-bar-charts/simple-charts/labels-on-data-points-auto-split"] = _ =>
            {
                var svg = new Svg(600, 200);

                svg.VerticalBarChart(DataSources.GetRenewableEnergyData())
                    .WithDataPointAutoLineSplit(12)
                    .WithDataLabelFormat("{0:p}")
                    .AlwaysShowDataLabel();

                return Response.AsSvg(svg);
            };

            Get["/examples/charts/vertical-bar-charts/simple-charts/as-inline-svg"] = _ =>
            {
                var svg = new Svg(200, 150);

                var data = new BarChartData(new double[]
                {
                    50, 25, 5
                });
                var chart = svg.VerticalBarChart(data)
                    .WithDataLabelFormat("{0}%")
                    .ShowDataLabelOutsideItem();

                return Response.AsText(svg.ToInlineSvgString());
            };
        }
Пример #51
0
 public static Response AsSvg(this IResponseFormatter formatter, Svg svg)
 {
     return formatter.AsText(svg.ToString(), "image/svg+xml");
 }