Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
e-plot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tag2y19
e-plot
Commits
5e695300
Commit
5e695300
authored
1 year ago
by
Tom Greig
Browse files
Options
Downloads
Patches
Plain Diff
Add legend and v keybind to toggle it
parent
37a3df65
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.txt
+5
-2
5 additions, 2 deletions
README.txt
src/main.c
+119
-0
119 additions, 0 deletions
src/main.c
with
124 additions
and
2 deletions
README.txt
+
5
−
2
View file @
5e695300
...
@@ -32,5 +32,8 @@ $ e-plot --help
...
@@ -32,5 +32,8 @@ $ e-plot --help
Keybinding:
Keybinding:
h,l - Move left and right
←, h - Move left
H,L - Zoom out and in
→, l - Move right
Shift+←, H - Zoom out
Shift+→, L - Zoom in
v - Toggle legend
This diff is collapsed.
Click to expand it.
src/main.c
+
119
−
0
View file @
5e695300
...
@@ -42,6 +42,7 @@ struct context {
...
@@ -42,6 +42,7 @@ struct context {
struct
{
struct
{
char
*
header
;
char
*
header
;
PangoLayout
*
legend
;
enum
{
XAXIS
,
LEFT_AXIS
,
RIGHT_AXIS
,
IGNORE
,
}
type
;
enum
{
XAXIS
,
LEFT_AXIS
,
RIGHT_AXIS
,
IGNORE
,
}
type
;
}
*
columns
;
}
*
columns
;
size_t
n_columns
;
size_t
n_columns
;
...
@@ -93,6 +94,8 @@ struct context {
...
@@ -93,6 +94,8 @@ struct context {
int
n
;
int
n
;
}
xtick_layouts
,
yltick_layouts
,
yrtick_layouts
;
}
xtick_layouts
,
yltick_layouts
,
yrtick_layouts
;
bool
show_legend
;
};
};
struct
fd_source
{
struct
fd_source
{
...
@@ -133,6 +136,7 @@ int main( int argc, char** argv ) {
...
@@ -133,6 +136,7 @@ int main( int argc, char** argv ) {
context
->
xfit
=
true
;
context
->
xfit
=
true
;
context
->
xfollow
=
true
;
context
->
xfollow
=
true
;
context
->
font_size
=
12
;
context
->
font_size
=
12
;
context
->
show_legend
=
true
;
static
const
char
*
colours
[]
=
{
static
const
char
*
colours
[]
=
{
"#005C84"
,
"#FCBC00"
,
"#0C838C"
,
"#E63037"
,
"#005C84"
,
"#FCBC00"
,
"#0C838C"
,
"#E63037"
,
...
@@ -479,6 +483,18 @@ static int key_callback( GtkEventControllerKey* event_controller,
...
@@ -479,6 +483,18 @@ static int key_callback( GtkEventControllerKey* event_controller,
}
}
case
'v'
:
{
if
(
0
==
mods
)
{
context
->
show_legend
=
!
context
->
show_legend
;
gtk_widget_queue_draw
(
context
->
plot
);
return
true
;
}
return
false
;
}
default:
{
default:
{
return
false
;
return
false
;
...
@@ -1424,6 +1440,109 @@ static void plot_draw( GtkDrawingArea* plot,
...
@@ -1424,6 +1440,109 @@ static void plot_draw( GtkDrawingArea* plot,
cairo_restore
(
cr
);
cairo_restore
(
cr
);
/* Legend */
if
(
context
->
show_legend
)
{
double
w
=
0
;
double
h
=
0
.
5
*
context
->
font_size
;
for
(
size_t
i
=
0
;
i
<
context
->
n_columns
;
i
++
)
{
if
(
XAXIS
==
context
->
columns
[
i
].
type
||
IGNORE
==
context
->
columns
[
i
].
type
)
{
continue
;
}
if
(
NULL
==
context
->
columns
[
i
].
legend
)
{
context
->
columns
[
i
].
legend
=
pango_cairo_create_layout
(
cr
);
pango_layout_set_font_description
(
context
->
columns
[
i
].
legend
,
context
->
tick_font_description
);
pango_layout_set_text
(
context
->
columns
[
i
].
legend
,
context
->
columns
[
i
].
header
,
-
1
);
}
int
lw
,
lh
;
pango_layout_get_pixel_size
(
context
->
columns
[
i
].
legend
,
&
lw
,
&
lh
);
if
(
w
<
lw
+
5
*
context
->
font_size
)
{
w
=
lw
+
5
*
context
->
font_size
;
}
h
+=
lh
+
0
.
5
*
context
->
font_size
;
}
cairo_save
(
cr
);
cairo_set_line_width
(
cr
,
1
);
cairo_move_to
(
cr
,
m
[
1
],
m
[
2
]
);
cairo_line_to
(
cr
,
m
[
1
]
+
w
,
m
[
2
]
);
cairo_line_to
(
cr
,
m
[
1
]
+
w
,
m
[
2
]
+
h
);
cairo_line_to
(
cr
,
m
[
1
],
m
[
2
]
+
h
);
cairo_line_to
(
cr
,
m
[
1
],
m
[
2
]
);
cairo_set_source_rgb
(
cr
,
1
,
1
,
1
);
cairo_fill_preserve
(
cr
);
cairo_set_source_rgb
(
cr
,
0
,
0
,
0
);
cairo_stroke
(
cr
);
cairo_restore
(
cr
);
h
=
0
.
5
*
context
->
font_size
+
m
[
2
];
size_t
c
=
0
;
for
(
size_t
i
=
0
;
i
<
context
->
n_columns
;
i
++
)
{
if
(
XAXIS
==
context
->
columns
[
i
].
type
||
IGNORE
==
context
->
columns
[
i
].
type
)
{
continue
;
}
int
lw
,
lh
;
pango_layout_get_pixel_size
(
context
->
columns
[
i
].
legend
,
&
lw
,
&
lh
);
if
(
context
->
columns
[
i
].
type
==
LEFT_AXIS
)
{
cairo_move_to
(
cr
,
m
[
1
]
+
context
->
font_size
*
4
,
h
);
}
else
{
cairo_move_to
(
cr
,
m
[
1
]
+
context
->
font_size
*
1
,
h
);
}
cairo_save
(
cr
);
cairo_set_source_rgb
(
cr
,
0
,
0
,
0
);
pango_cairo_show_layout
(
cr
,
context
->
columns
[
i
].
legend
);
cairo_restore
(
cr
);
if
(
context
->
columns
[
i
].
type
==
LEFT_AXIS
)
{
cairo_move_to
(
cr
,
m
[
1
]
+
context
->
font_size
*
1
,
h
+
lh
/
2
);
cairo_line_to
(
cr
,
m
[
1
]
+
context
->
font_size
*
3
,
h
+
lh
/
2
);
}
else
{
cairo_move_to
(
cr
,
m
[
1
]
+
w
-
context
->
font_size
*
3
,
h
+
lh
/
2
);
cairo_line_to
(
cr
,
m
[
1
]
+
w
-
context
->
font_size
*
1
,
h
+
lh
/
2
);
}
cairo_save
(
cr
);
cairo_set_source_rgb
(
cr
,
context
->
colours
[
c
][
0
],
context
->
colours
[
c
][
1
],
context
->
colours
[
c
][
2
]);
cairo_set_line_width
(
cr
,
1
);
cairo_stroke
(
cr
);
cairo_restore
(
cr
);
h
+=
lh
+
0
.
5
*
context
->
font_size
;
c
=
(
c
+
1
)
%
context
->
n_colours
;
}
}
}
}
static
int
pretty
(
double
*
lo
,
double
*
up
,
int
ndiv
)
{
static
int
pretty
(
double
*
lo
,
double
*
up
,
int
ndiv
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment