Module:Scale

local p = {} local h = {}

local utilsArg = require("Module:UtilsArg") local utilsMarkup = require("Module:UtilsMarkup") local utilsLayout = require("Module:UtilsLayout") local utilsTable = require("Module:UtilsTable")

local data = mw.loadData("Module:Scale/Data")

local NOTE_SIZE = "12px";

function p.Main(frame) local args = frame:getParent.args return p.main({   	system = args[1],    	notes = mw.text.split(args[2], '')    }) end

function p.main(args) local errorCategories = utilsArg.validator({		system = {			required = true,			enum = function return utilsTable.keys(data.notes) end,		},		notes = {			required = true,			enum = function return utilsTable.keys(data.notes[args.system]) end		}	})(args) if errorCategories then return utilsMarkup.categories(err) end local notes = utilsTable.map(h.symbolToNote(args.system))(args.notes) local scale = h.makeScale(notes) return scale end

function h.symbolToNote(system) local notes = data.notes[system] local positions = data.relativePositions[#utilsTable.keys(notes)] return function(symbol) local note = notes[symbol] local thumbnail = utilsMarkup.file(note.file, { link= '', size= NOTE_SIZE }) local notePosition = positions[note.position] local positionedNote = mw.html.create('span') :css({               position= 'relative',                top= notePosition .. 'px',            }) :wikitext(thumbnail, ' ') return positionedNote end end

function h.makeScale(notes) local div = mw.html.create('div') :css({           display= 'inline-block',            ['line-height']= '28px',        }) for _, note in ipairs(notes) do       div:node(note) end return tostring(div) end

function p.Documentation local tableData = { headerRows = , tabs = {} }	for system, notes in pairs(data.notes) do		local rows = {} for noteSymbol, noteData in pairs(notes) do			local result = p.main({				system = system,				notes = {noteSymbol},			}) local imageLink = ("File:%s"):format(noteData.file) table.insert(rows, {cells = {noteSymbol, result, imageLink}}) end table.insert(tableData.tabs, {			label = system,			rows = rows		}) end return utilsLayout.tabbedTable(tableData) end return p