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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 40 additions & 2 deletions
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/[email protected]" 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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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');

0 commit comments

Comments
 (0)