1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include "datawindow.h"
#include "../plot/xyplot.h"
#include <sstream>
#include <iomanip>
void DataWindow::SetData(const XYPlot& plot) {
_plot = &plot;
int selectedIndex = _comboBox.get_active_row_number();
if (selectedIndex < 0) selectedIndex = 0;
_comboListStore->clear();
for (size_t i = 0; i < plot.PointSetCount(); ++i) {
std::stringstream str;
str << (i + 1) << ". " << plot.GetPointSet(i).Label();
const Gtk::TreeModel::Row row = *_comboListStore->append();
row[_comboColumnRecord._comboListNameColumn] = str.str();
}
if (selectedIndex < (int)plot.PointSetCount())
_comboBox.set_active(selectedIndex);
else if (plot.PointSetCount() > 0)
_comboBox.set_active(0);
onComboChange();
}
void DataWindow::onComboChange() {
const int active = _comboBox.get_active_row_number();
if (active >= 0)
loadData(active);
else
loadData(_plot->PointSetCount());
}
void DataWindow::loadData(size_t plotSetIndex) {
std::stringstream _dataStream;
_dataStream << std::setprecision(14);
if (_plot->PointSetCount() > plotSetIndex) {
const XYPointSet& pointSet = _plot->GetPointSet(plotSetIndex);
const size_t valueCount = pointSet.Size();
for (size_t i = 0; i < valueCount; ++i) {
const double x = pointSet.GetX(i), y = pointSet.GetY(i);
if (_plot->XAxis().Type() == AxisType::kText) {
const std::string& label = _plot->XAxis().TickLabels()[i].second;
_dataStream << i << '\t' << label << '\t' << y << '\n';
} else {
_dataStream << i << '\t' << x << '\t' << y << '\n';
}
}
}
SetData(_dataStream.str());
}
|