Added initial support of statistical charts in earn channel section.
This commit is contained in:
@@ -28,13 +28,21 @@ 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(
|
||||
int newMaxHeight,
|
||||
int newMinHeight,
|
||||
bool useMinHeight,
|
||||
float64 rightRatio) {
|
||||
float64 rightRatio,
|
||||
int valueDivider) {
|
||||
if (!useMinHeight) {
|
||||
const auto v = (newMaxHeight > 100)
|
||||
? Round(newMaxHeight)
|
||||
@@ -92,7 +100,9 @@ ChartRulersData::ChartRulersData(
|
||||
const auto value = int(i * step);
|
||||
line.absoluteValue = newMinHeight + value;
|
||||
line.relativeValue = 1. - value / float64(diffAbsoluteValue);
|
||||
line.caption = Format(line.absoluteValue);
|
||||
line.caption = valueDivider
|
||||
? FormatF(line.absoluteValue / float64(valueDivider))
|
||||
: Format(line.absoluteValue);
|
||||
if (rightRatio > 0) {
|
||||
const auto v = (newMinHeight + i * step) / rightRatio;
|
||||
line.scaledLineCaption = (!skipFloatValues)
|
||||
|
||||
@@ -15,7 +15,8 @@ public:
|
||||
int newMaxHeight,
|
||||
int newMinHeight,
|
||||
bool useMinHeight,
|
||||
float64 rightRatio);
|
||||
float64 rightRatio,
|
||||
int valueDivider);
|
||||
|
||||
void computeRelative(
|
||||
int newMaxHeight,
|
||||
|
||||
@@ -172,3 +172,5 @@ boostsListGiftMiniIcon: icon{{ "boosts/mini_gift", historyPeer8UserpicBg2 }};
|
||||
boostsListGiveawayMiniIcon: icon{{ "boosts/mini_giveaway", historyPeer4UserpicBg2 }};
|
||||
boostsListUnclaimedIcon: icon{{ "boosts/boost_unknown", premiumButtonFg }};
|
||||
boostsListUnknownIcon: icon{{ "boosts/boost_unclaimed", premiumButtonFg }};
|
||||
|
||||
statisticsCurrencyIcon: icon {{ "statistics/mini_currency_graph", windowSubTextFg }};
|
||||
|
||||
@@ -61,7 +61,7 @@ Data::StatisticalChart StatisticalChartFromJSON(const QByteArray &json) {
|
||||
line.isHiddenOnStart = ranges::contains(hiddenLines, columnId);
|
||||
line.y.resize(length);
|
||||
for (auto i = 0; i < length; i++) {
|
||||
const auto value = array.at(i + 1).toInt();
|
||||
const auto value = array.at(i + 1).toInteger();
|
||||
line.y[i] = value;
|
||||
if (value > line.maxValue) {
|
||||
line.maxValue = value;
|
||||
@@ -132,6 +132,13 @@ 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();
|
||||
|
||||
@@ -23,6 +23,9 @@ void ChartRulersView::setChartData(
|
||||
std::shared_ptr<LinesFilterController> linesFilter) {
|
||||
_rulers.clear();
|
||||
_isDouble = (type == ChartViewType::DoubleLinear);
|
||||
_currencyIcon = chartData.isCurrency
|
||||
? &st::statisticsCurrencyIcon
|
||||
: nullptr;
|
||||
if (_isDouble && (chartData.lines.size() == 2)) {
|
||||
_linesFilter = std::move(linesFilter);
|
||||
_leftPen = QPen(chartData.lines.front().color);
|
||||
@@ -69,6 +72,7 @@ void ChartRulersView::paintCaptionsToRulers(
|
||||
for (auto &ruler : _rulers) {
|
||||
const auto rulerAlpha = alpha * ruler.alpha;
|
||||
p.setOpacity(rulerAlpha);
|
||||
const auto left = _currencyIcon ? _currencyIcon->width() : 0;
|
||||
for (const auto &line : ruler.lines) {
|
||||
const auto y = offset + r.height() * line.relativeValue;
|
||||
const auto hasLinesFilter = _isDouble && _linesFilter;
|
||||
@@ -78,8 +82,14 @@ void ChartRulersView::paintCaptionsToRulers(
|
||||
} else {
|
||||
p.setPen(st::windowSubTextFg);
|
||||
}
|
||||
if (_currencyIcon) {
|
||||
const auto iconTop = y
|
||||
- _currencyIcon->height()
|
||||
+ st::statisticsChartRulerCaptionSkip;
|
||||
_currencyIcon->paint(p, 0, iconTop, r.width());
|
||||
}
|
||||
p.drawText(
|
||||
0,
|
||||
left,
|
||||
y,
|
||||
(!_isDouble)
|
||||
? line.caption
|
||||
@@ -131,7 +141,8 @@ void ChartRulersView::add(Limits newHeight, bool animated) {
|
||||
newHeight.max,
|
||||
newHeight.min,
|
||||
true,
|
||||
_isDouble ? _scaledLineRatio : 0.);
|
||||
_isDouble ? _scaledLineRatio : 0.,
|
||||
_currencyIcon ? 1000000000 : 0);
|
||||
if (_isDouble) {
|
||||
const auto &font = st::statisticsDetailsBottomCaptionStyle.font;
|
||||
for (auto &line : newLinesData.lines) {
|
||||
|
||||
@@ -42,6 +42,7 @@ private:
|
||||
QPen _rightPen;
|
||||
int _leftLineId = 0;
|
||||
int _rightLineId = 0;
|
||||
const style::icon *_currencyIcon = nullptr;
|
||||
|
||||
std::vector<ChartRulersData> _rulers;
|
||||
|
||||
|
||||
@@ -132,7 +132,8 @@ PointDetailsWidget::PointDetailsWidget(
|
||||
, _zoomEnabled(zoomEnabled)
|
||||
, _chartData(chartData)
|
||||
, _textStyle(st::statisticsDetailsPopupStyle)
|
||||
, _headerStyle(st::statisticsDetailsPopupHeaderStyle) {
|
||||
, _headerStyle(st::statisticsDetailsPopupHeaderStyle)
|
||||
, _valueIcon(chartData.isCurrency ? &st::statisticsCurrencyIcon : nullptr) {
|
||||
|
||||
if (zoomEnabled) {
|
||||
rpl::single(rpl::empty_value()) | rpl::then(
|
||||
@@ -201,6 +202,7 @@ PointDetailsWidget::PointDetailsWidget(
|
||||
+ rect::m::sum::h(st::statisticsDetailsPopupPadding)
|
||||
+ st::statisticsDetailsPopupPadding.left() // Between strings.
|
||||
+ maxNameTextWidth
|
||||
+ (_valueIcon ? _valueIcon->width() : 0)
|
||||
+ _maxPercentageWidth;
|
||||
}();
|
||||
sizeValue(
|
||||
@@ -278,7 +280,9 @@ void PointDetailsWidget::setXIndex(int xIndex) {
|
||||
textLine.name.setText(_textStyle, dataLine.name);
|
||||
textLine.value.setText(
|
||||
_textStyle,
|
||||
QString("%L1").arg(dataLine.y[xIndex]));
|
||||
_chartData.isCurrency
|
||||
? QString::number(dataLine.y[xIndex] / float64(1000000000))
|
||||
: QString("%L1").arg(dataLine.y[xIndex]));
|
||||
hasPositiveValues |= (dataLine.y[xIndex] > 0);
|
||||
textLine.valueColor = QColor(dataLine.color);
|
||||
_lines.push_back(std::move(textLine));
|
||||
@@ -381,6 +385,14 @@ void PointDetailsWidget::paintEvent(QPaintEvent *e) {
|
||||
.outerWidth = _textRect.width(),
|
||||
.availableWidth = valueWidth,
|
||||
};
|
||||
if (_valueIcon) {
|
||||
_valueIcon->paint(
|
||||
p,
|
||||
valueContext.position.x() - _valueIcon->width(),
|
||||
lineY,
|
||||
valueContext.outerWidth,
|
||||
line.valueColor);
|
||||
}
|
||||
const auto nameContext = Ui::Text::PaintContext{
|
||||
.position = QPoint(
|
||||
_textRect.x() + _maxPercentageWidth,
|
||||
|
||||
@@ -47,6 +47,7 @@ private:
|
||||
const style::TextStyle &_textStyle;
|
||||
const style::TextStyle &_headerStyle;
|
||||
Ui::Text::String _header;
|
||||
const style::icon *_valueIcon = nullptr;
|
||||
|
||||
void invalidateCache();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user