Fix history jump (#792)

This commit is contained in:
Paulus Schoutsen 2018-01-10 09:39:53 -08:00 committed by GitHub
parent f2358acf2d
commit 728d781843
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 12 deletions

View File

@ -1,5 +1,5 @@
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/iron-resizable-behavior/iron-resizable-behavior.html">
<link rel="import" href="../../bower_components/polymer/lib/utils/debounce.html">
<script>
{
@ -19,8 +19,7 @@
return !isNaN(parsed) && isFinite(parsed) ? parsed : null;
}
class StateHistoryChartLine extends
Polymer.mixinBehaviors([Polymer.IronResizableBehavior], Polymer.Element) {
class StateHistoryChartLine extends Polymer.Element {
static get is() { return 'state-history-chart-line'; }
static get properties() {
return {
@ -55,9 +54,25 @@
super.connectedCallback();
this._isAttached = true;
this.drawChart();
this.addEventListener('iron-resize', () => {
setTimeout(() => this.drawChart(), 10);
});
this._resizeListener = () => {
this._debouncer = Polymer.Debouncer.debounce(
this._debouncer,
Polymer.Async.timeOut.after(10),
() => {
if (this._isAttached) {
this.drawChart();
}
}
);
};
window.addEventListener('resize', this._resizeListener);
}
disconnectedCallback() {
super.disconnectedCallback();
this._isAttached = false;
window.removeEventListener('resize', this._resizeListener);
}
dataChanged() {

View File

@ -1,9 +1,8 @@
<link rel="import" href="../../bower_components/polymer/polymer-element.html">
<link rel="import" href="../../bower_components/iron-resizable-behavior/iron-resizable-behavior.html">
<link rel="import" href="../../bower_components/polymer/lib/utils/debounce.html">
<script>
class StateHistoryChartTimeline extends
Polymer.mixinBehaviors([Polymer.IronResizableBehavior], Polymer.Element) {
class StateHistoryChartTimeline extends Polymer.Element {
static get is() { return 'state-history-chart-timeline'; }
static get properties() {
return {
@ -23,9 +22,25 @@ class StateHistoryChartTimeline extends
super.connectedCallback();
this._isAttached = true;
this.drawChart();
this.addEventListener('iron-resize', () => {
setTimeout(() => this.drawChart(), 10);
});
this._resizeListener = () => {
this._debouncer = Polymer.Debouncer.debounce(
this._debouncer,
Polymer.Async.timeOut.after(10),
() => {
if (this._isAttached) {
this.drawChart();
}
}
);
};
window.addEventListener('resize', this._resizeListener);
}
disconnectedCallback() {
super.disconnectedCallback();
this._isAttached = false;
window.removeEventListener('resize', this._resizeListener);
}
dataChanged() {