diff --git a/modules/line/line.js b/modules/line/line.js index ae8d9e4d..d224f63f 100644 --- a/modules/line/line.js +++ b/modules/line/line.js @@ -16,14 +16,10 @@ export default class Line extends Component { constructor (positionDefinition, points, options) { super(positionDefinition, options); - let positions; - try { - // Try to treat it as one position definition - positions = [Position.from(points)]; - } - catch (e) { - positions = points.map(point => Position.from(point)); - } + // Try to treat it as one position definition + const positions = points.slice(0, 2).every(n => n === undefined || typeof n === "number") ? + [Position.from(points)] : + points.map(point => Position.from(point)); /** * @type {Array} diff --git a/modules/line/line.test.js b/modules/line/line.test.js index 4745caf6..fa33a7eb 100644 --- a/modules/line/line.test.js +++ b/modules/line/line.test.js @@ -39,11 +39,8 @@ test("ishover", (t) => { test("toJSON", (t) => { const json = t.context.toJSON(); - t.deepEqual(json.position, [100, 50]); - t.deepEqual(json.points, [ - [150, 150], - [200, 200], - ]); + t.deepEqual(json.position, t.context.position); + t.deepEqual(json.points, t.context.points); t.is(json.constructor, "Line"); });