Skip to content

Commit 8dccfbd

Browse files
committed
Thêm các mô đun nhỏ
1 parent 5a512ae commit 8dccfbd

3 files changed

Lines changed: 217 additions & 0 deletions

File tree

Other/Gaps.lua

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
local p = {}
2+
3+
local getArgs
4+
5+
function p.main(frame)
6+
if not getArgs then
7+
getArgs = require('Mô đun:Arguments').getArgs
8+
end
9+
local args = getArgs(frame, {wrappers = 'Bản mẫu:Gaps'})
10+
11+
local ret = mw.html.create('span')
12+
:css({['white-space'] = 'nowrap',
13+
['font-size'] = args.size})
14+
15+
if args.lhs then
16+
ret:wikitext(args.lhs .. ' = ')
17+
end
18+
19+
local gap = string.lower(args.gap or '')
20+
21+
local gapSize, gapUnit = string.match(gap,'([%d%.]+)%s*([ep][mnx])')
22+
23+
local acceptedUnits = { em = 'em', en = 'en', px = 'px' }
24+
25+
gapUnit = acceptedUnits[gapUnit]
26+
27+
if gapSize and gapUnit then
28+
gap = gapSize..gapUnit
29+
else
30+
gap = '0.25em'
31+
end
32+
33+
for k,v in ipairs(args) do
34+
if k == 1 then
35+
ret:wikitext(v)
36+
else
37+
ret:tag('span')
38+
:css('margin-left',gap)
39+
:wikitext(v)
40+
end
41+
end
42+
43+
if args.e then
44+
ret
45+
:tag('span')
46+
:css({['margin-left'] = '0.27em',
47+
['margin-right']= '0.27em'})
48+
:wikitext('×')
49+
:done()
50+
:wikitext(args.base or '10')
51+
:tag('span')
52+
:css('display','none')
53+
:wikitext('^')
54+
:done()
55+
:tag('sup')
56+
-- the double parentheses here are not redundant.
57+
-- they keep the second return value from being passed
58+
:wikitext((mw.ustring.gsub(args.e,'-','')))
59+
:done()
60+
end
61+
62+
if args.u then
63+
ret:wikitext(' ' .. args.u)
64+
end
65+
66+
return ret
67+
end
68+
69+
return p

Other/RadarGraph.lua

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
local a = require('Module:ACandy').a
2+
local getArgs = require('Module:Arguments').getArgs
3+
4+
local p = {}
5+
6+
local function deg2rad(d) return d * math.pi / 180 end
7+
8+
local function makeRings(max)
9+
local step = 50 / max
10+
local parts = {}
11+
for i = 1, max do
12+
local pct = i * step
13+
local style = "radial-gradient(circle at center, rgba(127,127,127,0.1) %.2f%%, rgba(0,0,0,0) %.2f%%)"
14+
table.insert(parts, string.format(style, pct-0.3, pct+0.3))
15+
end
16+
return table.concat(parts, ",")
17+
end
18+
19+
function p.main(frame)
20+
local args = getArgs(frame, {removeBlanks = true})
21+
local maxValue = tonumber(args.max) or 5
22+
local width = args.width or "500px"
23+
24+
local names, values = {}, {}
25+
for _, arg in ipairs(args) do
26+
local i, _ = string.find(arg, "::");
27+
local key, value;
28+
if i then
29+
key = string.sub(arg, 1, i - 1);
30+
value = string.sub(arg, i + 2);
31+
local num = tonumber(value)
32+
if num then
33+
table.insert(names, key)
34+
table.insert(values, num)
35+
end
36+
end
37+
end
38+
39+
local n = #names
40+
if n < 3 then
41+
return 'Error: Need at least 3 axes.'
42+
end
43+
44+
local maxR, center = 35, 50 -- percentages
45+
local points, markers, labels, spokes = {}, {}, {}, {}
46+
47+
for i=1,n do
48+
-- Ensure there is always one angled to point to the top
49+
local angle = - 90 - (i-1) * (360/n)
50+
local r = (values[i] / maxValue) * maxR
51+
local x = center + r * math.cos(deg2rad(angle))
52+
local y = center + r * math.sin(deg2rad(angle))
53+
table.insert(points, string.format('%.3f%% %.3f%%', x, y))
54+
55+
-- marker
56+
table.insert(markers, a.div {
57+
style = string.format(
58+
'position:absolute;left:%.3f%%;top:%.3f%%;' ..
59+
'width:2%%;height:2%%;margin:-1%% 0 0 -1%%;' ..
60+
'border-radius:50%%;background:#377dff;border:0.6%% solid #fff',
61+
x, y
62+
)
63+
})
64+
65+
-- label (slightly beyond maxR)
66+
-- X-axis needs to be further away since text spans horizontally
67+
local lx = center + maxR * 1.3 * math.cos(deg2rad(angle))
68+
local ly = center + maxR * 1.2 * math.sin(deg2rad(angle))
69+
table.insert(labels, a.div {
70+
style = string.format(
71+
'position:absolute;left:%.3f%%;top:%.3f%%;' ..
72+
'transform:translate(-50%%,-50%%);' ..
73+
'font-size: larger',
74+
lx, ly
75+
),
76+
names[i]
77+
})
78+
79+
-- spoke
80+
table.insert(spokes, a.div {
81+
style = string.format(
82+
'position:absolute;left:50%%;top:50%%;' ..
83+
'width:0.6%%;height:%d%%;background:#cfcfcf;' ..
84+
'transform-origin:50%% 0%%;transform:translateX(-50%%) rotate(%.1fdeg);',
85+
maxR, - angle + 90
86+
)
87+
})
88+
end
89+
90+
-- polygon fill
91+
local poly = a.div {
92+
style = string.format(
93+
'position:absolute;left:0;top:0;width:100%%;height:100%%;' ..
94+
'clip-path:polygon(%s);' ..
95+
'background:linear-gradient(135deg,rgba(55,125,255,0.28),rgba(55,125,255,0.18));' ..
96+
'border:0.6%% solid rgba(55,125,255,0.5);border-radius:2%%;',
97+
table.concat(points, ',')
98+
)
99+
}
100+
101+
local rings = makeRings(maxValue);
102+
103+
return a.div {
104+
style = string.format(
105+
'width:%s;max-width:100%%;position:relative;' ..
106+
'aspect-ratio : 1 / 1;' ..
107+
'background: %s; ' ..
108+
'border-radius:2%%;box-shadow:0 0.3%% 0.6%% rgba(0,0,0,0.06);',
109+
width, rings
110+
),
111+
-- center dot
112+
a.div { style = 'position:absolute;left:50%;top:50%;width:1.8%;height:1.8%;margin:-0.9% 0 0 -0.9%;border-radius:50%;background:#666;opacity:0.8' },
113+
-- spokes, labels, polygon, markers
114+
spokes,
115+
labels,
116+
poly,
117+
markers
118+
};
119+
end
120+
121+
return p

Other/Seplist.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--[[
2+
Module to implement an unordered list with a generalised separator.
3+
Use TemplateStyles with an associated template to style the list.
4+
It will recognise "hr" as the horizontal rule.
5+
--]]
6+
7+
p = {}
8+
9+
p.makelist = function(frame)
10+
local args = frame.args
11+
if not args[1] then
12+
args = frame:getParent().args
13+
if not args[1] then return end
14+
end
15+
local sep = (args.sep or "")
16+
if sep == "hr" then sep = "<hr>" end
17+
local out = {}
18+
for k, v in ipairs(args) do
19+
v = mw.text.trim(v)
20+
table.insert(out, "<li>" .. v .. "</li>")
21+
end
22+
if #out > 0 then
23+
return '<ul class="seplist">' .. table.concat(out, sep) .. '</ul>'
24+
end
25+
end
26+
27+
return p

0 commit comments

Comments
 (0)