Commit 9c418d5f authored by Diego Rey's avatar Diego Rey
Browse files

Merged graficas-componente and 3DComponentInitialization branchs

parents 4d963927 4d7f6d66
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -84,6 +84,12 @@
<graph3d-component (graph3DComp)=graph3DComp></graph3d-component>
</ng-template>
</ngb-tab>
<ngb-tab id="FigurasBtn2" title="Figuras New">
<ng-template ngbTabContent>
<plotter-component (plotterComp)=plotterC></plotter-component>
</ng-template>
</ngb-tab>
</ngb-tabset>
</div>
......
File mode changed from 100644 to 100755
import { Component, NgModule, ViewChild, HostListener, ElementRef, ComponentRef, TemplateRef } from '@angular/core';
import { CanvasModule} from '../canvas/canvas.module';
import { CanvasComponent } from '../canvas/canvas.component';
import { PlotterModule } from '../plotter/plotter.module';
import { PlotterComponent } from '../plotter/plotter.component';
import { Http, JsonpModule } from '@angular/http';
import { Headers, RequestOptions } from '@angular/http';
import { HaskellService } from '../../shared/services/haskell.service';
......@@ -354,6 +356,8 @@ export class MateFunComponent {
@ViewChild(CanvasComponent) canvasC: CanvasComponent;
@ViewChild(Graph3DComponent) graph3DComp: Graph3DComponent;
@ViewChild(PlotterComponent) plotterC: PlotterComponent;
funcionSTR: string = 'Math.sin(x)*x*x-20';
consola: string = '';
command: string = '';
......
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { CanvasModule } from '../canvas/canvas.module'
import { PlotterModule } from '../plotter/plotter.module'
import { MateFunComponent } from './matefun.component';
import { BootstrapModalModule } from 'ng2-bootstrap-modal';
import { ConfirmComponent } from './confirm.component';
......@@ -17,6 +18,7 @@ import { Graph3DModule } from '../plotter/graph3D/graph3D.module';
CommonModule,
FormsModule,
CanvasModule,
PlotterModule,
Graph3DModule,
NotificacionModule,
MateFunRoutingModule,
......
File mode changed from 100644 to 100755
/**
* This barrel file provides the export for the lazy loaded BlankpageComponent.
*/
export * from './plotter.component';
export * from './plotter.routes';
<div class="card">
<div class="card-block contenedor-canvas" >
<div id="plotter-container" style="height: 100%; width: 100%;">
</div>
</div>
</div>
\ No newline at end of file
import { Component } from '@angular/core';
import { GHCIService } from '../../shared/services/ghci.service';
import functionPlot from 'function-plot';
@Component({
moduleId: module.id,
selector: 'plotter-component',
templateUrl: './plotter.component.html',
host: {
}
})
export class PlotterComponent {
public constructor(private ghciService: GHCIService) {
ghciService.messages.subscribe(
canvas=>{
if (canvas.tipo == 'graph'){
var jsonCanvas = JSON.parse(canvas.resultado);
let fun = eval(this.generarFuncion(jsonCanvas));
functionPlot({
target: '#plotter-container',
width: 770,
height: 720,
tip: {
color: 'green'
},
xAxis: {
label: 'x - axis',
scale: 'linear',
domain: {
initial: [-4, 4],
type: 'discrete'
}
},
data: [{
graphType: 'scatter',
fn: function (scope) {
// scope.x = Number
return fun(scope.x)
}
}]
})
// functionPlot({
// target: '#plotter-container',
// width: 620,
// height: 450,
// data: [{
// sampler: 'builtIn',
// fn: function(scope) {
// return fun(scope.x)
// },
// graphType: 'polyline'
// }]
// })
}
},
error=>{
})
}
generarFuncion = function(graph) {
var funcionString = '';
var grafica;
for (var fun of graph.funs) {
funcionString = 'var ' + fun.fun + ' = function(' + fun.args.join() + '){\n return ' + this.generarExpresion(fun.bdy) + '}\n' + funcionString;
if (fun.fun == graph.graph) {
funcionString += 'return ' + fun.fun + '(' + fun.args.join() + ');\n'
grafica = fun;
}
}
funcionString = '(' + grafica.args.join() + ',delta,hayPunto)=>{\n' + funcionString + '}';
console.log('funcion string', funcionString);
return funcionString;
}
generarExpresion = function(exp) {
var expresion = '';
if (exp.kind == 'cnd') {
expresion = ' (' + this.generarExpresion(exp.cond) + '?' + this.generarExpresion(exp.exp1) + ':' + this.generarExpresion(exp.exp2) + ') ';
} else if (exp.kind == 'bop') {
if (exp.op == '==') {
expresion = ' Math.abs((' + this.generarExpresion(exp.exp1) + ') - (' + this.generarExpresion(exp.exp2) + ')) < delta && hayPunto() ';
} else if (exp.op == '/=') {
expresion = ' Math.abs((' + this.generarExpresion(exp.exp1) + ') - (' + this.generarExpresion(exp.exp2) + ')) > delta || Math.abs((' + this.generarExpresion(exp.exp1) + ') - (' + this.generarExpresion(exp.exp2) + ')) < delta && !hayPunto() ';
} else if (exp.op == '^') {
expresion = ' Math.pow(' + this.generarExpresion(exp.exp1) + ',' + this.generarExpresion(exp.exp2) + ') ';
} else {
expresion = ' (' + this.generarExpresion(exp.exp1) + ')' + exp.op + '(' + this.generarExpresion(exp.exp2) + ') ';
}
} else if (exp.kind == 'uop') {
expresion = ' ' + exp.op + ' ' + this.generarExpresion(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 == 'red') {
exp.fun = 'Math.round'
}
expresion = ' ' + exp.fun + '(' + exp.args.map(e => this.generarExpresion(e)).join() + ') ';
} else if (exp.kind == 'tup') {
expresion = ' (' + exp.exps.map(e => this.generarExpresion(e)).join() + ') ';
} else if (exp.kind == 'lit') {
expresion = ' ' + exp.val + ' ';
} else if (exp.kind == 'var') {
expresion = ' ' + exp.var+' ';
} else {
expresion = ' undefined ';
}
return expresion;
}
}
import { NgModule} from '@angular/core';
import { CommonModule } from '@angular/common'
import { RouterModule } from '@angular/router';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { FormsModule } from '@angular/forms';
import { PlotterComponent } from './plotter.component';
@NgModule({
imports: [FormsModule, RouterModule, CommonModule, NgbModule],
declarations: [PlotterComponent],
exports: [PlotterComponent]
})
export class PlotterModule { }
\ No newline at end of file
import { Route } from '@angular/router';
import { PlotterComponent } from './index';
export const PlotterRoutes: Route[] = [
{
path: 'plotter',
component: PlotterComponent
}
];
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment