Add Graph Settings (#879)

This commit is contained in:
Rudy Huyn
2020-01-03 15:06:14 -08:00
committed by GitHub
parent 234ac8deb3
commit 8357f5d5c5
35 changed files with 1882 additions and 195 deletions

View File

@@ -451,6 +451,11 @@ namespace GraphControl
{
options.SetForceProportional(ForceProportionalAxes);
if (!options.GetAllowKeyGraphFeaturesForFunctionsWithParameters())
{
options.SetAllowKeyGraphFeaturesForFunctionsWithParameters(true);
}
if (!validEqs.empty())
{
vector<Graphing::Color> graphColors;
@@ -479,8 +484,9 @@ namespace GraphControl
return validEqs;
}
void Grapher::OnForceProportionalAxesPropertyChanged(bool /*oldValue*/, bool /*newValue*/)
void Grapher::OnForceProportionalAxesPropertyChanged(bool /*oldValue*/, bool newValue)
{
m_calculatedForceProportional = newValue;
TryUpdateGraph();
}

View File

@@ -107,6 +107,142 @@ public
void PlotGraph();
GraphControl::KeyGraphFeaturesInfo ^ AnalyzeEquation(GraphControl::Equation ^ equation);
// We can't use the EvalTrigUnitMode enum directly in as the property type because it comes from another module which doesn't expose
// it as a public enum class. So the compiler doesn't recognize it as a valid type for the ABI boundary.
property int TrigUnitMode
{
void set(int value)
{
if (value != (int)m_solver->EvalOptions().GetTrigUnitMode())
{
m_solver->EvalOptions().SetTrigUnitMode((Graphing::EvalTrigUnitMode)value);
PlotGraph();
}
}
int get()
{
return (int)m_solver->EvalOptions().GetTrigUnitMode();
}
}
property double XAxisMin
{
double get()
{
return m_graph->GetOptions().GetDefaultXRange().first;
}
void set(double value)
{
std::pair<double, double> newValue(value, XAxisMax);
if (m_graph != nullptr)
{
m_graph->GetOptions().SetDefaultXRange(newValue);
if (m_renderMain != nullptr)
{
m_renderMain->RunRenderPass();
}
}
}
}
property double XAxisMax
{
double get()
{
return m_graph->GetOptions().GetDefaultXRange().second;
}
void set(double value)
{
std::pair<double, double> newValue(XAxisMin, value);
if (m_graph != nullptr)
{
m_graph->GetOptions().SetDefaultXRange(newValue);
if (m_renderMain != nullptr)
{
m_renderMain->RunRenderPass();
}
}
}
}
property double YAxisMin
{
double get()
{
return m_graph->GetOptions().GetDefaultXRange().first;
}
void set(double value)
{
std::pair<double, double> newValue(value, YAxisMax);
if (m_graph != nullptr)
{
m_graph->GetOptions().SetDefaultYRange(newValue);
if (m_renderMain != nullptr)
{
m_renderMain->RunRenderPass();
}
}
}
}
property double YAxisMax
{
double get()
{
return m_graph->GetOptions().GetDefaultXRange().second;
}
void set(double value)
{
std::pair<double, double> newValue(YAxisMin, value);
if (m_graph != nullptr)
{
m_graph->GetOptions().SetDefaultYRange(newValue);
if (m_renderMain != nullptr)
{
m_renderMain->RunRenderPass();
}
}
}
}
void GetDisplayRanges(double* xMin, double* xMax, double* yMin, double* yMax)
{
try
{
if (m_graph != nullptr)
{
if (auto render = m_graph->GetRenderer())
{
render->GetDisplayRanges(*xMin, *xMax, *yMin, *yMax);
}
}
}
catch (const std::exception&)
{
OutputDebugString(L"GetDisplayRanges failed\r\n");
}
}
void SetDisplayRanges(double xMin, double xMax, double yMin, double yMax)
{
try
{
if (auto render = m_graph->GetRenderer())
{
render->SetDisplayRanges(xMin, xMax, yMin, yMax);
if (m_renderMain)
{
m_renderMain->RunRenderPass();
}
}
}
catch (const std::exception&)
{
OutputDebugString(L"SetDisplayRanges failed\r\n");
}
}
protected:
#pragma region Control Overrides
void OnApplyTemplate() override;
@@ -149,9 +285,6 @@ public
void SetEquationsAsValid();
void SetEquationErrors();
Windows::Foundation::Collections::IObservableVector<Platform::String ^> ^ ConvertWStringVector(std::vector<std::wstring> inVector);
Windows::Foundation::Collections::IObservableMap<Platform::String ^, Platform::String ^> ^ ConvertWStringIntMap(std::map<std::wstring, int> inMap);
private:
DX::RenderMain ^ m_renderMain = nullptr;
@@ -171,7 +304,7 @@ public
const std::unique_ptr<Graphing::IMathSolver> m_solver;
const std::shared_ptr<Graphing::IGraph> m_graph;
bool m_calculatedForceProportional = false;
bool m_tracingTracking;
enum KeysPressedSlots
{
@@ -184,7 +317,6 @@ public
bool m_KeysPressed[5];
bool m_Moving;
Windows::UI::Xaml::DispatcherTimer ^ m_TracingTrackingTimer;
public:

View File

@@ -171,28 +171,23 @@ namespace GraphControl::DX
if (m_drawNearestPoint || m_drawActiveTracing)
{
Point trackPoint = m_pointerLocation;
if (m_drawActiveTracing)
{
// Active tracing takes over for draw nearest point input from the mouse pointer.
trackPoint = m_activeTracingPointerLocation;
}
int formulaId;
Point nearestPointLocation;
pair<float, float> nearestPointValue;
renderer->GetClosePointData(
trackPoint.X,
trackPoint.Y,
formulaId,
nearestPointLocation.X,
nearestPointLocation.Y,
nearestPointValue.first,
nearestPointValue.second);
int formulaId = -1;
float nearestPointLocationX, nearestPointLocationY;
float nearestPointValueX, nearestPointValueY;
if (!isnan(nearestPointLocation.X) && !isnan(nearestPointLocation.Y))
if (renderer->GetClosePointData(
trackPoint.X, trackPoint.Y, formulaId, nearestPointLocationX, nearestPointLocationY, nearestPointValueX, nearestPointValueY)
== S_OK)
{
auto lineColors = m_graph->GetOptions().GetGraphColors();
if (!isnan(nearestPointLocationX) && !isnan(nearestPointLocationY))
{
auto lineColors = m_graph->GetOptions().GetGraphColors();
if (formulaId >= 0 && static_cast<unsigned int>(formulaId) < lineColors.size())
{
@@ -200,10 +195,16 @@ namespace GraphControl::DX
m_nearestPointRenderer.SetColor(D2D1::ColorF(dotColor.R * 65536 + dotColor.G * 256 + dotColor.B, 1.0));
}
m_nearestPointRenderer.Render(nearestPointLocation);
m_Tracing = true;
m_TraceLocation = Point(nearestPointLocation.X, nearestPointLocation.Y);
m_TraceValue = Point(nearestPointValue.first, nearestPointValue.second);
m_TraceLocation = Point(nearestPointLocationX, nearestPointLocationY);
m_nearestPointRenderer.Render(m_TraceLocation);
m_Tracing = true;
m_TraceLocation = Point(nearestPointLocationX, nearestPointLocationY);
m_TraceValue = Point(nearestPointValueX, nearestPointValueY);
}
else
{
m_Tracing = false;
}
}
else
{