Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
Clean up code with help of lint
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredwassermann committed May 29, 2018
1 parent 6965cd3 commit 7ce3b19
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 113 deletions.
5 changes: 3 additions & 2 deletions src/base/coordselement.js
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,8 @@ define([
* if the element is currently a glider, will remove the slideObject reference.
*/
free: function () {
var ancestorId, ancestor, child;
var ancestorId, ancestor;
// child;

if (this.type !== Const.OBJECT_TYPE_GLIDER) {
// remove all transformations
Expand Down Expand Up @@ -1160,7 +1161,7 @@ define([
* @see JXG.GeonextParser#geonext2JS
*/
addConstraint: function (terms) {
var fs, i, v, t,
var i, v,
newfuncs = [],
what = ['X', 'Y'],

Expand Down
20 changes: 10 additions & 10 deletions src/base/curve.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ define([
*/
hasPoint: function (x, y, start) {
var t, checkPoint, len, invMat, c,
i, j, tX, tY,
i, tX, tY,
res = [],
points, qdt,
steps = Type.evaluate(this.visProp.numberpointslow),
Expand Down Expand Up @@ -757,7 +757,7 @@ define([
},

updateTransformMatrix: function () {
var t, c, i,
var t, i,
len = this.transformations.length;

this.transformMat = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
Expand Down Expand Up @@ -820,7 +820,7 @@ define([
* @returns {JXG.Curve} Reference to the curve object.
*/
updateParametricCurveOld: function (mi, ma) {
var i, t, t0, d,
var i, t, d,
x, y, x0, y0, top, depth,
MAX_DEPTH, MAX_XDIST, MAX_YDIST,
suspendUpdate = false,
Expand Down Expand Up @@ -1124,8 +1124,7 @@ define([
t_nan, t_real, t_real2,
box,
vx, vy, vx2, vy2, dx, dy,
x, y,
asymptote, border, intersection;
asymptote;


if (depth <= 1) {
Expand Down Expand Up @@ -1459,7 +1458,7 @@ define([
var data = 'data' + which;

return function (t, suspendedUpdate) {
var i, j, f1, f2, z, t0, t1,
var i, j, t0, t1,
arr = this[data],
len = arr.length,
f = [];
Expand Down Expand Up @@ -2203,7 +2202,7 @@ define([
JXG.createCardinalSpline = function (board, parents, attributes) {
var el,
points, tau, type,
p, q, i, j, le,
p, q, i, le,
splineArr,
errStr = "\nPossible parent types: [points:array, tau:number|function, type:string]";

Expand Down Expand Up @@ -2482,7 +2481,7 @@ define([
c = board.create('curve', [[0], [0]], attr);

c.updateDataArray = function () {
var i, step, t, el, pEl, x, y, v, from, savetrace,
var i, step, t, el, pEl, x, y, from, savetrace,
le = attr.numberpoints,
savePos = glider.position,
slideObj = glider.slideObject,
Expand Down Expand Up @@ -2668,6 +2667,7 @@ define([
var c,
curve, dx, dy,
attr;

if (parents.length !== 1 && parents[0].class !== Const.OBJECT_CLASS_CURVE) {
throw new Error("JSXGraph: Can't create derivative curve with given parent'" +
"\nPossible parent types: [curve]");
Expand All @@ -2676,8 +2676,8 @@ define([
attr = Type.copyAttributes(attributes, board.options, 'curve');

curve = parents[0];
var dx = Numerics.D(curve.X);
var dy = Numerics.D(curve.Y);
dx = Numerics.D(curve.X);
dy = Numerics.D(curve.Y);

c = board.create('curve', [
function(t) { return curve.X(t); },
Expand Down
6 changes: 3 additions & 3 deletions src/base/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ define([
* })();
*
* </script><pre>
*
*
* @example
* var t = board.create('transform', [2, 1.5], {type: 'scale'});
* var l1 = board.create('line', [1, -5, 1]);
Expand Down Expand Up @@ -1519,7 +1519,7 @@ define([
},
function () {
var i = Math.floor(p.position),
p1, p2, q1, q2;
p1, p2;

if (i === c.numberPoints - 1) {
i--;
Expand All @@ -1538,7 +1538,7 @@ define([
},
function () {
var i = Math.floor(p.position),
p1, p2, q1, q2;
p1, p2;

if (i === c.numberPoints - 1) {
i--;
Expand Down
4 changes: 2 additions & 2 deletions src/base/point.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ define([
unit = Type.evaluate(this.visProp.sizeunit);

r = parseFloat(Type.evaluate(this.visProp.size));
if (unit == 'user') {
r *= Math.sqrt(this.board.unitX * this.board.unitY)
if (unit === 'user') {
r *= Math.sqrt(this.board.unitX * this.board.unitY);
}

r += parseFloat(Type.evaluate(this.visProp.strokewidth)) * 0.5;
Expand Down
4 changes: 2 additions & 2 deletions src/base/polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ define([
JXG.createPolygon = function (board, parents, attributes) {
var el, i, le, obj,
points = [],
attr, attr_points, p,
attr, attr_points,
is_transform = false;

attr = Type.copyAttributes(attributes, board.options, 'polygon');
Expand Down Expand Up @@ -1108,7 +1108,7 @@ define([
*/
JXG.createRegularPolygon = function (board, parents, attributes) {
var el, i, n,
p = [], rot, c, len, pointsExist, attr;
p = [], rot, len, pointsExist, attr;

len = parents.length;
n = parents[len - 1];
Expand Down
28 changes: 5 additions & 23 deletions src/element/arc.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ define([
* a = board.create('arc', [p1, p2, p3]);
* })();
* </script><pre>
*
*
* @example
* var t = board.create('transform', [2, 1.5], {type: 'scale'});
* var a1 = board.create('arc', [[1, 1], [0, 1], [1, 0]], {strokeColor: 'red'});
Expand All @@ -110,27 +110,9 @@ define([
*
*/
JXG.createArc = function (board, parents, attributes) {
var el, attr, i, points, obj, tmp;

obj = board.select(parents[0]);
// if (Type.isObject(obj) && obj.type === Const.OBJECT_TYPE_ARC &&
// Type.isTransformationOrArray(parents[1])) {
//
// //
// //
// tmp = obj.type;
// obj.type = Const.OBJECT_TYPE_CURVE;
// el = JXG.createCurve(board, [obj, parents[1]], attributes);
// obj.type = tmp;
//
// return el;
//
// } else {
// This method is used to create circumcirclearcs, too.
// If a circumcirclearc is created we get a fourth
// point, that's why we need to check that case, too.
points = Type.providePoints(board, parents, attributes, 'arc', ['center', 'radiuspoint', 'anglepoint']);
// }
var el, attr, points;

points = Type.providePoints(board, parents, attributes, 'arc', ['center', 'radiuspoint', 'anglepoint']);
if (points === false || points.length < 3) {
throw new Error("JSXGraph: Can't create Arc with parent types '" +
(typeof parents[0]) + "' and '" + (typeof parents[1]) + "' and '" +
Expand Down Expand Up @@ -186,7 +168,7 @@ define([

// documented in JXG.Curve
el.updateDataArray = function () {
var ar, phi, v, det, p0c, p1c, p2c,
var ar, phi, det, p0c, p1c, p2c,
sgn = 1,
A = this.radiuspoint,
B = this.center,
Expand Down
6 changes: 3 additions & 3 deletions src/element/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ define([

Env.addEvent(t.rendNodeButton, 'click', priv.ButtonClickEventHandler, t);

Env.addEvent(t.rendNodeButton, 'mousedown', function(evt) { if (Type.exists(evt.stopPropagation)) evt.stopPropagation(); }, t);
Env.addEvent(t.rendNodeButton, 'touchstart', function(evt) { if (Type.exists(evt.stopPropagation)) evt.stopPropagation(); }, t);
Env.addEvent(t.rendNodeButton, 'pointerdown', function(evt) { if (Type.exists(evt.stopPropagation)) evt.stopPropagation(); }, t);
Env.addEvent(t.rendNodeButton, 'mousedown', function (evt) { if (Type.exists(evt.stopPropagation)) evt.stopPropagation(); }, t);
Env.addEvent(t.rendNodeButton, 'touchstart', function (evt) { if (Type.exists(evt.stopPropagation)) evt.stopPropagation(); }, t);
Env.addEvent(t.rendNodeButton, 'pointerdown', function (evt) { if (Type.exists(evt.stopPropagation)) evt.stopPropagation(); }, t);

return t;
};
Expand Down
20 changes: 10 additions & 10 deletions src/element/comb.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ define([

"use strict";

// TODO Example with endpoints attached to X axis?
/**
* @class A comb to display domains of inequalities.
* @pseudo
Expand Down Expand Up @@ -92,7 +91,8 @@ define([
*
*/
JXG.createComb = function(board, parents, attributes) {
var p1, p2, c, attr;
var p1, p2, c, attr, parent_types,
ds, angle, width, p;

if (parents.length === 2) {
// point 1 given by coordinates
Expand Down Expand Up @@ -129,7 +129,7 @@ define([
"\nPossible parent types: [point,point], [[x1,y1],[x2,y2]]");
}
} else {
var parent_types = parents.map(function(parent) { return "'" + (typeof parent) + "'"; });
parent_types = parents.map(function(parent) { return "'" + (typeof parent) + "'"; });
throw new Error("JSXGraph: Can't create comb with parent types " +
parent_types.join(", ") + "." +
"\nPossible parent types: [point,point], [[x1,y1],[x2,y2]]");
Expand All @@ -139,11 +139,11 @@ define([
c = board.create('curve', [[0], [0]], attr);

attr = Type.copyAttributes(attributes, board.options, 'comb');
var ds = attr.frequency;
var angle = -attr.angle;
var width = attr.width;
ds = attr.frequency;
angle = -attr.angle;
width = attr.width;
if (attr.reverse) {
var p = p1;
p = p1;
p1 = p2;
p2 = p;
angle = -angle;
Expand All @@ -156,7 +156,7 @@ define([
sn = Math.sin(angle),
dx = (p2.X() - p1.X()) / max_s,
dy = (p2.Y() - p1.Y()) / max_s,
f;
x, y, f;

// But instead of lifting by sin(angle), we want lifting by width.
cs *= width / Math.abs(sn);
Expand All @@ -166,8 +166,8 @@ define([
this.dataY = [];
// TODO Handle infinite boundaries?
while (s < max_s) {
var x = p1.X() + dx * s;
var y = p1.Y() + dy * s;
x = p1.X() + dx * s;
y = p1.Y() + dy * s;

// We may need to cut the last piece of a comb.
f = Math.min(cs, max_s - s) / Math.abs(cs);
Expand Down
9 changes: 4 additions & 5 deletions src/element/composition.js
Original file line number Diff line number Diff line change
Expand Up @@ -2655,11 +2655,10 @@ define([
};
a.updateDataArray = function () {
var bb = this.board.getBoundingBox(),
factor = attr.inverse ? -1 : 1,
expansion = 1.5,
// inverse == true <=> y >= f(x)
hline = expansion * (attr.inverse ? bb[1] : bb[3]),
i, le;
expansion = 1.5,
// inverse == true <=> y >= f(x)
hline = expansion * (attr.inverse ? bb[1] : bb[3]),
i, le;

this.dataX = [];
this.dataY = [];
Expand Down
Loading

0 comments on commit 7ce3b19

Please sign in to comment.