From 754495d2519bf10e8f0cc96604d4913bf1a10ce2 Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Fri, 7 Jun 2019 08:16:45 -0500 Subject: [PATCH 01/15] =?UTF-8?q?=F0=9F=9B=A0=20add=20toJSON()=20method=20?= =?UTF-8?q?to=20vector=20and=20anchor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/anchor.js | 30 ++++++++++++++++++++++++++++++ js/vector.js | 22 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/js/anchor.js b/js/anchor.js index 0744810..e1723df 100644 --- a/js/anchor.js +++ b/js/anchor.js @@ -212,6 +212,36 @@ Anchor.prototype.normalizeRotate = function() { this.rotate.y = utils.modulo( this.rotate.y, TAU ); this.rotate.z = utils.modulo( this.rotate.z, TAU ); }; + +Anchor.prototype.toJSON = function () { + var result = {}; + var optionKeys = this.constructor.optionKeys; + + [...optionKeys, 'children'].forEach(function (key) { + if (['addTo', 'dragRotate', 'element', 'resize'].includes(key)) return; + var value = this[key]; + var defaults = this.constructor.defaults; + + if (!['undefined', 'function'].includes(typeof value) && value !== defaults[key]) { + if (Array.isArray(value) && value.length === 0) { + return; + } + if (value.toJSON) { + var serialized = value.toJSON(); + if (typeof serialized !== 'undefined') { + if (key === 'scale' && serialized === 1) { + return; + } + result[key] = serialized; + } + } else { + result[key] = value; + } + } + }, this); + + return result; +}; // ----- subclass ----- // diff --git a/js/vector.js b/js/vector.js index b896526..aa120d4 100644 --- a/js/vector.js +++ b/js/vector.js @@ -148,6 +148,28 @@ Vector.prototype.magnitude2d = function() { Vector.prototype.copy = function() { return new Vector( this ); }; + +Vector.prototype.toJSON = function() { + var x = this.x; + var y = this.y; + var z = this.z; + + if ( x === y && y === z ) { + return ( x !== 0 ) ? x : undefined; + } + + var obj = { x: x, y: y, z: z }; + var result = {}; + + Object.keys( obj ).forEach( function ( key ) { + var value = obj[ key ]; + if ( value !== 0 ) { + result[ key ] = value; + } + }) + + return Object.keys( result ).length ? result : undefined; +}; return Vector; From 686e90a675f2fc48ecb5863711c7df28c6fd564e Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Fri, 7 Jun 2019 08:53:25 -0500 Subject: [PATCH 02/15] =?UTF-8?q?=F0=9F=9B=A0=20add=20type=20property=20to?= =?UTF-8?q?=20all=20primitives?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/anchor.js | 12 +++++++++--- js/box.js | 5 ++++- js/cone.js | 2 ++ js/cylinder.js | 5 +++++ js/ellipse.js | 2 ++ js/group.js | 3 +++ js/hemisphere.js | 2 ++ js/illustration.js | 2 ++ js/polygon.js | 2 ++ js/rect.js | 2 ++ js/rounded-rect.js | 2 ++ js/shape.js | 2 ++ 12 files changed, 37 insertions(+), 4 deletions(-) diff --git a/js/anchor.js b/js/anchor.js index e1723df..1de5410 100644 --- a/js/anchor.js +++ b/js/anchor.js @@ -214,10 +214,16 @@ Anchor.prototype.normalizeRotate = function() { }; Anchor.prototype.toJSON = function () { - var result = {}; - var optionKeys = this.constructor.optionKeys; + var type = this.type; + var ignoreChildren = this.ignoreChildren || false; + var result = { type: type }; + var optionKeys = [...this.constructor.optionKeys]; + + if (!ignoreChildren) { + optionKeys = [...optionKeys, 'children']; + } - [...optionKeys, 'children'].forEach(function (key) { + optionKeys.forEach(function ( key ) { if (['addTo', 'dragRotate', 'element', 'resize'].includes(key)) return; var value = this[key]; var defaults = this.constructor.defaults; diff --git a/js/box.js b/js/box.js index 4f8735f..7d428da 100644 --- a/js/box.js +++ b/js/box.js @@ -18,9 +18,10 @@ // ----- BoxRect ----- // var BoxRect = Rect.subclass(); + // prevent double-creation in parent.copyGraph() // only create in Box.create() -BoxRect.prototype.copyGraph = function() {}; +BoxRect.prototype.copyGraph = function () { }; // ----- Box ----- // @@ -40,6 +41,8 @@ boxDefaults.fill = true; delete boxDefaults.path; var Box = Anchor.subclass( boxDefaults ); +Box.prototype.type = 'Box'; +Box.prototype.ignoreChildren = true; var TAU = utils.TAU; diff --git a/js/cone.js b/js/cone.js index 4535e5a..4b602ee 100644 --- a/js/cone.js +++ b/js/cone.js @@ -20,6 +20,8 @@ var Cone = Ellipse.subclass({ length: 1, fill: true, }); + +Cone.prototype.type = 'Cone'; var TAU = utils.TAU; diff --git a/js/cylinder.js b/js/cylinder.js index cc2a4f0..8e4ea85 100644 --- a/js/cylinder.js +++ b/js/cylinder.js @@ -25,6 +25,8 @@ var CylinderGroup = Group.subclass({ color: '#333', updateSort: true, }); + +CylinderGroup.prototype.type = 'CylinderGroup'; CylinderGroup.prototype.create = function() { Group.prototype.create.apply( this, arguments ); @@ -96,6 +98,9 @@ var Cylinder = Shape.subclass({ frontFace: undefined, fill: true, }); + +Cylinder.prototype.type = 'Cylinder'; + var TAU = utils.TAU; diff --git a/js/ellipse.js b/js/ellipse.js index fafbe98..9ae7bb6 100644 --- a/js/ellipse.js +++ b/js/ellipse.js @@ -22,6 +22,8 @@ var Ellipse = Shape.subclass({ quarters: 4, closed: false, }); + +Ellipse.prototype.type = 'Ellipse'; Ellipse.prototype.setPath = function() { var width = this.width != undefined ? this.width : this.diameter; diff --git a/js/group.js b/js/group.js index ffafb84..7740b5c 100644 --- a/js/group.js +++ b/js/group.js @@ -18,6 +18,9 @@ var Group = Anchor.subclass({ updateSort: false, visible: true, }); + +Group.prototype.type = 'Group'; + // ----- update ----- // diff --git a/js/hemisphere.js b/js/hemisphere.js index fa92c4e..6fd1a16 100644 --- a/js/hemisphere.js +++ b/js/hemisphere.js @@ -17,6 +17,8 @@ var Hemisphere = Ellipse.subclass({ fill: true, }); + +Hemisphere.prototype.type = 'Hemisphere'; var TAU = utils.TAU; diff --git a/js/illustration.js b/js/illustration.js index a8751bb..dbda72e 100644 --- a/js/illustration.js +++ b/js/illustration.js @@ -30,6 +30,8 @@ var Illustration = Anchor.subclass({ onDragEnd: noop, onResize: noop, }); + +Illustration.prototype.type = 'Illustration'; utils.extend( Illustration.prototype, Dragger.prototype ); diff --git a/js/polygon.js b/js/polygon.js index a3ea770..8ed0a3b 100644 --- a/js/polygon.js +++ b/js/polygon.js @@ -18,6 +18,8 @@ var Polygon = Shape.subclass({ sides: 3, radius: 0.5, }); + +Polygon.prototype.type = 'Polygon'; var TAU = utils.TAU; diff --git a/js/rect.js b/js/rect.js index 9e69542..16b935f 100644 --- a/js/rect.js +++ b/js/rect.js @@ -18,6 +18,8 @@ var Rect = Shape.subclass({ width: 1, height: 1, }); + +Rect.prototype.type = 'Rect'; Rect.prototype.setPath = function() { var x = this.width / 2; diff --git a/js/rounded-rect.js b/js/rounded-rect.js index 30c8a3f..49d726a 100644 --- a/js/rounded-rect.js +++ b/js/rounded-rect.js @@ -20,6 +20,8 @@ var RoundedRect = Shape.subclass({ cornerRadius: 0.25, closed: false, }); + +RoundedRect.prototype.type = 'RoundedRect'; RoundedRect.prototype.setPath = function() { /* eslint diff --git a/js/shape.js b/js/shape.js index 40c927c..aefbc59 100644 --- a/js/shape.js +++ b/js/shape.js @@ -26,6 +26,8 @@ var Shape = Anchor.subclass({ backface: true, }); +Shape.prototype.type = 'Shape'; + Shape.prototype.create = function( options ) { Anchor.prototype.create.call( this, options ); this.updatePath(); From 918dc82cb054974d4ba022bef5c1a7a582e5b07b Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Fri, 7 Jun 2019 09:02:02 -0500 Subject: [PATCH 03/15] =?UTF-8?q?=F0=9F=90=9E=20add=20type=20property=20to?= =?UTF-8?q?=20Anchor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/anchor.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/anchor.js b/js/anchor.js index 1de5410..a47b780 100644 --- a/js/anchor.js +++ b/js/anchor.js @@ -22,6 +22,7 @@ var onePoint = { x: 1, y: 1, z: 1 }; function Anchor( options ) { this.create( options || {} ); } +Anchor.prototype.type = 'Anchor'; Anchor.prototype.create = function( options ) { // set defaults & options From d8511df18bc9ab4a258fa964cdcdfd38b1700174 Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Fri, 7 Jun 2019 12:47:19 -0500 Subject: [PATCH 04/15] =?UTF-8?q?=F0=9F=9B=A0=20add=20Zdog.exportGraph=20a?= =?UTF-8?q?nd=20Anchor.importGraph?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/anchor.js | 34 ++++++++++++++++++++++++++++++++++ js/boilerplate.js | 4 ++++ 2 files changed, 38 insertions(+) diff --git a/js/anchor.js b/js/anchor.js index a47b780..bac77f4 100644 --- a/js/anchor.js +++ b/js/anchor.js @@ -41,6 +41,9 @@ Anchor.prototype.create = function( options ) { if ( this.addTo ) { this.addTo.addChild( this ); } + if ( options.importGraph ) { + this.importGraph( options.importGraph ); + } }; Anchor.defaults = {}; @@ -207,6 +210,37 @@ Anchor.prototype.copyGraph = function( options ) { }); return clone; }; + +Anchor.prototype.importGraph = function( model ) { + if ( typeof model === 'string' ) { + fetch( model ) + .then(function( res ) { + return res.json(); + }) + .then(function( model ) { + this.importGraph( model ); + }.bind( this )) + } else if ( typeof model === 'object' ) { + this.addChild( revive( model ) ); + } + + function revive( graph ) { + graph = utils.extend( {}, graph ); + var type = graph.type; + var children = (graph.children || []).slice( 0 ); + delete graph.children; + + var Item = Zdog[ type ]; + var rootGraph; + if ( Item ) { + rootGraph = new Item( graph ); + children.forEach( function( child ) { + revive( utils.extend( child, { addTo: rootGraph } ) ); + } ) + } + return rootGraph; + } +} Anchor.prototype.normalizeRotate = function() { this.rotate.x = utils.modulo( this.rotate.x, TAU ); diff --git a/js/boilerplate.js b/js/boilerplate.js index a22ddc9..ffefe4f 100644 --- a/js/boilerplate.js +++ b/js/boilerplate.js @@ -69,6 +69,10 @@ Zdog.easeInOut = function( alpha, power ) { curve /= 2; return isFirstHalf ? curve : 1 - curve; }; + +Zdog.exportGraph = function (model) { + return JSON.parse( JSON.stringify( model ) ); +} return Zdog; From 4ffceb0cb284534fb2b2d33c1563429db7224ec4 Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Fri, 7 Jun 2019 16:23:05 -0500 Subject: [PATCH 05/15] =?UTF-8?q?=F0=9F=90=9Eremove=20fetch=20for=20IE11?= =?UTF-8?q?=20#57?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/anchor.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/js/anchor.js b/js/anchor.js index bac77f4..a8135ed 100644 --- a/js/anchor.js +++ b/js/anchor.js @@ -212,17 +212,7 @@ Anchor.prototype.copyGraph = function( options ) { }; Anchor.prototype.importGraph = function( model ) { - if ( typeof model === 'string' ) { - fetch( model ) - .then(function( res ) { - return res.json(); - }) - .then(function( model ) { - this.importGraph( model ); - }.bind( this )) - } else if ( typeof model === 'object' ) { - this.addChild( revive( model ) ); - } + this.addChild( revive( model ) ); function revive( graph ) { graph = utils.extend( {}, graph ); From e3e372dcd973f0f3bd766ae67447c84c11b5ea57 Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Fri, 7 Jun 2019 16:28:31 -0500 Subject: [PATCH 06/15] =?UTF-8?q?=F0=9F=90=9E=20Array.includes=20=3D>=20Ar?= =?UTF-8?q?ray.indexOf=20#57?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/anchor.js | 19 ++++++++++++------- js/shape.js | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/js/anchor.js b/js/anchor.js index a8135ed..e1b32a7 100644 --- a/js/anchor.js +++ b/js/anchor.js @@ -59,7 +59,7 @@ Anchor.prototype.setOptions = function( options ) { var optionKeys = this.constructor.optionKeys; for ( var key in options ) { - if ( optionKeys.includes( key ) ) { + if ( optionKeys.indexOF( key ) > -1 ) { this[ key ] = options[ key ]; } } @@ -242,18 +242,23 @@ Anchor.prototype.toJSON = function () { var type = this.type; var ignoreChildren = this.ignoreChildren || false; var result = { type: type }; - var optionKeys = [...this.constructor.optionKeys]; + var optionKeys = this.constructor.optionKeys.slice(0); if (!ignoreChildren) { - optionKeys = [...optionKeys, 'children']; + optionKeys = optionKeys.concat(['children']); } optionKeys.forEach(function ( key ) { - if (['addTo', 'dragRotate', 'element', 'resize'].includes(key)) return; - var value = this[key]; + if (['addTo', 'dragRotate', 'element', 'resize'].indexOf(key) > -1) { + return; + } + value = this[key]; var defaults = this.constructor.defaults; - if (!['undefined', 'function'].includes(typeof value) && value !== defaults[key]) { + if ( + !['undefined', 'function'].indexOf(typeof value) > -1 + && value !== defaults[key] + ) { if (Array.isArray(value) && value.length === 0) { return; } @@ -292,7 +297,7 @@ function getSubclass( Super ) { Item.optionKeys = Super.optionKeys.slice(0); // add defaults keys to optionKeys, dedupe Object.keys( Item.defaults ).forEach( function( key ) { - if ( !Item.optionKeys.includes( key ) ) { + if ( !Item.optionKeys.indexOf( key ) > -1 ) { Item.optionKeys.push( key ); } }); diff --git a/js/shape.js b/js/shape.js index aefbc59..7544cef 100644 --- a/js/shape.js +++ b/js/shape.js @@ -62,7 +62,7 @@ Shape.prototype.updatePathCommands = function() { var method = keys[0]; var points = pathPart[ method ]; // default to line if no instruction - var isInstruction = keys.length == 1 && actionNames.includes( method ); + var isInstruction = keys.length == 1 && actionNames.indexOf( method ) > -1; if ( !isInstruction ) { method = 'line'; points = pathPart; From 561bff0059c840f60f02890a985d897a5adbac16 Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Fri, 7 Jun 2019 16:31:35 -0500 Subject: [PATCH 07/15] =?UTF-8?q?=F0=9F=90=9E=20indexOF=20=3D>=20indexOf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/anchor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/anchor.js b/js/anchor.js index e1b32a7..47dcd0d 100644 --- a/js/anchor.js +++ b/js/anchor.js @@ -59,7 +59,7 @@ Anchor.prototype.setOptions = function( options ) { var optionKeys = this.constructor.optionKeys; for ( var key in options ) { - if ( optionKeys.indexOF( key ) > -1 ) { + if ( optionKeys.indexOf( key ) > -1 ) { this[ key ] = options[ key ]; } } From d5a92def6c9d84ce23857be981842043eff92fa3 Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Fri, 7 Jun 2019 19:55:17 -0500 Subject: [PATCH 08/15] =?UTF-8?q?=F0=9F=8E=A9=20add=20importGraph=20demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demos/import-graph/import-graph.js | 30 ++ demos/import-graph/index.html | 47 ++ demos/import-graph/zdog.json | 797 +++++++++++++++++++++++++++++ 3 files changed, 874 insertions(+) create mode 100644 demos/import-graph/import-graph.js create mode 100644 demos/import-graph/index.html create mode 100644 demos/import-graph/zdog.json diff --git a/demos/import-graph/import-graph.js b/demos/import-graph/import-graph.js new file mode 100644 index 0000000..c03de2c --- /dev/null +++ b/demos/import-graph/import-graph.js @@ -0,0 +1,30 @@ +fetch('zdog.json') + .then(function( res ) { + return res.json(); + }).then(function (model) { + // ----- variables ----- // + var sceneSize = 100; + var TAU = Zdog.TAU; + var initRotate = { x: 20/360 * TAU, y: -50/360 * TAU }; + + // ----- model ----- // + var illo = new Zdog.Illustration({ + element: '.illo', + rotate: initRotate, + dragRotate: true, + resize: 'fullscreen', + importGraph: model, + onResize: function( width, height ) { + this.zoom = Math.floor( Math.min( width, height ) * 2 / sceneSize ) / 2; + }, + }); + + // ----- animate ----- // + + function animate() { + illo.updateRenderGraph(); + requestAnimationFrame(animate); + } + + animate(); +}) \ No newline at end of file diff --git a/demos/import-graph/index.html b/demos/import-graph/index.html new file mode 100644 index 0000000..6a1f241 --- /dev/null +++ b/demos/import-graph/index.html @@ -0,0 +1,47 @@ + + + + + + + Import graph + + + + + + +
+ +
+ + + + + + + + + + + + + + + + diff --git a/demos/import-graph/zdog.json b/demos/import-graph/zdog.json new file mode 100644 index 0000000..5533086 --- /dev/null +++ b/demos/import-graph/zdog.json @@ -0,0 +1,797 @@ +{ + "type": "Illustration", + "zoom": 8, + "children": [ + { + "type": "Group", + "children": [ + { + "type": "Group", + "updateSort": true, + "children": [ + { + "type": "Rect", + "rotate": { + "x": 1.5707963267948966 + }, + "translate": { + "y": -20 + }, + "stroke": 8, + "fill": true, + "color": "#E62", + "path": [ + { + "x": -20, + "y": -10 + }, + { + "x": 20, + "y": -10 + }, + { + "x": 20, + "y": 10 + }, + { + "x": -20, + "y": 10 + } + ], + "front": { + "z": 1 + }, + "width": 40, + "height": 20 + }, + { + "type": "Rect", + "rotate": { + "x": -1.5707963267948966 + }, + "translate": { + "y": 20 + }, + "stroke": 8, + "fill": true, + "color": "#E62", + "path": [ + { + "x": -20, + "y": -10 + }, + { + "x": 20, + "y": -10 + }, + { + "x": 20, + "y": 10 + }, + { + "x": -20, + "y": 10 + } + ], + "front": { + "z": 1 + }, + "width": 40, + "height": 20 + }, + { + "type": "Rect", + "rotate": { + "y": 1.5707963267948966 + }, + "translate": { + "x": -20, + "y": -16 + }, + "stroke": 8, + "fill": true, + "color": "#E62", + "path": [ + { + "x": -10, + "y": -4 + }, + { + "x": 10, + "y": -4 + }, + { + "x": 10, + "y": 4 + }, + { + "x": -10, + "y": 4 + } + ], + "front": { + "z": 1 + }, + "backface": false, + "width": 20, + "height": 8 + }, + { + "type": "Rect", + "rotate": { + "y": -1.5707963267948966 + }, + "translate": { + "x": 20, + "y": 16 + }, + "stroke": 8, + "fill": true, + "color": "#E62", + "path": [ + { + "x": -10, + "y": -4 + }, + { + "x": 10, + "y": -4 + }, + { + "x": 10, + "y": 4 + }, + { + "x": -10, + "y": 4 + } + ], + "front": { + "z": 1 + }, + "backface": false, + "width": 20, + "height": 8 + }, + { + "type": "Rect", + "rotate": { + "y": 1.5707963267948966 + }, + "translate": { + "x": -20, + "y": 15 + }, + "stroke": 8, + "fill": true, + "color": "#E62", + "path": [ + { + "x": -10, + "y": -5 + }, + { + "x": 10, + "y": -5 + }, + { + "x": 10, + "y": 5 + }, + { + "x": -10, + "y": 5 + } + ], + "front": { + "z": 1 + }, + "backface": false, + "width": 20, + "height": 10 + }, + { + "type": "Rect", + "rotate": { + "y": -1.5707963267948966 + }, + "translate": { + "x": 20, + "y": -15 + }, + "stroke": 8, + "fill": true, + "color": "#E62", + "path": [ + { + "x": -10, + "y": -5 + }, + { + "x": 10, + "y": -5 + }, + { + "x": 10, + "y": 5 + }, + { + "x": -10, + "y": 5 + } + ], + "front": { + "z": 1 + }, + "backface": false, + "width": 20, + "height": 10 + }, + { + "type": "Rect", + "rotate": { + "x": -1.5707963267948966 + }, + "translate": { + "x": -5, + "y": -12 + }, + "stroke": 8, + "fill": true, + "color": "#E62", + "path": [ + { + "x": -15, + "y": -10 + }, + { + "x": 15, + "y": -10 + }, + { + "x": 15, + "y": 10 + }, + { + "x": -15, + "y": 10 + } + ], + "front": { + "z": 1 + }, + "width": 30, + "height": 20 + }, + { + "type": "Rect", + "rotate": { + "x": 1.5707963267948966 + }, + "translate": { + "x": 5, + "y": 12 + }, + "stroke": 8, + "fill": true, + "color": "#E62", + "path": [ + { + "x": -15, + "y": -10 + }, + { + "x": 15, + "y": -10 + }, + { + "x": 15, + "y": 10 + }, + { + "x": -15, + "y": 10 + } + ], + "front": { + "z": 1 + }, + "width": 30, + "height": 20 + }, + { + "type": "Rect", + "rotate": { + "x": 1.5707963267948966, + "y": 0.6327488350021832 + }, + "translate": { + "x": -5, + "y": -1 + }, + "stroke": 8, + "fill": true, + "color": "#E62", + "path": [ + { + "x": -18.601075237738275, + "y": -10 + }, + { + "x": 18.601075237738275, + "y": -10 + }, + { + "x": 18.601075237738275, + "y": 10 + }, + { + "x": -18.601075237738275, + "y": 10 + } + ], + "front": { + "z": 1 + }, + "backface": false, + "width": 37.20215047547655, + "height": 20 + }, + { + "type": "Rect", + "rotate": { + "x": -1.5707963267948966, + "y": -0.6327488350021832 + }, + "translate": { + "x": 5, + "y": 1 + }, + "stroke": 8, + "fill": true, + "color": "#E62", + "path": [ + { + "x": -18.601075237738275, + "y": -10 + }, + { + "x": 18.601075237738275, + "y": -10 + }, + { + "x": 18.601075237738275, + "y": 10 + }, + { + "x": -18.601075237738275, + "y": 10 + } + ], + "front": { + "z": 1 + }, + "backface": false, + "width": 37.20215047547655, + "height": 20 + }, + { + "type": "Ellipse", + "rotate": { + "z": 1.5707963267948966 + }, + "translate": { + "x": 22, + "y": -4 + }, + "stroke": 8, + "color": "#E62", + "path": [ + { + "x": 0, + "y": -16 + }, + { + "arc": [ + { + "x": 16, + "y": -16 + }, + { + "x": 16, + "y": 0 + } + ] + } + ], + "front": { + "z": 1 + }, + "diameter": 32, + "quarters": 1 + }, + { + "type": "Anchor", + "rotate": { + "y": 1.5707963267948966 + }, + "translate": { + "x": -6, + "y": -7 + }, + "children": [ + { + "type": "Shape", + "rotate": { + "x": 0.9420000403794636 + }, + "stroke": 4, + "fill": true, + "color": "#636", + "path": [ + { + "x": -5, + "y": 0 + }, + { + "x": 5, + "y": 0 + }, + { + "x": 5, + "y": 12 + }, + { + "arc": [ + { + "x": 5, + "y": 17 + }, + { + "x": 0, + "y": 17 + } + ] + }, + { + "arc": [ + { + "x": -5, + "y": 17 + }, + { + "x": -5, + "y": 12 + } + ] + } + ], + "front": { + "z": 1 + } + } + ] + }, + { + "type": "Ellipse", + "rotate": { + "y": 1.5707963267948966, + "z": 1.5707963267948966 + }, + "translate": { + "x": -26, + "y": -20 + }, + "scale": 8, + "stroke": 5, + "fill": true, + "color": "#636", + "closed": true, + "path": [ + { + "x": 0, + "y": -0.5 + }, + { + "arc": [ + { + "x": 0.5, + "y": -0.5 + }, + { + "x": 0.5, + "y": 0 + } + ] + }, + { + "arc": [ + { + "x": 0.5, + "y": 0.5 + }, + { + "x": 0, + "y": 0.5 + } + ] + } + ], + "front": { + "z": 1 + }, + "quarters": 2 + } + ] + }, + { + "type": "Group", + "updateSort": true, + "children": [ + { + "type": "Shape", + "translate": { + "z": 10 + }, + "stroke": 8, + "fill": true, + "color": "#EA0", + "path": [ + { + "x": -20, + "y": -20 + }, + { + "x": 20, + "y": -20 + }, + { + "x": 20, + "y": -10 + }, + { + "x": -10, + "y": 12 + }, + { + "x": 20, + "y": 12 + }, + { + "x": 20, + "y": 20 + }, + { + "x": -20, + "y": 20 + }, + { + "x": -20, + "y": 10 + }, + { + "x": 10, + "y": -12 + }, + { + "x": -20, + "y": -12 + } + ], + "front": { + "z": 1 + }, + "backface": false + }, + { + "type": "Shape", + "rotate": { + "y": 3.141592653589793 + }, + "translate": { + "z": -10 + }, + "scale": { + "x": -1, + "y": 1, + "z": 1 + }, + "stroke": 8, + "fill": true, + "color": "#EA0", + "path": [ + { + "x": -20, + "y": -20 + }, + { + "x": 20, + "y": -20 + }, + { + "x": 20, + "y": -10 + }, + { + "x": -10, + "y": 12 + }, + { + "x": 20, + "y": 12 + }, + { + "x": 20, + "y": 20 + }, + { + "x": -20, + "y": 20 + }, + { + "x": -20, + "y": 10 + }, + { + "x": 10, + "y": -12 + }, + { + "x": -20, + "y": -12 + } + ], + "front": { + "z": 1 + }, + "backface": false + } + ] + } + ] + }, + { + "type": "Group", + "children": [ + { + "type": "Ellipse", + "rotate": { + "x": 0.39269908169872414, + "z": -0.39269908169872414 + }, + "translate": { + "x": 10, + "y": -14, + "z": 20 + }, + "scale": 24, + "stroke": 5, + "fill": true, + "color": "#636", + "closed": true, + "path": [ + { + "x": 0, + "y": -0.5 + }, + { + "arc": [ + { + "x": 0.5, + "y": -0.5 + }, + { + "x": 0.5, + "y": 0 + } + ] + }, + { + "arc": [ + { + "x": 0.5, + "y": 0.5 + }, + { + "x": 0, + "y": 0.5 + } + ] + } + ], + "front": { + "z": 1 + }, + "quarters": 2, + "children": [ + { + "type": "Shape", + "translate": { + "x": -0.5, + "z": 0.5 + }, + "visible": false, + "front": { + "z": 1 + } + } + ] + } + ] + }, + { + "type": "Group", + "scale": { + "x": 1, + "y": 1, + "z": -1 + }, + "children": [ + { + "type": "Ellipse", + "rotate": { + "x": 0.39269908169872414, + "z": -0.39269908169872414 + }, + "translate": { + "x": 10, + "y": -14, + "z": 20 + }, + "scale": 24, + "stroke": 5, + "fill": true, + "color": "#636", + "closed": true, + "path": [ + { + "x": 0, + "y": -0.5 + }, + { + "arc": [ + { + "x": 0.5, + "y": -0.5 + }, + { + "x": 0.5, + "y": 0 + } + ] + }, + { + "arc": [ + { + "x": 0.5, + "y": 0.5 + }, + { + "x": 0, + "y": 0.5 + } + ] + } + ], + "front": { + "z": 1 + }, + "quarters": 2, + "children": [ + { + "type": "Shape", + "translate": { + "x": -0.5, + "z": 0.5 + }, + "visible": false, + "front": { + "z": 1 + } + } + ] + } + ] + } + ] +} \ No newline at end of file From e8733aeebec3d78b952a4d3b2ccfce56f6ad7f58 Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Mon, 10 Jun 2019 21:59:33 -0500 Subject: [PATCH 09/15] Refactor ignored keys to ignoreKeysJSON per primitive --- js/anchor.js | 22 ++++++++++++---------- js/box.js | 3 +-- js/illustration.js | 8 +++++++- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/js/anchor.js b/js/anchor.js index 47dcd0d..747a960 100644 --- a/js/anchor.js +++ b/js/anchor.js @@ -54,6 +54,10 @@ Anchor.optionKeys = Object.keys( Anchor.defaults ).concat([ 'scale', 'addTo', ]); + +Anchor.ignoreKeysJSON = [ + 'addTo', +]; Anchor.prototype.setOptions = function( options ) { var optionKeys = this.constructor.optionKeys; @@ -240,20 +244,16 @@ Anchor.prototype.normalizeRotate = function() { Anchor.prototype.toJSON = function () { var type = this.type; - var ignoreChildren = this.ignoreChildren || false; var result = { type: type }; - var optionKeys = this.constructor.optionKeys.slice(0); - - if (!ignoreChildren) { - optionKeys = optionKeys.concat(['children']); - } + var defaults = this.constructor.defaults; + var optionKeys = this.constructor.optionKeys.slice(0).concat('children'); + var ignoreKeys = this.constructor.ignoreKeysJSON.slice(0).concat(Anchor.ignoreKeysJSON); optionKeys.forEach(function ( key ) { - if (['addTo', 'dragRotate', 'element', 'resize'].indexOf(key) > -1) { + if (ignoreKeys.indexOf(key) > -1) { return; } - value = this[key]; - var defaults = this.constructor.defaults; + value = this[key]; if ( !['undefined', 'function'].indexOf(typeof value) > -1 @@ -301,7 +301,9 @@ function getSubclass( Super ) { Item.optionKeys.push( key ); } }); - + // create ignoreKeysJSON + Item.ignoreKeysJSON = Super.ignoreKeysJSON.slice(0); + Item.subclass = getSubclass( Item ); return Item; diff --git a/js/box.js b/js/box.js index 7d428da..bd36fbe 100644 --- a/js/box.js +++ b/js/box.js @@ -39,10 +39,9 @@ var boxDefaults = utils.extend( { // default fill boxDefaults.fill = true; delete boxDefaults.path; - var Box = Anchor.subclass( boxDefaults ); +Box.ignoreKeysJSON = ['children']; Box.prototype.type = 'Box'; -Box.prototype.ignoreChildren = true; var TAU = utils.TAU; diff --git a/js/illustration.js b/js/illustration.js index dbda72e..3c6aada 100644 --- a/js/illustration.js +++ b/js/illustration.js @@ -30,7 +30,7 @@ var Illustration = Anchor.subclass({ onDragEnd: noop, onResize: noop, }); - +Illustration.ignoreKeysJSON = ['dragRotate', 'element', 'resize']; Illustration.prototype.type = 'Illustration'; utils.extend( Illustration.prototype, Dragger.prototype ); @@ -244,6 +244,12 @@ Illustration.prototype.dragMove = function( event, pointer ) { this.dragRotate.rotate.y = this.dragStartRY - moveRY; Dragger.prototype.dragMove.apply( this, arguments ); }; + +// ----- JSON ----- // +Illustration.prototype.importGraph = function (graph) { + console.log(`Import Graph on Illustration level`); + Anchor.prototype.importGraph.call(this, graph); +} return Illustration; From f9876fb24da9b57904ee00aaa793078fc11c644e Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Mon, 10 Jun 2019 22:02:22 -0500 Subject: [PATCH 10/15] Move type to static property on primitive constructor --- js/anchor.js | 6 +++--- js/box.js | 2 +- js/cone.js | 3 +-- js/cylinder.js | 4 ++-- js/ellipse.js | 2 +- js/group.js | 2 +- js/hemisphere.js | 2 +- js/illustration.js | 2 +- js/polygon.js | 2 +- js/rect.js | 2 +- js/rounded-rect.js | 2 +- js/shape.js | 2 +- 12 files changed, 15 insertions(+), 16 deletions(-) diff --git a/js/anchor.js b/js/anchor.js index 747a960..4656175 100644 --- a/js/anchor.js +++ b/js/anchor.js @@ -22,7 +22,7 @@ var onePoint = { x: 1, y: 1, z: 1 }; function Anchor( options ) { this.create( options || {} ); } -Anchor.prototype.type = 'Anchor'; +Anchor.type = 'Anchor'; Anchor.prototype.create = function( options ) { // set defaults & options @@ -243,11 +243,11 @@ Anchor.prototype.normalizeRotate = function() { }; Anchor.prototype.toJSON = function () { - var type = this.type; + var type = this.constructor.type; var result = { type: type }; var defaults = this.constructor.defaults; var optionKeys = this.constructor.optionKeys.slice(0).concat('children'); - var ignoreKeys = this.constructor.ignoreKeysJSON.slice(0).concat(Anchor.ignoreKeysJSON); + var ignoreKeys = Anchor.ignoreKeysJSON.slice(0).concat(this.constructor.ignoreKeysJSON); optionKeys.forEach(function ( key ) { if (ignoreKeys.indexOf(key) > -1) { diff --git a/js/box.js b/js/box.js index bd36fbe..231d00b 100644 --- a/js/box.js +++ b/js/box.js @@ -41,7 +41,7 @@ boxDefaults.fill = true; delete boxDefaults.path; var Box = Anchor.subclass( boxDefaults ); Box.ignoreKeysJSON = ['children']; -Box.prototype.type = 'Box'; +Box.type = 'Box'; var TAU = utils.TAU; diff --git a/js/cone.js b/js/cone.js index 4b602ee..73a63a8 100644 --- a/js/cone.js +++ b/js/cone.js @@ -20,8 +20,7 @@ var Cone = Ellipse.subclass({ length: 1, fill: true, }); - -Cone.prototype.type = 'Cone'; +Cone.type = 'Cone'; var TAU = utils.TAU; diff --git a/js/cylinder.js b/js/cylinder.js index 8e4ea85..d07ff0e 100644 --- a/js/cylinder.js +++ b/js/cylinder.js @@ -26,7 +26,7 @@ var CylinderGroup = Group.subclass({ updateSort: true, }); -CylinderGroup.prototype.type = 'CylinderGroup'; +CylinderGroup.type = 'CylinderGroup'; CylinderGroup.prototype.create = function() { Group.prototype.create.apply( this, arguments ); @@ -99,7 +99,7 @@ var Cylinder = Shape.subclass({ fill: true, }); -Cylinder.prototype.type = 'Cylinder'; +Cylinder.type = 'Cylinder'; var TAU = utils.TAU; diff --git a/js/ellipse.js b/js/ellipse.js index 9ae7bb6..9ccc342 100644 --- a/js/ellipse.js +++ b/js/ellipse.js @@ -23,7 +23,7 @@ var Ellipse = Shape.subclass({ closed: false, }); -Ellipse.prototype.type = 'Ellipse'; +Ellipse.type = 'Ellipse'; Ellipse.prototype.setPath = function() { var width = this.width != undefined ? this.width : this.diameter; diff --git a/js/group.js b/js/group.js index 7740b5c..3f33351 100644 --- a/js/group.js +++ b/js/group.js @@ -19,7 +19,7 @@ var Group = Anchor.subclass({ visible: true, }); -Group.prototype.type = 'Group'; +Group.type = 'Group'; // ----- update ----- // diff --git a/js/hemisphere.js b/js/hemisphere.js index 6fd1a16..1bc73e7 100644 --- a/js/hemisphere.js +++ b/js/hemisphere.js @@ -18,7 +18,7 @@ var Hemisphere = Ellipse.subclass({ fill: true, }); -Hemisphere.prototype.type = 'Hemisphere'; +Hemisphere.type = 'Hemisphere'; var TAU = utils.TAU; diff --git a/js/illustration.js b/js/illustration.js index 3c6aada..53ead66 100644 --- a/js/illustration.js +++ b/js/illustration.js @@ -31,7 +31,7 @@ var Illustration = Anchor.subclass({ onResize: noop, }); Illustration.ignoreKeysJSON = ['dragRotate', 'element', 'resize']; -Illustration.prototype.type = 'Illustration'; +Illustration.type = 'Illustration'; utils.extend( Illustration.prototype, Dragger.prototype ); diff --git a/js/polygon.js b/js/polygon.js index 8ed0a3b..eeb053c 100644 --- a/js/polygon.js +++ b/js/polygon.js @@ -19,7 +19,7 @@ var Polygon = Shape.subclass({ radius: 0.5, }); -Polygon.prototype.type = 'Polygon'; +Polygon.type = 'Polygon'; var TAU = utils.TAU; diff --git a/js/rect.js b/js/rect.js index 16b935f..119bbe5 100644 --- a/js/rect.js +++ b/js/rect.js @@ -19,7 +19,7 @@ var Rect = Shape.subclass({ height: 1, }); -Rect.prototype.type = 'Rect'; +Rect.type = 'Rect'; Rect.prototype.setPath = function() { var x = this.width / 2; diff --git a/js/rounded-rect.js b/js/rounded-rect.js index 49d726a..1ee9e05 100644 --- a/js/rounded-rect.js +++ b/js/rounded-rect.js @@ -21,7 +21,7 @@ var RoundedRect = Shape.subclass({ closed: false, }); -RoundedRect.prototype.type = 'RoundedRect'; +RoundedRect.type = 'RoundedRect'; RoundedRect.prototype.setPath = function() { /* eslint diff --git a/js/shape.js b/js/shape.js index 7544cef..673289b 100644 --- a/js/shape.js +++ b/js/shape.js @@ -26,7 +26,7 @@ var Shape = Anchor.subclass({ backface: true, }); -Shape.prototype.type = 'Shape'; +Shape.type = 'Shape'; Shape.prototype.create = function( options ) { Anchor.prototype.create.call( this, options ); From 404f964db2baf74b4974d32b893dba1d28a025a4 Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Mon, 10 Jun 2019 22:06:10 -0500 Subject: [PATCH 11/15] Round Vector.toJSON to 3 decimal precision --- demos/box-cross/box-cross.js | 2 ++ js/vector.js | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/demos/box-cross/box-cross.js b/demos/box-cross/box-cross.js index b4275ae..fb7afd5 100644 --- a/demos/box-cross/box-cross.js +++ b/demos/box-cross/box-cross.js @@ -107,6 +107,8 @@ dot.copy({ // ----- animate ----- // +console.log(Zdog.exportGraph(illo)); + var ticker = 0; var cycleCount = 150; diff --git a/js/vector.js b/js/vector.js index aa120d4..6cfddb6 100644 --- a/js/vector.js +++ b/js/vector.js @@ -149,13 +149,17 @@ Vector.prototype.copy = function() { return new Vector( this ); }; +var round = function( num ) { + return Math.round( num * 1000 ) / 1000; +}; + Vector.prototype.toJSON = function() { var x = this.x; var y = this.y; var z = this.z; if ( x === y && y === z ) { - return ( x !== 0 ) ? x : undefined; + return ( x !== 0 ) ? round( x ) : undefined; } var obj = { x: x, y: y, z: z }; @@ -164,7 +168,7 @@ Vector.prototype.toJSON = function() { Object.keys( obj ).forEach( function ( key ) { var value = obj[ key ]; if ( value !== 0 ) { - result[ key ] = value; + result[ key ] = round( value ); } }) From 6261cb0b0c867c3f45352808eb863ee5b8062f96 Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Mon, 10 Jun 2019 22:21:06 -0500 Subject: [PATCH 12/15] Remove custom importGraph for Illustration --- js/illustration.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/js/illustration.js b/js/illustration.js index 53ead66..5ef6803 100644 --- a/js/illustration.js +++ b/js/illustration.js @@ -244,12 +244,6 @@ Illustration.prototype.dragMove = function( event, pointer ) { this.dragRotate.rotate.y = this.dragStartRY - moveRY; Dragger.prototype.dragMove.apply( this, arguments ); }; - -// ----- JSON ----- // -Illustration.prototype.importGraph = function (graph) { - console.log(`Import Graph on Illustration level`); - Anchor.prototype.importGraph.call(this, graph); -} return Illustration; From efd9457fa4b32e11c0669825122283819b729d3c Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Tue, 11 Jun 2019 06:13:17 -0500 Subject: [PATCH 13/15] avoid nested Illustration errors --- js/anchor.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/js/anchor.js b/js/anchor.js index 4656175..d9ce31a 100644 --- a/js/anchor.js +++ b/js/anchor.js @@ -220,7 +220,8 @@ Anchor.prototype.importGraph = function( model ) { function revive( graph ) { graph = utils.extend( {}, graph ); - var type = graph.type; + // quick hack to avoid nested Illustration items + var type = graph.type === 'Illustration' ? 'Anchor' : graph.type; var children = (graph.children || []).slice( 0 ); delete graph.children; @@ -247,7 +248,7 @@ Anchor.prototype.toJSON = function () { var result = { type: type }; var defaults = this.constructor.defaults; var optionKeys = this.constructor.optionKeys.slice(0).concat('children'); - var ignoreKeys = Anchor.ignoreKeysJSON.slice(0).concat(this.constructor.ignoreKeysJSON); + var ignoreKeys = Anchor.ignoreKeysJSON.slice(0).concat(this.constructor.ignoreKeysJSON || []); optionKeys.forEach(function ( key ) { if (ignoreKeys.indexOf(key) > -1) { From 097a0c182dd7fe782a63c6ef8ad87182f106e67c Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Tue, 11 Jun 2019 06:15:19 -0500 Subject: [PATCH 14/15] lint fix --- demos/import-graph/import-graph.js | 5 +++-- js/anchor.js | 22 +++++++++++----------- js/boilerplate.js | 6 +++--- js/box.js | 4 ++-- js/cylinder.js | 4 ++-- js/ellipse.js | 2 +- js/group.js | 2 +- js/hemisphere.js | 2 +- js/illustration.js | 2 +- js/polygon.js | 2 +- js/rect.js | 2 +- js/rounded-rect.js | 2 +- js/vector.js | 14 +++++++------- 13 files changed, 35 insertions(+), 34 deletions(-) diff --git a/demos/import-graph/import-graph.js b/demos/import-graph/import-graph.js index c03de2c..6dcf643 100644 --- a/demos/import-graph/import-graph.js +++ b/demos/import-graph/import-graph.js @@ -1,7 +1,8 @@ fetch('zdog.json') .then(function( res ) { return res.json(); - }).then(function (model) { + }) + .then(function(model) { // ----- variables ----- // var sceneSize = 100; var TAU = Zdog.TAU; @@ -27,4 +28,4 @@ fetch('zdog.json') } animate(); -}) \ No newline at end of file +}); diff --git a/js/anchor.js b/js/anchor.js index d9ce31a..a4075ed 100644 --- a/js/anchor.js +++ b/js/anchor.js @@ -54,7 +54,7 @@ Anchor.optionKeys = Object.keys( Anchor.defaults ).concat([ 'scale', 'addTo', ]); - + Anchor.ignoreKeysJSON = [ 'addTo', ]; @@ -214,7 +214,7 @@ Anchor.prototype.copyGraph = function( options ) { }); return clone; }; - + Anchor.prototype.importGraph = function( model ) { this.addChild( revive( model ) ); @@ -224,41 +224,41 @@ Anchor.prototype.importGraph = function( model ) { var type = graph.type === 'Illustration' ? 'Anchor' : graph.type; var children = (graph.children || []).slice( 0 ); delete graph.children; - + var Item = Zdog[ type ]; var rootGraph; if ( Item ) { rootGraph = new Item( graph ); children.forEach( function( child ) { revive( utils.extend( child, { addTo: rootGraph } ) ); - } ) + } ); } return rootGraph; } -} +}; Anchor.prototype.normalizeRotate = function() { this.rotate.x = utils.modulo( this.rotate.x, TAU ); this.rotate.y = utils.modulo( this.rotate.y, TAU ); this.rotate.z = utils.modulo( this.rotate.z, TAU ); }; - -Anchor.prototype.toJSON = function () { + +Anchor.prototype.toJSON = function() { var type = this.constructor.type; var result = { type: type }; var defaults = this.constructor.defaults; var optionKeys = this.constructor.optionKeys.slice(0).concat('children'); var ignoreKeys = Anchor.ignoreKeysJSON.slice(0).concat(this.constructor.ignoreKeysJSON || []); - optionKeys.forEach(function ( key ) { + optionKeys.forEach(function( key ) { if (ignoreKeys.indexOf(key) > -1) { return; } value = this[key]; if ( - !['undefined', 'function'].indexOf(typeof value) > -1 - && value !== defaults[key] + ![ 'undefined', 'function' ].indexOf(typeof value) > -1 && + value !== defaults[key] ) { if (Array.isArray(value) && value.length === 0) { return; @@ -304,7 +304,7 @@ function getSubclass( Super ) { }); // create ignoreKeysJSON Item.ignoreKeysJSON = Super.ignoreKeysJSON.slice(0); - + Item.subclass = getSubclass( Item ); return Item; diff --git a/js/boilerplate.js b/js/boilerplate.js index ffefe4f..413c0fd 100644 --- a/js/boilerplate.js +++ b/js/boilerplate.js @@ -69,10 +69,10 @@ Zdog.easeInOut = function( alpha, power ) { curve /= 2; return isFirstHalf ? curve : 1 - curve; }; - -Zdog.exportGraph = function (model) { + +Zdog.exportGraph = function(model) { return JSON.parse( JSON.stringify( model ) ); -} +}; return Zdog; diff --git a/js/box.js b/js/box.js index 231d00b..e12ce3e 100644 --- a/js/box.js +++ b/js/box.js @@ -21,7 +21,7 @@ var BoxRect = Rect.subclass(); // prevent double-creation in parent.copyGraph() // only create in Box.create() -BoxRect.prototype.copyGraph = function () { }; +BoxRect.prototype.copyGraph = function() { }; // ----- Box ----- // @@ -40,7 +40,7 @@ var boxDefaults = utils.extend( { boxDefaults.fill = true; delete boxDefaults.path; var Box = Anchor.subclass( boxDefaults ); -Box.ignoreKeysJSON = ['children']; +Box.ignoreKeysJSON = [ 'children' ]; Box.type = 'Box'; var TAU = utils.TAU; diff --git a/js/cylinder.js b/js/cylinder.js index d07ff0e..d1b9979 100644 --- a/js/cylinder.js +++ b/js/cylinder.js @@ -25,7 +25,7 @@ var CylinderGroup = Group.subclass({ color: '#333', updateSort: true, }); - + CylinderGroup.type = 'CylinderGroup'; CylinderGroup.prototype.create = function() { @@ -98,7 +98,7 @@ var Cylinder = Shape.subclass({ frontFace: undefined, fill: true, }); - + Cylinder.type = 'Cylinder'; diff --git a/js/ellipse.js b/js/ellipse.js index 9ccc342..def1a05 100644 --- a/js/ellipse.js +++ b/js/ellipse.js @@ -22,7 +22,7 @@ var Ellipse = Shape.subclass({ quarters: 4, closed: false, }); - + Ellipse.type = 'Ellipse'; Ellipse.prototype.setPath = function() { diff --git a/js/group.js b/js/group.js index 3f33351..746e2a6 100644 --- a/js/group.js +++ b/js/group.js @@ -18,7 +18,7 @@ var Group = Anchor.subclass({ updateSort: false, visible: true, }); - + Group.type = 'Group'; diff --git a/js/hemisphere.js b/js/hemisphere.js index 1bc73e7..abaeb00 100644 --- a/js/hemisphere.js +++ b/js/hemisphere.js @@ -17,7 +17,7 @@ var Hemisphere = Ellipse.subclass({ fill: true, }); - + Hemisphere.type = 'Hemisphere'; var TAU = utils.TAU; diff --git a/js/illustration.js b/js/illustration.js index 5ef6803..f433bf3 100644 --- a/js/illustration.js +++ b/js/illustration.js @@ -30,7 +30,7 @@ var Illustration = Anchor.subclass({ onDragEnd: noop, onResize: noop, }); -Illustration.ignoreKeysJSON = ['dragRotate', 'element', 'resize']; +Illustration.ignoreKeysJSON = [ 'dragRotate', 'element', 'resize' ]; Illustration.type = 'Illustration'; utils.extend( Illustration.prototype, Dragger.prototype ); diff --git a/js/polygon.js b/js/polygon.js index eeb053c..e7da3f1 100644 --- a/js/polygon.js +++ b/js/polygon.js @@ -18,7 +18,7 @@ var Polygon = Shape.subclass({ sides: 3, radius: 0.5, }); - + Polygon.type = 'Polygon'; var TAU = utils.TAU; diff --git a/js/rect.js b/js/rect.js index 119bbe5..ffedaa9 100644 --- a/js/rect.js +++ b/js/rect.js @@ -18,7 +18,7 @@ var Rect = Shape.subclass({ width: 1, height: 1, }); - + Rect.type = 'Rect'; Rect.prototype.setPath = function() { diff --git a/js/rounded-rect.js b/js/rounded-rect.js index 1ee9e05..28316e3 100644 --- a/js/rounded-rect.js +++ b/js/rounded-rect.js @@ -20,7 +20,7 @@ var RoundedRect = Shape.subclass({ cornerRadius: 0.25, closed: false, }); - + RoundedRect.type = 'RoundedRect'; RoundedRect.prototype.setPath = function() { diff --git a/js/vector.js b/js/vector.js index 6cfddb6..2150656 100644 --- a/js/vector.js +++ b/js/vector.js @@ -148,29 +148,29 @@ Vector.prototype.magnitude2d = function() { Vector.prototype.copy = function() { return new Vector( this ); }; - + var round = function( num ) { return Math.round( num * 1000 ) / 1000; }; - + Vector.prototype.toJSON = function() { var x = this.x; var y = this.y; var z = this.z; - + if ( x === y && y === z ) { - return ( x !== 0 ) ? round( x ) : undefined; + return x !== 0 ? round( x ) : undefined; } var obj = { x: x, y: y, z: z }; var result = {}; - - Object.keys( obj ).forEach( function ( key ) { + + Object.keys( obj ).forEach( function( key ) { var value = obj[ key ]; if ( value !== 0 ) { result[ key ] = round( value ); } - }) + }); return Object.keys( result ).length ? result : undefined; }; From 0907e13ae1fbb335970852374a8022a913f37251 Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Tue, 11 Jun 2019 06:33:54 -0500 Subject: [PATCH 15/15] manually fix lint errors --- demos/box-cross/box-cross.js | 2 -- js/anchor.js | 8 +++++--- js/vector.js | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/demos/box-cross/box-cross.js b/demos/box-cross/box-cross.js index fb7afd5..b4275ae 100644 --- a/demos/box-cross/box-cross.js +++ b/demos/box-cross/box-cross.js @@ -107,8 +107,6 @@ dot.copy({ // ----- animate ----- // -console.log(Zdog.exportGraph(illo)); - var ticker = 0; var cycleCount = 150; diff --git a/js/anchor.js b/js/anchor.js index a4075ed..4926693 100644 --- a/js/anchor.js +++ b/js/anchor.js @@ -225,7 +225,7 @@ Anchor.prototype.importGraph = function( model ) { var children = (graph.children || []).slice( 0 ); delete graph.children; - var Item = Zdog[ type ]; + var Item = utils[ type ]; var rootGraph; if ( Item ) { rootGraph = new Item( graph ); @@ -248,13 +248,15 @@ Anchor.prototype.toJSON = function() { var result = { type: type }; var defaults = this.constructor.defaults; var optionKeys = this.constructor.optionKeys.slice(0).concat('children'); - var ignoreKeys = Anchor.ignoreKeysJSON.slice(0).concat(this.constructor.ignoreKeysJSON || []); + var ignoreKeys = Anchor.ignoreKeysJSON + .slice(0) + .concat(this.constructor.ignoreKeysJSON || []); optionKeys.forEach(function( key ) { if (ignoreKeys.indexOf(key) > -1) { return; } - value = this[key]; + var value = this[key]; if ( ![ 'undefined', 'function' ].indexOf(typeof value) > -1 && diff --git a/js/vector.js b/js/vector.js index 2150656..2d1f6d5 100644 --- a/js/vector.js +++ b/js/vector.js @@ -149,9 +149,9 @@ Vector.prototype.copy = function() { return new Vector( this ); }; -var round = function( num ) { +function round( num ) { return Math.round( num * 1000 ) / 1000; -}; +} Vector.prototype.toJSON = function() { var x = this.x;