Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
matefun
Frontend
Commits
62ea701f
Commit
62ea701f
authored
Mar 31, 2019
by
Leonel Rosano Montero
Browse files
Se dividen las funciones discontinuas
parent
ef8ef4f1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Frontend Angular 4/src/app/layout/plotter/graph2D/graph2D.component.ts
View file @
62ea701f
...
@@ -36,6 +36,8 @@ export class Graph2DComponent {
...
@@ -36,6 +36,8 @@ export class Graph2DComponent {
private
id
=
0
;
private
id
=
0
;
private
valores
=
[];
private
conjunto
=
[];
private
conjunto
=
[];
// Animation state
// Animation state
...
@@ -80,22 +82,58 @@ export class Graph2DComponent {
...
@@ -80,22 +82,58 @@ export class Graph2DComponent {
var
conjs
=
this
.
obtenerConjunto
(
jsonCanvas
.
funs
[
0
]);
var
conjs
=
this
.
obtenerConjunto
(
jsonCanvas
.
funs
[
0
]);
var
d
=
conjs
+
"
}
"
;
//Leo
var
d
=
conjs
+
"
}
"
;
//Leo
var
obj
=
JSON
.
parse
(
d
);
var
obj
=
JSON
.
parse
(
d
);
//Para las funciones
//Para las funciones
if
(
obj
.
conj
.
sets
.
fdom
==
"
function(x)
"
)
{
if
(
obj
.
conj
.
sets
.
fdom
==
"
function(x)
"
)
{
var
nom
=
jsonCanvas
.
funs
[
0
].
dom
;
var
nom
=
jsonCanvas
.
funs
[
0
].
dom
;
var
elemento1
=
this
.
recursionfuncion
(
jsonCanvas
.
funs
[
0
].
sets
,
nom
);
var
elemento1
=
this
.
recursionfuncion
(
jsonCanvas
.
funs
[
0
].
sets
,
nom
);
obj
.
conj
.
sets
.
fdom
=
function
(
x
)
{
return
eval
(
elemento1
)
}
var
funcionString
=
''
;
funcionString
=
"
var
"
+
nom
+
"
= function(x){
\n
return
"
+
elemento1
+
"
}
\n
"
funcionString
+=
'
return
'
+
nom
+
'
(x);
\n
'
for
(
var
funs
of
jsonCanvas
.
funs
)
{
funcionString
=
'
var
'
+
funs
.
fun
+
'
= function(
'
+
funs
.
args
+
'
){
\n
return
'
+
this
.
generarExpresion
(
funs
.
bdy
)
+
'
}
\n
'
+
funcionString
;
}
funcionString
=
'
(x)=>{
\n
'
+
funcionString
+
'
}
'
;
console
.
log
(
funcionString
)
obj
.
conj
.
sets
.
fdom
=
eval
(
funcionString
);
}
}
if
(
obj
.
conj
.
sets
.
fcod
==
"
function(x)
"
)
{
if
(
obj
.
conj
.
sets
.
fcod
==
"
function(x)
"
)
{
var
nom
=
jsonCanvas
.
funs
[
0
].
cod
;
var
nom
=
jsonCanvas
.
funs
[
0
].
cod
;
var
elemento2
=
this
.
recursionfuncion
(
jsonCanvas
.
funs
[
0
].
sets
,
nom
);
var
elemento2
=
this
.
recursionfuncion
(
jsonCanvas
.
funs
[
0
].
sets
,
nom
);
obj
.
conj
.
sets
.
fcod
=
function
(
x
)
{
return
(
eval
(
elemento2
))
}
obj
.
conj
.
sets
.
fcod
=
function
(
x
)
{
return
(
eval
(
elemento2
))
}
var
funcionString
=
''
;
funcionString
=
"
var
"
+
nom
+
"
= function(x){
\n
return
"
+
elemento2
+
"
}
\n
"
funcionString
+=
'
return
'
+
nom
+
'
(x);
\n
'
for
(
var
funs
of
jsonCanvas
.
funs
)
{
funcionString
=
'
var
'
+
funs
.
fun
+
'
= function(
'
+
funs
.
args
+
'
){
\n
return
'
+
this
.
generarExpresion
(
funs
.
bdy
)
+
'
}
\n
'
+
funcionString
;
}
funcionString
=
'
(x)=>{
\n
'
+
funcionString
+
'
}
'
;
obj
.
conj
.
sets
.
fdom
=
eval
(
funcionString
);
}
}
var
funcionGenerada
=
this
.
generarFuncion
(
jsonCanvas
);
var
funcionGenerada
=
this
.
generarFuncion
(
jsonCanvas
);
console
.
log
(
obj
)
//para Enumerados
//para Enumerados
if
(
obj
.
conj
.
dom
==
'
Numer
'
)
{
if
(
obj
.
conj
.
dom
==
'
Numer
'
)
{
...
@@ -116,9 +154,11 @@ export class Graph2DComponent {
...
@@ -116,9 +154,11 @@ export class Graph2DComponent {
}
}
let
fun
=
eval
(
funcionGenerada
);
let
fun
=
eval
(
funcionGenerada
);
var
colores
=
[
'
pink
'
,
'
red
'
,
'
blue
'
,
'
orange
'
,
'
green
'
]
var
colores
=
[
'
violet
'
,
'
red
'
,
'
blue
'
,
'
orange
'
,
'
green
'
,
'
black
'
,
''
]
var
num
=
this
.
getRandomArbitrary
(
0
,
4
);
var
num
=
this
.
getRandomArbitrary
(
0
,
4
);
var
color
=
colores
[
num
];
var
color
=
colores
[
num
];
...
@@ -135,18 +175,78 @@ export class Graph2DComponent {
...
@@ -135,18 +175,78 @@ export class Graph2DComponent {
this
.
conjunto
.
push
(
obj
.
conj
);
this
.
conjunto
.
push
(
obj
.
conj
);
this
.
id
=
0
;
this
.
id
=
0
;
this
.
funciones
=
[];
this
.
funciones
=
[];
this
.
funciones
.
push
({
if
(
obj
.
conj
.
baseDom
==
'
R
'
){
id
:
this
.
funciones
.
length
,
this
.
valores
=
[];
sampler
:
'
builtIn
'
,
var
funcionGenerada2
=
this
.
generarFuncionDisc
(
jsonCanvas
);
fn
:
function
(
scope
)
{
return
fun
(
scope
.
x
)
var
funcionesVer2019
=
this
.
createListFunction
(
jsonCanvas
);
},
var
listValores
=
[];
graphType
:
tipoGraf
,
for
(
var
k
of
this
.
valores
){
color
:
color
listValores
.
push
(
parseInt
(
k
))
})
}
for
(
var
i
of
this
.
valores
){
for
(
var
t
of
this
.
valores
){
var
aux
=
parseInt
(
t
);
var
aux2
=
parseInt
(
i
);
var
mul
=
aux
*
aux2
;
listValores
.
push
(
mul
)
}
}
for
(
i
=
-
999
;
i
<
1000
;
i
++
)
{
listValores
.
push
(
i
)
}
let
sinRepetidos
=
listValores
.
filter
((
valor
,
indiceActual
,
arreglo
)
=>
arreglo
.
indexOf
(
valor
)
===
indiceActual
);
for
(
var
fun2
of
funcionesVer2019
){
let
fun3
=
eval
(
fun2
);
var
insertar
=
false
;
var
punto1
=
[];
if
(
sinRepetidos
.
length
){
for
(
var
p
of
sinRepetidos
){
var
pn
=
parseInt
(
p
)
-
0.001
var
pp
=
parseInt
(
p
)
+
0.001
insertar
=
(((
fun3
(
pp
)
!=
undefined
)
)
||
((
fun3
(
pn
)
!=
undefined
))
||
insertar
)
if
((
fun3
(
pp
)
!=
undefined
)){
punto1
.
push
(
pp
);
}
else
if
((
fun3
(
pn
)
!=
undefined
)){
punto1
.
push
(
p
);
}
}
}
else
{
insertar
=
true
;
}
if
(
insertar
){
this
.
funciones
.
push
({
id
:
0
,
sampler
:
'
builtIn
'
,
fn
:
function
(
scope
)
{
return
fun3
(
scope
.
x
)
},
graphType
:
tipoGraf
,
point
:
punto1
[
0
],
color
:
color
,
});
}
}
}
else
{
this
.
funciones
.
push
({
id
:
this
.
funciones
.
length
,
sampler
:
'
builtIn
'
,
fn
:
function
(
scope
)
{
return
fun
(
scope
.
x
)
},
graphType
:
tipoGraf
,
color
:
color
})
}
}
else
{
}
else
{
if
(
this
.
conjunto
.
length
==
1
){
if
(
this
.
conjunto
.
length
==
1
){
this
.
id
=
1
;
this
.
id
=
1
;
this
.
conjunto
.
unshift
({
radio
:
2
,
dom
:
this
.
conjunto
[
0
].
baseDom
,
cod
:
this
.
conjunto
[
0
].
baseCod
,
baseCod
:
this
.
conjunto
[
0
].
baseCod
,
baseDom
:
this
.
conjunto
[
0
].
baseDom
,
sets
:{
fdom
:
this
.
conjunto
[
0
].
baseDom
,
fcod
:
this
.
conjunto
[
0
].
baseCod
}});
this
.
conjunto
.
unshift
({
radio
:
2
,
dom
:
this
.
conjunto
[
0
].
baseDom
,
cod
:
this
.
conjunto
[
0
].
baseCod
,
baseCod
:
this
.
conjunto
[
0
].
baseCod
,
baseDom
:
this
.
conjunto
[
0
].
baseDom
,
sets
:{
fdom
:
this
.
conjunto
[
0
].
baseDom
,
fcod
:
this
.
conjunto
[
0
].
baseCod
}});
this
.
funciones
[
0
].
id
=
this
.
id
;
this
.
funciones
[
0
].
id
=
this
.
id
;
...
@@ -164,9 +264,144 @@ export class Graph2DComponent {
...
@@ -164,9 +264,144 @@ export class Graph2DComponent {
}
}
}
}
this
.
conjunto
.
push
(
obj
.
conj
);
this
.
conjunto
.
push
(
obj
.
conj
);
var
identificador
=
0
;
if
(
this
.
conjunto
.
length
>
1
){
identificador
=
this
.
conjunto
.
length
-
2
+
this
.
id
;
}
if
(
obj
.
conj
.
baseDom
==
'
R
'
){
this
.
valores
=
[];
var
funcionGenerada2
=
this
.
generarFuncionDisc
(
jsonCanvas
);
var
funcionesVer2019
=
this
.
createListFunction
(
jsonCanvas
);
var
listValores
=
[];
for
(
var
k
of
this
.
valores
){
listValores
.
push
(
parseInt
(
k
))
}
for
(
var
i
of
this
.
valores
){
for
(
var
t
of
this
.
valores
){
var
aux
=
parseInt
(
t
);
var
aux2
=
parseInt
(
i
);
var
mul
=
aux
*
aux2
;
listValores
.
push
(
mul
)
}
}
for
(
i
=
-
999
;
i
<
1000
;
i
++
)
{
listValores
.
push
(
i
)
}
let
sinRepetidos
=
listValores
.
filter
((
valor
,
indiceActual
,
arreglo
)
=>
arreglo
.
indexOf
(
valor
)
===
indiceActual
);
for
(
var
fun2
of
funcionesVer2019
){
let
fun3
=
eval
(
fun2
);
var
insertar
=
false
;
var
punto1
=
[];
if
(
sinRepetidos
.
length
){
for
(
var
p
of
sinRepetidos
){
var
pn
=
parseInt
(
p
)
-
0.001
var
pp
=
parseInt
(
p
)
+
0.001
insertar
=
(((
fun3
(
pp
)
!=
undefined
)
)
||
((
fun3
(
pn
)
!=
undefined
))
||
insertar
)
if
((
fun3
(
pp
)
!=
undefined
)){
punto1
.
push
(
pp
);
}
else
if
((
fun3
(
pn
)
!=
undefined
)){
punto1
.
push
(
p
);
}
}
}
else
{
insertar
=
true
;
}
if
(
insertar
){
this
.
funciones
.
push
({
id
:
identificador
,
sampler
:
'
builtIn
'
,
fn
:
function
(
scope
)
{
return
fun3
(
scope
.
x
)
},
graphType
:
tipoGraf
,
point
:
punto1
[
0
],
color
:
color
,
});
}
}
}
else
{
this
.
funciones
.
push
({
id
:
identificador
,
sampler
:
'
builtIn
'
,
fn
:
function
(
scope
)
{
return
fun
(
scope
.
x
)
},
graphType
:
tipoGraf
,
color
:
color
});
}
}
}
else
{
this
.
conjunto
=
[];
this
.
conjunto
.
push
(
obj
.
conj
);
this
.
id
=
0
;
this
.
funciones
=
[];
if
(
obj
.
conj
.
baseDom
==
'
R
'
){
this
.
valores
=
[];
var
funcionGenerada2
=
this
.
generarFuncionDisc
(
jsonCanvas
);
var
funcionesVer2019
=
this
.
createListFunction
(
jsonCanvas
);
var
listValores
=
[];
for
(
var
k
of
this
.
valores
){
listValores
.
push
(
parseInt
(
k
))
}
for
(
var
i
of
this
.
valores
){
for
(
var
t
of
this
.
valores
){
var
aux
=
parseInt
(
t
);
var
aux2
=
parseInt
(
i
);
var
mul
=
aux
*
aux2
;
listValores
.
push
(
mul
)
}
}
for
(
i
=
-
999
;
i
<
1000
;
i
++
)
{
listValores
.
push
(
i
)
}
let
sinRepetidos
=
listValores
.
filter
((
valor
,
indiceActual
,
arreglo
)
=>
arreglo
.
indexOf
(
valor
)
===
indiceActual
);
for
(
var
fun2
of
funcionesVer2019
){
let
fun3
=
eval
(
fun2
);
var
insertar
=
false
;
var
punto1
=
[];
if
(
sinRepetidos
.
length
){
for
(
var
p
of
sinRepetidos
){
var
pn
=
parseInt
(
p
)
-
0.001
var
pp
=
parseInt
(
p
)
+
0.001
insertar
=
(((
fun3
(
pp
)
!=
undefined
)
)
||
((
fun3
(
pn
)
!=
undefined
))
||
insertar
)
if
((
fun3
(
pp
)
!=
undefined
)){
punto1
.
push
(
pp
);
}
else
if
((
fun3
(
pn
)
!=
undefined
)){
punto1
.
push
(
p
);
}
}
}
else
{
insertar
=
true
;
}
if
(
insertar
){
this
.
funciones
.
push
({
id
:
0
,
sampler
:
'
builtIn
'
,
fn
:
function
(
scope
)
{
return
fun3
(
scope
.
x
)
},
graphType
:
tipoGraf
,
point
:
punto1
[
0
],
color
:
color
,
});
}
}
}
else
{
this
.
funciones
.
push
({
this
.
funciones
.
push
({
id
:
this
.
funciones
.
length
+
this
.
id
,
id
:
this
.
funciones
.
length
,
sampler
:
'
builtIn
'
,
sampler
:
'
builtIn
'
,
fn
:
function
(
scope
)
{
fn
:
function
(
scope
)
{
return
fun
(
scope
.
x
)
return
fun
(
scope
.
x
)
...
@@ -174,21 +409,8 @@ export class Graph2DComponent {
...
@@ -174,21 +409,8 @@ export class Graph2DComponent {
graphType
:
tipoGraf
,
graphType
:
tipoGraf
,
color
:
color
color
:
color
});
});
}
}
else
{
}
this
.
conjunto
=
[];
this
.
conjunto
.
push
(
obj
.
conj
);
this
.
id
=
0
;
this
.
funciones
=
[];
this
.
funciones
.
push
({
id
:
this
.
funciones
.
length
,
sampler
:
'
builtIn
'
,
fn
:
function
(
scope
)
{
return
fun
(
scope
.
x
)
},
graphType
:
tipoGraf
,
color
:
color
});
}
}
let
bounding
=
this
.
getBounding
();
let
bounding
=
this
.
getBounding
();
this
.
instance
=
functionPlot
({
this
.
instance
=
functionPlot
({
...
@@ -747,9 +969,501 @@ export class Graph2DComponent {
...
@@ -747,9 +969,501 @@ export class Graph2DComponent {
return
expresion
;
return
expresion
;
}
}
//Nuevo 20-07-2018
// nueva
createListFunction
=
function
(
graph
)
{
var
funcionString
=
''
;
var
grafica
;
var
funciones
=
[];
var
j
=
0
;
while
(
graph
.
funs
[
j
].
fun
!=
graph
.
graph
)
{
j
+=
1
;
}
var
fun1
=
graph
.
funs
[
j
];
var
arrayFunction
=
[];
var
nameFun
=
[];
nameFun
.
push
(
fun1
.
fun
);
funciones
=
this
.
armarFuncion
(
fun1
.
bdy
,
graph
,
nameFun
);
for
(
var
funs
of
funciones
){
for
(
var
fun
of
graph
.
funs
){
if
(
fun
.
fun
!=
fun1
.
fun
){
funcionString
=
'
var
'
+
fun
.
fun
+
'
= function(
'
+
fun
.
args
.
join
()
+
'
){
\n
return
'
+
this
.
generarExpresion
(
fun
.
bdy
)
+
'
}
\n
'
+
funcionString
;
}
}
funcionString
=
'
var
'
+
fun1
.
fun
+
'
= function(
'
+
fun1
.
args
.
join
()
+
'
){
\n
return
'
+
funs
+
'
}
\n
'
+
funcionString
;
funcionString
+=
'
;return
'
+
fun1
.
fun
+
'
(
'
+
fun1
.
args
.
join
()
+
'
);
\n
'
grafica
=
fun1
;
funcionString
=
'
(
'
+
grafica
.
args
.
join
()
+
'
)=>{
\n
'
+
funcionString
+
'
}
'
;
arrayFunction
.
push
(
funcionString
);
var
funcionString
=
''
;
}
return
arrayFunction
;
}
armarFuncion
=
function
(
exp
,
graph
,
nameFun
){
var
lisArm
=
this
.
generateFunctionAndExp
(
exp
,
graph
,
nameFun
);
var
lisFun
=
[];
for
(
var
lis
of
lisArm
){
var
aux
=
''
;
if
(
lis
[
0
]
==
'
N
'
){
aux
=
lis
[
1
];
}
else
{
aux
=
'
(
'
+
lis
[
0
]
+
'
?
'
+
lis
[
1
]
+
'
: undefined )
'
;
}
lisFun
.
push
(
aux
);
}
return
lisFun
}
generateFunctionAndExp
=
function
(
exp
,
graph
,
namefun6
)
{
var
myList
=
[];
// devuelvo lista con tupla (cond,funcion)
if
(
exp
.
kind
==
'
cnd
'
)
{
var
lisA
=
this
.
generateFunctionAndExp
(
exp
.
exp1
,
graph
,
namefun6
);
var
lisB
=
this
.
generateFunctionAndExp
(
exp
.
exp2
,
graph
,
namefun6
);
var
cond
=
this
.
createListExp
(
exp
.
cond
);
var
g
=
this
.
createListExp
(
exp
.
cond
);
var
aux121
=
[];
var
cond2
=
g
.
splice
(
1
);
var
union
=
g
[
0
]
for
(
var
a
of
cond2
){
union
=
'
(
'
+
union
+
'
&&
'
+
a
+
'
)
'
;
}
for
(
var
fun1
of
lisA
){
if
(
fun1
[
0
]
==
'
N
'
){
if
(
cond
.
length
==
0
){
aux121
[
0
]
=
'
N
'
;
}
else
{
aux121
[
0
]
=
union
;
}
}
else
{
aux121
[
0
]
=
'
(
'
+
fun1
[
0
]
+
'
&&
'
+
union
+
'
)
'
;
}
aux121
[
1
]
=
fun1
[
1
];
myList
.
push
(
aux121
);
}
for
(
var
fun2
of
lisB
){
if
(
cond
.
length
!=
0
){
for
(
var
condi
of
cond
){
var
aux123
=
[];
aux123
[
1
]
=
fun2
[
1
];
if
(
fun2
[
0
]
==
'
N
'
){
aux123
[
0
]
=
'
!(
'
+
condi
+
'
)
'
;
}
else
{
aux123
[
0
]
=
'
(
'
+
fun2
[
0
]
+
'
&& !(
'
+
condi
+
'
))
'
;
}
myList
.
push
(
aux123
);
}
}
else
{
myList
.
push
(
fun2
);
}
}
}
else
if
(
exp
.
kind
==
'
bop
'
)
{
if
(
exp
.
op
==
'
^
'
)
{
var
lisA1
=
this
.
generateFunctionAndExp
(
exp
.
exp1
,
graph
,
namefun6
);
var
lisB1
=
this
.
generateFunctionAndExp
(
exp
.
exp2
,
graph
,
namefun6
);
var
aux1
=
[];
for
(
var
f1
of
lisA1
){
for
(
var
f2
of
lisB1
){
var
aux11
=
'
Math.pow(
'
+
f1
[
1
]
+
'
,
'
+
f2
[
1
]
+
'
)
'
;
var
aux21
;
if
((
f2
[
0
]
==
'
N
'
)
&&
(
f1
[
0
]
==
'
N
'
)){
aux21
=
'
N
'
}
else
if
(
f2
[
0
]
==
'
N
'
){
aux21
=
f1
[
0
]
}
else
if
(
f1
[
0
]
==
'
N
'
){
aux21
=
f2
[
0
]
}
else
{
aux21
=
'
(
'
+
f1
[
0
]
+
'
&&
'
+
f2
[
0
]
+
'
)
'
;
}
aux1
[
0
]
=
aux21
;
aux1
[
1
]
=
aux11
;
myList
.
push
(
aux1
);
}
}
}
else
{
var
lisA2
=
this
.
generateFunctionAndExp
(
exp
.
exp1
,
graph
,
namefun6
);
var
lisB2
=
this
.
generateFunctionAndExp
(
exp
.
exp2
,
graph
,
namefun6
);
var
aux2
=
[];
for
(
var
f1
of
lisA2
){
for
(
var
f2
of
lisB2
){
var
aux12
=
'
((
'
+
f1
[
1
]
+
'
)
'
+
exp
.
op
+
'
(
'
+
f2
[
1
]
+
'
))
'
;
var
aux22
if
((
f2
[
0
]
==
'
N
'
)
&&
(
f1
[
0
]
==
'
N
'
)){
aux22
=
'
N
'
}
else
if
(
f2
[
0
]
==
'
N
'
){
aux22
=
f1
[
0
]
}
else
if
(
f1
[
0
]
==
'
N
'
){
aux22
=
f2
[
0
]
}
else
{
aux22
=
'
(
'
+
f1
[
0
]
+
'
&&
'
+
f2
[
0
]
+
'
)
'
;
}
aux2
[
0
]
=
aux22
;
aux2
[
1
]
=
aux12
;
myList
.
push
(
aux2
);
}
}
}
}
else
if
(
exp
.
kind
==
'
uop
'
)
{
var
lisA3
=
this
.
generateFunctionAndExp
(
exp
.
exp
,
graph
,
namefun6
);
var
aux3
=
[];
for
(
var
f1
of
lisA3
){
var
aux13
=
'
'
+
exp
.
op
+
'
'
+
f1
[
1
]
+
'
'
;
aux3
[
0
]
=
f1
[
0
];
aux3
[
1
]
=
aux13
;
myList
.
push
(
aux3
);
}
}
else
if
(
exp
.
kind
==
'
app
'
)
{
if
((
exp
.
fun
==
'
Math.cos
'
)
||
(
exp
.
fun
==
'
cos
'
))
{
var
aux4
=
[];
var
aux14
=
'
Math.cos(
'
+
exp
.
args
.
map
(
e
=>
this
.
generarExpresion
(
e
)).
join
()
+
'
)
'
;
var
aux24
=
'
N
'
aux4
[
0
]
=
aux24
;
aux4
[
1
]
=
aux14
;
myList
.
push
(
aux4
);
}
else
if
((
exp
.
fun
==
'
Math.sin
'
)
||
(
exp
.
fun
==
'
sin
'
))
{
var
aux5
=
[];
var
aux15
=
'
Math.sin(
'
+
exp
.
args
.
map
(
e
=>
this
.
generarExpresion
(
e
)).
join
()
+
'
)
'
;
var
aux25
=
'
N
'
aux5
[
0
]
=
aux25
;
aux5
[
1
]
=
aux15
;
myList
.
push
(
aux5
);
}
else
if
((
exp
.
fun
==
'
Math.round
'
)
||
(
exp
.
fun
==
'
round
'
)){