graphite-web icon indicating copy to clipboard operation
graphite-web copied to clipboard

Allow return of base64 encoded PNG image

Open petegallagher opened this issue 12 years ago • 3 comments

I would like to be able to get a base64 encoded version of the PNG image. This would allow me to manipulate the image via JQuery (or other JS library) to update the image client side without having to refresh the entire page e.g.

var drawGraphs = function() {
    $.ajax({
        url: "http://www.example.com/render/?blah=123&format=pngbase64",
    })
    .done(function(data){
        $( "#graphs" ).html('<img src="data:image/png;base64,' + data + '" />'); 
    });
}

I have modified views.py to allow this (see petegallagher/graphite-web@ceea46b7576d7286dcae6f227e2c14282cdf3942) and it works fine, but I have some doubts this is the best way to handle it (e.g. will this affect SVG images?).

petegallagher avatar Dec 10 '13 04:12 petegallagher

This shouldn't be necessary: the graphite composer already has an "auto-refresh" mode that updates the image. It just relies on a common trick which is to inject a querystring parameter in the image URL to make the browser think the image has changed. Using a timestamp is common for this. That's what the composer does:

https://github.com/graphite-project/graphite-web/blob/master/webapp/content/js/composer.js#L104-L113

brutasse avatar Dec 10 '13 08:12 brutasse

My first attempt used the same timestamp technique, but I felt it would be better to have the option to return a base64 encoded version so no trick is required.

petegallagher avatar Dec 11 '13 01:12 petegallagher

I have to agree with @brutasse that this seems unnecessary. However, if you'd like to submit a PR for format=png64 or something to that effect, I'm sure we'd consider it. Thanks!

obfuscurity avatar Sep 03 '14 16:09 obfuscurity