Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix large numbers and add timestamp support #273

Merged
merged 2 commits into from
Jul 30, 2022

Conversation

TheGreatRambler
Copy link
Contributor

Fixes using large number for ticks and adds support for rendering timestamps in, for example, xticks

@TheGreatRambler
Copy link
Contributor Author

Just a note, what seem like formatting issues are actually the result of your own .clang-format file, for example some lines were changed because you have an 80 character column limit and you probably haven't touched these files since you added the column limit

Copy link
Owner

@alandefreitas alandefreitas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! :)

Fixes using large number for ticks

Why? Were the numbers outside the margins? What is the issue here?

and adds support for rendering timestamps

Are these two things related?

Just a note, what seem like formatting issues are actually the result of your own .clang-format file, for example some lines were changed because you have an 80 character column limit and you probably haven't touched these files since you added the column limit

That's fine. We don't reformat the whole thing whenever parameters change. We only reformat files as we change them.

@@ -143,6 +143,8 @@ namespace matplot {

std::string bars::data_string() {
std::stringstream ss;
ss.precision(5);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these generating some kind of gnuplot warning?

Shouldn't gnuplot understand any precision?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default stringstream precision prevented rendering of very small numbers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I believe (these are some old changes I wanted to PR so it's been a while) gnuplot would start using scientific notation without that change

if (terminal_ == "dumb") {
run_command("set terminal dumb " + num2str(position_[2]) + " " +
num2str(position_[3]));
} else {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else if (terminal_has_size_option(terminal_))

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay wait this shouldn't be here lmao, but I do remember why I put this here, the dumb terminal is super funny and actually has a nonstandard way of setting the size, as you can see here, but it's not relevant to this PR

if (terminal_has_size_option(terminal_)) {
run_command("set terminal " + terminal_ + " size " +
num2str(position_[2]) + "," + num2str(position_[3]));
if (terminal_ == "dumb") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry... How are these changes related to the PR?

if (terminal_ == "dumb") {
run_command("set terminal dumb " + num2str(position_[2]) + " " +
num2str(position_[3]));
} else {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else if (...)

@@ -106,6 +107,9 @@ namespace matplot {
return *this;
}

bool is_timestamp() const;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the timestamp related to the ss.precision(5)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timestamp(true) enables timestamp rendering, so ax->xtickformat ("%m/%d/%Y %H:%M:%S"); can be used for example. ss.precision() is relevant to large numbers

@@ -154,6 +158,8 @@ namespace matplot {
float label_font_size_{11};
color_array label_color_{0, 0, 0, 0};

bool is_timestamp_{false};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that all? Do other libraries also work like that?

if (is_timestamp_) {
char buff[20] = {0};
time_t now = (time_t)tick_values_[i];
strftime(buff, 20, tick_label_format_.c_str(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the default tick_label_format_ work for timestamps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because strftime supports formatting the hour, minute, second, etc using a millisecond input. num2str does not do this

@@ -46,6 +46,8 @@ namespace matplot {

template <class T> std::string num2str(Arithmetic<T> num) {
std::ostringstream ss;
ss.precision(5);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I completely understand the motivation for precision(5) at other classes, but it doesn't look like a sensible default for this function.

For instance,

str(2.5433653543232154254214321541)

gives me

'2.5433653543232153'

in python.

@TheGreatRambler
Copy link
Contributor Author

TheGreatRambler commented Jun 2, 2022

Okay so the dumb terminal should be removed entirely (though you do explicitly support the dumb terminal so this is sorta a bugfix), and ss.precision is probably not required (though ss << std::fixed is absolutely required to support large numbers)

@TheGreatRambler
Copy link
Contributor Author

I should mention this explicitely as well, the issue I was referring to was large numbers being converted to scientific notation by default, which is somewhat annoying especially in the y axis

@alandefreitas alandefreitas merged commit 3c81acc into alandefreitas:master Jul 30, 2022
@alandefreitas
Copy link
Owner

@TheGreatRambler
Copy link
Contributor Author

Glad it was useful! Got a bit preoccupied on other code, because of the font issue I shelved this project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants