diff --git a/.babelrc b/.babelrc index 3c3b968..3db41c1 100644 --- a/.babelrc +++ b/.babelrc @@ -1,4 +1,12 @@ { - "presets": ["es2015"], - "plugins": ["transform-object-assign"] + "presets": [ + [ + "@babel/preset-env", + { + "targets": { + "browsers": ["last 2 versions"] + } + } + ] + ] } diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..496b120 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,32 @@ +# Javascript Node CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-javascript/ for more details +# +version: 2.1 +jobs: + build: + docker: + # specify the version you desire here + - image: circleci/node:10 + + working_directory: ~/repo + + steps: + - checkout + + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "package.json" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + + - run: yarn install + + - save_cache: + paths: + - node_modules + key: v1-dependencies-{{ checksum "package.json" }} + + # run tests! + - run: yarn test diff --git a/.eslintrc b/.eslintrc index bd60054..91241a9 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,35 +1,51 @@ { - "parserOptions": { - "ecmaVersion": 6, - "sourceType": "module" - }, - "extends": ["eslint:recommended", "google"], - "plugins": ["import"], - "rules": { - "arrow-parens": ["error", "as-needed"], - "no-underscore-dangle": "off", - "no-use-before-define": "off", - "no-confusing-arrow": "off", - "no-unused-vars": "off", - "no-plusplus": "off", - "no-else-return": "off", - "one-var": "off", - "require-jsdoc": "off", - "valid-jsdoc": "off", - "space-before-function-paren": ["error", {"anonymous": "always", "named": "never", "asyncArrow": "always"}], - "no-param-reassign": ["error", { "props": false }], - "indent": ["error", 4], - "max-len": "off", - "quotes": ["error", "double"], - "new-cap": "off", - "no-invalid-this": "off", - "no-console": "off", - }, - "env": { - "browser": true - }, - "globals": { - "d3": false, - "$": false - } + "plugins": ["jest", "@typescript-eslint"], + "extends": [ + "plugin:@typescript-eslint/recommended", + "plugin:jest/recommended" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "./tsconfig.json" + }, + "rules": { + "@typescript-eslint/explicit-member-accessibility": "off", + "@typescript-eslint/explicit-function-return-type": [ + "error", + { + "allowExpressions": true + } + ], + "@typescript-eslint/no-parameter-properties": "off", + "arrow-parens": ["error", "as-needed"], + "indent": ["error", 2], + "max-len": [ + "warn", + { + "code": 100 + } + ], + "no-invalid-this": "warn", + "no-param-reassign": [ + "error", + { + "props": false + } + ], + "object-curly-spacing": ["error", "always"], + "quotes": ["error", "double"], + "require-jsdoc": "off", + "space-before-function-paren": [ + "error", + { + "anonymous": "always", + "named": "never", + "asyncArrow": "always" + } + ] + }, + "env": { + "browser": true, + "jest/globals": true + } } diff --git a/.gitignore b/.gitignore index ce380c6..6a2153b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/* .DS_Store +yarn-error.log diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index de9deb2..0000000 --- a/Gruntfile.js +++ /dev/null @@ -1,54 +0,0 @@ -module.exports = function (grunt) { - grunt.initConfig({ - pkg: grunt.file.readJSON("package.json"), - webpack: { - dist: { - entry: "./src/index.js", - output: { - path: "dist/", - filename: "<%= pkg.name %>.js", - }, - devtool: "source-map", - module: { - loaders: [ - { - loader: "babel-loader", - }, - ], - }, - }, - }, - eslint: { - src: ["src/**/*.js"], - }, - uglify: { - options: { - // the banner is inserted at the top of the output - banner: "/*! <%= pkg.name %> <%= pkg.version %> <%= grunt.template.today(\"dd-mm-yyyy\") %> */\n", - }, - dist: { - files: { - "dist/<%= pkg.name %>.min.js": ["dist/<%= pkg.name %>.es5.js"], - }, - }, - }, - babel: { - options: { - sourceMap: true, - }, - dist: { - files: { - "dist/<%= pkg.name %>.es5.js": ["dist/<%= pkg.name %>.js"], - }, - }, - }, - }); - - grunt.loadNpmTasks("grunt-contrib-uglify"); - grunt.loadNpmTasks("grunt-babel"); - grunt.loadNpmTasks("grunt-webpack"); - grunt.loadNpmTasks("gruntify-eslint"); - - // the default task can be run just by typing "grunt" on the command line - grunt.registerTask("default", ["eslint", "webpack", "babel", "uglify"]); -}; diff --git a/dist/bundle.js b/dist/bundle.js new file mode 100644 index 0000000..8c503f3 --- /dev/null +++ b/dist/bundle.js @@ -0,0 +1,113 @@ +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(); + else if(typeof define === 'function' && define.amd) + define([], factory); + else if(typeof exports === 'object') + exports["Heatmap"] = factory(); + else + root["Heatmap"] = factory(); +})(window, function() { +return /******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // create a fake namespace object +/******/ // mode & 1: value is a module id, require it +/******/ // mode & 2: merge all properties of value into the ns +/******/ // mode & 4: return value when already ns object +/******/ // mode & 8|1: behave like require +/******/ __webpack_require__.t = function(value, mode) { +/******/ if(mode & 1) value = __webpack_require__(value); +/******/ if(mode & 8) return value; +/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; +/******/ var ns = Object.create(null); +/******/ __webpack_require__.r(ns); +/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); +/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); +/******/ return ns; +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = "./src/index.ts"); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ "./src/index.ts": +/*!**********************!*\ + !*** ./src/index.ts ***! + \**********************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +/***/ }) + +/******/ }); +}); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly9IZWF0bWFwL3dlYnBhY2svdW5pdmVyc2FsTW9kdWxlRGVmaW5pdGlvbiIsIndlYnBhY2s6Ly9IZWF0bWFwL3dlYnBhY2svYm9vdHN0cmFwIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FB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index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..e69de29 diff --git a/dist/lib/utils.d.ts b/dist/lib/utils.d.ts new file mode 100644 index 0000000..7bdf32f --- /dev/null +++ b/dist/lib/utils.d.ts @@ -0,0 +1,3 @@ +export declare function stringHash(s: string): number; +export declare function brightness(rgb: d3.RGBColor): number; +export declare function getReadableColorFor(color: string): string; diff --git a/dist/unipept-visualizations.es5.js b/dist/unipept-visualizations.es5.js deleted file mode 100644 index 0997407..0000000 --- a/dist/unipept-visualizations.es5.js +++ /dev/null @@ -1,2096 +0,0 @@ -"use strict"; - -var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; - -/******/(function (modules) { - // webpackBootstrap - /******/ // The module cache - /******/var installedModules = {}; - /******/ - /******/ // The require function - /******/function __webpack_require__(moduleId) { - /******/ - /******/ // Check if module is in cache - /******/if (installedModules[moduleId]) - /******/return installedModules[moduleId].exports; - /******/ - /******/ // Create a new module (and put it into the cache) - /******/var module = installedModules[moduleId] = { - /******/exports: {}, - /******/id: moduleId, - /******/loaded: false - /******/ }; - /******/ - /******/ // Execute the module function - /******/modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); - /******/ - /******/ // Flag the module as loaded - /******/module.loaded = true; - /******/ - /******/ // Return the exports of the module - /******/return module.exports; - /******/ - } - /******/ - /******/ - /******/ // expose the modules object (__webpack_modules__) - /******/__webpack_require__.m = modules; - /******/ - /******/ // expose the module cache - /******/__webpack_require__.c = installedModules; - /******/ - /******/ // __webpack_public_path__ - /******/__webpack_require__.p = ""; - /******/ - /******/ // Load entry module and return exports - /******/return __webpack_require__(0); - /******/ -})( -/************************************************************************/ -/******/[ -/* 0 */ -/***/function (module, exports, __webpack_require__) { - - "use strict"; - - var _treeview = __webpack_require__(1); - - var _treeview2 = _interopRequireDefault(_treeview); - - var _treemap = __webpack_require__(6); - - var _treemap2 = _interopRequireDefault(_treemap); - - var _sunburst = __webpack_require__(8); - - var _sunburst2 = _interopRequireDefault(_sunburst); - - function _interopRequireDefault(obj) { - return obj && obj.__esModule ? obj : { default: obj }; - } - - /***/ -}, -/* 1 */ -/***/function (module, exports, __webpack_require__) { - - "use strict"; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - - var _extends = Object.assign || function (target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i];for (var key in source) { - if (Object.prototype.hasOwnProperty.call(source, key)) { - target[key] = source[key]; - } - } - }return target; - }; /** - * Zoomable treeview, inspiration from - * - http://bl.ocks.org/mbostock/4339083 - * - https://gist.github.com/robschmuecker/7880033 - * - http://www.brightpointinc.com/interactive/budget/index.html?source=d3js - */ - - exports.default = TreeView; - - var _univis = __webpack_require__(2); - - var _univis2 = _interopRequireDefault(_univis); - - var _maxcountheap = __webpack_require__(3); - - var _maxcountheap2 = _interopRequireDefault(_maxcountheap); - - var _treeviewNode = __webpack_require__(4); - - var _treeviewNode2 = _interopRequireDefault(_treeviewNode); - - function _interopRequireDefault(obj) { - return obj && obj.__esModule ? obj : { default: obj }; - } - - function TreeView(element, data) { - var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - - var that = {}; - - var MARGIN = { - top: 5, - right: 5, - bottom: 5, - left: 5 - }, - DURATION = 750, - COLOR_SCALE = d3.scale.category10(), - DEFAULTS = { - height: 300, - width: 600, - nodeDistance: 180, - levelsToExpand: 2, - minNodeSize: 2, - maxNodeSize: 105, - - countAccessor: function countAccessor(d) { - return d.data.count; - }, - rerootCallback: undefined, - - colors: function colors(d) { - return COLOR_SCALE(d.name); - }, - nodeFillColor: nodeFillColor, - nodeStrokeColor: nodeStrokeColor, - linkStrokeColor: linkStrokeColor, - - enableInnerArcs: true, - enableExpandOnClick: true, - enableRightClick: true, - - enableLabels: true, - getLabel: function getLabel(d) { - return d.name; - }, - - enableTooltips: true, - getTooltip: getTooltip, - getTooltipTitle: _univis2.default.getTooltipTitle, - getTooltipText: _univis2.default.getTooltipText, - enableAutoExpand: false - }; - - var settings = void 0; - - var visibleRoot = void 0, - tooltipTimer = void 0; - - var nodeId = 0, - root = void 0; - - var tree = void 0, - tooltip = void 0, - diagonal = void 0, - widthScale = void 0, - innerArc = void 0, - zoomListener = void 0, - svg = void 0; - - function init() { - settings = _extends({}, DEFAULTS, options); - _treeviewNode2.default.settings = settings; - - settings.width = settings.width - MARGIN.right - MARGIN.left; - settings.height = settings.height - MARGIN.top - MARGIN.bottom; - - if (settings.enableTooltips) { - initTooltip(); - } - - if (settings.enableInnerArcs) { - initInnerArcs(); - } - - tree = d3.layout.tree().nodeSize([2, 10]).separation(function (a, b) { - var width = nodeSize(a) + nodeSize(b), - distance = width / 2 + 4; - return a.parent === b.parent ? distance : distance + 4; - }); - - diagonal = d3.svg.diagonal().projection(function (d) { - return [d.y, d.x]; - }); - - widthScale = d3.scale.linear().range([settings.minNodeSize, settings.maxNodeSize]); - - // define the zoomListener which calls the zoom function on the "zoom" event constrained within the scaleExtents - zoomListener = d3.behavior.zoom().scaleExtent([0.1, 3]).on("zoom", function () { - svg.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")"); - }); - - svg = d3.select(element).append("svg").attr("version", "1.1").attr("xmlns", "http://www.w3.org/2000/svg").attr("viewBox", "0 0 " + (settings.width + MARGIN.right + MARGIN.left) + " " + (settings.height + MARGIN.top + MARGIN.bottom)).attr("width", settings.width + MARGIN.right + MARGIN.left).attr("height", settings.height + MARGIN.top + MARGIN.bottom).style("font-family", "'Helvetica Neue', Helvetica, Arial, sans-serif").call(zoomListener).append("g").attr("transform", "translate(" + MARGIN.left + "," + MARGIN.top + ")").append("g"); - - draw(_treeviewNode2.default.createNode(data)); - } - - function initTooltip() { - tooltip = d3.select("body").append("div").attr("id", element.id + "-tooltip").attr("class", "tip").style("position", "absolute").style("z-index", "10").style("visibility", "hidden").style("background-color", "white").style("padding", "2px").style("border", "1px solid #dddddd").style("border-radius", "3px;"); - } - - function initInnerArcs() { - var arcScale = d3.scale.linear().range([0, 2 * Math.PI]); - - innerArc = d3.svg.arc().outerRadius(nodeSize).startAngle(0).endAngle(function (d) { - return arcScale(d.data.self_count / d.data.count) || 0; - }); - } - - function draw(data) { - var _this = this; - - widthScale.domain([0, data.data.count]); - - root = data; - root.x0 = settings.height / 2; - root.y0 = 0; - - // set everything visible - root.setSelected(true); - - root.children.forEach(function (d, i) { - d.color = d3.functor(settings.colors).call(_this, d, i); - d.setRecursiveProperty("color", d.color); - }); - - if (settings.enableExpandOnClick) { - root.collapseAll(); - initialExpand(root); - } else { - root.expandAll(); - } - - update(root); - centerNode(root); - } - - function initialExpand(root) { - if (!settings.enableAutoExpand) { - root.expand(); - return; - } - - root.expand(1); - var allowedCount = root.data.count * (Number.isFinite(settings.enableAutoExpand) ? settings.enableAutoExpand : 0.8); - var pq = new _maxcountheap2.default(root.children || []); - while (allowedCount > 0 && pq.size > 0) { - var toExpand = pq.remove(); - allowedCount -= toExpand.data.count; - toExpand.expand(1); - (toExpand.children || []).forEach(function (c) { - return pq.add(c); - }); - } - } - - function update(source) { - // Compute the new tree layout. - var nodes = tree.nodes(root).reverse(), - links = tree.links(nodes); - - // Normalize for fixed-depth. - nodes.forEach(function (d) { - d.y = d.depth * settings.nodeDistance; - }); - - // Update the nodes… - var node = svg.selectAll("g.node").data(nodes, function (d) { - return d.id || (d.id = ++nodeId); - }); - - // Enter any new nodes at the parent's previous position. - var nodeEnter = node.enter().append("g").attr("class", "node").style("cursor", "pointer").attr("transform", function (d) { - return "translate(" + (source.y || 0) + "," + (source.x0 || 0) + ")"; - }).on("click", click).on("mouseover", tooltipIn).on("mouseout", tooltipOut).on("contextmenu", rightClick); - - nodeEnter.append("circle").attr("r", 1e-6).style("stroke-width", "1.5px").style("stroke", settings.nodeStrokeColor).style("fill", settings.nodeFillColor); - - if (settings.enableInnerArcs) { - nodeEnter.append("path").attr("d", innerArc).style("fill", settings.nodeStrokeColor).style("fill-opacity", 0); - } - - if (settings.enableLabels) { - nodeEnter.append("text").attr("x", function (d) { - return d.isLeaf() ? 10 : -10; - }).attr("dy", ".35em").attr("text-anchor", function (d) { - return d.isLeaf() ? "start" : "end"; - }).text(settings.getLabel).style("font", "10px sans-serif").style("fill-opacity", 1e-6); - } - - // Transition nodes to their new position. - var nodeUpdate = node.transition().duration(DURATION).attr("transform", function (d) { - return "translate(" + d.y + "," + d.x + ")"; - }); - - nodeUpdate.select("circle").attr("r", nodeSize).style("fill-opacity", function (d) { - return d._children ? 1 : 0; - }).style("stroke", settings.nodeStrokeColor).style("fill", settings.nodeFillColor); - - if (settings.enableLabels) { - nodeUpdate.select("text").style("fill-opacity", 1); - } - - if (settings.enableInnerArcs) { - nodeUpdate.select("path").duration(DURATION).attr("d", innerArc).style("fill-opacity", 0.8); - } - - // Transition exiting nodes to the parent's new position. - var nodeExit = node.exit().transition().duration(DURATION).attr("transform", function (d) { - return "translate(" + source.y + "," + source.x + ")"; - }).remove(); - - nodeExit.select("circle").attr("r", 1e-6); - - nodeExit.select("path").style("fill-opacity", 1e-6); - - nodeExit.select("text").style("fill-opacity", 1e-6); - - // Update the links… - var link = svg.selectAll("path.link").data(links, function (d) { - return d.target.id; - }); - - // Enter any new links at the parent's previous position. - link.enter().insert("path", "g").attr("class", "link").style("fill", "none").style("stroke-opacity", "0.5").style("stroke-linecap", "round").style("stroke", settings.linkStrokeColor).style("stroke-width", 1e-6).attr("d", function (d) { - var o = { - x: source.x0 || 0, - y: source.y0 || 0 - }; - return diagonal({ - source: o, - target: o - }); - }); - - // Transition links to their new position. - link.transition().duration(DURATION).attr("d", diagonal).style("stroke", settings.linkStrokeColor).style("stroke-width", function (d) { - if (d.source.selected) { - return widthScale(d.target.data.count) + "px"; - } else { - return "4px"; - } - }); - - // Transition exiting nodes to the parent's new position. - link.exit().transition().duration(DURATION).style("stroke-width", 1e-6).attr("d", function (d) { - var o = { - x: source.x, - y: source.y - }; - return diagonal({ - source: o, - target: o - }); - }).remove(); - - // Stash the old positions for transition. - nodes.forEach(function (d) { - var _ref = [d.x, d.y]; - d.x0 = _ref[0]; - d.y0 = _ref[1]; - }); - } - - function nodeSize(d) { - if (d.selected) { - return widthScale(d.data.count) / 2; - } else { - return 2; - } - } - - // Toggle children on click. - function click(d) { - if (!settings.enableExpandOnClick) { - return; - } - - // check if click is triggered by panning on a node - if (d3.event.defaultPrevented) { - return; - } - - if (d3.event.shiftKey) { - d.expandAll(); - } else if (d.children) { - d.collapse(); - } else { - d.expand(); - } - update(d); - centerNode(d); - } - - function rightClick(d) { - if (settings.enableRightClick) { - reroot(d); - } - } - - // Sets the width of the right clicked node to 100% - function reroot(d) { - if (d === visibleRoot && d !== root) { - reroot(root); - return; - } - visibleRoot = d; - - // set Selection properties - root.setSelected(false); - d.setSelected(true); - - // scale the lines - widthScale.domain([0, d.data.count]); - - d.expand(); - - // redraw - if (d3.event !== null) { - d3.event.preventDefault(); - } - update(d); - centerNode(d); - - if (settings.rerootCallback) { - settings.rerootCallback.call(null, d); - } - } - - // Center a node - function centerNode(source) { - var scale = zoomListener.scale(), - x = -source.y0, - y = -source.x0; - - x = x * scale + settings.width / 4; - y = y * scale + settings.height / 2; - svg.transition().duration(DURATION).attr("transform", "translate(" + x + "," + y + ")scale(" + scale + ")"); - zoomListener.scale(scale); - zoomListener.translate([x, y]); - } - - // tooltip functions - function tooltipIn(d, i) { - if (!settings.enableTooltips) { - return; - } - tooltip.html(settings.getTooltip(d)).style("top", d3.event.pageY - 5 + "px").style("left", d3.event.pageX + 15 + "px"); - - tooltipTimer = setTimeout(function () { - tooltip.style("visibility", "visible"); - }, 1000); - } - - function tooltipOut(d, i) { - if (!settings.enableTooltips) { - return; - } - clearTimeout(tooltipTimer); - tooltip.style("visibility", "hidden"); - } - - /** ************ Default methods ***************/ - // set fill color - function nodeFillColor(d) { - if (d.selected) { - return d._children ? d.color || "#aaa" : "#fff"; - } else { - return "#aaa"; - } - } - - // set node stroke color - function nodeStrokeColor(d) { - if (d.selected) { - return d.color || "#aaa"; - } else { - return "#aaa"; - } - } - - // set link stroke color - function linkStrokeColor(d) { - if (d.source.selected) { - return d.target.color; - } else { - return "#aaa"; - } - } - - function getTooltip(d) { - return "
" + settings.getTooltipText(d) + "
"; - } - - /** ************* Public methods ***************/ - that.reset = function reset() { - zoomListener.scale(1); - reroot(root); - }; - - /** - * Sets the visualisation in full screen mode - * - * @param