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
4ecda605
Commit
4ecda605
authored
1 year ago
by
tag2y19
Committed by
Tom Greig
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Add option to set the x-axis column
-x <column name> means we'll use that column's values as the x coordinates.
parent
9a9b6bf1
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
+62
-8
62 additions, 8 deletions
src/main.c
with
62 additions
and
8 deletions
src/main.c
+
62
−
8
View file @
4ecda605
...
...
@@ -33,6 +33,9 @@ struct context {
GtkWidget
*
plot
;
char
*
xaxis
;
size_t
xaxis_n
;
float
(
*
colours
)[
3
];
size_t
n_colours
;
...
...
@@ -98,8 +101,24 @@ int main( int argc, char** argv ) {
fcntl
(
STDIN_FILENO
,
F_SETFL
,
fcntl
(
STDIN_FILENO
,
F_GETFL
)
|
O_NONBLOCK
);
const
GOptionEntry
options
[]
=
{
{
.
long_name
=
"x-axis"
,
.
short_name
=
'x'
,
.
flags
=
G_OPTION_FLAG_NONE
,
.
arg
=
G_OPTION_ARG_STRING
,
.
arg_data
=
&
(
context
->
xaxis
),
.
description
=
"Column to use as the x-axis"
,
.
arg_description
=
"column"
,
},
{
NULL
,
},
};
GtkApplication
*
app
=
gtk_application_new
(
"uk.ac.soton.ecs.e-plot"
,
G_APPLICATION_DEFAULT_FLAGS
);
g_application_add_main_option_entries
(
G_APPLICATION
(
app
),
options
);
g_signal_connect
(
app
,
"activate"
,
G_CALLBACK
(
app_activate
),
context
);
...
...
@@ -418,6 +437,8 @@ static void parse_headers( struct context* context ) {
c
=
context
->
read_buffer
;
quote
=
'\0'
;
bool
found
=
false
;
while
(
'\0'
!=
*
c
)
{
header
[
0
]
=
'\0'
;
...
...
@@ -482,6 +503,13 @@ static void parse_headers( struct context* context ) {
stripped_header
[
strlen
(
stripped_header
)
-
1
]
=
'\0'
;
}
if
(
NULL
!=
context
->
xaxis
&&
0
==
strcmp
(
stripped_header
,
context
->
xaxis
)
)
{
found
=
true
;
}
else
{
context
->
headers
[
n
]
=
strdup
(
stripped_header
);
n
++
;
...
...
@@ -489,6 +517,14 @@ static void parse_headers( struct context* context ) {
}
if
(
!
found
)
{
free
(
context
->
xaxis
);
context
->
xaxis
=
NULL
;
context
->
xaxis_n
=
-
1
;
}
}
static
void
parse_data
(
struct
context
*
context
)
{
assert
(
0
!=
context
->
n_headers
);
...
...
@@ -514,6 +550,7 @@ static void parse_data( struct context* context ) {
size_t
n
=
0
;
char
value
[
strlen
(
context
->
read_buffer
)];
char
quote
=
'\0'
;
bool
timed
=
false
;
while
(
'\0'
!=
*
c
&&
n
<
context
->
n_headers
)
{
...
...
@@ -579,8 +616,23 @@ static void parse_data( struct context* context ) {
}
char
*
end_ptr
=
NULL
;
data
->
y
[
n
].
v
=
strtod
(
stripped_value
,
&
end_ptr
);
double
value
=
strtod
(
stripped_value
,
&
end_ptr
);
if
(
n
==
context
->
xaxis_n
&&
!
timed
)
{
timed
=
true
;
if
(
'\0'
==
*
end_ptr
)
{
data
->
x
=
value
;
}
else
{
free
(
data
);
return
;
}
}
else
{
if
(
'\0'
==
*
end_ptr
)
{
data
->
y
[
n
].
v
=
value
;
data
->
y
[
n
].
present
=
true
;
}
else
{
data
->
y
[
n
].
present
=
false
;
...
...
@@ -590,6 +642,8 @@ static void parse_data( struct context* context ) {
}
}
if
(
NULL
==
context
->
data
)
{
context
->
data
=
data
;
...
...
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