Added support of very large values in PointDetailsWidget.
This commit is contained in:
parent
25f401c22e
commit
40ab042fb5
|
@ -823,7 +823,13 @@ void ChartWidget::setupDetails() {
|
|||
}
|
||||
_details.widget = base::make_unique_q<PointDetailsWidget>(
|
||||
this,
|
||||
_chartData);
|
||||
_chartData,
|
||||
FindHeightLimitsBetweenXLimits(
|
||||
_chartData,
|
||||
{
|
||||
_chartData.xPercentage.front(),
|
||||
_chartData.xPercentage.back(),
|
||||
}).max);
|
||||
|
||||
_chartArea->mouseStateChanged(
|
||||
) | rpl::start_with_next([=](const RpMouseWidget::State &state) {
|
||||
|
@ -856,9 +862,13 @@ void ChartWidget::setupDetails() {
|
|||
*nearestXPercentageIt);
|
||||
const auto xLeft = _details.currentX
|
||||
- _details.widget->width();
|
||||
const auto x = (xLeft < 0)
|
||||
? (_details.currentX)
|
||||
: xLeft;
|
||||
const auto x = (xLeft >= 0)
|
||||
? xLeft
|
||||
: ((_details.currentX
|
||||
+ _details.widget->width()
|
||||
- _chartArea->width()) > 0)
|
||||
? 0
|
||||
: _details.currentX;
|
||||
_details.widget->moveToLeft(x, _chartArea->y());
|
||||
_details.widget->setXIndex(nearestXIndex);
|
||||
_details.widget->show();
|
||||
|
|
|
@ -17,22 +17,53 @@ namespace Statistic {
|
|||
|
||||
PointDetailsWidget::PointDetailsWidget(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
const Data::StatisticalChart &chartData)
|
||||
const Data::StatisticalChart &chartData,
|
||||
float64 maxAbsoluteValue)
|
||||
: Ui::RpWidget(parent)
|
||||
, _chartData(chartData)
|
||||
, _textStyle(st::statisticsDetailsPopupStyle)
|
||||
, _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(
|
||||
) | rpl::start_with_next([=](const QSize &s) {
|
||||
const auto fullRect = s.isNull()
|
||||
? Rect(Size(st::statisticsDetailsPopupWidth))
|
||||
? Rect(Size(calculatedWidth))
|
||||
: Rect(s);
|
||||
_innerRect = fullRect - st::statisticsDetailsPopupPadding;
|
||||
_textRect = _innerRect - st::statisticsDetailsPopupMargins;
|
||||
}, lifetime());
|
||||
|
||||
resize(
|
||||
st::statisticsDetailsPopupWidth,
|
||||
calculatedWidth,
|
||||
lineYAt(chartData.lines.size())
|
||||
+ st::statisticsDetailsPopupMargins.bottom());
|
||||
}
|
||||
|
@ -55,7 +86,7 @@ void PointDetailsWidget::setXIndex(int xIndex) {
|
|||
textLine.name.setText(_textStyle, dataLine.name);
|
||||
textLine.value.setText(
|
||||
_textStyle,
|
||||
QString::number(dataLine.y[xIndex]));
|
||||
QString("%L1").arg(dataLine.y[xIndex]));
|
||||
textLine.valueColor = QColor(dataLine.color);
|
||||
_lines.push_back(std::move(textLine));
|
||||
}
|
||||
|
|
|
@ -16,7 +16,8 @@ class PointDetailsWidget : public Ui::RpWidget {
|
|||
public:
|
||||
PointDetailsWidget(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
const Data::StatisticalChart &chartData);
|
||||
const Data::StatisticalChart &chartData,
|
||||
float64 maxAbsoluteValue);
|
||||
|
||||
[[nodiscard]] int xIndex() const;
|
||||
void setXIndex(int xIndex);
|
||||
|
|
|
@ -10,7 +10,6 @@ using "ui/basic.style";
|
|||
using "window/window.style";
|
||||
using "ui/widgets/widgets.style";
|
||||
|
||||
statisticsDetailsPopupWidth: 135px;
|
||||
statisticsDetailsPopupMargins: margins(8px, 8px, 8px, 8px);
|
||||
statisticsDetailsPopupPadding: margins(6px, 6px, 6px, 6px);
|
||||
statisticsDetailsPopupMidLineSpace: 8px;
|
||||
|
|
Loading…
Reference in New Issue