Skip to content

Commit

Permalink
refactor: Make some code simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Nov 19, 2024
1 parent af985cb commit ce38d21
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
6 changes: 2 additions & 4 deletions src/annotation/lineAnnotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ var lineAnnotation = function (args) {
line: function (d) {
/* Return an array that has the same number of items as we have
* vertices. */
return Array.apply(null, Array(m_this.options('vertices').length)).map(
function () { return d; });
return Array(m_this.options('vertices').length).fill(d);
},
position: function (d, i) {
return m_this.options('vertices')[i];
Expand All @@ -53,8 +52,7 @@ var lineAnnotation = function (args) {
line: function (d) {
/* Return an array that has the same number of items as we have
* vertices. */
return Array.apply(null, Array(m_this.options('vertices').length)).map(
function () { return d; });
return Array(m_this.options('vertices').length).fill(d);
},
position: function (d, i) {
return m_this.options('vertices')[i];
Expand Down
14 changes: 7 additions & 7 deletions src/annotation/polygonAnnotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ var polygonAnnotation = function (args) {
return new polygonAnnotation(args);
}

args = util.deepMerge({}, this.constructor.defaults, {
var m_this = this;

args = util.deepMerge({
style: {
polygon: function (d) { return d.polygon; }
},
Expand All @@ -52,26 +54,24 @@ var polygonAnnotation = function (args) {
const coord = m_this._coordinates();
/* Return an array that has the same number of items as we have
* vertices. */
return Array.apply(null, Array((coord.outer || coord).length)).map(
function () { return d; });
return Array((coord.outer || coord).length).fill(d);
},
position: function (d, i) {
if (d.x !== undefined) {
return d.x;
return d;

Check warning on line 61 in src/annotation/polygonAnnotation.js

View check run for this annotation

Codecov / codecov/patch

src/annotation/polygonAnnotation.js#L61

Added line #L61 was not covered by tests
}
return m_this.options('vertices')[i];
}
},
cursorStyle: {
position: util.identityFunction
}
}, args);
}, this.constructor.defaults, args);
args.vertices = args.vertices || args.coordinates || [];
delete args.coordinates;
annotation.call(this, 'polygon', args);

var m_this = this,
s_actions = this.actions,
var s_actions = this.actions,
s_state = this.state;

/**
Expand Down
12 changes: 6 additions & 6 deletions src/util/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1011,15 +1011,15 @@ var util = {
}
const copy = source[key];
if (copy && typeof copy === 'object' && (copy.constructor === Object || Array.isArray(copy))) {
let src = target[key];
let value = target[key];
if (!Array.isArray(copy)) {
if (typeof src !== 'object' || Array.isArray(src)) {
src = {};
if (typeof value !== 'object' || Array.isArray(value)) {
value = {};
}
} else if (!Array.isArray(src)) {
src = [];
} else if (!Array.isArray(value)) {
value = [];
}
target[key] = util.deepMerge(src, copy);
target[key] = util.deepMerge(value, copy);
} else if (copy !== undefined) {
target[key] = copy;
}
Expand Down

0 comments on commit ce38d21

Please sign in to comment.