@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 +1 -1
- package/src/export-funccall.ts +41 -15
package/package.json
CHANGED
package/src/export-funccall.ts
CHANGED
|
@@ -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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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(
|
|
105
|
+
worksheet.addImage(imageId, {
|
|
80
106
|
tl: {col: columnForImage, row: 0},
|
|
81
|
-
ext: {width
|
|
107
|
+
ext: {width, height},
|
|
82
108
|
});
|
|
83
109
|
} else {
|
|
84
110
|
const newWorksheet = exportWorkbook.addWorksheet(`Output - Plot - ${title}`);
|
|
85
|
-
newWorksheet.addImage(
|
|
111
|
+
newWorksheet.addImage(imageId, {
|
|
86
112
|
tl: {col: 0, row: 0},
|
|
87
|
-
ext: {width
|
|
113
|
+
ext: {width, height},
|
|
88
114
|
});
|
|
89
115
|
}
|
|
90
116
|
}
|