gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2012年06月05日 19:19:40 +0200
committerFrancesco Abbate <francesco.bbt@gmail.com>2012年06月05日 19:19:40 +0200
commit2d17ffeb35f0cf8fdc38ca8f548983132d64cc0f (patch)
treef60171c76384481468d6fa51b3001470df38e30f
parentabdd658306f69857216e6f3a41fcd9e1450e4352 (diff)
downloadgsl-shell-2d17ffeb35f0cf8fdc38ca8f548983132d64cc0f.tar.gz
Add get_legend method to plot class
Diffstat
-rw-r--r--agg-plot/lua-plot.cpp 42
-rw-r--r--agg-plot/plot.h 6
-rw-r--r--doc/user-manual/graphics.rst 5
3 files changed, 40 insertions, 13 deletions
diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp
index 0bc11e22..336d1bbd 100644
--- a/agg-plot/lua-plot.cpp
+++ b/agg-plot/lua-plot.cpp
@@ -69,6 +69,7 @@ static int plot_ylab_angle_set (lua_State *L);
static int plot_ylab_angle_get (lua_State *L);
static int plot_set_categories (lua_State *L);
static int plot_set_legend (lua_State *L);
+static int plot_get_legend (lua_State *L);
static int plot_sync_mode_get (lua_State *L);
static int plot_sync_mode_set (lua_State *L);
@@ -109,6 +110,7 @@ static const struct luaL_Reg plot_methods[] = {
{"save_svg", plot_save_svg },
{"set_categories", plot_set_categories},
{"set_legend", plot_set_legend},
+ {"get_legend", plot_get_legend},
{NULL, NULL}
};
@@ -229,6 +231,7 @@ objref_mref_add (lua_State *L, int table_index, int index, int value_index)
lua_pop (L, 1);
}
+
void
plot_lua_add_ref (lua_State* L, int plot_index, int ref_index)
{
@@ -671,15 +674,12 @@ plot_set_categories (lua_State *L)
return 0;
}
-int
-plot_set_legend(lua_State *L)
+static sg_plot::placement_e
+char_to_placement_enum(lua_State* L, const char *s)
{
- sg_plot* p = object_check<sg_plot>(L, 1, GS_PLOT);
- sg_plot* mp = object_check<sg_plot>(L, 2, GS_PLOT);
- const char* placement = luaL_optstring(L, 3, "r");
sg_plot::placement_e pos;
- char letter = placement[0];
+ char letter = s[0];
if (letter == 'r')
pos = sg_plot::right;
else if (letter == 'l')
@@ -689,11 +689,23 @@ plot_set_legend(lua_State *L)
else if (letter == 't')
pos = sg_plot::top;
else
- return luaL_error (L, "invalid legend placement specification.");
+ luaL_error (L, "invalid legend placement specification.");
+
+ return pos;
+}
+
+int
+plot_set_legend(lua_State *L)
+{
+ sg_plot* p = object_check<sg_plot>(L, 1, GS_PLOT);
+ sg_plot* mp = object_check<sg_plot>(L, 2, GS_PLOT);
+ const char* placement = luaL_optstring(L, 3, "r");
+ sg_plot::placement_e pos = char_to_placement_enum(L, placement);
int ref_index = (1 << 16) + (int)pos;
- lua_getfenv (L, 1);
- objref_mref_add (L, -1, ref_index, 2);
+ lua_getfenv(L, 1);
+ lua_pushvalue(L, 2);
+ lua_rawseti(L, -2, ref_index);
AGG_LOCK();
p->add_legend(mp, pos);
@@ -704,6 +716,18 @@ plot_set_legend(lua_State *L)
return 0;
}
+int
+plot_get_legend(lua_State *L)
+{
+ object_check<sg_plot>(L, 1, GS_PLOT);
+ const char* placement = luaL_optstring(L, 2, "r");
+ sg_plot::placement_e pos = char_to_placement_enum(L, placement);
+ int ref_index = (1 << 16) + (int)pos;
+ lua_getfenv(L, 1);
+ lua_rawgeti(L, -1, ref_index);
+ return 1;
+}
+
void
plot_register (lua_State *L)
{
diff --git a/agg-plot/plot.h b/agg-plot/plot.h
index f2c822a7..0a7a5e9e 100644
--- a/agg-plot/plot.h
+++ b/agg-plot/plot.h
@@ -156,10 +156,8 @@ public:
str& x_axis_title() { return m_x_axis.title; }
str& y_axis_title() { return m_y_axis.title; }
- void add_legend(plot* p, placement_e where)
- {
- m_legend[where] = p;
- }
+ void add_legend(plot* p, placement_e where) { m_legend[where] = p; }
+ plot* get_legend(placement_e where) { return m_legend[where]; }
axis& get_axis(axis_e axis_dir)
{
diff --git a/doc/user-manual/graphics.rst b/doc/user-manual/graphics.rst
index 832d05d7..6b4c9e22 100644
--- a/doc/user-manual/graphics.rst
+++ b/doc/user-manual/graphics.rst
@@ -546,6 +546,11 @@ You can add elements to a plot in any moments even when it is already shown. GSL
The plot legend is drawn on the screen using an area that is equal, in pixal, to the logical size of the plot legend itself.
+ .. method:: get_legend([placement])
+
+ Return the plot legend stored in the given ``placement``.
+ The placement parameter is interpreted as in the :meth:`~Plot.set_legend` method.
+
.. method:: set_categories(axis, categories)
Configure the given ``axis`` (a letter, 'x' or 'y') to use a custom set of labels specified by ``categories``.
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月14日 12:51:51 +0000

AltStyle によって変換されたページ (->オリジナル) /