Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/ChartDirector/simplePie with MouseClicks explode
Function:
Required plugins for this example: MBS ChartDirector Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /ChartDirector/simplePie with MouseClicks explode
This example is the version from Sun, 17th Mar 2012.
Project "simplePie with MouseClicks explode.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class PicWindow Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean dim sector as integer = findsector(x,y) if sector>=0 then Title="Sector "+Str(sector) else Title="" end if run sector Return true End EventHandler
EventHandler Sub Open() run -1 End EventHandler
Protected Sub Parse(s as string) // Parse the html map s=ReplaceLineEndings(s,EndOfLine) dim lines(-1) as string = split(s,EndOfLine) for each line as string in lines // <area shape="poly" coords="350,145,428,166,484,222,505,300,504,320,350,300" href="a?sector=0&label=Germany&value=55&percent=27.09"> dim parts(-1) as string = split(line,"""") if UBound(parts)>=6 then if parts(1)="poly" then dim po as new MyPoly po.setCoords parts(3) po.setSector parts(5) polys.Append po elseif parts(1)="Rect" then dim re as new MyRect re.setCoords parts(3) re.setSector parts(5) rects.Append re end if end if next End Sub
Function findsector(x as integer, y as integer) As integer // click in on of the Rectangles? for each re as MyRect in rects if x>=re.left and x<=re.right and y>=re.top and y<=re.bottom then Return re.sector end if next // click in a polygon? for each po as MyPoly in polys dim polysides as integer=UBound(po.x) dim j as integer=polySides dim oddNodes as Boolean=False for i as integer=0 to polySides if (po.y(i)<y and po.y(j)>=y) or (po.y(j)<y and po.y(i)>=y) then if (po.x(i)+(y-po.y(i))/(po.y(j)-po.y(i))*(po.x(j)-po.x(i))<x) then oddNodes=not oddNodes end if end if j=i next if oddNodes then // found it! Return po.sector end if next // nothing found Return -1 End Function
Sub run(HighLightSector as integer) // The data for the pie chart dim data(-1) as double=array(55.0, 18.0, 25.0, 22.0, 18.0, 30.0, 35.0) // The labels for the pie chart, Words are choosen random to check font! dim labels(-1) as string=array("Germany","Italy","France","Spain","UK","Poland","Russia") // Create a PieChart object of size 360 x 300 pixels c = new CDPieChartMBS(700, 600) // Set the center of the pie at (180, 140) and the radius to 100 pixels c.setPieSize 350,300,150 // Set the pie data and the pie labels c.setData data,labels call c.setLabelStyle "Times New Roman",18 if HighLightSector>=0 then c.setExplode HighLightSector end if pic=c.makeChartPicture Backdrop=pic // read in the html map Parse C.getHTMLImageMap("a") End Sub
Property c As CDPieChartMBS
Property pic As picture
Property Protected polys() As MyPoly
Property Protected rects() As MyRect
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyRect
Sub setCoords(s as string) // set coordinates dim co(-1) as string co=split(s,",") left=val(co(0)) top=val(co(1)) right=val(co(2)) bottom=val(co(3)) End Sub
Sub setSector(s as string) // set sector if left(s,9)="a?sector=" then sector=val(mid(s,10)) end if End Sub
Property bottom As Integer
Property left As Integer
Property right As Integer
Property sector As Integer
Property top As Integer
End Class
Class MyPoly
Sub setCoords(s as string) // set coordinates dim co(-1) as string co=split(s,",") dim u as integer=UBound(co) for i as integer=0 to u x.Append val(co(i)) i=i+1 y.Append val(co(i)) next End Sub
Sub setSector(s as string) // set sector if left(s,9)="a?sector=" then sector=val(mid(s,10)) end if End Sub
Property sector As Integer
Property x() As double
Property y() As double
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS ChartDirector Plugin.





Links
MBS Xojo PDF Plugins