npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

d3-server-renderer

v1.1.3

Published

A D3 renderer server that returns the generated svg

Downloads

3

Readme

d3-server-renderer

A d3 server renderer easy to customize, it uses d3.js to render svg charts on the server-side with node.js and to serve it.

Getting started

How to add a new chart type

  • inside the config directory, create a copy of radial-reingold–tilford-tree.js and call it with a significant name, e.g. donut.js
  • in donut.js delete all the code between // EDITING STARTS HERE [...] // EDITING ENDS ERE
  • following the e.g. http://bl.ocks.org/mbostock/3887193
  • edit the donut.js in this way (copy it as is in your IDE):
    var width = 960,
        height = 500,
        radius = Math.min(width, height) / 2;

    var color = d3.scale.ordinal()
        .range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]);

    var arc = d3.svg.arc()
        .outerRadius(radius - 10)
        .innerRadius(radius - 70);

    var pie = d3.layout.pie()
        .sort(null)
        .value(function(d) { return d.population; });
    /*
     * Use the `wrapper` variable instead of `d3.select("body").append("svg")
     * */
    // var svg = d3.select("body").a`ppend("svg")
    var svg = wrapper
        .attr("width", width)
        .attr("height", height)
        .append("g")
        .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");

    /*
     * Remove the csv call and invoke the `type` method on the data array `data = data.map(type)`
     * */
    // d3.csv("data.csv", type, function(error, data) {
    //     if (error) throw error;
        data = data.map(type);

        var g = svg.selectAll(".arc")
            .data(pie(data))
            .enter().append("g")
            .attr("class", "arc");

        g.append("path")
            .attr("d", arc)
            .style("fill", function(d) { return color(d.data.age); });

        g.append("text")
            .attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; })
            .attr("dy", ".35em")
            .text(function(d) { return d.data.age; });
    // });

    function type(d) {
        d.population = +d.population;
        return d;
    }
  • now in the demo-file, make a request to the new chart:
    • set the value of variable chartType to donut: var chartType = 'donut';
    • convert the csv file to a valid json using a service like this
    • set the value of variable chartData with the json value:
    [
        {
            "age": "<5",
            "population": 2704659
        },
        {
            "age": "5-13",
            "population": 4499890
        },
        {
            "age": "14-17",
            "population": 2159981
        },
        {
            "age": "18-24",
            "population": 3853788
        },
        {
            "age": "25-44",
            "population": 14106543
        },
        {
            "age": "45-64",
            "population": 8819342
        },
        {
            "age": "≥65",
            "population": 612463
        }
    ]
    • add the css style:
        .arc text {
            font: 10px sans-serif;
            text-anchor: middle;
        }
    
        .arc path {
            stroke: #fff;
        }