Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot title (and signature, sources). #92

Closed
Fil opened this issue Jan 11, 2021 · 13 comments · Fixed by #1761
Closed

Plot title (and signature, sources). #92

Fil opened this issue Jan 11, 2021 · 13 comments · Fixed by #1761
Labels
enhancement New feature or request

Comments

@Fil
Copy link
Contributor

Fil commented Jan 11, 2021

as part of legends

@Fil Fil mentioned this issue Jan 11, 2021
8 tasks
@mbostock mbostock added the enhancement New feature or request label Feb 24, 2021
@mbostock
Copy link
Member

This seems like a reasonable thing to include. I wonder if it should be called a “caption” rather than a “title”, and maybe we should use figure and figcaption to generate it if so.

@Fil
Copy link
Contributor Author

Fil commented Mar 4, 2021

Possible difficulties with figure/figcaption:

  • unexpected switch from svg to html (could be solved by always wrapping with figure)
  • html makes it harder to download the chart as svg/png in observable (and to post-process in Inkscape et al) [EDIT: it works!]
  • what would the {style: {}, background:…} options apply to? the svg or the figure?

If we use a figure though, it's tempting to use it also when we want a color legend (#23).

@mbostock
Copy link
Member

mbostock commented Mar 4, 2021

Exactly, I thought we might need HTML for color swatches anyway. Although I suppose it wouldn’t be the end of the world to layout the swatches manually by computing text metrics.

@ericemc3
Copy link

According to the usual rules of legibility, a chart should include an informative title, coming first (above the chart), possibly a subtitle, obligatorily a source, at the bottom of the chart, more optionally a copyright (which can also be arranged vertically, e.g. bottom right).

image

ggplot2 and vega-lite allow you to specify these essential elements, it would be very nice if Plot could as well.

The SVG export of the Plot should allow you to get the whole graphic, with titles and sources.

As vega-lite proposes, specifying a title as an array allows it to be spread over several lines.

The height specified for the graphic should not take these elements into account, but only the central body of the graphic.

@severo
Copy link

severo commented Aug 26, 2021

For whom is looking for how to add a title, see the caption option: #320 / https://github.com/observablehq/plot#layout-options

[edit] as mentioned by ericemc3, it's not necessarily a perfect solution, but at least it allows to embed the plot in a figure, with a figcaption element, without additional markup.

@ericemc3
Copy link

Caption, title, source... are different concepts. A title is what appears above a chart, a headline aiming at emphasizing the main takeaway, a caption is what typically appears below a photograph or a scientific diagram, a paragraph more like an explanation or a legend

@breck7
Copy link

breck7 commented Jul 14, 2022

Just another vote in support of title and subtitle support :). I would take @martgnz 's demo (#423) right now as it looks good enough and would unblock my need at PLDB. This is the one thing making it hard to build ready-to-share charts in Plot.

At Our World in Data the titles and subtitles are key, and the charts would be shared thousands of times less without them.

coronavirus-data-explorer

@kentr
Copy link
Contributor

kentr commented Feb 13, 2023

Have <title> and aria-labelledby been considered?

[Edit] Food for thought: Comparison of different patterns on smashingmagazine.com.

@Fil
Copy link
Contributor Author

Fil commented Feb 13, 2023

We haven't considered aria-labelledby for now, because it needs an associated element with a given id, which makes it a bit complicated to handle if we want to be able to have several charts on a single page (they're not supposed to share ids). But we'll definitely consider it if there is a clear use case. Not that this property is usually visible only to screen readers, so I seems to fall under a different category, and might need a separate issue?

@mbostock
Copy link
Member

I think maybe @kentr’s comment is regarding tooltips—which we already support via the title option; also note that we also already support ariaLabel and ariaDescription options. This issue is primarily regarding a visual title element, i.e., a heading above the chart.

@kentr
Copy link
Contributor

kentr commented Feb 14, 2023

@mbostock @Fil

My comment was regarding a title element for the whole SVG (not tooltips).

I envision markup like this:

<div id="svg-title">Daily new confirmed COVID-19 deaths per million people</div>
  <svg aria-labelledby="svg-title" ...>
    <g>
      ...
    </g>
</svg>

Originally, I didn't know that this issue was regarding a visual title, so I thought of <title> as a candidate for a non-visual title and aria-labelledby as a candidate for a visual title in an external element.

I'm thinking of explicitly connecting the "title" discussed in this issue to the SVG, for accessibility. For accessible titles, when there is already an element on the page that has the title text, MDN recommends connecting it to the SVG with aria-labelledby.

If an element can be described by visible text, it is recommended to reference that text with an aria-labelledby attribute rather than using the <title> element.

Plot supports aria-label, but if there's already a title element on the page, why not use that?

But the smashingmagazine.com article suggests that even with the aria-labelledby connection, adding a <title> element to the SVG is better for some browsers.

Using aria-labelledby does require a unique id attribute on the title element, but that seems doable. And having an aria-labelledby option lets the user provide their own value if they already have the title element on the page from something else (for example, when the plots are in a react app and there are already DOM elements with the SVG titles).

@Fil Fil mentioned this issue Jul 20, 2023
@maxlvhao
Copy link

frustrated by not able to add a proper title, i ended up cheating by using the following code
Plot.text(['Question: My university has a campus-wide generative AI (e.g. ChatGPT) policy for students.'], {frameAnchor: "Top",dy: -25}),

within my Marks:

I had to add marginTop:50 to make sure my title doesn't get cut off..

Screenshot 2023-07-21 at 8 38 53 AM

@maxlvhao
Copy link

maxlvhao commented Jul 21, 2023

frustrated by not able to add a proper title, i ended up cheating by using the following code Plot.text(['Question: My university has a campus-wide generative AI (e.g. ChatGPT) policy for students.'], {frameAnchor: "Top",dy: -25}),

within my Marks:

I had to add marginTop:50 to make sure my title doesn't get cut off..

Screenshot 2023-07-21 at 8 38 53 AM

after some more tweaks..
Screenshot 2023-07-21 at 8 47 49 AM
Screenshot 2023-07-21 at 8 49 14 AM

@Fil Fil closed this as completed in #1761 Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants