יחידה:גרפים: הבדלים בין גרסאות בדף
RTL |
מ 41 גרסאות של הדף wikipedia:he:יחידה:גרפים יובאו |
||
| (36 גרסאות ביניים של 5 משתמשים אינן מוצגות) | |||
| שורה 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 | ||
| שורה 25: | שורה 25: | ||
radius = 'רדיוס', | radius = 'רדיוס', | ||
percent = 'אחוזים', | percent = 'אחוזים', | ||
xrotation = 'סיבוב כותרות', | |||
valueInBar = 'הצגת הערך בעמודה', | |||
} -- here is what you want to translate | } -- here is what you want to translate | ||
| שורה 66: | שורה 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' ) | ||
) | ) | ||
| שורה 98: | שורה 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 '' | ||
links[i] = link | links[i] = link | ||
| שורה 125: | שורה 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 | ||
| שורה 216: | שורה 219: | ||
local values, xlegends, colors, tooltips, yscales = {}, {}, {}, {} ,{}, {}, {} | local values, xlegends, colors, tooltips, yscales = {}, {}, {}, {} ,{}, {}, {} | ||
local groupNames, unitsSuffix, unitsPrefix, links = {}, {}, {}, {} | local groupNames, unitsSuffix, unitsPrefix, links = {}, {}, {}, {} | ||
local width, height, stack, delimiter = 500, 350, false, args[keywords.delimiter] or ':' | local width, height, stack, delimiter, xrotation = 500, 350, false, args[keywords.delimiter] or ':' | ||
local chartWidth, chartHeight, defcolor, scalePerGroup | local chartWidth, chartHeight, defcolor, scalePerGroup | ||
local valueInBar = args[keywords.valueInBar] | |||
| שורה 224: | שורה 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] ) | ||
| שורה 231: | שורה 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') | ||
| שורה 244: | שורה 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 | ||
| שורה 257: | שורה 262: | ||
if #values[gi] ~= numValues then error( keywords.group .. " " .. gi .. " does not have same number of values as " .. keywords.group .. " 1" ) end | if #values[gi] ~= numValues then error( keywords.group .. " " .. gi .. " does not have same number of values as " .. keywords.group .. " 1" ) end | ||
end | end | ||
if #xlegends ~= numValues then error( 'Illegal number of ' .. keywords.xlegend .. '. Should be | if #xlegends ~= numValues then error( 'Illegal number of ' .. keywords.xlegend .. '. Should be exactly ' .. numValues .. | ||
'\n' .. '(param="' .. args[keywords.xlegend] .. '")') end | |||
end | end | ||
| שורה 286: | שורה 292: | ||
elseif k == keywords.scalePerGroup then scalePerGroup = true | elseif k == keywords.scalePerGroup then scalePerGroup = true | ||
elseif k == keywords.defcolor then defcolor = v | elseif k == keywords.defcolor then defcolor = v | ||
elseif k == keywords.xrotation then xrotation = true | |||
else | else | ||
for keyword, tab in pairs( { | for keyword, tab in pairs( { | ||
| שורה 308: | שורה 315: | ||
local ordermag = 10 ^ math.floor( math.log10( x ) ) | local ordermag = 10 ^ math.floor( math.log10( x ) ) | ||
local normalized = x / ordermag | local normalized = x / ordermag | ||
local top = normalized >= | local top = normalized >= 2.5 and ( math.floor( normalized + 1 ) ) | ||
or normalized >= 2 and 2.5 | |||
or normalized >= 1.5 and 2 | |||
or 1.5 | |||
return ordermag * top, top, ordermag | return ordermag * top, top, ordermag | ||
end | end | ||
| שורה 368: | שורה 378: | ||
local left, barWidth = calcx( gi, i ) | local left, barWidth = calcx( gi, i ) | ||
local barHeight, top = calcHeights( gi, i, val ) | local barHeight, top = calcHeights( gi, i, val ) | ||
local style = string.format("position:absolute;left:%spx;top:%spx;height:%spx;min-width:%spx;max-width:%spx;background-color:%s;box-shadow:2px -1px 4px 0 silver;overflow:hidden;", | local style = string.format("position:absolute;left:%spx;top:%spx;height:%spx;min-width:%spx;max-width:%spx;background-color:%s;box-shadow:2px -1px 4px 0 silver;overflow:hidden;text-align:center;line-height:%spx", | ||
left, top, barHeight, barWidth, barWidth, color) | left, top, barHeight, barWidth, barWidth, color, barHeight) | ||
local link = links[gi] and links[gi][i] or '' | local link = links[gi] and links[gi][i] or '' | ||
local img = not nulOrWhitespace( link ) and mw.ustring.format( '[[File:Transparent.png|1000px|link=%s|%s]]', link, custom and tooltip or '' ) or '' | local img = not nulOrWhitespace( link ) and mw.ustring.format( '[[File:Transparent.png|1000px|link=%s|%s]]', link, custom and tooltip or '' ) or '' | ||
table.insert( res, mw.text.tag( 'div', { style = style, title = tooltip, }, img ) ) | table.insert( res, mw.text.tag( 'div', { style = style, title = tooltip, }, img .. (valueInBar and val or '' ) ) ) | ||
end | end | ||
| שורה 381: | שורה 391: | ||
local _, top, ordermag = roundup( yscale * 0.999 ) | local _, top, ordermag = roundup( yscale * 0.999 ) | ||
local numnotches = top <= 1.5 and top * 4 | local numnotches = top <= 1.5 and top * 4 | ||
or top < 4 and top * 2 | or top == 2.5 and 10 | ||
or top <= 4 and top * 2 | |||
or top | or top | ||
local valStyleStr = | local valStyleStr = | ||
| שורה 414: | שורה 425: | ||
function drawXlegends() | function drawXlegends() | ||
local setOffset, setWidth | local setOffset, setWidth | ||
local legendDivStyleFormat = "position:absolute;left:%spx;top: | local legendDivStyleFormat = "position:absolute;left:%spx;top:20px;min-width:%spx;max-width:%spx;text-align:center;veritical-align:top;padding:0 0.3em;" | ||
local tickDivstyleFormat = "position:absolute;left:%spx;height:10px;width:1px;border-left:1px solid black;" | local tickDivstyleFormat = "position:absolute;left:%spx;height:10px;width:1px;border-left:1px solid black;" | ||
for i = 1, numValues do | for i = 1, numValues do | ||
if not nulOrWhitespace( xlegends[i] ) then | if not nulOrWhitespace( xlegends[i] ) then | ||
setOffset, setWidth = groupBounds( i ) | setOffset, setWidth = groupBounds( i ) | ||
table.insert( res, mw.text.tag( 'div', | |||
table.insert( res, mw.text.tag( 'div', { style = string.format( legendDivStyleFormat, setOffset | { | ||
class = xrotation and 'rot90', -- assigning null to a key means "do not use this key" | |||
style = string.format( legendDivStyleFormat, setOffset, setWidth, setWidth ) | |||
}, xlegends[i] or '' ) | |||
) | |||
table.insert( res, mw.text.tag( 'div', { style = string.format( tickDivstyleFormat, setOffset + setWidth / 2 ) }, '' ) ) | table.insert( res, mw.text.tag( 'div', { style = string.format( tickDivstyleFormat, setOffset + setWidth / 2 ) }, '' ) ) | ||
end | end | ||
| שורה 429: | שורה 444: | ||
table.insert( res, mw.text.tag( 'div', { style = string.format( 'max-width:%spx;', width ) } ) ) | table.insert( res, mw.text.tag( 'div', { style = string.format( 'max-width:%spx;', width ) } ) ) | ||
table.insert( res, mw.text.tag( 'div', { style = string.format("position:relative;min-height:%spx;min-width:%spx;max-width:%spx;", height, width, width ) } ) ) | table.insert( res, mw.text.tag( 'div', { style = string.format("position:relative;min-height:%spx;min-width:%spx;max-width:%spx;", height, width, width ) } ) ) | ||
table.insert( res, mw.text.tag( 'div', { style = string.format(" | table.insert( res, mw.text.tag( 'div', { style = string.format("position:relative;top:0;left:0;min-height:%spx;min-width:%spx;max-width:%spx;border-left:1px black solid;border-bottom:1px black solid;", chartHeight, chartWidth, chartWidth ) } ) ) | ||
for gi, group in pairs( values ) do | for gi, group in pairs( values ) do | ||
for i, val in ipairs( group ) do | for i, val in ipairs( group ) do | ||
| שורה 438: | שורה 453: | ||
table.insert( res, '</div>' ) | table.insert( res, '</div>' ) | ||
table.insert( res, mw.text.tag( 'div', { style = string.format("position:absolute;left:-4px;height:%spx;min-width:%spx;max-width:%spx;", chartHeight, scaleWidth, scaleWidth, scaleWidth ) } ) ) | table.insert( res, mw.text.tag( 'div', { style = string.format("position:absolute;top:0;left:-4px;height:%spx;min-width:%spx;max-width:%spx;", chartHeight, scaleWidth, scaleWidth, scaleWidth ) } ) ) | ||
drawYScale() | drawYScale() | ||
table.insert( res, '</div>' ) | table.insert( res, '</div>' ) | ||
| שורה 445: | שורה 460: | ||
drawXlegends() | drawXlegends() | ||
table.insert( res, '</div>' ) | table.insert( res, '</div>' ) | ||
table.insert( res, '</div>' ) | |||
createGroupList( res, groupNames, colors ) | createGroupList( res, groupNames, colors ) | ||
table.insert( res, '</div>' ) | table.insert( res, '</div>' ) | ||
end | end | ||
| שורה 464: | שורה 477: | ||
[keywords.pieChart] = pieChart, | [keywords.pieChart] = pieChart, | ||
} | } | ||
--</ | --</syntaxhighlight> | ||