From 46f31908c632a3030c2717843e674aa954d79461 Mon Sep 17 00:00:00 2001 From: Fabien Bodard Date: Fri, 1 May 2009 21:16:14 +0000 Subject: [PATCH] [GB.CHART] * NEW: some change on pie type (labels around the pie) git-svn-id: svn://localhost/gambas/trunk@1940 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- comp/src/gb.chart/.info | 8 +++++ comp/src/gb.chart/.project | 2 +- comp/src/gb.chart/Chart.class | 24 +++++++++++++-- comp/src/gb.chart/FTest.class | 7 +++++ comp/src/gb.chart/FTest.form | 17 +++++++---- comp/src/gb.chart/_CLabel.class | 41 ++++++++++++++++++++++++++ comp/src/gb.chart/_CLabels.class | 3 ++ comp/src/gb.chart/_CLegend.class | 8 +++-- comp/src/gb.chart/_CStyleColumns.class | 2 +- comp/src/gb.chart/_CStylePie.class | 26 +++++++++++++++- 10 files changed, 124 insertions(+), 14 deletions(-) create mode 100644 comp/src/gb.chart/_CLabel.class create mode 100644 comp/src/gb.chart/_CLabels.class diff --git a/comp/src/gb.chart/.info b/comp/src/gb.chart/.info index 69faa7126..f7f44280e 100644 --- a/comp/src/gb.chart/.info +++ b/comp/src/gb.chart/.info @@ -73,6 +73,14 @@ Style p i +Labels +r +_CLabels + +ShowLabels +p +b + _New m diff --git a/comp/src/gb.chart/.project b/comp/src/gb.chart/.project index c7580b8fc..5a8007e34 100644 --- a/comp/src/gb.chart/.project +++ b/comp/src/gb.chart/.project @@ -1,7 +1,7 @@ # Gambas Project File 3.0 # Compiled with Gambas 2.99.0 Title=gb.chart -Startup=FTest2 +Startup=FTest Version=0.0.5 Component=gb.qt Component=gb.form diff --git a/comp/src/gb.chart/Chart.class b/comp/src/gb.chart/Chart.class index 395740f88..b2f8e7608 100644 --- a/comp/src/gb.chart/Chart.class +++ b/comp/src/gb.chart/Chart.class @@ -28,7 +28,7 @@ Private $iHeight As Integer Private $oHeaders As _CHeaders Private $iBackground As Integer = Color.White Private $iBorder As Boolean = True - +Private $bShowLabels As Boolean = False Property Border As Boolean Property Background As Integer @@ -51,13 +51,15 @@ Property Count As Integer Property Proportionnal As Boolean Property Read Headers As _CHeaders Property Style As Integer +Property Read Labels As _CLabels +Property ShowLabels As Boolean Public Sub _New() id = Now() Me.CountDataSets = 1 - Me.Type = ChartType.Columns + Me.Type = ChartType.Pie _$ColChart.Add(Me, id) $oHeaders = New _CHeaders(id) $oLegend = New _CLegend(id) @@ -356,3 +358,21 @@ Public Sub _Free() End + +Private Function Labels_Read() As _CLabels + + + +End + +Private Function ShowLabels_Read() As Boolean + + Return $bShowLabels + +End + +Private Sub ShowLabels_Write(Value As Boolean) + + $bShowLabels = Value + +End diff --git a/comp/src/gb.chart/FTest.class b/comp/src/gb.chart/FTest.class index 8aa960da9..76afa1e1a 100644 --- a/comp/src/gb.chart/FTest.class +++ b/comp/src/gb.chart/FTest.class @@ -501,3 +501,10 @@ Public Sub spStep_Change() DrawingArea1.Refresh End + +Public Sub CheckBox11_Click() + + Chart.ShowLabels = Last.Value + DrawingArea1.Refresh + +End diff --git a/comp/src/gb.chart/FTest.form b/comp/src/gb.chart/FTest.form index fc336cfe3..ba30062db 100644 --- a/comp/src/gb.chart/FTest.form +++ b/comp/src/gb.chart/FTest.form @@ -4,12 +4,12 @@ MoveScaled(0,0,111,90) Text = ("") Arrangement = Arrange.Vertical - Spacing = 5 + Spacing = True Padding = 5 { HBox1 HBox MoveScaled(2,2,105,81) Expand = True - Spacing = 5 + Spacing = True { DrawingArea1 DrawingArea MoveScaled(1,4,61,61) Background = &HFFFFFF& @@ -18,7 +18,7 @@ { TabStrip1 TabStrip MoveScaled(63,2,44,79) Arrangement = Arrange.Vertical - Spacing = 5 + Spacing = True Padding = 5 Count = 4 Index = 0 @@ -83,7 +83,7 @@ { ScrollView1 ScrollView MoveScaled(1,5,63,18) Arrangement = Arrange.Row - Spacing = 10 + Spacing = True Padding = 5 ScrollBar = Scroll.Horizontal } @@ -94,7 +94,7 @@ { ScrollView2 ScrollView MoveScaled(1,28,63,18) Arrangement = Arrange.Row - Spacing = 5 + Spacing = True Padding = 5 } Index = 2 @@ -167,7 +167,7 @@ } } { Frame2 Frame - MoveScaled(3,46,37,23) + MoveScaled(3,46,37,26) Text = ("Axes") { CheckBox3 CheckBox MoveScaled(2,3,30,3) @@ -198,6 +198,11 @@ MoveScaled(2,8,24,2) Text = ("X Steps Arrange") } + { CheckBox11 CheckBox + MoveScaled(2,22,30,3) + Text = ("Show Data labels") + Value = CheckBox.True + } } Index = 3 Text = ("Colors") diff --git a/comp/src/gb.chart/_CLabel.class b/comp/src/gb.chart/_CLabel.class new file mode 100644 index 000000000..4637d0a4d --- /dev/null +++ b/comp/src/gb.chart/_CLabel.class @@ -0,0 +1,41 @@ +' Gambas class file +Property {Font} As Font +Property ForeColor As Integer +Property BackGround As Integer + + +Private Function Font_Read() As Font + + + +End + +Private Sub Font_Write(Value As Font) + + + +End + +Private Function ForeColor_Read() As Integer + + + +End + +Private Sub ForeColor_Write(Value As Integer) + + + +End + +Private Function BackGround_Read() As Integer + + + +End + +Private Sub BackGround_Write(Value As Integer) + + + +End diff --git a/comp/src/gb.chart/_CLabels.class b/comp/src/gb.chart/_CLabels.class new file mode 100644 index 000000000..6cc783315 --- /dev/null +++ b/comp/src/gb.chart/_CLabels.class @@ -0,0 +1,3 @@ +' Gambas class file + + diff --git a/comp/src/gb.chart/_CLegend.class b/comp/src/gb.chart/_CLegend.class index 7644ab67c..58af8adfa 100644 --- a/comp/src/gb.chart/_CLegend.class +++ b/comp/src/gb.chart/_CLegend.class @@ -101,13 +101,15 @@ Public Sub Draw(bSeries As Boolean) w = Chart._$ColChart[$sidChart].Width h = Chart._$ColChart[$sidChart].Height 'draw.Font = Chart.Font - 'Get the max text length + 'Get the max text length + + draw.Font = $oFont + draw.Font.Size = $oFont.Size * Chart._$ColChart[$sidChart]._fProportionnal For Each s In arsInt i = draw.TextWidth(s) If i > cnt Then cnt = i Next - draw.Font = $oFont - draw.Font.Size = $oFont.Size * Chart._$ColChart[$sidChart]._fProportionnal + Print cnt SQUARESIZE = draw.TextHeight("T") Select Case $iPosition diff --git a/comp/src/gb.chart/_CStyleColumns.class b/comp/src/gb.chart/_CStyleColumns.class index 25cce4a59..1c7140ae0 100644 --- a/comp/src/gb.chart/_CStyleColumns.class +++ b/comp/src/gb.chart/_CStyleColumns.class @@ -45,7 +45,7 @@ Public Sub Draw(CX As Integer, CY As Integer, CW As Integer, CH As Integer) fMinVal = Chart._$ColChart[$sidChart].YAxe.MinValue Endif Case ChartType.ColumnsStacked - fMaxVal = MTools.GetChartMaxCumulate(Chart._$ColChart[$sidChart]) + fMaxVal = MTools.GetChartMaxCumulate($sidChart) Case ChartType.ColumnsPercent fMaxVal = 100 End Select diff --git a/comp/src/gb.chart/_CStylePie.class b/comp/src/gb.chart/_CStylePie.class index b14d17510..37814792f 100644 --- a/comp/src/gb.chart/_CStylePie.class +++ b/comp/src/gb.chart/_CStylePie.class @@ -22,6 +22,7 @@ Public Sub Draw(CX As Integer, CY As Integer, CW As Integer, CH As Integer) Dim fRayon As Float Dim fMaxRayon As Float Dim fRayonUnit As Float + Dim tmpX, tmpY As Integer 'Obtenir la valeur cumulée: For Each s In Chart._$ColChart[$sidChart].Headers If draw.TextWidth(s) > iMaxTextWidth Then iMaxTextWidth = draw.TextWidth(s) @@ -63,8 +64,31 @@ Public Sub Draw(CX As Integer, CY As Integer, CW As Integer, CH As Integer) Else draw.Circle(CX + CW / 2, CY + Ch / 2, fRayon, fCumul, fNewPos) Endif + tmpX = CX + CW / 2 + Cos(fTextPos) * (fRayon + draw.TextWidth(Chart._$ColChart[$sidChart].Headers[i]) + (30 * Chart._$ColChart[$sidChart]._fProportionnal)) - draw.TextWidth(Chart._$ColChart[$sidChart].Headers[i]) / 2 + tmpY = CY + Ch / 2 + Sin(fTextPos - Rad(180)) * (fRayon + draw.TextWidth(Chart._$ColChart[$sidChart].Headers[i]) + 30 * Chart._$ColChart[$sidChart]._fProportionnal) + + '<--Text + If Chart._$ColChart[$sidChart].ShowLabels Then + draw.Text(Chart._$ColChart[$sidChart].Headers[i], tmpX, tmpY) + + 'If tmpY < CY + CH / 2 Then + tmpY += draw.TextHeight(Chart._$ColChart[$sidChart].Headers[i]) / 2 + If tmpX < CX + CW / 2 Then + tmpX += draw.TextWidth(Chart._$ColChart[$sidChart].Headers[i]) + 5 * Chart._$ColChart[$sidChart]._fProportionnal + draw.Line(tmpX + 10 * Chart._$ColChart[$sidChart]._fProportionnal, tmpY, tmpX, tmpY) + tmpX += 10 * Chart._$ColChart[$sidChart]._fProportionnal + Else + draw.Line(tmpX - 10 * Chart._$ColChart[$sidChart]._fProportionnal, tmpY, tmpX, tmpY) + tmpX -= 10 * Chart._$ColChart[$sidChart]._fProportionnal + Endif + + draw.Line(CX + CW / 2 + Cos(fTextPos) * (fRayon - 10 * Chart._$ColChart[$sidChart]._fProportionnal), CY + Ch / 2 + Sin(fTextPos - Rad(180)) * (fRayon - 10 * Chart._$ColChart[$sidChart]._fProportionnal), tmpX, tmpY) + Endif + '--> + + 'draw.Text(Chart[i].Label, Cos(fTextPos) * (fRayon) + CX + CW / 2, Sin((fTextPos) - Rad(180)) * (fRayon) + CY + fRayon - draw.Font.Height()) - + fCumul += Rad(f * frapport) Next