Skip to content

Commit 313fd91

Browse files
committed
Merge pull request #202 from plotly/expose-trace-modules
Expose trace modules
2 parents 96ab8c0 + bd658c1 commit 313fd91

35 files changed

+252
-39
lines changed

.npmignore

+9
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ test
99
dist/extras/mathjax
1010

1111
circle.yml
12+
docker-compose.yml
13+
bower.json
14+
15+
.ackrc
16+
.agignore
17+
.eslintignore
18+
.eslintrc
19+
20+
npm-debug.log

CONTRIBUTING.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ To view the results of a run on CircleCI, download the `build/test_images/` and
106106
### Repo organization
107107

108108
- Distributed files are in `dist/`
109+
- CommonJS require-able modules are in `lib/`
109110
- Sources files are in `src/`, including the index
110111
- Build and repo management scripts are in `tasks/`
111-
- All tasks can be run using [`npm run-srcript`](https://docs.npmjs.com/cli/run-script)
112+
- All tasks can be run using [`npm run-script`](https://docs.npmjs.com/cli/run-script)
112113
- Tests are `test/`, they are partitioned into `image` and `jasmine` tests
113114
- Test dashboard and image viewer code is in `devtools/`
114115
- Non-distributed, built files are in `build/` (most files in here are git-ignored, the css and font built files are exceptions)

README.md

+40-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<a href="https://plot.ly/javascript/"><img src="http://images.plot.ly/logo/plotlyjs-logo@2x.png" height="70"></a>
22

3-
[![npm version](https://badge.fury.io/js/plotly.js.svg)](https://badge.fury.io/js/plotly.js)
3+
[![npm version](https://badge.fury.io/js/plotly.js.svg)](https://badge.fury.io/js/plotly.js)
44
[![circle ci](https://circleci.com/gh/plotly/plotly.js.png?&style=shield&circle-token=1f42a03b242bd969756fc3e53ede204af9b507c0)](https://circleci.com/gh/plotly/plotly.js)
55

66
Built on top of [d3.js](http://d3js.org/) and [stack.gl](http://stack.gl/),
@@ -10,6 +10,7 @@ chart types, including 3D charts, statistical graphs, and SVG maps.
1010
## Table of contents
1111

1212
* [Quick start options](#quick-start-options)
13+
* [Modules](#modules)
1314
* [Bugs and feature requests](#bugs-and-feature-requests)
1415
* [Documentation](#documentation)
1516
* [Contributing](#contributing)
@@ -38,9 +39,46 @@ npm install plotly.js
3839
```html
3940
<!-- Latest compiled and minified plotly.js JavaScript -->
4041
<script type="text/javascript" src="https://cdn.plot.ly/plotly-latest.min.js"></script>
42+
43+
<!-- OR use a specific plotly.js release (e.g. version 1.5.0)-->
44+
<script type="text/javascript" src="https://cdn.plot.ly/plotly-1.5.0.min.js"></script>
4145
```
4246

43-
Read the [Getting started page](https://plot.ly/javascript/getting-started/) for examples.
47+
Read the [Getting started page](https://plot.ly/javascript/getting-started/) for more examples.
48+
49+
## Modules
50+
51+
If you would like to reduce the bundle size of plotly.js, you can create a *custom* bundle by using `plotly.js/lib/core`, and loading only the trace types that you need (e.g. `pie` or `choropleth`). The recommended way to do this is by creating a *bundling file*:
52+
53+
```javascript
54+
// in custom-plotly.js
55+
var plotlyCore = require('plotly.js/lib/core');
56+
57+
// Load in the trace types for pie, and choropleth
58+
plotlyCore.register([
59+
require('plotly.js/lib/pie'),
60+
require('plotly.js/lib/choropleth');
61+
]);
62+
63+
module.exports = customPlotly;
64+
```
65+
66+
Then elsewhere in your code:
67+
68+
```javascript
69+
var Plotly = require('./path/to/custom-plotly');
70+
```
71+
72+
**IMPORTANT**: the plotly.js code base contains some non-ascii characters. Therefore, please make sure to set the `chartset` attribute to `"utf-8"` in the script tag that imports your plotly.js bundle. For example:
73+
74+
```html
75+
<script type="text/javascript" src="my-plotly-bundle.js" charset="utf-8"></script>
76+
```
77+
78+
79+
#### Webpack Usage with Modules
80+
81+
Browserify [transforms](https://github.com/substack/browserify-handbook#transforms) are required to build plotly.js, namely, [glslify](https://github.com/stackgl/glslify) to transform WebGL shaders and [cwise](https://github.com/scijs/cwise) to compile component-wise array operations. To make the trace module system work with Webpack, you will need to install [ify-loader](https://github.com/hughsk/ify-loader) and add it to your `webpack.config.json` for your build to correctly bundle plotly.js files.
4482

4583
## Bugs and feature requests
4684

lib/bar.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
module.exports = require('../src/traces/bar');

lib/box.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
module.exports = require('../src/traces/box');

lib/choropleth.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
module.exports = require('../src/traces/choropleth');

lib/contour.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
module.exports = require('../src/traces/contour');

lib/core.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
module.exports = require('../src/core');

lib/heatmap.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
module.exports = require('../src/traces/heatmap');

lib/histogram.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
module.exports = require('../src/traces/histogram');

lib/histogram2d.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
module.exports = require('../src/traces/histogram2d');

lib/histogram2dcontour.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
module.exports = require('../src/traces/histogram2dcontour');

lib/index.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
/*
12+
* This file is browserify'ed into a standalone 'Plotly' object.
13+
*/
14+
15+
var Core = require('./core');
16+
17+
// Load all trace modules
18+
Core.register([
19+
require('./bar'),
20+
require('./box'),
21+
require('./heatmap'),
22+
require('./histogram'),
23+
require('./histogram2d'),
24+
require('./histogram2dcontour'),
25+
require('./pie'),
26+
require('./contour'),
27+
require('./scatter3d'),
28+
require('./surface'),
29+
require('./mesh3d'),
30+
require('./scattergeo'),
31+
require('./choropleth'),
32+
require('./scattergl')
33+
]);
34+
35+
module.exports = Core;

lib/mesh3d.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
module.exports = require('../src/traces/mesh3d');

lib/pie.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
module.exports = require('../src/traces/pie');

lib/scatter.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
module.exports = require('../src/traces/scatter');

lib/scatter3d.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
module.exports = require('../src/traces/scatter3d');

lib/scattergeo.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
module.exports = require('../src/traces/scattergeo');

lib/scattergl.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
module.exports = require('../src/traces/scattergl');

lib/surface.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
module.exports = require('../src/traces/surface');

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "1.4.1",
44
"description": "The open source javascript graphing library that powers plotly",
55
"license": "MIT",
6-
"main": "./src/index.js",
7-
"webpack": "./dist/plotly.min.js",
6+
"main": "./lib/index.js",
7+
"webpack": "./dist/plotly.js",
88
"repository": {
99
"type": "git",
1010
"url": "https://github.com/plotly/plotly.js.git"

src/index.js renamed to src/core.js

+1-20
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
/*
1212
* Export the plotly.js API methods.
13-
*
14-
* This file is browserify'ed into a standalone 'Plotly' object.
15-
*
1613
*/
1714

1815
var Plotly = require('./plotly');
@@ -32,6 +29,7 @@ exports.addTraces = Plotly.addTraces;
3229
exports.deleteTraces = Plotly.deleteTraces;
3330
exports.moveTraces = Plotly.moveTraces;
3431
exports.setPlotConfig = require('./plot_api/set_plot_config');
32+
exports.register = Plotly.register;
3533

3634
// plot icons
3735
exports.Icons = require('../build/ploticon');
@@ -45,20 +43,3 @@ exports.Queue = Plotly.Queue;
4543

4644
// export d3 used in the bundle
4745
exports.d3 = require('d3');
48-
49-
Plotly.register([
50-
require('./traces/bar'),
51-
require('./traces/box'),
52-
require('./traces/heatmap'),
53-
require('./traces/histogram'),
54-
require('./traces/histogram2d'),
55-
require('./traces/histogram2dcontour'),
56-
require('./traces/pie'),
57-
require('./traces/contour'),
58-
require('./traces/scatter3d'),
59-
require('./traces/surface'),
60-
require('./traces/mesh3d'),
61-
require('./traces/scattergeo'),
62-
require('./traces/choropleth'),
63-
require('./traces/scattergl')
64-
]);

tasks/bundle.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ catch(e) {
3535

3636

3737
// Browserify plotly.js
38-
browserify(constants.pathToPlotlySrc, {
38+
browserify(constants.pathToPlotlyIndex, {
3939
debug: DEV,
4040
standalone: 'Plotly',
4141
transform: [compressAttributes]
@@ -65,7 +65,7 @@ browserify(constants.pathToPlotlyGeoAssetsSrc, {
6565

6666

6767
// Browserify the plotly.js with meta
68-
browserify(constants.pathToPlotlySrc, {
68+
browserify(constants.pathToPlotlyIndex, {
6969
debug: DEV,
7070
standalone: 'Plotly'
7171
})

tasks/cibundle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var constants = require('./util/constants');
1616

1717

1818
// Browserify plotly.js
19-
browserify(constants.pathToPlotlySrc, {
19+
browserify(constants.pathToPlotlyIndex, {
2020
standalone: 'Plotly',
2121
transform: [compressAttributes]
2222
})

tasks/header.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ pathsDist.forEach(headerLicense);
3232
var licenseSrc = constants.licenseSrc;
3333
var licenseStr = licenseSrc.substring(2, licenseSrc.length - 2);
3434

35-
36-
glob(path.join(constants.pathToSrc, '**/*.js'), function(err, files) {
35+
var srcGlob = path.join(constants.pathToSrc, '**/*.js');
36+
var libGlob = path.join(constants.pathToLib, '**/*.js');
37+
glob('{' + srcGlob + ',' + libGlob + '}', function(err, files){
3738
files.forEach(function(file) {
3839
fs.readFile(file, 'utf-8', function(err, code) {
3940

tasks/preprocess.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ fs.copy(constants.pathToTopojsonSrc, constants.pathToTopojsonDist,
3131
);
3232

3333
// inject package version into source index files
34-
updateVersion(constants.pathToPlotlySrc);
34+
updateVersion(constants.pathToPlotlyCore);
3535
updateVersion(constants.pathToPlotlyGeoAssetsSrc);

0 commit comments

Comments
 (0)