-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
64 additions
and
51 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
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,60 @@ | ||
import React from 'react'; | ||
import Slider from 'rc-slider'; | ||
import { scaleLog } from 'd3-scale'; | ||
|
||
|
||
const CLICK_STEP = 0.05; | ||
const SLIDER_STEP = 0.001; | ||
|
||
const valueFromZoomScale = (props) => { | ||
const { scale, minScale, maxScale } = props; | ||
const value = scaleLog() | ||
.domain([minScale, maxScale]) | ||
.range([0, 1])(scale); | ||
// const value = Math.log(scale / minScale) / | ||
// Math.log(maxScale / minScale); | ||
// return isNaN(value) ? 0 : value; | ||
return value; | ||
}; | ||
|
||
export default class ZoomControl extends React.Component { | ||
constructor(props, context) { | ||
super(props, context); | ||
|
||
this.state = { value: valueFromZoomScale(props) }; | ||
|
||
this.handleZoomOut = this.handleZoomOut.bind(this); | ||
this.handleZoomIn = this.handleZoomIn.bind(this); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
this.setState({ value: valueFromZoomScale(nextProps)}); | ||
} | ||
|
||
updateValue(value) { | ||
const { minScale, maxScale, slideAction } = this.props; | ||
slideAction(Math.exp(value * Math.log(maxScale / minScale)) * minScale); | ||
} | ||
|
||
handleZoomOut() { | ||
this.updateValue(Math.max(0, this.state.value - CLICK_STEP)); | ||
} | ||
|
||
handleZoomIn() { | ||
this.updateValue(Math.min(1, this.state.value + CLICK_STEP)); | ||
} | ||
|
||
render() { | ||
const { value } = this.state; | ||
|
||
return ( | ||
<div className="zoom-control-wrapper"> | ||
<span className="zoom-control"> | ||
<a className="zoom-in" onClick={this.handleZoomIn}><span className="fa fa-plus" /></a> | ||
<Slider value={value} max={1} step={SLIDER_STEP} vertical onChange={this.updateValue} /> | ||
<a className="zoom-out" onClick={this.handleZoomOut}><span className="fa fa-minus" /></a> | ||
</span> | ||
</div> | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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