Commit b496eed1 authored by jose.ignacio.fagian's avatar jose.ignacio.fagian
Browse files

Actualizacion componente graph2d con los cambios de Leonel

parent 73c5a5eb
...@@ -3632,12 +3632,14 @@ ...@@ -3632,12 +3632,14 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
...@@ -3652,17 +3654,20 @@ ...@@ -3652,17 +3654,20 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
...@@ -3779,7 +3784,8 @@ ...@@ -3779,7 +3784,8 @@
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
...@@ -3791,6 +3797,7 @@ ...@@ -3791,6 +3797,7 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
...@@ -3805,6 +3812,7 @@ ...@@ -3805,6 +3812,7 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
...@@ -3812,12 +3820,14 @@ ...@@ -3812,12 +3820,14 @@
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.2.4", "version": "2.2.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.1", "safe-buffer": "^5.1.1",
"yallist": "^3.0.0" "yallist": "^3.0.0"
...@@ -3836,6 +3846,7 @@ ...@@ -3836,6 +3846,7 @@
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
...@@ -3916,7 +3927,8 @@ ...@@ -3916,7 +3927,8 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
...@@ -3928,6 +3940,7 @@ ...@@ -3928,6 +3940,7 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
...@@ -4049,6 +4062,7 @@ ...@@ -4049,6 +4062,7 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",
......
...@@ -74,17 +74,17 @@ ...@@ -74,17 +74,17 @@
</ng-template> </ng-template>
</ngb-tab> </ngb-tab>
<ngb-tab id="FigurasBtn" title="Figuras OLD"> <!-- <ngb-tab id="FigurasBtn" title="Figuras OLD">
<ng-template ngbTabContent> <ng-template ngbTabContent>
<canvas-component (canvasComp)=canvasC></canvas-component> <canvas-component (canvasComp)=canvasC></canvas-component>
</ng-template> </ng-template>
</ngb-tab> </ngb-tab> -->
<ngb-tab id="FigurasBtn2" title="Figuras 2D"> <ngb-tab id="FigurasBtn2D" title="Figuras 2D">
<ng-template ngbTabContent> <ng-template ngbTabContent>
<graph2D-component (graph2DComp)=graph2DComp></graph2D-component> <graph2D-component (graph2DComp)=graph2DComp></graph2D-component>
</ng-template> </ng-template>
</ngb-tab> </ngb-tab>
<ngb-tab id="FigurasBtn3" title="Figuras 3D"> <ngb-tab id="FigurasBtn3D" title="Figuras 3D">
<ng-template ngbTabContent> <ng-template ngbTabContent>
<graph3d-component (graph3DComp)=graph3DComp></graph3d-component> <graph3d-component (graph3DComp)=graph3DComp></graph3d-component>
</ng-template> </ng-template>
......
...@@ -354,7 +354,7 @@ export class MateFunComponent { ...@@ -354,7 +354,7 @@ export class MateFunComponent {
.replace(/>/g, '&gt;'); .replace(/>/g, '&gt;');
} }
@ViewChild(CanvasComponent) canvasC: CanvasComponent; // @ViewChild(CanvasComponent) canvasC: CanvasComponent;
@ViewChild(Graph3DComponent) graph3DComp: Graph3DComponent; @ViewChild(Graph3DComponent) graph3DComp: Graph3DComponent;
@ViewChild(Graph2DComponent) graph2DComp: Graph2DComponent; @ViewChild(Graph2DComponent) graph2DComp: Graph2DComponent;
......
...@@ -14,59 +14,66 @@ export class Graph2DComponent { ...@@ -14,59 +14,66 @@ export class Graph2DComponent {
public constructor(private ghciService: GHCIService) { public constructor(private ghciService: GHCIService) {
ghciService.messages.subscribe( ghciService.messages.subscribe(
canvas=>{ canvas=>{
if (canvas.tipo == 'graph'){ if (canvas.tipo == 'graph'){
var jsonCanvas = JSON.parse(canvas.resultado); var jsonCanvas = JSON.parse(canvas.resultado);
let fun = eval(this.generarFuncion(jsonCanvas)); let fun = eval(this.generarFuncion(jsonCanvas));
var conjs = this.obtenerConjunto(jsonCanvas.funs[0]);
functionPlot({ var d = conjs+"}";
target: '#implicit-complex',
xAxis: {
label: 'x - axis',
scale: 'linear',
domain: {
initial: [-4, 4],
type: 'discrete'
},
yAxis: {
domain: [-4, 4]
},
}, var obj = JSON.parse(d);
conj: { //Para las funciones
radio: 2, if (obj.conj.sets.fdom == "function(x)"){
baseDom: 'Z', var nom = jsonCanvas.funs[0].dom;
baseCod: 'Z', var elemento = this.recursionfuncion(jsonCanvas.funs[0].sets,nom);
cod: 'Numer', obj.conj.sets.fdom = function (x) { return eval(elemento)}
dom: 'Func', }
sets: { if (obj.conj.sets.fcod == "function(x)"){
fcod:['Lun','Mart','Mier','Juev','Vier','Saba','Dom','Lunes'], var nom = jsonCanvas.funs[0].cod;
fdom: function (x) { var elemento = this.recursionfuncion(jsonCanvas.funs[0].sets,nom);
// scope.x = Number obj.conj.sets.fcod = function (x) { return (eval(elemento))}
return (0 <= x); }
} //para Enumerados
} if(obj.conj.dom == 'Numer'){
}, var cantElementos = obj.conj.sets.fdom.length;
data: [{ var j = 0;
graphType: 'scatter', for (var fun of obj.conj.sets.fdom) {
fn: function (scope) { //var newstr = nuevo2.replace(fun, j);
return fun(scope.x) j = j + 1;
} }
}]
}) }
// functionPlot({ if(obj.conj.cod == 'Numer'){
// target: '#graph2D-container', var cantElementos = obj.conj.sets.fcod.length;
// width: 620, var j = 0;
// height: 450, for (var fun of obj.conj.sets.fcod) {
// data: [{ //var newstr = nuevo2.replace(fun, j);
// sampler: 'builtIn', j = j + 1;
// fn: function(scope) { }
// return fun(scope.x)
// }, }
// graphType: 'polyline'
// }] var colores = ['pink','red','blue','orange','green']
// }) var num = this.getRandomArbitrary(0,4);
var color = colores[num];
functionPlot({
target: '#graph2D-container',
width: 620,
height: 450,
conj:obj.conj,
data: [{
sampler: 'builtIn',
fn: function(scope) {
return fun(scope.x)
},
graphType: 'scatter',
color: color
}]
})
} }
}, },
error=>{ error=>{
...@@ -75,7 +82,9 @@ export class Graph2DComponent { ...@@ -75,7 +82,9 @@ export class Graph2DComponent {
} }
getRandomArbitrary= function (min, max) {
return Math.round(Math.random() * (max - min) + min);
}
generarFuncion = function(graph) { generarFuncion = function(graph) {
var funcionString = ''; var funcionString = '';
var grafica; var grafica;
...@@ -89,7 +98,6 @@ export class Graph2DComponent { ...@@ -89,7 +98,6 @@ export class Graph2DComponent {
} }
funcionString = '(' + grafica.args.join() + ',delta,hayPunto)=>{\n' + funcionString + '}'; funcionString = '(' + grafica.args.join() + ',delta,hayPunto)=>{\n' + funcionString + '}';
console.log('funcion string', funcionString);
return funcionString; return funcionString;
} }
...@@ -131,7 +139,162 @@ export class Graph2DComponent { ...@@ -131,7 +139,162 @@ export class Graph2DComponent {
return expresion; return expresion;
} }
//Nuevo 20-07-2018
obtenerConjunto= function(grf){
var setf = '\"sets\": {';
var dominio = '{\"conj\": {';
if (grf.dom == 'R'){
dominio += "\"radio\": 0.3, \"baseDom\": \"R\", \"dom\": \"R\"";
setf += "\"fdom\": \"R\",";
}else if(grf.dom == 'Z'){
dominio += "\"radio\": 2, \"baseDom\": \"Z\", \"dom\": \"Z\"";
setf += "\"fdom\": \"Z\",";
}else if(grf.dom == 'N'){
dominio += "\"radio\":2, \"baseDom\": \"N\", \"dom\": \"N\"";
setf += "\"fdom\": \"N\",";
}else{
var nom = grf.dom;
if (Array.isArray(grf.sets[0][nom])){
var arreglo = grf.sets[0][nom];
var arreglo2 = [];
for (var item of arreglo){
arreglo2.push("\""+item+"\"");
}
dominio += "\"radio\":2, \"baseDom\": \"N\", \"dom\": \"Numer\"";
setf += "\"fdom\": [" + arreglo2 + "], ";
}else{
dominio += this.recursivoDom(grf.sets,nom);
setf += "\"fdom\":\"function(x)\",";
}
}
dominio += ", ";
if (grf.cod == 'R'){
dominio += "\"baseCod\": \"R\", \"cod\": \"R\" ,";
setf += "\"fcod\": \"R\"";
}else if(grf.cod == 'Z'){
dominio += "\"baseCod\": \"Z\", \"cod\": \"Z\" ,";
setf += "\"fcod\": \"Z\"";
}else if(grf.cod == 'N'){
dominio += "\"baseCod\": \"N\", \"cod\": \"N\" ,";
setf += "\"fcod\": \"N\"";
}else{
var nom = grf.cod;
if (Array.isArray(grf.sets[0][nom])){
var arreglo = grf.sets[0][nom];
var arreglo2 = [];
for (var item of arreglo){
arreglo2.push("\""+item+"\"");
}
dominio += "\"baseCod\": \"N\", \"cod\": \"Numer\" ,";
setf += '\"fcod\":[' + arreglo2+']';
}else{
dominio += this.recursivoCod(grf.sets,nom);
setf += "\"fcod\": \"function(x)\"";
}
}
return dominio + setf + "}}";
}
recursionfuncion = function(func,nombre){
var fun = func[0][nombre].set;
var resul = "";
if (fun == 'R' || fun == 'Z' || fun == 'N'){
resul += this.generarF(func[0][nombre].cond);
}else {
resul += this.generarF(func[0][nombre].cond) + " && " + this.recursionfuncion(func,fun);
}
return resul;
}
recursivoDom = function (sets,nom){
var domin = "";
if (sets[0][nom].set == 'R'){
domin += "\"radio\": 0.3, \"baseDom\": \"R\", \"dom\": \"Func\"";
}else if(sets[0][nom].set == 'Z'){
domin += "\"radio\": 2, \"baseDom\": \"Z\", \"dom\": \"Func\"";
}else if(sets[0][nom].set == 'N'){
domin += "\"radio\": 2, \"baseDom\": \"N\", \"dom\": \"Func\"";
}else{
var nombre = sets[0][nom].set;
domin = this.recursivoDom(sets,nombre);
}
return domin;
}
recursivoCod = function (sets,nom){
var coodo = "";
if (sets[0][nom].set == 'R'){
coodo += "\"baseCod\": \"R\", \"cod\": \"Func\",";
}else if(sets[0][nom].set == 'Z'){
coodo += "\"baseCod\": \"Z\", \"cod\": \"Func\",";
}else if(sets[0][nom].set == 'N'){
coodo += "\"baseCod\": \"N\", \"cod\": \"Func\",";
}else{
var nombre = sets[0][nom].set;
coodo += this.recursivoDom(sets,nombre);
}
return coodo;
}
generarF = function(exp) {
var expresion = '';
if (exp.kind == 'cond') {
expresion = ' (' + this.generarF(exp.cond) + '?' + this.generarF(exp.exp1) + ':' + this.generarF(exp.exp2) + ') ';
} else if (exp.kind == 'bop') {
if (exp.op == '==') {
expresion = ' Math.abs((' + this.generarF(exp.exp1) + ') - (' + this.generarF(exp.exp2) + ')) == 0 ';
} else if (exp.op == '/=') {
expresion = ' Math.abs((' + this.generarF(exp.exp1) + ') - (' + this.generarF(exp.exp2) + ')) == 0 || Math.abs((' + this.generarF(exp.exp1) + ') - (' + this.generarF(exp.exp2) + ')) == 0 ';
} else if (exp.op == '^') {
expresion = ' Math.pow(' + this.generarF(exp.exp1) + ',' + this.generarF(exp.exp2) + ') ';
} else {
expresion = ' (' + this.generarF(exp.exp1) + ')' + exp.op + '(' + this.generarF(exp.exp2) + ') ';
}
} else if (exp.kind == 'uop') {
expresion = ' ' + exp.op + ' ' + this.generarF(exp.exp) + ' ';
} else if (exp.kind == 'app') {
if (exp.fun == 'cos') {
exp.fun = 'Math.cos'
} else if (exp.fun == 'sen') {
exp.fun = 'Math.sin'
} else if (exp.fun == 'round') {
exp.fun = 'Math.round'
}
expresion = ' ' + exp.fun + '(' + exp.args.map(e => this.generarF(e)).join() + ') ';
} else if (exp.kind == 'tup') {
expresion = ' (' + exp.exps.map(e => this.generarF(e)).join() + ') ';
} else if (exp.kind == 'lit') {
expresion = ' ' + exp.val + ' ';
} else if (exp.kind == 'var') {
expresion = ' ' + exp.var+' ';
} else {
expresion = ' undefined ';
}
return expresion;
}
generarFun = function(graph) {
var funcionString = '';
var grafica;
for (var fun of graph.funs) {
funcionString = 'var ' + fun.fun + ' = function(' + fun.args.join() + '){\n return ' + this.generarF(fun.bdy) + '}\n' + funcionString;
if (fun.fun == graph.graph) {
funcionString += 'return ' + fun.fun + '(' + fun.args.join() + ');\n'
grafica = fun;
}
}
funcionString = '(' + grafica.args.join() + ')=>{\n' + funcionString + '}';
return funcionString;
}
} }
import { Component, OnInit, ViewChild, ElementRef, NgZone } from '@angular/core'; import { Component, OnInit, ViewChild, ElementRef, NgZone } from '@angular/core';
import * as graph3DLib from 'graph3d'; import * as graph3DLib from 'graph3D';
import { GHCIService } from '../../../shared/services/ghci.service'; import { GHCIService } from '../../../shared/services/ghci.service';
import { formatJSON, AnimationProps, Zoom3DType, GraphProps, Default_GraphProps, debounce } from './graph3D.helper'; import { formatJSON, AnimationProps, Zoom3DType, GraphProps, Default_GraphProps, debounce } from './graph3D.helper';
......
//export const SERVER = 'https://matefun.mybluemix.net';
//export const GHCI_URL = 'wss://matefun.mybluemix.net/endpoint';
//export const SERVER = 'http://localhost:9090';
//export const GHCI_URL = 'ws://localhost:9090/endpoint';
export const SERVER = 'http://localhost:8080';
export const GHCI_URL = 'ws://localhost:8080/endpoint';
//Configuracion dinamica pensando en servidor con ip dinamica
<<<<<<< HEAD
//export const SERVER = window.location.protocol + '//' + window.location.host;//'http://localhost:9090';
//export const GHCI_URL = window.location.protocol == 'http:'? 'ws://'+window.location.host+'/endpoint': 'wss://'+window.location.host+'/endpoint';
//export const SERVER = 'http://ec2-52-15-74-22.us-east-2.compute.amazonaws.com:9090';
//export const GHCI_URL = 'ws://ec2-52-15-74-22.us-east-2.compute.amazonaws.com:9090/endpoint';
=======
// export const SERVER = window.location.protocol + '//' + window.location.host;//'http://localhost:9090';
// export const GHCI_URL = window.location.protocol == 'http:'? 'ws://'+window.location.host+'/endpoint': 'wss://'+window.location.host+'/endpoint';
//export const SERVER = 'http://192.168.95.3:9090';
//export const GHCI_URL = 'ws://192.168.95.3:9090/endpoint';