d3.compose

使用 d3 从可重复使用的图表和组件中组成复杂的、数据驱动的可视化。「Compose complex, data-driven visualizations from reusable charts and components with d3」

  • 所有者: CSNW/d3.compose
  • 平台: Web browsers
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

d3.compose

使用 d3 和 d3.chart 从图表(如线条和条形图)和组件(如坐标轴、标题和图例)组成丰富的、数据绑定的图表。

  • 先进的布局引擎可以自动定位和调整图表和组件的大小,按 z-index 分层,并且默认为自动缩放的响应式布局。
  • 用于快速创建漂亮图表的标准图表和组件库。
  • 用于创建可组合和可重用的图表和组件的图表和组件基础。
  • 包括涵盖一系列标准功能的辅助程序和混搭程序。
  • 基于 CSS 类的样式是可扩展的,并且易于定制,以匹配您的网站。

入门

  1. 下载 最新版本
  2. 下载依赖:
  3. 将 d3.compose 和依赖加入到你的 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}]);
        

例子和文档

参见 http://CSNW.github.io/d3.compose/,获取现场示例和文档。

开发

  1. 安装模块 npm install
  2. 使用 npm test 或 npm run test:watch 进行测试。
  3. 用 npm run build 构建

测试说明。需要 Node 4+(适用于最新的 jsdom),而且 d3.chart 目前不支持从 node 内运行,需要在 node_modules/d3.chart.js 中的 IIFE 内添加以下一行:window = this; (在 use strict 之前)。这个问题将通过一个 pending PR 来解决,以解决d3.chart的这个问题(另外,对 d3.chart 的依赖可能会在以后的 d3.compose 版本中被移除)。

发布

(所有的变化都合并到主分支上)

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

文档

  1. 在主站,运行 npm run docs
  2. 切换到 gh-pages 分支
  3. 导航到 _tasks 目录 (cd _tasks)
  4. (npm install _tasks, if necessary)
  5. 运行 docs 任务 npm run docs
  6. 导航回到根部
  7. 查看网站用 bundle exec jekyll serve

注意:为了加快迭代速度,单独创建一个克隆,切换到 gh-pages 分支,将 docs_path 环境变量设置为原始克隆(如 Windows:SET docs_path=C:\...\d3.compose_\docs\),然后运行步骤 3-6。


主要指标

概览
名称与所有者CSNW/d3.compose
主编程语言JavaScript
编程语言JavaScript (语言数: 3)
平台Web browsers
许可证MIT License
所有者活动
创建于2014-03-07 14:59:21
推送于2022-12-10 17:12:27
最后一次提交2020-03-31 16:38:37
发布数76
最新版本名称v0.15.21 (发布于 2020-03-31 16:38:37)
第一版名称v0.5.0 (发布于 )
用户参与
星数697
关注者数22
派生数24
提交数674
已启用问题?
问题数8
打开的问题数4
拉请求数45
打开的拉请求数14
关闭的拉请求数9
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?

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.