Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 7a360d2

Browse files
committed
Added basic support for Tonicdev use
1 parent 0017cb5 commit 7a360d2

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ plotly.plot(data,graphOptions,function() {
3131
});
3232
```
3333

34+
Usage is also possible with [Tonicdev](https://tonicdev.com) using the following code:
35+
36+
```javascript
37+
var plot = require('plotly/notebook');
38+
39+
plot([{ x: [1,2,3], y: [4,5,6] }], { title: 'Hello World!' titleFont: { color: '#663399' } });
40+
```
41+
42+
This simply returns an HTML string that will be rendered.
43+
3444
####Full REST API Documentation can be found here: [https://plot.ly/api/rest/](https://plot.ly/api/rest/)
3545

3646
Sign up for plotly here: [https://plot.ly/](https://plot.ly/) and obtain your API key and Stream Tokens in your plotly settings: [https://plot.ly/settings](https://plot.ly/settings).
@@ -45,8 +55,8 @@ var plotly = require('plotly')('username', 'apiKey');
4555

4656
##plotly.plot(data,graphOptions[, callback])
4757
Plotly graphs are described declaratively with a data JSON Object and a graphOptions JSON Object.
48-
`data` is an array of Objects and with each object containing data and styling information of separate graph traces. Docs: [https://plot.ly/api/rest](https://plot.ly/api/rest)
49-
`graphOptions` is an Object containing styling options like axis information and titles for your graph. Docs: [https://plot.ly/api/rest](https://plot.ly/api/rest)
58+
`data` is an array of Objects and with each object containing data and styling information of separate graph traces. Docs: [https://plot.ly/api/rest](https://plot.ly/api/rest)
59+
`graphOptions` is an Object containing styling options like axis information and titles for your graph. Docs: [https://plot.ly/api/rest](https://plot.ly/api/rest)
5060
`callback(err,msg)` where `err` is an error Object, and `msg` is the return response Object
5161

5262
The `msg` object has the following attributes : `msg.url`,`msg.filename`,`msg.message`,`msg.warning`,`msg.error`
@@ -180,7 +190,7 @@ plotly.getFigure('fileOwner', 'fileId', function (err, figure) {
180190
`options.width` | width in `px` (default : 700)
181191
`options.height` | height in `px` (default : 500)
182192

183-
`callback(err, imageData)`
193+
`callback(err, imageData)`
184194

185195
`err` is an Error Object
186196
`imageStream` is a Stream of base-64 encoded imageData

notebook.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
module.exports = function(div, data, layout) {
4+
div = div || 'notebook-plot';
5+
data = data || [];
6+
layout = layout || {};
7+
8+
var timestamp = new Date().getTime();
9+
10+
return [
11+
'<div class=\'plotly-plot\'>',
12+
'<script type=\'text/javascript\' ',
13+
'src=\'https://cdn.plot.ly/plotly-latest.min.js\'>',
14+
'</script>',
15+
'<div id=\'',
16+
div,
17+
'\'></div>',
18+
'<script>Plotly.plot(\'',
19+
div,
20+
'\',',
21+
JSON.stringify(data),
22+
',',
23+
JSON.stringify(layout),
24+
');</script>',
25+
'</div>'
26+
].join('');
27+
};

test/notebook.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
var test = require('tape');
4+
var Plot = require('../notebook');
5+
6+
test('works with no arguments', function(t) {
7+
t.plan(1);
8+
9+
var html = Plot(),
10+
expected = '<div class=\'plotly-plot\'><script type=\'text/javascript\' src=\'https://cdn.plot.ly/plotly-latest.min.js\'></script><div id=\'notebook-plot\'></div><script>Plotly.plot(\'notebook-plot\',[],{});</script></div>';
11+
12+
t.isEqual(html, expected);
13+
t.end();
14+
});
15+
16+
test('works with all arguments', function(t) {
17+
t.plan(1);
18+
19+
var html = Plot('test', [{ x: [1,2,3], y: [4,5,6] }], { titlefont: { color: 'red' } }),
20+
expected = '<div class=\'plotly-plot\'><script type=\'text/javascript\' src=\'https://cdn.plot.ly/plotly-latest.min.js\'></script><div id=\'test\'></div><script>Plotly.plot(\'test\',[{"x":[1,2,3],"y":[4,5,6]}],{"titlefont":{"color":"red"}});</script></div>';
21+
22+
t.isEqual(html, expected);
23+
t.end();
24+
});

0 commit comments

Comments
 (0)