Skip to content

Commit

Permalink
visibility title and labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelson-numerical-software committed Nov 13, 2023
1 parent f3120f6 commit 9493d45
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 63 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- function_handle parenthese precedence.
- [#997](http://github.com/Nelson-numerical-software/nelson/issues/997) Macos BigSur Github CI support removed.
- `patch` and `fill` manages `FaceAlpha`.
- visibility title and labels.

## 0.7.10 (2023-10-27)

Expand Down
3 changes: 2 additions & 1 deletion modules/graphics/functions/subplot.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
m = 1;
n = 1;
p = 1;
ax = [];
if ((nargin == 2) && ischar(varargin{1}))
if (strcmp(lower(varargin{1}), 'position'))
ax = axes('OuterPosition', varargin{2});
Expand Down Expand Up @@ -74,7 +75,7 @@
end
children(childrenToDelete) = [];
fig.Children = children;
if (~found)
if (~found || isempty(ax))
ax = axes('OuterPosition', position, 'LineStyleOrder', '-');
end
fig.NextPlot = 'add';
Expand Down
3 changes: 2 additions & 1 deletion modules/graphics/functions/text.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@
rmfield(inputAsStruct, 'Parent');
end
inputArguments = reshape([fieldnames(inputAsStruct)'; struct2cell(inputAsStruct)'], 1, []);
visibility = parent.Visible;
H = [];
for (i=1:numel(x))
H = [H, __text__('Parent', parent, 'Position', [x(i), y(i), z(i)], 'String', labelArray{i}, inputArguments{1:end})];
H = [H, __text__('Parent', parent, 'Visible', visibility, 'Position', [x(i), y(i), z(i)], 'String', labelArray{i}, inputArguments{1:end})];
end
if (nargout == 1)
varargout{1} = H;
Expand Down
2 changes: 2 additions & 0 deletions modules/graphics/functions/xlabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
else
ax = gca();
end
visibility = ax.Visible;
h = __text__('String', inputArguments{1}, ...
'Parent', ax, ...
'HorizontalAlignment', 'center', ...
'VerticalAlignment', 'middle', ...
'AutoParent', 'off', ...
'Visible', visibility, ...
inputArguments{2:end});
ax.XLabel = h;
if nargout == 1
Expand Down
2 changes: 2 additions & 0 deletions modules/graphics/functions/ylabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
else
ax = gca();
end
visibility = ax.Visible;
h = __text__('String', inputArguments{1}, ...
'Parent', ax, ...
'HorizontalAlignment', 'center', ...
'VerticalAlignment', 'middle', ...
'AutoParent', 'off', ...
'Visible', visibility, ...
inputArguments{2:end});
ax.YLabel = h;
if nargout == 1
Expand Down
2 changes: 2 additions & 0 deletions modules/graphics/functions/zlabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
else
ax = gca();
end
visibility = ax.Visible;
h = __text__('String', inputArguments{1}, ...
'Parent', ax, ...
'HorizontalAlignment', 'center', ...
'VerticalAlignment', 'middle', ...
'AutoParent', 'off', ...
'Visible', visibility, ...
inputArguments{2:end});
ax.ZLabel = h;
if nargout == 1
Expand Down
185 changes: 131 additions & 54 deletions modules/graphics/src/cpp/GOAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const int MAX_MINI_TICK_COUNT = 10;
std::wstring
GOAxis::getType()
{
return L"axes";
return GO_PROPERTY_VALUE_AXES_STR;
}
//=============================================================================
void
Expand Down Expand Up @@ -1173,10 +1173,10 @@ GOAxis::rePackFigure()
outerpos[0] / width, outerpos[1] / height, outerpos[2] / width, outerpos[3] / height);
return;
}
double posx0 = outerpos[2] * 0.1 + outerpos[0];
double posy0 = outerpos[3] * 0.1 + outerpos[1];
double poswidth = outerpos[2] * 0.8;
double posheight = outerpos[3] * .8;
double posx0 = outerpos[2] * 0.13 + outerpos[0];
double posy0 = outerpos[3] * 0.11 + outerpos[1];
double poswidth = outerpos[2] * 0.775;
double posheight = outerpos[3] * 0.815;
maxLabelHeight = (int)(maxLabelHeight * 2.0 + tickHeight);
if (posx0 < maxLabelHeight) {
posx0 = maxLabelHeight;
Expand All @@ -1192,8 +1192,8 @@ GOAxis::rePackFigure()
}
GOFourVectorProperty* hp
= static_cast<GOFourVectorProperty*>(findProperty(GO_POSITION_PROPERTY_NAME_STR));
hp->value((double)(posx0 / width), double(posy0 / height), double(poswidth / width),
double(posheight / height));
hp->value((double)(posx0) / double(width), double(posy0) / double(height),
double(poswidth) / double(width), double(posheight) / double(height));
hp->clearModified();
}
//=============================================================================
Expand Down Expand Up @@ -1277,16 +1277,16 @@ GOAxis::updateLimits(bool x, bool y, bool z, bool a, bool c)
return;
}
if (limits[1] == limits[0]) {
limits[0] = limits[0] - 0.5;
limits[1] = limits[0] + 1;
limits[0] = limits[0] - 1;
limits[1] = limits[0] + 1.9;
}
if (limits[3] == limits[2]) {
limits[2] = limits[2] - 0.5;
limits[3] = limits[2] + 1;
limits[2] = limits[2] - 1;
limits[3] = limits[2] + 1.9;
}
if (limits[5] == limits[4]) {
limits[4] = limits[4] - 0.5;
limits[5] = limits[4] + 1;
limits[4] = limits[4] - 1;
limits[5] = limits[4] + 1.9;
}
hp->value(limits[0], limits[1], limits[2], limits[3], limits[4], limits[5]);
if (x) {
Expand Down Expand Up @@ -1433,43 +1433,45 @@ GOAxis::drawTickLabels(RenderInterface& gc, const std::vector<double>& color, do
if (norm > 0) {
delx /= norm;
dely /= norm;
for (int i = 0; i < minortics.size(); i++) {
double t = minortics[i];
double x1, y1, x2, y2;
gc.toPixels(t * unitx + px1, t * unity + py1, t * unitz + pz1, x1, y1);
x2 = delx * ticlen * ticdir * 0.6 + x1;
y2 = dely * ticlen * ticdir * 0.6 + y1;
gc.setupDirectDraw();
gc.line(x1, y1, x2, y2);
gc.releaseDirectDraw();
}
for (int i = 0; i < maptics.size(); i++) {
double t = maptics[i];
double x1, y1, x2, y2;
gc.toPixels(t * unitx + px1, t * unity + py1, t * unitz + pz1, x1, y1);
x2 = delx * ticlen * ticdir + x1;
y2 = dely * ticlen * ticdir + y1;
gc.setupDirectDraw();
gc.line(x1, y1, x2, y2);
gc.releaseDirectDraw();
double x3, y3;
if (ticdir > 0) {
x3 = -delx * 0.015 * norm + x1;
y3 = -dely * 0.015 * norm + y1;
} else {
x3 = -delx * 0.015 * norm + x2;
y3 = -dely * 0.015 * norm + y2;
}
if (!labels.empty()) {
drawLabel(gc, -delx, -dely, x3, y3, color, labels[i % labels.size()]);
if (stringCheck(GO_VISIBLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_ON_STR)) {
for (int i = 0; i < minortics.size(); i++) {
double t = minortics[i];
double x1, y1, x2, y2;
gc.toPixels(t * unitx + px1, t * unity + py1, t * unitz + pz1, x1, y1);
x2 = delx * ticlen * ticdir * 0.6 + x1;
y2 = dely * ticlen * ticdir * 0.6 + y1;
gc.setupDirectDraw();
gc.line(x1, y1, x2, y2);
gc.releaseDirectDraw();
}
if (is2DView()) {
gc.toPixels(t * unitx + px2, t * unity + py2, t * unitz + pz2, x1, y1);
x2 = -delx * ticlen * ticdir + x1;
y2 = -dely * ticlen * ticdir + y1;
for (int i = 0; i < maptics.size(); i++) {
double t = maptics[i];
double x1, y1, x2, y2;
gc.toPixels(t * unitx + px1, t * unity + py1, t * unitz + pz1, x1, y1);
x2 = delx * ticlen * ticdir + x1;
y2 = dely * ticlen * ticdir + y1;
gc.setupDirectDraw();
gc.line(x1, y1, x2, y2);
gc.releaseDirectDraw();
double x3, y3;
if (ticdir > 0) {
x3 = -delx * 0.015 * norm + x1;
y3 = -dely * 0.015 * norm + y1;
} else {
x3 = -delx * 0.015 * norm + x2;
y3 = -dely * 0.015 * norm + y2;
}
if (!labels.empty()) {
drawLabel(gc, -delx, -dely, x3, y3, color, labels[i % labels.size()]);
}
if (is2DView()) {
gc.toPixels(t * unitx + px2, t * unity + py2, t * unitz + pz2, x1, y1);
x2 = -delx * ticlen * ticdir + x1;
y2 = -dely * ticlen * ticdir + y1;
gc.setupDirectDraw();
gc.line(x1, y1, x2, y2);
gc.releaseDirectDraw();
}
}
}
double maxx, maxy;
Expand Down Expand Up @@ -1497,6 +1499,7 @@ GOAxis::drawTickLabels(RenderInterface& gc, const std::vector<double>& color, do
} else {
ly = 1e10;
}

double lmax = std::min(lx, ly);
GOGObjectsProperty* lbl = static_cast<GOGObjectsProperty*>(findProperty(labelname));
if (!lbl->data().empty()) {
Expand Down Expand Up @@ -1578,30 +1581,53 @@ GOAxis::drawAxisLabels(RenderInterface& gc)
lbl = static_cast<GOGObjectsProperty*>(findProperty(GO_X_LABEL_PROPERTY_NAME_STR));
if (!lbl->data().empty()) {
GraphicsObject* fp = findGraphicsObject(lbl->data()[0]);
fp->paintMe(gc);
GOOnOffProperty* fv = static_cast<GOOnOffProperty*>(
fp->findProperty(GO_VISIBLE_PROPERTY_NAME_STR, false));
if (fv) {
if (fv->data() == GO_PROPERTY_VALUE_ON_STR) {
fp->paintMe(gc);
}
}
}
}
if (yvisible) {
lbl = static_cast<GOGObjectsProperty*>(findProperty(GO_Y_LABEL_PROPERTY_NAME_STR));
if (!lbl->data().empty()) {
GraphicsObject* fp = findGraphicsObject(lbl->data()[0]);
fp->paintMe(gc);
GOOnOffProperty* fv = static_cast<GOOnOffProperty*>(
fp->findProperty(GO_VISIBLE_PROPERTY_NAME_STR, false));
if (fv) {
if (fv->data() == GO_PROPERTY_VALUE_ON_STR) {
fp->paintMe(gc);
}
}
}
}
if (zvisible) {
lbl = static_cast<GOGObjectsProperty*>(findProperty(GO_Z_LABEL_PROPERTY_NAME_STR));
if (!lbl->data().empty()) {
GraphicsObject* fp = findGraphicsObject(lbl->data()[0], false);
if (fp) {
fp->paintMe(gc);
GraphicsObject* fp = findGraphicsObject(lbl->data()[0]);
GOOnOffProperty* fv = static_cast<GOOnOffProperty*>(
fp->findProperty(GO_VISIBLE_PROPERTY_NAME_STR, false));
if (fv) {
if (fv->data() == GO_PROPERTY_VALUE_ON_STR) {
fp->paintMe(gc);
}
}
}
}
lbl = static_cast<GOGObjectsProperty*>(findProperty(GO_TITLE_PROPERTY_NAME_STR));
if (!lbl->data().empty()) {
GraphicsObject* fp = findGraphicsObject(lbl->data()[0], false);
if (fp) {
fp->paintMe(gc);
GraphicsObject* fp = findGraphicsObject(lbl->data()[0]);
GOOnOffProperty* fv = static_cast<GOOnOffProperty*>(
fp->findProperty(GO_VISIBLE_PROPERTY_NAME_STR, false));
if (fv) {
if (fv->data() == GO_PROPERTY_VALUE_ON_STR) {
fp->paintMe(gc);
}
}
}
}
setupProjection(gc);
Expand Down Expand Up @@ -1879,6 +1905,57 @@ GOAxis::updateState()
fp->updateState();
}

if (hasChanged(GO_VISIBLE_PROPERTY_NAME_STR)) {
bool isVisible = stringCheck(GO_VISIBLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_ON_STR);

GOGObjectsProperty* lbl;
if (xvisible) {
lbl = static_cast<GOGObjectsProperty*>(findProperty(GO_X_LABEL_PROPERTY_NAME_STR));
if (!lbl->data().empty()) {
GraphicsObject* fp = findGraphicsObject(lbl->data()[0]);
GOOnOffProperty* fv = static_cast<GOOnOffProperty*>(
fp->findProperty(GO_VISIBLE_PROPERTY_NAME_STR, false));
if (fv) {
fv->data(isVisible ? GO_PROPERTY_VALUE_ON_STR : GO_PROPERTY_VALUE_OFF_STR);
}
}
}
if (yvisible) {
lbl = static_cast<GOGObjectsProperty*>(findProperty(GO_Y_LABEL_PROPERTY_NAME_STR));
if (!lbl->data().empty()) {
GraphicsObject* fp = findGraphicsObject(lbl->data()[0]);
GOOnOffProperty* fv = static_cast<GOOnOffProperty*>(
fp->findProperty(GO_VISIBLE_PROPERTY_NAME_STR, false));
if (fv) {
fv->data(isVisible ? GO_PROPERTY_VALUE_ON_STR : GO_PROPERTY_VALUE_OFF_STR);
}
}
}
if (zvisible) {
lbl = static_cast<GOGObjectsProperty*>(findProperty(GO_Z_LABEL_PROPERTY_NAME_STR));
if (!lbl->data().empty()) {
GraphicsObject* fp = findGraphicsObject(lbl->data()[0]);
GOOnOffProperty* fv = static_cast<GOOnOffProperty*>(
fp->findProperty(GO_VISIBLE_PROPERTY_NAME_STR, false));
if (fv) {
fv->data(isVisible ? GO_PROPERTY_VALUE_ON_STR : GO_PROPERTY_VALUE_OFF_STR);
}
}
}
lbl = static_cast<GOGObjectsProperty*>(findProperty(GO_TITLE_PROPERTY_NAME_STR));
if (!lbl->data().empty()) {
GraphicsObject* fp = findGraphicsObject(lbl->data()[0], false);
if (!lbl->data().empty()) {
GraphicsObject* fp = findGraphicsObject(lbl->data()[0]);
GOOnOffProperty* fv = static_cast<GOOnOffProperty*>(
fp->findProperty(GO_VISIBLE_PROPERTY_NAME_STR, false));
if (fv) {
fv->data(isVisible ? GO_PROPERTY_VALUE_ON_STR : GO_PROPERTY_VALUE_OFF_STR);
}
}
}
}

rePackFigure();
recalculateTicks();
rePackFigure();
Expand Down Expand Up @@ -1915,9 +1992,9 @@ GOAxis::paintMe(RenderInterface& gc)

if (stringCheck(GO_VISIBLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_ON_STR)) {
drawAxisLines(gc);
drawTickMarks(gc);
drawAxisLabels(gc);
}
drawTickMarks(gc);
drawAxisLabels(gc);
}
//=============================================================================
bool
Expand Down
4 changes: 2 additions & 2 deletions modules/graphics/src/cpp/GOFigure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ GOFigure::getType()
//=============================================================================
GOFigure::GOFigure(GOWindow* win, int number)
{
m_width = 640;
m_height = 480;
m_width = 560;
m_height = 445;
m_win = win;
registerProperties();
initializeProperties();
Expand Down
7 changes: 4 additions & 3 deletions modules/graphics/src/cpp/GOFixedVectorProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ GOFixedVectorProperty::set(ArrayOf num)
GOGenericProperty::set(num);
num.promoteType(NLS_DOUBLE);
const double* dp = (const double*)num.getDataPointer();
_data.clear();
indexType minLen = std::min((indexType)m_len, num.getElementCount());
_data.reserve(minLen);
for (indexType i = 0; i < minLen; i++) {
_data.push_back(dp[i]);
_data[i] = dp[i];
}
for (indexType i = minLen; i < m_len; i++) {
_data[i] = 0;
}
}
//=============================================================================
Expand Down
2 changes: 1 addition & 1 deletion modules/graphics/src/cpp/GOWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ GOWindow::GOWindow(int64 ahandle) : QMainWindow()
#ifdef _MSC_VER
forceWindowsTitleBarToDark(this->winId());
#endif
resize(600, 400);
createActions();
createMenuBar();
resize(560, 445);
initialized = true;
}
//=============================================================================
Expand Down
Loading

0 comments on commit 9493d45

Please sign in to comment.