Skip to content

Commit

Permalink
Finalize strings and translate charts
Browse files Browse the repository at this point in the history
Closes #22
  • Loading branch information
svetter committed Dec 23, 2023
1 parent 14eecd3 commit 8488d9c
Showing 5 changed files with 259 additions and 138 deletions.
2 changes: 1 addition & 1 deletion src/stats/chart.cpp
Original file line number Diff line number Diff line change
@@ -218,7 +218,7 @@ QBarSet* Chart::createBarSet(const QString& name, QAbstractBarSeries* series)
QLineSeries* Chart::createLineSeries(const QString& name)
{
QLineSeries* series = new QLineSeries();
series->setName(name);
if (!name.isEmpty()) series->setName(name);
return series;
}

2 changes: 1 addition & 1 deletion src/stats/chart.h
Original file line number Diff line number Diff line change
@@ -131,7 +131,7 @@ class Chart : public QObject

// Update helpers
public:
static QLineSeries* createLineSeries(const QString& name);
static QLineSeries* createLineSeries(const QString& name = QString());
static QScatterSeries* createScatterSeries(const QString& name, int markerSize = -1, QScatterSeries::MarkerShape markerShape = QScatterSeries::MarkerShape(-1));
protected:
static void adjustAxis(QValueAxis* axis, qreal minValue, qreal maxValue, int chartSize, qreal rangeBufferFactor = 0);
41 changes: 21 additions & 20 deletions src/stats/stats_engine.cpp
Original file line number Diff line number Diff line change
@@ -137,9 +137,9 @@ GeneralStatsEngine::~GeneralStatsEngine()
*/
void GeneralStatsEngine::setupStatsTab()
{
elevGainPerYearChart = new YearChart("Elevation gain sum per year", "km", false);
numAscentsPerYearChart = new YearChart("Number of scaled peaks per year", "Number of peaks", false);
heightsScatterChart = new YearChart("All elevation gains and peak heights over time", "m", true);
elevGainPerYearChart = new YearChart(tr("Elevation gain sum per year"), tr("km"), false);
numAscentsPerYearChart = new YearChart(tr("Number of ascents per year"), tr("Number of ascents"), false);
heightsScatterChart = new YearChart(tr("All elevation gains and peak heights over time"), tr("m"), true);

// Set layout
QHBoxLayout* statisticsTabUpperLayout = new QHBoxLayout();
@@ -180,11 +180,11 @@ void GeneralStatsEngine::updateStatsTab()
assert(elevGainPerYearChart);
assert(numAscentsPerYearChart);
assert(heightsScatterChart);

QLineSeries* elevGainPerYearSeries = Chart::createLineSeries ("Elevation gain");
QLineSeries* numAscentsPerYearSeries = Chart::createLineSeries ("Number of ascended peaks");
QScatterSeries* peakHeightSeries = Chart::createScatterSeries("Peak heights", 6, QScatterSeries::MarkerShapeTriangle);
QScatterSeries* elevGainSeries = Chart::createScatterSeries("Elevation gains", 6, QScatterSeries::MarkerShapeRotatedRectangle);
QLineSeries* elevGainPerYearSeries = Chart::createLineSeries();
QLineSeries* numAscentsPerYearSeries = Chart::createLineSeries();
QScatterSeries* elevGainSeries = Chart::createScatterSeries(tr("Elevation gains"), 6, QScatterSeries::MarkerShapeRotatedRectangle);
QScatterSeries* peakHeightSeries = Chart::createScatterSeries(tr("Peak heights"), 6, QScatterSeries::MarkerShapeTriangle);


QMap<int, int> yearElevGainSums = QMap<int, int>();
@@ -242,7 +242,7 @@ void GeneralStatsEngine::updateStatsTab()

elevGainPerYearChart ->updateData({elevGainPerYearSeries}, minYear, maxYear, 0, elevGainPerYearMaxY);
numAscentsPerYearChart ->updateData({numAscentsPerYearSeries}, minYear, maxYear, 0, numAscentsPerYearMaxY);
heightsScatterChart ->updateData({peakHeightSeries, elevGainSeries}, minDate, maxDate, 0, heightsMaxY);
heightsScatterChart ->updateData({elevGainSeries, peakHeightSeries}, minDate, maxDate, 0, heightsMaxY);
}


@@ -264,7 +264,7 @@ ItemStatsEngine::ItemStatsEngine(Database* db, PALItemType itemType, const Norma
statsLayout(statsLayout),
peakHeightHistCategoryIncrement(1000),
peakHeightHistCategoryMax(8848),
peakHeightHistCategories(getHistCategories(peakHeightHistCategoryIncrement, peakHeightHistCategoryMax, "", "s")),
peakHeightHistCategories(getHistCategories(peakHeightHistCategoryIncrement, peakHeightHistCategoryMax, "", tr("s"))),
numPeakHeightHistCategories(peakHeightHistCategories.size()),
elevGainHistCategoryIncrement(250),
elevGainHistCategoryMax(1500),
@@ -297,18 +297,19 @@ ItemStatsEngine::~ItemStatsEngine()
*/
void ItemStatsEngine::setupStatsPanel()
{
peakHeightHistChart = new HistogramChart("Peak height distribution", peakHeightHistCategories);
elevGainHistChart = new HistogramChart("Elevation gain distribution", elevGainHistCategories);
peakHeightHistChart = new HistogramChart(tr("Distribution of peak heights"), peakHeightHistCategories);
elevGainHistChart = new HistogramChart(tr("Distribution of elevation gains"), elevGainHistCategories);

heightsScatterChart = new YearChart("Elevation gains and peak heights over time", QString(), true);
heightsScatterChart = new YearChart(tr("Elevation gains and peak heights over time"), QString(), true);

int n = 10;
if (itemType != ItemTypeAscent) {
topTenNumAscentsChart = new TopNChart(10, "Most ascents");
topTenNumAscentsChart = new TopNChart(n, tr("Top %1: Most ascents").arg(n));
}
topTenMaxPeakHeightChart = new TopNChart(10, "Highest peak");
topTenMaxElevGainChart = new TopNChart(10, "Highest elevation gain");
topTenMaxPeakHeightChart = new TopNChart(n, tr("Top %1: Highest peak").arg(n));
topTenMaxElevGainChart = new TopNChart(n, tr("Top %1: Highest single elevation gain").arg(n));
if (itemType != ItemTypeAscent) {
topTenElevGainSumChart = new TopNChart(10, "Highest elevation gain sum [km]");
topTenElevGainSumChart = new TopNChart(n, tr("Top %1: Highest elevation gain sum [km]").arg(n));
}

heightsScatterChart->getChartView()->setMinimumHeight(250);
@@ -414,8 +415,8 @@ void ItemStatsEngine::updateStatsPanel(const QSet<BufferRowIndex>& selectedBuffe
// Heights scatterplot

if (heightsScatterChart) {
QScatterSeries* peakHeightScatterSeries = Chart::createScatterSeries("Peak heights", 5, QScatterSeries::MarkerShapeTriangle);
QScatterSeries* elevGainScatterSeries = Chart::createScatterSeries("Elevation gains", 5, QScatterSeries::MarkerShapeRotatedRectangle);
QScatterSeries* elevGainScatterSeries = Chart::createScatterSeries(tr("Elevation gains"), 5, QScatterSeries::MarkerShapeRotatedRectangle);
QScatterSeries* peakHeightScatterSeries = Chart::createScatterSeries(tr("Peak heights"), 5, QScatterSeries::MarkerShapeTriangle);
qreal minDate = 3000;
qreal maxDate = 0;
int heightsMaxY = 0;
@@ -446,7 +447,7 @@ void ItemStatsEngine::updateStatsPanel(const QSet<BufferRowIndex>& selectedBuffe
}
}

heightsScatterChart->updateData({peakHeightScatterSeries, elevGainScatterSeries}, minDate, maxDate, 0, heightsMaxY);
heightsScatterChart->updateData({elevGainScatterSeries, peakHeightScatterSeries}, minDate, maxDate, 0, heightsMaxY);
}


10 changes: 8 additions & 2 deletions src/stats/stats_engine.h
Original file line number Diff line number Diff line change
@@ -25,19 +25,21 @@
#define STATS_ENGINE_H

#include "src/db/database.h"

#include "chart.h"
#include "src/data/item_types.h"

#include <QObject>
#include <QBoxLayout>



/**
* A base class for statistical analysis classes, general and specific to each item type.
*/
class StatsEngine
class StatsEngine : protected QObject
{
Q_OBJECT

protected:
/** The database. */
Database* const db;
@@ -58,6 +60,8 @@ class StatsEngine
*/
class GeneralStatsEngine : public StatsEngine
{
Q_OBJECT

/** A double pointer to the layout of the statistics tab. */
QVBoxLayout** const statisticsTabLayoutPtr;

@@ -84,6 +88,8 @@ class GeneralStatsEngine : public StatsEngine
*/
class ItemStatsEngine : public StatsEngine
{
Q_OBJECT

/** The item type to compute and show statistics for and/or about. */
const PALItemType itemType;
/** The base table for the item type. */
Loading

0 comments on commit 8488d9c

Please sign in to comment.