Module talk:Piechart
Option not to sum to 100 percent
Would be nice to have an "other" chunk that isn't mentioned in the legend. Wizmut (talk) 22:00, 4 February 2024 (UTC)
- @Wizmut You can see an example for "other" here: Template:Latest pie chart of world power by source. Though this only makes sense if you have percentages as values. It might be a bit harder to update charts this way. Depends on whether the source has percentages or absolute values. Nux (talk) 02:50, 24 January 2025 (UTC)
- I'm not sure how this example applies. The other chunk is mentioned in the legend, the opposite of what I asked for. Wizmut (talk) 03:36, 24 January 2025 (UTC)
- @Wizmut, for better accessibility, any value in the pie chart should be in the legend. I think the linked example is rendering correctly, Rjjiii (talk) 07:45, 25 January 2025 (UTC)
- I'm not sure how this example applies. The other chunk is mentioned in the legend, the opposite of what I asked for. Wizmut (talk) 03:36, 24 January 2025 (UTC)
Combining with Template:Pie chart
This has some advantages over {{Pie chart}} (tooltips, calculates percentages, no crosshair glitches). I've been tinkering with using the template's pie chart as a replacement for the one in {{Pie chart}}. There are a bunch of demos of {{Pie chart/sandbox2}} at Template:Pie chart/testcases. Nux, I have a few questions, is this something that you'd want to get wider usage or more a proof of concept. It's only transcluded to a handful of pages right now.
Also, the module should do something to sanitize user input for titles. A lot of people will place links there so the brackets ([ and ]) need to be checked for, and in case they use a piped link, it also needs to remove the pipe (|) and the wikilink target. Rjjiii (talk) 21:03, 22 January 2025 (UTC)
- Hi, yes this module can be used widely. I've added suport for links in labels and added an example here: Module:Piechart#Links. I think now in most cases you should be able to replace {{Pie chart}}, maybe even converting it automatically to the {{Piechart}}. Also added support for floating graphs in the template. Nux (talk) 02:45, 24 January 2025 (UTC)
- Fantastic! I checked the link out above and it looks clean. When you mention "converting it automatically" do you mean as a kind of wrapper template that could just feed the parameters from existing transclusions to {{Piechart}}? Rjjiii (talk) 08:48, 24 January 2025 (UTC)
- @Nux I've gone ahead and made sandbox copies for the module and template. I also started Template:Piechart/testcases and am checking for any bugs. If you look at "verbose", the colored bullets in the legend need "min-width" set somewhere. On mobile, the live template as a "thumb" moves to the left instead of the center. It looks like adding "display:flex" to "div.pie-thumb" should fix it (visible in the sandbox). Also, I tried applying the same styling to the caption as in Template:Pie chart. That template can likely be made into a wrapper for this one, Rjjiii (talk) 07:44, 25 January 2025 (UTC)
- @Rjjiii I've fixed the bullets. Added some more tests. Some of those tests don't work the same as on plwiki, but should be enough to keep things compatible. Nux (talk) 11:43, 26 January 2025 (UTC)
- Awesome! What do you think about centering the "thumb" charts on mobile, and styling the caption similar to {{pie chart}}? Also, what's different on plwiki? Rjjiii (talk) 19:49, 26 January 2025 (UTC)
- Personally I wouldn't want to use thumb at all (I've only added that option for compatibility). There are a few problems with that... Default layout of Wikipedia is now quite thin and obviously even thinner on mobile device (which is most of the audience of Wikipedia these days). So personally I think that doing floats is mostly a thing of the past. Charts like that should just be part of the hypertext, with images and media flowing along with text (which also means less problems with a long infobox pushing things down and outside of intended spot).
- Another problem is using styles from Wikipedia. Just now there were changes in structure of images. It's generally not advised to use them. So it's probably best to write CSS here: Template:Piechart/styles.css (not in the module). Nux (talk) 20:43, 26 January 2025 (UTC)
- I've moved styles over to Template:Piechart/sandbox/styles.css. Regarding, "
So personally I think that doing floats is mostly a thing of the past.
" yeah absolutely. I'm just trying to get the best backwards compatibility with {{Pie chart}}. In truth, I was surprised when you took the initiative to move the thumb feature into the module, but good surprised like getting a third thigh in a Popeye's two-piece. Those style changes are minor and shouldn't affect the non-thumb output. Also, before I start a discussion at {{Pie chart}} about converting that template, do you want to apply for template editor rights on en-wiki? Rjjiii (talk) 04:39, 28 January 2025 (UTC)- Thanks for the suggestion. Will apply in a minute. Nux (talk) 20:30, 29 January 2025 (UTC)
- Hi. Another user opened a discussion here: Wikipedia:Templates for discussion: Template:Piechart. Nux (talk) 23:26, 30 January 2025 (UTC)
- @Nux, that discussion has now closed as merge. I read the outline at Template:Pie chart/sandbox, and you seem to have this mostly planned out. I tested the sandbox template against the live template on some different browsers, screen sizes, dark mode, and so on. For all of the places where the rendering is different, this module seems to offer better readability (for example the outline color on the bullets changes in dark mode and the text does not become small/grey on mobile). I have been fixing the bogus parameters used in transclusions of the older, widely used template {{pie chart}}. When you get closer to merging, feel free to reach out for a hand with writing/updating documentation, testing anything, feedback, etc. So far, it's looking good, Rjjiii (talk) 02:39, 26 February 2025 (UTC)
- @Rjjiii hi, thanks for the ping and the offer to help. Even thought I've merged the template, there is still probably a lot of typos and inconsistencies in the docs. Please have a look Template:Pie chart/doc. Can you also double check everything? I think Template:Piechart can now be redirected to the Template:Pie chart. But there's some other stuff which maybe needs a redirect or removal... or merge? I guess maybe you could add more testcases at the end of Template:Pie chart/testcases? Nux (talk) 02:38, 27 February 2025 (UTC)
- I'll try to look over the /doc documentation soon.
- Yes, it makes sense to redirect Template:Piechart, and since the subpages all have a corresponding page in the merged template, I think they should probably all become redirects (Template:Piechart/sandbox→Template:Pie chart/sandbox and so on).
- By "add more testcases" do you mean merging over the examples on Template:Piechart/testcases or do you have something else in mind? Rjjiii (talk) 03:00, 27 February 2025 (UTC)
- @Rjjiii hi, thanks for the ping and the offer to help. Even thought I've merged the template, there is still probably a lot of typos and inconsistencies in the docs. Please have a look Template:Pie chart/doc. Can you also double check everything? I think Template:Piechart can now be redirected to the Template:Pie chart. But there's some other stuff which maybe needs a redirect or removal... or merge? I guess maybe you could add more testcases at the end of Template:Pie chart/testcases? Nux (talk) 02:38, 27 February 2025 (UTC)
- @Nux, that discussion has now closed as merge. I read the outline at Template:Pie chart/sandbox, and you seem to have this mostly planned out. I tested the sandbox template against the live template on some different browsers, screen sizes, dark mode, and so on. For all of the places where the rendering is different, this module seems to offer better readability (for example the outline color on the bullets changes in dark mode and the text does not become small/grey on mobile). I have been fixing the bogus parameters used in transclusions of the older, widely used template {{pie chart}}. When you get closer to merging, feel free to reach out for a hand with writing/updating documentation, testing anything, feedback, etc. So far, it's looking good, Rjjiii (talk) 02:39, 26 February 2025 (UTC)
- Hi. Another user opened a discussion here: Wikipedia:Templates for discussion: Template:Piechart. Nux (talk) 23:26, 30 January 2025 (UTC)
- Thanks for the suggestion. Will apply in a minute. Nux (talk) 20:30, 29 January 2025 (UTC)
- I've moved styles over to Template:Piechart/sandbox/styles.css. Regarding, "
- Awesome! What do you think about centering the "thumb" charts on mobile, and styling the caption similar to {{pie chart}}? Also, what's different on plwiki? Rjjiii (talk) 19:49, 26 January 2025 (UTC)
- @Rjjiii I've fixed the bullets. Added some more tests. Some of those tests don't work the same as on plwiki, but should be enough to keep things compatible. Nux (talk) 11:43, 26 January 2025 (UTC)
- @Nux I've gone ahead and made sandbox copies for the module and template. I also started Template:Piechart/testcases and am checking for any bugs. If you look at "verbose", the colored bullets in the legend need "min-width" set somewhere. On mobile, the live template as a "thumb" moves to the left instead of the center. It looks like adding "display:flex" to "div.pie-thumb" should fix it (visible in the sandbox). Also, I tried applying the same styling to the caption as in Template:Pie chart. That template can likely be made into a wrapper for this one, Rjjiii (talk) 07:44, 25 January 2025 (UTC)
- Fantastic! I checked the link out above and it looks clean. When you mention "converting it automatically" do you mean as a kind of wrapper template that could just feed the parameters from existing transclusions to {{Piechart}}? Rjjiii (talk) 08:48, 24 January 2025 (UTC)
- @Rjjiii yeah, I was thinking about merging test cases. You've created most of the proper test cases for the module IIRC, so I was thinking you might want to do the honours :). And also to be honest I'm not sure what are the procedures here on en.wiki. On pl.wiki we have a simpler structure and don't use sandboxes that much. Nux (talk) 09:06, 27 February 2025 (UTC)
Problems
It's great that there is a new module but I need to report that some articles are in Category:Pages with script errors due to recent changes. For example, Karwar#Demographics currently shows "Lua error: mw.text.jsonDecode: Syntax error." That may well be due to bad wikitext in the article, but it would be better if the module gave an error message. I started to have a look at what the issue might be but Module:Piechart needs some general work before looking any further. I will have a go at tweaking Module:Piechart/sandbox so whitespace and global variables match the general style (tabs for indents and no globals). Unfortunately that will generate a huge diff from the current module, but it has to be done sooner or later.
- Module:Piechart • Module:Piechart/sandbox • same content
Johnuniq (talk) 07:18, 27 February 2025 (UTC)
- I cleaned the whitespace and fixed the globals. The diff is already large and I'll leave my temporary fix (forward declarations) in the sandbox until this has been considered. Johnuniq (talk) 07:50, 27 February 2025 (UTC)
- Experiments show some wikitext that results in errors. Karwar#Demographics has
|right
and Template:Pie chart of New Zealand vineyard area by region has|thumb
. Perhaps they are invalid parameters or haven't been implemented? Zagatala District#Ethnic groups has some misplaced text as parameter 1. Johnuniq (talk) 08:23, 27 February 2025 (UTC)
- Experiments show some wikitext that results in errors. Karwar#Demographics has
- Not oppose to some cleanup, but please don't move functions inside other functions. That makes the code less readable for me and might also break some of my testing habits I use. I also don't see the point. Why would you want to redefine a function each time you call a method. Nux (talk) 09:23, 27 February 2025 (UTC)
- If you really must I would rather have all functions assigned to p as method instead of moving them inside. Nux (talk) 09:25, 27 February 2025 (UTC)
- Also I don't know why are you calling them globals. Those are local functions private to the module. I've just double checked if I didn't messed up something and you cannot even call
trim("a ")
. Lua error in console input at line 7: attempt to call global 'trim' (a nil value).
- So it's clearly not a global function. Otherwise I would be able to call it from the debug console. Nux (talk) 09:51, 27 February 2025 (UTC)