Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

No way to resize getImage font #38

Open
edwinfinch opened this issue Dec 29, 2015 · 3 comments
Open

No way to resize getImage font #38

edwinfinch opened this issue Dec 29, 2015 · 3 comments

Comments

@edwinfinch
Copy link

Hello!

You have a really great library and service here, thank you for that. I'm using it for one of my Telegram bots now. When Telegram sends an image, it is compressed, and therefore a lot of the quality is lost. I find on the Plotly Node.JS library no way to resize the font of the text on the X or Y axis. I also can't put a title on the top of the image. Could you please add support for this?

Thanks!

@etpinard
Copy link
Contributor

@edwinfinch maybe this https://plot.ly/nodejs/font/ could help you out.

@edwinfinch
Copy link
Author

@etpinard That's what I thought, and then I actually gave it a shot and it simply ignores the font option. Looked into the plotly node code myself and it doesn't even send anything from imageOptions except what is put in the examples (type, width, height IIRC).

What I ended up doing for now is calling .plot() and taking the URL from there, appending an ending onto it to get the PNG file, downloaded that and sent that. Works fine for now, though getImage would be cleaner since I wouldn't have to write my own API for it. And I'm pretty sure getImage is not affected by the API limits (though it may be?), whereas plot is and I reached my 50/day limit pretty darn quick.

@etpinard
Copy link
Contributor

@edwinfinch getImage expect a figure object containing data and layout attributes:

So starting with:

var data = [
  {
    x: [0, 1, 2, 3, 4, 5, 6, 7, 8],
    y: [0, 1, 2, 3, 4, 5, 6, 7, 8],
    type: "scatter"
  }
];

var layout = {
  title: "Global Font",
  font: {
    family: "Courier New, monospace",
    size: 18,
    color: "#7f7f7f"
  }
};

the plot call signature is:

var graphOptions = {layout: layout, filename: "global-font", fileopt: "overwrite"};
plotly.plot(data, graphOptions, function (err, msg) {
    console.log(msg);
});

while the getImage call signature is:

var figure = {data: data, layout: layout};
var imgOpts = {format: 'png', width: 1000, height: 500};
plotly.getImage(figure, imgOpts, function (error, imageStream) {
    if (error) return console.log (error);

    var fileStream = fs.createWriteStream('1.png');
    imageStream.pipe(fileStream);
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants