Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions model/godleyIcon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ namespace minsky
float h=0;
for (auto& v: vars)
{
RenderVariable rv(*v);
h+=2*rv.height();
h+=v->height();
if (h>height) height=h;
float w=2*rv.width();
float w=v->width();
if (w>width) width=w;
}
}
Expand Down Expand Up @@ -173,15 +172,14 @@ namespace minsky

void GodleyIcon::resize(const LassoBox& b)
{
float z=zoomFactor(), iw=this->iWidth(svgRenderer.width()), ih=this->iHeight(svgRenderer.height()), is=scaleFactor();
float minusLeftMargin=iw*z*is, minusBottomMargin=ih*z*is;
float invZ=1.0/this->zoomFactor();
auto bw=abs(b.x0-b.x1), bh=abs(b.y0-b.y1);
if (bw<=leftMargin() || bh<=bottomMargin()) return;
this->iWidth((bw-leftMargin())/(minusLeftMargin));
this->iHeight((bh-bottomMargin())/(minusBottomMargin));
scaleIconForHeight(bh);
update();
moveTo(0.5*(b.x0+b.x1), 0.5*(b.y0+b.y1));
this->iWidth(0.5*(bw-leftMargin())*invZ);
this->iHeight(0.5*(bh-bottomMargin())*invZ);
scaleIcon(bw,bh);
update();
updateBB();
}

Expand Down Expand Up @@ -298,7 +296,7 @@ namespace minsky
flowMargin=0;
accumulateWidthHeight(m_stockVars, stockH, stockMargin);
accumulateWidthHeight(m_flowVars, flowH, flowMargin);
float iw=this->iWidth(), ih=this->iHeight();
float iw=this->iWidth()*this->zoomFactor(), ih=this->iHeight()*this->zoomFactor();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm comparing with the sum of all v->width() or all v->height() with g->iWidth() or g->iHeight(). I added the zoomFactor in item::width() and item::height() for ticket 1204, so I need to multiply iWdith() and iHeight() by the zoomFactor here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a mistake, The fact that v->width() and height() now contain the zoomFactor causes problems, as shown in ticket 1221. I'm reverting it to RenderVariable width() and height() and removing the zoomFactors here.

this->iWidth(max(iw, 1.8f*stockH));
this->iHeight(max(ih, 1.8f*flowH));
}
Expand Down
9 changes: 2 additions & 7 deletions model/godleyIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ namespace minsky
{
/// for placement of bank icon within complex
float flowMargin=0, stockMargin=0;
/// icon scale is adjusted when Godley icon is resized. legacy method.
float m_iconScale=1;
CLASSDESC_ACCESS(GodleyIcon);
friend struct SchemaHelper;

Expand Down Expand Up @@ -78,8 +76,8 @@ namespace minsky
bool variableDisplay=true;
void toggleVariableDisplay() {variableDisplay=!variableDisplay;}

/// scale icon until it's height matches \a h
void scaleIconForHeight(float h) {update(); scaleFactor(scaleFactor()*h/(bottomMargin()+iHeight()*scaleFactor()*zoomFactor()));}
/// scale icon until it's height or width matches \a h or \a w depending on which is minimum
void scaleIcon(float w, float h) {update(); scaleFactor(scaleFactor()*min(w/(leftMargin()+iWidth()*scaleFactor()*zoomFactor()),h/(bottomMargin()+iHeight()*scaleFactor()*zoomFactor())));}

/// left margin of bank icon with Godley icon
float leftMargin() const {return variableDisplay? flowMargin*scaleFactor()*zoomFactor(): 0;}
Expand All @@ -89,9 +87,6 @@ namespace minsky
/// helper for schema1
double schema1ZoomFactor() const;

/// icon scale is adjusted when Godley icon is resized. legacy method.
float iconScale() const {return m_iconScale;};

void resize(const LassoBox&) override;
void removeControlledItems() const override;

Expand Down
12 changes: 1 addition & 11 deletions schema/schema3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,9 @@ namespace schema3
{
std::vector<std::vector<std::string>> data;
std::vector<minsky::GodleyAssetClass::AssetClass> assetClasses;
float iconScale=1;
if (y.data) data=*y.data;
if (y.assetClasses) assetClasses=*y.assetClasses;
if (y.iconScale) iconScale=*y.iconScale;
SchemaHelper::setPrivates(*x1,data,assetClasses,iconScale);
SchemaHelper::setPrivates(*x1,data,assetClasses);
try
{
x1->table.orderAssetClasses();
Expand Down Expand Up @@ -575,15 +573,7 @@ namespace schema3
SchemaHelper::setStockAndFlow(*godley, flowVars, stockVars);
try
{

godley->update();
if (!godley->editorMode())
{
if (i.height)
godley->scaleIconForHeight(*i.height*godley->zoomFactor());
else if (i.iconScale) //legacy schema handling
godley->scaleIconForHeight(*i.iconScale * godley->iHeight());
}
}
catch (...) {} //ignore exceptions: ticket #1045
}
Expand Down
7 changes: 3 additions & 4 deletions schema/schema3.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ namespace schema3
// Godley Icon specific fields
Optional<std::vector<std::vector<std::string>>> data;
Optional<std::vector<minsky::GodleyAssetClass::AssetClass>> assetClasses;
Optional<float> iconScale; // for handling legacy schemas
Optional<bool> editorMode, buttonDisplay, variableDisplay;
// Plot specific fields
Optional<bool> logx, logy, ypercent;
Expand Down Expand Up @@ -142,8 +141,8 @@ namespace schema3
axis(o.axis), arg(o.arg) {}
Item(int id, const minsky::GodleyIcon& g, const std::vector<int>& ports):
ItemBase(id,static_cast<const minsky::Item&>(g),ports),
width(g.iWidth()/g.zoomFactor()), height(g.iHeight()/g.zoomFactor()), name(g.table.title), data(g.table.getData()),
assetClasses(g.table._assetClass()), iconScale(g.iconScale()),
width(g.iWidth()), height(g.iHeight()), name(g.table.title), data(g.table.getData()),
assetClasses(g.table._assetClass()),
editorMode(g.editorMode()),
buttonDisplay(g.buttonDisplay()), variableDisplay(g.variableDisplay) {}
Item(int id, const minsky::PlotWidget& p, const std::vector<int>& ports):
Expand Down Expand Up @@ -175,7 +174,7 @@ namespace schema3
slider(it.slider), intVar(it.intVar), dataOpData(it.dataOpData), filename(it.filename),
ravelState(it.ravelState), lockGroup(it.lockGroup), dimensions(it.dimensions),
axis(it.axis), arg(it.arg), data(it.data), assetClasses(it.assetClasses),
iconScale(it.iconScale), logx(it.logx), logy(it.logy), ypercent(it.ypercent),
logx(it.logx), logy(it.logy), ypercent(it.ypercent),
plotType(minsky::PlotWidget::PlotType(it.plotType? int(*it.plotType): 0)),
xlabel(it.xlabel), ylabel(it.ylabel), y1label(it.y1label),
nxTicks(it.nxTicks), nyTicks(it.nyTicks), xtickAngle(it.xtickAngle),
Expand Down
3 changes: 1 addition & 2 deletions schema/schemaHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ namespace minsky
}
static void setPrivates
(minsky::GodleyIcon& g, const vector<vector<string> >& data,
const vector<GodleyTable::AssetClass>& assetClass,float iconScale)
const vector<GodleyTable::AssetClass>& assetClass)
{
setPrivates(g.table, data, assetClass);
g.m_iconScale=iconScale;
}
Comment on lines 74 to 79

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can now get rid if this helper function too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried this and it caused the variables attached to GodleyIcons to disappear. So, I've left it in.


static void setStockAndFlow(minsky::GodleyIcon& g,
Expand Down
2 changes: 1 addition & 1 deletion test/testModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ SUITE(GodleyIcon)
update();
// TODO - shouldn't be needed, but there is some font problem causing bottomMargin to be calculated incorrectly

scaleIconForHeight(2.5*bottomMargin());
scaleIcon(2.5*bottomMargin(),2.5*leftMargin());
update();
CHECK_EQUAL(1,flowVars().size());
CHECK_EQUAL(1,stockVars().size());
Expand Down