Skip to content
This repository has been archived by the owner on Nov 19, 2019. It is now read-only.

Add zoomFriction option #106

Merged
merged 2 commits into from
Jan 26, 2019
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
10 changes: 10 additions & 0 deletions docs/src/OptionsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,16 @@ class OptionsPage extends React.Component {
</td>
</tr>

<tr>
<td>zoomFriction</td>
<td>number</td>
<td><code>5</code></td>
<td>
Specifies how strong the zooming is for each scroll tick. Higher zooming friction will slow
zooming speed.
</td>
</tr>

<tr>
<td>zoomKey</td>
<td>String</td>
Expand Down
2 changes: 1 addition & 1 deletion examples/basicUsage.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
</style>

<script src="../dist/timeline.js"></script>
<script src="../dist/timeline.min.js"></script>
<link href="../dist/timeline.min.css" rel="stylesheet" type="text/css" />

</head>
Expand Down
2 changes: 1 addition & 1 deletion lib/timeline/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class Core {
const fields = [
'width', 'height', 'minHeight', 'maxHeight', 'autoResize',
'start', 'end', 'clickToUse', 'dataAttributes', 'hiddenDates',
'locale', 'locales', 'moment', 'rtl', 'zoomKey', 'horizontalScroll', 'verticalScroll'
'locale', 'locales', 'moment', 'rtl', 'zoomKey', 'zoomFriction', 'horizontalScroll', 'verticalScroll'
];
util.selectiveExtend(fields, this.options, options);

Expand Down
8 changes: 5 additions & 3 deletions lib/timeline/Range.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default class Range extends Component {
// copy the options that we know
const fields = [
'animation', 'direction', 'min', 'max', 'zoomMin', 'zoomMax', 'moveable', 'zoomable',
'moment', 'activate', 'hiddenDates', 'zoomKey', 'rtl', 'showCurrentTime', 'rollingMode', 'horizontalScroll'
'moment', 'activate', 'hiddenDates', 'zoomKey', 'zoomFriction', 'rtl', 'showCurrentTime', 'rollingMode', 'horizontalScroll'
];
util.selectiveExtend(fields, this.options, options);

Expand Down Expand Up @@ -635,12 +635,14 @@ export default class Range extends Component {

// adjust a negative delta such that zooming in with delta 0.1
// equals zooming out with a delta -0.1

const zoomFriction = this.options.zoomFriction || 5;
let scale;
if (delta < 0) {
scale = 1 - (delta / 5);
scale = 1 - (delta / zoomFriction);
}
else {
scale = 1 / (1 + (delta / 5)) ;
scale = 1 / (1 + (delta / zoomFriction)) ;
}

// calculate center, the date to zoom around
Expand Down
1 change: 1 addition & 0 deletions lib/timeline/optionsTimeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ let allOptions = {
width: {string, number},
zoomable: { 'boolean': bool},
zoomKey: {string: ['ctrlKey', 'altKey', 'metaKey', '']},
zoomFriction: {number},
zoomMax: {number},
zoomMin: {number},

Expand Down