Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove tick labels that are outside the selected date interval #1960

Open
wants to merge 4 commits into
base: xdmod11.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion classes/DataWarehouse/Visualization/TimeseriesChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,6 @@ public function configure(
$value_count = count($xValues);

if (($this->_aggregationUnit == 'Day' || $this->_aggregationUnit == 'day')) {
$this->_chart['layout']['xaxis']['type'] = 'category';
$this->_chart['layout']['xaxis']['tickmode'] = 'auto';
}

Expand Down
3 changes: 2 additions & 1 deletion html/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"DashboardStore": false,
"grecaptcha": false,
"StringUtilities": false,
"Plotly": false
"Plotly": false,
"removeExtraTimeseriesTickLabels": false
}
}
2 changes: 2 additions & 0 deletions html/gui/js/PlotlyChartWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ XDMoD.utils.createChart = function (chartOptions, extraHandlers) {

if (baseChartOptions.layout.annotations.length === 0
|| (baseChartOptions.summary || baseChartOptions.dashboard || baseChartOptions.realmOverview)) {
removeExtraTimeseriesTickLabels(chartDiv, baseChartOptions);
return;
}

const update = relayoutChart(chartDiv, baseChartOptions.layout.height, true);
Plotly.relayout(baseChartOptions.renderTo, update);
removeExtraTimeseriesTickLabels(chartDiv, baseChartOptions);
});

return chart;
Expand Down
1 change: 1 addition & 0 deletions html/gui/js/PlotlyPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ Ext.extend(CCR.xdmod.ui.PlotlyPanel, Ext.Panel, {
return false;
}
});
removeExtraTimeseriesTickLabels(chartDiv, this.chartOptions);
});
// Subtitle context menu
chartDiv.on('plotly_clickannotation', (evt) => {
Expand Down
26 changes: 26 additions & 0 deletions html/gui/js/libraries/PlotlyUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,29 @@ function overrideLegendEvent(chartDiv) {

chartDiv.on('plotly_legenddoubleclick', (evt) => false);
}
/**
* Removes tick labels outside the selected time interval
* from the domain axis of the timeseries plot.
*
* @param {Object} chartDiv - Plotly JS chart div
* @param {Object} baseChartOptions - Object contain Plotly JS layout and data
*/
function removeExtraTimeseriesTickLabels(chartDiv, baseChartOptions) { // eslint-disable-line
const axis = baseChartOptions.layout.swapXY ? 'yaxis' : 'xaxis';
const isEmpty = (!baseChartOptions.data) || (baseChartOptions.data && baseChartOptions.data.length === 0);
if (!isEmpty && baseChartOptions.layout[axis].timeseries) {
const xAxisTicks = chartDiv.getElementsByClassName(`${axis}layer-below`)[0];
const len = baseChartOptions.layout.swapXY ? baseChartOptions.data[0].y.length - 1 : baseChartOptions.data[0].x.length - 1;
const min = baseChartOptions.layout.swapXY ? baseChartOptions.data[0].y[0] : baseChartOptions.data[0].x[0];
const max = baseChartOptions.layout.swapXY ? baseChartOptions.data[0].y[len] : baseChartOptions.data[0].x[len];
const minString = moment(min).format('YYYY-MM-DD');
const maxString = moment(max).format('YYYY-MM-DD');
for (let i = 0; i < xAxisTicks.children.length; i++) {
const currTick = xAxisTicks.children[i];
const currDate = moment(currTick.__data__.text);
if (currDate.isBefore(minString) || currDate.isAfter(maxString)) {
currTick.remove();
}
}
}
}
5 changes: 5 additions & 0 deletions html/gui/js/modules/Usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2592,6 +2592,7 @@ Ext.extend(XDMoD.Module.Usage, XDMoD.PortalModule, {
Plotly.relayout(this.chartId, { width: adjWidth, height: adjHeight });
const update = relayoutChart(chartDiv, adjHeight, false);
Plotly.relayout(this.chartId, update);
removeExtraTimeseriesTickLabels(chartDiv, this.chartOptions);
}
}
} //onResize
Expand Down Expand Up @@ -2726,6 +2727,10 @@ Ext.extend(XDMoD.Module.Usage, XDMoD.PortalModule, {
this.chartOptions = chartOptions;
var chartDiv = document.getElementById(baseChartOptions.renderTo);

chartDiv.on('plotly_relayout', (evt) => {
removeExtraTimeseriesTickLabels(chartDiv, this.chartOptions);
});

chartDiv.on('plotly_click', (evt) => {
let drillId;
let label;
Expand Down
1 change: 1 addition & 0 deletions html/gui/js/modules/metric_explorer/MetricExplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6337,6 +6337,7 @@ Ext.extend(XDMoD.Module.MetricExplorer, XDMoD.PortalModule, {
Plotly.relayout(`plotly-panel${this.id}`, { width: adjWidth, height: adjHeight });
const update = relayoutChart(chartDiv, adjHeight, false);
Plotly.relayout(`plotly-panel${this.id}`, update);
removeExtraTimeseriesTickLabels(chartDiv, CCR.xdmod.ui.metricExplorer.plotlyPanel.chartOptions);
}
} //onResize

Expand Down
2 changes: 1 addition & 1 deletion html/plotly_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
}
const update = relayoutChart(chartDiv, chartOptions.layout.height, true, true);
Plotly.relayout('container', update);

removeExtraTimeseriesTickLabels(chartDiv, chartOptions);
});
});

Expand Down