Skip to content

Commit

Permalink
reverse legend
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnarTumi committed Feb 21, 2024
1 parent 31ba8e5 commit 745f73d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions wagtailcharts/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ChartSettingsBlock(StructBlock):
('right', 'Right'),
), default = 'top', label="Legend position", group="General"
)
reverse_legend = BooleanBlock(default=False, required=False, label="Reverse legend", group="General")
show_values_on_chart = BooleanBlock(default=False, required=False, label="Show values on chart", group="General")
precision = IntegerBlock(default=1, label="Precision in labels/tooltips", group="General")
show_grid = BooleanBlock(default=True, required=False, label="Show Chart Grid", group="General")
Expand Down
1 change: 1 addition & 0 deletions wagtailcharts/static/wagtailcharts/js/chart-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ chart_types = {
chart_options: {
plugins:{
datalabels: {
offset: 5,
align: function(context) {
var value = parse_datalabels_value(context);
return value < 0 ? 'start' : 'end';
Expand Down
8 changes: 3 additions & 5 deletions wagtailcharts/static/wagtailcharts/js/wagtailcharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ for (i = 0; i < charts.length; ++i) {
plugins: {
legend: {
position: chart_settings['legend_position'],
display: chart_settings['show_legend']
display: chart_settings['show_legend'],
reverse: chart_settings['reverse_legend']
},
tooltip: {
callbacks: {
Expand Down Expand Up @@ -303,13 +304,10 @@ for (i = 0; i < charts.length; ++i) {
if (chart_settings['stacking'] === 'stacked') {
options.scales.x.stacked = true
options.scales.y.stacked = true
options.plugins.legend.reverse = true;
datasets = datasets.reverse();
}

if (chart_settings['stacking'] === 'stacked_100') {
options.plugins.stacked100 = { enable: true, replaceTooltipLabel: false }
options.plugins.legend.reverse = true;
datasets = datasets.reverse();
}

if (chart_settings['show_grid'] === false){
Expand Down

0 comments on commit 745f73d

Please sign in to comment.