Skip to content

Commit bd658c1

Browse files
committed
Merge branch 'expose-trace-modules' of github.com:plotly/plotly.js into expose-trace-modules
2 parents 66caf02 + a00395b commit bd658c1

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ 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/`
111112
- All tasks can be run using [`npm run-script`](https://docs.npmjs.com/cli/run-script)

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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,35 +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

4347
Read the [Getting started page](https://plot.ly/javascript/getting-started/) for more examples.
4448

4549
## Modules
4650

47-
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":
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*:
4852

4953
```javascript
50-
// custom-plotly.js
54+
// in custom-plotly.js
5155
var plotlyCore = require('plotly.js/lib/core');
5256

5357
// Load in the trace types for pie, and choropleth
5458
plotlyCore.register([
55-
require('plotly.js/lib/pie');
59+
require('plotly.js/lib/pie'),
5660
require('plotly.js/lib/choropleth');
5761
]);
5862

5963
module.exports = customPlotly;
6064
```
65+
6166
Then elsewhere in your code:
6267

6368
```javascript
64-
var Plotly = require('./custom-plotly');
69+
var Plotly = require('./path/to/custom-plotly');
6570
```
6671

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+
6779
#### Webpack Usage with Modules
6880

69-
Plotly.js uses a browserify transform (glslify) to transform shaders. To make the trace module system work with Webpack, you will need to install [ify-loader]() and add it to your `webpack.config.json` for your build to correctly bundle and parse `.glsl` files.
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.
7082

7183
## Bugs and feature requests
7284

0 commit comments

Comments
 (0)