Skip to content

Commit 3364015

Browse files
authored
Merge pull request #4 from keller-mark/downloads
Downloads
2 parents 1bb5601 + 041e2ec commit 3364015

File tree

8 files changed

+45
-41
lines changed

8 files changed

+45
-41
lines changed

examples-src/App.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
:pMarginTop="10"
125125
:pMarginLeft="120"
126126
:pMarginRight="10"
127-
:pMarginBottom="150"
127+
:pMarginBottom="180"
128128
>
129129
<Axis
130130
slot="axisLeft"
@@ -220,6 +220,7 @@ const xyDataContainer = new DataContainer(
220220
xyData
221221
);
222222
223+
223224
// Initialize data
224225
const getData = function(dataKey) {
225226
switch(dataKey) {
@@ -231,8 +232,6 @@ const getData = function(dataKey) {
231232
return rainfallDataContainer;
232233
case 'xy_data':
233234
return xyDataContainer;
234-
default:
235-
return {}
236235
}
237236
};
238237
@@ -264,6 +263,7 @@ const xyXScale = new ContinuousScale(
264263
[0, 50]
265264
);
266265
266+
267267
const getScale = function(scaleKey) {
268268
switch(scaleKey) {
269269
case 'sample_id':

examples-src/data/brca_12_exposures.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/components/Axis.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,8 @@ export default {
516516
517517
},
518518
downloadAxis() {
519-
console.log(saveSvgAsPng);
520-
// TODO
521-
519+
let node = d3_select(this.axisSelector).select("svg").node();
520+
saveSvgAsPng(node, this.axisElemID + ".png");
522521
}
523522
}
524523
}

src/components/plots/BarPlot.vue

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,17 +257,21 @@ export default {
257257
*/
258258
const canvasNode = canvas.node();
259259
260+
const getDataFromMouse = (mouseX, mouseY) => {
261+
// Get the corresponding pixel color on the hidden canvas
262+
const col = contextHidden.getImageData(mouseX * ratio, mouseY * ratio, scaledWidth, scaledHeight).data;
263+
const colString = "rgb(" + col[0] + "," + col[1] + ","+ col[2] + ")";
264+
// Look up the node in our map
265+
return colToNode[colString];
266+
};
267+
260268
const debouncedTooltipDestroy = debounce(vm.tooltipDestroy, TOOLTIP_DEBOUNCE);
261269
canvas.on("mousemove", () => {
262270
const mouse = d3_mouse(canvasNode);
263271
const mouseX = mouse[0];
264272
const mouseY = mouse[1];
265273
266-
// Get the corresponding pixel color on the hidden canvas
267-
const col = contextHidden.getImageData(mouseX * ratio, mouseY * ratio, scaledWidth, scaledHeight).data;
268-
const colString = "rgb(" + col[0] + "," + col[1] + ","+ col[2] + ")";
269-
// Look up the node in our map
270-
const node = colToNode[colString];
274+
const node = getDataFromMouse(mouseX, mouseY);
271275
272276
if(node) {
273277
vm.tooltip(mouseX, mouseY, node["x"], node["y"]);
@@ -283,11 +287,7 @@ export default {
283287
const mouseX = mouse[0];
284288
const mouseY = mouse[1];
285289
286-
// Get the corresponding pixel color on the hidden canvas
287-
const col = contextHidden.getImageData(mouseX * ratio, mouseY * ratio, scaledWidth, scaledHeight).data;
288-
const colString = "rgb(" + col[0] + "," + col[1] + ","+ col[2] + ")";
289-
// Look up the node in our map
290-
const node = colToNode[colString];
290+
const node = getDataFromMouse(mouseX, mouseY);
291291
292292
if(node) {
293293
vm.clickHandler(node["x"], node["y"]);

src/components/plots/MultiBoxPlot.vue

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -372,17 +372,21 @@ export default {
372372
*/
373373
const canvasNode = canvas.node();
374374
375+
const getDataFromMouse = (mouseX, mouseY) => {
376+
// Get the corresponding pixel color on the hidden canvas
377+
const col = contextHidden.getImageData(mouseX * ratio, mouseY * ratio, scaledWidth, scaledHeight).data;
378+
const colString = "rgb(" + col[0] + "," + col[1] + ","+ col[2] + ")";
379+
// Look up the node in our map
380+
return colToNode[colString];
381+
}
382+
375383
const debouncedTooltipDestroy = debounce(vm.tooltipDestroy, TOOLTIP_DEBOUNCE);
376384
canvas.on("mousemove", () => {
377385
const mouse = d3_mouse(canvasNode);
378386
const mouseX = mouse[0];
379387
const mouseY = mouse[1];
380388
381-
// Get the corresponding pixel color on the hidden canvas
382-
const col = contextHidden.getImageData(mouseX * ratio, mouseY * ratio, scaledWidth, scaledHeight).data;
383-
const colString = "rgb(" + col[0] + "," + col[1] + ","+ col[2] + ")";
384-
// Look up the node in our map
385-
const node = colToNode[colString];
389+
const node = getDataFromMouse(mouseX, mouseY);
386390
387391
if(node) {
388392
vm.tooltip(mouseX, mouseY, node);
@@ -398,11 +402,7 @@ export default {
398402
const mouseX = mouse[0];
399403
const mouseY = mouse[1];
400404
401-
// Get the corresponding pixel color on the hidden canvas
402-
const col = contextHidden.getImageData(mouseX * ratio, mouseY * ratio, scaledWidth, scaledHeight).data;
403-
const colString = "rgb(" + col[0] + "," + col[1] + ","+ col[2] + ")";
404-
// Look up the node in our map
405-
const node = colToNode[colString];
405+
const node = getDataFromMouse(mouseX, mouseY);
406406
407407
if(node) {
408408
vm.clickHandler(node["x"]);

src/components/plots/ScatterPlot.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,18 @@ export default {
227227
*/
228228
const canvasNode = canvas.node();
229229
230+
const getDataFromMouse = (mouseX, mouseY) => {
231+
const i = delaunay.find(mouseX, mouseY);
232+
return data[i];
233+
};
234+
230235
const debouncedTooltipDestroy = debounce(vm.tooltipDestroy, TOOLTIP_DEBOUNCE);
231236
canvas.on("mousemove", () => {
232237
const mouse = d3_mouse(canvasNode);
233238
const mouseX = mouse[0];
234239
const mouseY = mouse[1];
235240
236-
const i = delaunay.find(mouseX, mouseY);
237-
const node = data[i];
241+
const node = getDataFromMouse(mouseX, mouseY);
238242
239243
if(node) {
240244
vm.tooltip(mouseX, mouseY, node[vm.x], node[vm.y]);
@@ -250,8 +254,7 @@ export default {
250254
const mouseX = mouse[0];
251255
const mouseY = mouse[1];
252256
253-
const i = delaunay.find(mouseX, mouseY);
254-
const node = data[i];
257+
const node = getDataFromMouse(mouseX, mouseY);
255258
256259
if(node) {
257260
vm.clickHandler(node[vm.x], node[vm.y]);

src/components/plots/StackedBarPlot.vue

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,21 @@ export default {
285285
*/
286286
const canvasNode = canvas.node();
287287
288+
const getDataFromMouse = (mouseX, mouseY) => {
289+
// Get the corresponding pixel color on the hidden canvas
290+
const col = contextHidden.getImageData(mouseX * ratio, mouseY * ratio, scaledWidth, scaledHeight).data;
291+
const colString = "rgb(" + col[0] + "," + col[1] + ","+ col[2] + ")";
292+
// Look up the node in our map
293+
return colToNode[colString];
294+
};
295+
288296
const debouncedTooltipDestroy = debounce(vm.tooltipDestroy, TOOLTIP_DEBOUNCE);
289297
canvas.on("mousemove", () => {
290298
const mouse = d3_mouse(canvasNode);
291299
const mouseX = mouse[0];
292300
const mouseY = mouse[1];
293301
294-
// Get the corresponding pixel color on the hidden canvas
295-
const col = contextHidden.getImageData(mouseX * ratio, mouseY * ratio, scaledWidth, scaledHeight).data;
296-
const colString = "rgb(" + col[0] + "," + col[1] + ","+ col[2] + ")";
297-
// Look up the node in our map
298-
const node = colToNode[colString];
302+
const node = getDataFromMouse(mouseX, mouseY);
299303
300304
if(node) {
301305
vm.tooltip(mouseX, mouseY, node["x"], node["y"], node["c"]);
@@ -311,11 +315,7 @@ export default {
311315
const mouseX = mouse[0];
312316
const mouseY = mouse[1];
313317
314-
// Get the corresponding pixel color on the hidden canvas
315-
const col = contextHidden.getImageData(mouseX * ratio, mouseY * ratio, scaledWidth, scaledHeight).data;
316-
const colString = "rgb(" + col[0] + "," + col[1] + ","+ col[2] + ")";
317-
// Look up the node in our map
318-
const node = colToNode[colString];
318+
const node = getDataFromMouse(mouseX, mouseY);
319319
320320
if(node) {
321321
vm.clickHandler(node["x"], node["y"], node["c"]);

src/components/plots/mixin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ export default {
109109
// stub
110110
},
111111
downloadPlot: function() {
112-
return document.getElementById(this.plotElemID).toDataURL("image/png");
112+
let image = document.getElementById(this.plotElemID).toDataURL("image/png");
113+
document.write('<img src="'+image+'"/>');
113114
}
114115
}
115116
}

0 commit comments

Comments
 (0)