Added second rulers to currency chart in channel earn info section.
This commit is contained in:
@@ -28,13 +28,6 @@ constexpr auto kStep = 5.;
|
||||
: QString::number(absoluteValue);
|
||||
}
|
||||
|
||||
[[nodiscard]] QString FormatF(float64 absoluteValue) {
|
||||
constexpr auto kTooMuch = int(10'000);
|
||||
return (absoluteValue >= kTooMuch)
|
||||
? Lang::FormatCountToShort(absoluteValue).string
|
||||
: QString::number(absoluteValue);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
ChartRulersData::ChartRulersData(
|
||||
@@ -42,7 +35,8 @@ ChartRulersData::ChartRulersData(
|
||||
int newMinHeight,
|
||||
bool useMinHeight,
|
||||
float64 rightRatio,
|
||||
int valueDivider) {
|
||||
Fn<QString(float64)> leftCustomCaption,
|
||||
Fn<QString(float64)> rightCustomCaption) {
|
||||
if (!useMinHeight) {
|
||||
const auto v = (newMaxHeight > 100)
|
||||
? Round(newMaxHeight)
|
||||
@@ -100,12 +94,14 @@ ChartRulersData::ChartRulersData(
|
||||
const auto value = int(i * step);
|
||||
line.absoluteValue = newMinHeight + value;
|
||||
line.relativeValue = 1. - value / float64(diffAbsoluteValue);
|
||||
line.caption = valueDivider
|
||||
? FormatF(line.absoluteValue / float64(valueDivider))
|
||||
line.caption = leftCustomCaption
|
||||
? leftCustomCaption(line.absoluteValue)
|
||||
: Format(line.absoluteValue);
|
||||
if (rightRatio > 0) {
|
||||
if (rightRatio > 0 || rightCustomCaption) {
|
||||
const auto v = (newMinHeight + i * step) / rightRatio;
|
||||
line.scaledLineCaption = (!skipFloatValues)
|
||||
line.scaledLineCaption = rightCustomCaption
|
||||
? rightCustomCaption(line.absoluteValue)
|
||||
: (!skipFloatValues)
|
||||
? Format(v)
|
||||
: ((v - int(v)) < 0.01)
|
||||
? Format(v)
|
||||
|
||||
@@ -16,7 +16,8 @@ public:
|
||||
int newMinHeight,
|
||||
bool useMinHeight,
|
||||
float64 rightRatio,
|
||||
int valueDivider);
|
||||
Fn<QString(float64)> leftCustomCaption = nullptr,
|
||||
Fn<QString(float64)> rightCustomCaption = nullptr);
|
||||
|
||||
void computeRelative(
|
||||
int newMaxHeight,
|
||||
|
||||
@@ -132,13 +132,6 @@ Data::StatisticalChart StatisticalChartFromJSON(const QByteArray &json) {
|
||||
result.weekFormat = tooltipFormat.contains(u"'week'"_q);
|
||||
}
|
||||
}
|
||||
{
|
||||
const auto tickFormatIt = root.constFind(u"yTickFormatter"_q);
|
||||
if (tickFormatIt != root.constEnd()) {
|
||||
const auto tickFormat = tickFormatIt->toString();
|
||||
result.isCurrency = tickFormat.contains(u"TON"_q);
|
||||
}
|
||||
}
|
||||
|
||||
const auto colors = root.value(u"colors"_q).toObject();
|
||||
const auto names = root.value(u"names"_q).toObject();
|
||||
|
||||
@@ -8,12 +8,24 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "statistics/view/chart_rulers_view.h"
|
||||
|
||||
#include "data/data_channel_earn.h" // Data::kEarnMultiplier.
|
||||
#include "info/channel_statistics/earn/earn_format.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "statistics/chart_lines_filter_controller.h"
|
||||
#include "statistics/statistics_common.h"
|
||||
#include "styles/style_basic.h"
|
||||
#include "styles/style_statistics.h"
|
||||
|
||||
namespace Statistic {
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] QString FormatF(float64 absoluteValue) {
|
||||
constexpr auto kTooMuch = int(10'000);
|
||||
return (absoluteValue >= kTooMuch)
|
||||
? Lang::FormatCountToShort(absoluteValue).string
|
||||
: QString::number(absoluteValue);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
ChartRulersView::ChartRulersView() = default;
|
||||
|
||||
@@ -22,10 +34,18 @@ void ChartRulersView::setChartData(
|
||||
ChartViewType type,
|
||||
std::shared_ptr<LinesFilterController> linesFilter) {
|
||||
_rulers.clear();
|
||||
_isDouble = (type == ChartViewType::DoubleLinear);
|
||||
_currencyIcon = chartData.isCurrency
|
||||
? &st::statisticsCurrencyIcon
|
||||
: nullptr;
|
||||
_isDouble = (type == ChartViewType::DoubleLinear)
|
||||
|| chartData.currencyRate;
|
||||
if (chartData.currencyRate) {
|
||||
_currencyIcon = &st::statisticsCurrencyIcon;
|
||||
_leftCustomCaption = [=](float64 value) {
|
||||
return FormatF(value / float64(Data::kEarnMultiplier));
|
||||
};
|
||||
_rightCustomCaption = [=, rate = chartData.currencyRate](float64 v) {
|
||||
return Info::ChannelEarn::ToUsd(v, rate).mid(1);
|
||||
};
|
||||
_rightPen = QPen(st::windowSubTextFg);
|
||||
}
|
||||
if (_isDouble && (chartData.lines.size() == 2)) {
|
||||
_linesFilter = std::move(linesFilter);
|
||||
_leftPen = QPen(chartData.lines.front().color);
|
||||
@@ -96,8 +116,10 @@ void ChartRulersView::paintCaptionsToRulers(
|
||||
: _isLeftLineScaled
|
||||
? line.scaledLineCaption
|
||||
: line.caption);
|
||||
if (hasLinesFilter) {
|
||||
p.setOpacity(rulerAlpha * _linesFilter->alpha(_rightLineId));
|
||||
if (hasLinesFilter || _rightCustomCaption) {
|
||||
if (_linesFilter) {
|
||||
p.setOpacity(rulerAlpha * _linesFilter->alpha(_rightLineId));
|
||||
}
|
||||
p.setPen(_rightPen);
|
||||
p.drawText(
|
||||
r.width() - line.rightCaptionWidth,
|
||||
@@ -142,7 +164,8 @@ void ChartRulersView::add(Limits newHeight, bool animated) {
|
||||
newHeight.min,
|
||||
true,
|
||||
_isDouble ? _scaledLineRatio : 0.,
|
||||
_currencyIcon ? Data::kEarnMultiplier : 0);
|
||||
_leftCustomCaption,
|
||||
_rightCustomCaption);
|
||||
if (_isDouble) {
|
||||
const auto &font = st::statisticsDetailsBottomCaptionStyle.font;
|
||||
for (auto &line : newLinesData.lines) {
|
||||
|
||||
@@ -44,6 +44,9 @@ private:
|
||||
int _rightLineId = 0;
|
||||
const style::icon *_currencyIcon = nullptr;
|
||||
|
||||
Fn<QString(float64)> _leftCustomCaption = nullptr;
|
||||
Fn<QString(float64)> _rightCustomCaption = nullptr;
|
||||
|
||||
std::vector<ChartRulersData> _rulers;
|
||||
|
||||
std::shared_ptr<LinesFilterController> _linesFilter;
|
||||
|
||||
@@ -134,7 +134,7 @@ PointDetailsWidget::PointDetailsWidget(
|
||||
, _chartData(chartData)
|
||||
, _textStyle(st::statisticsDetailsPopupStyle)
|
||||
, _headerStyle(st::statisticsDetailsPopupHeaderStyle)
|
||||
, _valueIcon(chartData.isCurrency ? &st::statisticsCurrencyIcon : nullptr) {
|
||||
, _valueIcon(chartData.currencyRate ? &st::statisticsCurrencyIcon : nullptr) {
|
||||
|
||||
if (zoomEnabled) {
|
||||
rpl::single(rpl::empty_value()) | rpl::then(
|
||||
@@ -282,7 +282,7 @@ void PointDetailsWidget::setXIndex(int xIndex) {
|
||||
textLine.name.setText(_textStyle, dataLine.name);
|
||||
textLine.value.setText(
|
||||
_textStyle,
|
||||
_chartData.isCurrency
|
||||
_chartData.currencyRate
|
||||
? QString::number(dataLine.y[xIndex] / multiplier)
|
||||
: QString("%L1").arg(dataLine.y[xIndex]));
|
||||
hasPositiveValues |= (dataLine.y[xIndex] > 0);
|
||||
|
||||
Reference in New Issue
Block a user