/** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Paul Luna */ import PointComponent from './PointComponent'; import * as React from 'react'; import { Vec2 } from 'mol-math/linear-algebra'; // interface Line { // x1: number; // x2: number; // y1: number; // y2: number; // }; // interface Rect { // x: number; // y: number; // } // interface TextLabel { // x: number; // y: number; // } interface CanvasComponentState { points: Vec2[], selectedPoint: any, selected: number | undefined, copyPoint: any, updatedX: number, updatedY: number, } export default class CanvasComponent extends React.Component { private myRef:any; private height: number; private width: number; private padding: number; // private topLine: Line; // private bottomLine: Line; // private rightLine: Line; // private leftLine: Line; // private normalizedXLabels: Point[]; // private normalizedYLabels: Point[]; // private normalizedRect: Rect; // private normalizedLabel: TextLabel; // private normalizedInfoPoint: Point; // private normalizedInfoLabel: Point; // private label: TextLabel = {x: 0, y: 0.1}; // private infoPoint = {x: 0.95, y: 0.5}; // private infoLabel = {x: 0.945, y: 0.2}; // private rainbowRect: Rect = {x: 0.0, y: 0.5}; // private xLabel: Point[] = [ // {x: 0, y: 0.65}, // {x: 0.07, y: 0.65}, // {x: 0.17, y: 0.65}, // {x: 0.27, y: 0.65}, // {x: 0.37, y: 0.65}, // {x: 0.47, y: 0.65}, // {x: 0.57, y: 0.65}, // {x: 0.67, y: 0.65}, // {x: 0.77, y: 0.65}, // {x: 0.87, y: 0.65}, // {x: 0.97, y: 0.65}, // ]; // private yLabel: Point[] = [ // {x: 0.45, y: 0}, // {x: 0.45, y: 0.1}, // {x: 0.45, y: 0.2}, // {x: 0.45, y: 0.3}, // {x: 0.45, y: 0.4}, // {x: 0.45, y: 0.5}, // {x: 0.45, y: 0.6}, // {x: 0.45, y: 0.7}, // {x: 0.45, y: 0.8}, // {x: 0.45, y: 0.9}, // {x: 0.45, y: 1}, // ]; constructor(props: any) { super(props); this.myRef = React.createRef(); this.state = { points:[ Vec2.create(0, 0), Vec2.create(1, 0) ], selectedPoint: undefined, selected: undefined, copyPoint: undefined, updatedX: 0, updatedY: 0, }; this.height = 400; this.width = 600; this.padding = 70; // this.normalizedXLabels = this.normalizeXLabel(this.xLabel); // this.normalizedYLabels = this.normalizeYLabel(this.yLabel); // this.topLine = { // x1: this.padding/2, // x2: this.width+this.padding/2, // y1: this.padding/2, // y2: this.padding/2 // }; // this.rightLine = { // x1: this.width+this.padding/2, // x2: this.width+this.padding/2, // y1: this.padding/2, // y2: this.height+this.padding/2 // }; // this.bottomLine = { // x1: this.padding/2, // x2: this.width+this.padding/2, // y1: this.height+this.padding/2, // y2: this.height+this.padding/2 // }; // this.leftLine = { // x1: this.padding/2, // x2: this.padding/2, // y1: this.padding/2, // y2: this.height+this.padding/2 // }; // this.normalizedLabel = this.normalizeGraphLabel( // this.label, // this.padding/2, // this.height+this.padding/2, // this.width+this.padding/2, // this.height+this.padding // ); // this.normalizedInfoPoint = this.normalizeGraphLabel( // this.infoPoint, // this.padding/2, // this.height+this.padding/2, // this.width+this.padding/2, // this.height+this.padding // ); // this.normalizedInfoLabel = this.normalizeGraphLabel( // this.infoLabel, // this.padding/2, // this.height+this.padding/2, // this.width+this.padding/2, // this.height+this.padding // ); // this.normalizedRect = this.normalizeGraphLabel( // this.rainbowRect, // this.padding/2, // 0, // this.width+this.padding/2, // this.padding/2 // ); for (const point of this.props.data){ this.state.points.push(point); } this.state.points.sort((a, b) => { if(a[0] === b[0]){ if(a[0] === 0){ return a[1]-b[1]; } if(a[1] === 1){ return b[1]-a[1]; } return a[1]-b[1]; } return a[0] - b[0]; }); this.handleDrag = this.handleDrag.bind(this); this.handleClickCanvas = this.handleClickCanvas.bind(this); this.handleDoubleClick = this.handleDoubleClick.bind(this); this.refCallBack = this.refCallBack.bind(this); this.handlePointUpdate = this.handlePointUpdate.bind(this); this.change = this.change.bind(this); } public render() { const points = this.renderPoints(); const ghostPoint = this.state.copyPoint; const selectedPoint = this.state.selectedPoint; return ([
{/* YOUR LABEL HERE */} {/* */} {points} {ghostPoint} {selectedPoint} {/* */} {/* 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 */} {/* */}
,