Unstable commit

[GB.CHART2]

* Unstable commit don't use it
This commit is contained in:
gambix 2019-10-09 17:52:42 +02:00
parent 044bdc222e
commit 89a631f6bc
14 changed files with 600 additions and 82 deletions

View file

@ -1,6 +1,6 @@
[Component]
Key=gb.chart2
Version=0.0.3
Version=0.0.4
State=2
Authors=Fabien Bodard <gambas.fr@gmail.com>
Needs=Form

View file

@ -1,6 +1,6 @@
# Gambas Project File 3.0
Startup=Form1
Version=0.0.3
Startup=FPie
Version=0.0.4
Component=gb.image
Component=gb.gui
Component=gb.form

View file

@ -19,7 +19,7 @@ Private $aStyleList As String[] = ["Bar"]
Public Sub _new()
$hLegend = New _ChartLegend As "Legend"
$hTitle = New _ChartTitle
$hTitle = New _ChartTitle As "Title"
$bBorder = True
$aStyleList.ReadOnly = True
$aColors = [&hff6f00,
@ -51,14 +51,13 @@ Public Sub Paint(X As Integer, Y As Integer, Width As Integer, Height As Integer
If $bAutoScale Then _fProportionnal = IIf(Paint.Width <= Paint.Height, Paint.Width / (Desktop.Height * 2 / 3), Paint.Height / (Desktop.Height * 2 / 3))
'Paint.Scale(f, f)
hRect = RectF(X, Y, Width, Height)
If $hTitle.Visible And If $hTitle.Text Then
Paint.Font = $hTitle.Font
Paint.Font.Size = Paint.Font.Size * _fProportionnal
f = $hTitle.Font.Height * 1.5 * _fProportionnal
Paint.DrawText($hTitle.Text, X, Y, Width, f, Align.Center)
f = $hTitle._Paint(Width)
Endif
Y = Y + f
hRect = RectF(X, Y, Width, Height)
Height = Height - f
If $hLegend.Visible Then
hRect = $hLegend._Paint(0, Y, Width, Height)
@ -70,7 +69,7 @@ Public Sub Paint(X As Integer, Y As Integer, Width As Integer, Height As Integer
hRect = RectF(X, Y, Width, Height - hRect.H)
Case Align.Left
hRect = RectF(X + hRect.W, Y, Width, Height)
hRect = RectF(X + hRect.W, Y, Width - hRect.W, Height)
Case Align.Right
hRect = RectF(X, Y, Width - hRect.W, Height)
@ -82,7 +81,7 @@ Public Sub Paint(X As Integer, Y As Integer, Width As Integer, Height As Integer
If $bBorder Then
Paint.LineWidth = 2
Paint.DrawRect(0, 0, Width, Height, Color.Black)
Paint.DrawRect(0, 0, Width, Height + f, Color.Black)
Endif
@ -93,10 +92,10 @@ End
Public Sub SetStyle(sStyle As String)
Select Case (sStyle)
Case "Bar"
Select Case LCase(sStyle)
Case "bar"
$hStyle = New _ChartStyleBarBasic As "ChartStyleBarBasic"
Case "Pie"
Case "pie"
$hStyle = New _CharStylePie As "ChartStylePie"
End Select

View file

@ -0,0 +1,25 @@
' Gambas class file
Export
Inherits UserControl
Private $hChart As New Chart
Private $hView As DrawingArea
Public Sub _new()
$hView = New DrawingArea(Me) As "View"
$hChart.SetStyle("bar")
$hChart.Labels = ["1", "2", "3", "4"]
$hChart.Datas = [ChartDatas("Serie 1", [1, 2, 3, 4])]
$hChart.AutoScale = True
End
Public Sub View_Draw()
$hChart.Paint(0, 0, Paint.Width, Paint.Height)
End

View file

@ -12,7 +12,7 @@ End
Private Sub IniChart1()
hChart.Labels = ["Jan 14", "Fév", "Mar", "Avr", "Mai", "Jui", "Jui", "Aou", "Sep", "Oct", "Nov", "Déc"]
hChart.Datas = [ChartDatas("Serie 1", [-16, -12, -6, -1, 5, 14, 29, 22, 13, 3, -6])] ', ChartDatas("Serie 2", [1.0, 2, 3, 4, 5, 3.5]), ChartDatas("Serie 3", [1.0, 2, 3, 4, 5, 3.5])]
hChart.Datas = [ChartDatas("Serie 1", [-16, -12, -6, -1, 5, 14, 29, 22, 13, 3, -6, -10])] ', ChartDatas("Serie 2", [1.0, 2, 3, 4, 5, 3.5]), ChartDatas("Serie 3", [1.0, 2, 3, 4, 5, 3.5])]
'hChart.Datas = [ChartDatas("Serie 1", [1.0, 2, 3, 4, 5, 6.5]), ChartDatas("Serie 2", [1.2, 2.3, 3.4, 4.5, 5.6, 3.5]), ChartDatas("Serie 3", [1.3, 2.4, 3.5, 4.6, 5.7, 3.5])]
hChart.Border = True
hChart.Colors = [Color.Orange]

View file

@ -1,19 +1,54 @@
' Gambas class file
Private hChart As New Chart
Private aSerie As Float[] = [1.0, 2, 3, 4, 5, 6.5]
Private hTimer As New Timer As "Timer"
Private $fRotate As Float
Public Sub Form_Open()
hTimer.Delay = 10
hChart.Labels = ["Tic", "Tac", "Toe", "Titi", "Toto", "Tata"]
hChart.Datas = [ChartDatas("Serie 1", [1.0, 2, 3, 4, 5, 6.5])]
hChart.Datas = [ChartDatas("Serie 1", aSerie)]
hChart.SetStyle("Pie")
hChart.AutoScale = True
hChart.Legend.Border = Border("Padding:5")
hChart.Legend.Visible = True
hChart.Title.Visible = True
hChart.Title.Text = "A beautifull pie Chart"
hChart.Title.Color = Color.Orange
hChart.Title.Font = Font["+10"]
hChart.Legend.Title = "Chart values"
'hChart.Background = Color.Lighter(Color.Lighter(Color.Yellow))
hChart.Legend.Position = Align.Right
With hChart
.Legend.SymbolOutlineColor = Color.Transparent
'.Legend!InterlineColor = Color.LightGray
.Legend.InterlineWidth = 2
'.Legend.Background = Color.Lighter(Color.Yellow)
.Legend.Border = Border("width:2;radius:5;Padding:10;Style:2;color:gray")
.Legend.SymbolStyle = "circle"
.Legend.TitleColor = Color.Darker(Color.Orange)
.Legend.Color = Color.Darker(Color.Orange)
.Legend.TitleSpacing = 20
.Legend.TitleFont = Font["+5"]
.Legend.Font = Font["+5"]
.Legend.Spacing = 20
.Legend.Width = 200
.Style!Border = True
.Style!Background = Color.Yellow
.Style!Padding = 30
.Style!OutlineColor = Color.White
.Style!OutlineWidth = 2
.Style!Padding = 40
.Legend.InterlineColor = Color.LightGray
'.Style!ShowLabels = True
End With
End
@ -22,3 +57,21 @@ Public Sub DrawingArea1_Draw()
hChart.Paint(0, 0, Paint.W, Paint.H)
End
Public Sub Timer_Timer()
$fRotate = $fRotate + 0.5
If $fRotate = 361 Then $fRotate = 0
hChart.Style!Rotate = $fRotate
DrawingArea1.Refresh
End
Public Sub Button1_Click()
hTimer.Enabled = Not hTimer.Enabled
End

View file

@ -2,10 +2,14 @@
{ Form Form
MoveScaled(0,0,64,64)
Arrangement = Arrange.Horizontal
Arrangement = Arrange.Vertical
Margin = True
{ DrawingArea1 DrawingArea
MoveScaled(3,2,57,58)
MoveScaled(3,2,57,54)
Expand = True
}
{ Button1 Button
MoveScaled(5,58,53,4)
Text = ("Depart")
}
}

View file

@ -0,0 +1,8 @@
' Gambas class file
Public Sub Form_Open()
End

View file

@ -0,0 +1,9 @@
# Gambas Form File 3.0
{ Form Form
MoveScaled(0,0,64,64)
Arrangement = Arrange.Fill
{ ChartView1 ChartView
MoveScaled(7,4,51,51)
}
}

View file

@ -4,16 +4,22 @@ Inherits _ChartStyle
Property Read Symbols As String[] Use $aSymbols
Private $oLabelsFont As Font
Private $fPadding As Float
Private $bShowValues As Boolean
Private $bPercentage As Boolean
Private $iOulineColor As Integer
Private $fOutlineWidth As Float = 1
Private $bShowLabels As Boolean
Private $fRotate As Float
Event Foo
Public Sub _new()
$aSymbols = Super.Symbols.Insert(["LabelsFont"])
$aSymbols = Super.Symbols.Insert(["LabelsFont", "Padding", "ShowLabels", "Showvalues", "Percentage", "OutlineColor", "OutlineWidth", "Rotate"])
'$aSymbols.ReadOnly = True
$oLabelsFont = Font["+4"]
$oLabelsFont = Font["+2"]
End
@ -23,6 +29,20 @@ Public Sub _get(Symbol As String) As Variant
Select Case Symbol
Case "LabelsFont"
Return $oLabelsFont
Case "Padding"
Return $fPadding
Case "Showvalues"
Return $bShowValues
Case "Percentage"
Return $bPercentage
Case "OutlineColor"
Return $iOulineColor
Case "OutlineWidth"
Return $fOutlineWidth
Case "ShowLabels"
Return $bShowLabels
Case "Rotate"
Return $fRotate
Case Else
Return Super[Symbol]
@ -37,6 +57,20 @@ Public Sub _put(Value As Variant, Symbol As String)
Select Case Symbol
Case "LabelsFont"
$oLabelsFont = Value
Case "Padding"
$fPadding = Value
Case "Showvalues"
$bShowValues = Value
Case "Percentage"
$bPercentage = Value
Case "OutlineColor"
$iOulineColor = Value
Case "OutlineWidth"
$fOutlineWidth = Value
Case "ShowLabels"
$bShowLabels = value
Case "Rotate"
$fRotate = Value
Case Else
Super[Symbol] = Value
End Select
@ -47,11 +81,18 @@ Public Function _GetParam(X As Integer, Y As Integer, Width As Integer, Height A
Dim hChart As Chart = Me._GetParent()
Dim hPr As Collection
Dim f As Float
hpr = Super._GetParam(X, Y, Width, Height)
If hChart.Datas.Count = 0 Then Return
For i As Integer = 0 To hChart.Datas[0].Values.Max
f += hChart.Datas[0].Values[i]
Next
hpr!Total = f
Return hpr
@ -59,10 +100,12 @@ End
Public Sub _PaintBefore(hParam As Collection)
Super._PaintBefore(hParam)
End
@ -70,10 +113,161 @@ End
Public Sub _PaintAfter(hParam As Collection)
Dim hChart As Chart = Me._GetParent()
End
Public Sub _PaintContent(hParam As Collection)
Dim w As Float
Dim hChart As Chart = Me._GetParent()
Dim angle, anglePrev As Float
Dim f As Float
Dim Tot As Float = hParam!Total
Dim hCenter, hPos As Pointf
Dim hRect, hTextRect As RectF
Dim i As Integer
Dim s As String
Dim fRadius As Float
Dim fAngleLabel, ftmp As Float
Dim aLabelRect As New RectF[]
Dim fTr As Float
'Dim hPos As PointF
Dim aLabPos As PointF[]
Dim fMaxLabelWidth As Float
Dim H, AlfH As Integer
Dim fLabelRadius As Float
Dim fPadding As Float = $fPadding * hChart._fProportionnal
Dim oLabelFont, oValueFont As Font
Dim fRotate As Float = $fRotate - 90
oLabelFont = $oLabelsFont.Copy()
oLabelFont.Size = Max(oLabelFont.Size * hChart._fProportionnal, 1)
oValueFont = oLabelFont.Copy()
oValueFont.Size = oLabelFont.Size * 0.6
Paint.Font = oLabelFont
H = Paint.Font.H
AlfH = H / 4
w = Min(hParam!Rect.W, hParam!Rect.H) - fPadding
hRect = RectF(hParam!Rect.X + (hParam!Rect.W - w) / 2, hParam!Rect.Top + (hParam!Rect.H - w) / 2, w, w)
'Paint.Rectangle(hRect.X, hRect.Y, hRect.W, hRect.H)
'Paint.stroke
hCenter = hRect.Center()
'Get the largest label
For i As Integer = 0 To hChart.Labels.Max
s = hChart.Labels[i]
fMaxLabelWidth = Max(Paint.TextSize(s).W, fMaxLabelWidth)
Next
fMaxLabelWidth = fMaxLabelWidth + AlfH * 2
fLabelRadius = hRect.W / 2 - fMaxLabelWidth
'If fLabelRadius * 2 + fMaxLabelWidth * 2 < hRect.W Then fLabelRadius = hRect.H / 2 - H
If $bShowLabels Then
fRadius = fLabelRadius - H
Else
fRadius = hRect.W / 2
Endif
For i As Integer = 0 To hChart.Datas[0].Values.Max
Paint.Font = oLabelFont
Paint.LineWidth = Me!OutlineWidth * hChart._fProportionnal
f = hChart.Datas[0].Values[i]
angle = f / Tot * 360
ftr = W / 2 - fRadius
Paint.Ellipse(hRect.X + fTr, hRect.Y + fTr, hRect.W - fTr * 2, hRect.H - fTr * 2, Rad(anglePrev + fRotate), Rad(angle), True)
Paint.Background = hChart.Colors[i Mod hChart.Colors.count]
Paint.fill(True)
Paint.Background = Me!OutlineColor
Paint.Stroke
'Endif
'compute point on the pie.~
'f = Sqr((hCenter.X - hRect.X) ^ 2 + (hCenter.Y - hRect.Y) ^ 2)
fAngleLabel = anglePrev + angle / 2
'Draw the Label Pos
If $bShowLabels Then
'compute the label Pos
hPos = PointF(hCenter.X + Cos(Rad(fAngleLabel + fRotate)) * fLabelRadius, hCenter.Y + Sin(Rad(fAngleLabel + fRotate)) * fLabelRadius)
s = hChart.Labels[i]
hTextRect = Paint.TextSize(s)
hTextRect.W += AlfH * 2
Paint.Background = Color.Black
If fAngleLabel > 0 And fAngleLabel <= 90 Then
hTextRect.Move(hPos.X, hPos.Y - hTextRect.H / 2)
Paint.DrawText(s, hTextRect.X, hTextRect.Y, hTextRect.W, hTextRect.H, Align.Right)
Paint.MoveTo(hPos.X + AlfH, hPos.Y)
Paint.RelLineTo(-AlfH, 0)
Else If fAngleLabel > 90 And fAngleLabel <= 180 Then
hTextRect.Move(hPos.X, hPos.Y - hTextRect.H / 2)
Paint.DrawText(s, hTextRect.X, hTextRect.Y, hTextRect.W, hTextRect.H, Align.Right)
Paint.MoveTo(hPos.X + AlfH, hPos.Y)
Paint.RelLineTo(-AlfH, 0)
Else If fAngleLabel > 180 And fAngleLabel <= 270 Then
hTextRect.Move(hPos.X - hTextRect.W, hPos.Y - hTextRect.H / 2)
Paint.DrawText(s, hTextRect.X, hTextRect.Y, hTextRect.W, hTextRect.H, Align.Left)
Paint.MoveTo(hPos.X - AlfH, hPos.Y)
Paint.RelLineTo(AlfH, 0)
Else
hTextRect.Move(hPos.X - hTextRect.W, hPos.Y - hTextRect.H / 2)
Paint.DrawText(s, hTextRect.X, hTextRect.Y, hTextRect.W, hTextRect.H, Align.Left)
Paint.MoveTo(hPos.X - AlfH, hPos.Y)
Paint.RelLineTo(AlfH, 0)
Endif
hPos = pointf(hCenter.X + Cos(Rad(fAngleLabel + fRotate)) * (fRadius - AlfH), hCenter.Y + Sin(Rad(fAngleLabel + fRotate)) * (fRadius - AlfH))
Paint.LineTo(hPos.X, hPos.Y)
'Paint.Rectangle(hTextRect.X, hTextRect.Y, hTextRect.W, hTextRect.H)
Paint.Stroke
Paint.Ellipse(hPos.X - 2, hPos.Y - 2, 4, 4)
Paint.Fill
Endif
anglePrev += angle
If $bShowValues Then
Paint.LineWidth = 1 * hChart._fProportionnal
Paint.Background = Color.Black
'Paint the values
Paint.Font = oValueFont
hPos = PointF(hCenter.X + Cos(Rad(fAngleLabel + fRotate)) * fRadius * 0.6, hCenter.Y + Sin(Rad(fAngleLabel + fRotate)) * fRadius * 0.6)
'Paint.Rectangle(hPos.X, hPos.Y, 2, 2)
Paint.Stroke
If $bPercentage Then
s = Str(Int(hChart.Datas[0].Values[i] / Tot * 100)) & " %"
Else
s = Str(hChart.Datas[0].Values)
Endif
hTextRect = Paint.TextSize(s)
hTextRect.W += AlfH
hTextRect.Move(hPos.X - hTextRect.W / 2, hPos.Y - hTextRect.H / 2)
Paint.Rectangle(hTextRect.X, hTextRect.Y, hTextRect.W, hTextRect.H, 3)
Paint.Background = Color.SetAlpha(Color.Black, 180)
Paint.Fill
Paint.Background = Color.White
Paint.DrawText(s, hTextRect.X, hTextRect.Y, hTextRect.W, hTextRect.H, Align.Center)
Endif
Next
For j As Integer = 0 To 360
' Paint.Background = Color.Green
' Paint.Fill
Next
End

View file

@ -1,37 +1,72 @@
' Gambas class file
Inherits _Frame
Property Title As String Use $sTitle
Property Position As Integer Use $iPosition
Property Visible As Boolean Use $bVisible
Property {Font} As Font Use $oFont
'Property {Font} As Font Use $oFont
Property SymbolStyle As String Use $sSymbolStyle
Property SymbolOutlineColor As Integer Use $iSymbolOutlineColor
Property ShowPercent As Boolean Use $bShowPercent
Property InterlineColor As Integer Use $iInterlineColor
Property InterlineWidth As Float Use $fInterlineWidth
Property Font As Font Use $oFont
Property TitleFont As Font Use $oTitleFont
'Property Background As Integer Use $iBackground
'Property Border As Border Use $hBorder
Property TitleColor As Integer Use $iTitleColor
Property Color As Integer Use $iColor
Property Spacing As Integer Use $iSpace
Property TitleSpacing As Integer Use $iTitleSpace
Property Width As Integer Use $iWidth
Property Frame As _Frame Use $hFrame
Event foo
Private $iBackground As Integer
Public Sub _new()
'$bVisible = True
$oFont = New Font
$iPosition = Align.Left
$oTitleFont = New Font
$iBackground = -1
$hFrame = New _Frame
End
Public Sub _Paint(X As Integer, Y As Integer, Width As Integer, Height As Integer) As Rectf
Dim hChart As Chart = _GetParent()
Dim hRect As New Rectf
Dim hInnerRect As Rect
Dim hTextRect As Rectf
Dim W As Float
Dim aLabels As String[] = hChart.Labels
Dim s As String
Dim H As Float
Dim f, j As Float
Dim f, j, Tot As Float
Dim i As Integer
Dim hPercentRect As RectF
Dim hBorder As New Border
Dim fSpace As Float = $iSpace * hChart._fProportionnal
Dim fTitleSpace As Float = $iTitleSpace * hChart._fProportionnal
' If $hBorder Then
' hBorder = $hBorder.Copy()
' Else
' hBorder = New Border
' Endif
'Paint.save
Paint.font = $oFont
Paint.Font.Size *= hChart._fProportionnal
'hBorder.Padding = 30
H = Paint.Font.H
' Paint.Rectangle(X, Y, Width, Height)
' Paint.Background = Color.Red
' Paint.Stroke
Paint.LineWidth = 1 * hChart._fProportionnal
Select Case $iPosition
@ -44,13 +79,24 @@ Public Sub _Paint(X As Integer, Y As Integer, Width As Integer, Height As Intege
hRect.Height = H * 3.5
hRect.W = H * 2 + f + aLabels.Max * (H * 1.2 + H / 2) ', Width - H * 2)
If $iWidth > 0 Then hRect.W = Max(hRect.W, $iWidth * hChart._fProportionnal)
hRect.X = (Width + -hRect.W) / 2
If $iPosition = Align.top Then
hRect.Y = Y + H
Else
hRect.Y = Height - hRect.H - H
hRect.Y = Y + Height - hRect.H - H
Endif
hBorder.Padding = Max(hBorder.Padding, 10)
i = hBorder.LeftPadding + hBorder.LeftWidth
hRect.X = hRect.X - i
hRect.Width = hRect.Width + i + hBorder.RightPadding + hBorder.Width
i = hBorder.TopPadding + hBorder.TopWidth
hRect.Y = hRect.Y - i
hRect.H = hRect.H + i + hBorder.BottomPadding + hBorder.BottomWidth
hInnerRect = hBorder.GetRect(hRect, True)
Paint.Rectangle(hRect.X, hRect.Y, hRect.W, hRect.H)
Paint.Stroke
hRect.H += H
@ -63,11 +109,8 @@ Public Sub _Paint(X As Integer, Y As Integer, Width As Integer, Height As Intege
f = hRect.X + H / 2
j = h * 1.5
For Each s In aLabels
Paint.Rectangle(f, hRect.Y + j, H, H)
Paint.Background = hChart.Colors[i Mod hChart.Colors.Count]
Paint.Fill(True)
DrawSymbol($sSymbolStyle, f, hRect.Y + j, H, H, hChart.Colors[i Mod hChart.Colors.Count], $iSymbolOutlineColor)
Paint.Background = Color.Black
Paint.Stroke
f += H * 1.2
Paint.DrawText(s, f, hRect.Y + j + H / 1.3)
f += Paint.TextSize(s).W + H / 2
@ -75,43 +118,109 @@ Public Sub _Paint(X As Integer, Y As Integer, Width As Integer, Height As Intege
Next
Case Else
'compute the largest label
For Each s In aLabels
f = Max(Paint.TextSize(s).W, f)
hRect.W = Max(Paint.TextSize(s).W, f)
Next
f = Max(Paint.TextSize($sTitle).W, f)
hRect.H = aLabels.Count * H * 1.2 + H
hRect.W = H * 3 + f
hRect.Y = (Height - hRect.H) / 2
If $sTitle Then hRect.H = hRect.H + H
'generate the rect
'Test if the Title is larger than the largest label
'take the title into account
If $sTitle Then
Paint.Font = $oTitleFont
Paint.Font.Size = Paint.Font.Size * hChart._fProportionnal
hRect.W = Max(Paint.TextSize($sTitle).W, hRect.W)
Paint.Font = $oTitleFont
Paint.Font.Size = $oTitleFont.Size * hChart._fProportionnal
hRect.H = Paint.Font.H + fTitleSpace
Endif
If $iWidth > 0 Then hRect.W = Max(hRect.W, $iWidth * hChart._fProportionnal)
hRect.H = hRect.H + aLabels.Count * (H + fSpace) - fSpace
'Add the border and padding size to the legend size
'hBorder.Padding = Max(hBorder.Padding, 10)
'hBorder.Padding = hBorder.Padding * hChart._fProportionnal
'hBorder.Width = hBorder.Width * hChart._fProportionnal
'hBorder.Radius = hBorder.Radius * hChart._fProportionnal
With $hFrame
i = .Border.LeftPadding + .Border.LeftWidth
hRect.Width = hRect.Width + i + .Border.RightPadding + .Border.Width
i = hBorder.TopPadding + hBorder.TopWidth
hRect.H = hRect.H + i + .Border.BottomPadding + .Border.BottomWidth
If $iPosition = Align.Left Then
hRect.X = X + H
Else
hRect.X = Width - hRect.W - H
Endif
hRect.Y = Y + (Height - hRect.H) / 2
Paint.Rectangle(hRect.X, hRect.Y, hRect.W, hRect.H)
Paint.Stroke
End With
$hFrame.Rect = hRect
'get the interior rect
$hFrame._PaintBefore()
hInnerRect = $hFrame._GetRect()
f = hRect.Y + H * 1.5
'clip the drawing
'hBorder.Clip(hRect)
' If $hBorder Then
' Paint.Rectangle(hRect.X, hRect.Y, hRect.W, hRect.H)
' Paint.Background = IIf($iBackground = -1, Color.Transparent, $iBackground)
' Paint.Fill
' hBorder.Paint(hRect)
' Endif
'compute the title position
f = hInnerRect.Y
If $sTitle Then
f += fTitleSpace
Paint.Font.Bold = True
Paint.dRAWText($sTitle, hRect.X, hRect.Y, hRect.W, H, Align.Center)
Paint.Background = IIf($iTitleColor = -1, Color.Transparent, $iTitleColor)
Paint.dRAWText($sTitle, hInnerRect.X, hInnerRect.Y, hInnerRect.W, H, Align.Center)
Paint.Font.bold = False
f = f + H
f += Paint.Font.H
Endif
For Each s In aLabels
Paint.Rectangle(hRect.X + H / 2, f - H * 0.8, H, H)
Paint.Background = hChart.Colors[i Mod hChart.Colors.Count]
Paint.Fill(True)
Paint.Background = Color.Black
Paint.Stroke()
Paint.DrawText(s, hRect.X + 2 * H, f)
f += H * 1.2
Inc i
Paint.LineWidth = 1
'Compute total of value for percentages
For Each j In hChart.Datas[0].Values
Tot = Tot + j
Next
'get the minimal percentage label rect
hPercentRect = Paint.TextSize("000 %")
Paint.font = $oFont
Paint.Font.Size = Paint.Font.Size * hChart._fProportionnal
For i = 0 To aLabels.Max
s = aLabels[i]
hTextRect = Paint.TextSize(s)
DrawSymbol($sSymbolStyle, hInnerRect.X, f, H, H, hChart.Colors[i Mod hChart.Colors.Count], Color.Transparent)
Paint.Background = $iColor
hTextRect.Move(hInnerRect.X + H * 1.5, f)
Paint.DrawText(s, hTextRect.X, hTextRect.Y, hTextRect.W, hTextRect.H, Align.Left)
'Show percentages
If $bShowPercent Then
hPercentRect.Move(hTextRect.Right, hTextRect.Top)
hPercentRect.W = hInnerRect.Right - H / 2 - hPercentRect.Left
Paint.DrawText(Format(Floor(hChart.Datas[0].Values[i] / Tot * 100), "0") & " %", hPercentRect.X, hPercentRect.Y, hPercentRect.W, hPercentRect.H, align.Right)
Endif
'Break before drawing last separator
If i = aLabels.Max Then Break
'Draw separator
Paint.AntiAlias = False
Paint.LineWidth = $fInterlineWidth
Paint.Background = $iInterlineColor
Paint.MoveTo(hInnerRect.X, hTextRect.Bottom + fSpace / 2)
Paint.LineTo(hInnerRect.Right, hTextRect.Bottom + fSpace / 2)
Paint.stroke
Paint.AntiAlias = True
f += H + fSpace
Next
hRect.W += H
@ -119,31 +228,56 @@ Public Sub _Paint(X As Integer, Y As Integer, Width As Integer, Height As Intege
End Select
$hFrame._Paintafter
Return hRect
End
Public Sub GetRect(X As Integer, Y As Integer, Width As Integer, Height As Integer) As Rectf
Private Sub DrawSymbol(sSymbol As String, X As Float, Y As Float, W As Float, H As Float, iColor As Integer, iOutlineColor As Integer)
Select Case sSymbol
Case "circle"
Paint.Ellipse(X, Y, W, H)
Case "diam"
Paint.MoveTo(X + W / 2, Y)
Paint.RelLineTo(W / 2, H / 2)
Paint.RelLineTo(-W / 2, H / 2)
Paint.RelLineTo(-W / 2, -H / 2)
Paint.ClosePath
Case Else
Paint.Rectangle(X, Y, W, H, 1)
End Select
Paint.Background = iColor
Paint.Fill(True)
Paint.Background = iOutlineColor
Paint.Stroke
End
Private Function Font_Read() As Font
End
Private Sub Font_Write(Value As Font)
End
Public Sub _GetParent() As Chart
Return Object.Parent(Me)
End
Private Function Width_Read() As Integer
End
Private Sub Width_Write(Value As Integer)
End

View file

@ -4,8 +4,8 @@ Inherits _ChartStyle
Property Read Symbols As String[] Use $aSymbols
Private $oXFont As New Font
Private $oYFont As New Font
Private $fXMaxValue As Float = 100.0
Private $fYMaxValue As Float = 100.0
Private $fXMaxValue As Float = 10.0
Private $fYMaxValue As Float = 10.0
Private $fXMinValue As Float
Private $fYMinValue As Float
Private $fXStep As Float = 1.0
@ -217,7 +217,7 @@ Public Function _GetParam(X As Integer, Y As Integer, Width As Integer, Height A
aLabels = New String[]
If hChart.Datas.Count = 1 Then
For i = 0 To j
For i = 0 To j - 1
If i > hChart.Labels.Max Then
aLabels.Add("")
Else

View file

@ -3,6 +3,8 @@
Property Text As String Use $sText
Property {Font} As Font Use $oFont
Property Visible As Boolean Use $bVisible
Property {Color} As Integer Use $iColor
Event foo
Public Sub _new()
@ -12,7 +14,20 @@ Public Sub _new()
End
Public Sub Paint()
Public Sub _Paint(W As Integer) As Float
Dim hChart As Chart = GetParent()
Dim H As Float
Paint.Font = $oFont
Paint.Font.Size = Paint.Font.Size * hChart._fProportionnal
H = Paint.Font.H * 1.5
Paint.Background = $iColor
Paint.DrawText($sText, 0, 0, W, H, Align.Center)
Return H
End
Private Sub GetParent() As Chart
Return Object.Parent(Me)
End

View file

@ -0,0 +1,77 @@
' Gambas class file
Property Border As Border Use $hBorder
Property Name As String Use $sName
Property Background As Integer Use $iBackground
Property Rect As Rectf Use $hRect
Property Shadow As Float Use $fShadow
Property ShadowColor As Integer Use $iShadowColor
Private $hInnerShadow As Rectf
'Private $iBackground As Integer
Public Sub _new(Optional sStyle As String)
$hBorder = New Border
$hRect = RectF(0, 0, 10, 10)
$fShadow = 5
$iShadowColor = -1
$iBackground = -1
$hBorder.padding = 20
End
Public Sub _GetRect() As Rect
Return $hBorder.GetRect($hRect, True)
End
Public Sub _PaintBefore()
If $fShadow Then
Paint.save
$hInnerShadow = RectF($hRect.X + $fShadow, $hRect.Y + $fShadow, $hRect.W - $fShadow, $hRect.H - $fShadow)
$hBorder.Clip($hInnerShadow)
Paint.Rectangle($hInnerShadow.X, $hInnerShadow.Y, $hInnerShadow.Width, $hInnerShadow.Height)
Paint.Background = $iShadowColor
Paint.Fill
Paint.Restore
$hInnerShadow.Translate(-$fShadow, -$fShadow)
Else
$hInnerShadow = $hRect.Copy()
Endif
Paint.Save
$hBorder.Clip($hInnerShadow)
'Paint.Clip()
Paint.Rectangle($hInnerShadow.X, $hInnerShadow.Y, $hInnerShadow.Width, $hInnerShadow.Height)
Paint.Background = IIf($iBackground = -1, Color.Transparent, $iBackground)
Paint.Fill
End
Public Sub _PaintContent()
End
Public Sub _PaintAfter()
$hBorder.Paint($hInnerShadow)
Paint.Restore
End
Public Sub Paint()
_PaintBefore
_PaintAfter
End