Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
feat(chart): Add animation for chart heatfield.
Browse files Browse the repository at this point in the history
Part of #476
Create reusable fade animation
Fade in heatfield overlay
Animate scale of heatfield marker and heatfield backdrop
  • Loading branch information
peter-affenzeller authored and ffriedl89 committed Mar 31, 2020
1 parent ae5f304 commit 00deddd
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 30 deletions.
2 changes: 1 addition & 1 deletion apps/dev/src/chart/chart-demo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<a class="dt-link">View problem details</a>
</dt-chart-heatfield>
<dt-chart-heatfield
[start]="1564546530000"
[start]="1564546730000"
[end]="1564546960000"
color="main"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @license
* Copyright 2020 Dynatrace LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { ConnectedPosition } from '@angular/cdk/overlay';

/** Distance between heatfield backdrop and heatfield marker */
export const DT_HEATFIELD_TOP_OFFSET = 16;

/** Possible heatfield overlay positions */
export const DT_HEATFIELD_OVERLAY_POSITIONS: ConnectedPosition[] = [
{
originX: 'center',
originY: 'top',
overlayX: 'center',
overlayY: 'bottom',
offsetY: -8,
},
{
originX: 'end',
originY: 'top',
overlayX: 'start',
overlayY: 'top',
offsetX: 8,
},
{
originX: 'start',
originY: 'top',
overlayX: 'end',
overlayY: 'top',
offsetX: -8,
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
[cdkConnectedOverlayOpen]="_isValidStartEndRange && active"
[cdkConnectedOverlayPositions]="_positions"
>
<div class="dt-chart-heatfield-overlay">
<div [@fade]="_overlayAnimationState" class="dt-chart-heatfield-overlay">
<ng-content></ng-content>
</div>
</ng-template>

<div
class="dt-chart-heatfield-backdrop"
#backdrop
[style.visibility]="_isValidStartEndRange && active ? 'visible' : 'hidden'"
[style.height.px]="_boundingBox && _boundingBox.height"
></div>
16 changes: 15 additions & 1 deletion libs/barista-components/chart/src/heatfield/chart-heatfield.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
@import '../../../core/src/style/overlay';
@import './chart-heatfield-theme';

$animation-duration: 150ms;
$animation-delay: 40ms;

.dt-chart-heatfield-marker {
height: 8px;
outline: 2px solid #ffffff;
Expand All @@ -13,14 +16,25 @@
width: 100%;
display: block;
z-index: 1;
transform-origin: top;
transition: transform $animation-duration ease-in-out $animation-delay;
}

.dt-chart-heatfield-marker.dt-chart-heatfield-active {
height: 12px;
transform: scaleY(1.5);
transition: transform 50ms ease-in-out;
}

.dt-chart-heatfield-backdrop {
position: absolute;
transform-origin: top;
transform: scaleY(0);
transition: transform $animation-duration ease-out;
}

.dt-chart-heatfield-active + .dt-chart-heatfield-backdrop {
transform: scaleY(1);
transition: transform $animation-duration ease-out $animation-delay;
}

.dt-chart-heatfield-overlay {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
TestBed,
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import {
DtChart,
DtChartHeatfield,
Expand All @@ -57,7 +58,7 @@ describe('DtChartHeatfield', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [DtChartModule, DtThemingModule],
imports: [NoopAnimationsModule, DtChartModule, DtThemingModule],
declarations: [SingleHeatfield, MultipleHeatfield, DummyChart],
});

Expand Down
37 changes: 12 additions & 25 deletions libs/barista-components/chart/src/heatfield/chart-heatfield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
import {
CanColor,
Constructor,
dtFadeAnimation,
isDefined,
mixinColor,
_readKeyCode,
Expand All @@ -40,31 +41,10 @@ import { clamp, round } from 'lodash';
import { Subject } from 'rxjs';
import { PlotBackgroundInfo } from '../utils';

const DT_HEATFIELD_TOP_OFFSET = 16;

const DT_HEATFIELD_OVERLAY_POSITIONS: ConnectedPosition[] = [
{
originX: 'center',
originY: 'top',
overlayX: 'center',
overlayY: 'bottom',
offsetY: -8,
},
{
originX: 'end',
originY: 'top',
overlayX: 'start',
overlayY: 'top',
offsetX: 8,
},
{
originX: 'start',
originY: 'top',
overlayX: 'end',
overlayY: 'top',
offsetX: -8,
},
];
import {
DT_HEATFIELD_TOP_OFFSET,
DT_HEATFIELD_OVERLAY_POSITIONS,
} from './chart-heatfield-config';

/** Event object emitted by DtOption when selected or deselected. */
export class DtChartHeatfieldActiveChange {
Expand Down Expand Up @@ -94,6 +74,7 @@ export const _DtHeatfieldMixinBase = mixinColor<
preserveWhitespaces: false,
encapsulation: ViewEncapsulation.Emulated,
inputs: ['color'],
animations: [dtFadeAnimation],
})
export class DtChartHeatfield extends _DtHeatfieldMixinBase
implements CanColor<DtChartHeatfieldThemePalette>, OnDestroy {
Expand All @@ -102,6 +83,9 @@ export class DtChartHeatfield extends _DtHeatfieldMixinBase
DtChartHeatfieldActiveChange
>();

/** @internal The current state of the animation. */
_overlayAnimationState: 'void' | 'fadeIn' = 'void';

private _start: number;

/** Start on the xAxis of the chart for the heatfield */
Expand Down Expand Up @@ -141,6 +125,7 @@ export class DtChartHeatfield extends _DtHeatfieldMixinBase
const coercedValue = coerceBooleanProperty(val);
if (this._active !== coercedValue) {
this._active = coercedValue;
this._overlayAnimationState = coercedValue ? 'fadeIn' : 'void';
this.activeChange.next(new DtChartHeatfieldActiveChange(this));
this._changeDetectorRef.markForCheck();
}
Expand Down Expand Up @@ -233,6 +218,8 @@ export class DtChartHeatfield extends _DtHeatfieldMixinBase
* @internal
*/
_toggleActive(): void {
this._overlayAnimationState =
this._overlayAnimationState === 'fadeIn' ? 'void' : 'fadeIn';
this.active = !this.active;
}

Expand Down
48 changes: 48 additions & 0 deletions libs/barista-components/core/src/animations/fade-animation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @license
* Copyright 2020 Dynatrace LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {
animate,
AnimationTriggerMetadata,
state,
style,
transition,
trigger,
} from '@angular/animations';

/**
* Reusable fade animation with default parameters that can be overridden
* by the animation trigger property binding
* Default animation:
* _triggerProperty: 'void' | 'state-name' = 'void'
* Override params:
* _triggerProperty = { value: 'void', params: { duration: '300ms', easing: 'ease-out' }}
*/
export const dtFadeAnimation: AnimationTriggerMetadata = trigger('fade', [
state('void', style({ opacity: 0 })),
transition(':enter', [animate('{{ duration }} {{ easing }}')], {
params: {
duration: '150ms',
easing: 'ease-in-out',
},
}),
transition(':leave', [animate('{{ duration }} {{ easing }}')], {
params: {
duration: '150ms',
easing: 'ease-in-out',
},
}),
]);
1 change: 1 addition & 0 deletions libs/barista-components/core/src/animations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
*/

export * from './error-animations';
export * from './fade-animation';

0 comments on commit 00deddd

Please sign in to comment.