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
9a9b6bf1
Commit
9a9b6bf1
authored
Dec 4, 2023
by
tag2y19
Committed by
Tom Greig
May 2, 2024
Browse files
Options
Downloads
Patches
Plain Diff
Add controls for x-axis zooming/scrolling
[Shift-](H|L)
parent
bd1d4456
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.c
+173
-7
173 additions, 7 deletions
src/main.c
with
173 additions
and
7 deletions
src/main.c
+
173
−
7
View file @
9a9b6bf1
...
@@ -36,6 +36,14 @@ struct context {
...
@@ -36,6 +36,14 @@ struct context {
float
(
*
colours
)[
3
];
float
(
*
colours
)[
3
];
size_t
n_colours
;
size_t
n_colours
;
double
xdist
;
bool
xfit
;
double
xpos
;
bool
xfollow
;
double
ydist
;
/* 0 for fit all */
double
ypos
;
};
};
struct
fd_source
{
struct
fd_source
{
...
@@ -54,6 +62,9 @@ static int listener_check( GSource* source );
...
@@ -54,6 +62,9 @@ static int listener_check( GSource* source );
static
int
listener_dispatch
(
static
int
listener_dispatch
(
GSource
*
source
,
GSourceFunc
funk
,
void
*
data
);
GSource
*
source
,
GSourceFunc
funk
,
void
*
data
);
static
void
listener_finalise
(
GSource
*
source
);
static
void
listener_finalise
(
GSource
*
source
);
static
int
key_callback
(
GtkEventControllerKey
*
event_controller
,
unsigned
int
keyval
,
unsigned
int
keycode
,
GdkModifierType
mods
,
void
*
data
);
static
int
data_callback
(
void
*
data
);
static
int
data_callback
(
void
*
data
);
static
void
parse_headers
(
struct
context
*
context
);
static
void
parse_headers
(
struct
context
*
context
);
static
void
parse_data
(
struct
context
*
context
);
static
void
parse_data
(
struct
context
*
context
);
...
@@ -67,6 +78,8 @@ int main( int argc, char** argv ) {
...
@@ -67,6 +78,8 @@ int main( int argc, char** argv ) {
struct
context
*
context
=
calloc
(
1
,
sizeof
*
context
);
struct
context
*
context
=
calloc
(
1
,
sizeof
*
context
);
context
->
read_buffer
=
calloc
(
512
,
sizeof
(
char
)
);
context
->
read_buffer
=
calloc
(
512
,
sizeof
(
char
)
);
context
->
read_buffer_len
=
512
;
context
->
read_buffer_len
=
512
;
context
->
xfit
=
true
;
context
->
xfollow
=
true
;
static
const
char
*
colours
[]
=
{
static
const
char
*
colours
[]
=
{
"#005C84"
,
"#FCBC00"
,
"#0C838C"
,
"#E63037"
,
"#005C84"
,
"#FCBC00"
,
"#0C838C"
,
"#E63037"
,
...
@@ -145,6 +158,12 @@ static void app_activate( GtkApplication* app, void* data ) {
...
@@ -145,6 +158,12 @@ static void app_activate( GtkApplication* app, void* data ) {
GTK_DRAWING_AREA
(
context
->
plot
),
plot_draw
,
context
,
NULL
);
GTK_DRAWING_AREA
(
context
->
plot
),
plot_draw
,
context
,
NULL
);
gtk_window_set_child
(
GTK_WINDOW
(
window
),
context
->
plot
);
gtk_window_set_child
(
GTK_WINDOW
(
window
),
context
->
plot
);
GtkEventController
*
event_controller
=
gtk_event_controller_key_new
();
g_signal_connect
(
event_controller
,
"key-released"
,
G_CALLBACK
(
&
key_callback
),
context
);
gtk_widget_add_controller
(
window
,
event_controller
);
static
GSourceFuncs
listener_funks
=
{
static
GSourceFuncs
listener_funks
=
{
.
prepare
=
&
listener_prepare
,
.
prepare
=
&
listener_prepare
,
.
check
=
&
listener_check
,
.
check
=
&
listener_check
,
...
@@ -197,6 +216,99 @@ static void listener_finalise( GSource* source ) {
...
@@ -197,6 +216,99 @@ static void listener_finalise( GSource* source ) {
}
}
static
int
key_callback
(
GtkEventControllerKey
*
event_controller
,
unsigned
int
keyval
,
unsigned
int
keycode
,
GdkModifierType
mods
,
void
*
data
)
{
struct
context
*
context
=
(
struct
context
*
)
data
;
(
void
)
event_controller
;
(
void
)
keycode
;
mods
&=
GDK_CONTROL_MASK
|
GDK_ALT_MASK
|
GDK_SHIFT_MASK
;
switch
(
keyval
)
{
case
'h'
:
case
'H'
:
case
GDK_KEY_Left
:
{
switch
(
(
unsigned
int
)
mods
)
{
case
0
:
{
context
->
xpos
-=
context
->
xdist
/
8
;
context
->
xfollow
=
false
;
gtk_widget_queue_draw
(
context
->
plot
);
return
true
;
}
case
GDK_SHIFT_MASK
:
{
context
->
xfit
=
false
;
context
->
xdist
/=
2
;
gtk_widget_queue_draw
(
context
->
plot
);
return
true
;
}
default:
{
return
false
;
}
}
}
case
'l'
:
case
'L'
:
case
GDK_KEY_Right
:
{
switch
(
(
unsigned
int
)
mods
)
{
case
0
:
{
context
->
xpos
+=
context
->
xdist
/
8
;
context
->
xfollow
=
false
;
gtk_widget_queue_draw
(
context
->
plot
);
return
true
;
}
case
GDK_SHIFT_MASK
:
{
context
->
xdist
*=
2
;
gtk_widget_queue_draw
(
context
->
plot
);
return
true
;
}
default:
{
return
false
;
}
}
}
default:
{
return
false
;
}
}
}
static
int
data_callback
(
void
*
data
)
{
static
int
data_callback
(
void
*
data
)
{
struct
context
*
context
=
(
struct
context
*
)
data
;
struct
context
*
context
=
(
struct
context
*
)
data
;
...
@@ -540,7 +652,7 @@ static void plot_draw( GtkDrawingArea* plot,
...
@@ -540,7 +652,7 @@ static void plot_draw( GtkDrawingArea* plot,
return
;
return
;
}
}
/*
Data
*/
/*
Ranges
*/
double
xrange
[
2
]
=
{
context
->
data
->
x
,
};
double
xrange
[
2
]
=
{
context
->
data
->
x
,
};
double
yrange
[
2
];
double
yrange
[
2
];
...
@@ -576,6 +688,41 @@ static void plot_draw( GtkDrawingArea* plot,
...
@@ -576,6 +688,41 @@ static void plot_draw( GtkDrawingArea* plot,
return
;
return
;
}
}
if
(
!
context
->
xfit
&&
xrange
[
1
]
-
xrange
[
0
]
>
context
->
xdist
)
{
if
(
context
->
xfollow
)
{
xrange
[
0
]
=
xrange
[
1
]
-
context
->
xdist
;
context
->
xpos
=
(
xrange
[
0
]
+
xrange
[
1
]
)
/
2
;
}
else
{
if
(
xrange
[
0
]
>
context
->
xpos
-
context
->
xdist
/
2
)
{
xrange
[
1
]
=
xrange
[
0
]
+
context
->
xdist
;
}
else
if
(
xrange
[
1
]
<
context
->
xpos
+
context
->
xdist
/
2
)
{
xrange
[
0
]
=
xrange
[
1
]
-
context
->
xdist
;
context
->
xfollow
=
true
;
context
->
xpos
=
(
xrange
[
0
]
+
xrange
[
1
]
)
/
2
;
}
else
{
xrange
[
0
]
=
context
->
xpos
-
context
->
xdist
/
2
;
xrange
[
1
]
=
context
->
xpos
+
context
->
xdist
/
2
;
}
}
}
else
{
context
->
xfit
=
true
;
}
if
(
xrange
[
0
]
==
xrange
[
1
]
)
{
if
(
xrange
[
0
]
==
xrange
[
1
]
)
{
xrange
[
0
]
-=
0
.
5
;
xrange
[
0
]
-=
0
.
5
;
xrange
[
1
]
+=
0
.
5
;
xrange
[
1
]
+=
0
.
5
;
...
@@ -586,7 +733,19 @@ static void plot_draw( GtkDrawingArea* plot,
...
@@ -586,7 +733,19 @@ static void plot_draw( GtkDrawingArea* plot,
yrange
[
1
]
+=
0
.
5
;
yrange
[
1
]
+=
0
.
5
;
}
}
if
(
NULL
==
context
->
data
->
next
)
{
if
(
context
->
xfit
)
{
context
->
xdist
=
xrange
[
1
]
-
xrange
[
0
];
}
/* Data */
struct
data
*
first_data
=
context
->
data
;
while
(
NULL
!=
first_data
->
next
&&
xrange
[
0
]
>
first_data
->
next
->
x
)
{
first_data
=
first_data
->
next
;
}
if
(
NULL
==
first_data
->
next
)
{
cairo_save
(
cr
);
cairo_save
(
cr
);
cairo_set_source_rgb
(
cr
,
0
,
0
,
0
);
cairo_set_source_rgb
(
cr
,
0
,
0
,
0
);
...
@@ -611,7 +770,16 @@ static void plot_draw( GtkDrawingArea* plot,
...
@@ -611,7 +770,16 @@ static void plot_draw( GtkDrawingArea* plot,
}
}
for
(
struct
data
*
data
=
context
->
data
;
cairo_save
(
cr
);
cairo_move_to
(
cr
,
4
,
4
);
cairo_line_to
(
cr
,
width
-
4
,
4
);
cairo_line_to
(
cr
,
width
-
4
,
height
-
4
);
cairo_line_to
(
cr
,
4
,
height
-
4
);
cairo_line_to
(
cr
,
4
,
4
);
cairo_clip
(
cr
);
cairo_set_line_width
(
cr
,
1
);
for
(
struct
data
*
data
=
first_data
;
NULL
!=
data
->
next
;
NULL
!=
data
->
next
;
data
=
data
->
next
)
{
data
=
data
->
next
)
{
...
@@ -619,10 +787,8 @@ static void plot_draw( GtkDrawingArea* plot,
...
@@ -619,10 +787,8 @@ static void plot_draw( GtkDrawingArea* plot,
size_t
c
=
i
%
context
->
n_colours
;
size_t
c
=
i
%
context
->
n_colours
;
cairo_save
(
cr
);
cairo_set_source_rgb
(
cr
,
context
->
colours
[
c
][
0
],
cairo_set_source_rgb
(
cr
,
context
->
colours
[
c
][
0
],
context
->
colours
[
c
][
1
],
context
->
colours
[
c
][
2
]
);
context
->
colours
[
c
][
1
],
context
->
colours
[
c
][
2
]
);
cairo_set_line_width
(
cr
,
1
);
if
(
data
->
y
[
i
].
present
)
{
if
(
data
->
y
[
i
].
present
)
{
...
@@ -660,10 +826,10 @@ static void plot_draw( GtkDrawingArea* plot,
...
@@ -660,10 +826,10 @@ static void plot_draw( GtkDrawingArea* plot,
}
}
cairo_restore
(
cr
);
}
}
}
}
cairo_restore
(
cr
);
}
}
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