OK In progress...

This commit is contained in:
Kolan Sh 2018-01-22 16:54:54 +03:00
parent 491c303d4f
commit 4626587d45
2 changed files with 24 additions and 14 deletions

View File

@ -48,7 +48,7 @@ namespace CairoChart {
/** /**
* Legend. * Legend.
*/ */
public Legend legend = new Legend(); public Legend legend;
/** /**
* ``Chart`` Series array. * ``Chart`` Series array.
@ -100,7 +100,7 @@ namespace CairoChart {
public Chart () { public Chart () {
cursors = new Cursors (this); cursors = new Cursors (this);
title = new Text(this, "Cairo Chart"); title = new Text(this, "Cairo Chart");
legend = new Legend(this);
} }
/** /**
@ -147,7 +147,7 @@ namespace CairoChart {
draw_title (); draw_title ();
fix_evarea (); fix_evarea ();
legend.draw (this); legend.draw ();
fix_evarea (); fix_evarea ();
rot_axes_titles (); rot_axes_titles ();

View File

@ -5,6 +5,8 @@ namespace CairoChart {
*/ */
public class Legend { public class Legend {
Chart chart;
/** /**
* ``Legend`` position. * ``Legend`` position.
*/ */
@ -53,8 +55,20 @@ namespace CairoChart {
public double text_vspace = 2.0; public double text_vspace = 2.0;
public bool show = true; public bool show = true;
/**
* Constructs a new ``Legend``.
* @param chart ``Chart`` instance.
*/
public Legend (Chart chart) {
this.chart = chart;
border_style.color = Color (0, 0, 0, 0.3);
}
/**
* Gets a copy of the ``Legend``.
*/
public virtual Legend copy () { public virtual Legend copy () {
var legend = new Legend (); var legend = new Legend (chart);
legend.position = this.position; legend.position = this.position;
legend.bg_color = this.bg_color; legend.bg_color = this.bg_color;
legend.spacing = this.spacing; legend.spacing = this.spacing;
@ -68,17 +82,13 @@ namespace CairoChart {
return legend; return legend;
} }
public Legend () { public virtual void draw () {
border_style.color = Color (0, 0, 0, 0.3);
}
public virtual void draw (Chart chart) {
if (!show) return; if (!show) return;
process (chart, ProcessType.CALC); process (ProcessType.CALC);
process (chart, ProcessType.DRAW); process (ProcessType.DRAW);
} }
public virtual void draw_rect (Chart chart, out double x0, out double y0) { public virtual void draw_rect (out double x0, out double y0) {
x0 = y0 = 0.0; x0 = y0 = 0.0;
if (chart.ctx != null) { if (chart.ctx != null) {
switch (position) { switch (position) {
@ -123,7 +133,7 @@ namespace CairoChart {
} }
double [] max_font_heights; double [] max_font_heights;
public virtual void process (Chart chart, ProcessType process_type) { public virtual void process (ProcessType process_type) {
var legend_x0 = 0.0, legend_y0 = 0.0; var legend_x0 = 0.0, legend_y0 = 0.0;
var heights_idx = 0; var heights_idx = 0;
var leg_width_sum = 0.0; var leg_width_sum = 0.0;
@ -139,7 +149,7 @@ namespace CairoChart {
heights_idx = 0; heights_idx = 0;
break; break;
case ProcessType.DRAW: case ProcessType.DRAW:
draw_rect(chart, out legend_x0, out legend_y0); draw_rect(out legend_x0, out legend_y0);
break; break;
} }