Module:Sandbox/Con-struct (t)/Test1/svg-marker
Jump to navigation
Jump to search
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules
Lua
Documentation for this module may be created at Module:Sandbox/Con-struct (t)/Test1/svg-marker/doc
Code
require ("Module:Sandbox/Con-struct_(t)/Test1/standard")
---- predefined values ----
local MARKERSIZE = 0.0021 -- general marker size
---- MarkerCreate (), shape of marker for a graph ----
--[[
1: graph number
2: type, 0: real, 1: stretched marker;
stretched marker, but real pressed marker is expanded later with the stretched graph
3: size of marker
4: GraphStretchWidth
5: GraphStretchHeight
- more explanation in MarkerShape
]]
local function MarkerCreate (iGraph, iType, dSize, dGraphStretchWidth, dGraphStretchHeight)
local sReturn =
' <marker id="graph' .. iGraph .. 'marker'
if iType ~= 0 then
sReturn = sReturn .. 'stretch'
end
sReturn = sReturn .. '" class="graph' .. iGraph .. 'marker" '
if iType ~= 0 then -- stretched marker
if dGraphStretchWidth < dGraphStretchHeight then -- stretch y direction
sReturn = sReturn ..
'refX="' ..
round (10 * dSize, 2) .. '" ' ..
'refY="' ..
round (10 * dSize * dGraphStretchWidth / dGraphStretchHeight, 3) .. '" '
else -- stretch x direction
sReturn = sReturn ..
'refX="' ..
round (10 * dSize * dGraphStretchHeight / dGraphStretchWidth, 3) .. '" ' ..
'refY="' ..
round (10 * dSize, 2) .. '" '
end
else -- no stretched marker
sReturn = sReturn ..
'refX="' ..
round (10 * dSize, 2) .. '" ' ..
'refY="' ..
round (10 * dSize, 2) .. '" '
end
sReturn = sReturn ..
'viewBox="0 0 ' ..
round (20 * dSize, 2) .. ' ' ..
round (20 * dSize, 2) .. '" markerUnits="userSpaceOnUse" markerWidth="' ..
round (20 * dSize, 2) .. '" markerHeight="' ..
round (20 * dSize, 2) .. '">\n ' ..
' <use '
if iType ~= 0 then
sReturn = sReturn ..
'transform="scale('
if dGraphStretchWidth < dGraphStretchHeight then
sReturn = sReturn ..
'1, ' ..
round (dGraphStretchWidth / dGraphStretchHeight, 3)
else
sReturn = sReturn ..
round (dGraphStretchHeight / dGraphStretchWidth, 3) ..
', 1'
end
sReturn = sReturn ..
')"'
end
return
sReturn ..
' xlink:href="#graph' .. iGraph .. 'markershape"/>\n' ..
' </marker>\n'
end
---- function Marker (), create marker style for a graph ----
--[[call TestAutoSVG_GraphMarker2 for less calls of TestAutoSVG_Size
1: empty: no graph marker
2: graph number
3: marker type
4: ChartSize, px
5: size of graph marker, default: 100
6: none: no fill; color
7: GraphStretchWidth
8: GraphStretchHeight
]]
--[[
function Marker (bMarker, iGraph, iType, dChartSizePx, dSize, sFillColor, dGraphStretchWidth, dGraphStretchHeight)
local sReturn = ' \n'
if iType ~= 0 then
return MarkerShape (iGraph, iType, dChartSizePx * dSize/100 * MARKERSIZE, sFillColor, dGraphStretchWidth, dGraphStretchHeight)
end
]]
local function MarkerShapeVerticalLine (iType, dSize)
local sPercent
if iType == 20 then sPercent = 1
else if iType == 21 then sPercent = 2
else if iType == 22 then sPercent = 3
else if iType == 23 then sPercent = 4
else if iType == 24 then sPercent = 5
else if iType == 25 then sPercent = 7
else if iType == 26 then sPercent = 9
else if iType == 27 then sPercent = 12
else if iType == 28 then sPercent = 15
else if iType == 29 then sPercent = 20
end end end end end end end end end end
gsDebug = gsDebug .. 'svg-marker.MarkerShapeVerticalLine(): iType: ' .. iType .. ', dSize: ' .. dSize .. ', round (6 * dSize, 2): ' .. round (6 * dSize, 2) .. '\n'
return
' <path d="M 0, ' ..
round ( 6 * dSize, 2) .. ' L 0, ' ..
round (-6 * dSize, 2) .. ' z" stroke-width="' ..
sPercent ..
'%"/> <!-- vertical line ' ..
sPercent ..
' % -->'
end
local function MarkerShape (iGraph, sType, dSize, sFillColor, dGraphStretchWidth, dGraphStretchHeight)
local sFill
local iType = tonumber (sType)
-- local sComment = ''
local sReturn =
' <g id="graph' .. iGraph .. 'markershape" transform="translate(' ..
round (10 * dSize, 2) .. ', ' ..
round (10 * dSize, 2) .. ')">\n'
if sFillColor then
sFill = ' fill="' .. sFillColor .. '"'
else
sFill = ''
end
if iType == 0 then iType = iGraph end -- ToDo: if marker type is a word i.e. "yes", then use the graph number
if iType == 2 then
sReturn = sReturn ..
' <circle cx="0" dx="0" r="' ..
round (6 * dSize, 2) .. '"/>' ..
' <!-- circle -->'
else if iType == 3 then
sReturn = sReturn ..
' <polygon points="' .. -- triangle, side/height = 1/0,866, height/center = 1/3 ( orient="0">)
round (-6 * dSize, 2) .. ', ' .. -- left, bottom
round (-6 * dSize, 2) .. ' ' ..
round ( 6 * dSize, 2) .. ', ' .. -- right, bottom
round (-6 * dSize, 2) .. ' ' ..
round ( 0 * dSize, 2) .. ', ' .. -- center, top
round ( 6 * dSize, 2) .. '"/>' .. sFill ..
' <!-- triangle -->'
else if iType == 4 then
sReturn = sReturn ..
' <rect transform="rotate(45)" x="' .. -- tilted square
round (-5 * dSize, 3) .. '" y="' ..
round (-5 * dSize, 3) .. '" width="' ..
round (10 * dSize, 3) .. '" height="' ..
round (10 * dSize, 3) .. '"/>' .. sFill ..
' <!-- tilted square -->'
else if iType == 5 then
sReturn = sReturn ..
' <polygon points="' .. -- triangle, side/height = 1/0,866, height/center = 1/3
round (-6 * dSize, 2) .. ', ' .. -- left, top
round ( 6 * dSize, 2) .. ' ' ..
round ( 6 * dSize, 2) .. ', ' .. -- right, top
round ( 6 * dSize, 2) .. ' ' ..
round ( 0 * dSize, 2) .. ', ' .. -- center, bottom
round (-6 * dSize, 2) .. '"/>' .. sFill ..
' <!-- tilted triangle -->'
else if iType == 6 then
sReturn = sReturn ..
' <path d="M ' .. -- cross
round ( 6 * dSize, 2) .. ', ' ..
round ( 6 * dSize, 2) .. ' L ' ..
round (-6 * dSize, 2) .. ', ' ..
round (-6 * dSize, 2) .. ' z M ' ..
round ( 6 * dSize, 2) .. ', ' ..
round (-6 * dSize, 2) .. ' L ' ..
round (-6 * dSize, 2) .. ', ' ..
round ( 6 * dSize, 2) .. ' z"/>' .. sFill ..
' <!-- cross -->'
else if iType >= 20 and iType <30 then
sReturn = sReturn .. MarkerShapeVerticalLine (iType, dSize)
else
sReturn = sReturn ..
' <rect x="' .. -- default and 1: regular square
round (-5 * dSize, 3) .. '" y="' ..
round (-5 * dSize, 3) .. '" width="' ..
round (10 * dSize, 3) .. '" height="' ..
round (10 * dSize, 3) .. '"/>' .. sFill ..
' <!-- regular square -->'
end end end end end end
return
sReturn .. '\n' ..
' </g>\n' ..
MarkerCreate (iGraph, 0, dSize, dGraphStretchWidth, dGraphStretchHeight) ..
MarkerCreate (iGraph, 1, dSize, dGraphStretchWidth, dGraphStretchHeight) ..
'\n'
end
-- create marker style for a graph --
--[[
no: 1: empty: no graph marker
no: 2: graph number
3: marker type
4: ChartSize, px
5: size of graph marker, default: 100
6: none: no fill; color
7: GraphStretchWidth
8: GraphStretchHeight
]]
function svgMarkerDefs (tsType, dChartSizePx, tdMarkerSize100, tsFillColor, dGraphStretchWidth, dGraphStretchHeight)
local i, dMarkerSize, sMarkerFill
local sReturn = ''
for i = 1, MAXCHARTNUMBER, 1 do
if tsType[i] then
if tdMarkerSize100[i] then dMarkerSize = tdMarkerSize100[i]
else dMarkerSize = 100 end
gsDebug = gsDebug .. 'svg-marker.svgMarkerDefs(): i: ' .. i .. ', dChartSizePx: ' .. dChartSizePx .. ', dMarkerSize: ' .. dMarkerSize .. ', MARKERSIZE: ' .. MARKERSIZE .. ', dChartSizePx * dMarkerSize / 100 * MARKERSIZE: ' .. dChartSizePx * dMarkerSize / 100 * MARKERSIZE .. '\n'
sReturn = sReturn ..
MarkerShape (i, tsType[i],
dChartSizePx * dMarkerSize / 100 * MARKERSIZE,
tsFillColor[i], dGraphStretchWidth, dGraphStretchHeight)
--[[ MarkerShape (i, 2,
3,
4, 5, 6) ]]
end
end
if sReturn ~= '' then
return
' \n' ..
' <!--== graph marker ==-->\n' ..
' <g class="graphmarker">\n' ..
sReturn ..
' </g>\n'
else
return ''
end
end