aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbob <bcz@cs.brown.edu>2020-01-09 10:04:24 -0500
committerbob <bcz@cs.brown.edu>2020-01-09 10:04:24 -0500
commit540bda7295f6ee7c2eed848598de6f5df74b2723 (patch)
tree33ae259c81cfa2fd1caebff5f82acbe4ccb55133 /src
parent040cb79d01e3c9fcd7c5fb3777de4b2014414449 (diff)
fixed many warnings
Diffstat (limited to 'src')
-rw-r--r--src/client/util/TooltipTextMenu.tsx4
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx12
-rw-r--r--src/client/views/nodes/DocumentView.tsx1
-rw-r--r--src/pen-gestures/ndollar.ts122
4 files changed, 71 insertions, 68 deletions
diff --git a/src/client/util/TooltipTextMenu.tsx b/src/client/util/TooltipTextMenu.tsx
index 8aa304fad..e56930624 100644
--- a/src/client/util/TooltipTextMenu.tsx
+++ b/src/client/util/TooltipTextMenu.tsx
@@ -80,7 +80,7 @@ export class TooltipTextMenu {
span.appendChild(svg);
return span;
- }
+ };
const basicItems = [ // init basicItems in minimized toolbar -- paths to svgs are obtained from fontawesome
{ mark: schema.marks.strong, dom: svgIcon("strong", "Bold", "M333.49 238a122 122 0 0 0 27-65.21C367.87 96.49 308 32 233.42 32H34a16 16 0 0 0-16 16v48a16 16 0 0 0 16 16h31.87v288H34a16 16 0 0 0-16 16v48a16 16 0 0 0 16 16h209.32c70.8 0 134.14-51.75 141-122.4 4.74-48.45-16.39-92.06-50.83-119.6zM145.66 112h87.76a48 48 0 0 1 0 96h-87.76zm87.76 288h-87.76V288h87.76a56 56 0 0 1 0 112z") },
@@ -883,7 +883,7 @@ export class TooltipTextMenu {
if (!lastState || !lastState.doc.eq(view.state.doc) || !lastState.selection.eq(view.state.selection)) {
// UPDATE LINK DROPDOWN
- const linkTarget = await this.getTextLinkTargetTitle()
+ const linkTarget = await this.getTextLinkTargetTitle();
const linkDom = this.createLinkTool(linkTarget ? true : false).render(this.view).dom;
const linkDropdownDom = this.createLinkDropdown(linkTarget).render(this.view).dom;
this.linkDom && this.tooltip.replaceChild(linkDom, this.linkDom);
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx
index 178a5bcdc..b8fbaef5c 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx
@@ -54,8 +54,8 @@ export class CollectionFreeFormLinkView extends React.Component<CollectionFreeFo
} else {
setTimeout(() => {
(this.props.A.props.Document[(this.props.A.props as any).fieldKey] as Doc);
- let m = targetBhyperlink.getBoundingClientRect();
- let mp = this.props.A.props.ScreenToLocalTransform().transformPoint(m.right, m.top + 5);
+ const m = targetBhyperlink.getBoundingClientRect();
+ const mp = this.props.A.props.ScreenToLocalTransform().transformPoint(m.right, m.top + 5);
this.props.A.props.Document[afield + "_x"] = mp[0] / this.props.A.props.PanelWidth() * 100;
this.props.A.props.Document[afield + "_y"] = mp[1] / this.props.A.props.PanelHeight() * 100;
}, 0);
@@ -66,8 +66,8 @@ export class CollectionFreeFormLinkView extends React.Component<CollectionFreeFo
} else {
setTimeout(() => {
(this.props.B.props.Document[(this.props.B.props as any).fieldKey] as Doc);
- let m = targetAhyperlink.getBoundingClientRect();
- let mp = this.props.B.props.ScreenToLocalTransform().transformPoint(m.right, m.top + 5);
+ const m = targetAhyperlink.getBoundingClientRect();
+ const mp = this.props.B.props.ScreenToLocalTransform().transformPoint(m.right, m.top + 5);
this.props.B.props.Document[afield + "_x"] = mp[0] / this.props.B.props.PanelWidth() * 100;
this.props.B.props.Document[afield + "_y"] = mp[1] / this.props.B.props.PanelHeight() * 100;
}, 0);
@@ -93,8 +93,8 @@ export class CollectionFreeFormLinkView extends React.Component<CollectionFreeFo
apt.point.x, apt.point.y);
const pt1 = [apt.point.x, apt.point.y];
const pt2 = [bpt.point.x, bpt.point.y];
- let aActive = this.props.A.isSelected() || Doc.IsBrushed(this.props.A.props.Document);
- let bActive = this.props.A.isSelected() || Doc.IsBrushed(this.props.A.props.Document);
+ const aActive = this.props.A.isSelected() || Doc.IsBrushed(this.props.A.props.Document);
+ const bActive = this.props.A.isSelected() || Doc.IsBrushed(this.props.A.props.Document);
return !aActive && !bActive ? (null) :
<line key="linkLine" className="collectionfreeformlinkview-linkLine"
style={{ opacity: this._opacity, strokeDasharray: "2 2" }}
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index a14f69f71..10d2e2b3e 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -253,7 +253,6 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
document.removeEventListener("touchend", this.onTouchEnd);
document.addEventListener("touchend", this.onTouchEnd);
if ((e.nativeEvent as any).formattedHandled) e.stopPropagation();
- console.log("down")
}
}
diff --git a/src/pen-gestures/ndollar.ts b/src/pen-gestures/ndollar.ts
index 12c2b25bb..872c524d6 100644
--- a/src/pen-gestures/ndollar.ts
+++ b/src/pen-gestures/ndollar.ts
@@ -95,7 +95,7 @@ export class Unistroke {
constructor(public Name: string, useBoundedRotationInvariance: boolean, points: Point[]) {
this.Points = Resample(points, NumPoints);
- var radians = IndicativeAngle(this.Points);
+ const radians = IndicativeAngle(this.Points);
this.Points = RotateBy(this.Points, -radians);
this.Points = ScaleDimTo(this.Points, SquareSize, OneDThreshold);
if (useBoundedRotationInvariance) {
@@ -117,14 +117,14 @@ export class Multistroke {
{
this.NumStrokes = strokes.length; // number of individual strokes
- var order = new Array(strokes.length); // array of integer indices
+ const order = new Array(strokes.length); // array of integer indices
for (var i = 0; i < strokes.length; i++) {
order[i] = i; // initialize
}
- var orders = new Array(); // array of integer arrays
+ const orders = new Array(); // array of integer arrays
HeapPermute(strokes.length, order, /*out*/ orders);
- var unistrokes = MakeUnistrokes(strokes, orders); // returns array of point arrays
+ const unistrokes = MakeUnistrokes(strokes, orders); // returns array of point arrays
this.Unistrokes = new Array(unistrokes.length); // unistrokes for this multistroke
for (var j = 0; j < unistrokes.length; j++) {
this.Unistrokes[j] = new Unistroke(this.Name, useBoundedRotationInvariance, unistrokes[j]);
@@ -247,15 +247,15 @@ export class NDollarRecognizer {
}
Recognize = (strokes: any[], useBoundedRotationInvariance: boolean = false, requireSameNoOfStrokes: boolean = false, useProtractor: boolean = true) => {
- var t0 = Date.now();
- var points = CombineStrokes(strokes); // make one connected unistroke from the given strokes
- var candidate = new Unistroke("", useBoundedRotationInvariance, points);
+ const t0 = Date.now();
+ const points = CombineStrokes(strokes); // make one connected unistroke from the given strokes
+ const candidate = new Unistroke("", useBoundedRotationInvariance, points);
var u = -1;
var b = +Infinity;
for (var i = 0; i < this.Multistrokes.length; i++) // for each multistroke template
{
- if (!requireSameNoOfStrokes || strokes.length == this.Multistrokes[i].NumStrokes) // optional -- only attempt match when same # of component strokes
+ if (!requireSameNoOfStrokes || strokes.length === this.Multistrokes[i].NumStrokes) // optional -- only attempt match when same # of component strokes
{
for (var j = 0; j < this.Multistrokes[i].Unistrokes.length; j++) // for each unistroke within this multistroke
{
@@ -276,15 +276,15 @@ export class NDollarRecognizer {
}
}
}
- var t1 = Date.now();
- return (u == -1) ? null : new Result(this.Multistrokes[u].Name, useProtractor ? (1.0 - b) : (1.0 - b / HalfDiagonal), t1 - t0);
+ const t1 = Date.now();
+ return (u === -1) ? null : new Result(this.Multistrokes[u].Name, useProtractor ? (1.0 - b) : (1.0 - b / HalfDiagonal), t1 - t0);
}
AddGesture = (name: string, useBoundedRotationInvariance: boolean, strokes: any[]) => {
this.Multistrokes[this.Multistrokes.length] = new Multistroke(name, useBoundedRotationInvariance, strokes);
var num = 0;
for (var i = 0; i < this.Multistrokes.length; i++) {
- if (this.Multistrokes[i].Name == name) {
+ if (this.Multistrokes[i].Name === name) {
num++;
}
}
@@ -302,17 +302,17 @@ export class NDollarRecognizer {
// Private helper functions from here on down
//
function HeapPermute(n: number, order: any[], /*out*/ orders: any[]) {
- if (n == 1) {
+ if (n === 1) {
orders[orders.length] = order.slice(); // append copy
} else {
for (var i = 0; i < n; i++) {
HeapPermute(n - 1, order, orders);
- if (n % 2 == 1) { // swap 0, n-1
- var tmp = order[0];
+ if (n % 2 === 1) { // swap 0, n-1
+ const tmp = order[0];
order[0] = order[n - 1];
order[n - 1] = tmp;
} else { // swap i, n-1
- var tmp = order[i];
+ const tmp = order[i];
order[i] = order[n - 1];
order[n - 1] = tmp;
}
@@ -321,14 +321,14 @@ function HeapPermute(n: number, order: any[], /*out*/ orders: any[]) {
}
function MakeUnistrokes(strokes: any, orders: any) {
- var unistrokes = new Array(); // array of point arrays
+ const unistrokes = new Array(); // array of point arrays
for (var r = 0; r < orders.length; r++) {
for (var b = 0; b < Math.pow(2, orders[r].length); b++) // use b's bits for directions
{
- var unistroke = new Array(); // array of points
+ const unistroke = new Array(); // array of points
for (var i = 0; i < orders[r].length; i++) {
var pts;
- if (((b >> i) & 1) == 1) {// is b's bit at index i on?
+ if (((b >> i) & 1) === 1) {// is b's bit at index i on?
pts = strokes[orders[r][i]].slice().reverse(); // copy and reverse
}
else {
@@ -345,69 +345,71 @@ function MakeUnistrokes(strokes: any, orders: any) {
}
function CombineStrokes(strokes: any) {
- var points = new Array();
+ const points = new Array();
for (var s = 0; s < strokes.length; s++) {
- for (var p = 0; p < strokes[s].length; p++)
+ for (var p = 0; p < strokes[s].length; p++) {
points[points.length] = new Point(strokes[s][p].X, strokes[s][p].Y);
+ }
}
return points;
}
function Resample(points: any, n: any) {
- var I = PathLength(points) / (n - 1); // interval length
+ const I = PathLength(points) / (n - 1); // interval length
var D = 0.0;
- var newpoints = new Array(points[0]);
+ const newpoints = new Array(points[0]);
for (var i = 1; i < points.length; i++) {
- var d = Distance(points[i - 1], points[i]);
+ const d = Distance(points[i - 1], points[i]);
if ((D + d) >= I) {
- var qx = points[i - 1].X + ((I - D) / d) * (points[i].X - points[i - 1].X);
- var qy = points[i - 1].Y + ((I - D) / d) * (points[i].Y - points[i - 1].Y);
- var q = new Point(qx, qy);
+ const qx = points[i - 1].X + ((I - D) / d) * (points[i].X - points[i - 1].X);
+ const qy = points[i - 1].Y + ((I - D) / d) * (points[i].Y - points[i - 1].Y);
+ const q = new Point(qx, qy);
newpoints[newpoints.length] = q; // append new point 'q'
points.splice(i, 0, q); // insert 'q' at position i in points s.t. 'q' will be the next i
D = 0.0;
}
else D += d;
}
- if (newpoints.length == n - 1) // somtimes we fall a rounding-error short of adding the last point, so add it if so
+ if (newpoints.length === n - 1) {// sometimes we fall a rounding-error short of adding the last point, so add it if so
newpoints[newpoints.length] = new Point(points[points.length - 1].X, points[points.length - 1].Y);
+ }
return newpoints;
}
function IndicativeAngle(points: any) {
- var c = Centroid(points);
+ const c = Centroid(points);
return Math.atan2(c.Y - points[0].Y, c.X - points[0].X);
}
function RotateBy(points: any, radians: any) // rotates points around centroid
{
- var c = Centroid(points);
- var cos = Math.cos(radians);
- var sin = Math.sin(radians);
- var newpoints = new Array();
+ const c = Centroid(points);
+ const cos = Math.cos(radians);
+ const sin = Math.sin(radians);
+ const newpoints = new Array();
for (var i = 0; i < points.length; i++) {
- var qx = (points[i].X - c.X) * cos - (points[i].Y - c.Y) * sin + c.X
- var qy = (points[i].X - c.X) * sin + (points[i].Y - c.Y) * cos + c.Y;
+ const qx = (points[i].X - c.X) * cos - (points[i].Y - c.Y) * sin + c.X;
+ const qy = (points[i].X - c.X) * sin + (points[i].Y - c.Y) * cos + c.Y;
newpoints[newpoints.length] = new Point(qx, qy);
}
return newpoints;
}
function ScaleDimTo(points: any, size: any, ratio1D: any) // scales bbox uniformly for 1D, non-uniformly for 2D
{
- var B = BoundingBox(points);
- var uniformly = Math.min(B.Width / B.Height, B.Height / B.Width) <= ratio1D; // 1D or 2D gesture test
- var newpoints = new Array();
+ const B = BoundingBox(points);
+ const uniformly = Math.min(B.Width / B.Height, B.Height / B.Width) <= ratio1D; // 1D or 2D gesture test
+ const newpoints = new Array();
for (var i = 0; i < points.length; i++) {
- var qx = uniformly ? points[i].X * (size / Math.max(B.Width, B.Height)) : points[i].X * (size / B.Width);
- var qy = uniformly ? points[i].Y * (size / Math.max(B.Width, B.Height)) : points[i].Y * (size / B.Height);
+ const qx = uniformly ? points[i].X * (size / Math.max(B.Width, B.Height)) : points[i].X * (size / B.Width);
+ const qy = uniformly ? points[i].Y * (size / Math.max(B.Width, B.Height)) : points[i].Y * (size / B.Height);
newpoints[newpoints.length] = new Point(qx, qy);
}
return newpoints;
}
function TranslateTo(points: any, pt: any) // translates points' centroid
{
- var c = Centroid(points);
- var newpoints = new Array();
+ const c = Centroid(points);
+ const newpoints = new Array();
for (var i = 0; i < points.length; i++) {
- var qx = points[i].X + pt.X - c.X;
- var qy = points[i].Y + pt.Y - c.Y;
+ const qx = points[i].X + pt.X - c.X;
+ const qy = points[i].Y + pt.Y - c.Y;
newpoints[newpoints.length] = new Point(qx, qy);
}
return newpoints;
@@ -417,21 +419,21 @@ function Vectorize(points: any, useBoundedRotationInvariance: any) // for Protra
var cos = 1.0;
var sin = 0.0;
if (useBoundedRotationInvariance) {
- var iAngle = Math.atan2(points[0].Y, points[0].X);
- var baseOrientation = (Math.PI / 4.0) * Math.floor((iAngle + Math.PI / 8.0) / (Math.PI / 4.0));
+ const iAngle = Math.atan2(points[0].Y, points[0].X);
+ const baseOrientation = (Math.PI / 4.0) * Math.floor((iAngle + Math.PI / 8.0) / (Math.PI / 4.0));
cos = Math.cos(baseOrientation - iAngle);
sin = Math.sin(baseOrientation - iAngle);
}
var sum = 0.0;
- var vector = new Array<number>();
+ const vector = new Array<number>();
for (var i = 0; i < points.length; i++) {
- var newX = points[i].X * cos - points[i].Y * sin;
- var newY = points[i].Y * cos + points[i].X * sin;
+ const newX = points[i].X * cos - points[i].Y * sin;
+ const newY = points[i].Y * cos + points[i].X * sin;
vector[vector.length] = newX;
vector[vector.length] = newY;
sum += newX * newX + newY * newY;
}
- var magnitude = Math.sqrt(sum);
+ const magnitude = Math.sqrt(sum);
for (var i = 0; i < vector.length; i++) {
vector[i] /= magnitude;
}
@@ -445,7 +447,7 @@ function OptimalCosineDistance(v1: any, v2: any) // for Protractor
a += v1[i] * v2[i] + v1[i + 1] * v2[i + 1];
b += v1[i] * v2[i + 1] - v1[i + 1] * v2[i];
}
- var angle = Math.atan(b / a);
+ const angle = Math.atan(b / a);
return Math.acos(a * Math.cos(angle) + b * Math.sin(angle));
}
function DistanceAtBestAngle(points: any, T: any, a: any, b: any, threshold: any) {
@@ -471,7 +473,7 @@ function DistanceAtBestAngle(points: any, T: any, a: any, b: any, threshold: any
return Math.min(f1, f2);
}
function DistanceAtAngle(points: any, T: any, radians: any) {
- var newpoints = RotateBy(points, radians);
+ const newpoints = RotateBy(points, radians);
return PathDistance(newpoints, T.Points);
}
function Centroid(points: any) {
@@ -497,33 +499,35 @@ function BoundingBox(points: any) {
function PathDistance(pts1: any, pts2: any) // average distance between corresponding points in two paths
{
var d = 0.0;
- for (var i = 0; i < pts1.length; i++) // assumes pts1.length == pts2.length
+ for (var i = 0; i < pts1.length; i++) {// assumes pts1.length == pts2.length
d += Distance(pts1[i], pts2[i]);
+ }
return d / pts1.length;
}
function PathLength(points: any) // length traversed by a point path
{
var d = 0.0;
- for (var i = 1; i < points.length; i++)
+ for (var i = 1; i < points.length; i++) {
d += Distance(points[i - 1], points[i]);
+ }
return d;
}
function Distance(p1: any, p2: any) // distance between two points
{
- var dx = p2.X - p1.X;
- var dy = p2.Y - p1.Y;
+ const dx = p2.X - p1.X;
+ const dy = p2.Y - p1.Y;
return Math.sqrt(dx * dx + dy * dy);
}
function CalcStartUnitVector(points: any, index: any) // start angle from points[0] to points[index] normalized as a unit vector
{
- var v = new Point(points[index].X - points[0].X, points[index].Y - points[0].Y);
- var len = Math.sqrt(v.X * v.X + v.Y * v.Y);
+ const v = new Point(points[index].X - points[0].X, points[index].Y - points[0].Y);
+ const len = Math.sqrt(v.X * v.X + v.Y * v.Y);
return new Point(v.X / len, v.Y / len);
}
function AngleBetweenUnitVectors(v1: any, v2: any) // gives acute angle between unit vectors from (0,0) to v1, and (0,0) to v2
{
- var n = (v1.X * v2.X + v1.Y * v2.Y);
- var c = Math.max(-1.0, Math.min(1.0, n)); // ensure [-1,+1]
+ const n = (v1.X * v2.X + v1.Y * v2.Y);
+ const c = Math.max(-1.0, Math.min(1.0, n)); // ensure [-1,+1]
return Math.acos(c); // arc cosine of the vector dot product
}
function Deg2Rad(d: any) { return (d * Math.PI / 180.0); } \ No newline at end of file