-
-
Save mcanthony/dfd9c1227c619ba6a05d to your computer and use it in GitHub Desktop.
Revisions
-
curran revised this gist
Sep 23, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ The [Chiasm components](https://github.com/chiasm-project/chiasm-component) demo plugin for nested box layout. You can use this plugin to impose a grid system of rectangles on any collection of Chiasm components. * [`coloredRectangle`](https://gist.github.com/curran/1af08ad6cdb01707c33f#file-coloredrectangle-js) An example custom Chiasm component that draws a colored rectangle using [D3.js](http://d3js.org/) and [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics). The naming convention of `my` for the component is inspired by the wonderful piece on -
curran revised this gist
Sep 13, 2015 . 1 changed file with 20 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -99,22 +99,26 @@ } }); // Here's a simpler configuration to try, // including just a single component instance. /* chiasm.setConfig({ "layout": { "plugin": "layout", "state": { "containerSelector": "#chiasm-container", "layout": "visualization" } }, "visualization": { "plugin": "coloredRectangle", "state": { "color": "blue" } } }); */ </script> </body> </html> -
curran revised this gist
Sep 13, 2015 . 2 changed files with 57 additions and 57 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ // This function defines a Chiasm component that draws a colored rectangle using D3.js. function ColoredRectangle() { // Construct a Chiasm component instance, // specifying default values for public properties. var my = new ChiasmComponent({ // The color of the rectangle, a CSS color string. color: "white" }); // Initialize an SVG Group element for containing this component. var svg = my.initSVG(); // Add a background rectangle to the SVG Group element using D3. var rect = d3.select(svg).append("rect"); // Set the rectangle color to be the configured color. my.when("color", function (color){ rect.attr("fill", color); }); // Respond to dynamic width and height. // "box" is a special property set by chiasm-layout. my.when("box", function (box) { // Set the size of the background rectangle. rect .attr("width", box.width) .attr("height", box.height); }); // Set up the rectangle so that when you click on it, it changes color. rect.on("click", function (){ my.color = randomColor(); }); // Generates a random color. function randomColor(){ return "rgb(" + rand() + "," + rand() + "," + rand() + ")"; } // Generates a random integer between 0 and 255. function rand(){ return Math.floor(Math.random() * 256) }; return my; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,75 +4,24 @@ <meta charset="utf-8"> <title>Chiasm Boilerplate</title> <!-- A functional reactive model library. See github.com/curran/model --> <script src="http://curran.github.io/model/cdn/model-v0.2.4.js"></script> <!-- The common base for Chiasm components (depends on Model.js). --> <script src="http://chiasm-project.github.io/chiasm-component/chiasm-component-v0.2.1.js"></script> <!-- This script defines the ColoredRectangle component. --> <script src="coloredRectangle.js"> </script> <!-- Chiasm.js depends on Model.js, Lodash.js, D3.js. --> <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script> <!-- Load Chiasm.js. See github.com/chiasm-project --> <script src="http://chiasm-project.github.io/chiasm/chiasm-v0.2.0.js"></script> <!-- Load the nested box layout plugin. See https://github.com/chiasm-project/chiasm-layout --> <script src="http://chiasm-project.github.io/chiasm-layout/chiasm-layout-v0.2.2.js"></script> <!-- Make the Chiasm container fill the page and have a 20px black border. --> -
curran revised this gist
Sep 12, 2015 . 1 changed file with 19 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -46,17 +46,32 @@ .attr("height", box.height); }); // Set up the rectangle so that when you click on it, it changes color. rect.on("click", function (){ my.color = randomColor(); }); // Generates a random color. function randomColor(){ return "rgb(" + rand() + "," + rand() + "," + rand() + ")"; } // Generates a random integer between 0 and 255. function rand(){ return Math.floor(Math.random() * 256) }; return my; } </script> <!-- Chiasm.js depends on Model.js, Lodash.js, D3.js. --> <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script> <!-- Load Chiasm.js and layout plugin. See github.com/chiasm-project --> <script src="http://chiasm-project.github.io/chiasm/chiasm-v0.2.0.js"></script> <script src="http://chiasm-project.github.io/chiasm-layout/chiasm-layout-v0.2.2.js"></script> -
curran revised this gist
Sep 12, 2015 . 1 changed file with 38 additions and 35 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,51 +3,22 @@ <head> <meta charset="utf-8"> <title>Chiasm Boilerplate</title> <!-- A functional reactive model library. github.com/curran/model --> <script src="http://curran.github.io/model/cdn/model-v0.2.4.js"></script> <!-- Tha common base for Chiasm components (depends on model.js). --> <script src="http://chiasm-project.github.io/chiasm-component/chiasm-component-v0.2.1.js"></script> <!-- This script defines the ColoredRectangle component. --> <script> // This component draws a colored rectangle using D3.js. function ColoredRectangle() { // Construct a Chiasm component instance, // specifying default values for public properties. var my = new ChiasmComponent({ // The color of the rectangle, a CSS color string. color: "white" @@ -80,7 +51,39 @@ } </script> <!-- Chiasm.js depends on Lodash, D3.js, and Model.js. --> <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script> <!-- Load Chiasm.js and layout plugin. github.com/chiasm-project --> <script src="http://chiasm-project.github.io/chiasm/chiasm-v0.2.0.js"></script> <script src="http://chiasm-project.github.io/chiasm-layout/chiasm-layout-v0.2.2.js"></script> <!-- Make the Chiasm container fill the page and have a 20px black border. --> <style> body { background-color: black; } #chiasm-container { background-color: white; position: fixed; left: 20px; right: 20px; top: 20px; bottom: 20px; } </style> </head> <body> <!-- Chiasm component DOM elements will be injected into this div. --> <div id="chiasm-container"></div> <!-- This is the main program that sets up the Chiasm application. --> <script> // Create a new Chiasm instance. -
curran revised this gist
Sep 9, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,7 +36,7 @@ </head> <body> <!-- Chiasm component instances will be injected into this div. --> <div id="chiasm-container"></div> <!-- This script defines the ColoredRectangle Chiasm component. --> -
curran revised this gist
Sep 9, 2015 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,8 @@ Boilerplate starter code for [Chiasm](https://github.com/chiasm-project/chiasm). To get started, go ahead and [edit this example on blockbuilder.org](http://blockbuilder.org/curran/1af08ad6cdb01707c33f). From there you can experiment with creating your own Chiasm components and applications, then publish your work back to [bl.ocks.org](http://bl.ocks.org/). The [Chiasm components](https://github.com/chiasm-project/chiasm-component) demonstrated here are: * [`chiasm-layout`](https://github.com/chiasm-project/chiasm-layout) A Chiasm plugin for nested box layout. You can use this plugin to impose a grid system -
curran revised this gist
Sep 8, 2015 . 1 changed file with 5 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,6 @@ background-color: black; } #chiasm-container { background-color: white; position: fixed; @@ -34,7 +33,6 @@ } </style> </head> <body> @@ -59,7 +57,7 @@ // Initialize an SVG Group element for containing this component. var svg = my.initSVG(); // Add a background rectangle to the SVG Group element using D3. var rect = d3.select(svg).append("rect"); // Set the rectangle color to be the configured color. @@ -82,16 +80,17 @@ } </script> <!-- This script is the main program that uses the ColoredRectangle component. --> <script> // Create a new Chiasm instance. var chiasm = new Chiasm(); // Register plugins that the configuration can access. chiasm.plugins.layout = ChiasmLayout; chiasm.plugins.coloredRectangle = ColoredRectangle; // Set the Chaism configuration. chiasm.setConfig({ "layout": { "plugin": "layout", @@ -133,7 +132,7 @@ } }); // Here's a simpler configuration to try, including just a single component instance. //chiasm.setConfig({ // "layout": { // "plugin": "layout", -
curran revised this gist
Sep 8, 2015 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,6 +14,8 @@ your own Chiasm applications and custom plugins. The plugins demonstrated here a reusable D3 charts [Towards Reusable Charts](http://bost.ocks.org/mike/chart/). For a more complex example that creates data visualizations, check out [Fundamental Visualizations](http://bl.ocks.org/curran/3cc1a2a289dddbd64688). <!-- Start of SimpleHitCounter Code --> <div align="center"><a href="http://www.simplehitcounter.com" target="_blank"><img src="http://simplehitcounter.com/hit.php?uid=1948664&f=16777215&b=0" border="0" height="18" width="83" alt="web counter"></a></div> <!-- End of SimpleHitCounter Code --> -
curran revised this gist
Sep 8, 2015 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ <!-- Chiasm core and plugins. github.com/chiasm-project --> <script src="http://chiasm-project.github.io/chiasm/chiasm-v0.2.0.js"></script> <script src="http://chiasm-project.github.io/chiasm-component/chiasm-component-v0.2.1.js"></script> <script src="http://chiasm-project.github.io/chiasm-layout/chiasm-layout-v0.2.2.js"></script> <!-- Make the Chiasm container fill the page and have a 20px black border. --> @@ -56,12 +56,11 @@ }); // Initialize an SVG Group element for containing this component. var svg = my.initSVG(); // Add a background rectangle to the SVG Group element. var rect = d3.select(svg).append("rect"); // Set the rectangle color to be the configured color. my.when("color", function (color){ -
curran revised this gist
Sep 8, 2015 . 1 changed file with 5 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ <!-- Chiasm core and plugins. github.com/chiasm-project --> <script src="http://chiasm-project.github.io/chiasm/chiasm-v0.2.0.js"></script> <script src="http://chiasm-project.github.io/chiasm-component/chiasm-component-v0.2.0.js"></script> <script src="http://chiasm-project.github.io/chiasm-layout/chiasm-layout-v0.2.2.js"></script> <!-- Make the Chiasm container fill the page and have a 20px black border. --> <style> @@ -56,15 +56,12 @@ }); // Expose an SVG Group element that will be added to the Chiasm container SVG. // This is a special property that chiasm-layout looks for. my.el = document.createElementNS("http://www.w3.org/2000/svg", "g"); // Add a background rectangle to the SVG Group element. var rect = d3.select(my.el).append("rect"); // Set the rectangle color to be the configured color. my.when("color", function (color){ @@ -75,11 +72,6 @@ // "box" is a special property set by chiasm-layout. my.when("box", function (box) { // Set the size of the background rectangle. rect .attr("width", box.width) -
curran revised this gist
Sep 8, 2015 . 5 changed files with 108 additions and 135 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,7 @@ Boilerplate starter code for [Chiasm](https://github.com/chiasm-project/chiasm). To get started, go ahead and [edit this example on blockbuilder.org](http://blockbuilder.org/curran/1af08ad6cdb01707c33f). From there you can publish your work to bl.ocks.org. This example demonstrates the minimal code required to get started developing your own Chiasm applications and custom plugins. The plugins demonstrated here are: * [`chiasm-layout`](https://github.com/chiasm-project/chiasm-layout) A Chiasm plugin for nested box layout. You can use this plugin to impose a grid system @@ -18,10 +14,6 @@ The Chiasm plugins demonstrated here are: reusable D3 charts [Towards Reusable Charts](http://bost.ocks.org/mike/chart/). <!-- Start of SimpleHitCounter Code --> <div align="center"><a href="http://www.simplehitcounter.com" target="_blank"><img src="http://simplehitcounter.com/hit.php?uid=1948664&f=16777215&b=0" border="0" height="18" width="83" alt="web counter"></a></div> <!-- End of SimpleHitCounter Code --> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,55 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,45 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,6 @@ <head> <meta charset="utf-8"> <title>Chiasm Boilerplate</title> <!-- Chiasm depends on Lodash, D3.js, and Model.js. --> <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js"></script> @@ -17,9 +16,6 @@ <script src="http://chiasm-project.github.io/chiasm-component/chiasm-component-v0.2.0.js"></script> <script src="http://chiasm-project.github.io/chiasm-layout/chiasm-layout-v0.2.1.js"></script> <!-- Make the Chiasm container fill the page and have a 20px black border. --> <style> @@ -45,6 +41,56 @@ <!-- The Chiasm Layout Plugin will inject components into this div. --> <div id="chiasm-container"></div> <!-- This script defines the ColoredRectangle Chiasm component. --> <script> // An example custom Chiasm component that draws a colored rectangle using D3.js and SVG. function ColoredRectangle() { // Construct a Chiasm component instance, // specifying default values for public properties. var my = ChiasmComponent({ // The color of the rectangle, a CSS color string. color: "white" }); // Expose a div element that will be added to the Chiasm container. // This is a special property that chiasm-layout looks for. my.el = document.createElement("div"); // Create an SVG DOM element using D3 and append it to the div. var svg = d3.select(my.el).append("svg"); // Add a background rectangle to the SVG element. var rect = svg.append("rect"); // Set the rectangle color to be the configured color. my.when("color", function (color){ rect.attr("fill", color); }); // Respond to dynamic width and height. // "box" is a special property set by chiasm-layout. my.when("box", function (box) { // Set the size of the SVG element. svg .attr("width", box.width) .attr("height", box.height); // Set the size of the background rectangle. rect .attr("width", box.width) .attr("height", box.height); }); return my; } </script> <script> // Create a new Chiasm instance. @@ -54,14 +100,64 @@ chiasm.plugins.layout = ChiasmLayout; chiasm.plugins.coloredRectangle = ColoredRectangle; // Set the Chaism application configuration. chiasm.setConfig({ "layout": { "plugin": "layout", "state": { "containerSelector": "#chiasm-container", "layout": { "orientation": "vertical", "children": [ "A", { "orientation": "horizontal", "children": [ "B", { "orientation": "vertical", "children": [ "C", "D" ] }, "E" ] } ] } } }, "A": { "plugin": "coloredRectangle" }, "B": { "plugin": "coloredRectangle", "state": { "color": "#a8f0ff" } }, "C": { "plugin": "coloredRectangle", "state": { "color": "#ffe2a8" } }, "D": { "plugin": "coloredRectangle", "state": { "color": "#99e2c8" } }, "E": { "plugin": "coloredRectangle", "state": { "color": "#a8ffd0" } } }); // Here's a simpler configuration, including just a single component. //chiasm.setConfig({ // "layout": { // "plugin": "layout", // "state": { // "containerSelector": "#chiasm-container", // "layout": "visualization" // } // }, // "visualization": { // "plugin": "coloredRectangle", // "state": { // "color": "blue" // } // } //}); </script> </body> </html> -
curran revised this gist
Sep 8, 2015 . 1 changed file with 2 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,9 @@ Boilerplate starter code for [Chiasm](https://github.com/chiasm-project/chiasm). This example demonstrates the minimal code required to get started developing your own Chiasm applications and custom plugins. To get started, go ahead and [edit this example on blockbuilder.org](http://blockbuilder.org/curran/1af08ad6cdb01707c33f). From there you can publish your work to bl.ocks.org. The Chiasm plugins demonstrated here are: -
curran revised this gist
Sep 7, 2015 . 1 changed file with 9 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,15 @@ Boilerplate starter code for [Chiasm](https://github.com/chiasm-project/chiasm). This example demonstrates the minimal code required to get started developing your own Chiasm applications and custom plugins. You can clone this Gist and run it on your computer with the following commands: ``` git clone https://gist.github.com/1af08ad6cdb01707c33f.git cd 1af08ad6cdb01707c33f npm install http-server -g http-server ``` The Chiasm plugins demonstrated here are: -
curran revised this gist
Sep 6, 2015 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,3 +19,7 @@ The Chiasm plugins demonstrated here are: The configuration in `chiasmConfig.json` is intended to show how chiasm-layout can be set up with arbitrary levels of nested boxes. If you want something more mininal to start from, use `chiasmConfigSimplest.json`. <!-- Start of SimpleHitCounter Code --> <div align="center"><a href="http://www.simplehitcounter.com" target="_blank"><img src="http://simplehitcounter.com/hit.php?uid=1948664&f=16777215&b=0" border="0" height="18" width="83" alt="web counter"></a></div> <!-- End of SimpleHitCounter Code --> -
curran revised this gist
Sep 6, 2015 . 2 changed files with 7 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,5 +18,4 @@ The Chiasm plugins demonstrated here are: The configuration in `chiasmConfig.json` is intended to show how chiasm-layout can be set up with arbitrary levels of nested boxes. If you want something more mininal to start from, use `chiasmConfigSimplest.json`. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,10 +3,13 @@ "plugin": "layout", "state": { "containerSelector": "#chiasm-container", "layout": "visualization" } }, "visualization": { "plugin": "coloredRectangle", "state": { "color": "blue" } } } -
curran revised this gist
Sep 6, 2015 . 1 changed file with 2 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,17 +15,10 @@ "orientation": "vertical", "children": [ "C", "D" ] }, "E" ] } ] @@ -54,18 +47,6 @@ } }, "E": { "plugin": "coloredRectangle", "state": { "color": "#a8ffd0" -
curran revised this gist
Sep 6, 2015 . 2 changed files with 17 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,3 +15,8 @@ The Chiasm plugins demonstrated here are: convention of `my` for the component is inspired by the wonderful piece on reusable D3 charts [Towards Reusable Charts](http://bost.ocks.org/mike/chart/). The configuration in `chiasmConfig.json` is intended to show how chiasm-layout can be set up with arbitrary levels of nested boxes. If you want something more mininal to start from, change the main application to load `chiasmConfigSimplest.json` instead. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ { "layout": { "plugin": "layout", "state": { "containerSelector": "#chiasm-container", "layout": "A" } }, "A": { "plugin": "coloredRectangle" } } -
curran revised this gist
Sep 5, 2015 . 3 changed files with 34 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ The MIT License (MIT) Copyright (c) 2015 Curran Kelleher Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,6 +11,7 @@ The Chiasm plugins demonstrated here are: * `coloredRectangle` An example custom Chiasm component that draws a colored rectangle using [D3.js](http://d3js.org/) and [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics). The naming convention of `my` for the component is inspired by the wonderful piece on reusable D3 charts [Towards Reusable Charts](http://bost.ocks.org/mike/chart/). This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,4 @@ // An example custom Chiasm component that draws a colored rectangle using D3.js and SVG. function ColoredRectangle() { // Construct a Chiasm component instance, @@ -16,21 +14,19 @@ function ColoredRectangle() { // This is a special property that chiasm-layout looks for. my.el = document.createElement("div"); // Create an SVG DOM element using D3 and append it to the div. var svg = d3.select(my.el).append("svg"); // Add a background rectangle to the SVG element. var rect = svg.append("rect"); // Set the rectangle color to be the configured color. my.when("color", function (color){ rect.attr("fill", color); }); // Respond to dynamic width and height. // "box" is a special property set by chiasm-layout. my.when("box", function (box) { // Set the size of the SVG element. @@ -39,7 +35,7 @@ function ColoredRectangle() { .attr("height", box.height); // Set the size of the background rectangle. rect .attr("width", box.width) .attr("height", box.height); -
curran revised this gist
Sep 5, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed. -
curran revised this gist
Sep 5, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ Boilerplate starter code for [Chiasm](https://github.com/chiasm-project/chiasm). This example demonstrates the minimal code required to get started developing your own Chiasm applications and custom plugins. -
curran revised this gist
Sep 5, 2015 . 2 changed files with 0 additions and 138 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,64 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,74 +0,0 @@ -
curran created this gist
Sep 5, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ Boilerplate starter code for [Chiasm](https://github.com/curran/chiasm/). This example demonstrates the minimal code required to get started developing your own Chiasm applications and custom plugins. The Chiasm plugins demonstrated here are: * [`chiasm-layout`](https://github.com/chiasm-project/chiasm-layout) A Chiasm plugin for nested box layout. You can use this plugin to impose a grid system of rectangles on any collection of Chiasm components. * `coloredRectangle` An example custom Chiasm component that draws a colored rectangle using [D3.js](http://d3js.org/) and [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics). MIT License This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,74 @@ { "layout": { "plugin": "layout", "state": { "containerSelector": "#chiasm-container", "layout": { "orientation": "vertical", "children": [ "A", { "orientation": "horizontal", "children": [ "B", { "orientation": "vertical", "children": [ "C", { "orientation": "horizontal", "children": [ "D", "E", "F" ] } ] }, "G" ] } ] } } }, "A": { "plugin": "coloredRectangle" }, "B": { "plugin": "coloredRectangle", "state": { "color": "#a8f0ff" } }, "C": { "plugin": "coloredRectangle", "state": { "color": "#ffe2a8" } }, "D": { "plugin": "coloredRectangle", "state": { "color": "#99e2c8" } }, "E": { "plugin": "coloredRectangle", "state": { "color": "#99e2c8" } }, "F": { "plugin": "coloredRectangle", "state": { "color": "#99e2c8" } }, "G": { "plugin": "coloredRectangle", "state": { "color": "#a8ffd0" } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ // This is an example Chaism plugin that uses D3. A colored rectangle is // created with an X in the background and text in the foreground. The X in the // background is interactive. Clicking and dragging it updates `lineWidth`. function ColoredRectangle() { // Construct a Chiasm component instance, // specifying default values for public properties. var my = ChiasmComponent({ // The color of the rectangle, a CSS color string. color: "white" }); // Expose a div element that will be added to the Chiasm container. // This is a special property that chiasm-layout looks for. my.el = document.createElement("div"); // Create an SVG DOM element using D3. var svg = d3.select(my.el).append("svg"); // Add a background rectangle to the SVG. svg.append("rect") .attr("x", 0) .attr("y", 0); // Set the rectangle color to be the configured color. my.when("color", function (color){ svg.select("rect").attr("fill", color); }); // Respond to width and height changes. // "box" is a special property that gets set by chiasm-layout. my.when("box", function (box) { // Set the size of the SVG element. svg .attr("width", box.width) .attr("height", box.height); // Set the size of the background rectangle. svg.select("rect") .attr("width", box.width) .attr("height", box.height); }); return my; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,67 @@ <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Chiasm Boilerplate</title> <!-- By Curran Kelleher September 2015. Released under MIT Licence. --> <!-- Chiasm depends on Lodash, D3.js, and Model.js. --> <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script> <!-- A functional reactive model library. github.com/curran/model --> <script src="http://curran.github.io/model/cdn/model-v0.2.4.js"></script> <!-- Chiasm core and plugins. github.com/chiasm-project --> <script src="http://chiasm-project.github.io/chiasm/chiasm-v0.2.0.js"></script> <script src="http://chiasm-project.github.io/chiasm-component/chiasm-component-v0.2.0.js"></script> <script src="http://chiasm-project.github.io/chiasm-layout/chiasm-layout-v0.2.1.js"></script> <!-- Custom Chiasm plugins for this example. --> <script src="coloredRectangle.js"></script> <!-- Make the Chiasm container fill the page and have a 20px black border. --> <style> body { background-color: black; } /* Make the Chiasm container fill the page with a 20px margin. */ #chiasm-container { background-color: white; position: fixed; left: 20px; right: 20px; top: 20px; bottom: 20px; } </style> </head> <body> <!-- The Chiasm Layout Plugin will inject components into this div. --> <div id="chiasm-container"></div> <script> // Create a new Chiasm instance. var chiasm = new Chiasm(); // Register plugins that configurations can access. chiasm.plugins.layout = ChiasmLayout; chiasm.plugins.coloredRectangle = ColoredRectangle; // Use D3 to fetch the chiasm configuration file. d3.json("chiasmConfig.json", function (config){ // Set the Chaism application configuration. chiasm.setConfig(config); }); </script> </body> </html> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ // This is a prototype for a Chiasm plugin that does data binding between Chiasm // components. It uses a special domain specific language (DSL) to express two // types of data binding links between two components: // // * Unidirectional `myComponent.myPropertyA -> myOtherComponent.myPropertyB` // * Bidirectional (planned, not implemented) `myComponent.myPropertyA <-> myOtherComponent.myPropertyB` function Links(chiasm) { var model = Model({ publicProperties: [ "bindings" ], bindings: [] }); var sourceListeners = []; model.when("bindings", function (bindings){ var oldSourceListeners = sourceListeners; sourceListeners = []; // Clear out the listeners for the old bindings. oldSourceListeners.forEach(function (_){ chiasm.getComponent(_.sourceAlias).then(function (sourceComponent){ sourceComponent.cancel(_.listener); }); }); // Add listeners for the new bindings. bindings.forEach(function(bindingExpr){ // Parse the binding expression of the form // "sourceAlias.sourceProperty -> targetAlias.targetProperty" var parts = bindingExpr.split("->").map(function(str){ return str.trim(); }), source = parts[0].split("."), sourceAlias = source[0], sourceProperty = source[1], target = parts[1].split("."), targetAlias = target[0], targetProperty = target[1]; // Retreive the source and target components. chiasm.getComponent(sourceAlias).then(function(sourceComponent){ chiasm.getComponent(targetAlias).then(function(targetComponent){ // TODO report errors for missing components. // Add a reactive function that binds the source to the target. var listener = sourceComponent.when(sourceProperty, function(value){ targetComponent[targetProperty] = value; }); // Keep track of the added listener so it can be removed later. sourceListeners.push({ sourceAlias: sourceAlias, listener: listener }); }); }); }); }); return model; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,74 @@ { "layout": { "plugin": "layout", "state": { "containerSelector": "#chiasm-container", "layout": { "orientation": "vertical", "children": [ "A", { "orientation": "horizontal", "children": [ "B", { "orientation": "vertical", "children": [ "C", { "orientation": "horizontal", "children": [ "D", "E", "F" ] } ] }, "G" ] } ] } } }, "A": { "plugin": "coloredRectangle" }, "B": { "plugin": "coloredRectangle", "state": { "color": "#a8f0ff" } }, "C": { "plugin": "coloredRectangle", "state": { "color": "#ffe2a8" } }, "D": { "plugin": "coloredRectangle", "state": { "color": "#99e2c8" } }, "E": { "plugin": "coloredRectangle", "state": { "color": "#99e2c8" } }, "F": { "plugin": "coloredRectangle", "state": { "color": "#99e2c8" } }, "G": { "plugin": "coloredRectangle", "state": { "color": "#a8ffd0" } } }