Module:Sandbox/Con-struct (t)/Test1

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Lua

CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

All ...

Search ...

Test1

  • LineWidth2 
(frame)
  • GraphFill 
(frame)
  • SVGChart 
(frame)

Test1/standard

  • lenInteger 
(sValue)
  • lenDecimal 
(sValue)
  • min 
(d1, d2)
  • max 
(d1, d2)
  • sign 
(dValue)
  • round 
(dValue, iPrecision)
  • absDif 
(d1, d2, dDefault)

Test1/init

  • Size 
(dXMin, dXMax, dYMin, dYMax, dStretchX, dStretchY)
  • LineWidth 
(ChartSize, LineWidth, GraphStretchWidth, GraphStretchHeight)
  • ValueProcess1 
(sValue, dMin, dMax, iDotPos, iDigits, iFirst, iLast)
  • ChartValues 
(sValues)

Test1/svg

  • svgChartValuePair 
  • svgGraphLine 
  • svgGraphFill 
  • svgChartValues 

Test1/svg-legend

  • LegendBoxWidth 
(dChartSize, dFontSize, dLegendWidth)
  • LegendElement 
(iNumber, dChartSizePX, dFontSizePX, sText, iMarkerID, sLegendType, dLegendWidth)
  • Legend 
(sLegendType, dChartSizePX, dFontSizePX, dFontSize100, dLegendWidth, sBorderColor, tText, tMarker)

Code

-------- SVG Chart Generator --------
--[[ code conventions:
  - normally lua don't differentiate data formats but in the following processing is it sometime helpfull 
    to differentiate: - is to use the original input string or a (max(min) value of that string
    furthermore lua do internal assign types e.g. after "tonumber", "tonumber" avoid often type conversions
  - prefix of variables:
    g - global
    t - table
    b - boolean, true/false (intern: double, string)
    d - double
    i - integer (intern: double)
    s - string
  
  - suffix of variables:
    Px  - for sizes in pixel
    100 - means a value in %
    Fix - for user defined values
  ]]

---- predefined values ----
MAXCHARTNUMBER    = 6                    -- max number of processible charts, for visibnility and from experience a good max number
IMAGESIZE         = 750                  -- general visible size of the whole image in px

---- sub modules ----
require ("Module:Sandbox/Con-struct_(t)/Test1/error")
require ("Module:Sandbox/Con-struct_(t)/Test1/standard")
require ("Module:Sandbox/Con-struct_(t)/Test1/init")
require ("Module:Sandbox/Con-struct_(t)/Test1/svg-head")
require ("Module:Sandbox/Con-struct_(t)/Test1/svg-viewbox")
require ("Module:Sandbox/Con-struct_(t)/Test1/svg-axis")
require ("Module:Sandbox/Con-struct_(t)/Test1/svg-axistext")
require ("Module:Sandbox/Con-struct_(t)/Test1/svg-graphs")
require ("Module:Sandbox/Con-struct (t)/Test1/svg-marker")
require ("Module:Sandbox/Con-struct_(t)/Test1/svg-legend")
require ("Module:Sandbox/Con-struct_(t)/Test1/svg-text")

---- global arrays and variables ----

---- global variables ----


--sDebug = " \n Debug:\n"
gsDebug         = ''
gsDebugStandard = ''   -- for additional standard functions string..., math..., ...
gbDebug         = nil
gsValuesFirstSpace = "     "


local function WikiTextFirst ()
    return
        "Mark and copy the following text. Paste it into a plain text file. The text file should have an svg extension, for example ''mychart.svg''.\n\n" ..
        "You can check the result [http://toolserver.org/~jarry/svgcheck/stable/index.php here] or [[:File:Test.svg|here]].\n"
end


---- public functions ----
local p = {}

----- only for test and debug, todo: may be removed sometime: ----
function p.AxisMarkLengthTest (frame)
	return AxisMarkLengthT (frame.args.dChartElementSize, frame.args.dAxisMarkLengthFix)
end

---- real in use, not to be removed: ----

---- line size for graphs, px ----
function p.LineWidth2(frame)
    local ChartSize          = frame.args[1] or frame.args.ChartSize or 100            -- px
    local LineWidth          = frame.args[2] or frame.args.LineWidth or 100            -- %
    local GraphStretchWidth  = frame.args[4] or frame.args.GraphStretchWidth or 100    -- %
    local GraphStretchHeight = frame.args[5] or frame.args.GraphStretchHeight or 100   -- %
--[[ GraphStretchWidth and GraphStretchHeight are only used while missing the "non-scaling-stroke" feature in rsvg
  the line width is reduced in consideration of of stretching by the "scale" command
  in the other direction is the line thickness to imitate by arrange of several lines ]]
  
    local temp
    if GraphStretchWidth < GraphStretchHeight then
        temp = GraphStretchWidth / GraphStretchHeight else 
        temp = GraphStretchHeight / GraphStretchWidth end 
                
    return round (0.007                                              -- general relation of the line thickness
        * ChartSize
        * LineWidth / 100
        * temp
        , 5 - string.len (round (ChartSize, 0)))  -- only two relevant digits for font size
end


function p.testfind (frame)
	local iFirst, iLast
	
	iFirst, iLast = string.find (frame.args.String, frame.args.Pattern, frame.args.Start)
	return 'testfind(): iFirst:' .. tostring(iFirst) .. ', iLast: ' .. tostring(iLast) .. ', String: "' .. frame.args.String .. '"\n'
end


--[[
DiagramSize, px
href of graphs
GraphStretchWidth, %
GraphStretchHeight, %
]]
function p.GraphFill(frame)
    local GraphNumber        = frame.args[1] or frame.args.GraphNumber
    local href               = frame.args[2] or frame.args.href
    local DiagramSize        = frame.args[3] or frame.args.DiagramSize or 100          -- px
    local GraphStretchWidth  = frame.args[4] or frame.args.GraphStretchWidth or 100    -- %
    local GraphStretchHeight = frame.args[5] or frame.args.GraphStretchHeight or 100   -- %

    return '  &lt;!-- graph ' .. GraphNumber .. ' -->\
  <use id="graphuse' .. GraphNumber .. '-1" transform="translate(0, 0)" class="graph'
   .. GraphNumber .. 'line" xlink:href="#graph' .. GraphNumber .. '"/>'

end


-- SVGChart (), main function --
function p.SVGChart (frame)
	---- declarations ----
	local tsGraphValues  = {frame.args.Graph1Values, frame.args.Graph2Values, frame.args.Graph3Values, frame.args.Graph4Values, frame.args.Graph5Values, frame.args.Graph6Values}
	local tsGraphLine    = {frame.args.Graph1Line,   frame.args.Graph2Line,   frame.args.Graph3Line,   frame.args.Graph4Line,   frame.args.Graph5Line,   frame.args.Graph6Line}
	local tsGraphFill    = {frame.args.Graph1Fill,   frame.args.Graph2Fill,   frame.args.Graph3Fill,   frame.args.Graph4Fill,   frame.args.Graph5Fill,   frame.args.Graph6Fill}
	local tsGraphText    = {frame.args.Graph1Text,   frame.args.Graph2Text,   frame.args.Graph3Text,   frame.args.Graph4Text,   frame.args.Graph5Text,   frame.args.Graph6Text}
	local tsGraphColor   = {frame.args.Graph1Color or       'rgb(00%, 00%, 70%)',
                            frame.args.Graph2Color or       'rgb(75%, 10%, 10%)',
                            frame.args.Graph3Color or       'rgb(00%, 60%, 00%)',
                            frame.args.Graph4Color or       'rgb(00%, 60%, 60%)',
                            frame.args.Graph5Color or       'rgb(60%, 00%, 60%)',
                            frame.args.Graph6Color or       'rgb(60%, 60%, 00%)'
                           }
	local tsGraphMarker     = {frame.args.Graph1Marker,     frame.args.Graph2Marker,     frame.args.Graph3Marker,     frame.args.Graph4Marker,     frame.args.Graph5Marker,     frame.args.Graph6Marker}
	local tsGraphMarkerFill = {frame.args.Graph1MarkerFill, frame.args.Graph2MarkerFill, frame.args.Graph3MarkerFill, frame.args.Graph4MarkerFill, frame.args.Graph5MarkerFill, frame.args.Graph6MarkerFill}
	local tdGraphMarkerSize = {frame.args.Graph1MarkerSize, frame.args.Graph2MarkerSize, frame.args.Graph3MarkerSize, frame.args.Graph4MarkerSize, frame.args.Graph5MarkerSize, frame.args.Graph6MarkerSize}
--[[	local tsGraphMarkerFill = {frame.args.Graph1MarkerFill or 'rgb(00%, 00%, 70%)',
		                       frame.args.Graph2MarkerFill or 'rgb(75%, 10%, 10%)',
		                       frame.args.Graph3MarkerFill or 'rgb(00%, 60%, 00%)',
		                       frame.args.Graph4MarkerFill or 'rgb(00%, 60%, 60%)',
		                       frame.args.Graph5MarkerFill or 'rgb(60%, 00%, 60%)',
		                       frame.args.Graph6MarkerFill or 'rgb(60%, 60%, 00%)'
		                     }  ]]

	local tsText         = {frame.args.Text1,  frame.args.Text2,  frame.args.Text3,  frame.args.Text4,  frame.args.Text5,  frame.args.Text6}
	local tdTextX        = {frame.args.Text1X, frame.args.Text2X, frame.args.Text3X, frame.args.Text4X, frame.args.Text5X, frame.args.Text6X}
	local tdTextY        = {frame.args.Text1Y, frame.args.Text2Y, frame.args.Text3Y, frame.args.Text4Y, frame.args.Text5Y, frame.args.Text6Y}

	local tsX            = {}
	local tsY            = {}
	local tdXMin         = {};   local dXMin        = MAXVALUE;
	local tdXMax         = {};   local dXMax        = MINVALUE;
	local tdYMin         = {};   local dYMin        = 0
	local tdYMax         = {};   local dYMax        = MINVALUE;
	local dXMinFix       = frame.args.XMin                    or nil
	local dXMaxFix       = frame.args.XMax                    or nil
	local dYMinFix       = frame.args.YMin                    or nil
	local dYMaxFix       = frame.args.YMax                    or nil

	local tiXIntegerLen  = {};   local iXIntegerLen = 0;         -- max len up to the decimal point, for a propper SVG text layout
	local tiYIntegerLen  = {};   local iYIntegerLen = 0;         -- -"-
	local tiXLenMax      = {};   local iXLenMax     = 0;         -- whole max len of values, for a propper SVG text layout
	local tiYLenMax      = {};   local iYLenMax     = 0;         -- -"-
	local tsXFirst       = {}                                    -- for additionals for filled areas
	local tsXLast        = {}                                    -- -"-

	-- image and chart --
	local dImageSize          = tonumber (frame.args.ImageSize          or 100)
	local dChartSize          = tonumber (frame.args.ChartSize          or 100)	  -- user given chart size, %
	local dImageLeft          = frame.args.ImageLeft                    or nil
	local dImageRight         = frame.args.ImageRight                   or nil
	local dImageTop           = frame.args.ImageTop                     or nil
	local dImageBottom        = frame.args.ImageBottom                  or nil
	
	local dElementsWidth      = tonumber (frame.args.ElementsWidth      or 100)
	local dLineWidth100       = tonumber (frame.args.LineWidth          or 100)	  -- user given line size, %
	local dGraphStretchWidth  = tonumber (frame.args.GraphStretchWidth  or 100)
	local dGraphStretchHeight = tonumber (frame.args.GraphStretchHeight or 100)
	local dGraphWidth         = tonumber (frame.args.GraphWidth         or 100)
	local dGraph1Width        = tonumber (frame.args.Graph1Width or dGraphWidth)
	
	local dChartElementSize   = nil
	local dLineWidthPx        = nil	-- line size,px
	local dChartWidthRaw      = nil
	local dChartWidthStretch  = nil
	local dChartHeightRaw     = nil
	local dChartHeightStretch = nil

	-- font size --
	local dFontSize100            = tonumber (frame.args.FontSize            or 100)
    local dFontSizeTitle100       = tonumber (frame.args.FontSizeTitle       or dFontSize100)
	local dXAxisFontSize100       = tonumber (frame.args.XAxisFontSize       or dFontSize100)
	local dXAxisNumberFontSize100 = tonumber (frame.args.XAxisNumberFontSize or dXAxisFontSize100)
	local dYAxisFontSize100       = tonumber (frame.args.YAxisFontSize       or dFontSize100)
	local dYAxisNumberFontSize100 = tonumber (frame.args.YAxisNumberFontSize or dYAxisFontSize100)
    local dChartTextFontSize100   = tonumber (frame.args.ChartTextFontSize   or dFontSize100)    -- %
    local dLegendFontSize100      = tonumber (frame.args.LegendFontSize      or dFontSize100)    -- %
    local dLegendTextWA           = frame.args.LegendTextWA                  or 1    -- Workaround for librsvg: Fontsize factor for misplaced text
    local dGeneralFontSizePx
    local dFontSizePx
    local dLegendFontSizePx

	-- diagram text --
    local sTitle              = frame.args.Title                 or nil
    local dTitleX100          = frame.args.TitleX                or nil
    local dTitleY100          = frame.args.TitleY                or nil
    local dTitleXlibrsvg      = frame.args.TitleXlibrsvg         or nil
    local dTitleYlibrsvg      = frame.args.TitleYlibrsvg         or nil
	
	local sDescription        = frame.args.Description           or nil
	local sFootnote           = frame.args.Footnote              or nil
	local sBackgroundSVG      = frame.args.BackgroundSVG         or nil
	local sForegroundSVG      = frame.args.ForegroundSVG         or nil
	
	-- charts --
    local dAxisMarkLength     = frame.args.AxisMarkLength        or nil            -- may be nil
    
    -- axis marks --
	local sXAxisText          = frame.args.XAxisText             or nil
    local dXAxisMarkStart     = frame.args.XAxisMarkStartT       or nil
    local dXAxisMarkStep      = frame.args.XAxisMarkStep         or  10    
    local dXAxisMark2Start    = frame.args.XAxisMark2StartT      or nil
    local dXAxisMark2Step     = frame.args.XAxisMark2Step        or nil

	local sYAxisText          = frame.args.YAxisText             or nil
    local dYAxisMarkStart     = frame.args.YAxisMarkStartT       or nil
    local dYAxisMarkStep      = frame.args.YAxisMarkStep         or  10
    local dYAxisMark2Start    = frame.args.YAxisMark2StartT      or nil
    local dYAxisMark2Step     = frame.args.YAxisMark2Step        or nil

	local sYAxis2Text         = frame.args.YAxis2Text            or nil      -- criteria for further realisations
    local dYAxis2MarkStart    = frame.args.YAxis2MarkStartT      or nil
    local dYAxis2MarkStep     = frame.args.YAxis2MarkStep        or  10
    
    -- x axis values --
    local dXAxisValueStart     = frame.args.XAxisValueStart       or dXAxisMarkStart
    local dXAxisValueStep      = frame.args.XAxisValueStep        or nil
    local dXAxisValueEnd       = frame.args.XAxisValueEnd         or nil
    local dXAxisValueRound     = frame.args.XAxisValueRound       or   0
    local dXAxisValuePosStart  = frame.args.XAxisValuePosStartT   or nil
    local dXAxisValuePosStep   = frame.args.XAxisValuePosStep     or nil
    local sXAxisValuePrefix    = frame.args.XAxisValuePrefix      or nil
    local sXAxisValueSuffix    = frame.args.XAxisValueSuffix      or nil
    local sXAxisText           = frame.args.XAxisText             or nil
--    local dXAxisTextX          = frame.args.XAxisTextX            or 100
    local sXAxisTextAttribute  = frame.args.XAxisTextAttribute    or  ''
    local dXAxisValueDYlibrsvg = frame.args.XAxisValueDYlibrsvg   or nil
    local sXAxisValueSVG       = frame.args.XAxisValueSVG         or nil
    
    -- y axis values --
    local dYAxisValueStart     = frame.args.YAxisValueStart       or dYAxisMarkStart
    local dYAxisValueStep      = frame.args.YAxisValueStep        or nil
    local dYAxisValueEnd       = frame.args.YAxisValueEnd         or nil
    local dYAxisValueRound     = frame.args.YAxisValueRound       or   0
    local dYAxisValuePosStart  = frame.args.YAxisValuePosStartT   or nil
    local dYAxisValuePosStep   = frame.args.YAxisValuePosStep     or nil
    local sYAxisValuePrefix    = frame.args.YAxisValuePrefix      or nil
    local sYAxisValueSuffix    = frame.args.YAxisValueSuffix      or nil
    local sYAxisText           = frame.args.YAxisText             or nil
    local dYAxisTextX          = frame.args.YAxisTextX            or 100
    local sYAxisTextAttribute  = frame.args.YAxisTextAttribute    or  ''
    local dYAxisValueDYlibrsvg = frame.args.YAxisValueDYlibrsvg   or nil
    local sYAxisValueSVG       = frame.args.YAxisValueSVG         or nil
    
    -- 2nd y axis values --
    local dYAxis2ValueStart    = frame.args.YAxis2ValueStart      or dYAxis2MarkStart
    local dYAxis2ValueStep     = frame.args.YAxis2ValueStep       or nil
    local dYAxis2ValueEnd      = frame.args.YAxis2ValueEnd        or nil
    local dYAxis2ValueRound    = frame.args.YAxis2ValueRound      or   0
    local dYAxis2ValuePosStart = frame.args.YAxis2ValuePosStartT  or nil
    local dYAxis2ValuePosStep  = frame.args.YAxis2ValuePosStep    or nil
    local sYAxis2ValuePrefix   = frame.args.YAxis2ValuePrefix     or nil
    local sYAxis2ValueSuffix   = frame.args.YAxis2ValueSuffix     or nil
    local sYAxis2Text          = frame.args.YAxis2Text            or nil
    local dYAxis2TextX         = frame.args.YAxis2TextX           or 240
    local sYAxis2TextAttribute = frame.args.YAxis2TextAttribute   or  ''
    local dYAxis2ValueDYlibrsvg= frame.args.YAxis2ValueDYlibrsvg  or nil
    local sYAxis2ValueSVG      = frame.args.YAxis2ValueSVG        or nil
    
    -- grid --
	local dXGridStart          = frame.args.XGridStart            or nil
	local dXGridStep           = frame.args.XGridStep             or
	                             frame.args.XGrid                 or nil   -- 'none' if none realization
	local dYGridStart          = frame.args.YGridStart            or nil
	local dYGridStep           = frame.args.YGridStep             or
	                             frame.args.YGrid                 or nil   -- 'none' if none realization
    
    -- legend --
	local sLegendSVG           = frame.args.LegendSVG             or nil
	local sLegendType          = frame.args.LegendType            or 'box'
    local sLegendBorder        = frame.args.LegendBorder                           -- legend border color
    local dLegendWidth100      = tonumber (frame.args.LegendWidth or 100)
    local dLegendX             = tonumber (frame.args.LegendX     or 100)
    local dLegendY             = tonumber (frame.args.LegendY     or 100)
	local dLegendBoxDX         = nil
	local dLegendBoxWidth      = nil
     
    -- legend --
	local sBackground          = frame.args.Background            or nil   -- used in svg-axis.svgAxisGridBackground (), todo: is this function really usefull?

    -- other --
	  gbDebug              = frame.args.Debug                 or nil
  	local i, iNumberPairs, iNumberCharts, sOutLegend
    local dLeft, dRight, dTop, dBottom, sReturn
	local sOutGraphUse, sOutGraphValues, sOutGraphFillValues = " \n", " \n", " \n", " \n"
--	local sOutGraphFillUse = ""
	local bDefaultWWChart = true

    ---- initialisations ----
    iNumberCharts = 0
    for i = 1, MAXCHARTNUMBER do
    	if iserror () then break end
    	if tsGraphValues[i] then
    		bDefaultWWChart = false
    		iNumberCharts   = iNumberCharts + 1
    	    tsX[i], tsY[i], tdXMin[i], tdXMax[i], tdYMin[i], tdYMax[i], tiXLenMax[i], tiYLenMax[i], tiXIntegerLen[i], tiYIntegerLen[i], tsXFirst[i], tsXLast[i], iNumberPairs
        	    = ChartValues (tsGraphValues[i])                      -- all relevant values of one array of chart values
           	if iserror () then break end
        	    
        	dXMin        = min (dXMin, tdXMin[i])   -- min y
        	dXMax        = max (dXMax, tdXMax[i])   -- max x
        	dYMax        = max (dYMax, tdYMax[i])   -- max y
        	iXLenMax     = max (iXLenMax, tiXLenMax[i])
        	iYLenMax     = max (iYLenMax, tiYLenMax[i])
        	iXIntegerLen = max (iXIntegerLen, tiXIntegerLen[i])
        	iYIntegerLen = max (iYIntegerLen, tiYIntegerLen[i])
        	if iNumberPairs > 50 then gsValuesFirstSpace = " " end      -- shall minimize the size of the svg file
		end
    end

    if iNumberCharts == 1 then sLegendType = 'none' end
    	
	if dXMinFix then dXMin = dXMinFix end
	if dXMaxFix then dXMax = dXMaxFix end
	if dYMinFix then dYMin = dYMinFix end
	if dYMaxFix then dYMax = dYMaxFix end
	dXMin                  = tonumber (dXMin)
	dXMax                  = tonumber (dXMax)
	dXDif                  = math.abs (dXMax - dXMin)
	dYMin                  = tonumber (dYMin)
	dYMax                  = tonumber (dYMax)
	dYDif                  = math.abs (dYMax - dYMin)
	
	dTmp = math.max (dXDif, dYDif) / math.min (dXDif, dYDif)
	errorcheck (dTmp > 5, 'main', 'SVGChart', 'The range of x values is not congruent to the range of y values. The ratio is "' .. 
		dTmp .. '". Therefore it is not possible to create an svg file with original data. Please, change the values of Graph_Values for a ratio of differences for x/y or y/x to < 5. ')
	
    if not dXAxisMarkStart      then dXAxisMarkStart      = dXMin            end
    if not dXAxisMark2Start     then dXAxisMark2Start     = dXAxisMarkStart  end
	if not dXGridStart          then dXGridStart          = dXAxisMarkStart  end
	if not dXGridStep           then dXGridStep           = dXAxisMarkStep   end
    if not dXAxisValuePosStart  then dXAxisValuePosStart  = dXAxisMarkStart  end
    if not dXAxisValuePosStep   then dXAxisValuePosStep   = dXAxisMarkStep   end
	if not dXAxisValueStart     then dXAxisValueStart     = dXMin            end
    if not dXAxisValueStep      then dXAxisValueStep      = dXAxisMarkStep   end
    if not dXAxisValueEnd       then dXAxisValueEnd       = dXMax            end

    if not dYAxisMarkStart      then dYAxisMarkStart      = dYMin            end
    if not dYAxisMark2Start     then dYAxisMark2Start     = dYAxisMarkStart  end
    if not dYGridStart          then dYGridStart          = dYAxisMarkStart  end
    if not dYGridStep           then dYGridStep           = dYAxisMarkStep   end
    if not dYAxisValuePosStart  then dYAxisValuePosStart  = dYAxisMarkStart  end
    if not dYAxisValuePosStep   then dYAxisValuePosStep   = dYAxisMarkStep   end
	if not dYAxisValueStart     then dYAxisValueStart     = dYMin            end
    if not dYAxisValueStep      then dYAxisValueStep      = dYAxisMarkStep   end
    if not dYAxisValueEnd       then dYAxisValueEnd       = dYMax            end
    
    if not dYAxis2MarkStart     then dYAxis2MarkStart     = dYMin            end
    if not dYAxis2Mark2Start    then dYAxis2Mark2Start    = dYAxis2MarkStart end
    if not dYAxis2ValuePosStart then dYAxis2ValuePosStart = dYAxis2MarkStart end
    if not dYAxis2ValuePosStep  then dYAxis2ValuePosStep  = dYAxis2MarkStep  end
	if not dYAxis2ValueStart    then dYAxis2ValueStart    = dYMin            end
    if not dYAxis2ValueStep     then dYAxis2ValueStep     = dYAxis2MarkStep  end
    if not dYAxis2ValueEnd      then dYAxis2ValueEnd      = dYMax            end

    
    dChartSize          = Size (dXMin, dXMax, dYMin, dYMax, dGraphStretchWidth, dGraphStretchHeight)
    dChartElementSize   = dChartSize * dElementsWidth / 100
    dLineWidthPx        = LineWidth (dChartSize, dLineWidth100, 100, 100)
    dLineWidthStretchPx = LineWidth (dChartSize, dLineWidth100, dGraphStretchWidth, dGraphStretchHeight)

    if not dAxisMarkLength then dAxisMarkLength = AxisMarkLength (dChartElementSize) end     -- function in svg-axis
    
    dLegendBoxDX        = 0.05 * dChartSize
    dLegendBoxWidth     = LegendBoxWidth (dChartSize, dLegendFontSize100, dLegendWidth100)
    
    dGeneralFontSizePx  = round (dChartSize * dElementsWidth * dFontSize100 / 1000000 * 6.0, 3)               -- * x.x - the general font size, px, ToDo: dFontSize100 not here because also in dFontSizePx and so on
    dFontSizePx         = FontSize (dGeneralFontSizePx, dFontSize100)
    dLegendFontSizePx   = FontSize (dGeneralFontSizePx, dLegendFontSize100 or dFontSize100)
    
    dChartWidthRaw      = absDif (dXMin, dXMax)
    dChartWidthStretch  = dChartWidthRaw  * dGraphStretchWidth / 100
	dChartHeightRaw     = absDif (dYMin, dYMax)
	dChartHeightStretch = dChartHeightRaw * dGraphStretchHeight / 100

    -- defined in svg-viebox, todo: avoid a second call in svg-viewbox --
    dLeft               = Left   (dChartElementSize, dImageLeft, dYAxisFontSize100)                                                      -- x, left side for axis description
    dRight              = Right  (dChartElementSize, dChartWidthStretch, dImageRight, sLegendType, dLegendWidth100, dLegendX, sYAxis2Text, dLegendFontSize100, dYAxisFontSize100)     -- same expression as width in viewBox
    dTop                = Top    (dChartElementSize, dImageTop, sTitle, dFontSizeTitle100)
    dBottom             = Bottom (dChartElementSize, dImageBottom, iLegendType, sFootnote, dFontSize100, sXAxisText)

    ---- svg generation ----
    sReturn =
    	WikiTextFirst () ..
    	'<pre>\n' ..
--    	svgViewBox (dChartElementSize, dChartWidthStretch, dChartHeightStretch, dImageSize, dImageLeft, dImageRight, dImageTop, dImageBottom, sLegendType, dLegendWidth100, dLegendX, dLegendFontSize100, dFontSize100, dFontSizeTitle100, dYAxisFontSize100, sTitle, sFootnote, sYAxis2Text) ..
    	svgViewBox (dChartElementSize, dChartWidthStretch, dChartHeightStretch, dImageSize, dLeft, dRight, dTop, dBottom, sLegendType, dLegendWidth100, dLegendX, dLegendFontSize100, dFontSize100, dFontSizeTitle100, dYAxisFontSize100, sTitle, sFootnote, sYAxis2Text) ..
    	svgTitle (sTitle, sDescription) ..
    	svgBackground (dChartHeightStretch, dChartWidthStretch, dChartElementSize, dLeft, dRight, dTop, dBottom, sBackgroundImageSVG) ..
    	
    	'\n<style id="styles" type="text/css"> <![CDATA[\n' ..
    	LineMarkerStyles (dChartElementSize, dGraphWidth, dGraphStretchWidth, dGraphStretchHeight, tsGraphValues, tsGraphLine, tsGraphMarker, tsGraphColor, tsGraphFill, tsGraphMarkerFill) ..
    	AxisGridStyles (tsGraphMarker, dChartElementSize, dXGridStep, dYGridStep) ..
    	TextStyles (sLegendType, tsText, dGeneralFontSizePx, dFontSizeTitle100, dXAxisFontSize100, dYAxisFontSize100, dXAxisNumberFontSize100, dLegendFontSize100, dChartTextFontSize100, dLegendTextWA) ..
    	']]></style>\n' ..
    	
    	'\n<defs>\n' ..
    	svgAxisDefs (dChartElementSize, dGraphStretchWidth, dGraphStretchHeight, dChartWidthRaw, dChartHeightRaw, dXMin, dYMin, dXGridStart, dYGridStart, dXGridStep, dYGridStep, dXAxisMarkStart, dXAxisMarkStep, dXAxisMark2Start, dXAxisMark2Step, dYAxisMarkStart, dYAxisMarkStep, dYAxisMark2Start, dYAxisMark2Step, dYAxis2MarkStart, dYAxis2MarkStep) ..
--    	svgMarkerDefs (tsGraphMarker, dChartSize, tdGraphMarkerSize, tsGraphMarkerFill, dGraphStretchWidth, dGraphStretchHeight) ..
    	svgMarkerDefs (tsGraphMarker, dChartElementSize, tdGraphMarkerSize, tsGraphMarkerFill, dGraphStretchWidth, dGraphStretchHeight) ..
    	'</defs>\n\n' ..
    	
    	svgBackgroundSVG (dGraphStretchWidth, dGraphStretchHeight, sBackgroundSVG) ..
        svgBackground2   (sBackground, bDefaultWWChart, dChartWidthStretch, dChartHeightStretch, dXMin, dYMin, dXGrid, dYGrid, dAxisMarkLength, dXAxisMarkStart, dXAxisMark2Start, dXAxisMark2Step, dYAxisMark2Step, sYAxis2Text, dYAxis2MarkStep) ..
        svgGrid (bDefaultWWChart, dChartWidthStretch, dChartHeightStretch, dXGrid, dYGrid) ..
        svgXAxisText (
            dChartWidthStretch, dGraphStretchWidth, 
            dFontSizePx, dGeneralFontSizePx, dXAxisFontSize100, dXAxisNumberFontSize100, 
            dXMin, dXMax, dXAxisValuePosStart, dXAxisValuePosStep, 
            dXAxisValueStart, dXAxisValueStep, dXAxisValueRound, sXAxisValueSVG, 
            sXAxisText, sXAxisTextAttribute, sXAxisValuePrefix, sXAxisValueSuffix, 
            dXAxisValueDYlibrsvg, sXAxisTextDYlibrsvg) ..
        svgYAxisText (
            dChartHeightStretch, dGraphStretchHeight, dChartElementSize,
            dFontSizePx,
            dYMin, dYMax, dYAxisValuePosStart, dYAxisValuePosStep, 
            dYAxisValueStart, dYAxisValueStep, dYAxisValueRound, sYAxisValueSVG, 
            sYAxisText, dYAxisTextX, sYAxisTextAttribute, sYAxisValuePrefix, sYAxisValueSuffix, 
            dYAxisValueDYlibrsvg, sYAxisTextDYlibrsvg) ..
        svgYAxis2Text (
            dChartWidthStretch, dChartHeightStretch, dGraphStretchHeight, dChartElementSize,
            dFontSizePx,
            dYMin, dYMax, dYAxis2ValuePosStart, dYAxis2ValuePosStep, 
            dYAxis2ValueStart, dYAxis2ValueStep, iYAxis2ValueRound, sYAxis2ValueSVG, 
            sYAxis2Text, dYAxis2TextX, sYAxis2TextAttribute, sYAxis2ValuePrefix, sYAxis2ValueSuffix, 
            dYAxis2ValueDYlibrsvg, sYAxis2TextDYlibrsvg) ..
        svgLegend        (sLegendType, dChartSize, dLegendFontSizePx, dLegendFontSize100, dLegendBoxWidth, dLegendWidth100, sLegendBorder, tsGraphText, tsGraphMarker, sLegendSVG, dChartWidthStretch, dChartHeightStretch, dLegendX, dLegendY, dChartSize, sYAxis2Text, dYAxisFontSize100) ..
        svgChartTitle    (dChartWidthStretch, dChartHeightStretch, dGeneralFontSizePx, dFontSizeTitle100, sTitle, dTitleX100, dTitleY100, dTitleXlibrsvg, dTitleYlibrsvg) ..
        svgChartFootnote (dChartWidthStretch, sFootnote, dFootnoteX100, dFootnoteY100, dTitleXlibrsvg, dTitleYlibrsvg) ..
        
    	'\n<defs>\n' ..
    	svgGraphsDefs (dYMin, tsX, tsY, tsGraphValues, tsGraphFill, tsXFirst, tsXLast, tsGraphText, 
    		LineWidth (dChartElementSize, dGraph1Width, dGraphStretchWidth, dGraphStretchHeight), 
    		iXLenMax, iXIntegerLen, iYIntegerLen) ..
    	'</defs>\n' ..
    	
    	svgGraphsUse (dXMin, dYMin, dLineWidthPx, dImageSize, tsGraphValues, tsGraphFill, dGraphStretchWidth, dGraphStretchHeight, svgGraphFill) ..
--    	svgAxisGrid  (bDefaultWWChart, dChartWidthStretch, dChartHeightStretch, dXMin, dYMin, dXGridStep, dYGridStep, dAxisMarkLength, dXAxisMarkStart, dXAxisMark2Start, dXAxisMark2Step, dYAxisMark2Step, sYAxis2Text, dYAxis2MarkStep) ..
    	svgAxis (bDefaultWWChart, dChartWidthStretch, dChartHeightStretch, dXMin, dYMin, dAxisMarkLength, dXAxisMarkStart, dXAxisMark2Start, dXAxisMark2Step, dYAxisMark2Step, sYAxis2Text, dYAxis2MarkStep) ..
    	svgGraphText (dGraphStretchWidth, dGraphStretchHeight, dXMin, dYMin, tsText, tsGraphText, tdTextX, tdTextY, dGeneralFontSizePx, dYAxisFontSize100) ..
    	svgForeground (sForegroundSVG) ..
    	'\n</svg>\n</pre>\n'
    	
    if gbDebug then gsDebug =
        '<pre>Debug:\n\n' ..
        'main.p.SVGChart (): dChartSize: ' .. dChartSize .. ', dElementsWidth: ' .. dElementsWidth .. ', dElementsWidth: ' .. dElementsWidth .. ', dImageLeft: ' .. tostring (dImageLeft) .. ', dYAxisFontSize100: ' .. dYAxisFontSize100 .. '\n' ..
        '    dXMin: ' .. dXMin .. ', dXMax: ' .. dXMax .. ', dYMin: ' .. dYMin .. ', dYMax: ' .. dYMax .. '\n' ..
        '    dChartElementSize: ' .. dChartElementSize .. ', dChartSize: ' .. dChartSize .. '\n' ..
        '    dChartWidthRaw:  ' .. dChartWidthRaw ..  ', dGraphStretchWidth:  ' .. tostring (dGraphStretchWidth) ..  ', dChartWidthStretch:  ' .. dChartWidthStretch  .. '\n' ..
        '    dChartHeightRaw: ' .. dChartHeightRaw .. ', dGraphStretchHeight: ' .. tostring (dGraphStretchHeight) .. ', dChartHeightStretch: ' .. dChartHeightStretch .. '\n'	..
        '    dGeneralFontSizePx: ' .. dGeneralFontSizePx .. ', dFontSize100: ' .. dFontSize100 .. ', dFontSizePx: ' .. dFontSizePx .. ', dLegendFontSizePx: ' .. dLegendFontSizePx .. '\n' ..
        '    dAxisMarkLength: ' .. dAxisMarkLength .. '\n' ..
        '    dXAxisMarkStart: ' .. dXAxisMarkStart .. ', dXAxisMark2Start: ' .. tostring (dXAxisMark2Start) .. '\n' ..
        '    dXAxisValueStart: ' .. dXAxisValueStart .. ', dXAxisValueStep: ' .. dXAxisValueStep .. ', dXAxisValuePosStart: ' .. tostring (dXAxisValuePosStart) .. ', dXAxisValuePosStep: ' .. tostring (dXAxisValuePosStep) .. '\n' ..
        '    dYAxisMarkStart: ' .. dYAxisMarkStart .. ', dYAxisMark2Start: ' .. tostring (dYAxisMark2Start) .. '\n'	..
        '    dYAxisValueStart: ' .. dYAxisValueStart .. ', dYAxisValueStep: ' .. dYAxisValueStep .. ', dYAxisValuePosStart: ' .. tostring (dYAxisValuePosStart) .. ', dYAxisValuePosStep: ' .. tostring (dYAxisValuePosStep) .. '\n' ..
        '    dLegendWidth100: ' .. tostring (dLegendWidth100) .. ', dLegendBoxWidth: ' .. tostring (dLegendBoxWidth) .. ', dLegendBoxDX: ' .. tostring (dLegendBoxDX) .. ', sLegendBorder: ' .. tostring (sLegendBorder) .. '\n' ..
        gsDebug .. 
        '</pre>' ..
        '<pre>Debug standard functions:\n' .. gsDebugStandard .. '</pre>'
    end

    if gbError then
    	return errormessage () .. gsDebug
    else
        return sReturn .. gsDebug
    end
end


return p