Change trace point value precision to be dynamic based on graph scale (#1148)
* Dynamic precision * add comments * feedback * Update src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp Co-Authored-By: Rudy Huyn <rudyhuyn@gmail.com> * PR feedback * Pr comment Co-authored-by: Rudy Huyn <rudyhuyn@gmail.com>
This commit is contained in:
parent
1ded2c57db
commit
0465dc8538
@ -207,12 +207,44 @@ void GraphingCalculator::OnEquationsVectorChanged(IObservableVector<EquationView
|
|||||||
GraphingControl->PlotGraph(false);
|
GraphingControl->PlotGraph(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wstringstream GraphingCalculator::FormatTraceValue(double min, double max, float pointValue)
|
||||||
|
{
|
||||||
|
wstringstream traceValueString;
|
||||||
|
|
||||||
|
// Extract precision we will round to
|
||||||
|
auto precision = static_cast<int>(floor(log10(max - min)) - 3);
|
||||||
|
|
||||||
|
// Determine if we want to show scientific notation instead
|
||||||
|
if (precision <= -7 || precision >= 7)
|
||||||
|
{
|
||||||
|
traceValueString << scientific;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
traceValueString << fixed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we are rounding to a decimal place, set the precision
|
||||||
|
if (precision < 0)
|
||||||
|
{
|
||||||
|
traceValueString << setprecision(::min(7, abs(precision))) << pointValue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
traceValueString << setprecision(0) << pointValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return traceValueString;
|
||||||
|
}
|
||||||
|
|
||||||
void GraphingCalculator::OnTracePointChanged(Point newPoint)
|
void GraphingCalculator::OnTracePointChanged(Point newPoint)
|
||||||
{
|
{
|
||||||
wstringstream traceValueString;
|
wstringstream traceValueString;
|
||||||
|
|
||||||
// TODO: The below precision should ideally be dynamic based on the current scale of the graph.
|
double xAxisMin, xAxisMax, yAxisMin, yAxisMax;
|
||||||
traceValueString << "(" << fixed << setprecision(1) << newPoint.X << ", " << fixed << setprecision(1) << newPoint.Y << ")";
|
GraphingControl->GetDisplayRanges(&xAxisMin, &xAxisMax, &yAxisMin, &yAxisMax);
|
||||||
|
|
||||||
|
traceValueString << "(" << FormatTraceValue(xAxisMin, xAxisMax, newPoint.X).str() << ", " << FormatTraceValue(yAxisMin, yAxisMax, newPoint.Y).str() << ")";
|
||||||
|
|
||||||
TraceValue->Text = ref new String(traceValueString.str().c_str());
|
TraceValue->Text = ref new String(traceValueString.str().c_str());
|
||||||
|
|
||||||
|
@ -104,6 +104,7 @@ public ref class GraphingCalculator sealed : public Windows::UI::Xaml::Data::INo
|
|||||||
void OnEquationFormatRequested(Platform::Object ^ sender, CalculatorApp::Controls::MathRichEditBoxFormatRequest ^ e);
|
void OnEquationFormatRequested(Platform::Object ^ sender, CalculatorApp::Controls::MathRichEditBoxFormatRequest ^ e);
|
||||||
void GraphMenuFlyoutItem_Click(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
void GraphMenuFlyoutItem_Click(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||||
void OnVisualStateChanged(Platform::Object ^ sender, Windows::UI::Xaml::VisualStateChangedEventArgs ^ e);
|
void OnVisualStateChanged(Platform::Object ^ sender, Windows::UI::Xaml::VisualStateChangedEventArgs ^ e);
|
||||||
|
std::wstringstream FormatTraceValue(double min, double max, float pointValue);
|
||||||
void GraphViewButton_Click(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
void GraphViewButton_Click(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <WindowsNumerics.h>
|
#include <WindowsNumerics.h>
|
||||||
|
|
||||||
|
@ -232,10 +232,11 @@ public enum class GraphViewChangedReason
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (m_graph != nullptr)
|
if (m_graph != nullptr && m_renderMain != nullptr)
|
||||||
{
|
{
|
||||||
if (auto render = m_graph->GetRenderer())
|
if (auto render = m_graph->GetRenderer())
|
||||||
{
|
{
|
||||||
|
Concurrency::critical_section::scoped_lock lock(m_renderMain->GetCriticalSection());
|
||||||
render->GetDisplayRanges(*xMin, *xMax, *yMin, *yMax);
|
render->GetDisplayRanges(*xMin, *xMax, *yMin, *yMax);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user