forked from nicgirault/circosJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move axes in separated file and complet axe document
- Loading branch information
1 parent
eaf9bcd
commit 0dcb9e8
Showing
9 changed files
with
300 additions
and
84 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang='en'> | ||
|
||
<head> | ||
<title>circosJS</title> | ||
<meta charset='utf-8'></meta> | ||
<script src='../../dist/circos.js'></script> | ||
<script src='https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.js'></script> | ||
<script src='https://cdnjs.cloudflare.com/ajax/libs/d3-queue/3.0.3/d3-queue.js'></script> | ||
</head> | ||
|
||
<body> | ||
<div id='chart1'></div> | ||
<div id='chart2'></div> | ||
<div id='chart3'></div> | ||
<script src='./index.js'></script> | ||
</body> | ||
</html> |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
var main = function(error, snp250) { | ||
|
||
snp250 = snp250 | ||
.filter(function (d) { | ||
return d.chromosome === 'chr2' | ||
}) | ||
.map(function (d) { | ||
return { | ||
block_id: d.chromosome, | ||
position: (parseInt(d.start) + parseInt(d.end)) / 2, | ||
value: d.value | ||
} | ||
}) | ||
|
||
buildCircos('#chart1', snp250, [ | ||
{ | ||
color: 'red', | ||
position: 0.002 | ||
}, | ||
{ | ||
color: 'green', | ||
position: 0.013 | ||
} | ||
]) | ||
|
||
buildCircos('#chart2', snp250, [ | ||
{ | ||
color: '#333333', | ||
spacing: 0.001, | ||
opacity: 0.3, | ||
} | ||
]) | ||
|
||
buildCircos('#chart3', snp250, [ | ||
{ | ||
color: 'red', | ||
opacity: 0.3, | ||
spacing: 0.001, | ||
end: 0.004 | ||
}, | ||
{ | ||
color: 'green', | ||
opacity: 0.3, | ||
spacing: 0.001, | ||
start: 0.011 | ||
}, | ||
{ | ||
color: '#333333', | ||
opacity: 0.3, | ||
spacing: 0.002, | ||
thickness: 2, | ||
start: 0.004, | ||
end: 0.011 | ||
}, | ||
{ | ||
color: '#333333', | ||
opacity: 0.3, | ||
spacing: 0.001, | ||
thickness: 1, | ||
start: 0.004, | ||
end: 0.011 | ||
} | ||
]) | ||
} | ||
|
||
var buildCircos = function (container, snp250, axes) { | ||
var circos = new Circos({ | ||
container: container, | ||
width: 1000, | ||
height: 1000 | ||
}) | ||
|
||
circos | ||
.layout( | ||
[{id: "chr2", color: '#03a9f4', len:243199373}], | ||
{ | ||
innerRadius: 400, | ||
outerRadius: 400, | ||
labels: {display: false}, | ||
ticks: {display: false} | ||
} | ||
) | ||
.line('snp-250', snp250, { | ||
innerRadius: 0.5, | ||
outerRadius: 0.8, | ||
min: 0, | ||
max: 0.015, | ||
color: '#222222', | ||
axes: axes, | ||
}) | ||
.render() | ||
} | ||
|
||
d3.queue() | ||
.defer(d3.csv, '../data/snp.density.250kb.txt') | ||
.await(main) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import range from 'lodash/range' | ||
import reduce from 'lodash/reduce' | ||
import {arc} from 'd3-shape' | ||
|
||
const buildAxesData = (conf) => { | ||
return reduce(conf.axes, (aggregator, axesGroup) => { | ||
if (axesGroup.position) { | ||
aggregator.push({ | ||
value: axesGroup.position, | ||
thickness: axesGroup.thickness || 1, | ||
color: axesGroup.color || '#d3d3d3', | ||
opacity: axesGroup.opacity || conf.opacity | ||
}) | ||
} | ||
if (axesGroup.spacing) { | ||
const builtAxes = range( | ||
axesGroup.start || conf.cmin, | ||
axesGroup.end || conf.cmax, | ||
axesGroup.spacing | ||
) | ||
.map((value) => { | ||
return { | ||
value: value, | ||
thickness: axesGroup.thickness || 1, | ||
color: axesGroup.color || '#d3d3d3', | ||
opacity: axesGroup.opacity || conf.opacity | ||
} | ||
}) | ||
return aggregator.concat(builtAxes) | ||
} | ||
return aggregator | ||
}, []) | ||
} | ||
|
||
export const renderAxes = (parentElement, conf, layout, scale) => { | ||
const axes = buildAxesData(conf) | ||
|
||
const axis = arc() | ||
.innerRadius((d) => { | ||
return conf.direction === 'in' | ||
? conf.outerRadius - scale(d.value) | ||
: conf.innerRadius + scale(d.value) | ||
}) | ||
.outerRadius((d) => { | ||
return conf.direction === 'in' | ||
? conf.outerRadius - scale(d.value) | ||
: conf.innerRadius + scale(d.value) | ||
}) | ||
.startAngle(0) | ||
.endAngle((d) => d.length) | ||
|
||
return parentElement | ||
.selectAll('.axis') | ||
.data((blockData) => { | ||
const block = layout.blocks[blockData.key] | ||
return axes.map((d) => { | ||
return { | ||
value: d.value, | ||
thickness: d.thickness, | ||
color: d.color, | ||
opacity: d.opacity, | ||
block_id: blockData.key, | ||
length: block.end - block.start | ||
} | ||
}) | ||
}) | ||
.enter() | ||
.append('path') | ||
.attr('opacity', (d) => d.opacity) | ||
.attr('class', 'axis') | ||
.attr('d', axis) | ||
.attr('stroke-width', (d) => d.thickness) | ||
.attr('stroke', (d) => d.color) | ||
} |
This file contains 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 characters
Oops, something went wrong.