2018-01-08 23:33:13 +03:00
|
|
|
namespace CairoChart {
|
2018-01-22 14:31:34 +03:00
|
|
|
|
|
|
|
/**
|
2018-01-22 14:44:31 +03:00
|
|
|
* ``Chart`` axis.
|
2018-01-22 14:31:34 +03:00
|
|
|
*/
|
2017-08-28 14:47:31 +03:00
|
|
|
public class Axis {
|
2018-01-22 14:44:31 +03:00
|
|
|
|
2018-01-22 18:21:29 +03:00
|
|
|
protected Chart chart;
|
|
|
|
protected string _format = "%.2Lf";
|
|
|
|
protected string _date_format = "%Y.%m.%d";
|
|
|
|
protected string _time_format = "%H:%M:%S";
|
|
|
|
protected int _dsec_signs = 2; // 2 signs = centiseconds
|
2018-01-22 14:44:31 +03:00
|
|
|
|
2018-01-22 16:14:49 +03:00
|
|
|
/**
|
|
|
|
* ``Axis`` title.
|
|
|
|
*/
|
|
|
|
public Text title;
|
|
|
|
|
2018-01-22 14:44:31 +03:00
|
|
|
/**
|
|
|
|
* ``Axis`` range/limits.
|
|
|
|
*/
|
|
|
|
public Range range = new Range();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data type.
|
|
|
|
*/
|
2018-01-22 14:31:34 +03:00
|
|
|
public enum DType {
|
2018-01-22 14:44:31 +03:00
|
|
|
/**
|
|
|
|
* Float128 numbers.
|
|
|
|
*/
|
2017-08-28 14:47:31 +03:00
|
|
|
NUMBERS = 0,
|
2018-01-22 14:44:31 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Date/Time.
|
|
|
|
*/
|
2017-08-28 14:47:31 +03:00
|
|
|
DATE_TIME
|
|
|
|
}
|
2018-01-22 14:44:31 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Data type.
|
|
|
|
*/
|
|
|
|
public DType dtype;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ``Axis`` scale type.
|
|
|
|
*/
|
2018-01-22 14:46:00 +03:00
|
|
|
public enum Scale {
|
2018-01-22 14:44:31 +03:00
|
|
|
/**
|
|
|
|
* Linear scale.
|
|
|
|
*/
|
|
|
|
LINEAR = 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logarithmic scale.
|
|
|
|
*/
|
|
|
|
// LOGARITHMIC,
|
2017-08-28 14:47:31 +03:00
|
|
|
}
|
2018-01-22 14:44:31 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scale type.
|
|
|
|
*/
|
2018-01-22 14:46:00 +03:00
|
|
|
public Scale scale;
|
2018-01-22 14:44:31 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ``Axis`` position.
|
|
|
|
*/
|
2017-08-28 14:47:31 +03:00
|
|
|
public enum Position {
|
2018-01-22 14:54:08 +03:00
|
|
|
/**
|
|
|
|
* Bottom/Left ``Axis``.
|
|
|
|
*/
|
2017-08-28 14:47:31 +03:00
|
|
|
LOW = 0,
|
2018-01-22 14:54:08 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Top/Right ``Axis``.
|
|
|
|
*/
|
2017-08-28 14:47:31 +03:00
|
|
|
HIGH = 1,
|
2018-01-22 14:54:08 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 2 ``Axes``.
|
|
|
|
*/
|
2017-08-28 14:47:31 +03:00
|
|
|
BOTH = 2
|
|
|
|
}
|
2018-01-22 14:54:08 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Position.
|
|
|
|
*/
|
2017-08-28 14:47:31 +03:00
|
|
|
public Position position = Position.LOW;
|
|
|
|
|
2018-01-22 14:54:08 +03:00
|
|
|
/**
|
|
|
|
* Float128 numbers print string format.
|
|
|
|
*/
|
|
|
|
public virtual string format {
|
2017-08-28 14:47:31 +03:00
|
|
|
get { return _format; }
|
|
|
|
set {
|
|
|
|
// TODO: check format
|
|
|
|
_format = value;
|
|
|
|
}
|
|
|
|
default = "%.2Lf";
|
|
|
|
}
|
2018-01-22 14:54:08 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Date print string format.
|
|
|
|
*/
|
|
|
|
public virtual string date_format {
|
2017-08-28 14:47:31 +03:00
|
|
|
get { return _date_format; }
|
|
|
|
set {
|
|
|
|
// TODO: check format
|
|
|
|
_date_format = value;
|
|
|
|
}
|
|
|
|
default = "%Y.%m.%d";
|
|
|
|
}
|
2018-01-22 14:54:08 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Time print string format.
|
|
|
|
*/
|
|
|
|
public virtual string time_format {
|
2017-08-28 14:47:31 +03:00
|
|
|
get { return _time_format; }
|
|
|
|
set {
|
|
|
|
// TODO: check format
|
|
|
|
_time_format = value;
|
|
|
|
}
|
|
|
|
default = "%H:%M:%S";
|
|
|
|
}
|
2018-01-22 14:54:08 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of second's signs after point.
|
|
|
|
*
|
|
|
|
* 2 signs means centiseconds, 3 signs means milliseconds, etc...
|
|
|
|
*/
|
|
|
|
public virtual int dsec_signs {
|
2017-08-28 14:47:31 +03:00
|
|
|
get { return _dsec_signs; }
|
|
|
|
set {
|
|
|
|
// TODO: check format
|
|
|
|
_dsec_signs = value;
|
|
|
|
}
|
|
|
|
default = 2;
|
|
|
|
}
|
2018-01-22 14:58:41 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ``Axis`` Font style.
|
|
|
|
*/
|
2018-01-22 14:54:58 +03:00
|
|
|
public Font font = new Font ();
|
2018-01-22 14:58:41 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ``Axis`` color.
|
|
|
|
*/
|
2017-08-28 14:47:31 +03:00
|
|
|
public Color color = Color ();
|
2018-01-22 14:58:41 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ``Axis`` line style.
|
|
|
|
*/
|
2018-01-20 13:11:17 +03:00
|
|
|
public LineStyle line_style = LineStyle ();
|
2018-01-22 14:58:41 +03:00
|
|
|
|
2018-01-22 15:10:47 +03:00
|
|
|
/**
|
|
|
|
* Number of equally placed points to evaluate records sizes.
|
|
|
|
*/
|
|
|
|
public int nrecords = 128;
|
|
|
|
|
2018-01-22 15:07:19 +03:00
|
|
|
/**
|
|
|
|
* Constructs a new ``Axis``.
|
2018-01-22 15:10:47 +03:00
|
|
|
* @param chart {@link Chart} instance.
|
2018-01-22 15:07:19 +03:00
|
|
|
*/
|
2018-01-22 14:44:31 +03:00
|
|
|
public Axis (Chart chart) {
|
|
|
|
this.chart = chart;
|
|
|
|
title = new Text (chart, "");
|
|
|
|
}
|
|
|
|
|
2018-01-22 15:10:47 +03:00
|
|
|
/**
|
|
|
|
* Gets a copy of the ``Axis``.
|
|
|
|
*/
|
2018-01-15 12:05:21 +03:00
|
|
|
public virtual Axis copy () {
|
2018-01-21 17:27:46 +03:00
|
|
|
var axis = new Axis (chart);
|
2017-08-28 18:16:48 +03:00
|
|
|
axis._date_format = this._date_format;
|
|
|
|
axis._dsec_signs = this._dsec_signs;
|
|
|
|
axis._format = this._format;
|
|
|
|
axis._time_format = this._time_format;
|
|
|
|
axis.color = this.color;
|
2018-01-22 15:49:49 +03:00
|
|
|
axis.font = this.font.copy();
|
2017-08-28 18:16:48 +03:00
|
|
|
axis.line_style = this.line_style;
|
2018-01-22 15:49:49 +03:00
|
|
|
axis.range = this.range.copy();
|
2017-08-28 18:16:48 +03:00
|
|
|
axis.position = this.position;
|
2018-01-22 14:46:00 +03:00
|
|
|
axis.scale = this.scale;
|
2017-08-28 18:16:48 +03:00
|
|
|
axis.title = this.title.copy();
|
2018-01-22 14:31:34 +03:00
|
|
|
axis.dtype = this.dtype;
|
2018-01-10 14:15:42 +03:00
|
|
|
axis.nrecords = this.nrecords;
|
2017-08-28 18:16:48 +03:00
|
|
|
return axis;
|
|
|
|
}
|
|
|
|
|
2018-01-22 16:00:39 +03:00
|
|
|
/**
|
|
|
|
* Prints date/time to strings with a current formats.
|
2018-01-22 18:37:27 +03:00
|
|
|
* @param date returns formatted date string.
|
|
|
|
* @param time returns formatted time string.
|
2018-01-22 16:00:39 +03:00
|
|
|
*/
|
|
|
|
public virtual void print_dt (Float128 x, out string date, out string time) {
|
2018-01-10 14:15:42 +03:00
|
|
|
date = time = "";
|
|
|
|
var dt = new DateTime.from_unix_utc((int64)x);
|
|
|
|
date = dt.format(date_format);
|
|
|
|
var dsec_str =
|
|
|
|
("%."+(dsec_signs.to_string())+"Lf").printf((LongDouble)(x - (int64)x)).offset(1);
|
|
|
|
time = dt.format(time_format) + dsec_str;
|
|
|
|
}
|
|
|
|
|
2018-01-22 15:52:50 +03:00
|
|
|
/**
|
|
|
|
* Zooms out ``Axis``.
|
|
|
|
*/
|
2018-01-22 14:44:31 +03:00
|
|
|
public virtual void zoom_out () {
|
|
|
|
range.zoom_out();
|
2018-01-19 14:09:50 +03:00
|
|
|
}
|
2017-08-28 14:47:31 +03:00
|
|
|
}
|
|
|
|
}
|