Skip to content

Expose trace modules #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jan 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ test
dist/extras/mathjax

circle.yml
docker-compose.yml
bower.json

.ackrc
.agignore
.eslintignore
.eslintrc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍻


npm-debug.log
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ To view the results of a run on CircleCI, download the `build/test_images/` and
### Repo organization

- Distributed files are in `dist/`
- CommonJS require-able modules are in `lib/`
- Sources files are in `src/`, including the index
- Build and repo management scripts are in `tasks/`
- All tasks can be run using [`npm run-srcript`](https://docs.npmjs.com/cli/run-script)
- All tasks can be run using [`npm run-script`](https://docs.npmjs.com/cli/run-script)
- Tests are `test/`, they are partitioned into `image` and `jasmine` tests
- Test dashboard and image viewer code is in `devtools/`
- Non-distributed, built files are in `build/` (most files in here are git-ignored, the css and font built files are exceptions)
Expand Down
42 changes: 40 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<a href="https://plot.ly/javascript/"><img src="http://images.plot.ly/logo/[email protected]" height="70"></a>

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

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

* [Quick start options](#quick-start-options)
* [Modules](#modules)
* [Bugs and feature requests](#bugs-and-feature-requests)
* [Documentation](#documentation)
* [Contributing](#contributing)
Expand Down Expand Up @@ -38,9 +39,46 @@ npm install plotly.js
```html
<!-- Latest compiled and minified plotly.js JavaScript -->
<script type="text/javascript" src="https://cdn.plot.ly/plotly-latest.min.js"></script>

<!-- OR use a specific plotly.js release (e.g. version 1.5.0)-->
<script type="text/javascript" src="https://cdn.plot.ly/plotly-1.5.0.min.js"></script>
```

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put the Webpack Usage section below the Modules sections because a simple require('plotly.js') with webpack will grab the dist/ version so no need to worry about ify-loader in the simple case.


## Modules

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*:

```javascript
// in custom-plotly.js
var plotlyCore = require('plotly.js/lib/core');

// Load in the trace types for pie, and choropleth
plotlyCore.register([
require('plotly.js/lib/pie'),
require('plotly.js/lib/choropleth');
]);

module.exports = customPlotly;
```

Then elsewhere in your code:

```javascript
var Plotly = require('./path/to/custom-plotly');
```

**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:

```html
<script type="text/javascript" src="my-plotly-bundle.js" charset="utf-8"></script>
```


#### Webpack Usage with Modules

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.

## Bugs and feature requests

Expand Down
9 changes: 9 additions & 0 deletions lib/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = require('../src/traces/bar');
9 changes: 9 additions & 0 deletions lib/box.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = require('../src/traces/box');
9 changes: 9 additions & 0 deletions lib/choropleth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = require('../src/traces/choropleth');
9 changes: 9 additions & 0 deletions lib/contour.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = require('../src/traces/contour');
9 changes: 9 additions & 0 deletions lib/core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = require('../src/core');
9 changes: 9 additions & 0 deletions lib/heatmap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = require('../src/traces/heatmap');
9 changes: 9 additions & 0 deletions lib/histogram.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, Plotly, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdtusz could you make the glob here grab the lib/ files too before we forget.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done here.

* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = require('../src/traces/histogram');
9 changes: 9 additions & 0 deletions lib/histogram2d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = require('../src/traces/histogram2d');
9 changes: 9 additions & 0 deletions lib/histogram2dcontour.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = require('../src/traces/histogram2dcontour');
35 changes: 35 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

/*
* This file is browserify'ed into a standalone 'Plotly' object.
*/

var Core = require('./core');

// Load all trace modules
Core.register([
require('./bar'),
require('./box'),
require('./heatmap'),
require('./histogram'),
require('./histogram2d'),
require('./histogram2dcontour'),
require('./pie'),
require('./contour'),
require('./scatter3d'),
require('./surface'),
require('./mesh3d'),
require('./scattergeo'),
require('./choropleth'),
require('./scattergl')
]);

module.exports = Core;
9 changes: 9 additions & 0 deletions lib/mesh3d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = require('../src/traces/mesh3d');
9 changes: 9 additions & 0 deletions lib/pie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = require('../src/traces/pie');
9 changes: 9 additions & 0 deletions lib/scatter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = require('../src/traces/scatter');
9 changes: 9 additions & 0 deletions lib/scatter3d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = require('../src/traces/scatter3d');
9 changes: 9 additions & 0 deletions lib/scattergeo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = require('../src/traces/scattergeo');
9 changes: 9 additions & 0 deletions lib/scattergl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = require('../src/traces/scattergl');
9 changes: 9 additions & 0 deletions lib/surface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = require('../src/traces/surface');
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "1.4.1",
"description": "The open source javascript graphing library that powers plotly",
"license": "MIT",
"main": "./src/index.js",
"webpack": "./dist/plotly.min.js",
"main": "./lib/index.js",
"webpack": "./dist/plotly.js",
"repository": {
"type": "git",
"url": "https://github.com/plotly/plotly.js.git"
Expand Down
21 changes: 1 addition & 20 deletions src/index.js → src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

/*
* Export the plotly.js API methods.
*
* This file is browserify'ed into a standalone 'Plotly' object.
*
*/

var Plotly = require('./plotly');
Expand All @@ -32,6 +29,7 @@ exports.addTraces = Plotly.addTraces;
exports.deleteTraces = Plotly.deleteTraces;
exports.moveTraces = Plotly.moveTraces;
exports.setPlotConfig = require('./plot_api/set_plot_config');
exports.register = Plotly.register;

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

// export d3 used in the bundle
exports.d3 = require('d3');

Plotly.register([
require('./traces/bar'),
require('./traces/box'),
require('./traces/heatmap'),
require('./traces/histogram'),
require('./traces/histogram2d'),
require('./traces/histogram2dcontour'),
require('./traces/pie'),
require('./traces/contour'),
require('./traces/scatter3d'),
require('./traces/surface'),
require('./traces/mesh3d'),
require('./traces/scattergeo'),
require('./traces/choropleth'),
require('./traces/scattergl')
]);
4 changes: 2 additions & 2 deletions tasks/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ catch(e) {


// Browserify plotly.js
browserify(constants.pathToPlotlySrc, {
browserify(constants.pathToPlotlyIndex, {
debug: DEV,
standalone: 'Plotly',
transform: [compressAttributes]
Expand Down Expand Up @@ -65,7 +65,7 @@ browserify(constants.pathToPlotlyGeoAssetsSrc, {


// Browserify the plotly.js with meta
browserify(constants.pathToPlotlySrc, {
browserify(constants.pathToPlotlyIndex, {
debug: DEV,
standalone: 'Plotly'
})
Expand Down
2 changes: 1 addition & 1 deletion tasks/cibundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var constants = require('./util/constants');


// Browserify plotly.js
browserify(constants.pathToPlotlySrc, {
browserify(constants.pathToPlotlyIndex, {
standalone: 'Plotly',
transform: [compressAttributes]
})
Expand Down
5 changes: 3 additions & 2 deletions tasks/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ pathsDist.forEach(headerLicense);
var licenseSrc = constants.licenseSrc;
var licenseStr = licenseSrc.substring(2, licenseSrc.length - 2);


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

Expand Down
2 changes: 1 addition & 1 deletion tasks/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ fs.copy(constants.pathToTopojsonSrc, constants.pathToTopojsonDist,
);

// inject package version into source index files
updateVersion(constants.pathToPlotlySrc);
updateVersion(constants.pathToPlotlyCore);
updateVersion(constants.pathToPlotlyGeoAssetsSrc);
Loading