Skip to content

Commit

Permalink
Merge pull request #8 from ivanvanderbyl/master
Browse files Browse the repository at this point in the history
Added support for loading D3 v4
  • Loading branch information
ivanvanderbyl authored Oct 16, 2016
2 parents 5f98feb + 8de22ef commit 5e79fab
Show file tree
Hide file tree
Showing 38 changed files with 716 additions and 192 deletions.
17 changes: 17 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 6,
sourceType: 'module'
},
extends: [
'eslint:recommended',
'plugin:ember-suave/recommended'
],
env: {
'node': true
},
rules: {
'no-var':'off'
}
};
3 changes: 3 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
preset: "airbnb"
}
32 changes: 0 additions & 32 deletions .jshintrc

This file was deleted.

14 changes: 8 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
language: node_js
node_js:
- "0.12"
- "4"

sudo: false

Expand All @@ -22,14 +22,16 @@ matrix:
- env: EMBER_TRY_SCENARIO=ember-canary

before_install:
- export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH
- "npm config set spin false"
- "npm install -g npm@^2"
- if [[ `npm -v` != 3* ]]; then npm i -g npm@3; fi
- npm config set spin false
- npm install -g bower
- npm install phantomjs-prebuilt

install:
- npm install -g bower
- npm install
- bower install

script:
- ember try $EMBER_TRY_SCENARIO test
# Usually, it's ok to finish the test scenario without reverting
# to the addon's original dependency state, skipping "cleanup".
- ember try $EMBER_TRY_SCENARIO test --skip-cleanup
3 changes: 3 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Estelle DeBlois
Ivan Vanderbyl
Mike North
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015
Copyright (c) 2016

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
70 changes: 63 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,73 @@
# ember-d3
# ember-d3 [![Build Status](https://travis-ci.org/brzpegasus/ember-d3.svg?branch=master)](https://travis-ci.org/brzpegasus/ember-d3) [![Ember Observer Score](https://emberobserver.com/badges/ember-d3.svg)](https://emberobserver.com/addons/ember-d3) [![npm version](https://badge.fury.io/js/ember-d3.svg)](https://badge.fury.io/js/ember-d3) [![Dependency Status](https://david-dm.org/brzpegasus/ember-d3.svg)](https://david-dm.org/brzpegasus/ember-d3) [![devDependency Status](https://david-dm.org/brzpegasus/ember-d3/dev-status.svg)](https://david-dm.org/brzpegasus/ember-d3.svg#info=devDependencies)

An [Ember CLI](http://www.ember-cli.com/) addon that installs [d3](http://d3js.org/) in your Ember app and provides an ES2015 module shim for it.
Ember shim for loading `[email protected]`. To install:

## Usage
```
ember install ember-d3
```

D3 modules are loaded from NPM as ES2015 modules. It includes `d3-shape` and all version 4 modules in D3 `4.x`.

**If you're looking for the `ember-d3` for `[email protected]`, see the `v3` branch.**

## Advanced Installation

Install the addon:
If you need a specified d3 version, add this to your project:

```
ember install ember-d3
npm install --save-dev [email protected]
```

## Example usage:

```js
import { line } from 'd3-shape';
import { scaleOrdinal } from 'd3-scale';
import { extent } from 'd3-array';
```

Use it!
## Specifying the `d3` version

This addon is simply a loader for the `d3` NPM package. If you would like to
specify a specific version on the d3 v4.x track, you can do so by installing that
version directly in your project, and this addon will load that version.

## Svelte Builds

In case you do not want to include *all* of d3's dependencies, you may whitelist the packages
that you want to include in your project's `config/environment.js` file.

For example, if you only wanted to use `d3-scale`, you would do:

```js
import d3 from 'd3';
// config/environment.js
module.exports = function() {
return {
'ember-d3': {
only: ['d3-scale']
}
};
};
```

Or if you want to exclude a package:

```js
// config/environment.js
module.exports = function() {
return {
'ember-d3': {
except: ['d3-scale']
}
};
};
```

**Note**: Even though you only add `d3-scale`, it has a few transitive d3 dependencies.
These are added to your project automatically.

## Running Tests

* `npm test` (Runs `ember try:testall` to test your addon against multiple Ember versions)
* `ember test`
* `ember test --server`
Empty file removed app/.gitkeep
Empty file.
6 changes: 0 additions & 6 deletions blueprints/.jshintrc

This file was deleted.

13 changes: 0 additions & 13 deletions blueprints/ember-d3/index.js

This file was deleted.

11 changes: 2 additions & 9 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
{
"name": "ember-d3",
"dependencies": {
"ember": "~2.5.0",
"ember-cli-shims": "0.1.1",
"ember-cli-test-loader": "0.2.2",
"ember-qunit-notifications": "0.1.0",
"d3": "~3.5.6"
},
"resolutions": {
"qunit-notifications": "~0.1.0",
"ember": "~2.5.0"
"ember": "~2.6.0",
"ember-cli-shims": "0.1.1"
}
}
13 changes: 0 additions & 13 deletions client/ember-d3/ember-d3-shim.js

This file was deleted.

2 changes: 1 addition & 1 deletion config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*jshint node:true*/
/* jshint node:true*/
module.exports = {
scenarios: [
{
Expand Down
2 changes: 1 addition & 1 deletion config/environment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*jshint node:true*/
/* jshint node:true*/
'use strict';

module.exports = function(/* environment, appConfig */) {
Expand Down
1 change: 0 additions & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*jshint node:true*/
/* global require, module */
var EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

Expand Down
117 changes: 100 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,113 @@
/* jshint node: true */
'use strict';

/* eslint "no-var":off, "ember-suave/prefer-destructuring":off */
var Funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
var path = require('path');
var rename = require('broccoli-stew').rename;
var AMDDefineFilter = require('./lib/amd-define-filter');
var d3DepsForPackage = require('./lib/d3-deps-for-package');
// var pathToD3Source = require('./lib/path-to-d3-module-src');
var inclusionFilter = require('./lib/inclusion-filter');
var exclusionFilter = require('./lib/exclusion-filter');

module.exports = {
isDevelopingAddon() {
return false;
},

name: 'ember-d3',

included: function(app) {
this._super.included(app);
if (process.env.EMBER_CLI_FASTBOOT !== 'true') {
/**
* Array of d3 packages to load
*
* @private
* @type {Array<String>}
*/
d3Modules: [],

/**
* `import()` taken from ember-cli 2.7
* @private
*/
import(asset, options) {
var app = this.app;
while (app.app) {
app = app.app;
}

app.import(asset, options);
},

included(app) {
this._super.included && this._super.included.apply(this, arguments);
this.app = app;

/*
Find all dependencies of `d3`
*/
var config = app.project.config(app.env) || {};
var addonConfig = config[this.name] || {};
this.d3Modules = this.getD3Modules(addonConfig);

// Fix for loading it in addons/engines
if (typeof app.import !== 'function' && app.app) {
app = app.app;
/*
This essentially means we'll skip importing this package twice, if it's
a dependency of another package.
*/
if (!this.import) {
if (this.isDevelopingAddon()) {
this.ui.writeWarnLine('[ember-d3] skipping included hook for', this.name);
}

app.import(app.bowerDirectory + '/d3/d3.js');
app.import('vendor/ember-d3/ember-d3-shim.js', {
exports: {
d3: ['default']
}
});
return;
}

/*
Actually import the vendor tree packages to our app.
*/
var _this = this;
this.d3Modules.forEach(function(pkg) {
_this.import(path.join('vendor', pkg.name, `${pkg.name }.js`));
});
},

getD3Modules(config) {
var allModules = this._getAllD3Modules();
var onlyModules = config.only || [];
var exceptModules = config.except || [];

return allModules
.filter(inclusionFilter(onlyModules))
.filter(exclusionFilter(exceptModules));
},

_getAllD3Modules() {
console.log(this.dependencies(null, false));
return d3DepsForPackage('d3', this.parent.nodeModulesPath, this.ui);
},

treeForVendor: function() {
return path.join(__dirname, 'client');
treeForVendor(tree) {
var trees = [];

if (tree) {
trees.push(tree);
}

this.d3Modules.forEach(function(pkg) {
if (!(pkg && pkg.path)) {
return;
}

var tree = new Funnel(pkg.path, {
include: [pkg.buildPath],
destDir: `/${ pkg.name}`,
annotation: `Funnel: D3 Source [${ pkg.name }]`
});

var srcTree = new AMDDefineFilter(tree, pkg.name);
trees.push(rename(srcTree, function() {
return `/${ pkg.name }/${ pkg.name }.js`;
}));
});

return mergeTrees(trees);
}
};
18 changes: 18 additions & 0 deletions lib/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 5,
sourceType: 'module'
},
extends: [
'eslint:recommended',
'plugin:ember-suave/recommended'
],
env: {
'browser': false,
'node': true
},
rules: {
"no-var": "off"
}
};
Loading

0 comments on commit 5e79fab

Please sign in to comment.