From 999da3c25b5a1529cf706b918eacefe0a1391587 Mon Sep 17 00:00:00 2001 From: TaDaa Date: Sat, 1 Oct 2016 11:36:13 -0400 Subject: [PATCH] initial commit -- not ready yet --- README.md | 110 +++++++ build.js | 37 +++ dist/container.js | 11 + dist/index.js | 2 + dist/poppy.css | 76 +++++ dist/poppy.js | 776 +++++++++++++++++++++++++++++++++++++++++++++ libs/container.js | 9 + libs/index.js | 2 + libs/poppy.css | 76 +++++ libs/poppy.js | 787 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 35 +++ webpack.config.js | 86 +++++ 12 files changed, 2007 insertions(+) create mode 100644 README.md create mode 100644 build.js create mode 100644 dist/container.js create mode 100644 dist/index.js create mode 100644 dist/poppy.css create mode 100644 dist/poppy.js create mode 100644 libs/container.js create mode 100644 libs/index.js create mode 100644 libs/poppy.css create mode 100644 libs/poppy.js create mode 100644 package.json create mode 100644 webpack.config.js diff --git a/README.md b/README.md new file mode 100644 index 0000000..5c4e93a --- /dev/null +++ b/README.md @@ -0,0 +1,110 @@ +# C2 + +C2 is a helper library for creating custom components that render to canvas. Currently C2 is only compatible with D3 v4. + +C2 works by allowing you to define custom element tags that are intended to render to canvas. + +For example: +``` +//define custom component tag + +var Rect = c2.element(function (context) { + context.fillRect(this.x,this.y,this.width,this.height); +}).attributes({ + x : c2.types.float, + y : c2.types.float, + width: c2.types.float, + height : c2.types.float +}); + +//the attributes method above is used to compile optimized setAttribute +//and getAttribute functions. Attributes are also used by c2.animate to +//generate optimized tweening functions. + + + + + + +//c2.Context2d is a custom tag provided by c2 that selects the 2d context from a canvas element + +var context = d3.select('canvas').select(c2.Context2d) + //tick is an event that triggers before each render frame + //if you need to use an after render event, use "tock" + .on('tick',function () { + this.context.clearRect(0,0,this.context.canvas.width,this.context.canvas.height); + }) +var selection = context.selectAll(Rect).data(data,function (d,i) {return i;}); +selection.enter() + .append(Rect) + .attr('x',0) + .attr('y',0) + .attr('width',0) + .attr('height',0) +.merge(selection) + +//c2.animate is uses its own internal scheduler, groups tweens by +//start/duration/easing and is generally faster than d3.transition +//as well as being easier on the garbage collector. +.call(c2.animate() + .to({ + x : function (d,i) {return Math.random()*1000}, + y: function (d,i) {return Math.random()*500}, + height : 1, + width : 1 + }); + +selection.exit() + .call( + c2.animate() + .to({ + width : 0, + height: 0 + }) + .remove() + ); +``` + + +### TODO +WebGL support +api/docs + +### Demos (with code) +1) Bars + +2) Donut (uses Path2D for canvas with d3.arc) + + + +### Quickstart +1) Download script through npm or download/include the appropriate script. Pre-minified scripts are available. + +`