יחידה:גרפים: הבדלים בין גרסאות בדף
מ 41 גרסאות של הדף wikipedia:he:יחידה:גרפים יובאו |
|||
| (14 גרסאות ביניים של 4 משתמשים אינן מוצגות) | |||
| שורה 1: | שורה 1: | ||
--< | --<syntaxhighlight lang=lua> | ||
--[[ | --[[ | ||
keywords are used for languages: they are the names of the actual | keywords are used for languages: they are the names of the actual | ||
| שורה 68: | שורה 68: | ||
table.insert( tab, mw.text.tag( 'div' ) ) | table.insert( tab, mw.text.tag( 'div' ) ) | ||
local list = {} | local list = {} | ||
local spanStyle = "padding:0 1em;background-color:%s; | local spanStyle = "padding:0 1em;background-color:%s;border:1px solid %s;margin-right:1em;-webkit-print-color-adjust:exact;" | ||
for gi = 1, #legends do | for gi = 1, #legends do | ||
local span = mw.text.tag( 'span', { style = string.format( spanStyle, cols[gi] ) }, ' ' ) .. ' '.. legends[gi] | local span = mw.text.tag( 'span', { style = string.format( spanStyle, cols[gi], cols[gi] ) }, ' ' ) .. ' '.. legends[gi] | ||
table.insert( list, mw.text.tag( 'li', {}, span ) ) | table.insert( list, mw.text.tag( 'li', {}, span ) ) | ||
end | end | ||
table.insert( tab, | table.insert( tab, | ||
mw.text.tag( 'ul', | mw.text.tag( 'ul', | ||
{style="width:100%;list-style:none;-webkit-column-width:12em;-moz-column-width:12em;column-width:12em"}, | -- chrome bug with column display with rtl. {style="text-align:right;width:100%;list-style:none;-webkit-column-width:12em;-moz-column-width:12em;column-width:12em"}, | ||
{style="text-align:right;width:100%;list-style:none;-moz-column-width:12em;column-width:12em"}, | |||
table.concat( list, '\n' ) | table.concat( list, '\n' ) | ||
) | ) | ||
| שורה 100: | שורה 101: | ||
local value, name, color, link = unpack( mw.text.split( slice, '%s*' .. delimiter .. '%s*' ) ) | local value, name, color, link = unpack( mw.text.split( slice, '%s*' .. delimiter .. '%s*' ) ) | ||
values[i] = tonumber( lang:parseFormattedNumber( value ) ) | values[i] = tonumber( lang:parseFormattedNumber( value ) ) | ||
or error( string.format( 'Slice %d: "%s" | or error( string.format( 'Slice %d: \"%s\" could not be parsed as a number', i, value or '' ) ) | ||
colors[i] = not nulOrWhitespace( color ) and color or defColors[i] | colors[i] = not nulOrWhitespace( color ) and color or defColors[i] | ||
names[i] = name or '' | names[i] = name or '' | ||
| שורה 127: | שורה 128: | ||
local addprec = percent and string.format( ' (%0.1f%%)', value / sum * 100 ) or '' | local addprec = percent and string.format( ' (%0.1f%%)', value / sum * 100 ) or '' | ||
legends[i] = mw.ustring.format( '%s: %s%s%s%s', names[i], prefix, lang:formatNum( value ), suffix, addprec ) | legends[i] = mw.ustring.format( '%s: %s%s%s%s', names[i], prefix, lang:formatNum( value ), suffix, addprec ) | ||
links[i] = mw.text.trim( links[i] or mw.ustring.format( '[[#noSuchAnchor|%s]]', legends[i] ) ) | links[i] = mw.text.trim( links[i] or mw.ustring.format( '[[#noSuchAnchor|%s]]', mw.ustring.gsub( legends[i] or '', '[%[%]]', '' ) ) ) | ||
end | end | ||
end | end | ||
| שורה 227: | שורה 228: | ||
function validate() | function validate() | ||
function asGroups( name, tab, toDuplicate, emptyOK ) | function asGroups( name, tab, toDuplicate, emptyOK, defGroup ) | ||
if #tab == 0 and not emptyOK then | if #tab == 0 and not emptyOK then | ||
error( "must supply values for " .. keywords[name] ) | error( "must supply values for " .. keywords[name] ) | ||
| שורה 234: | שורה 235: | ||
for i = 2, numGroups do tab[i] = tab[1] end | for i = 2, numGroups do tab[i] = tab[1] end | ||
end | end | ||
if defGroup then for i = #tab + 1, numGroups do tab[i] = defGroup[i] end end | |||
if #tab > 0 and #tab ~= numGroups then | if #tab > 0 and #tab ~= numGroups then | ||
error ( keywords[name] .. ' should contain the same number of items as the number of groups (' .. numGroups .. '), but it has ' .. #tab .. ' items') | error ( keywords[name] .. ' should contain the same number of items as the number of groups (' .. numGroups .. '), but it has ' .. #tab .. ' items') | ||
| שורה 247: | שורה 249: | ||
numValues = #values[1] | numValues = #values[1] | ||
defcolor = defcolor or 'blue' | defcolor = defcolor or 'blue' | ||
colors[1] = colors[1] or | colors[1] = colors[1] or defColors[1] | ||
scaleWidth = scalePerGroup and 80 * numGroups or 100 | scaleWidth = scalePerGroup and 80 * numGroups or 100 | ||
chartWidth = width -scaleWidth | chartWidth = width -scaleWidth | ||
asGroups( 'unitsPrefix', unitsPrefix, true, true ) | asGroups( 'unitsPrefix', unitsPrefix, true, true ) | ||
asGroups( 'unitsSuffix', unitsSuffix, true, true ) | asGroups( 'unitsSuffix', unitsSuffix, true, true ) | ||
asGroups( 'colors', colors, true, | asGroups( 'colors', colors, false, true, defColors ) | ||
asGroups( 'groupNames', groupNames, false, false ) | asGroups( 'groupNames', groupNames, false, false ) | ||
if stack and scalePerGroup then | if stack and scalePerGroup then | ||
| שורה 475: | שורה 477: | ||
[keywords.pieChart] = pieChart, | [keywords.pieChart] = pieChart, | ||
} | } | ||
--</ | --</syntaxhighlight> | ||