OK In progress...

This commit is contained in:
Kolan Sh 2018-01-22 16:00:39 +03:00
parent 0d142ac4db
commit e0f9197cea
3 changed files with 12 additions and 8 deletions

View File

@ -182,7 +182,10 @@ namespace CairoChart {
return axis;
}
public virtual void format_date_time (Float128 x, out string date, out string time) {
/**
* Prints date/time to strings with a current formats.
*/
public virtual void print_dt (Float128 x, out string date, out string time) {
date = time = "";
var dt = new DateTime.from_unix_utc((int64)x);
date = dt.format(date_format);
@ -191,6 +194,7 @@ namespace CairoChart {
time = dt.format(time_format) + dsec_str;
}
// TODO: move to Series.vala
public virtual void calc_rec_sizes (out double max_rec_width, out double max_rec_height, bool horizontal = true) {
max_rec_width = max_rec_height = 0;
for (var i = 0; i < nrecords; ++i) {
@ -203,7 +207,7 @@ namespace CairoChart {
break;
case Axis.DType.DATE_TIME:
string date, time;
format_date_time(x, out date, out time);
print_dt(x, out date, out time);
var h = 0.0;
if (date_format != "") {

View File

@ -208,7 +208,7 @@ namespace CairoChart {
cross_what_to_show(s, out show_x, out show_time, out show_date, out show_y);
size = Point128 ();
string date, time;
s.axis_x.format_date_time(p.x, out date, out time);
s.axis_x.print_dt(p.x, out date, out time);
var date_t = new Text(chart, date, s.axis_x.font, s.axis_x.color);
var time_t = new Text(chart, time, s.axis_x.font, s.axis_x.color);
var x_t = new Text(chart, s.axis_x.format.printf((LongDouble)p.x), s.axis_x.font, s.axis_x.color);
@ -285,7 +285,7 @@ namespace CairoChart {
string text = "", time_text = "";
switch (s.axis_x.dtype) {
case Axis.DType.NUMBERS: text = s.axis_x.format.printf((LongDouble)x); break;
case Axis.DType.DATE_TIME: s.axis_x.format_date_time(x, out text, out time_text); break;
case Axis.DType.DATE_TIME: s.axis_x.print_dt(x, out text, out time_text); break;
}
var text_t = new Text(chart, text, s.axis_x.font, s.axis_x.color);
var time_text_t = new Text(chart, time_text, s.axis_x.font, s.axis_x.color);
@ -383,7 +383,7 @@ namespace CairoChart {
if (show_time) {
chart.color = s.axis_x.color;
string date = "", time = "";
s.axis_x.format_date_time(point.x, out date, out time);
s.axis_x.print_dt(point.x, out date, out time);
var text_t = new Text(chart, time, s.axis_x.font);
var y = svp.y + text_t.height / 2;
if (show_date) y -= text_t.height / 2 + s.axis_x.font.vspacing / 2;
@ -395,7 +395,7 @@ namespace CairoChart {
if (show_date) {
chart.color = s.axis_x.color;
string date = "", time = "";
s.axis_x.format_date_time(point.x, out date, out time);
s.axis_x.print_dt(point.x, out date, out time);
var text_t = new Text(chart, date, s.axis_x.font);
var y = svp.y + text_t.height / 2;
if (show_time) y += text_t.height / 2 + s.axis_x.font.vspacing / 2;
@ -461,7 +461,7 @@ namespace CairoChart {
case Axis.DType.DATE_TIME:
var date = "", time = "";
int64 days = (int64)(delta / 24 / 3600);
s.axis_x.format_date_time(delta, out date, out time);
s.axis_x.print_dt(delta, out date, out time);
str = days.to_string() + " + " + time;
break;
}

View File

@ -257,7 +257,7 @@ namespace CairoChart {
string text = "", time_text = "";
switch (axis_x.dtype) {
case Axis.DType.NUMBERS: text = axis_x.format.printf((LongDouble)x); break;
case Axis.DType.DATE_TIME: axis_x.format_date_time(x, out text, out time_text); break;
case Axis.DType.DATE_TIME: axis_x.print_dt(x, out text, out time_text); break;
}
var scr_x = get_scr_x (x);
var text_t = new Text(chart, text, axis_x.font, axis_x.color);