gambas-source-code/comp/src/gb.chart/_CLegend.class
Benoît Minisini ba19f3c1dd * Copy https://gambas.svn.sourceforge.net/svnroot/gambas/2.0 to https://gambas.svn.sourceforge.net/svnroot/gambas/gambas
git-svn-id: svn://localhost/gambas/trunk@893 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2007-12-30 16:41:49 +00:00

184 lines
4.1 KiB
Text

' Gambas class file
EXPORT
'PUBLIC CONST Top AS Integer = 1
PUBLIC CONST Bottom AS Integer = 2
'PUBLIC CONST {Left} AS Integer = 3
PUBLIC CONST {Right} AS Integer = 4
PRIVATE $iWidth AS Integer
PRIVATE $iHeight AS Integer
PRIVATE $iPosition AS Integer = ME.Right
PRIVATE $sTitle AS String
PRIVATE $bVisible AS Boolean = FALSE
PRIVATE $oFont AS NEW Font
PROPERTY {Font} AS Font
PROPERTY Title AS String
PROPERTY Position AS Integer
PROPERTY Visible AS Integer
PROPERTY READ _Width AS Integer
PROPERTY READ _Height AS Integer
PUBLIC SUB _New()
ME.Font.Size = 11
END
PRIVATE FUNCTION Title_Read() AS String
RETURN $sTitle
END
PRIVATE SUB Title_Write(Value AS String)
$sTitle = Value
END
PRIVATE FUNCTION Position_Read() AS Integer
RETURN $iPosition
END
PRIVATE SUB Position_Write(Value AS Integer)
$iPosition = Value
END
PRIVATE FUNCTION Visible_Read() AS Integer
RETURN $bVisible
END
PRIVATE SUB Visible_Write(Value AS Integer)
$bVisible = Value
END
PUBLIC SUB Draw(bSeries AS Boolean)
DIM x, y, w, h AS Integer
DIM S AS String
DIM i, cnt AS Integer
DIM SQUARESIZE AS Integer
DIM TitleH AS Integer
'DIM hColumn AS _Column
DIM iStaticSpace AS Integer = 5 * Chart._fProportionnal
DIM arsInt AS String[]
DIM oSerie AS _CSerie
$iWidth = 0
$iHeight = 0
'Créé un tableau interne contenant soit les série soit les entête
IF bSeries THEN
arsInt = NEW String[]
FOR EACH oSerie IN Chart
arsInt.Add(oSerie.Text)
NEXT
ELSE
arsInt = Chart.Headers.Values
ENDIF
IF NOT $bVisible THEN RETURN
w = Chart.Width
h = Chart.Height
'draw.Font = Chart.Font
'Get the max text length
FOR EACH s IN arsInt
i = draw.TextWidth(s)
IF i > cnt THEN cnt = i
NEXT
draw.Font.Size = $oFont.Size * Chart._fProportionnal
SQUARESIZE = draw.TextHeight("T")
SELECT CASE $iPosition
CASE ME.Right
IF draw.TextWidth(Chart.Legend.Title) > cnt THEN cnt = draw.TextWidth(Chart.Legend.Title)
w = iStaticSpace + SQUARESIZE + iStaticSpace + cnt + iStaticSpace
IF $sTitle <> "" THEN TitleH = draw.TextHeight($sTitle)
h = TitleH + iStaticSpace + arsInt.Count * (draw.Font.Height() + iStaticSpace)
x = Chart.Width - w - iStaticSpace
y = (Chart.Height - h) / 2
draw.ForeColor = Color.Black
Draw.Rect(x, Y, w, h)
Draw.Text(Chart.Legend.Title, x + iStaticSpace + (w - cnt) / 2, Y)
draw.Font.Size = $oFont.Size * Chart._fProportionnal
cnt = 0
FOR i = 0 TO arsInt.max
Draw.FillColor = Chart.Colors[i]
Draw.FillStyle = Fill.Solid
Draw.Rect(x + iStaticSpace, Y + TitleH + iStaticSpace + cnt, SQUARESIZE, SQUARESIZE)
Draw.Text(arsInt[i], x + iStaticSpace + SQUARESIZE + iStaticSpace, Y + TitleH + iStaticSpace + cnt)
cnt += Draw.Font.Height() + iStaticSpace
NEXT
$iWidth = w + iStaticSpace
$iHeight = 0
CASE Bottom
IF $sTitle <> "" THEN TitleH = draw.TextHeight($sTitle)
h = iStaticSpace + TitleH + iStaticSpace + SQUARESIZE + iStaticSpace
w = 0
FOR EACH s IN arsInt
w += iStaticSpace + SQUARESIZE + 5 + draw.TextWidth(s) + iStaticSpace
NEXT
w += iStaticSpace
Draw.Rect((Chart.Width - w) / 2, Chart.Height - h - iStaticSpace, w, h)
Draw.Text($sTitle, (Chart.Width - Draw.TextWidth($sTitle)) / 2, Chart.Height - h)
x = (Chart.Width - w) / 2
y = Chart.Height - h + TitleH + iStaticSpace
i = 0
draw.Font.Size = $oFont.Size * Chart._fProportionnal
FOR EACH s IN arsInt
x += iStaticSpace
draw.FillColor = Chart.Colors[i]
Draw.FillStyle = Fill.Solid
draw.Rect(x, y, SQUARESIZE, SQUARESIZE)
x += SQUARESIZE + iStaticSpace
draw.Text(s, x, y)
x += draw.TextWidth(s) + iStaticSpace
INC i
NEXT
$iWidth = 0
$iHeight = h + iStaticSpace
END SELECT
END
PRIVATE FUNCTION _Width_Read() AS Integer
RETURN $iWidth
END
PRIVATE FUNCTION _Height_Read() AS Integer
RETURN $iHeight
END
PRIVATE FUNCTION Font_Read() AS Font
RETURN $oFont
END
PRIVATE SUB Font_Write(Value AS Font)
$oFont = Value
END