Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add brush function in parallel coordinates #281

Merged
merged 1 commit into from
Sep 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions src/svg/components/ParallelCoordinates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {
line,
drag,
event,
min,
max
brushY
} from 'd3';

class ParallelCoordinates extends Component {
Expand All @@ -25,6 +24,7 @@ class ParallelCoordinates extends Component {
private parallelAxes: any;
private lineGenerator: Line<any>;
private dragEventPositions: any;
private brushedExtent: any;

constructor() {
super();
Expand All @@ -45,7 +45,9 @@ class ParallelCoordinates extends Component {

this.updateDomainOfDimensions();
this.updateYaxesByDimensions(data, height);

this.dragEventPositions = {};
this.brushedExtent = {};

let thisInstance = this; // To use instance method in selection event

Expand Down Expand Up @@ -78,6 +80,20 @@ class ParallelCoordinates extends Component {
.style('cursor', 'move')
.attr('y', -9)
.text((d) => d);

// TODO we will separate brush configuration later

dimensionEntries.append('g')
.attr('class', 'brush')
.each(function(d) {
select(this)
.call(brushY().extent([[-8, 0], [8, height]])
.on('brush', (dimension: any) => thisInstance.brushed(d))
);
})
.selectAll('rect')
.attr('x', -8)
.attr('width', 16);
}

private initializeParallelCoordinates(width: number, height: number) {
Expand Down Expand Up @@ -167,6 +183,23 @@ class ParallelCoordinates extends Component {
.attr('visibility', null);
}

// TODO we will separate brush component later

private brushed(dimension: any) {
this.brushedExtent[dimension] = [this._yScale[dimension].invert(event.selection[1]),
this._yScale[dimension].invert(event.selection[0])];

let activeDimension = this._dimensions.filter((d) => (this.brushedExtent[d] == null) ? false : true),
thisInstance = this;

this.svg.selectAll('.foreground')
.attr('opacity', (d: any) => activeDimension.every((i: string) =>
(thisInstance.brushedExtent[i][0] <= d[i] && thisInstance.brushedExtent[i][1] >= d[i]))
? 1
: 0
);
}

}

export default ParallelCoordinates;