First xosSmartPie working
diff --git a/views/ngXosLib/xosHelpers/spec/ui/smart-pie.test.js b/views/ngXosLib/xosHelpers/spec/ui/smart-pie.test.js
index a679c66..029f8d4 100644
--- a/views/ngXosLib/xosHelpers/spec/ui/smart-pie.test.js
+++ b/views/ngXosLib/xosHelpers/spec/ui/smart-pie.test.js
@@ -86,6 +86,28 @@
expect(isolatedScope.data).toEqual(groupedData);
});
+ describe('when a labelFormatter function is provided', () => {
+ beforeEach(inject(function ($compile, $rootScope){
+ scope = $rootScope.$new();
+ scope.config = {
+ resource: 'MockResource',
+ groupBy: 'category',
+ classes: 'label-formatter-test',
+ labelFormatter: (labels) => {
+ return labels.map(l => l === '1' ? 'First' : 'Second');
+ }
+ };
+ element = angular.element('<xos-smart-pie config="config"></xos-smart-pie>');
+ $compile(element)(scope);
+ scope.$digest();
+ isolatedScope = element.isolateScope().vm;
+ }));
+
+ it('should format labels', () => {
+ expect(isolatedScope.labels).toEqual(['First', 'Second'])
+ });
+ });
+
});
});
})();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/src/ui_components/smartComponents/smartPie/smartPie.component.js b/views/ngXosLib/xosHelpers/src/ui_components/smartComponents/smartPie/smartPie.component.js
index 0468644..e9a27f1 100644
--- a/views/ngXosLib/xosHelpers/src/ui_components/smartComponents/smartPie/smartPie.component.js
+++ b/views/ngXosLib/xosHelpers/src/ui_components/smartComponents/smartPie/smartPie.component.js
@@ -23,6 +23,11 @@
resource: 'Users',
groupBy: 'fieldName',
classes: 'my-custom-class',
+ labelFormatter: (labels) => {
+ // here you can format your label,
+ // you should return an array with the same order
+ return labels;
+ }
}
* ```
* @scope
@@ -43,6 +48,7 @@
bindToController: true,
controllerAs: 'vm',
controller: function($injector, _){
+
this.Resource = $injector.get(this.config.resource);
const getData = () => {
@@ -58,7 +64,7 @@
this.data = _.reduce(Object.keys(grouped), (data, group) => data.concat(grouped[group].length), []);
// create labels
- this.labels = Object.keys(grouped);
+ this.labels = angular.isFunction(this.config.labelFormatter) ? this.config.labelFormatter(Object.keys(grouped)) : Object.keys(grouped);
});
}