@datagrok/compute 0.2.7 → 0.2.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@datagrok/compute",
3
3
  "friendlyName": "Compute",
4
- "version": "0.2.7",
4
+ "version": "0.2.8",
5
5
  "description": "",
6
6
  "dependencies": {
7
7
  "cash-dom": "latest",
@@ -62,29 +62,55 @@ export async function exportFuncCall(call: DG.FuncCall) {
62
62
  const title = titleDiv.firstChild?.textContent;
63
63
  if (!title) continue;
64
64
 
65
- const plot = titleDiv.nextSibling;
66
- // if plot does not exist or it is only grid, skip it
67
- if (!plot || (plot.firstChild as HTMLElement).getAttribute('name') === 'viewer-Grid') continue;
68
-
69
- const canvas = await DG.HtmlUtils.renderToCanvas(plot as HTMLElement);
70
- const dataUrl = canvas.toDataURL('image/png');
71
- const testImageId = exportWorkbook.addImage({
72
- base64: dataUrl,
73
- extension: 'png',
74
- });
75
- const worksheet = exportWorkbook.getWorksheet(`Output - ${title}`);
65
+ let imageId;
66
+ let width = 0;
67
+ let height = 0;
68
+
69
+ const imageDiv = titleDiv.parentElement?.getElementsByClassName('grok-scripting-image-container')[0];
70
+ if (imageDiv) {
71
+ const regex = /background-image: url\(.*\)/;
72
+ const urlAttr = imageDiv.outerHTML.match(regex)?.[0];
73
+ if (!urlAttr) continue;
74
+ const url = urlAttr.substring(23, urlAttr?.length - 2);
75
+ const pic = (await (await fetch(url)).arrayBuffer());
76
+ imageId = exportWorkbook.addImage({
77
+ buffer: pic,
78
+ extension: 'png',
79
+ });
80
+ width = imageDiv.clientWidth;
81
+ height = imageDiv.clientHeight;
82
+ } else {
83
+ const plot = titleDiv.nextSibling;
84
+ // if plot does not exist or it is only grid, skip it
85
+ if (!plot || (plot.firstChild as HTMLElement).getAttribute('name') === 'viewer-Grid') continue;
86
+
87
+ if (plot) {
88
+ const canvas = await DG.HtmlUtils.renderToCanvas(plot as HTMLElement);
89
+ const dataUrl = canvas.toDataURL('image/png');
90
+
91
+ imageId = exportWorkbook.addImage({
92
+ base64: dataUrl,
93
+ extension: 'png',
94
+ });
95
+ width = canvas.width;
96
+ height = canvas.height;
97
+ }
98
+ }
99
+
100
+ if (imageId === null || imageId === undefined) continue;
76
101
 
102
+ const worksheet = exportWorkbook.getWorksheet(`Output - ${title}`);
77
103
  if (worksheet) {
78
104
  const columnForImage = ((call.outputs[title] as DG.DataFrame).columns as DG.ColumnList).length + 1;
79
- worksheet.addImage(testImageId, {
105
+ worksheet.addImage(imageId, {
80
106
  tl: {col: columnForImage, row: 0},
81
- ext: {width: canvas.width, height: canvas.height},
107
+ ext: {width, height},
82
108
  });
83
109
  } else {
84
110
  const newWorksheet = exportWorkbook.addWorksheet(`Output - Plot - ${title}`);
85
- newWorksheet.addImage(testImageId, {
111
+ newWorksheet.addImage(imageId, {
86
112
  tl: {col: 0, row: 0},
87
- ext: {width: canvas.width, height: canvas.height},
113
+ ext: {width, height},
88
114
  });
89
115
  }
90
116
  }