Sari la conținut

Modul:Overlay

De la Wikipedia, enciclopedia liberă

This template is called Overlay in Wikipedia. It is called Overlay legend in Commons.

In Wikipedia Overlay legend and Legend overlay redirect to Overlay.

Image overlay

[modificare sursă]

Allows image numbered, textual number, or colour tag overlays to be positioned over an image to indicate particular features in the image.

Up to 30 overlays can be positioned over the image. Any overlay can be placed over the image up to 3 times, to indicate multiple locations of the same feature in the image.

Typical colours of overlays are as follows:

Color name Example
red (default)
1
50
blue
1
50
green
1
50
brown
1
50
saddlebrown 
1
50
yellow
1
50

The colour of each overlay can be individually set. Each overlay inherits its colour from the previous overlay, so only the first of any colour grouped overlays needs to have its colour set.

Each overlay is configurably wikilinkable by the template.

The overlays can be turned off by setting overlay to 'no', which will result in the only the image and legend being displayed. This is particularly useful when the image itself already includes the overlays and-or colour tagging. See Spider's main organs below for example.

Overlay legend

[modificare sursă]

A legend of the text for each overlay is displayed by default, in 3 columns, under the image.

The legend can be turned off by setting the number of columns to '0'.

The legend can be grouped into groups of overlays, explicitly up to 6 groups. Each explicit legend grouping can optionally be given a title.

The number of overlay legend text items in each column is automatically balanced by the template across the columns within each legend grouping.

If the start overlay item for the first explicit grouping is after the first overlay item then the overlay text items from the first overlay up to but not including the first explicitly grouped overlay item are displayed as an untitled grouping before the first explicit group.

If an end overlay item is specified for any explicit grouping and there is no following explicit grouping, then the remainder of the overlay items are displayed as an untitled grouping after the last explicit group.

By setting the start of the first explicit grouping after the first overlay item and the end of the sixth explicit grouping before the last overlay item, effectively 8 groupings can be configured, the first and eighth being untitled.

Deficiences

[modificare sursă]

Automatic column balancing

[modificare sursă]

While the template will handle missing set overlay values at the start, that is the first overlay item does not have to be overlay1, the template treats intermediate missing overlays as though they exist for column balancing, and it does not allow for any text wrapped new lines within an overlay item's text.

Undeterminable legend start and ends

[modificare sursă]

If legend titles are provided without a corresponding start or end and the template cannot explicitly determine one from an adjacent legend then it will "guess" and unexpected results might be produced, which might not be stable with any template updates.

Legend start and end ranges can be overlapped. This is either a deficiency or a feature depending on how you look at it. However, overlapping ranges might result in unexpected behaviour, which might not be stable with any template updates.

Double quotes in pop up tips for overlays

[modificare sursă]

Double quotes, ", cannot be placed in overlay tips when form = text or when form = colour are used. To include a double quote use its HTML coding, ".

Double quotes are always allowed in the overlay, but if the overlay tip for that overlay is not set separately, the tip, which defaults to the same text as the overlay, will probably not display correctly. The overlay tip for an overlay with double quotes in it should always be set explicitly when form = text or when form = colour are used.

This is a colour/color friendly template. Either spelling can be used for any parameter value or any parameter name.

{{overlay
| image        = 
| width        = 
| height       = 
| columns      = 
| grid         = 
| link         = 
| legendbox    = 
| float        = 
| overlay      = 
| border       = 
| legend1title = 
| legend1start = 
| legend1end   = 
<!-- ...up to 6... -->
| overlay1form = 
| overlay1     = 
| overlay1colour = 
| overlay1tip  = 
| overlay1left = 
| overlay1top  = 
| overlay1link = 
<!-- ...up to 30... -->
}}

Editing grid and coordinates

[modificare sursă]

To assist in determining the position of each overlay a coordinate grid showing from the left ordinates and from the top ordinates can be displayed by setting the grid parameter to yes:

| grid         = yes

The coordinate grid is 900 x 900, so if the image is set to be smaller than this, the page content may be off scrolled, etc. The presentation will return to normal when the grid parameter is removed or set to a value other than yes.

Note that the top ordinate is the position of the top of the overlay from the top of the image and the left ordinate is the left of the overlay from the left of the image.

Form = colour

[modificare sursă]

When setting

| overlayNform = colour

then the overlays still use up numbered positions within the list of overlays. Accordingly, if using a mixture of image and-or text forms with colour forms, then gaps will appear in the number sequence where a colour form overlay is specified.

It might be generally best if colour form overlays are always set as the last overlays. See Spider's main organs below for example.

Full minimal skeleton

[modificare sursă]

To assist editors, a full 30 overlays but minimal skeleton is provided below:

Note: The data in these examples is not necessarily correct.

Brisbane (with grid turned on)

[modificare sursă]
1
Jack Pesch Bridge, Walter Taylor Bridge (road) (left), Albert Bridge (rail) (center), unnamed bridge (rail) (right)
Eleanor Schonell Bridge (Green Bridge) (pedestrians, pedal cycles, buses)
Merivale Bridge (rail)
William Jolly Bridge (road)
Victoria Bridge
Captain Cook Bridge
Story Bridge
Pacific Motorway
Suncorp Stadium (Lang Park) (Rugby league/Rugby Union/Soccer ground)
Norman Creek
Oxley Creek
Brisbane River
Indooroopilly Shoppingtown
"The Gabba" (Woolloongabba cricket ground)
South Bank arts and recreation precinct
Central business district
17
University of Queensland (UoQ) St Lucia Campus
City Botanic Gardens
19
Queensland University of Technology (QUT) Gardens Point Campus
Goodwill Bridge (pedestrians and pedal cycles)
21
Hospital
Mater Private Hospital
Roma Street Rail Station
Roma Street Parkland
New Farm Park
26
Victoria Park Golf Course
Royal National Association Exhibition Grounds
28
Floating pedestrian concourse
Inner City Bypass (rail) (left) (road) (right)
30
Long Pocket Golf Course

Charlotte Pass Village

[modificare sursă]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Accommodation and service buildings in Charlotte Pass Village
1
Kosciuszko Chalet Hotel
2
Charlotte Pass Ski Centre
3
Bella Vista Staff Lodge (Cell Block, Cellavista)
4
Kosciuszko Alpine Club
5
Knockshannoch Lodge
6
Jerrabomberra Lodge
7
Spencer's Creek Lodge
8
Stillwell Lodge
9
Southern Alps Ski Lodge
10
Pygmy Possum Lodge
11
Snowbird Lodge
12
Arlberg Lodge
13
Burrawong Lodge
14
Alitji Lodge
15
Tar Gan Gil Lodge
Other facilities and features (Guthries Poma (Platter lift) and Pulpit T-Bar not shown)
16
Sewage plant (Shakespear's Lodge)
17
Basin Poma
18
Kosi Carpet (Magic Carpet (Moving carpet))
19
Kangaroo Ridge Triple Chairlift
20
"Fox hole" at the eastern end of Stillwell Ridge
21
Workshop

Spider's main organs (pre labelled image)

[modificare sursă]
Spider's main organs[1]
1Fang (chelicera)
2Venom gland
3Brain
4Pumping stomach
5Forward aorta branch
6Digestive cecum
7Heart
8Midgut
9Malphigian tubules
10Cloacal chamber
11Rear aorta
12Spinneret
13Silk gland
14Trachea
15Ovary (female)
16Book lung
17Nerve cord
18Legs
19Pedipalp
Physiological systems[1]
  Nervous system
  Digestive & excretory system
  Circulatory system
  Respiratory system
  Reproductive system

Template parameters

[modificare sursă]
Parameter Name Required Description Values
image no The image. If not set then only the legend is presented. Image file name.
width no Width of the image in pixels. Defaults to 500. Number.
height no Height of the image in pixels. Defaults to 500. Number.
columns no The number of columns to display the legend in. Defaults to 3. Set to 0 to not display any legend. Number == 0, 1, 2, 3, . . .
grid no Set to 'yes' to turn on the coordinate grid to allow easier determination of overlay coorindates while editing. Defaults to 'no'. All values other than 'yes' are equivalent to 'no'. Text == yes.
link no Set to 'yes' to turn on default linking of overlay and legend entry. Defaults to 'no'. All values other than 'yes' are equivalent to 'no'. Text == yes.
legendbox no Set to 'no' to turn off a box / border around each legend group set of overlays. Defaults to 'yes'. All other values other than 'no' are equivalent to 'yes'. Text == no.
float no Floats the image and legend. Defaults to centering the image and legend on the page. Text == right, left.
overlay no Determines whether or not the overlays are presented when an image is available. Defaults to 'yes'. All values other than 'no' are equivalent to 'yes'. Text == no.
border no Determines whether or not a border is placed around the whole presentation. Defaults to 'yes'. All values other than 'no' are equivalent to 'yes'. Text == no.
legend1title no Text for legend1 title. Optionally linked text.
legend1start no The number of the first overlay to appear in legend1. Defaults to the first overlay set, otherwise to the previous legend end plus 1 if there is a previous legend. Number == 1, . ., 30.
legend1end no The number of the last overlay to appear in legend1. Defaults to the next legend start less 1 if there is a next legend, otherwise to the last set overlay. Number == 1, . ., 30.
Both legend starts and legend ends do not need to be provided. Legend starts only, or, legend ends only, for each legend may be provided.
overlay1form no The form of the overlays. The default form is an image number, for example,
1
. Other settings allow textual numbers, for example, 1, or coloured tags, for example,   . Defaults to the previous overlay form, or to 'image' if no previous overlay form.
Text == image, text, colour/color.
overlay1 no Text for overlay1 for the legend. Defaults to overlay1tip if any. Text. Do not link. The template will link.
overlay1colour no Colour of overlay1. Defaults to the previous overlay colour, or to 'red' if no previous overlay colour. Text == red, green, blue.
overlay1tip no Pop up tool tip text to appear when the screen pointer is over overlay1. Defaults to overlay1. Text.
overlay1left no Distance in pixels of the left edge of overlay1 from the left side of the image. Number.
overlay1top no Distance in pixels of the top edge of overlay1 from the top side of the image. Number.
overlay1link no Text to be used as a link for the overlay legend text. Defaults to overlay1 if link is not set to no. Text. Do not link.
overlay1left1 no The same as overlay1left. As per overlay1left.
overlay1top1 no The same as overlay1top. As per overlay1top.
overlay1left2 no The left ordinate for a second position of overlay1. As per overlay1left.
overlay1top2 no The top ordinate for a second position of overlay1. As per overlay1top.
overlay1left3 no The left ordinate for a third position of overlay1. As per overlay1left.
overlay1top3 no The top ordinate for a third position of overlay1. As per overlay1top.
  • {{Annotated image}}, allows text notes to overlap image, allows cropping
  • {{Site plan}}, to relatively position a marker image over a map image with selectable map, markers, and size
  • {{Superimpose}}, absolutely position one image over another
  • {{Superimpose2}}, to place up to 50 image layers over one another
  • {{Location map}}, places a single image over another at a map coordinate location

References and notes

[modificare sursă]
  1. ^ a b Ruppert, E.E.; Fox, R.S. & Barnes, R.D. (). Invertebrate Zoology (ed. 7). Brooks / Cole. pp. 571–584. ISBN 0030259827. 

-- this module implements [[Format:Overlay]]
local p = {}

local mArguments = require('Modul:Arguments')

-- used to cache the calculated font color to avoid repeat calculations
local previous_backgroundcolor = ''
local fontcolor = ''

local function buildicon(n, form, lk, c, t)
	local res
	if form == 'text' then
		return tostring(
				mw.html.create('span')
					:css('font-weight', 'bold')
					:css('color', c)
					:wikitext(n)
				)
	elseif form == 'color' or form == 'colour' then
		return tostring(
				mw.html.create('span')
					:css('background-color', c)
					:wikitext('&#160;&#160;')
				)
	else
		-- check if the color is difference from the previous color
		if c ~= previous_backgroundcolor then
			-- color changed, so look up the best font color
			local greatercontrast = require('Modul:Color contrast')._greatercontrast
			fontcolor = greatercontrast{c, 'white', 'black', bias = 1.3}
			-- update the previous value for the next check
			previous_backgroundcolor = c
		end
		-- build the inner span for the icon
		local span = mw.html.create('span')
			:css('color', fontcolor)
			:css('font-size', '88%')
			:css('font-weight', 'bold')
			:attr('title', t)
			:wikitext(n)
		-- build the outer div
		local div = mw.html.create('div')
			:css('display', 'inline-block')
			:css('width', 'auto')
			:css('height', 'auto')
			:css('text-align', 'center')
			:css('padding', ((tonumber(n) or 0) < 10) and '0px 4px' or '0px 2px')
			:css('vertical-align', 'middle')
			:css('-moz-border-radius', '3px')
			:css('-webkit-border-radius', '3px')
			:css('border-radius', '3px')
			:css('background-color', c)

		-- link the inner span if requested and insert in the div
		if lk ~= '' then
			div:wikitext('[[:' .. lk .. '|' .. tostring(span) .. ']]')
		else
			div:wikitext(tostring(span))
		end
		-- convert to a string
		return tostring(div)
	end
end

local function buildlegend(data, cols, border, caption)
	-- create the outer table to hold the columns
	local root = mw.html.create('table')
		:css('width', '100%')
		:css('border', (border ~= 'no') and '1px #ccc solid' or '')
	-- create the outer row which will contain the columns
	local outerrow = root:tag('tr')
	local percol = math.ceil((#data) / cols)
	local k = 0
	for j=1,cols do
		-- create the outer cell to hold this column
		local colcell = outerrow:tag('td')
			:css('width', (math.floor(10/cols)/10) .. '%')
			:css('vertical-align', 'top')
		-- create the inner table to hold the entries in the column
		local coltable = colcell:tag('table')
			:css('width', '100%')
			:css('font-size', '85%')
			:css('line-height', '95%')
		-- add the entries to the column
		for l = 1,percol do
			k = k   1
			if k <= #data then
				local rdata = data[k]
				local tr = coltable:tag('tr'):css('vertical-align','top')
				tr:tag('td')
					:css('width', '12px')
					:css('text-align', 'right')
					:css('padding-bottom', '2px')
					:wikitext(rdata[1] or '')
				tr:tag('td')
					:css('padding-bottom', '2px')
					:wikitext(rdata[2] or '')
			end
		end
	end
	return caption .. tostring(root)
end

local function buildlegenditem(im, lk, t)
	local res = {im, ''}
	if t ~= '' then
		if lk ~= '' then
			res[2] = '[[:' .. lk .. '|' .. t .. ']]'
		else
			res[2] = t
		end
	else
		res[2] = '[[:' .. lk .. '|' .. lk .. ']]'
	end
	return res 
end

function p.icon(frame)
	local args = mArguments.getArgs(frame)
	return tostring(
		mw.html.create('div')
			:css('display', 'inline-block')
			:css('line-height', '95%')
			:wikitext(buildicon(args['1'] or '', 
								args['form'] or 'icon',
								args['link'] or '', 
								args['2'] or 'red',
								args['tip'] or ''))
	)
end

function p.main(frame)
	local args = mArguments.getArgs(frame)
	
	local image = args['image'] or ''
	local width = tonumber(args['width'] or '500') or 500
	local height = tonumber(args['height'] or '500') or 500
	local columns = tonumber(args['columns'] or '3') or 3
	local grid = ((args['grid'] or ''):lower() == 'yes') and 'yes' or 'no'
	local legendbox = ((args['legendbox'] or ''):lower() == 'no') and 'no' or 'yes'
	local overlay = (image == '') and 'no' or ( ((args['overlay'] or ''):lower() == 'no') and 'no' or 'yes' )
	local float = args['float'] or 'center'
	local border = ((args['border'] or ''):lower() == 'no') and 'no' or 'yes'
	local padding = args['padding'] or ''

	-- create the root table
	local root = mw.html.create('table')
	if float == 'center' or float == 'centre' then
		root:css('margin-left', 'auto')
			:css('margin-right', 'auto')
	elseif float == 'right' then
		root:css('float', 'right')
			:css('clear', 'right')
			:css('margin-left', '1em')
	elseif float == 'left' then
		root:css('float', 'left')
			:css('clear', 'left')
			:css('margin-right', '1em')
	else
		root:css('float', float)
	end
	if border == 'yes' then
		root:css('border', '1px #ccc solid')
	end

	-- create a list of all the overlay numbers
	local itemnums = {}
	for k, v in pairs( args ) do
		local i = tonumber(tostring(k):match( '^%s*overlay([%d] )%s*$' ) or '-1')
		if i > -1 then
			table.insert(itemnums, i)
		else
			i = tonumber(tostring(k):match( '^%s*overlay([%d] )tip%s*$' ) or '-1')
			if i > -1 then
				table.insert(itemnums, i)
			end
		end
	end
	-- sort to process in order
	table.sort( itemnums )
	
	-- remove duplicates
	for k = 2,#itemnums do
		if itemnums[k] == itemnums[k-1] then
			table.remove(itemnums, k)
		end
	end

	-- build the overlay markers and text
	itemdata = {}
	local colori = args['color'] or args['colour'] or 'red'
	local formi = ''	
	for k = 1,#itemnums do
		local i = itemnums[k]
		formi = args['overlay' .. i .. 'form'] or formi
		colori = args['overlay' .. i .. 'color'] or args['overlay' .. i .. 'colour'] or colori
		local linki = args['overlay' .. i .. 'link'] or ''
		local tipi = args['overlay' .. i .. 'tip'] or args['overlay' .. i] or ''
		local overlayi = args['overlay' .. i] or args['overlay' .. i .. 'tip'] or ''
		if (overlayi ~= '' or tipi ~= '') then
			local imagei = buildicon(i, formi, linki, colori, tipi)
			itemdata[k] = buildlegenditem(imagei, args['overlay' .. i .. 'link'] or '', overlayi)
		end
	end

	-- create the overlay image
	if image ~= '' then
		local cell = root:tag('tr'):tag('td')
		cell:attr('align', 'center')
		if( padding ~= '' ) then
			cell:css('padding', padding)
		end
		if( columns > 1 and legendbox == 'yes' ) then
			cell:attr('colspan', columns)
		end
		local imagediv = cell:tag('div')
		imagediv:css('position','relative')
			:css('left', '0px')
			:css('top', '0px')
			:css('width', ((grid == 'yes') and 940 or width) .. 'px')
			:css('height', ((grid == 'yes') and 940 or height) .. 'px')
		if grid == 'yes' then
			imagediv:tag('span')
				:css('position', 'absolute')
				:css('left', '0px')
				:css('top', '0px')
				:css('z-index', '2')
				:wikitext('[[File:Grid 99, 100 int red 50 int yellow (940).svg|940px]]')
		end
		imagediv:tag('span')
			:css('position', 'absolute')
			:css('left', '0px')
			:css('top', '0px')
			:css('z-index', '0')
			:css('width', width .. 'px')
			:css('height', height .. 'px')
			:wikitext('[[File:' .. image .. '|' .. width .. 'x' .. height .. 'px]]')
		if overlay == 'yes' then
			for k = 1,#itemnums do
				local i = itemnums[k]
				local imagei = (itemdata[k])[1]
				for j =0,3 do
					local overlayileftj = args['overlay' .. i .. 'left' .. ((j == 0) and '' or j)] or ''
					local overlayitopj = args['overlay' .. i .. 'top' .. ((j == 0) and '' or j)] or ''
					if overlayileftj ~= '' then
						imagediv:tag('div')
							:css('position', 'absolute')
							:css('left', overlayileftj .. 'px')
							:css('top', overlayitopj .. 'px')
							:css('line-height', '95%')
							:css('z-index', '1')
							:wikitext(imagei)
					end
				end
			end
		end
	end

	-- Split the legend items into sub-legends
	legend = {{}, {}, {}, {}, {}}
	local jmax = itemnums[#itemnums]
	for i=1,5 do
		if args['legend' .. i .. 'start'] then
			-- default is all items
			j1 = 0
			j2 = jmax
			-- set start item number to (legendistart) or (legend(i-1)end   1)
			if args['legend' .. i .. 'start'] then
				j1 = tonumber(args['legend' .. i .. 'start']) or j1
			elseif args['legend' .. (i-1) .. 'end'] then
				j1 = (tonumber(args['legend' .. (i-1) .. 'end']) or j1)   1
			end
			-- set end item number to (legendiend) or (legend(i 1)start - 1)
			if args['legend' .. i .. 'end'] then
				j2 = tonumber(args['legend' .. i .. 'end']) or j2
			elseif args['legend' .. (i 1) .. 'start'] then
				j2 = (tonumber(args['legend' .. (i 1) .. 'start']) or j2) - 1
			end
			-- get the items within the range, marking them as they are used
			for k=1,#itemnums do
				j = itemnums[k]
				if (j >= 0 and j >= j1 and j <= j2) then
					table.insert(legend[i], itemdata[k])
					itemnums[k] = -1
				end
			end
		end
	end

	-- Add any left over items to the first legend
	for k = 1,#itemnums do
		if itemnums[k] >= 0 then
			table.insert(legend[1], itemdata[k])
		end
	end

	-- Build the legend
	if columns > 0 then
		for i = 1,5 do
			local locallegend = legend[i]
			if (locallegend and #locallegend > 0) then
				local cell = root:tag('tr'):tag('td')
				cell:wikitext(buildlegend(locallegend, columns, border, args['legend' .. i .. 'title'] or ''))
			end
		end
	end

	return tostring(root)
end

return p