Skip to content

Commit 96174a6

Browse files
x, y and y1 titles are interpreted as LaTeX strings. For #1643.
1 parent d26ffd5 commit 96174a6

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

gui-js/libs/shared/src/lib/backend/minsky.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,10 +1766,10 @@ export class PlotWidget extends Item {
17661766
updateIcon(a1: number): void {return this.callMethod('updateIcon',a1);}
17671767
vectorRender(a1: number,a2: minsky__dummy): object {return this.callMethod('vectorRender',a1,a2);}
17681768
width(): number {return this.callMethod('width');}
1769-
xlabel(...args: string[]): string {return this.callMethod('xlabel',...args);}
1769+
xlabel(...args: any[]): string {return this.callMethod('xlabel',...args);}
17701770
xtickAngle(...args: number[]): number {return this.callMethod('xtickAngle',...args);}
1771-
y1label(...args: string[]): string {return this.callMethod('y1label',...args);}
1772-
ylabel(...args: string[]): string {return this.callMethod('ylabel',...args);}
1771+
y1label(...args: any[]): string {return this.callMethod('y1label',...args);}
1772+
ylabel(...args: any[]): string {return this.callMethod('ylabel',...args);}
17731773
zoom(a1: number,a2: number,a3: number): void {return this.callMethod('zoom',a1,a2,a3);}
17741774
}
17751775

model/plotWidget.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ namespace minsky
8989
double w=iWidth()*z, h=iHeight()*z;
9090

9191
// if any titling, draw an extra bounding box (ticket #285)
92-
if (!title.empty()||!xlabel.empty()||!ylabel.empty()||!y1label.empty())
92+
if (!title.empty()||!xlabel().empty()||!ylabel().empty()||!y1label().empty())
9393
{
9494
cairo_rectangle(cairo,-0.5*w+10,-0.5*h,w-20,h-10);
9595
cairo_set_line_width(cairo,1);
@@ -109,7 +109,7 @@ namespace minsky
109109
pango.setFontSize(fabs(fy));
110110
pango.setMarkup(latexToPango(title));
111111
cairo_set_source_rgb(cairo,0,0,0);
112-
cairo_move_to(cairo,0.5*(w-pango.width()), 0/*pango.height()*/);
112+
cairo_move_to(cairo,0.5*(w-pango.width()), 0);
113113
pango.show();
114114

115115
// allow some room for the title

model/plotWidget.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "renderNativeWindow.h"
2323
#include <TCL_obj_base.h>
2424
#include "classdesc_access.h"
25+
#include "latexMarkup.h"
2526
#include "plot.h"
2627
#include "variable.h"
2728
#include "variableValue.h"
@@ -62,6 +63,10 @@ namespace minsky
6263

6364
bool xIsSecsSinceEpoch=false;
6465
bool redraw(int, int, int, int) override;
66+
67+
// shadow labels, so we can interpret as LaTeX code rather than Pango markup
68+
std::string m_xlabel, m_ylabel, m_y1label;
69+
6570
public:
6671
using Item::x;
6772
using Item::y;
@@ -95,7 +100,24 @@ namespace minsky
95100

96101
const PlotWidget* plotWidgetCast() const override {return this;}
97102
PlotWidget* plotWidgetCast() override {return this;}
98-
103+
104+
/// shadowed label commands to allow latex intepretation
105+
const std::string& xlabel() const {return m_xlabel;}
106+
const std::string& xlabel(const std::string& x) {
107+
ecolab::Plot::xlabel=latexToPangoNonItalicised(x);
108+
return m_xlabel=x;
109+
}
110+
const std::string& ylabel() const {return m_ylabel;}
111+
const std::string& ylabel(const std::string& x) {
112+
ecolab::Plot::ylabel=latexToPangoNonItalicised(x);
113+
return m_ylabel=x;
114+
}
115+
const std::string& y1label() const {return m_y1label;}
116+
const std::string& y1label(const std::string& x) {
117+
ecolab::Plot::y1label=latexToPangoNonItalicised(x);
118+
return m_y1label=x;
119+
}
120+
99121
void addPlotPt(double t); ///< add another plot point
100122
void updateIcon(double t) override {addPlotPt(t);}
101123
/// add vector/tensor curves to plot

schema/schema3.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,9 @@ namespace schema3
495495
if (y.ypercent) x1->percent=*y.ypercent;
496496
if (y.plotTabDisplay) x1->plotTabDisplay=*y.plotTabDisplay;
497497
if (y.plotType) x1->plotType=*y.plotType;
498-
if (y.xlabel) x1->xlabel=*y.xlabel;
499-
if (y.ylabel) x1->ylabel=*y.ylabel;
500-
if (y.y1label) x1->y1label=*y.y1label;
498+
if (y.xlabel) x1->xlabel(*y.xlabel);
499+
if (y.ylabel) x1->ylabel(*y.ylabel);
500+
if (y.y1label) x1->y1label(*y.y1label);
501501
if (y.nxTicks) x1->nxTicks=*y.nxTicks;
502502
if (y.nyTicks) x1->nyTicks=*y.nyTicks;
503503
if (y.xtickAngle) x1->xtickAngle=*y.xtickAngle;

schema/schema3.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ namespace schema3
187187
ItemBase(id,static_cast<const minsky::Item&>(p),ports), name(p.title),
188188
logx(p.logx), logy(p.logy), ypercent(p.percent), plotTabDisplay(p.plotTabDisplay),
189189
plotType(p.plotType),
190-
xlabel(p.xlabel), ylabel(p.ylabel), y1label(p.y1label),
190+
xlabel(p.xlabel()), ylabel(p.ylabel()), y1label(p.y1label()),
191191
nxTicks(p.nxTicks), nyTicks(p.nyTicks), xtickAngle(p.xtickAngle),
192192
exp_threshold(p.exp_threshold), legendGeometry(LegendGeometry(p)), palette(p.palette)
193193
{

0 commit comments

Comments
 (0)