canvasxpress-cli 41.3.4 → 41.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cmds/help.js CHANGED
@@ -7,94 +7,29 @@ const menus = {
7
7
  svg ................ create a svg CanvasXpress file from inline parameters, file or url
8
8
  json ............... create a json CanvasXpress file from inline parameters, file or url
9
9
 
10
- csv ................ create a CanvasXpress png file from a local csv file or url
11
- reproduce .......... create CanvasXpress png files from a local file or url
12
- canvas ............. run scripts files to test CanvasXpres
10
+ canvas ............. run scripts files to test CanvasXpres [internal]
13
11
 
14
12
  test ............... test package. Creates images and json file in test directory
15
13
  version ............ show this package version
16
14
  help ............... show this help. Add command to show correponding help
17
15
  `,
18
16
 
19
- canvas: `
20
- --input, -i ........ <required> path/to/js/file
21
- --directory, -f .... [optional] directory of CanvasXpres version to check
22
- --graph, -g ........ [optional] graph name
23
- --number, -n ....... [optional] number for the graph
24
- --timeout, -t ...... [optional] timeout in millisecods to close browser
25
- {default} 500
26
- --browser, -b ...... [optional] boolean to do not run headless and pause for debugging
27
-
28
- Examples:
29
-
30
- canvasxpress canvas -i canvas/scripts/compareImages.js
31
-
32
- canvasxpress canvas -i canvas/scripts/compareImages.js -g violin -n 11
33
- `,
34
-
35
- csv: `
36
- --input, -i ........ [optional - required] file or url with a csv file:
37
- file:///path/to/local/file.csv
38
- http://page/with/file.csv
39
- https://page/with/file.csv
40
- --output, -o ....... [optional] directory path to save image
41
- {default} './'
42
- --width, -x ........ [optional] integer for image width
43
- {default} 800
44
- --height, -y ....... [optional] integer for image height
45
- {default} 800
46
- --data, -d ......... [optional - required] json string with the data for CanvasXpress
47
- --config, -c ....... [optional] json string with configuration for CanvasXpress
48
- --timeout, -t ...... [optional] timeout in millisecods to close browser
49
- {default} 500
50
- --browser, -b ...... [optional] boolean to do not run headless and pause for debugging
51
-
52
- Examples:
53
-
54
- canvasxpress csv -i ../src/ToothGrowth.csv -t 3000
55
-
56
- canvasxpress csv -i https://raw.githubusercontent.com/neuhausi/Rdatasets/master/csv/datasets/ToothGrowth.csv -t 3000
57
-
58
- canvasxpress csv -i file:///node/src/ToothGrownth.csv -c '{"graphType":"Boxplot","transposeData":true,"asVariableFactors":["dose"],"stringSampleFactors":["dose"],"groupingFactors":["dose"]}' -t 3000
59
-
60
- canvasxpress csv -d '{"y":{"vars":["Variable1"],"smps":["Sample1","Sample2","Sample3"],"data":[[33,44,55]]}}' -c '{"graphOrientation":"vertical","theme":"CanvasXpress","title":"Bar Graph Title"}' -t 3000
61
- `,
62
-
63
- reproduce: `
64
- --input, -i ........ <required> file or url with a html file:
65
- file:///path/to/local/file.html
66
- http://page/with/file.html
67
- https://page/with/file.html
68
- --output, -o ....... [optional] directory path to save image
69
- {default} './'
70
- --timeout, -t ...... [optional] timeout in millisecods to close browser
71
- {default} 500
72
- --browser, -b ...... [optional] boolean to do not run headless and pause for debugging
73
-
74
- Examples:
75
-
76
- canvasxpress reproduce -i https://canvasxpress.org/examples/layout-7.html
77
-
78
- canvasxpress reproduce -i file:///node/src/canvasXpress.html
79
-
80
- canvasxpress reproduce -i ../src/canvasXpress.html
81
- `,
82
-
83
17
  png: `
84
- --input, -i ........ [optional - required] file or url with a html file:
85
- file:///path/to/local/file.html
86
- http://page/with/file.html
87
- https://page/with/file.html
18
+ --input, -i ........ [optional - required] file or url:
19
+ /path/to/local/file.[json|png|csv|txt|html]
20
+ http://page/with/file.[json|png|csv|txt|html]
21
+ https://page/with/file.[json|png|csv|txt|html]
88
22
  --output, -o ....... [optional] directory path to save image
89
23
  {default} './'
90
24
  --width, -x ........ [optional] integer for image width
91
25
  {default} 800
92
26
  --height, -y ....... [optional] integer for image height
93
27
  {default} 800
28
+ --target, -t ....... [optional] string id for CanvasXpress
94
29
  --data, -d ......... [optional - required] json string with the data for CanvasXpress
95
- --config, -c ....... [optional] json string with configuration for CanvasXpress --timeout, -t ...... [optional] timeout in millisecods to close browser
96
- {default} 500
97
- --timeout, -t ...... [optional] timeout in millisecods to close browser
30
+ --config, -c ....... [optional] json string with configuration for CanvasXpress
31
+ --events, -e ....... [optional] json/javascript string with events for CanvasXpress
32
+ --timeout, -q ...... [optional] timeout in millisecods to close browser
98
33
  {default} 500
99
34
  --browser, -b ...... [optional] boolean to do not run headless and pause for debugging
100
35
 
@@ -102,28 +37,31 @@ const menus = {
102
37
 
103
38
  canvasxpress png -i https://canvasxpress.org/examples/bar-3.html
104
39
 
105
- canvasxpress png -i file:///node/src/canvasXpress.html
40
+ canvasxpress png -i ../src/area.json
41
+
42
+ canvasxpress png -i ../src/dotplot.png
106
43
 
107
- canvasxpress png -i ../src/canvasXpress.html
44
+ canvasxpress png -d '{"y":{"vars":["Variable1"],"smps":["Sample1","Sample2","Sample3"],"data":[[33,44,55]]}}' -c '{"graphOrientation":"vertical","title":"Bar Graph Title"}'
108
45
 
109
- canvasxpress png -d '{"y":{"vars":["Variable1"],"smps":["Sample1","Sample2","Sample3"],"data":[[33,44,55]]}}'
110
- -c '{"graphOrientation":"vertical","theme":"CanvasXpress","title":"Bar Graph Title"}'
46
+ canvasxpress png -i ../src/ToothGrowth.csv -c '{"graphType":"Boxplot","asVariableFactors":["dose"],"stringSampleFactors":["dose"],"groupingFactors":["dose"]}'
111
47
  `,
112
48
 
113
49
  svg: `
114
- --input, -i ........ [optional - required] file or url with a html file:
115
- file:///path/to/local/file.html
116
- http://page/with/file.html
117
- https://page/with/file.html
50
+ --input, -i ........ [optional - required] file or url:
51
+ /path/to/local/file.[json|png|csv|txt|html]
52
+ http://page/with/file.[json|png|csv|txt|html]
53
+ https://page/with/file.[json|png|csv|txt|html]
118
54
  --output, -o ....... [optional] directory path to save image
119
55
  {default} './'
120
56
  --width, -x ........ [optional] integer for image width
121
57
  {default} 800
122
58
  --height, -y ....... [optional] integer for image height
123
59
  {default} 800
60
+ --target, -t ....... [optional] string id for CanvasXpress
124
61
  --data, -d ......... [optional - required] json string with the data for CanvasXpress
125
62
  --config, -c ....... [optional] json string with configuration for CanvasXpress
126
- --timeout, -t ...... [optional] timeout in millisecods to close browser
63
+ --events, -e ....... [optional] json/javascript string with events for CanvasXpress
64
+ --timeout, -q ...... [optional] timeout in millisecods to close browser
127
65
  {default} 500
128
66
  --browser, -b ...... [optional] boolean to do not run headless and pause for debugging
129
67
 
@@ -131,28 +69,31 @@ const menus = {
131
69
 
132
70
  canvasxpress svg -i https://canvasxpress.org/examples/bar-3.html
133
71
 
134
- canvasxpress svg -i file:///node/src/canvasXpress.html
72
+ canvasxpress svg -i ../src/area.json
135
73
 
136
- canvasxpress svg -i ../src/canvasXpress.html
74
+ canvasxpress svg -i ../src/dotplot.png
137
75
 
138
- canvasxpress svg -d '{"y":{"vars":["Variable1"],"smps":["Sample1","Sample2","Sample3"],"data":[[33,44,55]]}}'
139
- -c '{"graphOrientation":"vertical","theme":"CanvasXpress","title":"Bar Graph Title"}'
76
+ canvasxpress svg -d '{"y":{"vars":["Variable1"],"smps":["Sample1","Sample2","Sample3"],"data":[[33,44,55]]}}' -c '{"graphOrientation":"vertical","title":"Bar Graph Title"}'
77
+
78
+ canvasxpress svg -i ../src/ToothGrowth.csv -c '{"graphType":"Boxplot","asVariableFactors":["dose"],"stringSampleFactors":["dose"],"groupingFactors":["dose"]}'
140
79
  `,
141
80
 
142
81
  json: `
143
- --input, -i ........ [optional - required] file or url with a html file:
144
- file:///path/to/local/file.html
145
- http://page/with/file.html
146
- https://page/with/file.html
82
+ --input, -i ........ [optional - required] file or url:
83
+ /path/to/local/file.[json|png|csv|txt|html]
84
+ http://page/with/file.[json|png|csv|txt|html]
85
+ https://page/with/file.[json|png|csv|txt|html]
147
86
  --output, -o ....... [optional] directory path to save image
148
87
  {default} './'
149
88
  --width, -x ........ [optional] integer for image width
150
89
  {default} 800
151
90
  --height, -y ....... [optional] integer for image height
152
91
  {default} 800
92
+ --target, -t ....... [optional] string id for CanvasXpress
153
93
  --data, -d ......... [optional - required] json string with the data for CanvasXpress
154
94
  --config, -c ....... [optional] json string with configuration for CanvasXpress
155
- --timeout, -t ...... [optional] timeout in millisecods to close browser
95
+ --events, -e ....... [optional] json/javascript string with events for CanvasXpress
96
+ --timeout, -q ...... [optional] timeout in millisecods to close browser
156
97
  {default} 500
157
98
  --browser, -b ...... [optional] boolean to do not run headless and pause for debugging
158
99
 
@@ -160,28 +101,29 @@ const menus = {
160
101
 
161
102
  canvasxpress json -i https://canvasxpress.org/examples/bar-3.html
162
103
 
163
- canvasxpress json -i file:///node/src/canvasXpress.html
104
+ canvasxpress json -i ../src/area.json
164
105
 
165
- canvasxpress json -i ../src/canvasXpress.html
106
+ canvasxpress json -i ../src/dotplot.png
166
107
 
167
- canvasxpress json -d '{"y":{"vars":["Variable1"],"smps":["Sample1","Sample2","Sample3"],"data":[[33,44,55]]}}'
168
- -c '{"graphOrientation":"vertical","theme":"CanvasXpress","title":"Bar Graph Title"}'
169
- `,
108
+ canvasxpress json -d '{"y":{"vars":["Variable1"],"smps":["Sample1","Sample2","Sample3"],"data":[[33,44,55]]}}' -c '{"graphOrientation":"vertical","title":"Bar Graph Title"}'
170
109
 
171
- target: `
172
- --target, -t ....... [optional] string with CanvasXpress target Id
110
+ canvasxpress json -i ../src/ToothGrowth.csv -c '{"graphType":"Boxplot","asVariableFactors":["dose"],"stringSampleFactors":["dose"],"groupingFactors":["dose"]}'
173
111
  `,
174
112
 
175
- data: `
176
- --data, -d ......... [optional] json string with data for CanvasXpress
177
- `,
113
+ canvas: `
114
+ --input, -i ........ <required> path/to/js/file
115
+ --directory, -f .... [optional] directory of CanvasXpres version to check
116
+ --graph, -g ........ [optional] graph name
117
+ --number, -n ....... [optional] number for the graph
118
+ --timeout, -q ...... [optional] timeout in millisecods to close browser
119
+ {default} 500
120
+ --browser, -b ...... [optional] boolean to do not run headless and pause for debugging
178
121
 
179
- config:`
180
- --config, -d ....... [optional] json string with configuration for CanvasXpress
181
- `,
122
+ Examples:
182
123
 
183
- events:`
184
- --events, -e ....... [optional] javascript string with events for CanvasXpress
124
+ canvasxpress canvas -i canvas/scripts/compareImages.js
125
+
126
+ canvasxpress canvas -i canvas/scripts/compareImages.js -g violin -n 11
185
127
  `
186
128
 
187
129
  }
package/cmds/io.js CHANGED
@@ -14,7 +14,7 @@ module.exports = async (obj) => {
14
14
 
15
15
  const logStdout = process.stdout;
16
16
 
17
- const defhtml = ("file://" + dirname + "/src/canvasXpress.html" + (obj.debug ? "?cXH" : ""));
17
+ const html = (obj.input && obj.input.match(/.html$/) ? obj.input : ("file://" + dirname + "/src/canvasXpress.html")) + (obj.debug ? "?cXH" : "");
18
18
 
19
19
  console.log = function () {
20
20
  logFile.write(util.format.apply(null, arguments) + '\n');
@@ -44,17 +44,20 @@ module.exports = async (obj) => {
44
44
 
45
45
  const page = await browser.newPage();
46
46
 
47
+ page.on("console", (consoleObj) => console.log(consoleObj.text()));
48
+
47
49
  if (obj.input && !obj.input.match(/^file|^http/)) {
48
50
  obj.input = "file://" + path.resolve(obj.input);
49
51
  }
50
52
 
51
53
  const func = function (obj) {
54
+
52
55
  if (obj.debug) {
53
56
  debugger;
54
57
  }
58
+
55
59
  var exec = function (cx, tg) {
56
60
  switch (obj.cmd) {
57
- case 'csv':
58
61
  case 'png':
59
62
  cx.print(false, tg + '.png');
60
63
  break;
@@ -64,70 +67,72 @@ module.exports = async (obj) => {
64
67
  case 'json':
65
68
  cx.save(false, tg + '.json');
66
69
  break;
67
- case 'reproduce':
68
- cx.reproduce(false, true, true);
69
- break;
70
70
  }
71
71
  }
72
+
72
73
  var clbk = function () {
73
- var cxs = CanvasXpress.instances;
74
- var cx = cxs[cxs.length - 1];
75
- var tg = cx.target;
76
- console.log("Creating " + (obj.cmd == 'csv' ? 'png' : obj.cmd) + " file from " + (obj.input ? obj.input : 'input data') + " (" + obj.output + (obj.target || cx.target) + ".png)");
77
- exec(cx, tg);
74
+ var cx = CanvasXpress.instances[1];
75
+ console.log(logStr);
76
+ exec(cx, cx.target);
78
77
  }
79
- var cxs = CanvasXpress.instances;
80
- for (var i = 0; i < cxs.length; i++) {
81
- var cx = cxs[i];
82
-
83
- cx.setDimensions(obj.width, obj.height);
84
- if (obj.input) {
85
- try {
86
- if (obj.cmd == 'csv') {
78
+
79
+ var cx = CanvasXpress.instances[0];
80
+
81
+ const extFile = obj.input ? obj.input.split(".").pop() : false;
82
+
83
+ const logStr = "Creating " + obj.cmd + " file from " + (obj.input ? obj.input : 'input data') + " (" + obj.output + (obj.target || cx.target) + (extFile == 'html' ? '' : '-1') + "." + obj.cmd + ")";
84
+
85
+ cx.setDimensions(obj.width, obj.height);
86
+
87
+ if (obj.input) {
88
+ try {
89
+ switch (extFile) {
90
+ case 'html':
91
+ console.log(logStr);
92
+ exec(cx, obj.target || cx.target);
93
+ return;
94
+ case 'json':
95
+ case 'csv':
96
+ case 'text':
97
+ case 'png':
87
98
  cx.dataURL = obj.input;
88
99
  cx.remoteTransitionEffect = 'none';
89
100
  cx.getDataFromURLOrString(obj.target || cx.target, obj.config, false, false, clbk);
90
- } else {
91
- console.log("Creating " + (obj.cmd == 'csv' ? 'png' : obj.cmd) + " file from " + (obj.input ? obj.input : 'input data') + " (" + obj.output + (obj.target || cx.target) + "." + obj.cmd + ")");
92
- exec(cx, obj.target || cx.target);
93
- }
94
- } catch (err) {
95
- console.error(err);
96
- }
97
- } else if (obj.data) {
98
- try {
99
- console.log("Creating " + (obj.cmd == 'csv' ? 'png' : obj.cmd) + " file from " + (obj.input ? obj.input : 'input data') + " (" + obj.output + (obj.target || cx.target) + "." + obj.cmd + ")");
100
- cx.updateData(obj.data, false, false, obj.config);
101
- exec(cx, obj.target || cx.target);
102
- return;
103
- } catch (err) {
104
- console.error(err);
101
+ return;
105
102
  }
103
+ } catch (err) {
104
+ console.error(err);
105
+ }
106
+ } else if (obj.data) {
107
+ try {
108
+ console.log(logStr);
109
+ cx.updateData(obj.data, false, false, obj.config);
110
+ exec(cx, obj.target || cx.target);
111
+ return;
112
+ } catch (err) {
113
+ console.error(err);
106
114
  }
107
-
108
115
  }
116
+
109
117
  }
110
118
 
111
- const client = await page.target().createCDPSession()
119
+ const client = await page.target().createCDPSession();
120
+
112
121
  await client.send('Page.setDownloadBehavior', {
113
122
  behavior: 'allow',
114
123
  downloadPath: obj.output
115
124
  })
116
125
 
117
- if (obj.input) {
118
- await page.goto(obj.cmd == 'csv' ? defhtml : obj.cmd == 'reproduce' ? obj.input + '?showTransition=false' + (obj.debug ? '&cXH' : '') : obj.input + (obj.debug ? '?cXH' : ''));
119
- } else {
120
- await page.goto(defhtml);
121
- }
126
+ await page.goto(html);
122
127
 
123
- await page.waitForTimeout(() => typeof (CanvasXpress) !== undefined && CanvasXpress.ready);
128
+ await page.waitForFunction('typeof (CanvasXpress) !== undefined && CanvasXpress.ready');
124
129
 
125
130
  await page.evaluate(`(${func.toString()})(${JSON.stringify(obj)})`);
126
131
 
127
132
  await setTimeout(() => {
128
133
  browser.close();
129
134
  spinner.stop();
130
- }, obj.cmd == 'csv' || obj.cmd == 'reproduce' ? obj.tmout + 2500 : obj.tmout);
135
+ }, obj.tmout);
131
136
 
132
137
  } catch (err) {
133
138
 
package/index.js CHANGED
@@ -28,11 +28,11 @@ module.exports = () => {
28
28
 
29
29
  let height = args.height || args.y || 800;
30
30
 
31
- let tmout = args.timeout || args.t || 2500;
31
+ let tmout = args.timeout || args.q || 2500;
32
32
 
33
- let data = dat ? JSON.parse(dat) : { "y": { "vars": ["Variable1"], "smps": ["Sample1", "Sample2", "Sample3"], "data": [[55, 44, 33]] } };
33
+ let data = dat ? JSON.parse(dat) : false;
34
34
 
35
- let config = conf ? JSON.parse(conf) : { "graphType": "Boxplot", "transposeData": true, "asVariableFactors": ["dose"], "stringSampleFactors": ["dose"], "groupingFactors": ["dose"] };
35
+ let config = conf ? JSON.parse(conf) : false;
36
36
 
37
37
  let obj = {
38
38
  cmd: cmd,
@@ -71,11 +71,9 @@ module.exports = () => {
71
71
 
72
72
  switch (cmd) {
73
73
 
74
- case 'csv':
75
74
  case 'png':
76
75
  case 'svg':
77
76
  case 'json':
78
- case 'reproduce':
79
77
  if (input || data) {
80
78
  require('./cmds/io')(obj);
81
79
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasxpress-cli",
3
- "version": "41.3.4",
3
+ "version": "41.3.8",
4
4
  "license": {
5
5
  "type": "Dual licensing",
6
6
  "url": "https://www.canvasxpress.org/docs/license.html"
package/src/area.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "version": 41.2,
3
+ "renderTo": "area1",
4
+ "data": {
5
+ "y": {
6
+ "data": [
7
+ [10,100,70,130,60]
8
+ ],
9
+ "vars": ["A"],
10
+ "smps": ["S1","S2","S3","S4","S5"]
11
+ }
12
+ },
13
+ "config": {
14
+ "colorScheme": "CanvasXpress",
15
+ "graphOrientation": "vertical",
16
+ "graphType": "Area",
17
+ "lineType": "rect",
18
+ "objectBorderColor": false,
19
+ "showLegend": false,
20
+ "showSampleNames": true,
21
+ "showTransition": false,
22
+ "smpLabelRotate": 90,
23
+ "smpTitle": "time"
24
+ },
25
+ "events": false,
26
+ "info": false,
27
+ "afterRenderInit": false,
28
+ "afterRender": [
29
+ [
30
+ "setDimensions",
31
+ [609,609,true]
32
+ ]
33
+ ],
34
+ "noValidate": true,
35
+ "factory": {
36
+ "version": 41.2,
37
+ "buildDate": "12-05-2022",
38
+ "client": "MDo6MTo6NDEuMjo6",
39
+ "siteSrc": false,
40
+ "href": "http://localhost:8000/examples/area-1.html",
41
+ "services": "https://www.canvasxpress.org/cgi-bin/services.pl"
42
+ },
43
+ "system": {
44
+ "browser": "Chrome",
45
+ "browserVersion": "107",
46
+ "os": "Mac OS",
47
+ "alt": "&#8997;",
48
+ "command": "&#8984;",
49
+ "control": "&#8963;",
50
+ "shift": "&#8679;",
51
+ "isNode": false,
52
+ "isHeadless": false,
53
+ "isjQuery": false,
54
+ "isReveal": false,
55
+ "isZoom": false,
56
+ "isIE": false,
57
+ "isInIframe": false,
58
+ "isTouchScreen": 0,
59
+ "isR": false,
60
+ "isHTMLWidgets": false,
61
+ "isShiny": false,
62
+ "isRViewer": false,
63
+ "isRConsole": false,
64
+ "isCxplot": false
65
+ }
66
+ }
@@ -3,29 +3,26 @@
3
3
  <!-- CanvasXpress -->
4
4
  <link rel="stylesheet" href="../src/canvasXpress.css" type="text/css"/>
5
5
  <script type="text/javascript" src="../src/canvasXpress.js"></script>
6
- <!-- Page Script -->
7
- <script>
8
- onReady(function () {
9
- var cx = new CanvasXpress("cX",
10
- {
11
- "y" : {
12
- "vars" : ["Variable1"],
13
- "smps" : ["Sample1", "Sample2", "Sample3"],
14
- "data" : [[33, 44, 55]]
15
- }
16
- },
17
- {
18
- "graphOrientation": "vertical",
19
- "graphType": "Bar",
20
- "title": "Simple Bar graph"
21
- }
22
- );
23
- });
24
- </script>
25
6
  </head>
26
7
  <body>
27
8
  <div>
28
9
  <canvas id='cX' width='600' height='600' data-responsive='true' data-aspectRatio='1:1'></canvas>
29
10
  </div>
11
+ <!-- Page Script -->
12
+ <script>
13
+ var cx = new CanvasXpress("cX",
14
+ {
15
+ "y" : {
16
+ "vars" : ["Variable1"],
17
+ "smps" : ["Sample1", "Sample2", "Sample3"],
18
+ "data" : [[33, 44, 55]]
19
+ }
20
+ }, {
21
+ "graphOrientation": "vertical",
22
+ "graphType": "Bar",
23
+ "title": "Simple Bar graph"
24
+ }
25
+ );
26
+ </script>
30
27
  </body>
31
28
  </html>
Binary file