From 0ea1bf638a9b57d2764ede02fdf7b2093d88bcda Mon Sep 17 00:00:00 2001 From: "jose.ignacio.fagian" <nachofagian@gmail.com> Date: Tue, 31 Jul 2018 00:23:58 -0300 Subject: [PATCH] Parametrizaciones de opciones para el visor 3D, regex de parseo line3D --- .../plotter/graph3D/graph3D.component.html | 6 +++- .../plotter/graph3D/graph3D.component.ts | 29 ++++++++++++++++-- .../layout/plotter/graph3D/graph3D.helper.ts | 30 +++++++++++++++---- 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/Frontend Angular 4/src/app/layout/plotter/graph3D/graph3D.component.html b/Frontend Angular 4/src/app/layout/plotter/graph3D/graph3D.component.html index 2cbdffc..4a6e68d 100644 --- a/Frontend Angular 4/src/app/layout/plotter/graph3D/graph3D.component.html +++ b/Frontend Angular 4/src/app/layout/plotter/graph3D/graph3D.component.html @@ -175,8 +175,12 @@ <input type="number" - style="width: 55px;" class="form-control form-control-sm" + [(ngModel)]="graphProps.quality" + [max]="99" + [min]="2" + (change)="onChangeQuality()" + style="width: 55px;" /> </div> </div> diff --git a/Frontend Angular 4/src/app/layout/plotter/graph3D/graph3D.component.ts b/Frontend Angular 4/src/app/layout/plotter/graph3D/graph3D.component.ts index 690432c..36c1c56 100644 --- a/Frontend Angular 4/src/app/layout/plotter/graph3D/graph3D.component.ts +++ b/Frontend Angular 4/src/app/layout/plotter/graph3D/graph3D.component.ts @@ -1,7 +1,8 @@ import { Component, OnInit, ViewChild, ElementRef, NgZone } from '@angular/core'; import * as graph3DLib from 'graph3d'; import { GHCIService } from '../../../shared/services/ghci.service'; -import { formatJSON, AnimationProps, Zoom3DType, GraphProps, Default_GraphProps } from './graph3D.helper'; +import { formatJSON, AnimationProps, Zoom3DType, GraphProps, Default_GraphProps, debounce } from './graph3D.helper'; +import { debounceTime, distinctUntilChanged } from 'rxjs/operators' @Component({ selector: 'graph3d-component', @@ -104,12 +105,23 @@ export class Graph3DComponent implements OnInit { graph3DLib.showAxes(this.graphProps.showAxes); } + handleAxesRangeDebounced = debounce(function () { + setTimeout(() => + graph3DLib.changeAxesSize(this.graphProps.range) + ); + }, 500); + public onChangeAxesSize = (v, event) => { let value = this.graphProps.range[v]; const min = parseInt(event.target.min); const max = parseInt(event.target.max); + if (value == null) { + value = v.search('Min') ? min : max; + this.graphProps.range[v] = value; + } + if (value < min) { this.graphProps.range[v] = min; } @@ -117,8 +129,21 @@ export class Graph3DComponent implements OnInit { if (value > max) { this.graphProps.range[v] = max; } + this.handleAxesRangeDebounced(); + //graph3DLib.changeAxesSize(this.graphProps.range) + } + + public onChangeQuality = () => { + const value = this.graphProps.quality; - graph3DLib.changeAxesSize(this.graphProps.range) + if (value == null || value <= 1) { + this.graphProps.quality = 30; + } + else { + this.graphProps.quality = value; + } + + graph3DLib.changeOptions({quality: value}); } public zoomIn = () => { diff --git a/Frontend Angular 4/src/app/layout/plotter/graph3D/graph3D.helper.ts b/Frontend Angular 4/src/app/layout/plotter/graph3D/graph3D.helper.ts index 90fc980..eef025d 100644 --- a/Frontend Angular 4/src/app/layout/plotter/graph3D/graph3D.helper.ts +++ b/Frontend Angular 4/src/app/layout/plotter/graph3D/graph3D.helper.ts @@ -1,11 +1,18 @@ export function formatJSON(jsonString: string) : string { const regexRot = /\"rot\"\:\((\d*.\d*),(\d*.\d*),(\d*.\d*)\)/g; + const regexPts = /\"pts\"\:\[\((\-?\d*.\d*),(\-?\d*.\d*),(\-?\d*.\d*)\),\((\-?\d*.\d*),(\-?\d*.\d*),(\-?\d*.\d*)\)\]/g; - return jsonString.replace( - regexRot, (match, x, y, z) => { - return `"rot": { "x": ${x}, "y": ${y}, "z": ${z} }` - } - ) + return jsonString + .replace( + regexRot, (match, x, y, z) => { + return `"rot": { "x": ${x}, "y": ${y}, "z": ${z} }` + } + ) + .replace( + regexPts, (match, x1, y1, z1, x2, y2, z2) => { + return `"pts": [{ "x": ${x1}, "y": ${y1}, "z": ${z1} },{ "x": ${x2}, "y": ${y2}, "z": ${z2} }]` + } + ) } @@ -26,6 +33,7 @@ export enum Zoom3DType { export interface GraphProps { zoomType?: Zoom3DType, showAxes?: boolean, + quality?: number, range: { xMin?: number, xMax?: number, @@ -39,6 +47,7 @@ export interface GraphProps { export const Default_GraphProps : GraphProps = { zoomType: Zoom3DType.Normal, showAxes: true, + quality: 30, range: { xMin: -10, xMax: 10, @@ -49,3 +58,14 @@ export const Default_GraphProps : GraphProps = { } } +export function debounce(fn, delay) { + var timer = null; + return function () { + var context = this, args = arguments; + clearTimeout(timer); + timer = setTimeout(function () { + fn.apply(context, args); + }, delay); + }; +} + -- GitLab