Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Education
Cantor
Commits
9b2f4422
Commit
9b2f4422
authored
Jul 02, 2020
by
Nikita Sirgienko
Browse files
[GSoC 2020][T9475] Support popular Julia plot packages in PlotExtension
parent
8aac1569
Pipeline
#25647
passed with stage
in 18 minutes and 54 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/backends/julia/juliabackend.kcfg
View file @
9b2f4422
...
...
@@ -27,5 +27,15 @@
</choices>
<default>
svg
</default>
</entry>
<entry
name=
"plotExtenstionGraphicPackage"
type=
"Enum"
>
<choices>
<choice
name=
"gr"
/>
<choice
name=
"plots"
/>
<choice
name=
"pyplot"
/>
<choice
name=
"gadfly"
/>
</choices>
<label>
Graphical package, for which will be enable support for embedding plots
</label>
<default>
0
</default>
</entry>
</group>
</kcfg>
src/backends/julia/juliaextensions.cpp
View file @
9b2f4422
...
...
@@ -22,6 +22,8 @@
#include
<QDebug>
#include
<KLocalizedString>
#include
"settings.h"
#include
"juliascriptloading.h"
#define JULIA_EXT_CDTOR(name) Julia##name##Extension::Julia##name##Extension(QObject *parent) : name##Extension(parent) {} \
...
...
@@ -136,26 +138,61 @@ QString JuliaPlotExtension::plotFunction2d(
const
QString
&
left
,
const
QString
&
right
)
{
auto
new_left
=
left
;
auto
new_right
=
right
;
if
(
new_left
.
isEmpty
()
&&
new_right
.
isEmpty
())
{
new_left
=
QLatin1String
(
"-1"
);
new_right
=
QLatin1String
(
"1"
);
}
else
if
(
new_left
.
isEmpty
())
{
new_left
=
QString
::
fromLatin1
(
"(%1) - 1"
).
arg
(
new_right
);
}
else
if
(
new_right
.
isEmpty
())
{
new_right
=
QString
::
fromLatin1
(
"(%1) + 1"
).
arg
(
new_left
);
}
QString
command
;
QString
limits
;
switch
(
JuliaSettings
::
plotExtenstionGraphicPackage
())
{
case
JuliaSettings
::
EnumPlotExtenstionGraphicPackage
::
gr
:
{
if
(
!
left
.
isEmpty
()
&&
!
right
.
isEmpty
())
limits
=
QString
::
fromLatin1
(
"GR.xlim((%1, %2))
\n
"
).
arg
(
left
).
arg
(
right
);
command
=
QString
::
fromLatin1
(
"import GR
\n
"
"
\n
"
"%3"
"GR.plot(%1, %2)"
).
arg
(
variable
).
arg
(
function
).
arg
(
limits
);
break
;
}
auto
xlimits
=
QString
::
fromLatin1
(
"GR.xlim((%1, %2))
\n
"
).
arg
(
new_left
).
arg
(
new_right
);
auto
linspace
=
QString
::
fromLatin1
(
"linspace(%1, %2, 100)"
).
arg
(
new_left
).
arg
(
new_right
);
case
JuliaSettings
::
EnumPlotExtenstionGraphicPackage
::
plots
:
if
(
!
left
.
isEmpty
()
&&
!
right
.
isEmpty
())
limits
=
QString
::
fromLatin1
(
", xlims = (%1, %2)"
).
arg
(
left
).
arg
(
right
);
command
=
QString
::
fromLatin1
(
"import Plots
\n
"
"
\n
"
"Plots.plot(%1, %2%3)"
).
arg
(
variable
,
function
,
limits
);
break
;
case
JuliaSettings
::
EnumPlotExtenstionGraphicPackage
::
pyplot
:
if
(
!
left
.
isEmpty
()
&&
!
right
.
isEmpty
())
limits
=
QString
::
fromLatin1
(
"PyPlot.xlim(%1, %2)
\n
"
).
arg
(
left
).
arg
(
right
);
command
=
QString
::
fromLatin1
(
"import PyPlot
\n
"
"
\n
"
"%3"
"PyPlot.plot(%1, %2)"
).
arg
(
variable
,
function
,
limits
);
break
;
case
JuliaSettings
::
EnumPlotExtenstionGraphicPackage
::
gadfly
:
if
(
!
left
.
isEmpty
()
&&
!
right
.
isEmpty
())
limits
=
QString
::
fromLatin1
(
", Gadfly.Scale.x_continuous(minvalue=%1, maxvalue=%2)"
).
arg
(
left
).
arg
(
right
);
command
=
QString
::
fromLatin1
(
"import Gadfly
\n
"
"
\n
"
"Gadfly.plot(x=%1, y=%2%3)"
).
arg
(
variable
,
function
,
limits
);
break
;
}
return
QString
::
fromLatin1
(
"import GR
\n
"
"%3"
"GR.plot(%1, [%2 for %4 in %1])
\n
"
).
arg
(
linspace
).
arg
(
function
).
arg
(
xlimits
).
arg
(
variable
);
return
command
;
}
QString
JuliaPlotExtension
::
plotFunction3d
(
...
...
@@ -163,41 +200,69 @@ QString JuliaPlotExtension::plotFunction3d(
const
VariableParameter
&
var1
,
const
VariableParameter
&
var2
)
{
QString
command
;
auto
update_interval
=
[](
Interval
&
interval
)
{
if
(
interval
.
first
.
isEmpty
()
&&
interval
.
second
.
isEmpty
())
{
interval
.
first
=
QLatin1String
(
"-1"
);
interval
.
second
=
QLatin1String
(
"1"
);
}
else
if
(
interval
.
first
.
isEmpty
())
{
interval
.
second
=
QString
::
fromLatin1
(
"(%1) + 1"
)
.
arg
(
interval
.
first
);
}
else
if
(
interval
.
second
.
isEmpty
())
{
interval
.
first
=
QString
::
fromLatin1
(
"(%1) - 1"
)
.
arg
(
interval
.
second
);
const
Interval
&
interval1
=
var1
.
second
;
const
Interval
&
interval2
=
var2
.
second
;
QString
interval1Limits
;
QString
interval2Limits
;
switch
(
JuliaSettings
::
plotExtenstionGraphicPackage
())
{
case
JuliaSettings
::
EnumPlotExtenstionGraphicPackage
::
gr
:
{
if
(
!
interval1
.
first
.
isEmpty
()
&&
!
interval1
.
second
.
isEmpty
())
interval1Limits
=
QString
::
fromLatin1
(
"GR.xlim((%1, %2))
\n
"
).
arg
(
interval1
.
first
).
arg
(
interval1
.
second
);
if
(
!
interval2
.
first
.
isEmpty
()
&&
!
interval2
.
second
.
isEmpty
())
interval1Limits
=
QString
::
fromLatin1
(
"GR.ylim((%1, %2))
\n
"
).
arg
(
interval2
.
first
).
arg
(
interval2
.
second
);
command
=
QString
::
fromLatin1
(
"import GR
\n
"
"
\n
"
"%4%5"
"GR.plot3(%1, %2, %3)"
).
arg
(
interval1
.
first
,
interval2
.
first
,
function
,
interval1Limits
,
interval2Limits
);
break
;
}
};
Interval
interval1
=
var1
.
second
;
Interval
interval2
=
var2
.
second
;
update_interval
(
interval1
);
update_interval
(
interval2
);
return
QString
::
fromLatin1
(
"import GR
\n
"
"values = zeros(100, 100)
\n
"
"for p_x in enumerate(linspace(%1, %2, 100))
\n
"
" i, %6 = p_x
\n
"
" for p_y in enumerate(linspace(%3, %4, 100))
\n
"
" j, %7 = p_y
\n
"
" values[i, j] = %5
\n
"
" end
\n
"
"end
\n
"
"GR.surface(linspace(%1, %2, 100), linspace(%3, %4, 100), values)
\n
"
).
arg
(
interval1
.
first
).
arg
(
interval1
.
second
)
.
arg
(
interval2
.
first
).
arg
(
interval2
.
second
)
.
arg
(
function
)
.
arg
(
var1
.
first
).
arg
(
var2
.
first
);
case
JuliaSettings
::
EnumPlotExtenstionGraphicPackage
::
plots
:
if
(
!
interval1
.
first
.
isEmpty
()
&&
!
interval1
.
second
.
isEmpty
())
interval1Limits
=
QString
::
fromLatin1
(
", xlims = (%1, %2)"
).
arg
(
interval1
.
first
).
arg
(
interval1
.
second
);
if
(
!
interval2
.
first
.
isEmpty
()
&&
!
interval2
.
second
.
isEmpty
())
interval1Limits
=
QString
::
fromLatin1
(
", ylims = (%1, %2)"
).
arg
(
interval2
.
first
).
arg
(
interval2
.
second
);
command
=
QString
::
fromLatin1
(
"import Plots
\n
"
"
\n
"
"%4%5"
"GR.plot3d(%1, %2, %3)"
).
arg
(
interval1
.
first
,
interval2
.
first
,
function
,
interval1Limits
,
interval2Limits
);
break
;
case
JuliaSettings
::
EnumPlotExtenstionGraphicPackage
::
pyplot
:
if
(
!
interval1
.
first
.
isEmpty
()
&&
!
interval1
.
second
.
isEmpty
())
interval1Limits
=
QString
::
fromLatin1
(
"GR.xlim((%1, %2))
\n
"
).
arg
(
interval1
.
first
).
arg
(
interval1
.
second
);
if
(
!
interval2
.
first
.
isEmpty
()
&&
!
interval2
.
second
.
isEmpty
())
interval1Limits
=
QString
::
fromLatin1
(
"GR.ylim((%1, %2))
\n
"
).
arg
(
interval2
.
first
).
arg
(
interval2
.
second
);
command
=
QString
::
fromLatin1
(
"import GR
\n
"
"
\n
"
"%4%5"
"PyPlot.plot3D(%1, %2, %3)"
).
arg
(
interval1
.
first
,
interval2
.
first
,
function
,
interval1Limits
,
interval2Limits
);
break
;
case
JuliaSettings
::
EnumPlotExtenstionGraphicPackage
::
gadfly
:
command
=
i18n
(
"# Sorry, but Gadfly don't support 3d plots"
);
break
;
}
return
command
;
}
...
...
src/backends/julia/settings.ui
View file @
9b2f4422
...
...
@@ -7,7 +7,7 @@
<x>
0
</x>
<y>
0
</y>
<width>
609
</width>
<height>
22
2
</height>
<height>
22
7
</height>
</rect>
</property>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout"
>
...
...
@@ -26,29 +26,29 @@
</layout>
</item>
<item>
<widget
class=
"QCheckBox"
name=
"kcfg_
variableManagement
"
>
<widget
class=
"QCheckBox"
name=
"kcfg_
integratePlots
"
>
<property
name=
"toolTip"
>
<string>
Monitor the creation and destruction of variables and show the existing variables in the variable panel
.
</string>
<string>
If enabled, plots will be shown inside of the worksheet. Otherwise, plots will be shown in an external window
.
</string>
</property>
<property
name=
"text"
>
<string>
Enable Variable Managemen
t
</string>
<string>
Integrate Plots in Workshee
t
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QCheckBox"
name=
"kcfg_
integratePlots
"
>
<widget
class=
"QCheckBox"
name=
"kcfg_
variableManagement
"
>
<property
name=
"toolTip"
>
<string>
If enabled, plots will be shown inside of the worksheet. Otherwise, plots will be shown in an external window
.
</string>
<string>
Monitor the creation and destruction of variables and show the existing variables in the variable panel
.
</string>
</property>
<property
name=
"text"
>
<string>
Integrate Plots in Workshee
t
</string>
<string>
Enable Variable Managemen
t
</string>
</property>
</widget>
</item>
<item>
<layout
class=
"QHBoxLayout"
name=
"horizontalLayout
_
2"
>
<layout
class=
"QHBoxLayout"
name=
"horizontalLayout2"
>
<item>
<widget
class=
"QLabel"
name=
"label
_
2"
>
<widget
class=
"QLabel"
name=
"label2"
>
<property
name=
"text"
>
<string>
Inline Plots Intermediate Format:
</string>
</property>
...
...
@@ -73,6 +73,50 @@
</item>
</layout>
</item>
<item>
<layout
class=
"QHBoxLayout"
name=
"horizontalLayout3"
>
<item>
<widget
class=
"QLabel"
name=
"label3"
>
<property
name=
"toolTip"
>
<string>
Graphic package, which code will be used for plotting via
"
Plot
"
Cantor menu.
</string>
</property>
<property
name=
"text"
>
<string>
Preferred package for the
"
Plot
"
menu:
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"KComboBox"
name=
"kcfg_plotExtenstionGraphicPackage"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"Expanding"
vsizetype=
"Fixed"
>
<horstretch>
0
</horstretch>
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<item>
<property
name=
"text"
>
<string>
GR
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
Plots
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
PyPlot
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
Gadfly
</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<spacer
name=
"verticalSpacer1"
>
<property
name=
"orientation"
>
...
...
@@ -89,6 +133,11 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>
KComboBox
</class>
<extends>
QComboBox
</extends>
<header>
kcombobox.h
</header>
</customwidget>
<customwidget>
<class>
KUrlRequester
</class>
<extends>
QFrame
</extends>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment