Commit d158c26b authored by Sylvain Schmitz's avatar Sylvain Schmitz

simplified code

parent e12ee580
......@@ -59,22 +59,51 @@ svg {
<option value="group">by Cluster</option>
</select>
</aside>
<script>
var margin = {top: 80, right: 0, bottom: 10, left: 80},
matrixw = 135,
matrixh = 135;
<script>
var N = 9;
var margin = {top: 80, right: 0, bottom: 10, left: 80},
matrixw = matrixh = 15*N;
var x = d3.scaleBand().range([0, matrixw]),
z = d3.scaleLinear().range([0.09,1]).clamp(true);
var formatPercent = d3.format(".1%");
var matrixsvg = d3.select("body").append("svg")
.attr("id", "matrix")
.attr("width", matrixw + margin.left + margin.right)
.attr("height", matrixh + margin.top + margin.bottom)
.attr("id", "matrix")
.style("margin-left", -margin.left + "px")
.style("margin-top", 20 - margin.top + "px")
.append("g")
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var width = 720,
height = 720,
outerRadius = Math.min(width, height) / 2 - 10,
innerRadius = outerRadius - 24;
var arc = d3.arc()
.innerRadius(innerRadius)
.outerRadius(outerRadius);
var layout = d3.chord()
.sortSubgroups(d3.descending)
.sortChords(d3.ascending);
layout.padding = .04;
var path = d3.ribbon()
.radius(innerRadius);
var chordsvg = d3.select("body").append("svg")
.style("margin-top", - matrixh - margin.top + "px")
.style("margin-left", matrixw + "px")
.attr("id", "chord")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("id", "circle")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
chordsvg.append("circle")
.attr("r", outerRadius);
queue()
.defer(d3.csv, "fragments.csv")
......@@ -83,12 +112,6 @@ queue()
function ready(error, fragments, matrix) {
if (error) throw error;
var mx = [], n = fragments.length;
// Compute index per node.
fragments.forEach(function(d, i) {
mx[i] = d3.range(n).map(function(j) { return {x: j, y: i, z: 0}; });
});
// maximal number of entries
var maxentries = 0;
......@@ -96,6 +119,22 @@ function ready(error, fragments, matrix) {
maxentries = (maxentries < parseInt(f.entries))?
parseInt(f.entries): maxentries;
matrixgraph(fragments, matrix, maxentries);
chordgraph(fragments, matrix, maxentries);
}
function matrixgraph(fragments, matrix, maxentries) {
var mx = [], n = fragments.length;
var x = d3.scaleBand().range([0, matrixw]),
z = d3.scaleLinear().range([0.09,1]).clamp(true);
// Compute index per node.
fragments.forEach(function(d, i) {
mx[i] = d3.range(n).map(function(j) { return {x: j, y: i, z: 0}; });
});
// Convert matrix; count character occurrences.
var maxdiff = 0;
for (var i = 0; i < n; i++)
......@@ -220,59 +259,13 @@ function ready(error, fragments, matrix) {
d3.select("#order").property("selectedIndex", 2).node().focus();
}, 5000);
}
</script>
<script>
var width = 720,
height = 720,
outerRadius = Math.min(width, height) / 2 - 10,
innerRadius = outerRadius - 24;
var formatPercent = d3.format(".1%");
var arc = d3.arc()
.innerRadius(innerRadius)
.outerRadius(outerRadius);
var layout = d3.chord()
.sortSubgroups(d3.descending)
.sortChords(d3.ascending);
layout.padding = .04;
var path = d3.ribbon()
.radius(innerRadius);
var chordsvg = d3.select("body").append("svg")
.style("margin-top", 20 - margin.top + "px")
.attr("id", "chord")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("id", "circle")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
chordsvg.append("circle")
.attr("r", outerRadius);
queue()
.defer(d3.csv, "fragments.csv")
.defer(d3.json, "matrix.json")
.await(ready);
function ready(error, fragments, matrix) {
if (error) throw error;
function chordgraph(fragments, matrix, maxentries) {
// total number of entries
var nentries = 0;
for (let f of fragments)
nentries += parseInt(f.entries);
// maximal number of entries
var maxentries = 0;
for (let f of fragments)
maxentries = (maxentries < parseInt(f.entries))?
parseInt(f.entries): maxentries;
nentries += parseInt(f.entries);
layout.matrix = matrix;
layout.n = matrix.length;
layout.padding = .04;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment