MCPcopy Create free account
hub / github.com/chrxh/alien / drawValuesAtMouseCursor

Method drawValuesAtMouseCursor

source/Gui/StatisticsWindow.cpp:776–843  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

774}
775
776void StatisticsWindow::drawValuesAtMouseCursor(
777 double const* dataPoints,
778 double const* timePoints,
779 double const* systemClock,
780 int count,
781 double startTime,
782 double endTime,
783 double upperBound,
784 int fracPartDecimals)
785{
786 auto constexpr stride = sizeof(DataPointCollection) / sizeof(double);
787
788 auto mousePos = ImPlot::GetPlotMousePos();
789 mousePos.x = std::max(startTime, std::min(endTime, mousePos.x));
790 mousePos.y = dataPoints[0];
791
792 auto dateTimeString =
793 [&] {
794 if (systemClock == nullptr) {
795 for (int i = 1; i < count; ++i) {
796 if (timePoints[i * stride] > mousePos.x) {
797 mousePos.y = dataPoints[i * stride];
798 break;
799 }
800 }
801 return std::string();
802 }
803 auto systemClockEntry = systemClock[0];
804 for (int i = 1; i < count; ++i) {
805 if (timePoints[i * stride] > mousePos.x) {
806 mousePos.y = dataPoints[i * stride];
807 systemClockEntry = systemClock[i * stride];
808 break;
809 }
810 }
811 mousePos.y = std::max(0.0, std::min(upperBound, mousePos.y));
812
813 return systemClockEntry != 0 ? convertSystemClockToString(systemClockEntry) : std::string("-");
814 }();
815
816 ImPlot::PushStyleColor(ImPlotCol_InlayText, ImColor::HSV(0.0f, 0.0f, 1.0f).Value);
817 ImPlot::PlotText(ICON_FA_GENDERLESS, mousePos.x, mousePos.y, {scale(1.0f), scale(2.0f)});
818 ImPlot::PopStyleColor();
819
820 ImPlot::PushStyleColor(ImPlotCol_Line, ImColor::HSV(0.0f, 0.0f, 1.0f).Value);
821 ImPlot::PlotInfLines("", &mousePos.x, 1);
822 ImPlot::PopStyleColor();
823
824 char label[256];
825 auto leftSideFactor = mousePos.x > (startTime + endTime) / 2 ? -1.0f : 1.0f;
826 if (!dateTimeString.empty()) {
827 snprintf(
828 label,
829 sizeof(label),
830 "Time step: %s\nTimestamp: %s\nValue: %s",
831 StringHelper::format(mousePos.x, 0).c_str(),
832 dateTimeString.c_str(),
833 StringHelper::format(mousePos.y, fracPartDecimals).c_str());

Callers

nothing calls this directly

Calls 2

scaleFunction · 0.85

Tested by

no test coverage detected