diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..1b7cc59 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module", + "ecmaFeatures": { + "jsx": true + } + }, + "rules": { + "semi": 2, "no-undef": 2 + } +} diff --git a/examples/boundingbox.html b/examples/boundingbox.html new file mode 100644 index 0000000..5dcb231 --- /dev/null +++ b/examples/boundingbox.html @@ -0,0 +1,92 @@ + + + + + Venn diagram of Venn diagrams + + + + +
+ + + + + + diff --git a/examples/mds.html b/examples/mds.html deleted file mode 100644 index 6dcc017..0000000 --- a/examples/mds.html +++ /dev/null @@ -1,56 +0,0 @@ - - - - - mds venn.js example - - - - -
- - - - - - - - diff --git a/examples/venn_venn.html b/examples/venn_venn.html index 2e7f884..593e31c 100644 --- a/examples/venn_venn.html +++ b/examples/venn_venn.html @@ -37,18 +37,5 @@ div.selectAll("text").style("fill", "white"); div.selectAll(".venn-circle path").style("fill-opacity", .6); - -function annotateSizes() { - d3.select(this).select("text") - .append("tspan") - .text(function(d) { return "size " + d.size; }) - .attr("x", function() { return d3.select(this.parentNode).attr("x"); }) - .attr("dy", "1.5em") - .style("fill", "#666") - .style("font-size", "10px"); -} -div.selectAll("g").transition("venn").each("end", annotateSizes).duration(0); - - diff --git a/index.js b/index.js index 2478e51..80aa1c1 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ export {fmin, minimizeConjugateGradient, bisect} from "./src/fmin"; export {intersectionArea, circleCircleIntersection, circleOverlap, circleArea, distance, circleIntegral} from "./src/circleintersection"; -export {venn, greedyLayout, classicMDSLayout, scaleSolution, normalizeSolution, bestInitialLayout, +export {venn, greedyLayout, scaleSolution, normalizeSolution, bestInitialLayout, lossFunction, disjointCluster, distanceFromIntersectArea} from "./src/layout"; export {VennDiagram, wrapText, computeTextCentres, computeTextCentre, sortAreas, circlePath, circleFromPath, intersectionAreaPath} from "./src/diagram"; diff --git a/package.json b/package.json index 5c4dc74..ed6ad11 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "venn.js", - "version": "0.2.8", + "version": "0.2.9", "author": "Ben Frederickson (http:/www.benfrederickson.com)", "url": "https://github.com/benfred/venn.js/issues", "devDependencies": { diff --git a/src/diagram.js b/src/diagram.js index 9ee4744..95da54d 100644 --- a/src/diagram.js +++ b/src/diagram.js @@ -2,6 +2,8 @@ import {venn, normalizeSolution, scaleSolution} from "./layout"; import {intersectionArea, distance, getCenter} from "./circleintersection"; import {fmin} from "./fmin"; +/*global d3 console:true*/ + export function VennDiagram() { var width = 600, height = 350, diff --git a/src/layout.js b/src/layout.js index 0ff779d..4d241c2 100644 --- a/src/layout.js +++ b/src/layout.js @@ -387,35 +387,6 @@ export function greedyLayout(areas) { return circles; } -/// Uses multidimensional scaling to approximate a first layout here -export function classicMDSLayout(areas) { - // bidirectionally map sets to a rowid (so we can create a matrix) - var sets = [], setids = {}; - for (var i = 0; i < areas.length; ++i ) { - var area = areas[i]; - if (area.sets.length == 1) { - setids[area.sets[0]] = sets.length; - sets.push(area); - } - } - - // get the distance matrix, and use to position sets - var distances = getDistanceMatrices(areas, sets, setids).distances; - var positions = mds.classic(distances); - - // translate rows back to (x,y,radius) coordinates - var circles = {}; - for (i = 0; i < sets.length; ++i) { - var set = sets[i]; - circles[set.sets[0]] = { - x: positions[i][0], - y: positions[i][1], - radius: Math.sqrt(set.size / Math.PI) - }; - } - return circles; -} - /** Given a bunch of sets, and the desired overlaps between these sets - computes the distance from the actual overlaps to the desired overlaps. Note that this method ignores overlaps of more than 2 circles */ @@ -604,7 +575,7 @@ export function normalizeSolution(solution, orientation, orientationOrder) { if (right) { xOffset = returnBounds.xRange.max - bounds.xRange.min + spacing; } else { - xOffset = returnBounds.xRange.max - bounds.xRange.max - spacing; + xOffset = returnBounds.xRange.max - bounds.xRange.max; centreing = (bounds.xRange.max - bounds.xRange.min) / 2 - (returnBounds.xRange.max - returnBounds.xRange.min) / 2; if (centreing < 0) xOffset += centreing; @@ -613,7 +584,7 @@ export function normalizeSolution(solution, orientation, orientationOrder) { if (bottom) { yOffset = returnBounds.yRange.max - bounds.yRange.min + spacing; } else { - yOffset = returnBounds.yRange.max - bounds.yRange.max - spacing; + yOffset = returnBounds.yRange.max - bounds.yRange.max; centreing = (bounds.yRange.max - bounds.yRange.min) / 2 - (returnBounds.yRange.max - returnBounds.yRange.min) / 2; if (centreing < 0) yOffset += centreing; diff --git a/venn.js b/venn.js index f1536ce..1004ef5 100644 --- a/venn.js +++ b/venn.js @@ -1135,7 +1135,7 @@ if (right) { xOffset = returnBounds.xRange.max - bounds.xRange.min + spacing; } else { - xOffset = returnBounds.xRange.max - bounds.xRange.max - spacing; + xOffset = returnBounds.xRange.max - bounds.xRange.max; centreing = (bounds.xRange.max - bounds.xRange.min) / 2 - (returnBounds.xRange.max - returnBounds.xRange.min) / 2; if (centreing < 0) xOffset += centreing; @@ -1144,7 +1144,7 @@ if (bottom) { yOffset = returnBounds.yRange.max - bounds.yRange.min + spacing; } else { - yOffset = returnBounds.yRange.max - bounds.yRange.max - spacing; + yOffset = returnBounds.yRange.max - bounds.yRange.max; centreing = (bounds.yRange.max - bounds.yRange.min) / 2 - (returnBounds.yRange.max - returnBounds.yRange.min) / 2; if (centreing < 0) yOffset += centreing; @@ -1772,4 +1772,4 @@ exports.circleFromPath = circleFromPath; exports.intersectionAreaPath = intersectionAreaPath; -})); \ No newline at end of file +}));