mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-09 10:59:50 +00:00
Remove zoom plugin (#1104)
This commit is contained in:
@@ -102,14 +102,6 @@
|
||||
</template>
|
||||
</ul>
|
||||
</div>
|
||||
<template is="dom-if" if="[[isZoomable]]">
|
||||
<div class="chartZoomInline">
|
||||
<paper-icon-button
|
||||
icon='mdi:image-filter-center-focus'
|
||||
on-click='resetZoom'
|
||||
></paper-icon-button>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
<div id="chartTarget" style="height:40px; width:100%">
|
||||
@@ -130,7 +122,7 @@
|
||||
</dom-module>
|
||||
<script>
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
/* global Chart moment Color Hammer */
|
||||
/* global Chart moment Color */
|
||||
{
|
||||
let SCRIPT_LOADED = false;
|
||||
|
||||
@@ -145,7 +137,6 @@
|
||||
return {
|
||||
data: Object,
|
||||
identifier: String,
|
||||
isZoomable: Boolean,
|
||||
rendered: {
|
||||
type: Boolean,
|
||||
notify: true,
|
||||
@@ -170,10 +161,6 @@
|
||||
};
|
||||
}
|
||||
|
||||
static get observers() {
|
||||
return ['onPropsChange(data, isZoomable)'];
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this._isAttached = true;
|
||||
@@ -349,7 +336,6 @@
|
||||
this._drawLegend();
|
||||
}
|
||||
this.resizeChart();
|
||||
this.updateZoomlimits();
|
||||
} else {
|
||||
if (!data.datasets) {
|
||||
return;
|
||||
@@ -387,27 +373,6 @@
|
||||
};
|
||||
options = Chart.helpers.merge(options, this.data.options);
|
||||
options.scales.xAxes[0].ticks.callback = this._formatTickValue;
|
||||
if (this.data.type === 'timeline') {
|
||||
// timeline is not zoomable, so dont capture mouse
|
||||
options = Chart.helpers.merge(options, {
|
||||
pan: { enabled: false },
|
||||
zoom: { enabled: false },
|
||||
});
|
||||
} else {
|
||||
// allow free zooming&moving around
|
||||
options = Chart.helpers.merge(options, {
|
||||
pan: {
|
||||
enabled: true,
|
||||
drag: true,
|
||||
mode: 'xy',
|
||||
},
|
||||
zoom: {
|
||||
enabled: true,
|
||||
drag: false,
|
||||
mode: 'xy',
|
||||
}
|
||||
});
|
||||
}
|
||||
if (this.data.type === 'timeline') {
|
||||
this.set('isTimeline', true);
|
||||
if (this.data.colors !== undefined) {
|
||||
@@ -441,48 +406,9 @@
|
||||
this._drawLegend();
|
||||
}
|
||||
this.resizeChart();
|
||||
this.updateZoomlimits();
|
||||
}
|
||||
}
|
||||
|
||||
updateZoomlimits() {
|
||||
if (!this._chart) return;
|
||||
if (this.isTimeline) return;
|
||||
|
||||
const buffer = {
|
||||
x: { min: null, max: null },
|
||||
y: { min: null, max: null }
|
||||
};
|
||||
Object.keys(this._chart.scales).forEach((name) => {
|
||||
var scale = this._chart.scales[name];
|
||||
var axis = name.substr(0, 1);
|
||||
if (!(axis in buffer)) return;
|
||||
|
||||
if (buffer[axis].max === null || buffer[axis].max < scale.max) {
|
||||
// ===null to accept negative-max
|
||||
buffer[axis].max = scale.max;
|
||||
}
|
||||
if (buffer[axis].min === null || buffer[axis].min > scale.min) {
|
||||
// ===null to allow to go "up" on the first value
|
||||
buffer[axis].min = scale.min;
|
||||
}
|
||||
});
|
||||
|
||||
this._chart.options = Chart.helpers.merge(this._chart.options, {
|
||||
pan: {
|
||||
enabled: !!this.isZoomable,
|
||||
rangeMin: { x: buffer.x.min, y: buffer.y.min },
|
||||
rangeMax: { x: buffer.x.max, y: buffer.y.max }
|
||||
},
|
||||
zoom: {
|
||||
enabled: !!this.isZoomable,
|
||||
// x is nulled so users are able to "zoom in on time"
|
||||
rangeMin: { x: null /* buffer.x.min */, y: buffer.y.min },
|
||||
rangeMax: { x: null /* buffer.x.max */, y: buffer.y.max }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
resizeChart() {
|
||||
if (!this._chart) return;
|
||||
// Chart not ready
|
||||
@@ -539,14 +465,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
// for chartjs-plugin-zoom
|
||||
resetZoom(event = null) {
|
||||
if (event) {
|
||||
event.stopPropagation();
|
||||
}
|
||||
this._chart.resetZoom();
|
||||
}
|
||||
|
||||
// Get HSL distributed color list
|
||||
static getColorList(count) {
|
||||
let processL = false;
|
||||
|
||||
Reference in New Issue
Block a user