Skip to content
This repository has been archived by the owner on Dec 17, 2017. It is now read-only.

Commit

Permalink
More natural logarithmic scale
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzmas committed Oct 27, 2012
1 parent 6db15fd commit 322021c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 50 deletions.
10 changes: 6 additions & 4 deletions razorqt-panel/plugin-sysstat/razorsysstat.cpp
Expand Up @@ -135,7 +135,9 @@ void RazorSysStatContent::updateSettings(const QSettings &settings)
netTransmittedColour = QColor(settings.value("net/transmittedColour", "0x808000").toString().toInt(NULL, 0) | 0xff000000);
netMaximumSpeed = PluginSysStat::netSpeedFromString(settings.value("net/maximumSpeed", "1 MB/s").toString());
logarithmicScale = settings.value("net/logarithmicScale", true).toBool();
logarithmicScaleValue = settings.value("net/logarithmicScaleValue", 1.0).toDouble();

logScaleSteps = settings.value("net/logarithmicScaleSteps", 4).toInt();
logScaleMax = static_cast<qreal>(static_cast<int64_t>(1) << logScaleSteps);

netRealMaximumSpeed = static_cast<qreal>(static_cast<int64_t>(1) << netMaximumSpeed);

Expand Down Expand Up @@ -320,7 +322,7 @@ void RazorSysStatContent::swapUpdate(float used)
int height = historyImage[imageIndex].height() - titleFontPixelHeight;
int y_used = height - height * used + 0.5;

drawLine(imageIndex, x, 0, y_used, bgColour);
drawLine(imageIndex, x, 0, y_used, bgColour);
drawLine(imageIndex, x, y_used, height, swapUsedColour);

++historyOffset;
Expand All @@ -341,8 +343,8 @@ void RazorSysStatContent::networkUpdate(unsigned received, unsigned transmitted)
qreal max_value = qMin(qMax(static_cast<qreal>(qMax(received, transmitted)) / netRealMaximumSpeed, 0.0), 1.0);
if (logarithmicScale)
{
min_value = qLn(min_value * (qPow(M_E, logarithmicScaleValue) - 1.0) + 1.0) / logarithmicScaleValue;
max_value = qLn(max_value * (qPow(M_E, logarithmicScaleValue) - 1.0) + 1.0) / logarithmicScaleValue;
min_value = qLn(min_value * (logScaleMax - 1.0) + 1.0) / qLn(2.0) / static_cast<qreal>(logScaleSteps);
max_value = qLn(max_value * (logScaleMax - 1.0) + 1.0) / qLn(2.0) / static_cast<qreal>(logScaleSteps);
}
int y_min = height - height * min_value + 0.5;
int y_max = height - height * max_value + 0.5;
Expand Down
3 changes: 2 additions & 1 deletion razorqt-panel/plugin-sysstat/razorsysstat.h
Expand Up @@ -114,7 +114,8 @@ protected slots:
int netMaximumSpeed;
qreal netRealMaximumSpeed;
bool logarithmicScale;
double logarithmicScaleValue;
int logScaleSteps;
qreal logScaleMax;

int historyOffset;
QImage historyImage[2];
Expand Down
5 changes: 2 additions & 3 deletions razorqt-panel/plugin-sysstat/razorsysstatconfiguration.cpp
Expand Up @@ -137,8 +137,7 @@ void RazorSysStatConfiguration::loadSettings()
ui->maximumHS->setValue(PluginSysStat::netSpeedFromString(mSettings.value("net/maximumSpeed", "1 MB/s").toString()));
on_maximumHS_valueChanged(ui->maximumHS->value());
ui->logarithmicCB->setChecked(mSettings.value("net/logarithmicScale", true).toBool());
ui->logScaleSB->setValue(mSettings.value("net/logarithmicScaleValue", 1.0).toDouble());

ui->logScaleSB->setValue(mSettings.value("net/logarithmicScaleSteps", 4).toInt());

lockSaving = false;
}
Expand Down Expand Up @@ -181,7 +180,7 @@ void RazorSysStatConfiguration::saveSettings()
mSettings.setValue("net/transmittedColour", QString("0x%1").arg(ui->netTransmittedF->palette().color(QPalette::Window).rgb() & 0x00ffffff, 6, 16, QChar('0')));
mSettings.setValue("net/maximumSpeed", PluginSysStat::netSpeedToString(ui->maximumHS->value()));
mSettings.setValue("net/logarithmicScale", ui->logarithmicCB->isChecked());
mSettings.setValue("net/logarithmicScaleValue", ui->logScaleSB->value());
mSettings.setValue("net/logarithmicScaleSteps", ui->logScaleSB->value());
}

void RazorSysStatConfiguration::dialogButtonsAction(QAbstractButton *btn)
Expand Down
49 changes: 7 additions & 42 deletions razorqt-panel/plugin-sysstat/razorsysstatconfiguration.ui
Expand Up @@ -972,21 +972,18 @@
</layout>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="logScaleSB">
<property name="enabled">
<bool>false</bool>
</property>
<property name="decimals">
<number>1</number>
<widget class="QSpinBox" name="logScaleSB">
<property name="suffix">
<string> steps</string>
</property>
<property name="minimum">
<double>0.000000000000000</double>
<number>1</number>
</property>
<property name="maximum">
<double>3.000000000000000</double>
<number>64</number>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
<property name="value">
<number>4</number>
</property>
</widget>
</item>
Expand Down Expand Up @@ -1262,38 +1259,6 @@
</hint>
</hints>
</connection>
<connection>
<sender>logarithmicCB</sender>
<signal>toggled(bool)</signal>
<receiver>logScaleSB</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>502</x>
<y>201</y>
</hint>
<hint type="destinationlabel">
<x>566</x>
<y>201</y>
</hint>
</hints>
</connection>
<connection>
<sender>logScaleSB</sender>
<signal>valueChanged(double)</signal>
<receiver>RazorSysStatConfiguration</receiver>
<slot>saveSettings()</slot>
<hints>
<hint type="sourcelabel">
<x>703</x>
<y>204</y>
</hint>
<hint type="destinationlabel">
<x>732</x>
<y>203</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<signal>maximumNetSpeedChanged(QString)</signal>
Expand Down

0 comments on commit 322021c

Please sign in to comment.