Jump to content

Module:Graph and Module:Graph/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
Undid revision 1141810373 by Frietjes (talk)
 
simplification
 
Line 150: Line 150:
if isNumbers then
if isNumbers then
if colorScale then colorScale = string.lower(colorScale) end
if colorScale then colorScale = string.lower(colorScale) end
if colorScale == "category10" or colorScale == "category20" then else colorScale = stringArray(colorScale) end
if colorScale ~= "category10" and colorScale ~= "category20" then colorScale = stringArray(colorScale) end
scales =
scales =
{
{
Line 165: Line 165:
if domainMax then scales[1].domainMax = domainMax end
if domainMax then scales[1].domainMax = domainMax end


local exponent = string.match(scaleType, "pow%s+(%d+%.?%d+)") -- check for exponent
local exponent = scaleType:match("pow%s+(%d+%.?%d+)") -- check for exponent
if exponent then
if exponent then
scales[1].type = "pow"
scales[1].type = "pow"
Line 195: Line 195:
-- get map url
-- get map url
local basemapUrl
local basemapUrl
if (string.sub(basemap, 1, 10) == "wikiraw://") then
if (basemap:sub(1, 10) == "wikiraw://") then
basemapUrl = basemap
basemapUrl = basemap
else
else
-- if not a (supported) url look for a colon as namespace separator. If none prepend default map directory name.
-- if not a (supported) url look for a colon as namespace separator. If none prepend default map directory name.
if not string.find(basemap, ":") then basemap = baseMapDirectory .. basemap end
if not basemap:find(":") then basemap = baseMapDirectory .. basemap end
basemapUrl = "wikiraw:///" .. mw.uri.encode(mw.title.new(basemap).prefixedText, "PATH")
basemapUrl = "wikiraw:///" .. mw.uri.encode(mw.title.new(basemap).prefixedText, "PATH")
end
end
Line 281: Line 281:
if isInteger then xType = "integer" else xType = "number" end
if isInteger then xType = "integer" else xType = "number" end
end
end
elseif xType then
else
if xType then error("Numbers expected for parameter 'x'") end
error("Numbers expected for parameter 'x'")
end
end
end
end
if not x then
if not x then
x = stringArray(serializedX)
x = stringArray(serializedX)
if not xType then xType = "string" end
xType = xType or "string"
end
end
return x, xType, xMin, xMax
return x, xType, xMin, xMax
Line 303: Line 303:
if yValues then
if yValues then
areAllInteger = areAllInteger and isInteger
areAllInteger = areAllInteger and isInteger
elseif yType then
else
if yType then
error("Numbers expected for parameter '" .. name .. "'")
error("Numbers expected for parameter '" .. name .. "'")
else
else
return deserializeYData(serializedYs, "string", yMin, yMax)
return deserializeYData(serializedYs, "string", yMin, yMax)
end
end
end
end
end
if not yValues then yValues = stringArray(value) end
yValues = yValues or stringArray(value)


y[yNum] = yValues
y[yNum] = yValues
Line 442: Line 440:
local hasAlpha = false
local hasAlpha = false
for i = 1, #colors do
for i = 1, #colors do
local a, rgb = string.match(colors[i], "#(%x%x)(%x%x%x%x%x%x)")
local a, rgb = colors[i]:match("#(%x%x)(%x%x%x%x%x%x)")
if a then
if a then
hasAlpha = true
hasAlpha = true
Line 510: Line 508:
local function addInteractionToChartVisualisation(plotMarks, colorField, dataField)
local function addInteractionToChartVisualisation(plotMarks, colorField, dataField)
-- initial setup
-- initial setup
if not plotMarks.properties.enter then plotMarks.properties.enter = {} end
plotMarks.properties.enter = plotMarks.properties.enter or {}
plotMarks.properties.enter[colorField] = { scale = "color", field = dataField }
plotMarks.properties.enter[colorField] = { scale = "color", field = dataField }


-- action when cursor is over plot mark: highlight
-- action when cursor is over plot mark: highlight
if not plotMarks.properties.hover then plotMarks.properties.hover = {} end
plotMarks.properties.hover = plotMarks.properties.hover or {}
plotMarks.properties.hover[colorField] = { value = "red" }
plotMarks.properties.hover[colorField] = { value = "red" }


-- action when cursor leaves plot mark: reset to initial setup
-- action when cursor leaves plot mark: reset to initial setup
if not plotMarks.properties.update then plotMarks.properties.update = {} end
plotMarks.properties.update = plotMarks.properties.update or {}
plotMarks.properties.update[colorField] = { scale = "color", field = dataField }
plotMarks.properties.update[colorField] = { scale = "color", field = dataField }
end
end
Line 572: Line 570:
if colorField == "stroke" then
if colorField == "stroke" then
chartvis.properties.enter.strokeWidth = { value = linewidth or 2.5 }
chartvis.properties.enter.strokeWidth = { value = linewidth or 2.5 }
if type(lineScale) =="table" then
if type(lineScale) == "table" then
chartvis.properties.enter.strokeWidth.value = nil
chartvis.properties.enter.strokeWidth.value = nil
chartvis.properties.enter.strokeWidth =
chartvis.properties.enter.strokeWidth =
Line 622: Line 620:
-- if there are multiple series, connect linewidths to series
-- if there are multiple series, connect linewidths to series
if chartype == "line" then
if chartType == "line" then
chartvis.properties.update["strokeWidth"].field = "series"
chartvis.properties.update["strokeWidth"].field = "series"
end
end
Line 1,022: Line 1,020:
-- chart type
-- chart type
local chartType = frame.args.type or "line"
local chartType = frame.args.type or "line"
mw.log('test')
mw.log(chartType)
-- interpolation mode for line and area charts: linear, step-before, step-after, basis, basis-open, basis-closed (type=line only), bundle (type=line only), cardinal, cardinal-open, cardinal-closed (type=line only), monotone
-- interpolation mode for line and area charts: linear, step-before, step-after, basis, basis-open, basis-closed (type=line only), bundle (type=line only), cardinal, cardinal-open, cardinal-closed (type=line only), monotone
local interpolate = frame.args.interpolate
local interpolate = frame.args.interpolate
Line 1,088: Line 1,088:


if xType == "number" or xType == "integer" then
if xType == "number" or xType == "integer" then
v_annoLine = numericArray(v_annoLineString)
v_annoLine = numericArray(v_annoLineString)

else
else
v_annoLine = stringArray(v_annoLineString)
v_annoLine = stringArray(v_annoLineString)

end
end
v_annoLabel = stringArray(v_annoLabelString)
v_annoLabel = stringArray(v_annoLabelString)
Line 1,100: Line 1,098:
if yType == "number" or yType == "integer" then
if yType == "number" or yType == "integer" then
h_annoLine = numericArray(h_annoLineString)
h_annoLine = numericArray(h_annoLineString)

else
else
h_annoLine = stringArray(h_annoLineString)
h_annoLine = stringArray(h_annoLineString)

end
end
h_annoLabel = stringArray(h_annoLabelString)
h_annoLabel = stringArray(h_annoLabelString)
Line 1,127: Line 1,123:
for name, value in pairs(frame.args) do
for name, value in pairs(frame.args) do
local yNum
local yNum
if name == "y" then yNum = 1 else yNum = tonumber(string.match(name, "^y(%d+)$")) end
if name == "y" then yNum = 1 else yNum = tonumber(name:match("^y(%d+)$")) end
if yNum then
if yNum then
yValues[yNum] = value
yValues[yNum] = value
Line 1,149: Line 1,145:
local stacked = false
local stacked = false
local stats
local stats
if string.sub(chartType, 1, 7) == "stacked" then
if chartType:sub(1, 7) == "stacked" then
chartType = string.sub(chartType, 8)
chartType = chartType:sub(8)
if #y > 1 then -- ignore stacked charts if there is only one series
if #y > 1 then -- ignore stacked charts if there is only one series
stacked = true
stacked = true
Line 1,246: Line 1,242:
-- grids
-- grids
if xGrid then
if xGrid then
if xGrid == "0" then xGrid = false
xGrid = not (xGrid == "0" or xGrid == 0 or xGrid == "false" or xGrid == "n")
elseif xGrid == 0 then xGrid = false
elseif xGrid == "false" then xGrid = false
elseif xGrid == "n" then xGrid = false
else xGrid = true
end
end
end
if yGrid then
if yGrid then
if yGrid == "0" then yGrid = false
yGrid = not (yGrid == "0" or yGrid == 0 or yGrid == "false" or yGrid == "n")
elseif yGrid == 0 then yGrid = false
elseif yGrid == "false" then yGrid = false
elseif yGrid == "n" then yGrid = false
else yGrid = true
end
end
end
Line 1,401: Line 1,387:
function p.mapWrapper(frame)
function p.mapWrapper(frame)
return p.map(frame:getParent())
return p.map(frame:getParent())
end

function p.chartWrapper2(frame)
return p.chart(frame)
end
end