diff --git a/src/chartMappings.ts b/src/chartMappings.ts
index 166c96c..a22a1ff 100644
--- a/src/chartMappings.ts
+++ b/src/chartMappings.ts
@@ -1,4 +1,4 @@
-export const axisChartMappings = {
+export const chartMappings = {
calls_per_day: {
columns: [
{
@@ -8,10 +8,12 @@ export const axisChartMappings = {
{
key: 'Answered',
xAxis: false,
+ name: "Answered Calls"
},
{
key: 'Missed',
xAxis: false,
+ name: "Missed Calls"
}
]
},
@@ -57,10 +59,7 @@ export const axisChartMappings = {
xAxis: false,
}
]
- }
-};
-
-export const listChartMappings = {
+ },
top_customers_by_calls: {
columns: [
{
@@ -85,4 +84,4 @@ export const listChartMappings = {
}
]
}
-};
\ No newline at end of file
+};
diff --git a/src/components/axisChart/axis-chart.component.ts b/src/components/axisChart/axis-chart.component.ts
index b300999..fb2cbdf 100644
--- a/src/components/axisChart/axis-chart.component.ts
+++ b/src/components/axisChart/axis-chart.component.ts
@@ -1,7 +1,7 @@
///
-import { axisChartMappings } from '../../chartMappings';
import { FsData, FsDataResponse } from '../../services/FsData.service';
-import { FsSeriesTranslation } from '../../services/FsData.service';
+import { DataLabelTransformer } from "../../services/DataLabelTransformer.service";
+import { ChartMapping } from "../../services/ChartMapping.service";
import './bar-chart.styles.scss';
interface ChartResponse {
@@ -24,15 +24,19 @@ export abstract class AxisChartWidget {
protected fromDate: string;
protected toDate: string;
- constructor(protected $scope: ng.IScope, protected FsData: FsData) {
-
+ constructor(
+ protected $scope: ng.IScope,
+ protected FsData: FsData,
+ protected DataLabelTransformer: DataLabelTransformer,
+ protected ChartMapping: ChartMapping
+ ) {
}
protected setResponse(dataset: string, value: FsDataResponse): any {
let data: any[] = [];
let labels: string[] = [];
let series: any[] = [];
- const chartMap = axisChartMappings[dataset];
+ const chartMap = this.ChartMapping.getMappingForType(dataset);
if (chartMap === undefined) {
throw new Error(`Chartmapping missing for ${dataset}`);
}
@@ -53,14 +57,9 @@ protected setResponse(dataset: string, value: FsDataResponse): any {
return a.name < b.name ? -1 : 1;
}
})
- .map(d => {
- if (d[xAxisColumn.key].length > 15) {
- return d[xAxisColumn.key].substr(0, 18)+'...';
- } else {
- return d[xAxisColumn.key];
- }
- })
- .filter((entry, index, arr) => labels.indexOf(entry) === -1);
+ .map(d => d[xAxisColumn.key])
+ .filter((entry, index, arr) => labels.indexOf(entry) === -1)
+ .map(this.DataLabelTransformer.transform);
labels.push(...dataLabels);
const objKeys = Object.keys(ds.data[0]);
diff --git a/src/components/bar-chart/bar-chart.component.ts b/src/components/bar-chart/bar-chart.component.ts
index 59fe992..1fba5c8 100644
--- a/src/components/bar-chart/bar-chart.component.ts
+++ b/src/components/bar-chart/bar-chart.component.ts
@@ -2,6 +2,8 @@
import { AxisChartWidget } from '../axisChart/axis-chart.component';
import { Component } from '../../decorators';
import { FsData } from '../../services/FsData.service';
+import { DataLabelTransformer } from "../../services/DataLabelTransformer.service";
+import { ChartMapping } from "../../services/ChartMapping.service";
import '../axisChart/bar-chart.styles.scss';
@Component({
@@ -31,8 +33,13 @@ import '../axisChart/bar-chart.styles.scss';
})
export class BarChartWidget extends AxisChartWidget {
- constructor(protected $scope: ng.IScope, protected FsData: FsData) {
- super($scope, FsData);
+ constructor(
+ protected $scope: ng.IScope,
+ protected FsData: FsData,
+ protected DataLabelTransformer: DataLabelTransformer,
+ protected ChartMapping: ChartMapping
+ ) {
+ super($scope, FsData, DataLabelTransformer, ChartMapping);
}
}
\ No newline at end of file
diff --git a/src/components/line-chart/line-chart.component.ts b/src/components/line-chart/line-chart.component.ts
index 924c4e0..672098a 100644
--- a/src/components/line-chart/line-chart.component.ts
+++ b/src/components/line-chart/line-chart.component.ts
@@ -2,6 +2,8 @@
import { AxisChartWidget } from '../axisChart/axis-chart.component';
import { Component } from '../../decorators';
import { FsData } from '../../services/FsData.service';
+import { DataLabelTransformer } from "../../services/DataLabelTransformer.service";
+import { ChartMapping } from "../../services/ChartMapping.service";
import '../axisChart/line-chart.styles.scss';
@Component({
@@ -31,8 +33,13 @@ import '../axisChart/line-chart.styles.scss';
})
export class LineChartWidget extends AxisChartWidget {
- constructor(protected $scope: ng.IScope, protected FsData: FsData) {
- super($scope, FsData);
+ constructor(
+ protected $scope: ng.IScope,
+ protected FsData: FsData,
+ protected DataLabelTransformer: DataLabelTransformer,
+ protected ChartMapping: ChartMapping
+ ) {
+ super($scope, FsData, DataLabelTransformer, ChartMapping);
}
}
\ No newline at end of file
diff --git a/src/components/single-value/single-value.component.ts b/src/components/single-value/single-value.component.ts
index 9fc1549..0b88885 100644
--- a/src/components/single-value/single-value.component.ts
+++ b/src/components/single-value/single-value.component.ts
@@ -15,6 +15,7 @@ import './single-value.styles.scss';
title: '@',
type: '@',
segment: '@',
+ suffix: '@',
fromDate: '@',
toDate: '@'
},
@@ -25,6 +26,7 @@ export class SingleValueWidget {
private type: string;
private segments: string[] = ['all_data'];
private value: any;
+ private suffix: string;
private fromDate: string;
private toDate: string;
@@ -33,7 +35,12 @@ export class SingleValueWidget {
}
private setResponse(value: FsDataResponse): any {
- this.value = value.datasources[0].data;
+ let data = value.datasources[0].data;
+ if(this.suffix) {
+ this.value = `${data} ${this.suffix}`;
+ } else {
+ this.value = data
+ }
}
async $onChanges() {
diff --git a/src/components/top-list/top-list.component.ts b/src/components/top-list/top-list.component.ts
index 2914086..365d3f4 100644
--- a/src/components/top-list/top-list.component.ts
+++ b/src/components/top-list/top-list.component.ts
@@ -2,6 +2,7 @@
import { listChartMappings } from '../../chartMappings';
import { Component } from '../../decorators';
import { FsData, FsDataResponse } from '../../services/FsData.service';
+import { ChartMapping } from "../../services/ChartMapping.service";
import './top-list.styles.scss';
interface ToplistData {
@@ -14,12 +15,12 @@ interface ToplistData {
{{vm.title}}
- Name |
- Value |
+ {{vm.keyTitle}} |
+ {{vm.valueTitle}} |
|
|
@@ -29,6 +30,9 @@ interface ToplistData {
`,
bindings: {
title: '@',
+ keyTitle: '@',
+ valueTitle: '@',
+ limit: '@',
type: '@',
segments: '<',
fromDate: '@',
@@ -44,13 +48,15 @@ export class TopListWidget {
private fromDate: string;
private toDate: string;
- constructor (private $scope: ng.IScope, private FsData: FsData) {
-
- }
+ constructor (
+ private $scope: ng.IScope,
+ private FsData: FsData,
+ private ChartMapping: ChartMapping
+ ) {}
private setResponse(dataset: string, value: FsDataResponse): any {
let data: any[] = [];
- const chartMap = listChartMappings[dataset];
+ const chartMap = this.ChartMapping.getMappingForType(dataset);
if (chartMap === undefined) {
throw new Error(`Chartmapping missing for ${dataset}`);
}
diff --git a/src/index.html b/src/index.html
index 38249de..1618761 100644
--- a/src/index.html
+++ b/src/index.html
@@ -54,10 +54,14 @@
type="top_customers_by_calls"
from-date="{{ctrl.fromDate}}"
to-date="{{ctrl.toDate}}"
+ limit=4
>
new FsData()])
+ .service("DataLabelTransformer", [() => new DataLabelTransformer()])
.run(($http: ng.IHttpService) => $http.defaults.headers.common['Access-Control-Allow-Origin'] = '*')
.component('fsLineChart', LineChartWidget)
.component('fsBarChart', BarChartWidget)
diff --git a/src/services/ChartMapping.service.ts b/src/services/ChartMapping.service.ts
new file mode 100644
index 0000000..a4de0ae
--- /dev/null
+++ b/src/services/ChartMapping.service.ts
@@ -0,0 +1,30 @@
+export interface AxisChartMappings {
+ [type: String]: ChartMappingModel
+}
+
+export interface ChartMappingModel {
+ type: String;
+ sort: boolean;
+ columns: [AxisMapping];
+}
+
+export interface AxisMapping {
+ key: String;
+ xAxis: boolean;
+ name: String;
+}
+
+class ChartMapping implements ng.IServiceProvider {
+
+ private axisChartMappings: AxisChartMappings;
+
+ constructor(axisChartMappings: AxisChartMappings) {
+ this.axisChartMappings = axisChartMappings;
+ }
+
+ getMappingForType(type: String): ChartMappingModel {
+ return this.axisChartMappings[type];
+ }
+}
+
+export { ChartMapping };
diff --git a/src/services/DataLabelTransformer.service.ts b/src/services/DataLabelTransformer.service.ts
new file mode 100644
index 0000000..e27d75d
--- /dev/null
+++ b/src/services/DataLabelTransformer.service.ts
@@ -0,0 +1,9 @@
+// This class is just a placeholder
+// You can replace it with your own service if you need to
+class DataLabelTransformer implements ng.IServiceProvider {
+ transform(seriesName): string {
+ return seriesName;
+ }
+}
+
+export { DataLabelTransformer };