Platforms to show: All Mac Windows Linux Cross-Platform
/ChartDirector/symbolline zoom
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/symbolline zoom
This example is the version from Tue, 11th Feb 2019.
Project "symbolline zoom.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
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 PicWindow Inherits Window
Const zoomInRatio = 2.0
Const zoomOutRatio = 0.5
Control out Inherits Canvas
ControlInstance out Inherits Canvas
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean
if ToolMove.Value then
out.MouseCursor=System.Cursors.HandClosed
StartX=X
StartY=Y
viewport.startDrag
else
// zoom
StartX=X
StartY=Y
StartX2=X
StartY2=Y
end if
Return true
End EventHandler
EventHandler Sub MouseDrag(X As Integer, Y As Integer)
if ToolMove.Value then
if viewport.dragTo(CDBaseChartMBS.kDirectionHorizontalVertical, x-Startx, y-Starty) then
redraw
end if
else
StartX2 = X
StartY2 = Y
dim l as integer = min(StartX, StartX2)
dim t as integer = min(StartY, StartY2)
dim w as integer = StartX2 - StartX
dim h as integer = StartY2 - StartY
if w<0 then w=-w
if h<0 then h=-h
dragPicture = new Picture(lastpicture.Width, lastpicture.Height)
dragPicture.Graphics.DrawPicture lastpicture, 0, 0, dragPicture.Width, dragPicture.Height, 0, 0, lastpicture.Width, lastpicture.Height
dragPicture.Graphics.DrawPicture rectanglePicture, l, t, w, h, 0, 0, rectanglePicture.Width, rectanglePicture.Height
out.Invalidate // trigger redraw
end if
End EventHandler
EventHandler Sub MouseUp(X As Integer, Y As Integer)
if ToolMove.Value then
out.MouseCursor=System.Cursors.HandOpen
elseif ToolZoomIn.Value then
// zoom on point?
if abs(X-StartX)<3 and abs(Y-StartY)<3 then
// zoom in on point
if viewport.canZoomIn(CDBaseChartMBS.kDirectionHorizontalVertical) then
if viewport.zoomAt(CDBaseChartMBS.kDirectionHorizontalVertical, x, y, zoomInRatio) then
redraw
end if
else
redraw
beep
end if
else
// zoom in on a rectangle
if viewport.canZoomIn(CDBaseChartMBS.kDirectionHorizontalVertical) then
if viewport.zoomTo(CDBaseChartMBS.kDirectionHorizontalVertical, x, y, StartX, StartY) then
redraw
end if
else
redraw
beep
end if
end if
elseif ToolZoomOut.Value then
// zoom out on point
if viewport.canZoomOut(CDBaseChartMBS.kDirectionHorizontalVertical) then
if viewport.zoomAt(CDBaseChartMBS.kDirectionHorizontalVertical, x, y, zoomOutRatio) then
redraw
end if
elseif viewport.canZoomOut(CDBaseChartMBS.kDirectionHorizontal) then
if viewport.zoomAt(CDBaseChartMBS.kDirectionHorizontal, x, y, zoomOutRatio) then
redraw
end if
elseif viewport.canZoomOut(CDBaseChartMBS.kDirectionVertical) then
if viewport.zoomAt(CDBaseChartMBS.kDirectionVertical, x, y, zoomOutRatio) then
redraw
end if
else
redraw
beep
end if
end if
End EventHandler
EventHandler Sub Open()
me.MouseCursor=System.Cursors.HandOpen
// fix some properties if set wrong in IDE
me.DoubleBuffer = false
me.EraseBackground = false
#if RBVersion >= 2013.0 then
me.Transparent = False
#endif
End EventHandler
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect)
#pragma Unused areas
draw g
End EventHandler
End Control
Control ToolMove Inherits RadioButton
ControlInstance ToolMove Inherits RadioButton
EventHandler Sub Action()
out.MouseCursor=System.Cursors.HandOpen
End EventHandler
End Control
Control ToolZoomIn Inherits RadioButton
ControlInstance ToolZoomIn Inherits RadioButton
EventHandler Sub Action()
out.MouseCursor=System.Cursors.MagnifyLarger
End EventHandler
End Control
Control ToolZoomOut Inherits RadioButton
ControlInstance ToolZoomOut Inherits RadioButton
EventHandler Sub Action()
out.MouseCursor=System.Cursors.MagnifySmaller
End EventHandler
End Control
EventHandler Sub Open()
viewport=new CDViewPortManagerMBS
viewport.setViewPortHeight 1.0
viewport.setViewPortTop 0.0
viewport.setViewPortWidth 1.0
viewport.setViewPortLeft 0.0
'viewport.setZoomInWidthLimit 0.01
'viewport.setZoomInHeightLimit 0.01
viewport.setZoomOutWidthLimit 0.2
'viewport.setZoomOutHeightLimit 1.0
dim x0 as Double=70
dim x1 as Double=50
dim x2 as Double=30
data0.Append x0
data1.Append x1
data2.Append x2
for i as integer=1 to 100
x0=x0+rnd*5.0-2.5
x1=x1+rnd*5.0-2.5
x2=x2+rnd*5.0-2.5
data0.Append x0
data1.Append x1
data2.Append x2
next
// for the selection box
rectanglePicture=New Picture(32,32,32)
rectanglePicture.Graphics.ForeColor=&cFF0000
rectanglePicture.Graphics.FillRect 0,0,32,32
rectanglePicture.mask.Graphics.ForeColor=&cCCCCCC
rectanglePicture.mask.Graphics.FillRect 0,0,32,32
End EventHandler
Protected Sub Render(g as Graphics)
// The data for the line chart
viewport.validateViewPort
// Create a XYChart object of size 600 x 375 pixels
dim c as new CDXYChartMBS(600, 375)
// Add a title to the chart using 18 pts Times Bold Italic font
call c.addTitle("Product Line Global Revenue", "timesbi.ttf", 18)
// Set the plotarea at (50, 55) and of 500 x 280 pixels in size. Use a vertical
// gradient color from light blue (f9f9ff) to sky blue (aaccff) as background.
// Set border to transparent and grid lines to white (ffffff).
call c.setPlotArea(50, 55, 500, 280, c.linearGradientColor(0, 55, 0, 335, &hf9fcff, &haaccff), -1, c.kTransparent, &hffffff)
call c.setClipping
// Add a legend box at (50, 28) using horizontal layout. Use 10pts Arial Bold as
// font, with transparent background.
c.addLegend(50, 28, false, "arialbd.ttf", 10).setBackground(c.kTransparent)
// Set the x axis labels
'call c.xAxis.setLabels(labels)
// Set y-axis tick density to 30 pixels. ChartDirector auto-scaling will use this
// as the guideline when putting ticks on the y-axis.
c.yAxis.setTickDensity(30)
c.yAxis2.setTickDensity(30)
// Set axis label style to 8pts Arial Bold
call c.xAxis.setLabelStyle("arialbd.ttf", 8)
call c.yAxis.setLabelStyle("arialbd.ttf", 8)
call c.yAxis2.setLabelStyle("arialbd.ttf", 8)
// Set axis line width to 2 pixels
c.xAxis.setWidth(2)
c.yAxis.setWidth(2)
c.yAxis2.setWidth(2)
// Add axis title using 10pts Arial Bold Italic font
call c.yAxis.setTitle("Revenue in US millions", "arialbi.ttf", 10)
call c.yAxis2.setTitle("Revenue in US millions", "arialbi.ttf", 10)
// scroll
dim axisLowerLimit as double
dim axisUpperLimit as double
axisUpperLimit = 100.0 *(viewport.getViewPortLeft + viewport.getViewPortWidth)
axisLowerLimit = 100.0 * viewport.getViewPortLeft
c.xAxis.setLinearScale(axisLowerLimit,axisUpperLimit)
c.xAxis.setRounding(false, false)
axisLowerLimit = 100.0 - 100.0 * (viewport.getViewPortTop + viewport.getViewPortHeight)
axisUpperLimit = 100.0 - 100.0 * viewport.getViewPortTop
c.yAxis.setLinearScale(axisLowerLimit,axisUpperLimit)
c.yAxis.setRounding(false, false)
c.yAxis2.setLinearScale(axisLowerLimit,axisUpperLimit)
c.yAxis2.setRounding(false, false)
// Add a line layer to the chart
dim layer as CDLineLayerMBS
layer = c.addLineLayer
// Set the line width to 3 pixels
layer.setLineWidth(3)
// Add the three data sets to the line layer, using circles, diamands and X
// shapes as symbols
layer.addDataSet(data0, &hff0000, "Quantum Computer").setDataSymbol(c.kCircleSymbol, 9)
layer.addDataSet(data1, &h00ff00, "Atom Synthesizer").setDataSymbol(c.kDiamondSymbol, 11)
layer.addDataSet(data2, &hff6600, "Proton Cannon").setDataSymbol(c.Cross2Shape, 11)
lastpicture = c.makeChartPicture
viewport.setChartMetrics c.getChartMetrics
End Sub
Protected Sub draw(g as graphics)
if dragPicture <> nil then
g.DrawPicture dragPicture, 0, 0, g.Width, g.Height, 0, 0, dragPicture.Width, dragPicture.Height
return
end if
if lastpicture = nil or (lastpicture.Width <> g.Width or lastpicture.Height <> g.Height) then
render g
end if
if lastpicture <> nil then
g.DrawPicture lastpicture, 0, 0, g.Width, g.Height, 0, 0, lastpicture.Width, lastpicture.Height
end if
End Sub
Protected Sub redraw()
lastpicture = nil // will render again
dragPicture = nil
out.Invalidate
End Sub
Property Protected StartX As Integer
Property Protected StartX2 As Integer
Property Protected StartY As Integer
Property Protected StartY2 As Integer
Property Protected data0() As double
Property Protected data1() As double
Property Protected data2() As double
Property Protected dragPicture As Picture
Property Protected lastpicture As picture
Property Protected maxvalue As double
Property Protected minvalue As double
Property Protected rectanglePicture As picture
Property Protected viewport As cdviewPortManagerMBS
End Class
End Project
See also:
The items on this page are in the following plugins: MBS ChartDirector Plugin.