Jump to content

Modding:Mod compatibility/barchart: Difference between revisions

From Stardew Valley Wiki
imported>Pathoschild
tweak format, update script
imported>Pathoschild
calculate percentages in template for more informative diffs on the main page
Line 1: Line 1:
{| class="wikitable"
{| class="wikitable"
|-
|-
| <div style="display: inline-block; width: {{#expr:({{{ok|0}}} + {{{workaround|0}}}) * 2}}px; background: #9F9;">&nbsp;</div>
| <div style="display: inline-block; width: {{#expr:(({{{ok|0}}} + {{{workaround|0}}}) / {{{total|<noinclude>1</noinclude>0}}}) * 2}}px; background: #9F9;">&nbsp;</div>
| {{#expr:{{{ok|0}}} + {{{workaround|0}}}}}% are compatible or have a working alternative.
| {{#expr:(({{{ok|0}}} + {{{workaround|0}}}) / {{{total|<noinclude>1</noinclude>0}}}) * 100 round 0}}% are compatible or have a working alternative.
|-
|-
| <div style="display: inline-block; width: {{#expr:{{{soon|0}}} * 2}}px; background: #FF9;">&nbsp;</div>
| <div style="display: inline-block; width: {{#expr:({{{soon|0}}} / {{{total|<noinclude>1</noinclude>0}}}) * 2}}px; background: #FF9;">&nbsp;</div>
| {{{soon|0}}}% have an update coming soon.
| {{#expr:({{{soon|0}}} / {{{total|<noinclude>1</noinclude>0}}}) * 100 round 0}}% have an update coming soon.
|-
|-
| <div style="display: inline-block; width: {{#expr:{{{broken|0}}} * 2}}px; background: #F99;">&nbsp;</div>
| <div style="display: inline-block; width: {{#expr:({{{broken|0}}} / {{{total|<noinclude>1</noinclude>0}}}) * 2}}px; background: #F99;">&nbsp;</div>
| {{{broken|0}}}% are broken and not open-source.¹
| {{#expr:({{{broken|0}}} / {{{total|<noinclude>1</noinclude>0}}}) * 100 round 0}}% are broken and not open-source.¹
|}
|}
<small>¹ Many of these broke in Stardew Valley 1.1 or 1.2. Some may be updated by their authors.</small><noinclude>
<small>¹ Many of these broke in Stardew Valley 1.1 or 1.2. Some may be updated by their authors.</small><noinclude>


==Usage==
==Usage==
List the percentage values for each group:
List the counts for each group:
<pre>
<pre>
{{/barchart
{{/barchart
   |ok        = 52
   |ok        = 135
   |workaround = 23
   |workaround = 33
   |soon      = 10
   |soon      = 56
   |broken    = 15
   |broken    = 33
  |total      = 257
}}
}}
</pre>
</pre>
Line 26: Line 27:
This tiny script generates the template call when run from the parent page.
This tiny script generates the template call when run from the parent page.
<source lang="javascript">
<source lang="javascript">
var ok = $("#mod-list tr[data-status='ok']").length;
var entries = $("#mod-list tr[data-status]");
var workaround = $("#mod-list tr[data-status='workaround']").length;
var ok = entries.filter("[data-status='ok']").length;
var soon = $("#mod-list tr[data-status='soon']").length;
var workaround = entries.filter("[data-status='workaround'], [data-status='obsolete']").length;
var broken = $("#mod-list tr[data-status='broken']").length;
var soon = entries.filter("[data-status='soon'], [data-status='soon-official']").length;
var broken = entries.filter("[data-status='broken']").length;
var total = ok + workaround + soon + broken;


var total = ok + workaround + soon + broken;
if (total != entries.length)
var okPercent = Math.round(ok / total * 100);
  throw 'found entries with unknown status.';
var workaroundPercent = Math.round(workaround / total * 100);
var soonPercent = Math.round(soon / total * 100);
var brokenPercent = Math.round(broken / total * 100);


`
`
{{/barchart
{{/barchart
   |ok        = ${okPercent}
   |ok        = ${ok}
   |workaround = ${workaroundPercent}
   |workaround = ${workaround}
   |soon      = ${soonPercent}
   |soon      = ${soon}
   |broken    = ${brokenPercent}
   |broken    = ${broken}
  |total      = ${total}
}}
}}
`
`

Revision as of 03:08, 20 July 2017

 
0% are compatible or have a working alternative.
 
0% have an update coming soon.
 
0% are broken and not open-source.¹

¹ Many of these broke in Stardew Valley 1.1 or 1.2. Some may be updated by their authors.

Usage

List the counts for each group:

{{/barchart
  |ok         = 135
  |workaround = 33
  |soon       = 56
  |broken     = 33
  |total      = 257
}}

Script

This tiny script generates the template call when run from the parent page.

var entries = $("#mod-list tr[data-status]");
var ok = entries.filter("[data-status='ok']").length;
var workaround = entries.filter("[data-status='workaround'], [data-status='obsolete']").length;
var soon = entries.filter("[data-status='soon'], [data-status='soon-official']").length;
var broken = entries.filter("[data-status='broken']").length;
var total = ok + workaround + soon + broken;

if (total != entries.length)
   throw 'found entries with unknown status.';

`
{{/barchart
  |ok         = ${ok}
  |workaround = ${workaround}
  |soon       = ${soon}
  |broken     = ${broken}
  |total      = ${total}
}}
`