various chart window updates and improvements

- charts are reset if the thermo style changes
- charts are reset if the timestep is reset (to a lower value)
- charts are not updated if thermo data is not valid (e.g. during setup)
- use integer format for Steps on the x-axis
This commit is contained in:
Axel Kohlmeyer
2023-08-15 01:05:54 -04:00
parent 8bfa0b2b04
commit 3bf70c1b97
3 changed files with 62 additions and 4 deletions

View File

@ -49,6 +49,31 @@ ChartWindow::ChartWindow(const QString &_filename, QWidget *parent) :
resize(settings.value("chartx", 500).toInt(), settings.value("charty", 320).toInt()); resize(settings.value("chartx", 500).toInt(), settings.value("charty", 320).toInt());
} }
int ChartWindow::get_step() const
{
if (charts.size() > 0) {
auto *v = charts[0];
return (int)v->get_step(v->get_count()-1);
} else {
return -1;
}
}
void ChartWindow::reset_charts()
{
while (layout()->count() > 1) {
auto *item = layout()->takeAt(1);
if (item) {
layout()->removeItem(item);
delete item->widget();
delete item;
}
}
charts.clear();
columns->clear();
active_chart = 0;
}
void ChartWindow::add_chart(const QString &title, int index) void ChartWindow::add_chart(const QString &title, int index)
{ {
auto *chart = new ChartViewer(title, index); auto *chart = new ChartViewer(title, index);
@ -182,6 +207,7 @@ ChartViewer::ChartViewer(const QString &title, int _index, QWidget *parent) :
series->attachAxis(yaxis); series->attachAxis(yaxis);
xaxis->setTitleText("Time step"); xaxis->setTitleText("Time step");
xaxis->setTickCount(5); xaxis->setTickCount(5);
xaxis->setLabelFormat("%d");
yaxis->setTickCount(5); yaxis->setTickCount(5);
xaxis->setMinorTickCount(5); xaxis->setMinorTickCount(5);
yaxis->setMinorTickCount(5); yaxis->setMinorTickCount(5);

View File

@ -31,7 +31,13 @@ class ChartWindow : public QWidget {
public: public:
ChartWindow(const QString &filename, QWidget *parent = nullptr); ChartWindow(const QString &filename, QWidget *parent = nullptr);
bool has_charts() const { return !charts.isEmpty(); } int num_charts() const { return charts.size(); }
bool has_title(const QString &title, int index) const
{
return (columns->itemText(index) == title);
}
int get_step() const;
void reset_charts();
void add_chart(const QString &title, int index); void add_chart(const QString &title, int index);
void add_data(int step, double data, int index); void add_data(int step, double data, int index);

View File

@ -558,7 +558,11 @@ void LammpsGui::logupdate()
// extract cached thermo data // extract cached thermo data
if (chartwindow) { if (chartwindow) {
void *ptr = lammps.last_thermo("step", 0); // thermo data is not yet valid during setup
void *ptr = lammps.last_thermo("setup", 0);
if (ptr && *(int *)ptr) return;
ptr = lammps.last_thermo("step", 0);
if (ptr) { if (ptr) {
int step = 0; int step = 0;
if (lammps.extract_setting("bigint") == 4) if (lammps.extract_setting("bigint") == 4)
@ -566,7 +570,29 @@ void LammpsGui::logupdate()
else else
step = (int)*(int64_t *)ptr; step = (int)*(int64_t *)ptr;
int ncols = *(int *)lammps.last_thermo("num", 0); int ncols = *(int *)lammps.last_thermo("num", 0);
if (!chartwindow->has_charts()) {
// check if the column assignment has changed
// if yes, delete charts and start over
if (chartwindow->num_charts() > 0) {
int count = 0;
bool do_reset = false;
if (step < chartwindow->get_step()) do_reset = true;
for (int i = 0, idx = 0; i < ncols; ++i) {
QString label = (const char *)lammps.last_thermo("keyword", i);
// no need to store the timestep column
if (label == "Step") continue;
if (!chartwindow->has_title(label, idx)) {
do_reset = true;
} else {
++count;
}
++idx;
}
if (chartwindow->num_charts() != count) do_reset = true;
if (do_reset) chartwindow->reset_charts();
}
if (chartwindow->num_charts() == 0) {
for (int i = 0; i < ncols; ++i) { for (int i = 0; i < ncols; ++i) {
QString label = (const char *)lammps.last_thermo("keyword", i); QString label = (const char *)lammps.last_thermo("keyword", i);
// no need to store the timestep column // no need to store the timestep column
@ -622,7 +648,7 @@ void LammpsGui::run_done()
step = (int)*(int64_t *)ptr; step = (int)*(int64_t *)ptr;
int ncols = *(int *)lammps.last_thermo("num", 0); int ncols = *(int *)lammps.last_thermo("num", 0);
for (int i = 0; i < ncols; ++i) { for (int i = 0; i < ncols; ++i) {
if (!chartwindow->has_charts()) { if (chartwindow->num_charts() == 0) {
QString label = (const char *)lammps.last_thermo("keyword", i); QString label = (const char *)lammps.last_thermo("keyword", i);
// no need to store the timestep column // no need to store the timestep column
if (label == "Step") continue; if (label == "Step") continue;