Persist variable settings after graph is plotted (#1055)

* Allow copying graph as image

* Persist variables

* Revert "Allow copying graph as image"

This reverts commit 4fc9d798bc5f3ff82efc4fb00140103213fb81e2.

* fix binding bug

* undo cert change

* fix animation

* remove extra lines

* remove overrides

* undo key comment
This commit is contained in:
Pepe Rivera
2020-03-17 11:27:00 -07:00
committed by GitHub
parent 1b72ecb6b3
commit 28dbdb3d94
10 changed files with 125 additions and 50 deletions

View File

@@ -442,9 +442,9 @@ namespace GraphControl
{
critical_section::scoped_lock lock(m_renderMain->GetCriticalSection());
for (auto variable : Variables)
for (auto variablePair : Variables)
{
graph->SetArgValue(variable->Key->Data(), variable->Value);
graph->SetArgValue(variablePair->Key->Data(), variablePair->Value->Value);
}
}
}
@@ -470,7 +470,7 @@ namespace GraphControl
void Grapher::UpdateVariables()
{
auto updatedVariables = ref new Map<String ^, double>();
auto updatedVariables = ref new Map<String ^, Variable ^>();
if (m_graph)
{
@@ -483,12 +483,19 @@ namespace GraphControl
auto key = ref new String(graphVar->GetVariableName().data());
double value = 1.0;
Variable ^ variable;
if (Variables->HasKey(key))
{
value = Variables->Lookup(key);
variable = Variables->Lookup(key);
}
updatedVariables->Insert(key, value);
if (variable == nullptr)
{
variable = ref new Variable(1.0);
}
updatedVariables->Insert(key, variable);
}
}
}
@@ -504,17 +511,11 @@ namespace GraphControl
void Grapher::SetVariable(Platform::String ^ variableName, double newValue)
{
if (Variables->HasKey(variableName))
if (!Variables->HasKey(variableName))
{
if (Variables->Lookup(variableName) == newValue)
{
return;
}
Variables->Remove(variableName);
Variables->Insert(variableName, ref new Variable(newValue));
}
Variables->Insert(variableName, newValue);
if (m_graph != nullptr && m_renderMain != nullptr)
{

View File

@@ -4,9 +4,10 @@
#pragma once
#include "DirectX/RenderMain.h"
#include "../Models/Equation.h"
#include "../Models/EquationCollection.h"
#include "../Utils.h"
#include "Models/Equation.h"
#include "Models/EquationCollection.h"
#include "Models/Variable.h"
#include "Utils.h"
#include "IGraphAnalyzer.h"
#include "IMathSolver.h"
#include "Common.h"
@@ -43,9 +44,9 @@ public
DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(bool, ForceProportionalAxes, true);
DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(bool, UseCommaDecimalSeperator, false);
DEPENDENCY_PROPERTY_WITH_DEFAULT(
SINGLE_ARG(Windows::Foundation::Collections::IObservableMap<Platform::String ^, double> ^),
SINGLE_ARG(Windows::Foundation::Collections::IObservableMap<Platform::String ^, GraphControl::Variable ^> ^),
Variables,
SINGLE_ARG(ref new Platform::Collections::Map<Platform::String ^, double>()));
SINGLE_ARG(ref new Platform::Collections::Map<Platform::String ^, GraphControl::Variable ^>()));
DEPENDENCY_PROPERTY_R_WITH_DEFAULT_AND_CALLBACK(GraphControl::EquationCollection ^, Equations, nullptr);
DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(Windows::UI::Color, AxesColor, Windows::UI::Colors::Transparent);
DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(Windows::UI::Color, GraphBackground, Windows::UI::Colors::Transparent);
@@ -105,7 +106,7 @@ public
}
}
event Windows::Foundation::EventHandler<Windows::Foundation::Collections::IMap<Platform::String ^, double> ^> ^ VariablesUpdated;
event Windows::Foundation::EventHandler<Windows::Foundation::Collections::IMap<Platform::String ^, Variable ^> ^> ^ VariablesUpdated;
void SetVariable(Platform::String ^ variableName, double newValue);
Platform::String ^ ConvertToLinear(Platform::String ^ mmlString);
Platform::String ^ FormatMathML(Platform::String ^ mmlString);

View File

@@ -300,6 +300,7 @@
<ClInclude Include="Models\KeyGraphFeaturesInfo.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="Utils.h" />
<ClInclude Include="Models\Variable.h" />
<ClInclude Include="winrtHeaders.h" />
</ItemGroup>
<ItemGroup>

View File

@@ -60,6 +60,9 @@
<ClInclude Include="Models\EquationCollection.h">
<Filter>Models</Filter>
</ClInclude>
<ClInclude Include="Models\Variable.h">
<Filter>Models</Filter>
</ClInclude>
<ClInclude Include="Logger\TraceLogger.h" />
</ItemGroup>
<ItemGroup>
@@ -70,7 +73,5 @@
<ItemGroup>
<CopyFileToFolders Include="$(GraphingImplDll)" />
<CopyFileToFolders Include="$(GraphingEngineDll)" />
<CopyFileToFolders Include="$(GraphingImplDll)" />
<CopyFileToFolders Include="$(GraphingEngineDll)" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
#include "Utils.h"
namespace GraphControl
{
public
ref class Variable sealed
{
public:
PROPERTY_RW(double, Value);
PROPERTY_RW(double, Step);
PROPERTY_RW(double, Min);
PROPERTY_RW(double, Max);
Variable(double value)
: m_Value{ value }
, m_Step{ 0.1 }
, m_Min{ 0.0 }
, m_Max{ 2.0 }
{
}
};
}