-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from ivanvanderbyl/master
Added support for loading D3 v4
- Loading branch information
Showing
38 changed files
with
716 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
preset: "airbnb" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Estelle DeBlois | ||
Ivan Vanderbyl | ||
Mike North |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/*jshint node:true*/ | ||
/* jshint node:true*/ | ||
module.exports = { | ||
scenarios: [ | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
}; |
Oops, something went wrong.