Main functional added. Need Zoom/Move, Cursors.
This commit is contained in:
parent
9d1cfc0ffa
commit
f2e220b92e
|
@ -1,6 +1,6 @@
|
|||
[submodule "cmake/backbone"]
|
||||
path = cmake/backbone
|
||||
url = git@git.backbone.ws:cmake/backbone.git
|
||||
url = git@git.backbone.ws:make/cmake-backbone-modules.git
|
||||
[submodule "util/backbone-utils"]
|
||||
path = util/backbone
|
||||
url = git@git.backbone.ws:cmake/backbone-utils.git
|
||||
url = git@git.backbone.ws:make/cmake-backbone-utils.git
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
PROJECT (GtkChart C)
|
||||
PROJECT (CairoChart C)
|
||||
|
||||
CMAKE_MINIMUM_REQUIRED (VERSION 2.8)
|
||||
|
||||
SET (PROJECT_LOWERCASE_NAME "gtk-chart")
|
||||
SET (PROJECT_DESCRIPTION "GtkChart for Gtk.DrawingArea.")
|
||||
SET (PROJECT_LOWERCASE_NAME "cairo-chart")
|
||||
SET (PROJECT_DESCRIPTION "GtkChart for Gtk.DrawingArea (Cairo).")
|
||||
|
||||
SET (MAJOR 0)
|
||||
SET (MINOR 0)
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
SET (LibName ${PROJECT_LOWERCASE_NAME})
|
||||
FILE (GLOB_RECURSE LibSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.vala)
|
||||
SET (LibPackages cairo)
|
||||
SET (LibPackages cairo gtk+-3.0)
|
||||
SET (LibPkgModules gtk+-3.0)
|
||||
SET (LibInstall ON)
|
||||
SET (LibExtraSources ${CMAKE_CURRENT_BINARY_DIR}/library_constructor.c)
|
||||
SET (LC_RELATIVE_PREFIX "..")
|
||||
CONFIGURE_FILE ( "${CMAKE_SOURCE_DIR}/cmake/backbone/templates/library_constructor.c.in" "${LibExtraSources}")
|
||||
INCLUDE_DIRECTORIES ("${CMAKE_SOURCE_DIR}/src")
|
||||
SET (LibCustomVapis ${CMAKE_SOURCE_DIR}/src/float128type.vapi)
|
||||
INCLUDE (ValaLibCommonRules)
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
using Cairo;
|
||||
|
||||
namespace Gtk.CairoChart {
|
||||
|
||||
public struct Color {
|
||||
double red;
|
||||
double green;
|
||||
double blue;
|
||||
double alpha;
|
||||
|
||||
public Color (double red = 0.0, double green = 0.0, double blue = 0.0, double alpha = 1.0) {
|
||||
this.red = red; this.green = green; this.blue = blue; this.alpha = alpha;
|
||||
}
|
||||
}
|
||||
|
||||
public enum FontOrient {
|
||||
HORIZONTAL = 0,
|
||||
VERTICAL
|
||||
}
|
||||
public struct FontStyle {
|
||||
string family;
|
||||
FontSlant slant;
|
||||
FontWeight weight;
|
||||
|
||||
FontOrient orientation;
|
||||
double size;
|
||||
|
||||
public FontStyle (string family = "Sans",
|
||||
FontSlant slant = Cairo.FontSlant.NORMAL,
|
||||
FontWeight weight = Cairo.FontWeight.NORMAL,
|
||||
double size = 10) {
|
||||
this.family = family;
|
||||
this.slant = slant;
|
||||
this.weight = weight;
|
||||
this.size = size;
|
||||
}
|
||||
}
|
||||
|
||||
public struct LineStyle {
|
||||
double width;
|
||||
LineJoin line_join;
|
||||
LineCap line_cap;
|
||||
double[]? dashes;
|
||||
double dash_offset;
|
||||
Color color;
|
||||
|
||||
public LineStyle (double width = 1,
|
||||
LineJoin line_join = Cairo.LineJoin.MITER,
|
||||
LineCap line_cap = Cairo.LineCap.ROUND,
|
||||
double[]? dashes = null, double dash_offset = 0,
|
||||
Color color = Color()) {
|
||||
this.width = width;
|
||||
this.line_join = line_join;
|
||||
this.line_cap = line_cap;
|
||||
this.dashes = dashes;
|
||||
this.dash_offset = dash_offset;
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
[Compact]
|
||||
public class Text {
|
||||
public string text = "";
|
||||
public FontStyle style = new FontStyle ();
|
||||
public Color color = new Color();
|
||||
|
||||
TextExtents get_extents (Cairo.Context context) {
|
||||
context.select_font_face (style.family,
|
||||
style.slant,
|
||||
style.weight);
|
||||
context.set_font_size (style.size);
|
||||
TextExtents extents;
|
||||
context.text_extents (text, out extents);
|
||||
return extents;
|
||||
}
|
||||
|
||||
public double get_width (Cairo.Context context) {
|
||||
var extents = get_extents (context);
|
||||
if (style.orientation == FontOrient.HORIZONTAL)
|
||||
return extents.width;
|
||||
else
|
||||
return extents.height;
|
||||
}
|
||||
|
||||
public double get_height (Cairo.Context context) {
|
||||
var extents = get_extents (context);
|
||||
if (style.orientation == FontOrient.HORIZONTAL)
|
||||
return extents.height;
|
||||
else
|
||||
return extents.width;
|
||||
}
|
||||
|
||||
public double get_x_bearing (Cairo.Context context) {
|
||||
var extents = get_extents (context);
|
||||
if (style.orientation == FontOrient.HORIZONTAL)
|
||||
return extents.x_bearing;
|
||||
else
|
||||
return extents.y_bearing;
|
||||
}
|
||||
|
||||
public Text (string text = "",
|
||||
FontStyle style = new FontStyle(),
|
||||
Color color = new Color()) {
|
||||
this.text = text;
|
||||
this.style = style;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Text.by_instance (Text text) {
|
||||
this.text = text.text;
|
||||
this.style = text.style;
|
||||
this.color = text.color;
|
||||
}
|
||||
}
|
||||
}
|
1016
src/GtkChart.vala
1016
src/GtkChart.vala
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,169 @@
|
|||
using Cairo;
|
||||
|
||||
namespace Gtk.CairoChart {
|
||||
|
||||
public class Series {
|
||||
|
||||
public struct Point {
|
||||
Double128 x;
|
||||
Double128 y;
|
||||
|
||||
public Point (Double128 x, Double128 y) {
|
||||
this.x = x; this.y = y;
|
||||
}
|
||||
}
|
||||
|
||||
public Point[] points = {};
|
||||
public enum Sort {
|
||||
BY_X = 0,
|
||||
BY_Y = 1,
|
||||
NO_SORT
|
||||
}
|
||||
public Sort sort = Sort.BY_X;
|
||||
|
||||
// If one of axis:title or axis:min/max are different
|
||||
// then draw separate axis for each/all series
|
||||
// or specify series name near the axis
|
||||
public class Axis {
|
||||
public Double128 min = 0;
|
||||
public Double128 max = 1;
|
||||
public Text title = new Text ("");
|
||||
public enum Type {
|
||||
NUMBERS = 0,
|
||||
DATE_TIME
|
||||
}
|
||||
public enum ScaleType {
|
||||
LINEAR = 0, // default
|
||||
// LOGARITHMIC, // TODO
|
||||
// etc
|
||||
}
|
||||
public Type type;
|
||||
public ScaleType scale_type;
|
||||
public enum Position {
|
||||
LOW = 0,
|
||||
HIGH = 1,
|
||||
BOTH = 2
|
||||
}
|
||||
public Position position = Position.LOW;
|
||||
|
||||
string _format = "%.2Lf";
|
||||
string _date_format = "%Y.%m.%d";
|
||||
string _time_format = "%H:%M:%S";
|
||||
int _dsec_signs = 2; // 2 signs = centiseconds
|
||||
public string format {
|
||||
get { return _format; }
|
||||
set {
|
||||
// TODO: check format
|
||||
_format = value;
|
||||
}
|
||||
default = "%.2Lf";
|
||||
}
|
||||
public string date_format {
|
||||
get { return _date_format; }
|
||||
set {
|
||||
// TODO: check format
|
||||
_date_format = value;
|
||||
}
|
||||
default = "%Y.%m.%d";
|
||||
}
|
||||
public string time_format {
|
||||
get { return _time_format; }
|
||||
set {
|
||||
// TODO: check format
|
||||
_time_format = value;
|
||||
}
|
||||
default = "%H:%M:%S";
|
||||
}
|
||||
public int dsec_signs {
|
||||
get { return _dsec_signs; }
|
||||
set {
|
||||
// TODO: check format
|
||||
_dsec_signs = value;
|
||||
}
|
||||
default = 2;
|
||||
}
|
||||
public FontStyle font_style = new FontStyle ();
|
||||
public Color color = new Color ();
|
||||
public LineStyle line_style = new LineStyle ();
|
||||
public double font_indent = 5;
|
||||
|
||||
public Axis () {}
|
||||
}
|
||||
|
||||
public Axis axis_x = new Axis();
|
||||
public Axis axis_y = new Axis();
|
||||
|
||||
public struct Place {
|
||||
double x_low;
|
||||
double x_high;
|
||||
double y_low;
|
||||
double y_high;
|
||||
|
||||
public Place (double x_low = 0, double x_high = 0, double y_low = 0, double y_high = 0) {
|
||||
this.x_low = x_low;
|
||||
this.x_high = x_high;
|
||||
this.y_low = y_low;
|
||||
this.y_high = y_high;
|
||||
}
|
||||
}
|
||||
|
||||
public enum MarkerType {
|
||||
NONE = 0, // default
|
||||
SQUARE,
|
||||
CIRCLE,
|
||||
TRIANGLE,
|
||||
PRICLE_SQUARE,
|
||||
PRICLE_CIRCLE,
|
||||
PRICLE_TRIANGLE
|
||||
}
|
||||
|
||||
public Place place = new Place();
|
||||
public Text title = new Text ();
|
||||
public MarkerType marker_type = MarkerType.SQUARE;
|
||||
|
||||
public class Grid {
|
||||
/*public enum GridType {
|
||||
PRICK_LINE = 0, // default
|
||||
LINE
|
||||
}*/
|
||||
public Color color = Color (0, 0, 0, 0.1);
|
||||
|
||||
public LineStyle line_style = new LineStyle ();
|
||||
|
||||
public Grid () {
|
||||
line_style.dashes = {2, 3};
|
||||
}
|
||||
}
|
||||
|
||||
public Grid grid = new Grid ();
|
||||
|
||||
public GLib.List<Double128?> cursors = new List<Double128?> ();
|
||||
public LineStyle line_style = new LineStyle ();
|
||||
|
||||
protected Color _color = Color (0.0, 0.0, 0.0, 1.0);
|
||||
public Color color {
|
||||
get { return _color; }
|
||||
set {
|
||||
_color = value;
|
||||
line_style.color = _color;
|
||||
axis_x.color = _color;
|
||||
axis_y.color = _color;
|
||||
grid.color = _color;
|
||||
grid.color.alpha = 0.5;
|
||||
grid.line_style.color = _color;
|
||||
grid.line_style.color.alpha = 0.5;
|
||||
}
|
||||
default = new Color (0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
public Series () {
|
||||
}
|
||||
|
||||
public class LabelStyle {
|
||||
FontStyle font_style = new FontStyle();
|
||||
LineStyle frame_line_style = new LineStyle();
|
||||
Color bg_color = new Color();
|
||||
Color frame_color = new Color();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
typedef long double double128;
|
|
@ -0,0 +1,2 @@
|
|||
[CCode (cname = "double128", has_type_id = false, cheader_filename = "float128type.h")]
|
||||
public struct Double128 : double {}
|
|
@ -1,7 +1,7 @@
|
|||
SET (BinName chart_test)
|
||||
FILE (GLOB_RECURSE BinSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ChartTest.vala)
|
||||
SET (BinPackages gtk+-3.0)
|
||||
SET (BinCustomVapis ${CMAKE_BINARY_DIR}/src/${PROJECT_LOWERCASE_NAME}-${MAJOR}.vapi)
|
||||
SET (BinCustomVapis ${CMAKE_BINARY_DIR}/src/${PROJECT_LOWERCASE_NAME}-${MAJOR}.vapi ${CMAKE_SOURCE_DIR}/src/float128type.vapi)
|
||||
SET (BinLinkLibs ${PROJECT_LOWERCASE_NAME})
|
||||
INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src")
|
||||
INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src;${CMAKE_SOURCE_DIR}/src")
|
||||
INCLUDE (ValaBinCommonRules)
|
||||
|
|
|
@ -1,30 +1,371 @@
|
|||
using Gtk;
|
||||
using Gtk, CairoChart;
|
||||
|
||||
void plot_chart1 (Chart chart) {
|
||||
var s1 = new Series ();
|
||||
var s2 = new Series ();
|
||||
var s3 = new Series ();
|
||||
|
||||
s1.title = new Text("Series 1"); s1.color = new Color (1, 0, 0);
|
||||
s1.points = {new Series.Point(0, 0), new Series.Point(2, 1), new Series.Point(1, 3)};
|
||||
s1.axis_x.position = Series.Axis.Position.HIGH;
|
||||
s1.axis_x.format = "%.3Lf";
|
||||
s2.title = new Text("Series 2"); s2.color = new Color (0, 1, 0);
|
||||
s2.points = {new Series.Point(5, -3), new Series.Point(25, -18), new Series.Point(-11, 173)};
|
||||
s3.title = new Text("Series 3"); s3.color = new Color (0, 0, 1);
|
||||
s3.points = {new Series.Point(9, 17), new Series.Point(2, 10), new Series.Point(122, 31)};
|
||||
s3.axis_y.position = Series.Axis.Position.HIGH;
|
||||
|
||||
s1.axis_x.min = 0; s1.axis_x.max = 2;
|
||||
s1.axis_y.min = 0; s1.axis_y.max = 3;
|
||||
s1.place.x_low = 0.25; s1.place.x_high = 0.75;
|
||||
s1.place.y_low = 0.3; s1.place.y_high = 0.9;
|
||||
|
||||
s2.axis_x.min = -15; s2.axis_x.max = 30;
|
||||
s2.axis_y.min = -20; s2.axis_y.max = 200;
|
||||
s2.place.x_low = 0.5; s2.place.x_high = 1;
|
||||
s2.place.y_low = 0.0; s2.place.y_high = 0.5;
|
||||
|
||||
s3.axis_x.min = 0; s3.axis_x.max = 130;
|
||||
s3.axis_y.min = 15; s3.axis_y.max = 35;
|
||||
s3.place.x_low = 0; s3.place.x_high = 0.5;
|
||||
s3.place.y_low = 0.5; s3.place.y_high = 1.0;
|
||||
|
||||
s2.marker_type = Series.MarkerType.CIRCLE;
|
||||
s3.marker_type = Series.MarkerType.PRICLE_TRIANGLE;
|
||||
|
||||
s1.axis_x.title = new Text("Series 1: Axis X.");
|
||||
s1.axis_y.title = new Text("Series 1: Axis Y.");
|
||||
s2.axis_x.title = new Text("Series 2: Axis X.");
|
||||
s2.axis_y.title = new Text("Series 2: Axis Y.");
|
||||
s3.axis_x.title = new Text("Series 3: Axis X.");
|
||||
s3.axis_y.title = new Text("Series 3: Axis Y.");
|
||||
|
||||
chart.series = { s1, s2, s3 };
|
||||
}
|
||||
|
||||
void plot_chart2 (Chart chart) {
|
||||
var s1 = new Series ();
|
||||
var s2 = new Series ();
|
||||
var s3 = new Series ();
|
||||
|
||||
s1.title = new Text("Series 1"); s1.color = new Color (1, 0, 0);
|
||||
s1.points = {new Series.Point(-12, 0), new Series.Point(2, 1), new Series.Point(20, 3)};
|
||||
s2.axis_y.position = Series.Axis.Position.HIGH;
|
||||
s1.axis_x.format = "%.3Lf";
|
||||
s2.title = new Text("Series 2"); s2.color = new Color (0, 1, 0);
|
||||
s2.points = {new Series.Point(5, -3), new Series.Point(25, -18), new Series.Point(-11, 173)};
|
||||
s3.title = new Text("Series 3"); s3.color = new Color (0, 0, 1);
|
||||
s3.points = {new Series.Point(9, 17), new Series.Point(2, 10), new Series.Point(-15, 31)};
|
||||
s3.axis_y.position = Series.Axis.Position.HIGH;
|
||||
|
||||
s1.axis_x.min = -15; s1.axis_x.max = 30;
|
||||
s1.axis_y.min = 0; s1.axis_y.max = 3;
|
||||
s1.place.x_low = 0.0; s1.place.x_high = 1.0;
|
||||
s1.place.y_low = 0.3; s1.place.y_high = 0.9;
|
||||
|
||||
s2.axis_x.min = -15; s2.axis_x.max = 30;
|
||||
s2.axis_y.min = -20; s2.axis_y.max = 200;
|
||||
s2.place.x_low = 0.0; s2.place.x_high = 1.0;
|
||||
s2.place.y_low = 0.0; s2.place.y_high = 0.5;
|
||||
|
||||
s3.axis_x.min = -15; s3.axis_x.max = 30;
|
||||
s3.axis_y.min = 15; s3.axis_y.max = 35;
|
||||
s3.place.x_low = 0.0; s3.place.x_high = 1.0;
|
||||
s3.place.y_low = 0.5; s3.place.y_high = 1.0;
|
||||
|
||||
s1.marker_type = Series.MarkerType.PRICLE_CIRCLE;
|
||||
s2.marker_type = Series.MarkerType.PRICLE_SQUARE;
|
||||
|
||||
s1.axis_x.title = new Text("All Series: Axis X.");
|
||||
s1.axis_y.title = new Text("Series 1: Axis Y.");
|
||||
s2.axis_x.title = new Text("All Series: Axis X.");
|
||||
s2.axis_y.title = new Text("Series 2: Axis Y.");
|
||||
s3.axis_x.title = new Text("All Series: Axis X.");
|
||||
s3.axis_y.title = new Text("Series 3: Axis Y.");
|
||||
|
||||
chart.series = { s1, s2, s3 };
|
||||
}
|
||||
|
||||
void plot_chart3 (Chart chart) {
|
||||
var s1 = new Series ();
|
||||
var s2 = new Series ();
|
||||
var s3 = new Series ();
|
||||
|
||||
s1.title = new Text("Series 1"); s1.color = new Color (1, 0, 0);
|
||||
s1.points = {new Series.Point(0, 70), new Series.Point(2, 155), new Series.Point(1, -3)};
|
||||
s1.axis_x.position = Series.Axis.Position.HIGH;
|
||||
s1.axis_y.position = Series.Axis.Position.HIGH;
|
||||
s1.axis_x.format = "%.3Lf";
|
||||
s2.title = new Text("Series 2"); s2.color = new Color (0, 1, 0);
|
||||
s2.points = {new Series.Point(5, -3), new Series.Point(25, -18), new Series.Point(-11, 173)};
|
||||
s2.axis_y.position = Series.Axis.Position.HIGH;
|
||||
s3.title = new Text("Series 3"); s3.color = new Color (0, 0, 1);
|
||||
s3.points = {new Series.Point(9, -17), new Series.Point(2, 10), new Series.Point(122, 31)};
|
||||
s3.axis_y.position = Series.Axis.Position.HIGH;
|
||||
|
||||
s1.axis_x.min = 0; s1.axis_x.max = 2;
|
||||
s1.axis_y.min = -20; s1.axis_y.max = 200;
|
||||
s1.place.x_low = 0.25; s1.place.x_high = 0.75;
|
||||
s1.place.y_low = 0.0; s1.place.y_high = 1.0;
|
||||
|
||||
s2.axis_x.min = -15; s2.axis_x.max = 30;
|
||||
s2.axis_y.min = -20; s2.axis_y.max = 200;
|
||||
s2.place.x_low = 0.5; s2.place.x_high = 1;
|
||||
s2.place.y_low = 0.0; s2.place.y_high = 1.0;
|
||||
|
||||
s3.axis_x.min = 0; s3.axis_x.max = 130;
|
||||
s3.axis_y.min = -20; s3.axis_y.max = 200;
|
||||
s3.place.x_low = 0; s3.place.x_high = 0.5;
|
||||
s3.place.y_low = 0.0; s3.place.y_high = 1.0;
|
||||
|
||||
s2.marker_type = Series.MarkerType.PRICLE_CIRCLE;
|
||||
s3.marker_type = Series.MarkerType.TRIANGLE;
|
||||
|
||||
s1.axis_x.title = new Text("Series 1: Axis X.");
|
||||
s1.axis_y.title = new Text("Series 1: Axis Y.");
|
||||
s2.axis_x.title = new Text("Series 2: Axis X.");
|
||||
s2.axis_y.title = new Text("Series 2: Axis Y.");
|
||||
s3.axis_x.title = new Text("Series 3: Axis X.");
|
||||
s3.axis_y.title = new Text("Series 3: Axis Y.");
|
||||
|
||||
chart.series = { s1, s2, s3 };
|
||||
}
|
||||
|
||||
void plot_chart4 (Chart chart) {
|
||||
var s1 = new Series ();
|
||||
var s2 = new Series ();
|
||||
var s3 = new Series ();
|
||||
var s4 = new Series ();
|
||||
|
||||
s1.axis_x.type = Series.Axis.Type.DATE_TIME;
|
||||
s3.axis_x.type = Series.Axis.Type.DATE_TIME;
|
||||
s4.axis_x.type = Series.Axis.Type.DATE_TIME;
|
||||
s4.axis_x.dsec_signs = 5;
|
||||
|
||||
var now = new DateTime.now_local().to_unix();
|
||||
var high = (uint64) (253000000000L);
|
||||
|
||||
s1.title = new Text("Series 1"); s1.color = new Color (1, 0, 0);
|
||||
s1.points = {new Series.Point(now, 70), new Series.Point(now - 100000, 155), new Series.Point(now + 100000, 30)};
|
||||
s1.axis_x.position = Series.Axis.Position.HIGH;
|
||||
s1.axis_y.position = Series.Axis.Position.HIGH;
|
||||
s2.title = new Text("Series 2"); s2.color = new Color (0, 1, 0);
|
||||
s2.points = {new Series.Point(5, -3), new Series.Point(25, -18), new Series.Point(-11, 173)};
|
||||
s2.axis_y.position = Series.Axis.Position.HIGH;
|
||||
s3.title = new Text("Series 3"); s3.color = new Color (0, 0, 1);
|
||||
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)};
|
||||
s3.axis_y.position = Series.Axis.Position.HIGH;
|
||||
s4.title = new Text("Series 4"); s4.color = new Color (0.5, 0.3, 0.9);
|
||||
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)};
|
||||
s4.axis_y.position = Series.Axis.Position.HIGH;
|
||||
|
||||
s1.axis_x.min = now - 100000; s1.axis_x.max = now + 100000;
|
||||
s1.axis_y.min = -20; s1.axis_y.max = 200;
|
||||
s1.place.x_low = 0.25; s1.place.x_high = 0.75;
|
||||
s1.place.y_low = 0.0; s1.place.y_high = 1.0;
|
||||
|
||||
s2.axis_x.min = -15; s2.axis_x.max = 30;
|
||||
s2.axis_y.min = -20; s2.axis_y.max = 200;
|
||||
s2.place.x_low = 0.2; s2.place.x_high = 1;
|
||||
s2.place.y_low = 0.0; s2.place.y_high = 1.0;
|
||||
|
||||
s3.axis_x.min = high - 2; s3.axis_x.max = high + 1;
|
||||
s3.axis_y.min = -20; s3.axis_y.max = 200;
|
||||
s3.place.x_low = 0; s3.place.x_high = 0.8;
|
||||
s3.place.y_low = 0.0; s3.place.y_high = 1.0;
|
||||
|
||||
s4.axis_x.min = high + 0.0049; s4.axis_x.max = high + 0.0054;
|
||||
s4.axis_y.min = -20; s4.axis_y.max = 200;
|
||||
s4.place.x_low = 0.2; s4.place.x_high = 1.0;
|
||||
s4.place.y_low = 0.0; s4.place.y_high = 1.0;
|
||||
|
||||
s2.marker_type = Series.MarkerType.PRICLE_CIRCLE;
|
||||
s3.marker_type = Series.MarkerType.TRIANGLE;
|
||||
s4.marker_type = Series.MarkerType.PRICLE_SQUARE;
|
||||
|
||||
s1.axis_x.title = new Text("Series 1: Axis X.");
|
||||
s1.axis_y.title = new Text("Series 1: Axis Y.");
|
||||
s2.axis_x.title = new Text("Series 2: Axis X.");
|
||||
s2.axis_y.title = new Text("Series 2: Axis Y.");
|
||||
s3.axis_x.title = new Text("Series 3: Axis X.");
|
||||
s3.axis_y.title = new Text("Series 3: Axis Y.");
|
||||
s4.axis_x.title = new Text("Series 4: Axis X.");
|
||||
s4.axis_y.title = new Text("Series 4: Axis Y.");
|
||||
|
||||
chart.series = { s1, s2, s3, s4 };
|
||||
}
|
||||
|
||||
int main (string[] args) {
|
||||
init (ref args);
|
||||
|
||||
var window = new Window ();
|
||||
window.title = "Gtk.Chart Test.";
|
||||
window.border_width = 10;
|
||||
window.title = "Chart Test.";
|
||||
window.border_width = 5;
|
||||
window.window_position = WindowPosition.CENTER;
|
||||
window.set_default_size (640, 480);
|
||||
window.destroy.connect (main_quit);
|
||||
|
||||
var da = new DrawingArea();
|
||||
var chart = new Gtk.Chart();
|
||||
var label = new Label ("Gtk.Chart Test!");
|
||||
var button = new Button.with_label("Click me");
|
||||
button.clicked.connect (() => {
|
||||
da.draw.connect((context) => {
|
||||
chart.draw(context);
|
||||
return true;
|
||||
});
|
||||
var chart1 = new Chart();
|
||||
var chart2 = new Chart();
|
||||
var chart3 = new Chart();
|
||||
var chart4 = new Chart();
|
||||
var label = new Label ("Chart Test!");
|
||||
var button1 = new Button.with_label("Separate axes");
|
||||
var button2 = new Button.with_label("Common X axes");
|
||||
var button3 = new Button.with_label("Common Y axes");
|
||||
var button4 = new Button.with_label("Dates/Times");
|
||||
var button5 = new Button.with_label("rm Axis Titles");
|
||||
var button6 = new Button.with_label("rm Dates");
|
||||
var button7 = new Button.with_label("rm Times");
|
||||
|
||||
plot_chart1 (chart1);
|
||||
plot_chart2 (chart2);
|
||||
plot_chart3 (chart3);
|
||||
plot_chart4 (chart4);
|
||||
|
||||
var da = new DrawingArea();
|
||||
da.set_events ( Gdk.EventMask.BUTTON_PRESS_MASK
|
||||
|Gdk.EventMask.BUTTON_RELEASE_MASK
|
||||
|Gdk.EventMask.POINTER_MOTION_MASK
|
||||
);
|
||||
|
||||
var chart = chart1;
|
||||
|
||||
var radio_button1 = new RadioButton.with_label (null, "Top Legend");
|
||||
var radio_button2 = new RadioButton.with_label (radio_button1.get_group(), "Right Legend");
|
||||
var radio_button3 = new RadioButton.with_label_from_widget (radio_button1, "Left Legend");
|
||||
var radio_button4 = new RadioButton.with_label_from_widget (radio_button1, "Bottom Legend");
|
||||
|
||||
button1.clicked.connect (() => {
|
||||
chart = chart1; da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||
switch (chart.legend.position) {
|
||||
case Chart.Legend.Position.TOP: radio_button1.set_active(true); break;
|
||||
case Chart.Legend.Position.RIGHT: radio_button2.set_active(true); break;
|
||||
case Chart.Legend.Position.LEFT: radio_button3.set_active(true); break;
|
||||
case Chart.Legend.Position.BOTTOM: radio_button4.set_active(true); break;
|
||||
default: break;
|
||||
}
|
||||
});
|
||||
button2.clicked.connect (() => {
|
||||
chart = chart2; da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||
switch (chart.legend.position) {
|
||||
case Chart.Legend.Position.TOP: radio_button1.set_active(true); break;
|
||||
case Chart.Legend.Position.RIGHT: radio_button2.set_active(true); break;
|
||||
case Chart.Legend.Position.LEFT: radio_button3.set_active(true); break;
|
||||
case Chart.Legend.Position.BOTTOM: radio_button4.set_active(true); break;
|
||||
default: break;
|
||||
}
|
||||
});
|
||||
button3.clicked.connect (() => {
|
||||
chart = chart3; da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||
switch (chart.legend.position) {
|
||||
case Chart.Legend.Position.TOP: radio_button1.set_active(true); break;
|
||||
case Chart.Legend.Position.RIGHT: radio_button2.set_active(true); break;
|
||||
case Chart.Legend.Position.LEFT: radio_button3.set_active(true); break;
|
||||
case Chart.Legend.Position.BOTTOM: radio_button4.set_active(true); break;
|
||||
default: break;
|
||||
}
|
||||
});
|
||||
button4.clicked.connect (() => {
|
||||
chart = chart4; da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||
switch (chart.legend.position) {
|
||||
case Chart.Legend.Position.TOP: radio_button1.set_active(true); break;
|
||||
case Chart.Legend.Position.RIGHT: radio_button2.set_active(true); break;
|
||||
case Chart.Legend.Position.LEFT: radio_button4.set_active(true); break;
|
||||
case Chart.Legend.Position.BOTTOM: radio_button4.set_active(true); break;
|
||||
default: break;
|
||||
}
|
||||
});
|
||||
button5.clicked.connect (() => {
|
||||
for (var i = 0; i < chart.series.length; ++i) {
|
||||
var s = chart.series[i];
|
||||
s.axis_x.title.text = "";
|
||||
s.axis_y.title.text = "";
|
||||
}
|
||||
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||
});
|
||||
button6.clicked.connect (() => {
|
||||
for (var i = 0; i < chart.series.length; ++i) {
|
||||
var s = chart.series[i];
|
||||
s.axis_x.date_format = "";
|
||||
}
|
||||
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||
});
|
||||
|
||||
button7.clicked.connect (() => {
|
||||
for (var i = 0; i < chart.series.length; ++i) {
|
||||
var s = chart.series[i];
|
||||
s.axis_x.time_format = "";
|
||||
}
|
||||
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||
});
|
||||
|
||||
|
||||
radio_button1.toggled.connect ((button) => {
|
||||
if (button.get_active()) {
|
||||
chart.legend.position = Chart.Legend.Position.TOP;
|
||||
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||
}
|
||||
});
|
||||
radio_button2.toggled.connect ((button) => {
|
||||
if (button.get_active()) {
|
||||
chart.legend.position = Chart.Legend.Position.RIGHT;
|
||||
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||
}
|
||||
});
|
||||
radio_button3.toggled.connect ((button) => {
|
||||
if (button.get_active()) {
|
||||
chart.legend.position = Chart.Legend.Position.LEFT;
|
||||
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||
}
|
||||
});
|
||||
radio_button4.toggled.connect ((button) => {
|
||||
if (button.get_active()) {
|
||||
chart.legend.position = Chart.Legend.Position.BOTTOM;
|
||||
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||
}
|
||||
});
|
||||
|
||||
da.draw.connect((context) => {
|
||||
// user's pre draw operations here...
|
||||
chart.context = context;
|
||||
var ret = chart.draw();
|
||||
// user's post draw operations here...
|
||||
return ret;
|
||||
});
|
||||
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||
|
||||
da.button_release_event.connect((event) => {
|
||||
// user's pre button_release_event operations here...
|
||||
var ret = chart.button_release_event(event);
|
||||
// user's post button_release_event operations here...
|
||||
return ret;
|
||||
});
|
||||
da.button_press_event.connect((event) => {
|
||||
// user's pre button_press_event operations here...
|
||||
var ret = chart.button_press_event(event);
|
||||
// user's post button_press_event operations here...
|
||||
return ret;
|
||||
});
|
||||
da.motion_notify_event.connect((event) => {
|
||||
// user's pre motion_notify_event operations here...
|
||||
var ret = chart.motion_notify_event(event);
|
||||
// user's post motion_notify_event operations here...
|
||||
return ret;
|
||||
});
|
||||
|
||||
var vbox2 = new Box(Orientation.VERTICAL, 0);
|
||||
vbox2.pack_end(button, false, false, 0);
|
||||
vbox2.pack_start(button1, false, false, 0);
|
||||
vbox2.pack_start(button2, false, false, 0);
|
||||
vbox2.pack_start(button3, false, false, 0);
|
||||
vbox2.pack_start(button4, false, false, 0);
|
||||
vbox2.pack_start(button5, false, false, 0);
|
||||
vbox2.pack_start(button6, false, false, 0);
|
||||
vbox2.pack_start(button7, false, false, 0);
|
||||
vbox2.pack_start(radio_button1, false, false, 0);
|
||||
vbox2.pack_start(radio_button2, false, false, 0);
|
||||
vbox2.pack_start(radio_button3, false, false, 0);
|
||||
vbox2.pack_start(radio_button4, false, false, 0);
|
||||
|
||||
var hbox = new Box(Orientation.HORIZONTAL, 0);
|
||||
hbox.pack_start(da, true, true, 0);
|
||||
|
@ -38,6 +379,7 @@ int main (string[] args) {
|
|||
|
||||
window.show_all();
|
||||
|
||||
Double128 d = 5.5;
|
||||
Gtk.main();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue