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

אין תקציר עריכה
מ 41 גרסאות של הדף wikipedia:he:יחידה:גרפים יובאו
 
(25 גרסאות ביניים של 5 משתמשים אינן מוצגות)
שורה 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
שורה 25: שורה 25:
     radius = 'רדיוס',
     radius = 'רדיוס',
     percent = 'אחוזים',
     percent = 'אחוזים',
    xrotation = 'סיבוב כותרות',
     valueInBar = 'הצגת הערך בעמודה',
     valueInBar = 'הצגת הערך בעמודה',


שורה 67: שורה 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' )
             )
             )
שורה 99: שורה 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 ''
שורה 126: שורה 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
שורה 217: שורה 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]
     local valueInBar = args[keywords.valueInBar]
שורה 226: שורה 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] )
שורה 233: שורה 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')
שורה 246: שורה 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
שורה 289: שורה 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( {
שורה 421: שורה 425:
     function drawXlegends()
     function drawXlegends()
         local setOffset, setWidth
         local setOffset, setWidth
         local legendDivStyleFormat = "position:absolute;left:%spx;top:10px;min-width:%spx;max-width:%spx;text-align:center;veritical-align: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 )
                -- setWidth = 0.85 * setWidth
                 table.insert( res, mw.text.tag( 'div',  
                 table.insert( res, mw.text.tag( 'div', { style = string.format( legendDivStyleFormat, setOffset - 5, setWidth - 10, setWidth - 10 ) }, 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
שורה 436: שורה 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("float:right;position:relative;min-height:%spx;min-width:%spx;max-width:%spx;border-left:1px black solid;border-bottom:1px black solid;", chartHeight, chartWidth, chartWidth ) } ) )
         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
שורה 445: שורה 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>' )
שורה 469: שורה 477:
     [keywords.pieChart] = pieChart,
     [keywords.pieChart] = pieChart,
}
}
--</source>
--</syntaxhighlight>