Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make this easier

  • Loading branch information...
commit 1e6cb24f02cb469e31136c03df26aed9f8acb928 1 parent 0957d22
@migueldeicaza migueldeicaza authored
View
168 CorePlot/iOS-sample/Main.cs
@@ -4,6 +4,7 @@
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.CorePlot;
+using MonoTouch.Dialog;
using System.Drawing;
namespace iOSsample
@@ -23,100 +24,26 @@ static void Main (string[] args)
// The name AppDelegate is referenced in the MainWindow.xib file.
public partial class AppDelegate : UIApplicationDelegate
{
- CPGraphHostingView host;
- CPXYGraph graph;
+ UINavigationController navigation;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window.MakeKeyAndVisible ();
- SetupGraph ();
- SetupAxes ();
- SetupScatterPlots ();
-
- // Host the graph
- host = new CPGraphHostingView (new RectangleF (10, 40, 310, 310));
- host.HostedGraph = graph;
- window.Add (host);
- window.BackgroundColor = UIColor.Brown;
-
- return true;
- }
-
- void SetupGraph ()
- {
- var theme = CPTheme.ThemeNamed ("Plain Black");
-
- graph = new CPXYGraph (new RectangleF (0, 0, 300, 300), CPScaleType.Linear, CPScaleType.Linear){
- PaddingLeft = 10,
- PaddingRight = 10,
- PaddingTop = 10,
- PaddingBottom = 10,
- Title = "My graph",
-
- TitleTextStyle = new CPTextStyle () {
- FontSize = 18,
- FontName = "Helvetica",
- Color = CPColor.GrayColor
- },
- };
- graph.ApplyTheme (theme);
- }
-
- void SetupAxes ()
- {
- var plotspace = graph.DefaultPlotSpace;
- plotspace.AllowsUserInteraction = true;
-
- var major = new CPLineStyle () {
- LineWidth = .75f,
- LineColor = CPColor.FromGenericGray (0.2f).ColorWithAlphaComponent (.75f)
- };
-
- var minor = new CPLineStyle () {
- LineWidth = .25f,
- LineColor = CPColor.WhiteColor.ColorWithAlphaComponent (0.1f)
- };
- var axisSet = (CPXYAxisSet) graph.AxisSet;
- // Label x with a fixed interval policy
- var x = axisSet.XAxis;
- x.LabelingPolicy = CPAxisLabelingPolicy.PolicyAutomatic;
- x.MinorTicksPerInterval = 4;
- x.PreferredNumberOfMajorTicks = 8;
- x.MajorGridLineStyle = major;
- x.MinorGridLineStyle = minor;
- x.Title = "X Axis";
- x.TitleOffset = -30;
-
- // Label y with an automatic label policy.
- var y = axisSet.YAxis;
- y.LabelingPolicy = CPAxisLabelingPolicy.PolicyAutomatic;
- y.MinorTicksPerInterval = 4;
- y.PreferredNumberOfMajorTicks = 8;
- y.MajorGridLineStyle = major;
- y.MinorGridLineStyle = minor;
- y.LabelOffset = 20;
- y.Title = "Y Axis";
- y.TitleOffset = -30;
- }
-
- void SetupScatterPlots ()
- {
- // Create a plot that uses the data source method
- var dataSourceLinePlot = new CPScatterPlot () {
- CachePrecision = CPPlotCachePrecision.Double,
- DataLineStyle = new CPLineStyle () {
- LineWidth = 2,
- LineColor = CPColor.GreenColor
- },
- // For Kang, check this out:
- DataSource = new RandomSamplesSource ()
+ var root = new RootElement ("CorePlot Samples"){
+ new Section () {
+ new RootElement ("XYGraph", r => new ScatterPlot ())
+ }
};
- graph.AddPlot (dataSourceLinePlot);
+
+ var dvc = new DialogViewController (root);
+ navigation = new UINavigationController (dvc);
+ window.Add (navigation.View);
+ return true;
}
-
+
// This method is required in iPhoneOS 3.0
public override void OnActivated (UIApplication application)
@@ -124,74 +51,5 @@ public override void OnActivated (UIApplication application)
}
}
- public class RandomSamplesSource : CPScatterPlotDataSource {
- List<PointF> data;
-
- public RandomSamplesSource ()
- {
- Random r = new Random ();
-
- data = new List<PointF> ();
- for (int i = 0; i < 100; i++){
- var y = i;
- data.Add (new PointF (i * 0.5f, (float) y));
- }
- }
-
- public override int NumberOfRecordsForPlot (CPPlot plot)
- {
- return data.Count;
- }
-
- public override NSNumber NumberForPlot (CPPlot plot, CPPlotField forFieldEnum, int index)
- {
- if (forFieldEnum == CPPlotField.ScatterPlotFieldX)
- return data [index].X;
- else
- return data [index].Y;
- }
-
- public override CPPlotSymbol GetSymbol (CPScatterPlot plot, int recordIndex)
- {
- return CPPlotSymbol.DiamondPlotSymbol;
- }
- }
-}
-#if false
-
- // Set plot delegate, to know when symbols have been touched
- // We will display an annotation when a symbol is touched
- dataSourceLinePlot.delegate = self;
- dataSourceLinePlot.plotSymbolMarginForHitDetection = 5.0;
-
- // Create a plot for the selection marker
- CPScatterPlot *selectionPlot = [[[CPScatterPlot alloc] init] autorelease];
- selectionPlot.identifier = SELECTION_PLOT;
- selectionPlot.cachePrecision = CPPlotCachePrecisionDouble;
-
- lineStyle = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease];
- lineStyle.lineWidth = 3.0;
- lineStyle.lineColor = [CPColor redColor];
- selectionPlot.dataLineStyle = lineStyle;
-
- selectionPlot.dataSource = self;
- [graph addPlot:selectionPlot];
-
- // Auto scale the plot space to fit the plot data
- // Compress ranges so we can scroll
- CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
- [plotSpace scaleToFitPlots:[NSArray arrayWithObject:dataSourceLinePlot]];
- CPPlotRange *xRange = plotSpace.xRange;
- [xRange expandRangeByFactor:CPDecimalFromDouble(0.75)];
- plotSpace.xRange = xRange;
- CPPlotRange *yRange = plotSpace.yRange;
- [yRange expandRangeByFactor:CPDecimalFromDouble(0.75)];
- plotSpace.yRange = yRange;
-
- CPPlotRange *globalXRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(-1.0) length:CPDecimalFromDouble(10.0)];
- plotSpace.globalXRange = globalXRange;
- CPPlotRange *globalYRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(-5.0) length:CPDecimalFromDouble(10.0)];
- plotSpace.globalYRange = globalYRange;
- }
-#endif
+}
View
184 CorePlot/iOS-sample/ScatterPlot.cs
@@ -0,0 +1,184 @@
+using System;
+using MonoTouch.UIKit;
+using MonoTouch.CorePlot;
+using System.Drawing;
+using System.Collections.Generic;
+using MonoTouch.Foundation;
+
+namespace iOSsample
+{
+ // A convenience class to show samples
+ public class PlotViewController : UIViewController {
+ CPGraphHostingView host;
+ protected CPGraph Graph;
+
+ public override void ViewWillAppear (bool animated)
+ {
+ base.ViewWillAppear (animated);
+
+ // Host the graph
+ host = new CPGraphHostingView (new RectangleF (10, 40, 300, 300)) {
+ HostedGraph = Graph
+ };
+ View.AddSubview (host);
+ }
+
+ }
+
+ public class ScatterPlot : PlotViewController {
+ CPXYGraph graph;
+
+ public ScatterPlot ()
+ {
+ SetupGraph ();
+ SetupAxes ();
+ SetupScatterPlots ();
+ Graph = graph;
+ }
+
+ void SetupGraph ()
+ {
+ var theme = CPTheme.ThemeNamed ("Plain Black");
+
+ graph = new CPXYGraph (new RectangleF (0, 0, 300, 300), CPScaleType.Linear, CPScaleType.Linear){
+ PaddingLeft = 10,
+ PaddingRight = 10,
+ PaddingTop = 10,
+ PaddingBottom = 10,
+ Title = "My graph",
+
+ TitleTextStyle = new CPTextStyle () {
+ FontSize = 18,
+ FontName = "Helvetica",
+ Color = CPColor.GrayColor
+ },
+ };
+ graph.ApplyTheme (theme);
+ }
+
+ void SetupAxes ()
+ {
+ var plotspace = graph.DefaultPlotSpace;
+ plotspace.AllowsUserInteraction = true;
+
+ var major = new CPLineStyle () {
+ LineWidth = .75f,
+ LineColor = CPColor.FromGenericGray (0.2f).ColorWithAlphaComponent (.75f)
+ };
+
+ var minor = new CPLineStyle () {
+ LineWidth = .25f,
+ LineColor = CPColor.WhiteColor.ColorWithAlphaComponent (0.1f)
+ };
+
+ var axisSet = (CPXYAxisSet) graph.AxisSet;
+
+ // Label x with a fixed interval policy
+ var x = axisSet.XAxis;
+ x.LabelingPolicy = CPAxisLabelingPolicy.PolicyAutomatic;
+ x.MinorTicksPerInterval = 4;
+ x.PreferredNumberOfMajorTicks = 8;
+ x.MajorGridLineStyle = major;
+ x.MinorGridLineStyle = minor;
+ x.Title = "X Axis";
+ x.TitleOffset = -30;
+
+ // Label y with an automatic label policy.
+ var y = axisSet.YAxis;
+ y.LabelingPolicy = CPAxisLabelingPolicy.PolicyAutomatic;
+ y.MinorTicksPerInterval = 4;
+ y.PreferredNumberOfMajorTicks = 8;
+ y.MajorGridLineStyle = major;
+ y.MinorGridLineStyle = minor;
+ y.LabelOffset = 20;
+ y.Title = "Y Axis";
+ y.TitleOffset = -30;
+ }
+
+ void SetupScatterPlots ()
+ {
+ // Create a plot that uses the data source method
+ var dataSourceLinePlot = new CPScatterPlot () {
+ CachePrecision = CPPlotCachePrecision.Double,
+ DataLineStyle = new CPLineStyle () {
+ LineWidth = 2,
+ LineColor = CPColor.GreenColor
+ },
+ // For Kang, check this out:
+ DataSource = new RandomSamplesSource ()
+ };
+ graph.AddPlot (dataSourceLinePlot);
+ }
+ }
+ public class RandomSamplesSource : CPScatterPlotDataSource {
+ List<PointF> data;
+
+ public RandomSamplesSource ()
+ {
+ Random r = new Random ();
+
+ data = new List<PointF> ();
+ for (int i = 0; i < 100; i++){
+ var y = i;
+ data.Add (new PointF (i * 0.5f, (float) y));
+ }
+ }
+
+ public override int NumberOfRecordsForPlot (CPPlot plot)
+ {
+ return data.Count;
+ }
+
+ public override NSNumber NumberForPlot (CPPlot plot, CPPlotField forFieldEnum, int index)
+ {
+ if (forFieldEnum == CPPlotField.ScatterPlotFieldX)
+ return data [index].X;
+ else
+ return data [index].Y;
+ }
+
+ public override CPPlotSymbol GetSymbol (CPScatterPlot plot, int recordIndex)
+ {
+ return CPPlotSymbol.DiamondPlotSymbol;
+ }
+ }
+
+#if false
+
+ // Set plot delegate, to know when symbols have been touched
+ // We will display an annotation when a symbol is touched
+ dataSourceLinePlot.delegate = self;
+ dataSourceLinePlot.plotSymbolMarginForHitDetection = 5.0;
+
+ // Create a plot for the selection marker
+ CPScatterPlot *selectionPlot = [[[CPScatterPlot alloc] init] autorelease];
+ selectionPlot.identifier = SELECTION_PLOT;
+ selectionPlot.cachePrecision = CPPlotCachePrecisionDouble;
+
+ lineStyle = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease];
+ lineStyle.lineWidth = 3.0;
+ lineStyle.lineColor = [CPColor redColor];
+ selectionPlot.dataLineStyle = lineStyle;
+
+ selectionPlot.dataSource = self;
+ [graph addPlot:selectionPlot];
+
+ // Auto scale the plot space to fit the plot data
+ // Compress ranges so we can scroll
+ CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
+ [plotSpace scaleToFitPlots:[NSArray arrayWithObject:dataSourceLinePlot]];
+ CPPlotRange *xRange = plotSpace.xRange;
+ [xRange expandRangeByFactor:CPDecimalFromDouble(0.75)];
+ plotSpace.xRange = xRange;
+ CPPlotRange *yRange = plotSpace.yRange;
+ [yRange expandRangeByFactor:CPDecimalFromDouble(0.75)];
+ plotSpace.yRange = yRange;
+
+ CPPlotRange *globalXRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(-1.0) length:CPDecimalFromDouble(10.0)];
+ plotSpace.globalXRange = globalXRange;
+ CPPlotRange *globalYRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(-5.0) length:CPDecimalFromDouble(10.0)];
+ plotSpace.globalYRange = globalYRange;
+ }
+#endif
+}
+
View
5 CorePlot/iOS-sample/iOS-sample.csproj
@@ -85,6 +85,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\CorePlotiOS.dll</HintPath>
</Reference>
+ <Reference Include="MonoTouch.Dialog, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\MonoTouch.Dialog.dll</HintPath>
+ </Reference>
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
@@ -96,6 +100,7 @@
<DependentUpon>MainWindow.xib</DependentUpon>
</Compile>
<Compile Include="Main.cs" />
+ <Compile Include="ScatterPlot.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="MainWindow.xib" />
View
BIN  MonoTouch.Dialog.dll
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.