Giter Club home page Giter Club logo

middleman-static-d3's Introduction

middleman-static-d3

A middleman template that allows the creation of self-contained static d3 visualization. No web server required!

I was looking for an easy way to use D3.js to produce static self-contained HTML files. Ordinarily, d3.js has several dependencies that prevent it from running off the filesystem -- you usually need a webserver.

However, there are times when you want to compile a D3.js visualization without requiring a webserver.

#How it works

This template provides some helpers that basically take your middleman file dependencies and render them as data-uris, in-page. This means you can use js, css, json files without having to worry about deploying your d3 vis.

The end result of a build is a completely portable static html file (no extra css, js, or other data files).

Try it!

You should have the following prerequisites:

  • ruby 2.1.2
  • git
  • modern brower that supports d3.js
  • (optional) rvm

Quickstart with the sample viz included in the template:

$ git clone https://github.com/coldnebo/middleman-static-d3.git my_d3_vis
$ cd my_d3_vis
$ bundle install
$ middleman build
      create  build/index.html
$ google-chrome build/index.html

Template details

Let's take a look at the template in more detail:

.
├── config.rb
├── Gemfile
├── Gemfile.lock
├── lib
│   └── static_d3_helpers.rb
├── README.md
└── source
    ├── data                 # d3 data folder (not to be confused with middleman ./data!)
    │   └── data.tsv         # example TSV data file
    ├── images
    │   └── middleman.png
    ├── index.html.erb       # example d3.js viz
    ├── javascripts
    │   ├── d3.js
    │   ├── d3.min.js        # included d3.js version
    │   └── LICENSE
    ├── layouts
    │   └── layout.erb
    └── stylesheets
        └── normalize.css

Next, it's time to make your own.

  • take a look at source/index.html.erb to see how the file format works.

Normalize.css and d3.js are automatically included for you (see source/layouts/layout.erb for how). You can embed your own js and css files with the embedding helpers below.

#Helpers

Adds the following helpers:

  • javascript_embed(js_path)
  • stylesheet_embed(css_path)
  • data_embed(data_path, var_name) - used to embed files under data
  • data_uri(source_path, mime_type) - used to create a data_uri for image tags, etc.
  • inline(data) - used to fit data on a single line for embedding into js.

middleman-static-d3's People

Contributors

coldnebo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.