Giter Site home page Giter Site logo

csnw / d3.compose Goto Github PK

View Code? Open in Web Editor NEW
697.0 24.0 24.0 5.99 MB

Compose complex, data-driven visualizations from reusable charts and components with d3

Home Page: http://CSNW.github.io/d3.compose/

License: MIT License

JavaScript 73.77% CSS 2.29% HTML 23.94%

d3.compose's Introduction

d3.compose

Compose rich, data-bound charts from charts (like Lines and Bars) and components (like Axis, Title, and Legend) with d3 and d3.chart.

  • Advanced layout engine automatically positions and sizes charts and components, layers by z-index, and is responsive by default with automatic scaling
  • Standard library of charts and components for quickly creating beautiful charts
  • Chart and Component bases for creating composable and reusable charts and components
  • Includes helpers and mixins that cover a range of standard functionality
  • CSS class-based styling is extensible and easy to customize to match your site

npm version

Getting Started

  1. Download the latest release

  2. Download the dependencies:

  3. Add d3.compose and dependencies to your html:

    <!doctype html>
    <html>
      <head>
        <!-- ... -->
    
        <link rel="stylesheet" type="text/css" href="d3.compose.css">
      </head>
      <body>
        <!-- ... -->
    
        <script src="d3.js"></script>
        <script src="d3.chart.js"></script>
    
        <script src="d3.compose.js"></script>
    
        <!-- Your code -->
      </body>
    </html>
  4. Create your first chart

    var chart = d3.select('#chart')
      .chart('Compose', function(data) {
        var scales = {
          x: {type: 'ordinal', data: data, key: 'x'},
          y: {data: data, key: 'y'}
        };
    
        var charts = [
          d3c.lines({
            data: data,
            xScale: scales.x,
            yScale: scales.y
          })
        ];
    
        var yAxis = d3c.axis({scale: scales.y});
    
        return [
          [yAxis, d3c.layered(charts)]
        ];
      })
      .width(600)
      .height(400);
    
    chart.draw([{x: 0, y: 10}, {x: 10, y: 50}, {x: 20, y: 30}]);

Examples and Docs

See http://CSNW.github.io/d3.compose/ for live examples and docs.

Development

  1. Install modules npm install
  2. Test with npm test or npm run test:watch
  3. Build with npm run build

Note on testing: Requires Node 4+ (for latest jsdom) and d3.chart doesn't currently support running from within node and requires the following line be added inside the IIFE in node_modules/d3.chart.js: window = this; (before use strict). This will be resolved by a pending PR to fix this issue with d3.chart (also, the dependency on d3.chart is likely to be removed in a later version of d3.compose).

Release

(With all changes merged to master and on master branch)

  1. npm version {patch|minor|major|version}
  2. npm publish

Docs

  1. On master, run npm run docs
  2. Switch to gh-pages branch
  3. Navigate to _tasks directory (cd _tasks)
  4. (npm install _tasks, if necessary)
  5. Run docs task npm run docs
  6. Navigate back to root
  7. View site with bundle exec jekyll serve

Note: For faster iteration, create a separate clone, switch to gh-pages branch, set docs_path environment variable to original clone (e.g. Windows: SET docs_path=C:\...\d3.compose\_docs\), and then run steps 3-6.

d3.compose's People

Contributors

john-clarke avatar timhall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

d3.compose's Issues

Example causes typeError

Probably missing something simple but.

test.html

    <html>
      <head>
        <script type="text/javascript"
                src="/vast/libs/d3.js"></script>
        <script type="text/javascript"
                src="/vast/libs/d3.chart.js"></script>
        <script type="text/javascript"
                src="/vast/libs/d3.compose-all.js"></script>
        <link   type="text/css"
               href="/vast/css/d3.compose.css"
                rel="stylesheet"
               >
       <script>
        var data = [
            {x: 1, y: 100,},
            {x: 2, y: 200,},
            {x: 3, y: 150,}
        ];

        var chart = d3.select('#chart').chart('Compose', function(data){
            var charts = [
                d3c.lines('results', {data: data})
            ];
            return [
                d3c.layered(charts)
            ];
        });
        chart.draw(data);
    </script>
  </head>
  <body>
    <h1>Competed Count</h1>
    <div id="chart"></div>
  </body>
</html>

Generates the following Error:
Uncaught TypeError: Cannot read property 'tagName' of nullBase.extend.initialize @ d3.compose-all.js:2106Base @ d3.compose-all.js:1151Child @ d3.compose-all.js:1303d3.selection.chart @ d3.chart.js:721(anonymous function) @ vizstats.html:20

d3.js 3.5.5
d3.chart 0.2.1
everything else pulled from links on your website.

Thanks.

Time scales do not have width or rangeBand

The itemWidth function returns either a scale's width or uses the rangeBand to calculate one. It appears that d3.scale.time has neither function.

I've not come up with a workaround for this, as most suggestions are to simply calculate width/data.length which seems unlikely to be what's intended.

Open to suggestions!

Transition to better layout/options

Currently, layout of components/charts depends on the order they were added to the charts or components object, but this is unreliable and the order of object keys cannot be guaranteed. A new ordering system based on arrays will make component and chart ordering explicit and consistent. Additionally, the type: '...' approach can be verbose and relies on d3.chart's global chart registration (a dependency that may not be required in the future). A new approach of using helpers functions is proposed for phase 2.

Phase 1:

// Before
d3.select('#chart').chart('Compose', function(data) {
  return {
    charts: {
      results: {type: 'Lines', data: data.results, ...},
      control: {type: 'Bars', data: data.control, ...}
    },
    components: {
      title: {type: 'Title', text: 'Chart Title'},
      yAxis: {type: 'Axis', position: 'left', ...},
      xAxis: {type: 'Axis', position: 'bottom', ...},
      xAxisTitle: {type: 'Title', position: 'bottom', text: 'x-axis'}
    }
  };
});

// After
let { layered } = d3.compose;

d3.select('#chart').chart('Compose', function(data) {
  return [// rows: top-to-bottom
    {type: 'Title', text: 'Chart Title'}, // full-width column
    [// columns: left-to-right
      {type: 'Axis', ...},
      layered(
        {type: 'Lines', data: data.results, ...},
        {type: 'Bars', data: data.control, ...}
      )
    ],
    {type: 'Axis', ...},
    {type: 'Title', text: 'x-axis'}
  ];
});

The keys for identifying charts/components (e.g. results, control) are estimated based on layout position and type and can be set explicitly with key: '...' if necessary (e.g. component is moving)

Phase 2:

let {
  layered,
  title,
  axis,
  lines,
  bars
} = d3.compose;

d3.select('#chart').chart('Compose', function(data) {
  return [
    title('Chart Title'),
    [
      axis({...}),
      layered(
        lines({data: data.results, ...}),
        bars({data: data.control, ...})
      )
    ],
    axis({...}),
    title('x-axis')
  ];
});

The helper functions would simply return a formatted standard object, but could be expanded later. (e.g. axis({...}) returns {type: 'Axis', ...})

  • Phase 1 (Switch to arrays)
  • Phase 2 (Add helper functions)

Add a flamegraph

For many types of visualization, especially related to performance monitoring, a heatmap is one of the best visualizations. Consider adding this to d3.compose

Investigate non-ordinal issues for Bars

Currently, mixins.XYValues (which Bars extends), looks for width to be set on scale (from helpers.createScale) or rangeBand (from ordinal scale). If a linear scale is used with Bars the width will be 0. Need to investigate how this is resolved in other bar chart examples and any potential fixes.

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.