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

#17 animations #21

Merged
merged 2 commits into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion components/Defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export const FONTOFFSET = 22
export const AXISCOLOR = '#888888'
export const AXISSIZE = 2
export const AXISGAP = 0
export const MAXNUMAXIS = 5
export const MAXNUMAXIS = 6

export const OPACITYNOTSELECTED = 0.3

export const SVGMARGIN = 20

Expand All @@ -18,4 +20,5 @@ export const FEATUREWIDTH = 2
export const FEATURESIZE = 18
export const FEATURESTROKE = 0
export const FEATUREFILLCOLOR = '#E74C3C'
export const FEATUREFILLCOLORS = ['#18247e', '#2870b8', '#4ebcd7', '#bbe4c6']
export const FEATURESTROKECOLOR = '#2C3E50'
8 changes: 6 additions & 2 deletions components/RadialVis/FeatureAxis.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { PropTypes } from 'react'
import * as d3 from 'd3'
import { AXISGAP, AXISCOLOR, AXISSIZE,
FONTCOLOR, FONTSIZE, FONTOFFSET } from '../Defaults'
FONTCOLOR, FONTSIZE, FONTOFFSET, FEATUREFILLCOLOR } from '../Defaults'

import Feature from './features/Feature'

Expand Down Expand Up @@ -98,6 +98,7 @@ class FeatureAxis extends React.Component {
.exit()
.remove()

// Early Transition Code
// if (d !== this.props.d) {
// const arc2 = d3.arc()
// .innerRadius(r + 10)
Expand All @@ -119,7 +120,7 @@ class FeatureAxis extends React.Component {
// }

render() {
const { d, axisGap, geneLength, features } = this.props
const { d, axisGap, geneLength, features, fillColor } = this.props
return (
<g>
<g ref={(c) => { this.clickArea = c }} />
Expand All @@ -132,6 +133,7 @@ class FeatureAxis extends React.Component {
stop={x[1]}
axisGap={axisGap}
geneLength={geneLength}
fillColor={fillColor}
/>
))
}
Expand All @@ -147,6 +149,7 @@ FeatureAxis.defaultProps = {
axisSize: AXISSIZE,
fontColor: FONTCOLOR,
fontSize: FONTSIZE,
fillColor: FEATUREFILLCOLOR,
}

FeatureAxis.propTypes = {
Expand All @@ -161,6 +164,7 @@ FeatureAxis.propTypes = {
axisSize: PropTypes.number,
fontColor: PropTypes.string,
fontSize: PropTypes.number,
fillColor: PropTypes.string,
}

export default FeatureAxis
6 changes: 4 additions & 2 deletions components/RadialVis/RadialVis.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
pointer-events: none;
}

.centered {
.svg {
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
position: absolute;
pointer-events: auto;
user-select: none;
cursor: default;
}

.hovered {
Expand All @@ -19,7 +21,7 @@
}

.hovered:hover {
opacity: 0.7 !important;
opacity: 0.6 !important;
transition: 300ms;
transition-timing-function: ease;
}
65 changes: 40 additions & 25 deletions components/RadialVis/RadialVis.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, { PropTypes } from 'react'
import ReactDOM from 'react-dom'
import uID from 'lodash.uniqueid'

import MainAxis from './MainAxis'
import FeatureAxis from './FeatureAxis'
import style from './RadialVis.css'
import ProteinViewer from '../ProteinViewer'

import { SVGMARGIN, MAXNUMAXIS } from '../Defaults'
import { SVGMARGIN, MAXNUMAXIS, FEATUREFILLCOLORS, OPACITYNOTSELECTED } from '../Defaults'
import { selectAxis, deselectAxis } from '../../actions/radialVis'

/**
Expand All @@ -23,42 +24,27 @@ class RadialVis extends React.PureComponent {
if (feature === visState.selected) {
return 1
}
return 0.3
return OPACITYNOTSELECTED
}

constructor(props) {
super(props)
this.calculateRadius = this.calculateRadius.bind(this)
this.handleClick = this.handleClick.bind(this)
this.handleDrag = this.handleDrag.bind(this)
this.handleDragClick = this.handleDragClick.bind(this)

this.handle = [0, 0]
this.oldAngle = 0
this.drag = false
}

componentWillMount() {
// TODO probably useless
this.setState({
mainAxisKey: uID('mainAxis'),
})
}

// componentWillReceiveProps(nextProps) {
// // Calculate new IDs for Features
// if (typeof nextProps.currentSequenceData.uniprot.data !== 'undefined') {
// const currentLength = this.state.featureAxisKeys.length
// const nextLength = nextProps.currentSequenceData.uniprot.data.length
//
// if (nextLength > currentLength) {
// let featureAxisKeys = this.state.featureAxisKeys
//
// for (let i = currentLength - 1; i < nextLength; i++) {
// featureAxisKeys = featureAxisKeys.concat(uID('featureAxis'))
// }
// this.setState(Object.assign({}, this.state,
// {
// featureAxisKeys,
// }))
// }
// }
// }

handleClick(e, feature) {
if (feature === this.props.visState.selected) {
this.props.dispatch(deselectAxis(feature))
Expand All @@ -67,6 +53,28 @@ class RadialVis extends React.PureComponent {
}
}

handleDrag(e) {
if (this.drag) {
const center = Math.floor(this.calculateRadius(MAXNUMAXIS - 1) / 2)
const v1 = [e.nativeEvent.offsetX - center, e.nativeEvent.offsetY - center]
const v2 = [this.handle[0] - center, this.handle[1] - center]

let newAngle = Math.atan2(v1[1], v1[0])
newAngle -= Math.atan2(v2[1], v2[0])
newAngle += this.oldAngle

const degree = (newAngle * (360 / (2 * Math.PI)))
ReactDOM.findDOMNode(this.svg).style.transform = `rotate(${degree}deg)`

this.oldAngle = newAngle
}
}

handleDragClick(e, mouseDown) {
this.handle = [e.nativeEvent.offsetX, e.nativeEvent.offsetY]
this.drag = mouseDown
}

calculateRadius(i) {
const { ui } = this.props
const margin = 50
Expand Down Expand Up @@ -96,11 +104,17 @@ class RadialVis extends React.PureComponent {
}

return (
<div className={style.parent}>
<div
className={style.parent}
ref={(c) => { this.svg = c }}
>
<svg
width={this.calculateRadius(MAXNUMAXIS - 1) + SVGMARGIN}
height={this.calculateRadius(MAXNUMAXIS - 1) + SVGMARGIN}
className={style.centered}
className={style.svg}
onMouseMove={e => this.handleDrag(e)}
onMouseDown={e => this.handleDragClick(e, true)}
onMouseUp={e => this.handleDragClick(e, false)}
>
<g transform={centerOrigin} >
{uniprot.data && keys.length > 0 && keys.slice(0, MAXNUMAXIS - 1).map((feature, i) => {
Expand All @@ -121,6 +135,7 @@ class RadialVis extends React.PureComponent {
geneLength={uniprot.chainLength}
id={feature}
name={uniprot.data[feature].name}
fillColor={FEATUREFILLCOLORS[i % FEATUREFILLCOLORS.length]}
/>
</g>
)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"redux-thunk": "^2.1.0",
"redux-logger": "^2.7.4",
"whatwg-fetch": "^2.0.2",
"lodash.uniqueid": "4.0.1"
"lodash.uniqueid": "^4.0.1"
},
"devDependencies": {
"assets-webpack-plugin": "^3.5.0",
Expand Down
1 change: 1 addition & 0 deletions src/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}

.maxSize {
Expand Down
6 changes: 5 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4450,7 +4450,7 @@ lodash.uniq@^4.3.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"

[email protected]:
lodash.uniqueid@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/lodash.uniqueid/-/lodash.uniqueid-4.0.1.tgz#3268f26a7c88e4f4b1758d679271814e31fa5b26"

Expand Down Expand Up @@ -5734,6 +5734,10 @@ rc@^1.0.1, rc@^1.1.6, rc@~1.1.6:
minimist "^1.2.0"
strip-json-comments "~1.0.4"

react-clickdrag@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/react-clickdrag/-/react-clickdrag-3.0.2.tgz#54df5f3df6d695c54e9978a08253f83de7611bd2"

react-deep-force-update@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/react-deep-force-update/-/react-deep-force-update-2.0.1.tgz#4f7f6c12c3e7de42f345992a3c518236fa1ecad3"
Expand Down