Skip to content

Commit

Permalink
add files (#146)
Browse files Browse the repository at this point in the history
Signed-off-by: Shan He <heshan0131@gmail.com>
  • Loading branch information
heshan0131 committed Aug 2, 2021
1 parent 94ad4aa commit 9bf89a8
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 14 deletions.
45 changes: 31 additions & 14 deletions modules/core/src/keyframes/kepler-filter-keyframes.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,18 @@ import {hold, linear} from './easings';
* Current time is a point. An array of sorted time steps need to be provided.
* animation controller calls next animation at a interval when the point jumps to the next step
*/
function timeRangeKeyframes({filter, timings}) {
function getKeyFramesFree(filter) {
const delta = filter.value[1] - filter.value[0];
return {
keyframes: [
{value: [filter.domain[0], filter.domain[0] + delta]},
{value: [filter.domain[1] - delta, filter.domain[1]]}
],
easings: linear
};
}

export function timeRangeKeyframes({filter, timings}) {
if (filter.type !== 'timeRange') {
throw new Error("filter type must be 'timeRange'.'");
}
Expand All @@ -53,14 +64,7 @@ function timeRangeKeyframes({filter, timings}) {
switch (filter.animationWindow) {
default:
case 'free': {
const delta = filter.value[1] - filter.value[0];
return {
keyframes: [
{value: [filter.domain[0], filter.domain[0] + delta]},
{value: [filter.domain[1] - delta, filter.domain[1]]}
],
easings: linear
};
return getKeyFramesFree(filter);
}
case 'incremental': {
return {
Expand All @@ -78,13 +82,26 @@ function timeRangeKeyframes({filter, timings}) {
};
}
case 'interval': {
const delta = Math.round(duration / filter.steps.length);
const {bins, plotType} = filter;
const {interval} = plotType;
if (
!interval ||
!bins ||
Object.keys(bins).length === 0 ||
!Object.values(bins)[0][interval]
) {
// shouldn't happen return
return getKeyFramesFree(filter);
}
const intervalBins = Object.values(bins)[0][interval];
const delta = Math.round(duration / intervalBins.length);

// const delta = Math.round(duration / filter.steps.length);
return {
timings: filter.steps.map((_, idx) => timings[0] + delta * idx),
keyframes: filter.steps.map((step, idx) => {
const nextIdx = idx >= filter.steps.length - 1 ? 0 : idx + 1;
timings: intervalBins.map((_, idx) => timings[0] + delta * idx),
keyframes: intervalBins.map(bin => {
return {
value: [step, nextIdx]
value: [bin.x0, bin.x1]
};
}),
easings: hold
Expand Down
1 change: 1 addition & 0 deletions modules/core/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import './keyframes/camera-keyframes.spec';
import './keyframes/kepler-filter-keyframes.spec';
import './keyframes/utils.spec';
83 changes: 83 additions & 0 deletions modules/core/test/keyframes/kepler-filter-keyframes.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) 2021 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import test from 'tape-catch';

import {
timeRangeKeyframes
// @ts-ignore
// eslint-disable-next-line import/no-unresolved
} from '@hubble.gl/core/keyframes/kepler-filter-keyframes';

const intervalFilter = {
type: 'timeRange',
id: 'test-test',
animationWindow: 'interval',
value: [1421315219000, 1421315400000],
domain: [1421315219000, 1421348744000],
plotType: {
type: 'histogram',
interval: '5-minute'
},
bins: {
a543fcbd: {
'5-minute': [
{
x0: 1421315100000,
x1: 1421315400000
},
{
x0: 1421315400000,
x1: 1421315700000
},
{
x0: 1421315700000,
x1: 1421316000000
}
]
}
}
};
const TEST_CASES = [
{
args: {
filter: intervalFilter,
timings: [0, 1000]
},
expected: {
keyframes: [
{value: [1421315100000, 1421315400000]},
{value: [1421315400000, 1421315700000]},
{value: [1421315700000, 1421316000000]}
],
timings: [0, 333, 666]
},
message: 'keyframes for interval filter should be correct'
}
];

test('CameraKeyframes#flyToInterpolator', t => {
TEST_CASES.forEach(testCase => {
const result = timeRangeKeyframes(testCase.args);
t.deepEqual(result.keyframes, testCase.expected.keyframes, testCase.message);
t.deepEqual(result.timings, testCase.expected.timings, testCase.message);
});

t.end();
});

0 comments on commit 9bf89a8

Please sign in to comment.