Browse Source

Main functional added. Need Zoom/Move, Cursors.

tags/v0.1.0^2
Kolan Sh 2 years ago
parent
commit
f2e220b92e
10 changed files with 1652 additions and 75 deletions
  1. 2
    2
      .gitmodules
  2. 3
    3
      CMakeLists.txt
  3. 3
    1
      src/CMakeLists.txt
  4. 115
    0
      src/Common.vala
  5. 983
    37
      src/GtkChart.vala
  6. 169
    0
      src/Series.vala
  7. 1
    0
      src/float128type.h
  8. 2
    0
      src/float128type.vapi
  9. 2
    2
      test/CMakeLists.txt
  10. 372
    30
      test/ChartTest.vala

+ 2
- 2
.gitmodules View File

@@ -1,6 +1,6 @@
1 1
 [submodule "cmake/backbone"]
2 2
 	path = cmake/backbone
3
-	url = git@git.backbone.ws:cmake/backbone.git
3
+	url = git@git.backbone.ws:make/cmake-backbone-modules.git
4 4
 [submodule "util/backbone-utils"]
5 5
 	path = util/backbone
6
-	url = git@git.backbone.ws:cmake/backbone-utils.git
6
+	url = git@git.backbone.ws:make/cmake-backbone-utils.git

+ 3
- 3
CMakeLists.txt View File

@@ -1,9 +1,9 @@
1
-PROJECT (GtkChart C)
1
+PROJECT (CairoChart C)
2 2
 
3 3
 CMAKE_MINIMUM_REQUIRED (VERSION 2.8)
4 4
 
5
-SET (PROJECT_LOWERCASE_NAME "gtk-chart")
6
-SET (PROJECT_DESCRIPTION "GtkChart for Gtk.DrawingArea.")
5
+SET (PROJECT_LOWERCASE_NAME "cairo-chart")
6
+SET (PROJECT_DESCRIPTION "GtkChart for Gtk.DrawingArea (Cairo).")
7 7
 
8 8
 SET (MAJOR 0)
9 9
 SET (MINOR 0)

+ 3
- 1
src/CMakeLists.txt View File

@@ -1,9 +1,11 @@
1 1
 SET (LibName ${PROJECT_LOWERCASE_NAME})
2 2
 FILE (GLOB_RECURSE LibSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.vala)
3
-SET (LibPackages cairo)
3
+SET (LibPackages cairo gtk+-3.0)
4 4
 SET (LibPkgModules gtk+-3.0)
5 5
 SET (LibInstall ON)
6 6
 SET (LibExtraSources ${CMAKE_CURRENT_BINARY_DIR}/library_constructor.c)
7 7
 SET (LC_RELATIVE_PREFIX "..")
8 8
 CONFIGURE_FILE ( "${CMAKE_SOURCE_DIR}/cmake/backbone/templates/library_constructor.c.in" "${LibExtraSources}")
9
+INCLUDE_DIRECTORIES ("${CMAKE_SOURCE_DIR}/src")
10
+SET (LibCustomVapis ${CMAKE_SOURCE_DIR}/src/float128type.vapi)
9 11
 INCLUDE (ValaLibCommonRules)

+ 115
- 0
src/Common.vala View File

@@ -0,0 +1,115 @@
1
+using Cairo;
2
+
3
+namespace Gtk.CairoChart {
4
+
5
+	public struct Color {
6
+		double red;
7
+		double green;
8
+		double blue;
9
+		double alpha;
10
+
11
+		public Color (double red = 0.0, double green = 0.0, double blue = 0.0, double alpha = 1.0) {
12
+			this.red = red; this.green = green; this.blue = blue; this.alpha = alpha;
13
+		}
14
+	}
15
+
16
+	public enum FontOrient {
17
+			HORIZONTAL = 0,
18
+			VERTICAL
19
+		}
20
+	public struct FontStyle {
21
+		string family;
22
+		FontSlant slant;
23
+		FontWeight weight;
24
+
25
+		FontOrient orientation;
26
+		double size;
27
+
28
+		public FontStyle (string family = "Sans",
29
+		                  FontSlant slant = Cairo.FontSlant.NORMAL,
30
+		                  FontWeight weight = Cairo.FontWeight.NORMAL,
31
+		                  double size = 10) {
32
+			this.family = family;
33
+			this.slant = slant;
34
+			this.weight = weight;
35
+			this.size = size;
36
+		}
37
+	}
38
+
39
+	public struct LineStyle {
40
+		double width;
41
+		LineJoin line_join;
42
+		LineCap line_cap;
43
+		double[]? dashes;
44
+		double dash_offset;
45
+		Color color;
46
+
47
+		public LineStyle (double width = 1,
48
+		                  LineJoin line_join = Cairo.LineJoin.MITER,
49
+		                  LineCap line_cap = Cairo.LineCap.ROUND,
50
+		                  double[]? dashes = null, double dash_offset = 0,
51
+		                  Color color = Color()) {
52
+			this.width = width;
53
+			this.line_join = line_join;
54
+			this.line_cap = line_cap;
55
+			this.dashes = dashes;
56
+			this.dash_offset = dash_offset;
57
+			this.color = color;
58
+		}
59
+	}
60
+
61
+	[Compact]
62
+	public class Text {
63
+		public string text = "";
64
+		public FontStyle style = new FontStyle ();
65
+		public Color color = new Color();
66
+
67
+		TextExtents get_extents (Cairo.Context context) {
68
+			context.select_font_face (style.family,
69
+			                          style.slant,
70
+			                          style.weight);
71
+			context.set_font_size (style.size);
72
+			TextExtents extents;
73
+			context.text_extents (text, out extents);
74
+			return extents;
75
+		}
76
+
77
+		public double get_width (Cairo.Context context) {
78
+			var extents = get_extents (context);
79
+			if (style.orientation == FontOrient.HORIZONTAL)
80
+				return extents.width;
81
+			else
82
+				return extents.height;
83
+		}
84
+
85
+		public double get_height (Cairo.Context context) {
86
+			var extents = get_extents (context);
87
+			if (style.orientation == FontOrient.HORIZONTAL)
88
+				return extents.height;
89
+			else
90
+				return extents.width;
91
+		}
92
+
93
+		public double get_x_bearing (Cairo.Context context) {
94
+			var extents = get_extents (context);
95
+			if (style.orientation == FontOrient.HORIZONTAL)
96
+				return extents.x_bearing;
97
+			else
98
+				return extents.y_bearing;
99
+		}
100
+
101
+		public Text (string text = "",
102
+		             FontStyle style = new FontStyle(),
103
+		             Color color = new Color()) {
104
+			this.text = text;
105
+			this.style = style;
106
+			this.color = color;
107
+		}
108
+
109
+		public Text.by_instance (Text text) {
110
+			this.text = text.text;
111
+			this.style = text.style;
112
+			this.color = text.color;
113
+		}
114
+	}
115
+}

+ 983
- 37
src/GtkChart.vala
File diff suppressed because it is too large
View File


+ 169
- 0
src/Series.vala View File

@@ -0,0 +1,169 @@
1
+using Cairo;
2
+
3
+namespace Gtk.CairoChart {
4
+
5
+	public class Series {
6
+
7
+		public struct Point {
8
+			Double128 x;
9
+			Double128 y;
10
+
11
+			public Point (Double128 x, Double128 y) {
12
+				this.x = x; this.y = y;
13
+			}
14
+		}
15
+
16
+		public Point[] points = {};
17
+		public enum Sort {
18
+			BY_X = 0,
19
+			BY_Y = 1,
20
+			NO_SORT
21
+		}
22
+		public Sort sort = Sort.BY_X;
23
+
24
+		// If one of axis:title or axis:min/max are different
25
+		// then draw separate axis for each/all series
26
+		// or specify series name near the axis
27
+		public class Axis {
28
+			public Double128 min = 0;
29
+			public Double128 max = 1;
30
+			public Text title = new Text ("");
31
+			public enum Type {
32
+				NUMBERS = 0,
33
+				DATE_TIME
34
+			}
35
+			public enum ScaleType {
36
+				LINEAR = 0,		// default
37
+				// LOGARITHMIC, // TODO
38
+				// etc
39
+			}
40
+			public Type type;
41
+			public ScaleType scale_type;
42
+			public enum Position {
43
+				LOW = 0,
44
+				HIGH = 1,
45
+				BOTH = 2
46
+			}
47
+			public Position position = Position.LOW;
48
+
49
+			string _format = "%.2Lf";
50
+			string _date_format = "%Y.%m.%d";
51
+			string _time_format = "%H:%M:%S";
52
+			int _dsec_signs = 2; // 2 signs = centiseconds
53
+			public string format {
54
+				get { return _format; }
55
+				set {
56
+					// TODO: check format
57
+					_format = value;
58
+				}
59
+				default = "%.2Lf";
60
+			}
61
+			public string date_format {
62
+				get { return _date_format; }
63
+				set {
64
+					// TODO: check format
65
+					_date_format = value;
66
+				}
67
+				default = "%Y.%m.%d";
68
+			}
69
+			public string time_format {
70
+				get { return _time_format; }
71
+				set {
72
+					// TODO: check format
73
+					_time_format = value;
74
+				}
75
+				default = "%H:%M:%S";
76
+			}
77
+			public int dsec_signs {
78
+				get { return _dsec_signs; }
79
+				set {
80
+					// TODO: check format
81
+					_dsec_signs = value;
82
+				}
83
+				default = 2;
84
+			}
85
+			public FontStyle font_style = new FontStyle ();
86
+			public Color color = new Color ();
87
+			public LineStyle line_style = new LineStyle ();
88
+			public double font_indent = 5;
89
+
90
+			public Axis () {}
91
+		}
92
+
93
+		public Axis axis_x = new Axis();
94
+		public Axis axis_y = new Axis();
95
+
96
+		public struct Place {
97
+			double x_low;
98
+			double x_high;
99
+			double y_low;
100
+			double y_high;
101
+
102
+			public Place (double x_low = 0, double x_high = 0, double y_low = 0, double y_high = 0) {
103
+				this.x_low = x_low;
104
+				this.x_high = x_high;
105
+				this.y_low = y_low;
106
+				this.y_high = y_high;
107
+			}
108
+		}
109
+
110
+		public enum MarkerType {
111
+			NONE = 0,	// default
112
+			SQUARE,
113
+			CIRCLE,
114
+			TRIANGLE,
115
+			PRICLE_SQUARE,
116
+			PRICLE_CIRCLE,
117
+			PRICLE_TRIANGLE
118
+		}
119
+
120
+		public Place place = new Place();
121
+		public Text title = new Text ();
122
+		public MarkerType marker_type = MarkerType.SQUARE;
123
+
124
+		public class Grid {
125
+			/*public enum GridType {
126
+				PRICK_LINE = 0, // default
127
+				LINE
128
+			}*/
129
+			public Color color = Color (0, 0, 0, 0.1);
130
+
131
+			public LineStyle line_style = new LineStyle ();
132
+
133
+			public Grid () {
134
+				line_style.dashes = {2, 3};
135
+			}
136
+		}
137
+
138
+		public Grid grid = new Grid ();
139
+
140
+		public GLib.List<Double128?> cursors = new List<Double128?> ();
141
+		public LineStyle line_style = new LineStyle ();
142
+
143
+		protected Color _color = Color (0.0, 0.0, 0.0, 1.0);
144
+		public Color color {
145
+			get { return _color; }
146
+			set {
147
+				_color = value;
148
+				line_style.color = _color;
149
+				axis_x.color = _color;
150
+				axis_y.color = _color;
151
+				grid.color = _color;
152
+				grid.color.alpha = 0.5;
153
+				grid.line_style.color = _color;
154
+				grid.line_style.color.alpha = 0.5;
155
+			}
156
+			default = new Color (0.0, 0.0, 0.0, 1.0);
157
+		}
158
+
159
+		public Series () {
160
+		}
161
+
162
+		public class LabelStyle {
163
+			FontStyle font_style = new FontStyle();
164
+			LineStyle frame_line_style = new LineStyle();
165
+			Color bg_color = new Color();
166
+			Color frame_color = new Color();
167
+		}
168
+	}
169
+}

+ 1
- 0
src/float128type.h View File

@@ -0,0 +1 @@
1
+typedef long double double128;

+ 2
- 0
src/float128type.vapi View File

@@ -0,0 +1,2 @@
1
+[CCode (cname = "double128", has_type_id = false, cheader_filename = "float128type.h")]
2
+public struct Double128 : double {}

+ 2
- 2
test/CMakeLists.txt View File

@@ -1,7 +1,7 @@
1 1
 SET (BinName chart_test)
2 2
 FILE (GLOB_RECURSE BinSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ChartTest.vala)
3 3
 SET (BinPackages gtk+-3.0)
4
-SET (BinCustomVapis ${CMAKE_BINARY_DIR}/src/${PROJECT_LOWERCASE_NAME}-${MAJOR}.vapi)
4
+SET (BinCustomVapis ${CMAKE_BINARY_DIR}/src/${PROJECT_LOWERCASE_NAME}-${MAJOR}.vapi ${CMAKE_SOURCE_DIR}/src/float128type.vapi)
5 5
 SET (BinLinkLibs ${PROJECT_LOWERCASE_NAME})
6
-INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src")
6
+INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src;${CMAKE_SOURCE_DIR}/src")
7 7
 INCLUDE (ValaBinCommonRules)

+ 372
- 30
test/ChartTest.vala View File

@@ -1,43 +1,385 @@
1
-using Gtk;
1
+using Gtk, CairoChart;
2
+
3
+void plot_chart1 (Chart chart) {
4
+	var s1 = new Series ();
5
+	var s2 = new Series ();
6
+	var s3 = new Series ();
7
+
8
+	s1.title = new Text("Series 1"); s1.color = new Color (1, 0, 0);
9
+	s1.points = {new Series.Point(0, 0), new Series.Point(2, 1), new Series.Point(1, 3)};
10
+	s1.axis_x.position = Series.Axis.Position.HIGH;
11
+	s1.axis_x.format = "%.3Lf";
12
+	s2.title = new Text("Series 2"); s2.color = new Color (0, 1, 0);
13
+	s2.points = {new Series.Point(5, -3), new Series.Point(25, -18), new Series.Point(-11, 173)};
14
+	s3.title = new Text("Series 3"); s3.color = new Color (0, 0, 1);
15
+	s3.points = {new Series.Point(9, 17), new Series.Point(2, 10), new Series.Point(122, 31)};
16
+	s3.axis_y.position = Series.Axis.Position.HIGH;
17
+
18
+	s1.axis_x.min = 0; s1.axis_x.max = 2;
19
+	s1.axis_y.min = 0; s1.axis_y.max = 3;
20
+	s1.place.x_low = 0.25; s1.place.x_high = 0.75;
21
+	s1.place.y_low = 0.3; s1.place.y_high = 0.9;
22
+
23
+	s2.axis_x.min = -15; s2.axis_x.max = 30;
24
+	s2.axis_y.min = -20; s2.axis_y.max = 200;
25
+	s2.place.x_low = 0.5; s2.place.x_high = 1;
26
+	s2.place.y_low = 0.0; s2.place.y_high = 0.5;
27
+
28
+	s3.axis_x.min = 0; s3.axis_x.max = 130;
29
+	s3.axis_y.min = 15; s3.axis_y.max = 35;
30
+	s3.place.x_low = 0; s3.place.x_high = 0.5;
31
+	s3.place.y_low = 0.5; s3.place.y_high = 1.0;
32
+
33
+	s2.marker_type = Series.MarkerType.CIRCLE;
34
+	s3.marker_type = Series.MarkerType.PRICLE_TRIANGLE;
35
+
36
+	s1.axis_x.title = new Text("Series 1: Axis X.");
37
+	s1.axis_y.title = new Text("Series 1: Axis Y.");
38
+	s2.axis_x.title = new Text("Series 2: Axis X.");
39
+	s2.axis_y.title = new Text("Series 2: Axis Y.");
40
+	s3.axis_x.title = new Text("Series 3: Axis X.");
41
+	s3.axis_y.title = new Text("Series 3: Axis Y.");
42
+
43
+	chart.series = { s1, s2, s3 };
44
+}
45
+
46
+void plot_chart2 (Chart chart) {
47
+	var s1 = new Series ();
48
+	var s2 = new Series ();
49
+	var s3 = new Series ();
50
+
51
+	s1.title = new Text("Series 1"); s1.color = new Color (1, 0, 0);
52
+	s1.points = {new Series.Point(-12, 0), new Series.Point(2, 1), new Series.Point(20, 3)};
53
+	s2.axis_y.position = Series.Axis.Position.HIGH;
54
+	s1.axis_x.format = "%.3Lf";
55
+	s2.title = new Text("Series 2"); s2.color = new Color (0, 1, 0);
56
+	s2.points = {new Series.Point(5, -3), new Series.Point(25, -18), new Series.Point(-11, 173)};
57
+	s3.title = new Text("Series 3"); s3.color = new Color (0, 0, 1);
58
+	s3.points = {new Series.Point(9, 17), new Series.Point(2, 10), new Series.Point(-15, 31)};
59
+	s3.axis_y.position = Series.Axis.Position.HIGH;
60
+
61
+	s1.axis_x.min = -15; s1.axis_x.max = 30;
62
+	s1.axis_y.min = 0; s1.axis_y.max = 3;
63
+	s1.place.x_low = 0.0; s1.place.x_high = 1.0;
64
+	s1.place.y_low = 0.3; s1.place.y_high = 0.9;
65
+
66
+	s2.axis_x.min = -15; s2.axis_x.max = 30;
67
+	s2.axis_y.min = -20; s2.axis_y.max = 200;
68
+	s2.place.x_low = 0.0; s2.place.x_high = 1.0;
69
+	s2.place.y_low = 0.0; s2.place.y_high = 0.5;
70
+
71
+	s3.axis_x.min = -15; s3.axis_x.max = 30;
72
+	s3.axis_y.min = 15; s3.axis_y.max = 35;
73
+	s3.place.x_low = 0.0; s3.place.x_high = 1.0;
74
+	s3.place.y_low = 0.5; s3.place.y_high = 1.0;
75
+
76
+	s1.marker_type = Series.MarkerType.PRICLE_CIRCLE;
77
+	s2.marker_type = Series.MarkerType.PRICLE_SQUARE;
78
+
79
+	s1.axis_x.title = new Text("All Series: Axis X.");
80
+	s1.axis_y.title = new Text("Series 1: Axis Y.");
81
+	s2.axis_x.title = new Text("All Series: Axis X.");
82
+	s2.axis_y.title = new Text("Series 2: Axis Y.");
83
+	s3.axis_x.title = new Text("All Series: Axis X.");
84
+	s3.axis_y.title = new Text("Series 3: Axis Y.");
85
+
86
+	chart.series = { s1, s2, s3 };
87
+}
88
+
89
+void plot_chart3 (Chart chart) {
90
+	var s1 = new Series ();
91
+	var s2 = new Series ();
92
+	var s3 = new Series ();
93
+
94
+	s1.title = new Text("Series 1"); s1.color = new Color (1, 0, 0);
95
+	s1.points = {new Series.Point(0, 70), new Series.Point(2, 155), new Series.Point(1, -3)};
96
+	s1.axis_x.position = Series.Axis.Position.HIGH;
97
+	s1.axis_y.position = Series.Axis.Position.HIGH;
98
+	s1.axis_x.format = "%.3Lf";
99
+	s2.title = new Text("Series 2"); s2.color = new Color (0, 1, 0);
100
+	s2.points = {new Series.Point(5, -3), new Series.Point(25, -18), new Series.Point(-11, 173)};
101
+	s2.axis_y.position = Series.Axis.Position.HIGH;
102
+	s3.title = new Text("Series 3"); s3.color = new Color (0, 0, 1);
103
+	s3.points = {new Series.Point(9, -17), new Series.Point(2, 10), new Series.Point(122, 31)};
104
+	s3.axis_y.position = Series.Axis.Position.HIGH;
105
+
106
+	s1.axis_x.min = 0; s1.axis_x.max = 2;
107
+	s1.axis_y.min = -20; s1.axis_y.max = 200;
108
+	s1.place.x_low = 0.25; s1.place.x_high = 0.75;
109
+	s1.place.y_low = 0.0; s1.place.y_high = 1.0;
110
+
111
+	s2.axis_x.min = -15; s2.axis_x.max = 30;
112
+	s2.axis_y.min = -20; s2.axis_y.max = 200;
113
+	s2.place.x_low = 0.5; s2.place.x_high = 1;
114
+	s2.place.y_low = 0.0; s2.place.y_high = 1.0;
115
+
116
+	s3.axis_x.min = 0; s3.axis_x.max = 130;
117
+	s3.axis_y.min = -20; s3.axis_y.max = 200;
118
+	s3.place.x_low = 0; s3.place.x_high = 0.5;
119
+	s3.place.y_low = 0.0; s3.place.y_high = 1.0;
120
+
121
+	s2.marker_type = Series.MarkerType.PRICLE_CIRCLE;
122
+	s3.marker_type = Series.MarkerType.TRIANGLE;
123
+
124
+	s1.axis_x.title = new Text("Series 1: Axis X.");
125
+	s1.axis_y.title = new Text("Series 1: Axis Y.");
126
+	s2.axis_x.title = new Text("Series 2: Axis X.");
127
+	s2.axis_y.title = new Text("Series 2: Axis Y.");
128
+	s3.axis_x.title = new Text("Series 3: Axis X.");
129
+	s3.axis_y.title = new Text("Series 3: Axis Y.");
130
+
131
+	chart.series = { s1, s2, s3 };
132
+}
133
+
134
+void plot_chart4 (Chart chart) {
135
+	var s1 = new Series ();
136
+	var s2 = new Series ();
137
+	var s3 = new Series ();
138
+	var s4 = new Series ();
139
+
140
+	s1.axis_x.type = Series.Axis.Type.DATE_TIME;
141
+	s3.axis_x.type = Series.Axis.Type.DATE_TIME;
142
+	s4.axis_x.type = Series.Axis.Type.DATE_TIME;
143
+	s4.axis_x.dsec_signs = 5;
144
+
145
+	var now = new DateTime.now_local().to_unix();
146
+	var high = (uint64) (253000000000L);
147
+
148
+	s1.title = new Text("Series 1"); s1.color = new Color (1, 0, 0);
149
+	s1.points = {new Series.Point(now, 70), new Series.Point(now - 100000, 155), new Series.Point(now + 100000, 30)};
150
+	s1.axis_x.position = Series.Axis.Position.HIGH;
151
+	s1.axis_y.position = Series.Axis.Position.HIGH;
152
+	s2.title = new Text("Series 2"); s2.color = new Color (0, 1, 0);
153
+	s2.points = {new Series.Point(5, -3), new Series.Point(25, -18), new Series.Point(-11, 173)};
154
+	s2.axis_y.position = Series.Axis.Position.HIGH;
155
+	s3.title = new Text("Series 3"); s3.color = new Color (0, 0, 1);
156
+	s3.points = {new Series.Point(high - 2 + 0.73, -17), new Series.Point(high - 1 + 0.234, 10), new Series.Point(high + 1 + 0.411, 31)};
157
+	s3.axis_y.position = Series.Axis.Position.HIGH;
158
+	s4.title = new Text("Series 4"); s4.color = new Color (0.5, 0.3, 0.9);
159
+	s4.points = {new Series.Point(high + 0.005, -19.05), new Series.Point(high + 0.0051, 28), new Series.Point(high + 0.0052, 55), new Series.Point(high + 0.0053, 44)};
160
+	s4.axis_y.position = Series.Axis.Position.HIGH;
161
+
162
+	s1.axis_x.min = now - 100000; s1.axis_x.max = now + 100000;
163
+	s1.axis_y.min = -20; s1.axis_y.max = 200;
164
+	s1.place.x_low = 0.25; s1.place.x_high = 0.75;
165
+	s1.place.y_low = 0.0; s1.place.y_high = 1.0;
166
+
167
+	s2.axis_x.min = -15; s2.axis_x.max = 30;
168
+	s2.axis_y.min = -20; s2.axis_y.max = 200;
169
+	s2.place.x_low = 0.2; s2.place.x_high = 1;
170
+	s2.place.y_low = 0.0; s2.place.y_high = 1.0;
171
+
172
+	s3.axis_x.min = high - 2; s3.axis_x.max = high + 1;
173
+	s3.axis_y.min = -20; s3.axis_y.max = 200;
174
+	s3.place.x_low = 0; s3.place.x_high = 0.8;
175
+	s3.place.y_low = 0.0; s3.place.y_high = 1.0;
176
+
177
+	s4.axis_x.min = high + 0.0049; s4.axis_x.max = high + 0.0054;
178
+	s4.axis_y.min = -20; s4.axis_y.max = 200;
179
+	s4.place.x_low = 0.2; s4.place.x_high = 1.0;
180
+	s4.place.y_low = 0.0; s4.place.y_high = 1.0;
181
+
182
+	s2.marker_type = Series.MarkerType.PRICLE_CIRCLE;
183
+	s3.marker_type = Series.MarkerType.TRIANGLE;
184
+	s4.marker_type = Series.MarkerType.PRICLE_SQUARE;
185
+
186
+	s1.axis_x.title = new Text("Series 1: Axis X.");
187
+	s1.axis_y.title = new Text("Series 1: Axis Y.");
188
+	s2.axis_x.title = new Text("Series 2: Axis X.");
189
+	s2.axis_y.title = new Text("Series 2: Axis Y.");
190
+	s3.axis_x.title = new Text("Series 3: Axis X.");
191
+	s3.axis_y.title = new Text("Series 3: Axis Y.");
192
+	s4.axis_x.title = new Text("Series 4: Axis X.");
193
+	s4.axis_y.title = new Text("Series 4: Axis Y.");
194
+
195
+	chart.series = { s1, s2, s3, s4 };
196
+}
2 197
 
3 198
 int main (string[] args) {
4
-    init (ref args);
199
+	init (ref args);
5 200
 
6
-    var window = new Window ();
7
-    window.title = "Gtk.Chart Test.";
8
-    window.border_width = 10;
9
-    window.window_position = WindowPosition.CENTER;
10
-    window.set_default_size (640, 480);
11
-    window.destroy.connect (main_quit);
201
+	var window = new Window ();
202
+	window.title = "Chart Test.";
203
+	window.border_width = 5;
204
+	window.window_position = WindowPosition.CENTER;
205
+	window.set_default_size (640, 480);
206
+	window.destroy.connect (main_quit);
12 207
 
13
-    var da = new DrawingArea();
14
-    var chart = new Gtk.Chart();
15
-    var label = new Label ("Gtk.Chart Test!");
16
-    var button = new Button.with_label("Click me");
17
-    button.clicked.connect (() => {
18
-		da.draw.connect((context) => {
19
-			chart.draw(context);
20
-			return true;
21
-		});
208
+	var chart1 = new Chart();
209
+	var chart2 = new Chart();
210
+	var chart3 = new Chart();
211
+	var chart4 = new Chart();
212
+	var label = new Label ("Chart Test!");
213
+	var button1 = new Button.with_label("Separate axes");
214
+	var button2 = new Button.with_label("Common X axes");
215
+	var button3 = new Button.with_label("Common Y axes");
216
+	var button4 = new Button.with_label("Dates/Times");
217
+	var button5 = new Button.with_label("rm Axis Titles");
218
+	var button6 = new Button.with_label("rm Dates");
219
+	var button7 = new Button.with_label("rm Times");
22 220
 
23
-		da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
221
+	plot_chart1 (chart1);
222
+	plot_chart2 (chart2);
223
+	plot_chart3 (chart3);
224
+	plot_chart4 (chart4);
225
+
226
+	var da = new DrawingArea();
227
+	da.set_events ( Gdk.EventMask.BUTTON_PRESS_MASK
228
+	               |Gdk.EventMask.BUTTON_RELEASE_MASK
229
+	               |Gdk.EventMask.POINTER_MOTION_MASK
230
+	);
231
+
232
+	var chart = chart1;
233
+
234
+	var radio_button1 = new RadioButton.with_label (null, "Top Legend");
235
+	var radio_button2 = new RadioButton.with_label (radio_button1.get_group(), "Right Legend");
236
+	var radio_button3 = new RadioButton.with_label_from_widget (radio_button1, "Left Legend");
237
+	var radio_button4 = new RadioButton.with_label_from_widget (radio_button1, "Bottom Legend");
238
+
239
+	button1.clicked.connect (() => {
240
+			chart = chart1; da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
241
+			switch (chart.legend.position) {
242
+			case Chart.Legend.Position.TOP: radio_button1.set_active(true); break;
243
+			case Chart.Legend.Position.RIGHT: radio_button2.set_active(true); break;
244
+			case Chart.Legend.Position.LEFT: radio_button3.set_active(true); break;
245
+			case Chart.Legend.Position.BOTTOM: radio_button4.set_active(true); break;
246
+			default: break;
247
+			}
248
+	});
249
+	button2.clicked.connect (() => {
250
+			chart = chart2; da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
251
+			switch (chart.legend.position) {
252
+			case Chart.Legend.Position.TOP: radio_button1.set_active(true); break;
253
+			case Chart.Legend.Position.RIGHT: radio_button2.set_active(true); break;
254
+			case Chart.Legend.Position.LEFT: radio_button3.set_active(true); break;
255
+			case Chart.Legend.Position.BOTTOM: radio_button4.set_active(true); break;
256
+			default: break;
257
+			}
258
+	});
259
+	button3.clicked.connect (() => {
260
+			chart = chart3; da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
261
+			switch (chart.legend.position) {
262
+			case Chart.Legend.Position.TOP: radio_button1.set_active(true); break;
263
+			case Chart.Legend.Position.RIGHT: radio_button2.set_active(true); break;
264
+			case Chart.Legend.Position.LEFT: radio_button3.set_active(true); break;
265
+			case Chart.Legend.Position.BOTTOM: radio_button4.set_active(true); break;
266
+			default: break;
267
+			}
268
+	});
269
+	button4.clicked.connect (() => {
270
+			chart = chart4; da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
271
+			switch (chart.legend.position) {
272
+			case Chart.Legend.Position.TOP: radio_button1.set_active(true); break;
273
+			case Chart.Legend.Position.RIGHT: radio_button2.set_active(true); break;
274
+			case Chart.Legend.Position.LEFT: radio_button4.set_active(true); break;
275
+			case Chart.Legend.Position.BOTTOM: radio_button4.set_active(true); break;
276
+			default: break;
277
+			}
278
+	});
279
+	button5.clicked.connect (() => {
280
+			for (var i = 0; i < chart.series.length; ++i) {
281
+				var s = chart.series[i];
282
+				s.axis_x.title.text = "";
283
+				s.axis_y.title.text = "";
284
+			}
285
+			da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
286
+	});
287
+	button6.clicked.connect (() => {
288
+			for (var i = 0; i < chart.series.length; ++i) {
289
+				var s = chart.series[i];
290
+				s.axis_x.date_format = "";
291
+			}
292
+			da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
293
+	});
294
+
295
+	button7.clicked.connect (() => {
296
+			for (var i = 0; i < chart.series.length; ++i) {
297
+				var s = chart.series[i];
298
+				s.axis_x.time_format = "";
299
+			}
300
+			da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
301
+	});
302
+
303
+
304
+	radio_button1.toggled.connect ((button) => {
305
+		if (button.get_active()) {
306
+			chart.legend.position = Chart.Legend.Position.TOP;
307
+			da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
308
+		}
309
+	});
310
+	radio_button2.toggled.connect ((button) => {
311
+		if (button.get_active()) {
312
+			chart.legend.position = Chart.Legend.Position.RIGHT;
313
+			da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
314
+		}
315
+	});
316
+	radio_button3.toggled.connect ((button) => {
317
+		if (button.get_active()) {
318
+			chart.legend.position = Chart.Legend.Position.LEFT;
319
+			da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
320
+		}
321
+	});
322
+	radio_button4.toggled.connect ((button) => {
323
+		if (button.get_active()) {
324
+			chart.legend.position = Chart.Legend.Position.BOTTOM;
325
+			da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
326
+		}
327
+	});
328
+
329
+	da.draw.connect((context) => {
330
+	    // user's pre draw operations here...
331
+		chart.context = context;
332
+		var ret = chart.draw();
333
+	    // user's post draw operations here...
334
+		return ret;
335
+	});
336
+	da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
337
+
338
+	da.button_release_event.connect((event) => {
339
+	    // user's pre button_release_event operations here...
340
+		var ret = chart.button_release_event(event);
341
+	    // user's post button_release_event operations here...
342
+		return ret;
343
+	});
344
+	da.button_press_event.connect((event) => {
345
+	    // user's pre button_press_event operations here...
346
+		var ret = chart.button_press_event(event);
347
+	    // user's post button_press_event operations here...
348
+		return ret;
349
+	});
350
+	da.motion_notify_event.connect((event) => {
351
+	    // user's pre motion_notify_event operations here...
352
+		var ret = chart.motion_notify_event(event);
353
+	    // user's post motion_notify_event operations here...
354
+		return ret;
24 355
 	});
25 356
 
26
-    var vbox2 = new Box(Orientation.VERTICAL, 0);
27
-    vbox2.pack_end(button, false, false, 0);
357
+	var vbox2 = new Box(Orientation.VERTICAL, 0);
358
+	vbox2.pack_start(button1, false, false, 0);
359
+	vbox2.pack_start(button2, false, false, 0);
360
+	vbox2.pack_start(button3, false, false, 0);
361
+	vbox2.pack_start(button4, false, false, 0);
362
+	vbox2.pack_start(button5, false, false, 0);
363
+	vbox2.pack_start(button6, false, false, 0);
364
+	vbox2.pack_start(button7, false, false, 0);
365
+	vbox2.pack_start(radio_button1, false, false, 0);
366
+	vbox2.pack_start(radio_button2, false, false, 0);
367
+	vbox2.pack_start(radio_button3, false, false, 0);
368
+	vbox2.pack_start(radio_button4, false, false, 0);
28 369
 
29
-    var hbox = new Box(Orientation.HORIZONTAL, 0);
30
-    hbox.pack_start(da, true, true, 0);
31
-    hbox.pack_end(vbox2, false, false, 0);
370
+	var hbox = new Box(Orientation.HORIZONTAL, 0);
371
+	hbox.pack_start(da, true, true, 0);
372
+	hbox.pack_end(vbox2, false, false, 0);
32 373
 
33
-    var vbox = new Box(Orientation.VERTICAL, 0);
34
-    vbox.pack_start(label, false, false, 0);
35
-    vbox.pack_end(hbox, true, true, 0);
374
+	var vbox = new Box(Orientation.VERTICAL, 0);
375
+	vbox.pack_start(label, false, false, 0);
376
+	vbox.pack_end(hbox, true, true, 0);
36 377
 
37
-    window.add(vbox);
378
+	window.add(vbox);
38 379
 
39
-    window.show_all();
380
+	window.show_all();
40 381
 
41
-    Gtk.main();
42
-    return 0;
382
+Double128 d = 5.5;
383
+	Gtk.main();
384
+	return 0;
43 385
 }

Loading…
Cancel
Save