├── .gitignore ├── js ├── collections │ ├── edge-collection.js │ └── node-collection.js ├── models │ ├── edge-model.js │ ├── node-model.js │ └── graph-model.js ├── tests │ ├── tests-master.js │ └── tests.js ├── main.js ├── views │ ├── concept-list-item.js │ └── concept-list-view.js └── lib │ ├── backbone.touch.js │ ├── underscore-min.js │ ├── require-min.js │ └── backbone-min.js ├── tests.html ├── css ├── demo.css ├── mocha.css ├── list.css └── graph.css ├── LICENSE ├── demo ├── demojs │ ├── dev.js │ └── khan.js ├── dev.html └── khan.html ├── README.md └── data └── metacademy_demo.json /.gitignore: -------------------------------------------------------------------------------- 1 | .tern-port 2 | .DS_Store 3 | demo_kmap.json 4 | -------------------------------------------------------------------------------- /js/collections/edge-collection.js: -------------------------------------------------------------------------------- 1 | /*global define */ 2 | define(["backbone", "../models/edge-model"], function(Backbone, DirectedEdge){ 3 | return Backbone.Collection.extend({ 4 | model: DirectedEdge 5 | }); 6 | }); 7 | -------------------------------------------------------------------------------- /tests.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /css/demo.css: -------------------------------------------------------------------------------- 1 | html { 2 | overflow: hidden; 3 | } 4 | 5 | body { 6 | margin: 0; 7 | padding: 0; 8 | width: 100%; 9 | height: 100%; 10 | font-size: 1.0em; 11 | overflow: hidden; 12 | font-family: "Lato", Arial, sans-serif; 13 | } 14 | 15 | #graph-view-wrapper{ 16 | height: inherit; 17 | width: 100%; 18 | } 19 | 20 | #main-display-view{ 21 | height: inherit; 22 | overflow: auto; 23 | } 24 | -------------------------------------------------------------------------------- /js/collections/node-collection.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file contains the node collection 3 | * it is a basic collection that should not depend on aux 4 | */ 5 | 6 | /*global define */ 7 | define(['backbone', 'underscore', 'jquery', '../models/node-model'], function(Backbone, _, $, NodeModel){ 8 | "use strict"; 9 | 10 | /** 11 | * Collection of all node models in graph 12 | */ 13 | return Backbone.Collection.extend({ 14 | model: NodeModel 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /js/models/edge-model.js: -------------------------------------------------------------------------------- 1 | /*global define*/ 2 | define(["backbone"], function(Backbone){ 3 | /** 4 | * general directed edge model 5 | */ 6 | return Backbone.Model.extend({ 7 | 8 | /** 9 | * default values -- underscore attribs used to match data from server 10 | */ 11 | defaults: function () { 12 | return { 13 | from_tag: "", 14 | to_tag: "", 15 | reason: "" 16 | }; 17 | }, 18 | 19 | /** 20 | * Initialize the DE (currently sets the id properly) 21 | */ 22 | initialize: function(inp){ 23 | this.id = inp.id || inp.from_tag + inp.to_tag; 24 | } 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright 2018 Colorado Reed 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /js/tests/tests-master.js: -------------------------------------------------------------------------------- 1 | 2 | /*global require*/ 3 | require.config({ 4 | baseUrl: "/js", 5 | paths: { 6 | jquery:"lib/jquery-1.10.2.min", 7 | underscore: "lib/underscore-min", 8 | backbone: "lib/backbone-min", 9 | d3: "lib/d3", 10 | "dagre": "lib/dagre", 11 | "btouch": "lib/backbone.touch", 12 | "chai": "lib/chai", 13 | "mocha": "lib/mocha" 14 | }, 15 | 16 | shim: { 17 | 'underscore': { 18 | exports: '_' 19 | }, 20 | dagre: { 21 | exports: "dagre" 22 | }, 23 | 'jquery': { 24 | exports: '$' 25 | }, 26 | 'backbone': { 27 | deps: ['underscore', 'jquery'], 28 | exports: 'Backbone' 29 | }, 30 | "btouch": { 31 | deps: ["jquery", "underscore", "backbone"] 32 | }, 33 | 'mocha': { 34 | init: function () { 35 | this.mocha.setup('bdd'); 36 | return this.mocha; 37 | } 38 | } 39 | }, 40 | urlArgs: 'bust=' + (new Date()).getTime() 41 | }); 42 | 43 | require(['require', 'chai', 'mocha', 'jquery'], function(require, chai, mocha, $){ 44 | 45 | require([ 46 | 'tests/tests' 47 | ], function(require) { 48 | if (window.mochaPhantomJS) { window.mochaPhantomJS.run(); } 49 | else { mocha.run(); } 50 | }); 51 | 52 | }); 53 | -------------------------------------------------------------------------------- /js/main.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Basic kmap demonstration 3 | */ 4 | 5 | /*global requirejs, define*/ 6 | 7 | // configure requirejs 8 | requirejs.config( { 9 | // TODO use min files here since we're not using a compressor 10 | paths: { 11 | jquery:"lib/jquery-1.10.2.min", 12 | backbone: "lib/backbone-min", 13 | underscore: "lib/underscore-min", 14 | d3: "lib/d3", 15 | "dagre": "lib/dagre", 16 | "btouch": "lib/backbone.touch" 17 | }, 18 | shim: { 19 | d3: { 20 | exports: "d3" 21 | }, 22 | dagre: { 23 | exports: "dagre" 24 | }, 25 | underscore: { 26 | exports: "_" 27 | }, 28 | backbone: { 29 | deps: ['underscore', 'jquery'], 30 | exports: 'Backbone' 31 | }, 32 | "btouch": { 33 | deps: ["jquery", "underscore", "backbone"] 34 | } 35 | } 36 | }); 37 | 38 | //main execution 39 | define(["models/graph-model", "views/graph-view", "views/concept-list-view", "jquery", "btouch"], function(GraphModel, GraphView, ListView){ 40 | var KMap = {}; 41 | KMap.GraphModel = GraphModel; 42 | KMap.GraphView = GraphView; 43 | KMap.GraphListView = ListView; 44 | /* make the KMap object global 45 | this hack provides a library-esk mode for kmap 46 | and preserves metacademy integration */ 47 | window.KMap = KMap; 48 | return KMap; 49 | }); 50 | -------------------------------------------------------------------------------- /demo/demojs/dev.js: -------------------------------------------------------------------------------- 1 | // development testing script - not used for library 2 | 3 | require.config({ 4 | baseUrl: "../js" 5 | }); 6 | 7 | 8 | /*global require, KMap, $*/ 9 | require(["main"], function(KMap){ 10 | // create the model/settings so we can pass it into the views 11 | var graphModel = new KMap.GraphModel(), 12 | settings = {model: graphModel, useWisps: false, graphDirection: "TB", showTransEdgesWisps: true}; 13 | 14 | var graphView = new KMap.GraphView(settings), 15 | graphListView = new KMap.GraphListView({model: graphModel}); 16 | 17 | var handleDataFun = function (data) { 18 | 19 | // add the data to the graph model 20 | graphModel.addJsonNodesToGraph(data); 21 | 22 | // set the graph placement (don't use if "x" and "y" are specified in the data) 23 | graphView.optimizeGraphPlacement(false, false); 24 | 25 | // render the views 26 | graphView.render(); 27 | graphListView.render(); 28 | 29 | // insert them into the html 30 | $("body").prepend(graphListView.$el); 31 | $("#graph-view-wrapper").append(graphView.$el); 32 | 33 | // TODO integrate this into the view 34 | var $wrap = $(document.body); 35 | $wrap.height($(window).height()); 36 | $(window).resize(function () { 37 | $wrap.height($(window).height()); 38 | }); 39 | 40 | // center on a leaf element 41 | var topoSortList = graphModel.getTopoSort(); 42 | graphView.centerForNode(graphModel.getNode(topoSortList[topoSortList.length -1])); 43 | 44 | }; 45 | 46 | // fetch some graph data 47 | $.getJSON("../data/metacademy_demo.json", handleDataFun); 48 | 49 | }); 50 | -------------------------------------------------------------------------------- /demo/dev.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
10 |
11 |
12 |
13 |