GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||
GeezerVison is showing github.com — Use plot title as default filename for "Download plot" button by emilykl · Pull Request #7828 · plotly/plotly.js Conversation
|
|
Nice! Plotly.newPlot(gd, [{y: [1, 2]}], {title: {text: "."}}); Right now it returns |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // so ignore the title entirely if it contains LaTeX markup | ||
| if (!svgTextUtils.matchTex(plotTitle)) { | ||
| potentialFilename = Lib.slugify(plotTitle, 40); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You may also consider adding the subtitle.text if present.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm open to that, but I'm having trouble thinking of a real-world example where adding the subtitle would result in a better filename.
I suppose maybe in the case where you have multiple plots with the same title but different subtitles, that could differentiate the filenames.
Do you have any particular examples in mind?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here is a common example where subtitle could be used to provide the time stamp of the graph.
Plotly.newPlot(gd, [{y: [1, 2]}], {title: {text: "Hourly Temp. (°C) Forecast - Montréal", subtitle: {text: "9 June 2026"}}});
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
That's a positive example, if we add the subtitle we would get hourly-temp-c-forecast-montreal-9-june-2.png instead of hourly-temp-c-forecast-montreal.png. Though I also think the filename with just the title is fine.
However I also see cases where adding the subtitle gives a worse result, for example this plot in the docs where we would end up with life-expectancy-life-expectancy-by-europ.png rather than life-expectancy.png.
I've updated the logic to fall back to the subtitle in cases where the title is missing or consists of MathJax, which I think might be the best of both worlds.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Good catch!! That's a wild edge case, I guess I would have expected it to return I suppose |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
@archmoj Updated — I added |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| .replace(UNICODE_REPLACEMENT_CHAR_REGEX, '') // Drop Unicode replacement chars left by previous step | ||
| .replace(HTML_TAGS_REGEX, ' ') // Remove < > tags, such as <br> (replace with space) | ||
| .replace(FORBIDDEN_CHARS_REGEX, '') // Remove forbidden filename characters | ||
| .toLowerCase() // Lowercase everything |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about lowering the case.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm going to keep the lowercasing for now, since it's consistent with the lowercasing in newplot.png and also matches the way most URLs are lowercased. However open to changing it in the future depending on feedback.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Cameron DeCoster <[email protected]>
…icode classes) from filenames
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I made one small suggestion, but feel free to ignore it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Cameron DeCoster <[email protected]>
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.