Remove zoom plugin (#1104)

This commit is contained in:
Paulus Schoutsen 2018-04-27 14:09:25 -04:00 committed by GitHub
parent 811d99b68c
commit 4c6d9602ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 5 additions and 98 deletions

View File

@ -58,9 +58,7 @@
"webcomponentsjs": "^1.0.10", "webcomponentsjs": "^1.0.10",
"chart.js": "~2.7.2", "chart.js": "~2.7.2",
"moment": "^2.20.0", "moment": "^2.20.0",
"chartjs-chart-timeline": "fanthos/chartjs-chart-timeline#^0.1.5", "chartjs-chart-timeline": "fanthos/chartjs-chart-timeline#^0.1.5"
"chartjs-plugin-zoom": "^0.6.3",
"hammerjs": "^2.0.8"
}, },
"devDependencies": { "devDependencies": {
"web-component-tester": "^6.3.0" "web-component-tester": "^6.3.0"

View File

@ -84,8 +84,7 @@
history-data="[[stateHistory]]" history-data="[[stateHistory]]"
is-loading-data="[[isLoadingData]]" is-loading-data="[[isLoadingData]]"
end-time="[[endTime]]" end-time="[[endTime]]"
no-single no-single>
is-zoomable>
</state-history-charts> </state-history-charts>
</div> </div>
</app-header-layout> </app-header-layout>

View File

@ -48,8 +48,7 @@
history-data="[[stateHistory]]" history-data="[[stateHistory]]"
is-loading-data="[[stateHistoryLoading]]" is-loading-data="[[stateHistoryLoading]]"
up-to-now up-to-now
no-single no-single>
is-zoomable="[[inDialog]]">
</state-history-charts> </state-history-charts>
</div> </div>
</paper-card> </paper-card>

View File

@ -102,14 +102,6 @@
</template> </template>
</ul> </ul>
</div> </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> </div>
</template> </template>
<div id="chartTarget" style="height:40px; width:100%"> <div id="chartTarget" style="height:40px; width:100%">
@ -130,7 +122,7 @@
</dom-module> </dom-module>
<script> <script>
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
/* global Chart moment Color Hammer */ /* global Chart moment Color */
{ {
let SCRIPT_LOADED = false; let SCRIPT_LOADED = false;
@ -145,7 +137,6 @@
return { return {
data: Object, data: Object,
identifier: String, identifier: String,
isZoomable: Boolean,
rendered: { rendered: {
type: Boolean, type: Boolean,
notify: true, notify: true,
@ -170,10 +161,6 @@
}; };
} }
static get observers() {
return ['onPropsChange(data, isZoomable)'];
}
connectedCallback() { connectedCallback() {
super.connectedCallback(); super.connectedCallback();
this._isAttached = true; this._isAttached = true;
@ -349,7 +336,6 @@
this._drawLegend(); this._drawLegend();
} }
this.resizeChart(); this.resizeChart();
this.updateZoomlimits();
} else { } else {
if (!data.datasets) { if (!data.datasets) {
return; return;
@ -387,27 +373,6 @@
}; };
options = Chart.helpers.merge(options, this.data.options); options = Chart.helpers.merge(options, this.data.options);
options.scales.xAxes[0].ticks.callback = this._formatTickValue; 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') { if (this.data.type === 'timeline') {
this.set('isTimeline', true); this.set('isTimeline', true);
if (this.data.colors !== undefined) { if (this.data.colors !== undefined) {
@ -441,48 +406,9 @@
this._drawLegend(); this._drawLegend();
} }
this.resizeChart(); 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() { resizeChart() {
if (!this._chart) return; if (!this._chart) return;
// Chart not ready // 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 // Get HSL distributed color list
static getColorList(count) { static getColorList(count) {
let processL = false; let processL = false;

View File

@ -15,7 +15,6 @@
<ha-chart-base <ha-chart-base
id='chart' id='chart'
data="[[chartData]]" data="[[chartData]]"
is-zoomable="[[isZoomable]]"
identifier="[[identifier]]" identifier="[[identifier]]"
rendered="{{rendered}}" rendered="{{rendered}}"
></ha-chart-base> ></ha-chart-base>
@ -30,7 +29,6 @@ class StateHistoryChartLine extends Polymer.Element {
data: Object, data: Object,
unit: String, unit: String,
identifier: String, identifier: String,
isZoomable: Boolean,
isSingleDevice: { isSingleDevice: {
type: Boolean, type: Boolean,

View File

@ -40,7 +40,6 @@
data='[[item.data]]' data='[[item.data]]'
identifier='[[item.identifier]]' identifier='[[item.identifier]]'
is-single-device='[[_computeIsSingleLineChart(item.data, noSingle)]]' is-single-device='[[_computeIsSingleLineChart(item.data, noSingle)]]'
is-zoomable='[[isZoomable]]'
end-time='[[_computeEndTime(endTime, upToNow, historyData)]]'> end-time='[[_computeEndTime(endTime, upToNow, historyData)]]'>
</state-history-chart-line> </state-history-chart-line>
</template> </template>
@ -66,7 +65,6 @@ class StateHistoryCharts extends Polymer.Element {
upToNow: Boolean, upToNow: Boolean,
noSingle: Boolean, noSingle: Boolean,
isZoomable: Boolean,
}; };
} }

View File

@ -77,7 +77,6 @@
is-loading-data="[[_stateHistoryLoading]]" is-loading-data="[[_stateHistoryLoading]]"
up-to-now up-to-now
no-single=[[large]] no-single=[[large]]
is-zoomable=[[large]]
></state-history-charts> ></state-history-charts>
</template> </template>
<more-info-content <more-info-content

View File

@ -1,12 +1,10 @@
<script src="../../bower_components/moment/moment.js"></script> <script src="../../bower_components/moment/moment.js"></script>
<script src="../../bower_components/chart.js/dist/Chart.min.js"></script> <script src="../../bower_components/chart.js/dist/Chart.min.js"></script>
<script src="../../bower_components/chartjs-chart-timeline/timeline.js"></script> <script src="../../bower_components/chartjs-chart-timeline/timeline.js"></script>
<script src="../../bower_components/hammerjs/hammer.min.js"></script>
<script src="../../bower_components/chartjs-plugin-zoom/chartjs-plugin-zoom.min.js"></script>
<script> <script>
// Use minified(Chart.min.js) version to fix strange color after uglify // Use minified(Chart.min.js) version to fix strange color after uglify
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
/* global Chart moment Color Hammer */ /* global Chart moment Color */
// This function add a new interaction mode to Chart.js that // This function add a new interaction mode to Chart.js that
// returns one point for every dataset. // returns one point for every dataset.