Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single Path Fills and Strokes #2

Open
emeeks opened this issue Aug 8, 2015 · 1 comment
Open

Single Path Fills and Strokes #2

emeeks opened this issue Aug 8, 2015 · 1 comment

Comments

@emeeks
Copy link

emeeks commented Aug 8, 2015

It would be nice to have an option to have all the drawing instructions in a single svg:path element rather than multiple path elements in each g. The latter produces an enormous number of dom elements and the former should have better performance, especially for animating things.

@emeeks
Copy link
Author

emeeks commented Aug 8, 2015

So I tested this out with something like the following:

    sketchy.circleStroke = function(opts){
        var merged_opts = extend(defaults, opts);

        var svg =  merged_opts.svg.append("g").attr('transform', function() { return "translate("+merged_opts.x+" "+merged_opts.y+") "+circleTransform(1,1, 0,360); });

        var drawCode = "";

        for(var i = 0; i<merged_opts.count; i++){
                drawCode += " " + circlePath(merged_opts.r, merged_opts.sketch/-50/(i+1),merged_opts.sketch/10/(i+1), 200,240, 0,merged_opts.sketch/5/(i+1));
        }

        svg.append('path')
            .attr('d', drawCode);

        return svg;
    };

And it seems like the multiple path elements, even up to 5000, can be transitioned around the screen pretty smoothly. But other animation is slower. Here's both methods animated using the (dasharray line drawing)[http://bl.ocks.org/mbostock/5649592].

Multiple path elements

Multiple path elements

Single path elements

Single path elements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant