Skip to content

Commit

Permalink
feat(models): add ShapePath model with convenience constructor in Sha…
Browse files Browse the repository at this point in the history
…peGroup (#17)
  • Loading branch information
Kevin Goedecke authored and dbanksdesign committed Jul 23, 2019
1 parent d5453a5 commit 9954aec
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 0 deletions.
24 changes: 24 additions & 0 deletions models/ShapeGroup/ShapeGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
const uuid = require('uuid-v4');
const Layer = require('../Layer');
const Rectangle = require('../Rectangle');
const ShapePath = require('../ShapePath');
const Oval = require('../Oval');
const Rect = require('../Rect');
const Style = require('../Style');
Expand Down Expand Up @@ -76,6 +77,29 @@ class ShapeGroup extends Layer {
],
});
}

static ShapePath(args) {
return new this({
name: args.name,
id: args.id,
style: args.style,
frame: {
x: args.x,
y: args.y,
width: args.width,
height: args.height,
},
layers: [
new ShapePath({
x: 0,
y: 0,
width: args.width,
height: args.height,
points: args.points,
}),
],
});
}
}

ShapeGroup.Model = Object.assign({}, Layer.Model, {
Expand Down
70 changes: 70 additions & 0 deletions models/ShapePath/ShapePath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

const uuid = require('uuid-v4');
const Layer = require('../Layer');
const Rect = require('../Rect');
const Style = require('../Style');

/**
*
*/
class ShapePath extends Layer {
/**
*
* @param {Object} args
* @param {String} args.name
* @param {integer} args.x
* @param {integer} args.y
* @param {integer} args.height
* @param {integer} args.width
* @param {Array.<CurvePoint>} args.points
* @param {Object} args.style Passed to {@link LayerStyle}
* @param {ShapePath.Model} json
*/
constructor(args = {}, json) {
super(args, json);
if (!json) {
const id = args.id || uuid().toUpperCase();
Object.assign(this, ShapePath.Model, {
points: args.points || [],
do_objectID: id,
frame: new Rect({
x: args.x,
y: args.y,
width: args.width,
height: args.height,
}),
style: new Style(args.style),
name: args.name || id,
});
}
}
}

/**
* @mixes Layer.Model
* @property {boolean} edited
* @property {boolean} isClosed
* @property {integer} pointRadiusBehaviour
* @property {String[]} points
*/
ShapePath.Model = Object.assign({}, Layer.Model, {
_class: 'shapePath',
edited: true,
isClosed: false,
pointRadiusBehaviour: 1,
points: [],
});

module.exports = ShapePath;
22 changes: 22 additions & 0 deletions models/ShapePath/ShapePath.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

const ShapePath = require('./index');

const json = {};

describe('ShapePath', () => {
it('should work from raw JSON', () => {
expect(true).toBeTruthy();
});
});
14 changes: 14 additions & 0 deletions models/ShapePath/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

module.exports = require('./ShapePath');
1 change: 1 addition & 0 deletions models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = {
RulerData: require('./RulerData'),
Shadow: require('./Shadow'),
ShapeGroup: require('./ShapeGroup'),
ShapePath: require('./ShapePath'),
SharedStyle: require('./SharedStyle'),
Sketch: require('./Sketch'),
Style: require('./Style'),
Expand Down

0 comments on commit 9954aec

Please sign in to comment.