Skip to content

Commit

Permalink
Refactor slider parameters to variableValue; Add slider parameters to…
Browse files Browse the repository at this point in the history
… summary tab. For feature #256.
  • Loading branch information
highperformancecoder committed Dec 27, 2024
1 parent 2afa39f commit 2c5b385
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 65 deletions.
10 changes: 5 additions & 5 deletions engine/mdlReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,15 @@ namespace minsky
vector<string> spec;
for (size_t i=1; i<=match.size(); ++i) spec.push_back(match[i]);
if (!spec.empty() && regex_match(spec[0],match,number))
v->sliderMin=stod(spec[0]);
v->sliderMin(stod(spec[0]));
else
v->sliderMin=0.1*stod(definition);
v->sliderMin(0.1*stod(definition));
if (spec.size()>1 && regex_match(spec[1],match,number))
v->sliderMax=stod(spec[1]);
v->sliderMax(stod(spec[1]));
else
v->sliderMax=10*stod(definition);
v->sliderMax(10*stod(definition));
if (spec.size()>2 && regex_match(spec[2],match,number))
v->sliderStep=stod(spec[2]);
v->sliderStep(stod(spec[2]));
v->adjustSliderBounds();
}
else
Expand Down
1 change: 1 addition & 0 deletions engine/variableSummary.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace minsky
std::string definition; ///< LaTeXable definition
std::string udfDefinition; ///< use function compatible definition
std::string init; ///< initial value
double sliderStep, sliderMin, sliderMax; ///< slider parameters
double value=nan(""); ///< value, if scalar
std::string scope; ///< name, id of scope if local, ":" if global
std::string godley; ///< name or id of Godley table, if contained in a Godley table
Expand Down
2 changes: 2 additions & 0 deletions engine/variableValue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "index.rcd"
#include "index.xcd"
#include "nobble.h"
#include "slider.rcd"
#include "tensorInterface.rcd"
#include "tensorInterface.xcd"
#include "tensorVal.rcd"
Expand Down Expand Up @@ -533,6 +534,7 @@ namespace minsky
definition,
udfDefinition,
init(),
sliderStep, sliderMin, sliderMax,
value(),
scopeName,
godleyName,
Expand Down
2 changes: 1 addition & 1 deletion engine/variableValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace minsky
typedef std::shared_ptr<Group> GroupPtr;
using namespace civita;

struct VariableValueData: public civita::ITensorVal
struct VariableValueData: public civita::ITensorVal, public Slider
{
using ITensorVal::operator=;

Expand Down
18 changes: 12 additions & 6 deletions gui-js/libs/shared/src/lib/backend/minsky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class VariableBase extends Item {
async drawSelected(a1: minsky__dummy): Promise<void> {return this.$callMethod('drawSelected',a1);}
async dummyDraw(): Promise<void> {return this.$callMethod('dummyDraw');}
async editorMode(): Promise<boolean> {return this.$callMethod('editorMode');}
async enableSlider(...args: boolean[]): Promise<boolean> {return this.$callMethod('enableSlider',...args);}
async enableSlider(...args: any[]): Promise<boolean> {return this.$callMethod('enableSlider',...args);}
async engExp(): Promise<object> {return this.$callMethod('engExp');}
async ensureBBValid(): Promise<void> {return this.$callMethod('ensureBBValid');}
async ensureValueExists(a1: VariableValue,a2: string): Promise<void> {return this.$callMethod('ensureValueExists',a1,a2);}
Expand Down Expand Up @@ -293,12 +293,12 @@ export class VariableBase extends Item {
async selected(...args: boolean[]): Promise<boolean> {return this.$callMethod('selected',...args);}
async setDimLabelsPicked(a1: string,a2: string): Promise<object> {return this.$callMethod('setDimLabelsPicked',a1,a2);}
async setUnits(a1: string): Promise<void> {return this.$callMethod('setUnits',a1);}
async sliderBoundsSet(...args: boolean[]): Promise<boolean> {return this.$callMethod('sliderBoundsSet',...args);}
async sliderMax(...args: number[]): Promise<number> {return this.$callMethod('sliderMax',...args);}
async sliderMin(...args: number[]): Promise<number> {return this.$callMethod('sliderMin',...args);}
async sliderBoundsSet(...args: any[]): Promise<boolean> {return this.$callMethod('sliderBoundsSet',...args);}
async sliderMax(...args: any[]): Promise<number> {return this.$callMethod('sliderMax',...args);}
async sliderMin(...args: any[]): Promise<number> {return this.$callMethod('sliderMin',...args);}
async sliderSet(a1: number): Promise<void> {return this.$callMethod('sliderSet',a1);}
async sliderStep(...args: number[]): Promise<number> {return this.$callMethod('sliderStep',...args);}
async sliderStepRel(...args: boolean[]): Promise<boolean> {return this.$callMethod('sliderStepRel',...args);}
async sliderStep(...args: any[]): Promise<number> {return this.$callMethod('sliderStep',...args);}
async sliderStepRel(...args: any[]): Promise<boolean> {return this.$callMethod('sliderStepRel',...args);}
async sliderVisible(): Promise<boolean> {return this.$callMethod('sliderVisible');}
async temp(): Promise<boolean> {return this.$callMethod('temp');}
async throw_error(a1: string): Promise<void> {return this.$callMethod('throw_error',a1);}
Expand Down Expand Up @@ -2289,6 +2289,7 @@ export class VariableValue extends CppClass {
async cancel(a1: boolean): Promise<void> {return this.$callMethod('cancel',a1);}
async data(): Promise<number[]> {return this.$callMethod('data');}
async detailedText(...args: string[]): Promise<string> {return this.$callMethod('detailedText',...args);}
async enableSlider(...args: boolean[]): Promise<boolean> {return this.$callMethod('enableSlider',...args);}
async end(): Promise<number> {return this.$callMethod('end');}
async exportAsCSV(a1: string,a2: string,a3: boolean): Promise<void> {return this.$callMethod('exportAsCSV',a1,a2,a3);}
async godleyOverridden(...args: boolean[]): Promise<boolean> {return this.$callMethod('godleyOverridden',...args);}
Expand All @@ -2310,6 +2311,11 @@ export class VariableValue extends CppClass {
async setValue(...args: any[]): Promise<number> {return this.$callMethod('setValue',...args);}
async shape(): Promise<number[]> {return this.$callMethod('shape');}
async size(): Promise<number> {return this.$callMethod('size');}
async sliderBoundsSet(...args: boolean[]): Promise<boolean> {return this.$callMethod('sliderBoundsSet',...args);}
async sliderMax(...args: number[]): Promise<number> {return this.$callMethod('sliderMax',...args);}
async sliderMin(...args: number[]): Promise<number> {return this.$callMethod('sliderMin',...args);}
async sliderStep(...args: number[]): Promise<number> {return this.$callMethod('sliderStep',...args);}
async sliderStepRel(...args: boolean[]): Promise<boolean> {return this.$callMethod('sliderStepRel',...args);}
async sliderVisible(...args: boolean[]): Promise<boolean> {return this.$callMethod('sliderVisible',...args);}
async summary(): Promise<object> {return this.$callMethod('summary');}
async temp(): Promise<boolean> {return this.$callMethod('temp');}
Expand Down
73 changes: 62 additions & 11 deletions gui-js/libs/ui-components/src/lib/summary/summary.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
<div class="data-cell">Name</div>
<div class="data-cell extra-wide">Definition</div>
<div class="data-cell wide">Dimensions</div>
<div class="data-cell numeric">Initial</div>
<div class="data-cell wide">Units</div>
<div class="data-cell numeric">Initial</div>
<div *ngIf="type=='parameter'" class="data-cell numeric">Step</div>
<div *ngIf="type=='parameter'" class="data-cell numeric">Min</div>
<div *ngIf="type=='parameter'" class="data-cell numeric">Max</div>
<div class="data-cell numeric">Value</div>
</div>

Expand Down Expand Up @@ -57,6 +60,22 @@
{{variable.dimensions.toString()}}
</div>

<div *ngIf="!editing(variable,'units')"
[title]="variable.units"
(click)="edit($event,variable,'units')"
class="data-cell wide" latex
equation="{{variable.units}}"
>
</div>
<div
*ngIf="editing(variable,'units')"
class="data-cell wide">
<input
(keydown.Enter)="finishEditing()"
(click)="$event.stopImmediatePropagation()"
type="text" [(ngModel)]="editCellContents"/>
</div>

<div *ngIf="!editing(variable,'init')"
[title]="variable.init"
(click)="edit($event,variable,'init')"
Expand All @@ -65,35 +84,67 @@
>
</div>
<div *ngIf="editing(variable,'init')"
class="data-cell numeric">
class="data-cell">
<input
(keydown.Enter)="finishEditing()"
(click)="$event.stopImmediatePropagation()"
type="text" [(ngModel)]="editCellContents"/>
</div>

<div *ngIf="!editing(variable,'units')"
[title]="variable.units"
(click)="edit($event,variable,'units')"
class="data-cell wide" latex
equation="{{variable.units}}"
<div *ngIf="type=='parameter' && !editing(variable,'sliderStep')"
[title]="variable.sliderStep"
(click)="edit($event,variable,'sliderStep')"
class="data-cell numeric" latex
equation="{{truncateValue(variable.sliderStep)}}"
>
</div>
<div
*ngIf="editing(variable,'units')"
class="data-cell wide">
<div *ngIf="type=='parameter' && editing(variable,'sliderStep')"
class="data-cell">
<input
(keydown.Enter)="finishEditing()"
(click)="$event.stopImmediatePropagation()"
type="text" [(ngModel)]="editCellContents"/>
</div>


<div *ngIf="type=='parameter' && !editing(variable,'sliderMin')"
[title]="variable.sliderMin"
(click)="edit($event,variable,'sliderMin')"
class="data-cell numeric" latex
equation="{{truncateValue(variable.sliderMin)}}"
>
</div>
<div *ngIf="type=='parameter' && editing(variable,'sliderMin')"
class="data-cell">
<input
(keydown.Enter)="finishEditing()"
(click)="$event.stopImmediatePropagation()"
type="text" [(ngModel)]="editCellContents"/>
</div>

<div *ngIf="type=='parameter' && !editing(variable,'sliderMax')"
[title]="variable.sliderMax"
(click)="edit($event,variable,'sliderMax')"
class="data-cell numeric" latex
equation="{{truncateValue(variable.sliderMax)}}"
>
</div>
<div *ngIf="type=='parameter' && editing(variable,'sliderMax')"
class="data-cell">
<input
(keydown.Enter)="finishEditing()"
(click)="$event.stopImmediatePropagation()"
type="text" [(ngModel)]="editCellContents"/>
</div>

<div *ngIf="!variable.dimensions.length"
[title]="variable.value" class="data-cell numeric"
latex
equation="{{truncateValue(variable.value)}}"
>
</div>



</div>
</div>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ export class SummaryComponent implements OnInit {
case 'init':
this.electronService.minsky.variableValues.elem(this.editRow.valueId).init(this.editCellContents);
break;
case 'sliderMin':
this.electronService.minsky.variableValues.elem(this.editRow.valueId).sliderMin(+this.editCellContents);
break;
case 'sliderMax':
this.electronService.minsky.variableValues.elem(this.editRow.valueId).sliderMax(+this.editCellContents);
break;
case 'sliderStep':
this.electronService.minsky.variableValues.elem(this.editRow.valueId).sliderStep(+this.editCellContents);
break;
case 'units':
this.electronService.minsky.variableValues.elem(this.editRow.valueId).setUnits(this.editCellContents);
break;
Expand Down
4 changes: 2 additions & 2 deletions model/cairoItems.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ bool RenderVariable::inImage(float x, float y)

double RenderVariable::handlePos() const
{
if (var.sliderStep<std::numeric_limits<double>::min() || std::isnan(var.sliderStep)) var.initSliderBounds(); // this should only be used when sliderStep's value has not been set or is a nonsensicl
if (var.sliderStep()<std::numeric_limits<double>::min() || std::isnan(var.sliderStep())) var.initSliderBounds(); // this should only be used when sliderStep's value has not been set or is a nonsensicl
var.adjustSliderBounds();
return (w<0.5*var.iWidth()? 0.5*var.iWidth() : w)*(var.value()-0.5*(var.sliderMin+var.sliderMax))/(var.sliderMax-var.sliderMin);
return (w<0.5*var.iWidth()? 0.5*var.iWidth() : w)*(var.value()-0.5*(var.sliderMin()+var.sliderMax()))/(var.sliderMax()-var.sliderMin());
}

void minsky::drawTriangle
Expand Down
2 changes: 1 addition & 1 deletion model/minsky.cc
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ namespace minsky
else if (auto v=(*i)->variableCast())
{ //determine whether a slider should be shown
if (auto vv=v->vValue())
vv->sliderVisible = v->enableSlider &&
vv->sliderVisible = v->enableSlider() &&
(v->type()==VariableType::parameter || (v->type()==VariableType::flow && !inputWired(v->valueId())));
v->resetMiniPlot();
}
Expand Down
Loading

0 comments on commit 2c5b385

Please sign in to comment.