Skip to content

Commit

Permalink
lint: prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
ozyx committed May 2, 2024
1 parent 8fc2cce commit bede498
Show file tree
Hide file tree
Showing 2 changed files with 240 additions and 240 deletions.
124 changes: 62 additions & 62 deletions src/plugins/plot/draw/Draw2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,99 +43,99 @@ class Draw2D extends EventEmitter {
constructor(canvas) {
super();
eventHelpers.extend(this);
this.canvas = canvas;
this.c2d = canvas.getContext('2d');
this.width = canvas.width;
this.height = canvas.height;
this.dimensions = [this.width, this.height];
this.origin = [0, 0];
this.canvas = canvas;
this.c2d = canvas.getContext('2d');
this.width = canvas.width;
this.height = canvas.height;
this.dimensions = [this.width, this.height];
this.origin = [0, 0];

if (!this.c2d) {
throw new Error('Canvas 2d API unavailable.');
if (!this.c2d) {
throw new Error('Canvas 2d API unavailable.');
}
}
}
// Convert from logical to physical x coordinates
// Convert from logical to physical x coordinates
x(v) {
return ((v - this.origin[0]) / this.dimensions[0]) * this.width;
return ((v - this.origin[0]) / this.dimensions[0]) * this.width;
}
// Convert from logical to physical y coordinates
// Convert from logical to physical y coordinates
y(v) {
return this.height - ((v - this.origin[1]) / this.dimensions[1]) * this.height;
return this.height - ((v - this.origin[1]) / this.dimensions[1]) * this.height;
}
// Set the color to be used for drawing operations
// Set the color to be used for drawing operations
setColor(color) {
const mappedColor = color
.map(function (c, i) {
return i < 3 ? Math.floor(c * 255) : c;
})
.join(',');
this.c2d.strokeStyle = 'rgba(' + mappedColor + ')';
this.c2d.fillStyle = 'rgba(' + mappedColor + ')';
const mappedColor = color
.map(function (c, i) {
return i < 3 ? Math.floor(c * 255) : c;
})
.join(',');
this.c2d.strokeStyle = 'rgba(' + mappedColor + ')';
this.c2d.fillStyle = 'rgba(' + mappedColor + ')';
}
clear() {
this.width = this.canvas.width = this.canvas.offsetWidth;
this.height = this.canvas.height = this.canvas.offsetHeight;
this.c2d.clearRect(0, 0, this.width, this.height);
this.width = this.canvas.width = this.canvas.offsetWidth;
this.height = this.canvas.height = this.canvas.offsetHeight;
this.c2d.clearRect(0, 0, this.width, this.height);
}
setDimensions(newDimensions, newOrigin) {
this.dimensions = newDimensions;
this.origin = newOrigin;
this.dimensions = newDimensions;
this.origin = newOrigin;
}
drawLine(buf, color, points) {
let i;
let i;

this.setColor(color);
this.setColor(color);

// Configure context to draw two-pixel-thick lines
this.c2d.lineWidth = 1;
// Configure context to draw two-pixel-thick lines
this.c2d.lineWidth = 1;

// Start a new path...
if (buf.length > 1) {
this.c2d.beginPath();
this.c2d.moveTo(this.x(buf[0]), this.y(buf[1]));
}
// Start a new path...
if (buf.length > 1) {
this.c2d.beginPath();
this.c2d.moveTo(this.x(buf[0]), this.y(buf[1]));
}

// ...and add points to it...
for (i = 2; i < points * 2; i = i + 2) {
this.c2d.lineTo(this.x(buf[i]), this.y(buf[i + 1]));
}
// ...and add points to it...
for (i = 2; i < points * 2; i = i + 2) {
this.c2d.lineTo(this.x(buf[i]), this.y(buf[i + 1]));
}

// ...before finally drawing it.
this.c2d.stroke();
// ...before finally drawing it.
this.c2d.stroke();
}
drawSquare(min, max, color) {
const x1 = this.x(min[0]);
const y1 = this.y(min[1]);
const w = this.x(max[0]) - x1;
const h = this.y(max[1]) - y1;
const x1 = this.x(min[0]);
const y1 = this.y(min[1]);
const w = this.x(max[0]) - x1;
const h = this.y(max[1]) - y1;

this.setColor(color);
this.c2d.fillRect(x1, y1, w, h);
this.setColor(color);
this.c2d.fillRect(x1, y1, w, h);
}
drawPoints(buf, color, points, pointSize, shape) {
const drawC2DShape = MARKER_SHAPES[shape].drawC2D.bind(this);
const drawC2DShape = MARKER_SHAPES[shape].drawC2D.bind(this);

this.setColor(color);
this.setColor(color);

for (let i = 0; i < points; i++) {
drawC2DShape(this.x(buf[i * 2]), this.y(buf[i * 2 + 1]), pointSize);
}
for (let i = 0; i < points; i++) {
drawC2DShape(this.x(buf[i * 2]), this.y(buf[i * 2 + 1]), pointSize);
}
}
drawLimitPoint(x, y, size) {
this.c2d.fillRect(x + size, y, size, size);
this.c2d.fillRect(x, y + size, size, size);
this.c2d.fillRect(x - size, y, size, size);
this.c2d.fillRect(x, y - size, size, size);
this.c2d.fillRect(x + size, y, size, size);
this.c2d.fillRect(x, y + size, size, size);
this.c2d.fillRect(x - size, y, size, size);
this.c2d.fillRect(x, y - size, size, size);
}
drawLimitPoints(points, color, pointSize) {
const limitSize = pointSize * 2;
const offset = limitSize / 2;
const limitSize = pointSize * 2;
const offset = limitSize / 2;

this.setColor(color);
this.setColor(color);

for (let i = 0; i < points.length; i++) {
this.drawLimitPoint(this.x(points[i].x) - offset, this.y(points[i].y) - offset, limitSize);
}
for (let i = 0; i < points.length; i++) {
this.drawLimitPoint(this.x(points[i].x) - offset, this.y(points[i].y) - offset, limitSize);
}
}
}

Expand Down

0 comments on commit bede498

Please sign in to comment.