יחידה:גרפים: הבדלים בין גרסאות בדף

ניסוי
מ 41 גרסאות של הדף wikipedia:he:יחידה:גרפים יובאו
 
(18 גרסאות ביניים של 4 משתמשים אינן מוצגות)
שורה 1: שורה 1:
--<source lang=lua>
--<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;box-shadow:2px -1px 4px 0 silver;margin-right:1em;"
         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] ) }, '&nbsp;' ) .. ' '..  legends[gi]
             local span = mw.text.tag( 'span', { style = string.format( spanStyle, cols[gi], cols[gi] ) }, '&nbsp;' ) .. ' '..  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", first item("%s") could not be parsed as a number', i, value or '', sliceStr ) )
                 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 defcolor
         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, 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
שורה 423: שורה 425:
     function drawXlegends()
     function drawXlegends()
         local setOffset, setWidth
         local setOffset, setWidth
        local rotationTransform = xrotation and '-webkit-transform:rotate(90deg);-moz-transform:rotate(90deg);'..
         local legendDivStyleFormat = "position:absolute;left:%spx;top:20px;min-width:%spx;max-width:%spx;text-align:center;veritical-align:top;padding:0 0.3em;"
            '-ms-transform:rotate(90deg);-o-transform:rotate(%sdeg);transform:rotate(90deg)'
            or ''
         local legendDivStyleFormat = "position:absolute;left:%spx;top:20px;min-width:%spx;max-width:%spx;text-align:center;veritical-align:top;%s"
         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 )
                -- setWidth = 0.85 * setWidth
                 table.insert( res, mw.text.tag( 'div',  
                 table.insert( res, mw.text.tag( 'div', { style = string.format( legendDivStyleFormat, setOffset, setWidth - 10, setWidth - 10,  rotationTransform ) }, xlegends[i] or '' ) )
                    {  
                        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
שורה 474: שורה 477:
     [keywords.pieChart] = pieChart,
     [keywords.pieChart] = pieChart,
}
}
--</source>
--</syntaxhighlight>