mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 07:33:52 +02:00
Added support of very large values in PointDetailsWidget.
This commit is contained in:
parent
25f401c22e
commit
40ab042fb5
4 changed files with 51 additions and 10 deletions
|
@ -823,7 +823,13 @@ void ChartWidget::setupDetails() {
|
||||||
}
|
}
|
||||||
_details.widget = base::make_unique_q<PointDetailsWidget>(
|
_details.widget = base::make_unique_q<PointDetailsWidget>(
|
||||||
this,
|
this,
|
||||||
_chartData);
|
_chartData,
|
||||||
|
FindHeightLimitsBetweenXLimits(
|
||||||
|
_chartData,
|
||||||
|
{
|
||||||
|
_chartData.xPercentage.front(),
|
||||||
|
_chartData.xPercentage.back(),
|
||||||
|
}).max);
|
||||||
|
|
||||||
_chartArea->mouseStateChanged(
|
_chartArea->mouseStateChanged(
|
||||||
) | rpl::start_with_next([=](const RpMouseWidget::State &state) {
|
) | rpl::start_with_next([=](const RpMouseWidget::State &state) {
|
||||||
|
@ -856,9 +862,13 @@ void ChartWidget::setupDetails() {
|
||||||
*nearestXPercentageIt);
|
*nearestXPercentageIt);
|
||||||
const auto xLeft = _details.currentX
|
const auto xLeft = _details.currentX
|
||||||
- _details.widget->width();
|
- _details.widget->width();
|
||||||
const auto x = (xLeft < 0)
|
const auto x = (xLeft >= 0)
|
||||||
? (_details.currentX)
|
? xLeft
|
||||||
: xLeft;
|
: ((_details.currentX
|
||||||
|
+ _details.widget->width()
|
||||||
|
- _chartArea->width()) > 0)
|
||||||
|
? 0
|
||||||
|
: _details.currentX;
|
||||||
_details.widget->moveToLeft(x, _chartArea->y());
|
_details.widget->moveToLeft(x, _chartArea->y());
|
||||||
_details.widget->setXIndex(nearestXIndex);
|
_details.widget->setXIndex(nearestXIndex);
|
||||||
_details.widget->show();
|
_details.widget->show();
|
||||||
|
|
|
@ -17,22 +17,53 @@ namespace Statistic {
|
||||||
|
|
||||||
PointDetailsWidget::PointDetailsWidget(
|
PointDetailsWidget::PointDetailsWidget(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
const Data::StatisticalChart &chartData)
|
const Data::StatisticalChart &chartData,
|
||||||
|
float64 maxAbsoluteValue)
|
||||||
: Ui::RpWidget(parent)
|
: Ui::RpWidget(parent)
|
||||||
, _chartData(chartData)
|
, _chartData(chartData)
|
||||||
, _textStyle(st::statisticsDetailsPopupStyle)
|
, _textStyle(st::statisticsDetailsPopupStyle)
|
||||||
, _headerStyle(st::semiboldTextStyle) {
|
, _headerStyle(st::semiboldTextStyle) {
|
||||||
|
const auto calculatedWidth = [&]{
|
||||||
|
const auto maxValueText = Ui::Text::String(
|
||||||
|
_textStyle,
|
||||||
|
QString("%L1").arg(maxAbsoluteValue));
|
||||||
|
const auto maxValueTextWidth = maxValueText.maxWidth();
|
||||||
|
|
||||||
|
auto maxNameTextWidth = 0;
|
||||||
|
for (const auto &dataLine : _chartData.lines) {
|
||||||
|
const auto maxNameText = Ui::Text::String(
|
||||||
|
_textStyle,
|
||||||
|
dataLine.name);
|
||||||
|
maxNameTextWidth = std::max(
|
||||||
|
maxNameText.maxWidth(),
|
||||||
|
maxNameTextWidth);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const auto maxHeaderText = Ui::Text::String(
|
||||||
|
_headerStyle,
|
||||||
|
_chartData.getDayString(0));
|
||||||
|
maxNameTextWidth = std::max(
|
||||||
|
maxHeaderText.maxWidth()
|
||||||
|
+ st::statisticsDetailsPopupPadding.left(),
|
||||||
|
maxNameTextWidth);
|
||||||
|
}
|
||||||
|
return maxValueTextWidth
|
||||||
|
+ rect::m::sum::h(st::statisticsDetailsPopupMargins)
|
||||||
|
+ rect::m::sum::h(st::statisticsDetailsPopupPadding)
|
||||||
|
+ st::statisticsDetailsPopupPadding.left() // Between strings.
|
||||||
|
+ maxNameTextWidth;
|
||||||
|
}();
|
||||||
sizeValue(
|
sizeValue(
|
||||||
) | rpl::start_with_next([=](const QSize &s) {
|
) | rpl::start_with_next([=](const QSize &s) {
|
||||||
const auto fullRect = s.isNull()
|
const auto fullRect = s.isNull()
|
||||||
? Rect(Size(st::statisticsDetailsPopupWidth))
|
? Rect(Size(calculatedWidth))
|
||||||
: Rect(s);
|
: Rect(s);
|
||||||
_innerRect = fullRect - st::statisticsDetailsPopupPadding;
|
_innerRect = fullRect - st::statisticsDetailsPopupPadding;
|
||||||
_textRect = _innerRect - st::statisticsDetailsPopupMargins;
|
_textRect = _innerRect - st::statisticsDetailsPopupMargins;
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
resize(
|
resize(
|
||||||
st::statisticsDetailsPopupWidth,
|
calculatedWidth,
|
||||||
lineYAt(chartData.lines.size())
|
lineYAt(chartData.lines.size())
|
||||||
+ st::statisticsDetailsPopupMargins.bottom());
|
+ st::statisticsDetailsPopupMargins.bottom());
|
||||||
}
|
}
|
||||||
|
@ -55,7 +86,7 @@ void PointDetailsWidget::setXIndex(int xIndex) {
|
||||||
textLine.name.setText(_textStyle, dataLine.name);
|
textLine.name.setText(_textStyle, dataLine.name);
|
||||||
textLine.value.setText(
|
textLine.value.setText(
|
||||||
_textStyle,
|
_textStyle,
|
||||||
QString::number(dataLine.y[xIndex]));
|
QString("%L1").arg(dataLine.y[xIndex]));
|
||||||
textLine.valueColor = QColor(dataLine.color);
|
textLine.valueColor = QColor(dataLine.color);
|
||||||
_lines.push_back(std::move(textLine));
|
_lines.push_back(std::move(textLine));
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,8 @@ class PointDetailsWidget : public Ui::RpWidget {
|
||||||
public:
|
public:
|
||||||
PointDetailsWidget(
|
PointDetailsWidget(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
const Data::StatisticalChart &chartData);
|
const Data::StatisticalChart &chartData,
|
||||||
|
float64 maxAbsoluteValue);
|
||||||
|
|
||||||
[[nodiscard]] int xIndex() const;
|
[[nodiscard]] int xIndex() const;
|
||||||
void setXIndex(int xIndex);
|
void setXIndex(int xIndex);
|
||||||
|
|
|
@ -10,7 +10,6 @@ using "ui/basic.style";
|
||||||
using "window/window.style";
|
using "window/window.style";
|
||||||
using "ui/widgets/widgets.style";
|
using "ui/widgets/widgets.style";
|
||||||
|
|
||||||
statisticsDetailsPopupWidth: 135px;
|
|
||||||
statisticsDetailsPopupMargins: margins(8px, 8px, 8px, 8px);
|
statisticsDetailsPopupMargins: margins(8px, 8px, 8px, 8px);
|
||||||
statisticsDetailsPopupPadding: margins(6px, 6px, 6px, 6px);
|
statisticsDetailsPopupPadding: margins(6px, 6px, 6px, 6px);
|
||||||
statisticsDetailsPopupMidLineSpace: 8px;
|
statisticsDetailsPopupMidLineSpace: 8px;
|
||||||
|
|
Loading…
Add table
Reference in a new issue