]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Reversible Legends
authorTanner Linsley <tannerlinsley@gmail.com>
Wed, 17 Feb 2016 19:42:09 +0000 (12:42 -0700)
committerTanner Linsley <tannerlinsley@gmail.com>
Wed, 17 Feb 2016 19:42:09 +0000 (12:42 -0700)
Legends can now be reversed with the `reversed: true` property.

src/core/core.legend.js
test/core.legend.tests.js

index e42db5825b6fac4aa2f1e9b2858fd4c03def8e84..d695f2df5fcfd2c2a967cf01eb62de633ec06adc 100644 (file)
@@ -9,6 +9,7 @@ module.exports = function(Chart) {
                display: true,
                position: 'top',
                fullWidth: true, // marks that this box should take the full width of the canvas (pushing down other boxes)
+               reverse: false,
 
                // a callback that will handle
                onClick: function(e, legendItem) {
@@ -143,6 +144,9 @@ module.exports = function(Chart) {
                beforeBuildLabels: helpers.noop,
                buildLabels: function() {
                        this.legendItems = this.options.labels.generateLabels.call(this, this.chart.data);
+                       if(this.options.reverse){
+                               this.legendItems.reverse();
+                       }
                },
                afterBuildLabels: helpers.noop,
 
@@ -321,4 +325,4 @@ module.exports = function(Chart) {
                }
        });
 
-};
\ No newline at end of file
+};
index fc83e63ce4419fd411043f240839d26bc946200c..1e411827a27f3e92dbc258b9b87d665762a2f790 100644 (file)
@@ -11,6 +11,7 @@ describe('Legend block tests', function() {
                        display: true,
                        position: 'top',
                        fullWidth: true, // marks that this box should take the full width of the canvas (pushing down other boxes)
+                       reverse: false,
 
                        // a callback that will handle
                        onClick: jasmine.any(Function),
@@ -305,4 +306,4 @@ describe('Legend block tests', function() {
                        "args": ["dataset3", 228, 132]
                }]);
        });
-});
\ No newline at end of file
+});