Commit c036a3f0 authored by Remi  PLANEL's avatar Remi PLANEL
Browse files

Rename genome-axis-with-selection.ts to brushable-genome-axis.ts

parent cca73be6
import { GlobalAxisData, GenericAxisData } from "../../types"; import { BrushableAxisData, GenericAxisData } from "../../types";
import { select, Selection } from "d3-selection"; import { select, Selection } from "d3-selection";
import { scaleLinear } from "d3-scale"; import { scaleLinear } from "d3-scale";
import GenomeAxis from "./genome-axis"; import GenomeAxis from "./genome-axis";
import { brushX, BrushBehavior } from "d3-brush";
export default function () { export default function () {
const GenomeAxisComponent = GenomeAxis(); const genomeAxisComponent = GenomeAxis();
function globalGenomeAxis( function globalGenomeAxis(
_selection: Selection<SVGElement, GlobalAxisData, SVGElement, any>, _selection: Selection<SVGElement, BrushableAxisData, SVGElement, any>,
width: number, width: number,
yPosition: number yPosition: number
) { ) {
...@@ -16,10 +17,18 @@ export default function () { ...@@ -16,10 +17,18 @@ export default function () {
.domain(_data.interval) .domain(_data.interval)
.range([0, width]); .range([0, width]);
const brush: BrushBehavior<any> = brushX()
.extent([[0, 0], [width, 50]])
.on("brush", () => {
if (_data.eventHandler) {
_data.eventHandler.brushed(genomeAxisComponent.scale())
}
});
const container = select(this) const container = select(this)
.attr("transform", "translate(0," + yPosition + ")"); .attr("transform", "translate(0," + yPosition + ")");
const globalAxis = container const globalAxis = container
.selectAll<SVGElement, GlobalAxisData>("g.global-axis-container") .selectAll<SVGElement, BrushableAxisData>("g.global-axis-container")
.data([_data]); .data([_data]);
const globalAxisEnter = globalAxis const globalAxisEnter = globalAxis
...@@ -27,32 +36,29 @@ export default function () { ...@@ -27,32 +36,29 @@ export default function () {
.append<SVGElement>("g") .append<SVGElement>("g")
.classed("global-axis-container", true); .classed("global-axis-container", true);
globalAxisEnter.append("g").classed("generic-axis", true); globalAxisEnter.append("g")
globalAxisEnter.append("rect").classed("genome-axis-window", true); .classed("generic-axis", true);
globalAxisEnter.append("g")
.attr("transform", "translate(0,25)")
.classed("brush-selection", true);
globalAxis.exit().remove(); globalAxis.exit().remove();
const globalAxisUpdate = globalAxis.merge(globalAxisEnter); const globalAxisUpdate = globalAxis.merge(globalAxisEnter);
globalAxisUpdate
.select("rect") globalAxisUpdate.select<any>("g.brush-selection")
.attr("transform", function(d: GlobalAxisData) { .call(brush)
const x = xScale(d.window[0]) .call(brush.move, [xScale(_data.window[0]), xScale(_data.window[1])]);
return "translate(" + x + ", 25)";
})
.attr("width", function(d) {
return xScale(d.window[1] - d.window[0]);
})
.attr("height", 50);
globalAxisUpdate globalAxisUpdate
.select<SVGElement>("g.generic-axis") .select<SVGElement>("g.generic-axis")
.datum((d: GlobalAxisData): GenericAxisData => ({ title: d.title, interval: [d.interval[0], d.interval[1]] })) .datum((d: BrushableAxisData): GenericAxisData => ({ title: d.title, interval: [d.interval[0], d.interval[1]] }))
.call(GenomeAxisComponent, width, yPosition); .call(genomeAxisComponent, width, yPosition);
}); });
} }
return globalGenomeAxis; return globalGenomeAxis;
} }
\ No newline at end of file
Supports Markdown
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