Skip to content

Commit

Permalink
Fix in highcharts selector
Browse files Browse the repository at this point in the history
Fix in SlickReportingListView
  • Loading branch information
RamezIssac committed Oct 6, 2023
1 parent 46a5b7a commit 7f46720
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 55 deletions.
5 changes: 3 additions & 2 deletions demo_proj/demo_app/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ class LastTenSales(ListReportView):
report_model = SalesTransaction
report_title = "Last 10 sales"
date_field = "date"
filters = ["client"]
filters = ["client", "date"]
columns = [
"product",
"product__name",
"client__name",
"date",
"quantity",
"price",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Created by ramez on 11/20/14.
* Created by Ramez on 11/20/14.
*/
(function ($) {

Expand Down Expand Up @@ -50,28 +50,22 @@
}
}

function createChartObject(response, chart_id, extraOptions) {
function createChartObject(response, chartOptions, extraOptions) {
// Create the chart Object
// First specifying the global default
// second, Get the data from the serponse
// Adjust the Chart Object accordingly
let chartOptions = $.slick_reporting.getObjFromArray(response.chart_settings, 'id', chart_id, true)
// First specifying the global defaults then apply teh specification from the response

try {


$.extend(chartOptions, {
'sub_title': '',
});
// chartOptions = getChartOptions(isGroup, response, chartOptions);
chartOptions.data = response.data;


let is_time_series = is_timeseries_support(response, chartOptions); // response.metadata.time_series_pattern || '';
let is_crosstab = is_crosstab_support(response, chartOptions);

let chart_type = chartOptions.type;
var enable3d = false;
let enable3d = false;
let chart_data = {};

let rtl = false; // $.slick_reporting.highcharts.defaults.rtl;
Expand All @@ -88,25 +82,18 @@
let highchart_object = {
chart: {
type: '',
//renderTo: 'container',
//printWidth: 600
},
title: {
text: chartOptions.title,
// useHTML: Highcharts.hasBidiBug
//useHTML: true
},
subtitle: {
text: chartOptions.sub_title,
useHTML: Highcharts.hasBidiBug
//useHTML: true
},
yAxis: {
// title: {text: chartyAxisTitle},
opposite: rtl,
},
xAxis: {
// title: {text: chartxAxisTitle},
labels: {enabled: true},
reversed: rtl,
},
Expand All @@ -118,7 +105,6 @@
allowHTML: true,

enabled: true,
//scale:2,
}
};

Expand All @@ -131,9 +117,6 @@
if (chart_type === 'bar' || chart_type === 'column') {
highchart_object['xAxis'] = {
categories: chart_data['titles'],
// title: {
// text: null
// }
};
}
highchart_object['yAxis']['labels'] = {overflow: 'justify'};
Expand All @@ -156,18 +139,6 @@
}
};

// highchart_object.tooltip = {
// useHTML: true,
// headerFormat: '<small>{point.key}</small><table class="chart-tooltip">',
// pointFormat: '<tr><td style="color:' + Highcharts.theme.contrastTextColor + '">{series.name}: </td>' +
// '<td style="text-align: right; color: ' + Highcharts.theme.contrastTextColor + '"><b>{point.y} </b></td></tr>' +
//
// '<tr><td style="color: ' + Highcharts.theme.contrastTextColor + '">' + $.ra.highcharts.defaults.messages.percent + '</td>' +
// '<td style="text-align: right; color: ' + Highcharts.theme.contrastTextColor + '"><b>{point.percentage:.1f} %</b></td></tr>',
// footerFormat: '</table>',
// valueDecimals: 2
// };

highchart_object['legend'] = {
layout: 'vertical',
align: 'right',
Expand Down Expand Up @@ -383,10 +354,7 @@
'name': col_dict[col].verbose_name,
'data': [totalValues[col]]
})

})


})
}
return {
Expand All @@ -406,16 +374,13 @@
return response.metadata.crosstab_model || ''
}

function displayChart(data, $elem, chart_id) {
chart_id = chart_id || $elem.attr('data-report-default-chart') || '';
function displayChart(data, $elem, chartOptions) {
if ($elem.find("div[data-inner-chart-container]").length === 0) {
$elem.append('<div data-inner-chart-container style="width:100%; height:400px;"></div>')
}

let chart = $elem.find("div[data-inner-chart-container]")
// chart.append("<canvas width=\"400\" height=\"100\"></canvas>");
// let chartObject = getObjFromArray(data.chart_settings, 'id', chart_id, true);
let cache_key = data.report_slug + ':' + chart_id
let cache_key = data.report_slug + ':' + chartOptions.id;
try {
let existing_chart = _chart_cache[cache_key];
if (typeof (existing_chart) !== 'undefined') {
Expand All @@ -425,7 +390,7 @@
console.error(e)
}

chartObject = $.slick_reporting.highcharts.createChartObject(data, chart_id);
let chartObject = $.slick_reporting.highcharts.createChartObject(data, chartOptions);
_chart_cache[cache_key] = chart.highcharts(chartObject);

}
Expand All @@ -441,15 +406,12 @@
percent: 'Percent',
},
credits: {
// text: 'RaSystems.io',
// href: 'https://rasystems.io'
// text: '',
// href: ''
},
// notify_error: notify_error,
enable3d: false,

}
};

}

(jQuery)
Expand Down
12 changes: 6 additions & 6 deletions slick_reporting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def __init_subclass__(cls) -> None:
super().__init_subclass__()


class SlickReportingListViewMixin:
class SlickReportingListViewMixin(ReportViewBase):
report_generator_class = ListViewReportGenerator
filters = None

Expand Down Expand Up @@ -514,13 +514,13 @@ def get_form_filters(self, form):
def get_form_crispy_helper(self):
return get_crispy_helper(self.filters)

def get_report_generator(self, queryset, for_print):
def get_report_generator(self, queryset=None, for_print=False):
q_filters, kw_filters = self.get_form_filters(self.form)

return self.report_generator_class(
self.get_report_model(),
start_date=self.form.get_start_date(),
end_date=self.form.get_end_date(),
# start_date=self.form.get_start_date(),
# end_date=self.form.get_end_date(),
q_filters=q_filters,
kwargs_filters=kw_filters,
date_field=self.date_field,
Expand All @@ -538,7 +538,7 @@ def get_form_class(self):

elif self.filters:
return modelform_factory(
self.get_report_model(),
model=self.get_report_model(),
fields=self.filters,
formfield_callback=default_formfield_callback,
)
Expand Down Expand Up @@ -574,7 +574,7 @@ def __init_subclass__(cls) -> None:
super().__init_subclass__()


class ListReportView(SlickReportingListViewMixin, ReportViewBase):
class ListReportView(SlickReportingListViewMixin):
pass


Expand Down

0 comments on commit 7f46720

Please sign in to comment.