Skip to content

Commit

Permalink
Fixes in Highcharts time series charts
Browse files Browse the repository at this point in the history
  • Loading branch information
RamezIssac committed Jun 15, 2024
1 parent d782627 commit 3681c9d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 9 deletions.
41 changes: 41 additions & 0 deletions demo_proj/demo_app/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,47 @@ class ChartJSExample(TimeSeriesReport):
class HighChartExample(ChartJSExample):
chart_engine = "highcharts"

chart_settings = [
Chart("Client Sales Column", Chart.COLUMN, data_source=["sum__value"], title_source=["name"]),
Chart(
"Total Client Sales Column",
Chart.COLUMN,
data_source=["sum__value"],
title_source=["name"],
plot_total=True,
),
Chart(
"Client Sales [Bar]",
Chart.BAR,
data_source=["sum__value"],
title_source=["name"],
),
Chart(
"Total Client Sales [Bar]", Chart.BAR, data_source=["sum__value"], title_source=["name"], plot_total=True
),
Chart(
"Client Sales [Line]",
Chart.LINE,
data_source=["sum__value"],
title_source=["name"],
# plot_total=True,
),
Chart(
"Total Client Sales [Line]",
Chart.LINE,
data_source=["sum__value"],
title_source=["name"],
plot_total=True,
),
Chart(
"Total Sales [Pie]",
Chart.PIE,
data_source=["sum__value"],
title_source=["name"],
plot_total=True,
),
]


class ProductSalesApexChart(ReportView):
report_title = _("Product Sales Apex Charts")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@
valueDecimals: 2
}
}


} else if (chart_type === 'area') {
highchart_object.chart.type = 'area';

Expand All @@ -195,7 +197,8 @@
}
}
} else if (chart_type === 'line') {
var marker_enabled = true;
let marker_enabled = true;
highchart_object.chart.type = 'line';
// disable marker when ticks are more then 12 , relying on the hover of the mouse ;
try {
if (highchart_object.series[0].data.length > 12) marker_enabled = false;
Expand All @@ -218,7 +221,11 @@
}

if (is_time_series) {
highchart_object.xAxis.categories = chart_data.titles;
if (chartOptions.plot_total && chartOptions.type !== 'line') {
highchart_object.xAxis.categories = [chartOptions.title]
} else {
highchart_object.xAxis.categories = chart_data.titles;
}
highchart_object.xAxis.tickmarkPlacement = 'on';
if (chart_type !== 'line')
highchart_object.tooltip.shared = false //Option here;
Expand Down Expand Up @@ -291,22 +298,32 @@
})
} else {
let all_column_to_be_summed = []
let data = []
Object.keys(data_sources).forEach(function (series_cols, index) {
all_column_to_be_summed = all_column_to_be_summed.concat(data_sources[series_cols]);
})
let totalValues = $.slick_reporting.calculateTotalOnObjectArray(response.data, all_column_to_be_summed)

Object.keys(data_sources).forEach(function (series_cols, index) {
let data = []
data_sources[series_cols].forEach(function (col, index) {

series.push({
'name': response.metadata.time_series_column_verbose_names[index],
data: [totalValues[col]]
})
data_sources[series_cols].forEach(function (col, index) {
data.push(totalValues[col])
if (chartOptions.type !== "line") {
series.push({
'name': response.metadata.time_series_column_verbose_names[index],
data: [totalValues[col]]
})
}
})

})
if (chartOptions.type === "line") {
series.push({
'name': chartOptions.title,
data: data
})
}

}
return {
'categories': response.metadata.time_series_column_verbose_names,
Expand Down
2 changes: 1 addition & 1 deletion slick_reporting/static/slick_reporting/slick_reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
let paths = [];
for (; element && element.nodeType === Node.ELEMENT_NODE; element = element.parentNode) {
let index = 0;
for (var sibling = element.previousSibling; sibling; sibling = sibling.previousSibling) {
for (let sibling = element.previousSibling; sibling; sibling = sibling.previousSibling) {
if (sibling.nodeType === Node.DOCUMENT_TYPE_NODE)
continue;
if (sibling.nodeName === element.nodeName)
Expand Down

0 comments on commit 3681c9d

Please sign in to comment.