Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions client-api/C++/examples/all_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ int main()

VIBES_TEST( vibes::axisAuto() );
// VIBES_TEST( vibes::axisLimits(-1,1, -3,2) );
VIBES_TEST( vibes::axisEqual() );

VIBES_TEST( vibes::saveImage("vibes_test.png") );
VIBES_TEST( vibes::saveImage("vibes_test.jpg") );
Expand Down
8 changes: 8 additions & 0 deletions client-api/C++/src/vibes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ namespace vibes
setFigureProperty(figureName.empty()?current_fig:figureName, "viewbox", "auto");
}

//>[#144]
void axisEqual(const std::string &figureName)
{
beginDrawingIfNeeded();
setFigureProperty(figureName.empty()?current_fig:figureName, "viewbox", "equal");
}
//<[#144]

void axisLimits(const double &x_lb, const double &x_ub, const double &y_lb, const double &y_ub, const std::string &figureName)
{
beginDrawingIfNeeded();
Expand Down
3 changes: 3 additions & 0 deletions client-api/C++/src/vibes.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ namespace vibes {
/// Set axes limits to the bounding box of the drawing
void axisAuto(const std::string &figureName = std::string());

/// Set axis equal aspect ratio to the bounding box of the drawing [#144]
void axisEqual(const std::string &figureName = std::string());

/// Specify the rectangle to be displayed: Lower-left corner (\a x_lb, \a y_lb) and a upper-right corner (\a x_ub, \a y_ub).
void axisLimits(const double &x_lb, const double &x_ub, const double &y_lb, const double &y_ub, const std::string &figureName = std::string());

Expand Down
4 changes: 2 additions & 2 deletions viewer/vibesgraphicsitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ bool VibesGraphicsItem::parseJson(QJsonObject &json)
json.remove("format");
}

//>[VBS_VR_000002]
//>[#142]
// Hexadecimal/Short color name -> Qt Predefined color name
// for group color names
if (this->_qGraphicsItem->type() == VibesGraphicsGroupType){
Expand All @@ -297,7 +297,7 @@ bool VibesGraphicsItem::parseJson(QJsonObject &json)
}
}
}
//<[VBS_VR_000002]
//<[#142]

// Process object name
if (json.contains("name") && json["name"].isString())
Expand Down
4 changes: 2 additions & 2 deletions viewer/vibesgraphicsitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class VibesDefaults {
return std::max(0.,width.toDouble());
}

//>[VBS_VR_000002]
//>[#142]
// Hexadecimal/Short color name -> Qt Predefined color name
bool toPredefinedColorName(QString &color){

Expand Down Expand Up @@ -83,7 +83,7 @@ class VibesDefaults {

return true;
}
//<[VBS_VR_000002]
//<[#142]

const QBrush brush(const QString & name = QString()) {
if( !_brushes.contains(name)){
Expand Down
16 changes: 12 additions & 4 deletions viewer/vibeswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,18 @@ VibesWindow::processMessage(const QByteArray &msg_data)
QRectF sceneSize=fig->sceneRect();
qreal x, y, w, h;
sceneSize.getRect(&x,&y,&w,&h);
qreal a = std::max(h,w);
x += (w-a)/2;
y += (h-a)/2;
fig->setSceneRect(x,y,a,a);

//>[#144]
qreal u=x+w/2.0, v=y+h/2.0;
qreal m=static_cast<qreal>(fig->width());
qreal n=static_cast<qreal>(fig->height());
qreal cw = h/n*m;
qreal ch = w/m*n;
if(cw>w){ w=cw; x=u-w/2.0; }
else { h=ch; y=v-h/2.0; }
fig->setSceneRect(x,y,w,h);
//<[#144]

fig->fitInView(fig->sceneRect());
}

Expand Down