Skip to content
Snippets Groups Projects
Select Git revision
  • 4d7f6d66da11a3ae6d89a4df1a5529107972ed32
  • master default
  • remove-matefun-graf-from-angular
  • pg-moodle-integration-main
  • feature/discontinuidades
  • feature/i18n-with-routes
  • develop
  • feature/functions-information
  • feature/editor-improvements
  • feature/add-in18-frontend
  • feature/integration-graph-2d-3d
  • feature/3DComponentInitialization
  • graficas-componente
  • feature/codeMatchBrackets
  • v2.0
  • v1.0
16 results

plotter.component.ts

Blame
  • Forked from matefun / Frontend
    Source project has a limited visibility.
    plotter.component.ts 4.78 KiB
    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) {