Skip to content

Commit

Permalink
LLCAXCHZF-57/changes by review
Browse files Browse the repository at this point in the history
  • Loading branch information
TomeCirun committed Jul 29, 2024
1 parent 4b22ee3 commit ca80e63
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
27 changes: 8 additions & 19 deletions ckanext/charts/assets/js/charts-render-chartjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,24 @@ ckan.module("charts-render-chartjs", function ($, _) {

const unsupportedTypes = ['pie', 'doughnut', 'radar'];
const isZoomSupported = !unsupportedTypes.includes(this.options.config.type);
let zoomOptions = null;

if (isZoomSupported) {
zoomOptions = this.options.config.options.plugins.zoom;
const zoomOptions = this.options.config.options.plugins.zoom;

this.options.config.options.plugins.title.text = () => {
return 'Zoom: ' + this.zoomStatus(zoomOptions) + ', Pan: ' + this.panStatus(zoomOptions);
};

$('#resetZoom').show();
$('#toggleZoom').show();
$('#togglePan').show();
} else {
$('#resetZoom').hide();
$('#toggleZoom').hide();
$('#togglePan').hide();
$('#resetZoom').on('click', this.resetZoom);
$('#toggleZoom').on('click', (e) => this.toggleZoom(e, zoomOptions));
$('#togglePan').on('click', (e) => this.togglePan(e, zoomOptions));
}

var chart = new Chart(this.el[0].getContext("2d"), this.options.config);
window.charts_chartjs = chart;
$(".zoom-control").toggle(isZoomSupported);

$('#resetZoom').on('click', this.resetZoom);
$('#toggleZoom').on('click', (e) => this.toggleZoom(e, zoomOptions));
$('#togglePan').on('click', (e) => this.togglePan(e, zoomOptions));
window.charts_chartjs = new Chart(this.el[0].getContext("2d"), this.options.config);
},

resetZoom: function(event) {
event.preventDefault();
window.charts_chartjs.resetZoom();
Expand All @@ -67,17 +60,13 @@ ckan.module("charts-render-chartjs", function ($, _) {
zoomOptions.zoom.pinch.enabled = !zoomEnabled;
zoomOptions.zoom.drag.enabled = !zoomEnabled;

// Update the chart with the new zoom options
window.charts_chartjs.update();
},

togglePan: function(event, zoomOptions) {
event.preventDefault();

const currentPanEnabled = zoomOptions.pan.enabled;
zoomOptions.pan.enabled = !currentPanEnabled;

// Update the chart with the new zoom options
zoomOptions.pan.enabled = !zoomOptions.pan.enabled;
window.charts_chartjs.update();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% if chart %}
<canvas id="chart-container" data-module="charts-render-chartjs" data-module-config="{{ chart }}"></canvas>
<div>
<div class="zoom-control">
<button class="btn btn-primary" id="resetZoom">Reset Zoom</button>
<button class="btn btn-primary" id="toggleZoom" class="btn btn-primary">Toggle Zoom</button>
<button class="btn btn-primary" id="togglePan" class="btn btn-primary">Toggle Pan</button>
Expand Down

0 comments on commit ca80e63

Please sign in to comment.