@@ -10,7 +10,6 @@ local Lua = require('Module:Lua')
1010local Array = Lua .import (' Module:Array' )
1111local DateExt = Lua .import (' Module:Date/Ext' )
1212local Character = Lua .import (' Module:Character' )
13- local Class = Lua .import (' Module:Class' )
1413local Logic = Lua .import (' Module:Logic' )
1514local Operator = Lua .import (' Module:Operator' )
1615
@@ -22,13 +21,20 @@ local BooleanOperator = Condition.BooleanOperator
2221local ColumnName = Condition .ColumnName
2322local ConditionUtil = Condition .Util
2423
25- local Widget = Lua .import (' Module:Widget' )
2624local CharacterStatsTable = Lua .import (' Module:Widget/CharacterStats/Table' )
27- local DataTable = Lua .import (' Module:Widget/Basic/DataTable ' )
25+ local Component = Lua .import (' Module:Widget/Component ' )
2826local Html = Lua .import (' Module:Widget/Html' )
2927local IconImage = Lua .import (' Module:Widget/Image/Icon/Image' )
28+ local TableWidgets = Lua .import (' Module:Widget/Table2/All' )
3029local WidgetUtil = Lua .import (' Module:Widget/Util' )
3130
31+ local Helpers = {}
32+
33+ --- @class CharacterStatsData
34+ --- @field name string
35+ --- @field bans integer
36+ --- @field total table<string , integer>
37+
3238--- @class CharacterStatsWidgetProps
3339--- @field characterSize string
3440--- @field characterType string
@@ -40,83 +46,87 @@ local WidgetUtil = Lua.import('Module:Widget/Util')
4046--- @field sideWins table<string , integer>
4147--- @field statspage string
4248
43- --- @class CharacterStatsWidget : Widget
44- --- @operator call (CharacterStatsWidgetProps ): CharacterStatsWidget
45- --- @field props CharacterStatsWidgetProps
46- local CharacterStatsWidget = Class .new (Widget )
47- CharacterStatsWidget .defaultProps = {
49+ local defaultProps = {
4850 characterSize = ' 25x25px' ,
4951 includeGlobalBans = false ,
5052 numGames = 0 ,
5153 statspage = mw .title .getCurrentTitle ().prefixedText
5254}
5355
54- --- @return Widget[] ?
55- function CharacterStatsWidget :render ()
56- local data = self .props .data
56+ --- @param props CharacterStatsWidgetProps
57+ --- @return Renderable[] ?
58+ local function CharacterStatsWidget (props )
59+ local data = props .data
5760 if Logic .isEmpty (data ) then
5861 return
5962 end
60- local showExtraStats = self . props .statspage == mw .title .getCurrentTitle ().prefixedText
63+ local showExtraStats = props .statspage == mw .title .getCurrentTitle ().prefixedText
6164 return WidgetUtil .collect (
62- CharacterStatsTable (self . props ),
65+ CharacterStatsTable (props ),
6366 showExtraStats and WidgetUtil .collect (
64- self : _displayUnpickedCharacters (),
65- self . props .includeBans and {
66- self : _displayUnbannedCharacters (),
67- self : _displayUnpickedAndUnbannedCharacters (),
68- }
67+ Helpers . _displayUnpickedCharacters (props ),
68+ props .includeBans and {
69+ Helpers . _displayUnbannedCharacters (props ),
70+ Helpers . _displayUnpickedAndUnbannedCharacters (props ),
71+ } or nil
6972 ) or nil
7073 )
7174end
7275
7376--- @private
74- --- @return Widget ?
75- function CharacterStatsWidget :_displayUnpickedCharacters ()
77+ --- @param props CharacterStatsWidgetProps
78+ --- @return Renderable ?
79+ function Helpers ._displayUnpickedCharacters (props )
7680 --- @type string[]
7781 local playedCharacters = Array .map (
78- Array .filter (self .props .data , function (dataEntry )
82+ Array .filter (props .data , function (dataEntry )
83+ --- @cast dataEntry CharacterStatsData
7984 return dataEntry .total .pick > 0
8085 end ),
8186 Operator .property (' name' )
8287 )
8388
84- return self : _buildUnchosenCharactersTable (' Unpicked' , playedCharacters )
89+ return Helpers . _buildUnchosenCharactersTable (' Unpicked' , playedCharacters , props )
8590end
8691
8792--- @private
88- --- @return Widget ?
89- function CharacterStatsWidget :_displayUnbannedCharacters ()
93+ --- @param props CharacterStatsWidgetProps
94+ --- @return Renderable ?
95+ function Helpers ._displayUnbannedCharacters (props )
9096 --- @type string[]
9197 local bannedCharacters = Array .map (
92- Array .filter (self .props .data , function (dataEntry )
98+ Array .filter (props .data , function (dataEntry )
99+ --- @cast dataEntry CharacterStatsData
93100 return dataEntry .bans > 0
94101 end ),
95102 Operator .property (' name' )
96103 )
97104
98- return self : _buildUnchosenCharactersTable (' Unbanned' , bannedCharacters )
105+ return Helpers . _buildUnchosenCharactersTable (' Unbanned' , bannedCharacters , props )
99106end
100107
101108--- @private
102- --- @return Widget ?
103- function CharacterStatsWidget :_displayUnpickedAndUnbannedCharacters ()
109+ --- @param props CharacterStatsWidgetProps
110+ --- @return Renderable ?
111+ function Helpers ._displayUnpickedAndUnbannedCharacters (props )
104112 --- @type string[]
105113 local playedCharacters = Array .map (
106- Array .filter (self .props .data , function (dataEntry )
114+ Array .filter (props .data , function (dataEntry )
115+ --- @cast dataEntry CharacterStatsData
107116 return dataEntry .total .pick > 0 or dataEntry .bans > 0
108117 end ),
109118 Operator .property (' name' )
110119 )
111120
112- return self : _buildUnchosenCharactersTable (' Unpicked & Unbanned' , playedCharacters )
121+ return Helpers . _buildUnchosenCharactersTable (' Unpicked & Unbanned' , playedCharacters , props )
113122end
114123
115124--- @private
116125--- @param titlePrefix string
117126--- @param excludedCharacters string[]
118- --- @return Widget ?
119- function CharacterStatsWidget :_buildUnchosenCharactersTable (titlePrefix , excludedCharacters )
127+ --- @param props CharacterStatsWidgetProps
128+ --- @return Renderable ?
129+ function Helpers ._buildUnchosenCharactersTable (titlePrefix , excludedCharacters , props )
120130 local conditions = ConditionTree (BooleanOperator .all ):add {
121131 ConditionNode (ColumnName (' date' ), Comparator .le , DateExt .getContextualDateOrNow ()),
122132 ConditionUtil .noneOf (ColumnName (' name' ), excludedCharacters )
@@ -127,23 +137,34 @@ function CharacterStatsWidget:_buildUnchosenCharactersTable(titlePrefix, exclude
127137 if Logic .isEmpty (characters ) then
128138 return
129139 end
130- return DataTable {
131- children = {
132- Html .Tr {children = Html .Th {
133- children = {titlePrefix .. ' ' .. self .props .characterType , ' ' , Html .I {children = {' (' , # characters , ' )' }}
134- }}},
135- Html .Tr {children = Html .Td {
136- children = Array .map (characters , function (character )
137- return IconImage {
138- imageLight = character .iconLight ,
139- imageDark = character .iconDark ,
140- link = character .pageName ,
141- size = self .props .characterSize ,
140+ return TableWidgets .Table {
141+ columns = {{}},
142+ children = WidgetUtil .collect (
143+ TableWidgets .TableHeader {
144+ children = TableWidgets .Row {
145+ children = TableWidgets .CellHeader {
146+ align = ' center' ,
147+ children = {titlePrefix .. ' ' .. props .characterType , ' ' , Html .I {children = {' (' , # characters , ' )' }}}
142148 }
143- end )
144- }}
145- }
149+ }
150+ },
151+ TableWidgets .TableBody {
152+ children = TableWidgets .Row {
153+ children = TableWidgets .Cell {
154+ css = {[' white-space' ] = ' normal' }, -- so it will wrap
155+ children = Array .map (characters , function (character )
156+ return IconImage {
157+ imageLight = character .iconLight ,
158+ imageDark = character .iconDark ,
159+ link = character .pageName ,
160+ size = props .characterSize ,
161+ }
162+ end )
163+ }
164+ }
165+ }
166+ )
146167 }
147168end
148169
149- return CharacterStatsWidget
170+ return Component . component ( CharacterStatsWidget , defaultProps )
0 commit comments