diff --git a/examples/src/components/LineChartExample.jsx b/examples/src/components/LineChartExample.jsx
index cf1469db26..503414bde7 100644
--- a/examples/src/components/LineChartExample.jsx
+++ b/examples/src/components/LineChartExample.jsx
@@ -1,6 +1,6 @@
// (C) 2007-2018 GoodData Corporation
import React, { Component } from 'react';
-import { LineChart } from '@gooddata/react-components';
+import { LineChart, BucketApi } from '@gooddata/react-components';
import '@gooddata/react-components/styles/css/main.css';
@@ -28,75 +28,24 @@ export class LineChartExample extends Component {
render() {
const measures = [
- {
- measure: {
- localIdentifier: 'franchiseFeesIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesAdRoyaltyIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesAdRoyaltyIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesInitialFranchiseFeeIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesInitialFranchiseFeeIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesIdentifierOngoingRoyalty',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesIdentifierOngoingRoyalty
- }
- }
- },
- format: '#,##0'
- }
- }
+ BucketApi.measure(franchiseFeesIdentifier)
+ .format('#,##0'),
+ BucketApi.measure(franchiseFeesAdRoyaltyIdentifier)
+ .format('#,##0'),
+ BucketApi.measure(franchiseFeesInitialFranchiseFeeIdentifier)
+ .format('#,##0'),
+ BucketApi.measure(franchiseFeesIdentifierOngoingRoyalty)
+ .format('#,##0')
];
- const attribute = {
- visualizationAttribute: {
- displayForm: {
- identifier: monthDateIdentifier
- },
- localIdentifier: 'month'
- }
- };
+ const trendBy = BucketApi.visualizationAttribute(monthDateIdentifier);
return (
);
diff --git a/examples/src/components/ParentFilterExample.jsx b/examples/src/components/ParentFilterExample.jsx
index aee47f7db3..6b079f0919 100644
--- a/examples/src/components/ParentFilterExample.jsx
+++ b/examples/src/components/ParentFilterExample.jsx
@@ -1,6 +1,6 @@
// (C) 2007-2018 GoodData Corporation
import React, { Component } from 'react';
-import { AttributeElements, BarChart } from '@gooddata/react-components';
+import { AttributeElements, BarChart, BucketApi } from '@gooddata/react-components';
import Select from 'react-select';
import 'react-select/dist/react-select.css';
import '@gooddata/react-components/styles/css/main.css';
@@ -50,49 +50,22 @@ export class ParentFilterExample extends Component {
const visFilters = [];
if (stateFilterValues.length) {
- visFilters.push({
- positiveAttributeFilter: {
- displayForm: {
- identifier: locationStateDisplayFormIdentifier
- },
- in: stateFilterValues.map(filter => filter.value)
- }
- });
+ visFilters.push(
+ BucketApi.positiveAttributeFilter(
+ locationStateDisplayFormIdentifier,
+ stateFilterValues.map(filter => filter.value)));
}
if (cityFilterValues.length) {
- visFilters.push({
- positiveAttributeFilter: {
- displayForm: {
- identifier: locationCityDisplayFormIdentifier
- },
- in: cityFilterValues.map(filter => filter.value)
- }
- });
+ visFilters.push(
+ BucketApi.positiveAttributeFilter(
+ locationCityDisplayFormIdentifier,
+ cityFilterValues.map(filter => filter.value)));
}
- const measureTotalSales = {
- measure: {
- localIdentifier: 'amount',
- definition: {
- measureDefinition: {
- item: {
- identifier: totalSalesIdentifier
- }
- }
- },
- alias: '$ Total Sales',
- format: '#,##0'
- }
- };
+ const measureTotalSales = BucketApi.measure(totalSalesIdentifier).format('#,##0').alias('$ Total Sales');
- const viewByLocationName = {
- visualizationAttribute: {
- displayForm: {
- identifier: locationNameDisplayFormIdentifier
- },
- localIdentifier: 'location_name'
- }
- };
+ const viewByLocationName = BucketApi.visualizationAttribute(locationNameDisplayFormIdentifier)
+ .localIdentifier('location_name');
return (
diff --git a/examples/src/components/PieChartExample.jsx b/examples/src/components/PieChartExample.jsx
index a3bfede302..0cbe42c417 100644
--- a/examples/src/components/PieChartExample.jsx
+++ b/examples/src/components/PieChartExample.jsx
@@ -1,6 +1,6 @@
// (C) 2007-2018 GoodData Corporation
import React, { Component } from 'react';
-import { PieChart } from '@gooddata/react-components';
+import { PieChart, BucketApi } from '@gooddata/react-components';
import '@gooddata/react-components/styles/css/main.css';
@@ -25,45 +25,12 @@ export class PieChartExample extends Component {
render() {
const measures = [
- {
- measure: {
- localIdentifier: 'franchiseFeesAdRoyaltyIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesAdRoyaltyIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesInitialFranchiseFeeIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesInitialFranchiseFeeIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesIdentifierOngoingRoyalty',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesIdentifierOngoingRoyalty
- }
- }
- },
- format: '#,##0'
- }
- }
+ BucketApi.measure(franchiseFeesAdRoyaltyIdentifier)
+ .format('#,##0'),
+ BucketApi.measure(franchiseFeesInitialFranchiseFeeIdentifier)
+ .format('#,##0'),
+ BucketApi.measure(franchiseFeesIdentifierOngoingRoyalty)
+ .format('#,##0')
];
return (
diff --git a/examples/src/components/PivotTableDrillExample.jsx b/examples/src/components/PivotTableDrillExample.jsx
index c2bec056ea..da99d66493 100644
--- a/examples/src/components/PivotTableDrillExample.jsx
+++ b/examples/src/components/PivotTableDrillExample.jsx
@@ -1,6 +1,6 @@
// (C) 2007-2018 GoodData Corporation
import React, { Component } from 'react';
-import { PivotTable, HeaderPredicateFactory } from '@gooddata/react-components';
+import { PivotTable, HeaderPredicateFactory, BucketApi } from '@gooddata/react-components';
import '@gooddata/react-components/styles/css/main.css';
@@ -38,58 +38,14 @@ export class PivotTableDrillExample extends Component {
const { drillEvent } = this.state;
const measures = [
- {
- measure: {
- localIdentifier: 'franchiseFeesIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesAdRoyaltyIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesAdRoyaltyIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesInitialFranchiseFeeIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesInitialFranchiseFeeIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesIdentifierOngoingRoyalty',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesIdentifierOngoingRoyalty
- }
- }
- },
- format: '#,##0'
- }
- }
+ BucketApi.measure(franchiseFeesIdentifier)
+ .format('#,##0'),
+ BucketApi.measure(franchiseFeesAdRoyaltyIdentifier)
+ .format('#,##0'),
+ BucketApi.measure(franchiseFeesInitialFranchiseFeeIdentifier)
+ .format('#,##0'),
+ BucketApi.measure(franchiseFeesIdentifierOngoingRoyalty)
+ .format('#,##0')
];
const drillableItems = [
@@ -97,49 +53,14 @@ export class PivotTableDrillExample extends Component {
];
const attributes = [
- {
- visualizationAttribute: {
- displayForm: {
- identifier: locationStateDisplayFormIdentifier
- },
- localIdentifier: 'state'
- }
- },
- {
- visualizationAttribute: {
- displayForm: {
- identifier: locationNameDisplayFormIdentifier
- },
- localIdentifier: 'location'
- }
- },
- {
- visualizationAttribute: {
- displayForm: {
- identifier: menuCategoryAttributeDFIdentifier
- },
- localIdentifier: 'menu'
- }
- }
+ BucketApi.visualizationAttribute(locationStateDisplayFormIdentifier),
+ BucketApi.visualizationAttribute(locationNameDisplayFormIdentifier),
+ BucketApi.visualizationAttribute(menuCategoryAttributeDFIdentifier)
];
const columns = [
- {
- visualizationAttribute: {
- displayForm: {
- identifier: quarterDateIdentifier
- },
- localIdentifier: 'quarter'
- }
- },
- {
- visualizationAttribute: {
- displayForm: {
- identifier: monthDateIdentifier
- },
- localIdentifier: 'month'
- }
- }
+ BucketApi.visualizationAttribute(quarterDateIdentifier),
+ BucketApi.visualizationAttribute(monthDateIdentifier)
];
return (
diff --git a/examples/src/components/PivotTableDynamicExample.jsx b/examples/src/components/PivotTableDynamicExample.jsx
index ec3c76f633..fd755f851b 100644
--- a/examples/src/components/PivotTableDynamicExample.jsx
+++ b/examples/src/components/PivotTableDynamicExample.jsx
@@ -1,6 +1,6 @@
// (C) 2007-2018 GoodData Corporation
import React, { Component } from 'react';
-import { PivotTable, Table, HeaderPredicateFactory } from '@gooddata/react-components';
+import { PivotTable, Table, HeaderPredicateFactory, BucketApi } from '@gooddata/react-components';
import '@gooddata/react-components/styles/css/main.css';
@@ -17,24 +17,22 @@ import {
monthDateIdentifierJanuary,
dateDatasetIdentifier
} from '../utils/fixtures';
-import {
- createMeasureBucketItem,
- createAttributeBucketItem,
- createAttributeSortItem,
- createMeasureSortItem,
- createColumnTotal,
- createPositiveAttributeFilter,
- createRelativeDateFilter
-} from '../utils/helpers';
+import { createColumnTotal } from '../utils/helpers';
import { ElementWithParam } from './utils/ElementWithParam';
-const measureFranchiseFees = createMeasureBucketItem(franchiseFeesIdentifier);
-const measureAdRoyalty = createMeasureBucketItem(franchiseFeesAdRoyaltyIdentifier);
-const attributeLocationState = createAttributeBucketItem(locationStateDisplayFormIdentifier);
-const attributeLocationName = createAttributeBucketItem(locationNameDisplayFormIdentifier);
-const attributeMenuCategory = createAttributeBucketItem(menuCategoryAttributeDFIdentifier);
-const attributeQuarter = createAttributeBucketItem(quarterDateIdentifier);
-const attributeMonth = createAttributeBucketItem(monthDateIdentifier);
+const measureFranchiseFees = BucketApi.measure(franchiseFeesIdentifier).localIdentifier(franchiseFeesIdentifier);
+const measureAdRoyalty = BucketApi.measure(franchiseFeesAdRoyaltyIdentifier)
+ .localIdentifier(franchiseFeesAdRoyaltyIdentifier);
+const attributeLocationState = BucketApi.visualizationAttribute(locationStateDisplayFormIdentifier)
+ .localIdentifier(locationStateDisplayFormIdentifier);
+const attributeLocationName = BucketApi.visualizationAttribute(locationNameDisplayFormIdentifier)
+ .localIdentifier(locationNameDisplayFormIdentifier);
+const attributeMenuCategory = BucketApi.visualizationAttribute(menuCategoryAttributeDFIdentifier)
+ .localIdentifier(menuCategoryAttributeDFIdentifier);
+const attributeQuarter = BucketApi.visualizationAttribute(quarterDateIdentifier)
+ .localIdentifier(quarterDateIdentifier);
+const attributeMonth = BucketApi.visualizationAttribute(monthDateIdentifier)
+ .localIdentifier(monthDateIdentifier);
const measures = [measureFranchiseFees, measureAdRoyalty];
const columns = [attributeQuarter, attributeMonth];
@@ -174,7 +172,7 @@ const filterPresets = {
attributeCalifornia: {
label: 'Attribute (California)',
key: 'attributeCalifornia',
- filterItem: createPositiveAttributeFilter(
+ filterItem: BucketApi.positiveAttributeFilter(
locationStateDisplayFormIdentifier,
[locationStateAttributeCaliforniaUri]
)
@@ -182,12 +180,12 @@ const filterPresets = {
lastYear: {
label: 'Last year',
key: 'lastYear',
- filterItem: createRelativeDateFilter(dateDatasetIdentifier, 'GDC.time.year', -1, -1)
+ filterItem: BucketApi.relativeDateFilter(dateDatasetIdentifier, 'GDC.time.year', -1, -1)
},
noData: {
label: 'No Data',
key: 'noData',
- filterItem: createRelativeDateFilter(dateDatasetIdentifier, 'GDC.time.year', 1, 1)
+ filterItem: BucketApi.relativeDateFilter(dateDatasetIdentifier, 'GDC.time.year', 1, 1)
},
franchiseFeesCalifornia: {
label: 'Franchise Fees California',
@@ -197,10 +195,10 @@ const filterPresets = {
};
const franchiseFeesCalifornia =
- createMeasureBucketItem(franchiseFeesIdentifier, 'franchiseFeesCalifornia', 'FranchiseFees (California)', [filterPresets.attributeCalifornia.filterItem]);
-
-const ASC = 'asc';
-const DESC = 'desc';
+ BucketApi.measure(franchiseFeesIdentifier)
+ .localIdentifier('franchiseFeesCalifornia')
+ .alias('FranchiseFees (California)')
+ .filters(filterPresets.attributeCalifornia.filterItem);
const sortingPresets = {
noSort: {
@@ -211,38 +209,46 @@ const sortingPresets = {
byMenuCategory: {
label: 'By Menu Category ASC',
key: 'byMenuCategory',
- sortBy: [createAttributeSortItem(menuCategoryAttributeDFIdentifier, ASC)]
+ sortBy: [BucketApi.attributeSortItem(menuCategoryAttributeDFIdentifier, 'asc')]
},
byLocationState: {
label: 'By Location State DESC',
key: 'byLocationState',
- sortBy: [createAttributeSortItem(locationStateDisplayFormIdentifier, DESC)]
+ sortBy: [BucketApi.attributeSortItem(locationStateDisplayFormIdentifier, 'desc')]
},
byQ1JanFranchiseFees: {
label: 'by Q1 / Jan / FranchiseFees DESC',
key: 'byQ1JanFranchiseFees',
- sortBy: [createMeasureSortItem(
- franchiseFeesIdentifier,
- DESC,
- [
- quarterDateIdentifier, '/gdc/md/xms7ga4tf3g3nzucd8380o2bev8oeknp/obj/2009/elements?id=1',
- monthDateIdentifier, '/gdc/md/xms7ga4tf3g3nzucd8380o2bev8oeknp/obj/2071/elements?id=1'
- ]
- )]
+ sortBy: [
+ BucketApi.measureSortItem(franchiseFeesIdentifier, 'desc')
+ .attributeLocators(
+ {
+ attributeIdentifier: quarterDateIdentifier,
+ element: '/gdc/md/xms7ga4tf3g3nzucd8380o2bev8oeknp/obj/2009/elements?id=1'
+ },
+ {
+ attributeIdentifier: monthDateIdentifier,
+ element: '/gdc/md/xms7ga4tf3g3nzucd8380o2bev8oeknp/obj/2071/elements?id=1'
+ }
+ )
+ ]
},
byLocationStateAndQ1JanFranchiseFees: {
label: 'By Location State ASC And Q1 Jan Franchise Fees DESC',
key: 'byLocationStateAndQ1JanFranchiseFees',
sortBy: [
- createAttributeSortItem(locationStateDisplayFormIdentifier, ASC),
- createMeasureSortItem(
- franchiseFeesIdentifier,
- DESC,
- [
- quarterDateIdentifier, '/gdc/md/xms7ga4tf3g3nzucd8380o2bev8oeknp/obj/2009/elements?id=1',
- monthDateIdentifier, '/gdc/md/xms7ga4tf3g3nzucd8380o2bev8oeknp/obj/2071/elements?id=1'
- ]
- )
+ BucketApi.attributeSortItem(locationStateDisplayFormIdentifier, 'asc'),
+ BucketApi.measureSortItem(franchiseFeesIdentifier, 'desc')
+ .attributeLocators(
+ {
+ attributeIdentifier: quarterDateIdentifier,
+ element: '/gdc/md/xms7ga4tf3g3nzucd8380o2bev8oeknp/obj/2009/elements?id=1'
+ },
+ {
+ attributeIdentifier: monthDateIdentifier,
+ element: '/gdc/md/xms7ga4tf3g3nzucd8380o2bev8oeknp/obj/2071/elements?id=1'
+ }
+ )
]
}
};
diff --git a/examples/src/components/PivotTableExample.jsx b/examples/src/components/PivotTableExample.jsx
index ba016fa7c2..68a427aefb 100644
--- a/examples/src/components/PivotTableExample.jsx
+++ b/examples/src/components/PivotTableExample.jsx
@@ -1,6 +1,6 @@
// (C) 2007-2018 GoodData Corporation
import React, { Component } from 'react';
-import { PivotTable } from '@gooddata/react-components';
+import { PivotTable, BucketApi } from '@gooddata/react-components';
import PropTypes from 'prop-types';
import '@gooddata/react-components/styles/css/main.css';
@@ -38,104 +38,25 @@ export class PivotTableExample extends Component {
render() {
const { withMeasures, withAttributes, withPivot, hasError, className } = this.props;
const measures = withMeasures ? [
- {
- measure: {
- localIdentifier: 'franchiseFeesIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesAdRoyaltyIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesAdRoyaltyIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesInitialFranchiseFeeIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesInitialFranchiseFeeIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesIdentifierOngoingRoyalty',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesIdentifierOngoingRoyalty
- }
- }
- },
- format: '#,##0'
- }
- }
+ BucketApi.measure(franchiseFeesIdentifier)
+ .format('#,##0'),
+ BucketApi.measure(franchiseFeesAdRoyaltyIdentifier)
+ .format('#,##0'),
+ BucketApi.measure(franchiseFeesInitialFranchiseFeeIdentifier)
+ .format('#,##0'),
+ BucketApi.measure(franchiseFeesIdentifierOngoingRoyalty)
+ .format('#,##0')
] : [];
const attributes = withAttributes ? [
- {
- visualizationAttribute: {
- displayForm: {
- identifier: locationStateDisplayFormIdentifier
- },
- localIdentifier: 'state'
- }
- },
- {
- visualizationAttribute: {
- displayForm: {
- identifier: locationNameDisplayFormIdentifier
- },
- localIdentifier: 'location'
- }
- },
- {
- visualizationAttribute: {
- displayForm: {
- identifier: menuCategoryAttributeDFIdentifier
- },
- localIdentifier: 'menu'
- }
- }
+ BucketApi.visualizationAttribute(locationStateDisplayFormIdentifier),
+ BucketApi.visualizationAttribute(locationNameDisplayFormIdentifier),
+ BucketApi.visualizationAttribute(menuCategoryAttributeDFIdentifier)
] : [];
const columns = withPivot ? [
- {
- visualizationAttribute: {
- displayForm: {
- identifier: quarterDateIdentifier
- },
- localIdentifier: 'quarter'
- }
- },
- {
- visualizationAttribute: {
- displayForm: {
- identifier: monthDateIdentifier
- },
- localIdentifier: 'month'
- }
- }
+ BucketApi.visualizationAttribute(quarterDateIdentifier),
+ BucketApi.visualizationAttribute(monthDateIdentifier)
] : [];
return (
diff --git a/examples/src/components/PivotTableSortingExample.jsx b/examples/src/components/PivotTableSortingExample.jsx
index 971ccfb46c..cf5759131c 100644
--- a/examples/src/components/PivotTableSortingExample.jsx
+++ b/examples/src/components/PivotTableSortingExample.jsx
@@ -1,6 +1,6 @@
// (C) 2007-2018 GoodData Corporation
import React, { Component } from 'react';
-import { PivotTable } from '@gooddata/react-components';
+import { PivotTable, BucketApi } from '@gooddata/react-components';
import '@gooddata/react-components/styles/css/main.css';
@@ -20,113 +20,29 @@ import {
export class PivotTableSortingExample extends Component {
render() {
const measures = [
- {
- measure: {
- localIdentifier: 'franchiseFeesIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesAdRoyaltyIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesAdRoyaltyIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesInitialFranchiseFeeIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesInitialFranchiseFeeIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesIdentifierOngoingRoyalty',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesIdentifierOngoingRoyalty
- }
- }
- },
- format: '#,##0'
- }
- }
+ BucketApi.measure(franchiseFeesIdentifier)
+ .format('#,##0'),
+ BucketApi.measure(franchiseFeesAdRoyaltyIdentifier)
+ .format('#,##0'),
+ BucketApi.measure(franchiseFeesInitialFranchiseFeeIdentifier)
+ .format('#,##0'),
+ BucketApi.measure(franchiseFeesIdentifierOngoingRoyalty)
+ .format('#,##0')
];
const attributes = [
- {
- visualizationAttribute: {
- displayForm: {
- identifier: locationStateDisplayFormIdentifier
- },
- localIdentifier: 'state'
- }
- },
- {
- visualizationAttribute: {
- displayForm: {
- identifier: locationNameDisplayFormIdentifier
- },
- localIdentifier: 'location'
- }
- },
- {
- visualizationAttribute: {
- displayForm: {
- identifier: menuCategoryAttributeDFIdentifier
- },
- localIdentifier: 'menu'
- }
- }
+ BucketApi.visualizationAttribute(locationStateDisplayFormIdentifier),
+ BucketApi.visualizationAttribute(locationNameDisplayFormIdentifier),
+ BucketApi.visualizationAttribute(menuCategoryAttributeDFIdentifier).localIdentifier('menu')
];
const columns = [
- {
- visualizationAttribute: {
- displayForm: {
- identifier: quarterDateIdentifier
- },
- localIdentifier: 'quarter'
- }
- },
- {
- visualizationAttribute: {
- displayForm: {
- identifier: monthDateIdentifier
- },
- localIdentifier: 'month'
- }
- }
+ BucketApi.visualizationAttribute(quarterDateIdentifier),
+ BucketApi.visualizationAttribute(monthDateIdentifier)
];
const sortBy = [
- {
- attributeSortItem: {
- direction: 'asc',
- attributeIdentifier: 'menu'
- }
- }
+ BucketApi.attributeSortItem('menu', 'asc')
];
return (
diff --git a/examples/src/components/PivotTableTotalsExample.jsx b/examples/src/components/PivotTableTotalsExample.jsx
index 00ccd15cfc..a08a2f3356 100644
--- a/examples/src/components/PivotTableTotalsExample.jsx
+++ b/examples/src/components/PivotTableTotalsExample.jsx
@@ -1,6 +1,6 @@
// (C) 2007-2018 GoodData Corporation
import React, { Component } from 'react';
-import { PivotTable } from '@gooddata/react-components';
+import { PivotTable, BucketApi } from '@gooddata/react-components';
import '@gooddata/react-components/styles/css/main.css';
@@ -20,104 +20,29 @@ import {
export class PivotTableTotalsExample extends Component {
render() {
const measures = [
- {
- measure: {
- localIdentifier: 'franchiseFeesIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesAdRoyaltyIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesAdRoyaltyIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesInitialFranchiseFeeIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesInitialFranchiseFeeIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesIdentifierOngoingRoyalty',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesIdentifierOngoingRoyalty
- }
- }
- },
- format: '#,##0'
- }
- }
+ BucketApi.measure(franchiseFeesIdentifier)
+ .format('#,##0')
+ .localIdentifier('franchiseFeesIdentifier'),
+ BucketApi.measure(franchiseFeesAdRoyaltyIdentifier)
+ .format('#,##0')
+ .localIdentifier('franchiseFeesAdRoyaltyIdentifier'),
+ BucketApi.measure(franchiseFeesInitialFranchiseFeeIdentifier)
+ .format('#,##0')
+ .localIdentifier('franchiseFeesInitialFranchiseFeeIdentifier'),
+ BucketApi.measure(franchiseFeesIdentifierOngoingRoyalty)
+ .format('#,##0')
+ .localIdentifier('franchiseFeesIdentifierOngoingRoyalty')
];
const attributes = [
- {
- visualizationAttribute: {
- displayForm: {
- identifier: locationStateDisplayFormIdentifier
- },
- localIdentifier: 'state'
- }
- },
- {
- visualizationAttribute: {
- displayForm: {
- identifier: locationNameDisplayFormIdentifier
- },
- localIdentifier: 'location'
- }
- },
- {
- visualizationAttribute: {
- displayForm: {
- identifier: menuCategoryAttributeDFIdentifier
- },
- localIdentifier: 'menu'
- }
- }
+ BucketApi.visualizationAttribute(locationStateDisplayFormIdentifier).localIdentifier('state'),
+ BucketApi.visualizationAttribute(locationNameDisplayFormIdentifier),
+ BucketApi.visualizationAttribute(menuCategoryAttributeDFIdentifier)
];
const columns = [
- {
- visualizationAttribute: {
- displayForm: {
- identifier: quarterDateIdentifier
- },
- localIdentifier: 'quarter'
- }
- },
- {
- visualizationAttribute: {
- displayForm: {
- identifier: monthDateIdentifier
- },
- localIdentifier: 'month'
- }
- }
+ BucketApi.visualizationAttribute(quarterDateIdentifier),
+ BucketApi.visualizationAttribute(monthDateIdentifier)
];
const totals = [
diff --git a/examples/src/components/PreviousPeriodHeadlineExample.jsx b/examples/src/components/PreviousPeriodHeadlineExample.jsx
index 95636ac3d9..865bc1dbb5 100644
--- a/examples/src/components/PreviousPeriodHeadlineExample.jsx
+++ b/examples/src/components/PreviousPeriodHeadlineExample.jsx
@@ -1,7 +1,7 @@
// (C) 2007-2018 GoodData Corporation
import React, { Component } from 'react';
-import { Headline } from '@gooddata/react-components';
+import { Headline, BucketApi } from '@gooddata/react-components';
import '@gooddata/react-components/styles/css/main.css';
@@ -10,11 +10,6 @@ import {
dateDataSetUri,
projectId
} from '../utils/fixtures';
-import {
- createRelativeDateFilter,
- createMeasureBucketItem,
- createPreviousPeriodMeasureBucketItem
-} from '../utils/helpers';
export class PreviousPeriodHeadlineExample extends Component {
onLoadingChanged(...params) {
@@ -32,10 +27,16 @@ export class PreviousPeriodHeadlineExample extends Component {
diff --git a/examples/src/components/SamePeriodColumnChartExample.jsx b/examples/src/components/SamePeriodColumnChartExample.jsx
index f5408d231a..c4473c2072 100644
--- a/examples/src/components/SamePeriodColumnChartExample.jsx
+++ b/examples/src/components/SamePeriodColumnChartExample.jsx
@@ -1,7 +1,7 @@
// (C) 2007-2018 GoodData Corporation
import React, { Component } from 'react';
-import { ColumnChart } from '@gooddata/react-components';
+import { ColumnChart, BucketApi } from '@gooddata/react-components';
import '@gooddata/react-components/styles/css/main.css';
@@ -11,11 +11,6 @@ import {
yearDateDataSetAttributeIdentifier,
projectId
} from '../utils/fixtures';
-import {
- createAttributeBucketItem,
- createSamePeriodMeasureBucketItem,
- createMeasureBucketItem
-} from '../utils/helpers';
export class SamePeriodColumnChartExample extends Component {
onLoadingChanged(...params) {
@@ -34,11 +29,13 @@ export class SamePeriodColumnChartExample extends Component {
diff --git a/examples/src/components/ScatterPlotExample.jsx b/examples/src/components/ScatterPlotExample.jsx
index b347a43efb..bcce8929a2 100644
--- a/examples/src/components/ScatterPlotExample.jsx
+++ b/examples/src/components/ScatterPlotExample.jsx
@@ -1,6 +1,6 @@
// (C) 2007-2018 GoodData Corporation
import React, { Component } from 'react';
-import { ScatterPlot } from '@gooddata/react-components';
+import { ScatterPlot, BucketApi } from '@gooddata/react-components';
import '@gooddata/react-components/styles/css/main.css';
@@ -23,42 +23,11 @@ export class ScatterPlotExample extends Component {
}
render() {
- const xMeasure = {
- measure: {
- localIdentifier: 'franchiseFeesIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesIdentifier
- }
- }
- },
- format: '#,##0'
- }
- };
+ const xMeasure = BucketApi.measure(franchiseFeesIdentifier).format('#,##0');
- const yMeasure = {
- measure: {
- localIdentifier: 'franchisedSalesIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchisedSalesIdentifier
- }
- }
- },
- format: '#,##0'
- }
- };
+ const yMeasure = BucketApi.measure(franchisedSalesIdentifier).format('#,##0');
- const locationResort = {
- visualizationAttribute: {
- displayForm: {
- identifier: locationResortIdentifier
- },
- localIdentifier: 'location_resort'
- }
- };
+ const locationResort = BucketApi.visualizationAttribute(locationResortIdentifier);
return (
diff --git a/examples/src/components/StackedAreaChartExample.jsx b/examples/src/components/StackedAreaChartExample.jsx
index 440e452fed..057a8b87c9 100644
--- a/examples/src/components/StackedAreaChartExample.jsx
+++ b/examples/src/components/StackedAreaChartExample.jsx
@@ -1,6 +1,6 @@
// (C) 2007-2018 GoodData Corporation
import React, { Component } from 'react';
-import { AreaChart } from '@gooddata/react-components';
+import { AreaChart, BucketApi } from '@gooddata/react-components';
import '@gooddata/react-components/styles/css/main.css';
@@ -26,68 +26,17 @@ export class StackedAreaChartExample extends Component {
render() {
const measures = [
- {
- measure: {
- localIdentifier: 'franchiseFeesIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesAdRoyaltyIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesAdRoyaltyIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesInitialFranchiseFeeIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesInitialFranchiseFeeIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesIdentifierOngoingRoyalty',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesIdentifierOngoingRoyalty
- }
- }
- },
- format: '#,##0'
- }
- }
+ BucketApi.measure(franchiseFeesIdentifier)
+ .format('#,##0'),
+ BucketApi.measure(franchiseFeesAdRoyaltyIdentifier)
+ .format('#,##0'),
+ BucketApi.measure(franchiseFeesInitialFranchiseFeeIdentifier)
+ .format('#,##0'),
+ BucketApi.measure(franchiseFeesIdentifierOngoingRoyalty)
+ .format('#,##0')
];
- const viewBy = {
- visualizationAttribute: {
- displayForm: {
- identifier: monthDateIdentifier
- },
- localIdentifier: 'month'
- }
- };
+ const viewBy = BucketApi.visualizationAttribute(monthDateIdentifier);
return (
diff --git a/examples/src/components/TableExample.jsx b/examples/src/components/TableExample.jsx
index ea037902e1..4dda0a351f 100644
--- a/examples/src/components/TableExample.jsx
+++ b/examples/src/components/TableExample.jsx
@@ -1,6 +1,6 @@
// (C) 2007-2018 GoodData Corporation
import React, { Component } from 'react';
-import { Table } from '@gooddata/react-components';
+import { Table, BucketApi } from '@gooddata/react-components';
import '@gooddata/react-components/styles/css/main.css';
@@ -26,58 +26,18 @@ export class TableExample extends Component {
render() {
const measures = [
- {
- measure: {
- localIdentifier: 'franchiseFeesIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesAdRoyaltyIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesAdRoyaltyIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesInitialFranchiseFeeIdentifier',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesInitialFranchiseFeeIdentifier
- }
- }
- },
- format: '#,##0'
- }
- },
- {
- measure: {
- localIdentifier: 'franchiseFeesIdentifierOngoingRoyalty',
- definition: {
- measureDefinition: {
- item: {
- identifier: franchiseFeesIdentifierOngoingRoyalty
- }
- }
- },
- format: '#,##0'
- }
- }
+ BucketApi.measure(franchiseFeesIdentifier)
+ .format('#,##0')
+ .localIdentifier('franchiseFeesIdentifier'),
+ BucketApi.measure(franchiseFeesAdRoyaltyIdentifier)
+ .format('#,##0')
+ .localIdentifier('franchiseFeesAdRoyaltyIdentifier'),
+ BucketApi.measure(franchiseFeesInitialFranchiseFeeIdentifier)
+ .format('#,##0')
+ .localIdentifier('franchiseFeesInitialFranchiseFeeIdentifier'),
+ BucketApi.measure(franchiseFeesIdentifierOngoingRoyalty)
+ .format('#,##0')
+ .localIdentifier('franchiseFeesIdentifierOngoingRoyalty')
];
const totals = [
@@ -104,14 +64,7 @@ export class TableExample extends Component {
];
const attributes = [
- {
- visualizationAttribute: {
- displayForm: {
- identifier: monthDateIdentifier
- },
- localIdentifier: 'month'
- }
- }
+ BucketApi.visualizationAttribute(monthDateIdentifier).localIdentifier('month')
];
return (
diff --git a/examples/src/components/TreemapExample.jsx b/examples/src/components/TreemapExample.jsx
index 1c208d1de6..a8a97e3c9c 100644
--- a/examples/src/components/TreemapExample.jsx
+++ b/examples/src/components/TreemapExample.jsx
@@ -1,6 +1,6 @@
// (C) 2007-2018 GoodData Corporation
import React, { Component } from 'react';
-import { Treemap } from '@gooddata/react-components';
+import { Treemap, BucketApi } from '@gooddata/react-components';
import '@gooddata/react-components/styles/css/main.css';
@@ -18,38 +18,11 @@ export class TreeMapExample extends Component {
}
render() {
- const numberOfChecks = {
- measure: {
- localIdentifier: 'numberOfChecks',
- definition: {
- measureDefinition: {
- item: {
- identifier: numberOfChecksIdentifier
- }
- }
- },
- alias: '# Checks',
- format: '#,##0'
- }
- };
+ const numberOfChecks = BucketApi.measure(numberOfChecksIdentifier).format('#,##0').alias('# Checks');
- const locationState = {
- visualizationAttribute: {
- displayForm: {
- identifier: locationStateDisplayFormIdentifier
- },
- localIdentifier: 'label.restaurantlocation.locationstate'
- }
- };
+ const locationState = BucketApi.visualizationAttribute(locationStateDisplayFormIdentifier);
- const locationCity = {
- visualizationAttribute: {
- displayForm: {
- identifier: locationCityDisplayFormIdentifier
- },
- localIdentifier: 'label.restaurantlocation.locationcity'
- }
- };
+ const locationCity = BucketApi.visualizationAttribute(locationCityDisplayFormIdentifier);
return (
diff --git a/examples/src/routes/AggregationTest.jsx b/examples/src/routes/AggregationTest.jsx
index 64fdccaf4a..40919e1148 100644
--- a/examples/src/routes/AggregationTest.jsx
+++ b/examples/src/routes/AggregationTest.jsx
@@ -1,6 +1,6 @@
// (C) 2007-2018 GoodData Corporation
import React, { Component } from 'react';
-import { BarChart, ColumnChart, PieChart } from '@gooddata/react-components';
+import { BarChart, ColumnChart, PieChart, BucketApi } from '@gooddata/react-components';
import '@gooddata/react-components/styles/css/main.css';
@@ -14,24 +14,20 @@ import {
franchiseFeesIdentifierOngoingRoyalty,
projectId
} from '../utils/fixtures';
-import { createMeasureBucketItem, createAttributeBucketItem } from '../utils/helpers';
-const totalSales = createMeasureBucketItem(totalSalesIdentifier);
-totalSales.measure.definition.measureDefinition.aggregation = 'sum';
+const totalSales = BucketApi.measure(totalSalesIdentifier)
+ .aggregation('sum')
+ .localIdentifier(totalSalesIdentifier);
-const locationResort = createAttributeBucketItem(locationResortIdentifier);
-const month = createAttributeBucketItem(monthDateIdentifier);
+const locationResort = BucketApi.visualizationAttribute(locationResortIdentifier);
+const month = BucketApi.visualizationAttribute(monthDateIdentifier);
const franchiseFeesMeasures = [
franchiseFeesIdentifier,
franchiseFeesAdRoyaltyIdentifier,
franchiseFeesInitialFranchiseFeeIdentifier,
franchiseFeesIdentifierOngoingRoyalty
-].map((identifier) => {
- const bucket = createMeasureBucketItem(identifier);
- bucket.measure.definition.measureDefinition.aggregation = 'sum';
- return bucket;
-});
+].map(identifier => BucketApi.measure(identifier).aggregation('sum').localIdentifier(identifier));
export class AggregationTest extends Component {
onLoadingChanged(...params) {
diff --git a/examples/src/utils/helpers.js b/examples/src/utils/helpers.js
index 3bcd71c645..4651641515 100644
--- a/examples/src/utils/helpers.js
+++ b/examples/src/utils/helpers.js
@@ -1,165 +1,4 @@
// (C) 2007-2018 GoodData Corporation
-import { DataLayer } from '@gooddata/gooddata-js';
-import { chunk } from 'lodash';
-
-const { Uri: { isUri } } = DataLayer;
-
-const getQualifierObject = qualifierString => ({
- [(isUri(qualifierString) ? 'uri' : 'identifier')]: qualifierString
-});
-
-export const createMeasureBucketItem = (qualifierString, localIdentifier, alias, filters = []) => {
- const aliasProp = alias ? { alias } : {};
- const filtersProp = filters.length > 0 ? { filters } : {};
- return {
- measure: {
- localIdentifier: localIdentifier || qualifierString,
- definition: {
- measureDefinition: {
- item: getQualifierObject(qualifierString),
- ...filtersProp
- }
- },
- ...aliasProp
- }
- };
-};
-
-export const createSamePeriodMeasureBucketItem = (masterLocalIdentifier, attributeDFQualifier, alias) => {
- const aliasProp = alias ? { alias } : {};
- return {
- measure: {
- localIdentifier: `${masterLocalIdentifier}_sp`,
- definition: {
- popMeasureDefinition: {
- measureIdentifier: masterLocalIdentifier,
- popAttribute: {
- [isUri(attributeDFQualifier) ? 'uri' : 'identifier']: attributeDFQualifier
- }
- }
- },
- ...aliasProp
- }
- };
-};
-
-export const createPreviousPeriodMeasureBucketItem = (masterLocalIdentifier, dateDataSetQualifier, alias) => {
- const aliasProp = alias ? { alias } : {};
- return {
- measure: {
- localIdentifier: `${masterLocalIdentifier}_pp`,
- definition: {
- previousPeriodMeasure: {
- measureIdentifier: masterLocalIdentifier,
- dateDataSets: [
- {
- dataSet: {
- [isUri(dateDataSetQualifier) ? 'uri' : 'identifier']: dateDataSetQualifier
- },
- periodsAgo: 1
- }
- ]
- }
- },
- ...aliasProp
- }
- };
-};
-
-export const createAttributeBucketItem = (qualifierString, localIdentifier, alias) => {
- const aliasProp = alias ? { alias } : {};
- return {
- visualizationAttribute: {
- localIdentifier: qualifierString,
- displayForm: getQualifierObject(qualifierString),
- ...aliasProp
- }
- };
-};
-
-export const createPositiveAttributeFilter = (qualifierString, values) => {
- return {
- positiveAttributeFilter: {
- displayForm: getQualifierObject(qualifierString),
- in: values
- }
- };
-};
-
-export const createNegativeAttributeFilter = (qualifierString, values) => {
- return {
- negativeAttributeFilter: {
- displayForm: getQualifierObject(qualifierString),
- notIn: values
- }
- };
-};
-
-export const createRelativeDateFilter = (dateDataSetQualifier, granularity, from, to) => {
- return {
- relativeDateFilter: {
- dataSet: {
- [isUri(dateDataSetQualifier) ? 'uri' : 'identifier']: dateDataSetQualifier
- },
- granularity,
- from,
- to
- }
- };
-};
-
-export const createMeasureAttributeFilter = (qualifierString, values) => {
- return {
- positiveAttributeFilter: {
- displayForm: getQualifierObject(qualifierString),
- in: values
- }
- };
-};
-
-export const createAttributeSortItem = (attributeIdentifier, direction = 'asc', aggregation) => {
- const aggregationSpread = aggregation ? { aggregation } : {};
- return {
- attributeSortItem: {
- direction,
- attributeIdentifier,
- ...aggregationSpread
- }
- };
-};
-
-/* createMeasureSortItem
- * This helps build measure sort items. This enables sorting data by measure.
- * If you are sorting data that have measures and attributes in the same dimension,
- * you need to also specify attribute locators. Attribute locators are pairs of
- * attributeIdentifiers and attributeValueUris. They need to be in the same order
- * as defined in the dimension.
- */
-export const createMeasureSortItem = (measureIdentifier, direction = 'desc', attributeLocators = []) => {
- const attributeLocatorSpread = chunk(attributeLocators, 2)
- .map(([attributeLocatorIdentifier, attributeLocatorValue]) => {
- return {
- attributeLocatorItem: {
- attributeIdentifier: attributeLocatorIdentifier,
- element: attributeLocatorValue
- }
- };
- });
-
- return {
- measureSortItem: {
- direction,
- locators: [
- ...attributeLocatorSpread,
- {
- measureLocatorItem: {
- measureIdentifier
- }
- }
- ]
- }
- };
-};
export const createColumnTotal = (measureLocalIdentifier, attributeLocalIdentifier, type = 'sum') => {
return {
diff --git a/src/helpers/bucketApi/attributes.ts b/src/helpers/bucketApi/attributes.ts
new file mode 100644
index 0000000000..6e694593ad
--- /dev/null
+++ b/src/helpers/bucketApi/attributes.ts
@@ -0,0 +1,27 @@
+// (C) 2018 GoodData Corporation
+import { VisualizationObject } from '@gooddata/typings';
+import { getQualifierObject } from './utils';
+
+export class VisualizationAttributeBuilder implements VisualizationObject.IVisualizationAttribute {
+ private static lastAttributeId = 0;
+ public visualizationAttribute: VisualizationObject.IVisualizationAttribute['visualizationAttribute'];
+ constructor(displayForm: string) {
+ this.visualizationAttribute = {
+ displayForm: getQualifierObject(displayForm),
+ localIdentifier: `va_${VisualizationAttributeBuilder.lastAttributeId++}`
+ };
+ }
+
+ public alias = (alias: string) => {
+ this.visualizationAttribute.alias = alias;
+ return this;
+ }
+
+ public localIdentifier = (localIdentifier: string) => {
+ this.visualizationAttribute.localIdentifier = localIdentifier;
+ return this;
+ }
+}
+
+export const visualizationAttribute = (displayForm: string) =>
+ new VisualizationAttributeBuilder(displayForm);
diff --git a/src/helpers/bucketApi/filters.ts b/src/helpers/bucketApi/filters.ts
new file mode 100644
index 0000000000..8b02515b85
--- /dev/null
+++ b/src/helpers/bucketApi/filters.ts
@@ -0,0 +1,49 @@
+// (C) 2018 GoodData Corporation
+import { VisualizationObject } from '@gooddata/typings';
+import { getQualifierObject } from './utils';
+
+export const positiveAttributeFilter = (
+ qualifier: string,
+ inValues: string[]
+): VisualizationObject.IVisualizationObjectPositiveAttributeFilter => ({
+ positiveAttributeFilter: {
+ displayForm: getQualifierObject(qualifier),
+ in: inValues
+ }
+});
+
+export const negativeAttributeFilter = (
+ qualifier: string,
+ notInValues: string[]
+): VisualizationObject.IVisualizationObjectNegativeAttributeFilter => ({
+ negativeAttributeFilter: {
+ displayForm: getQualifierObject(qualifier),
+ notIn: notInValues
+ }
+});
+
+export const absoluteDateFilter = (
+ dataSet: string,
+ from?: string,
+ to?: string
+): VisualizationObject.IVisualizationObjectAbsoluteDateFilter => ({
+ absoluteDateFilter: {
+ dataSet: getQualifierObject(dataSet),
+ from,
+ to
+ }
+});
+
+export const relativeDateFilter = (
+ dataSet: string,
+ granularity: string,
+ from?: number,
+ to?: number
+): VisualizationObject.IVisualizationObjectRelativeDateFilter => ({
+ relativeDateFilter: {
+ dataSet: getQualifierObject(dataSet),
+ granularity,
+ from,
+ to
+ }
+});
diff --git a/src/helpers/bucketApi/index.ts b/src/helpers/bucketApi/index.ts
new file mode 100644
index 0000000000..4c60bb82e0
--- /dev/null
+++ b/src/helpers/bucketApi/index.ts
@@ -0,0 +1,5 @@
+// (C) 2018 GoodData Corporation
+export * from './attributes';
+export * from './filters';
+export * from './measures';
+export * from './sortBy';
diff --git a/src/helpers/bucketApi/measures.ts b/src/helpers/bucketApi/measures.ts
new file mode 100644
index 0000000000..c739d305a8
--- /dev/null
+++ b/src/helpers/bucketApi/measures.ts
@@ -0,0 +1,132 @@
+// (C) 2018 GoodData Corporation
+import { VisualizationObject } from '@gooddata/typings';
+import { getQualifierObject } from './utils';
+
+export interface IPreviousPeriodDateDataSetSimple {
+ dataSet: VisualizationObject.ObjQualifier | string;
+ periodsAgo: number;
+}
+
+export interface IMeasureAux
{
+ measure: {
+ definition: T;
+ localIdentifier: VisualizationObject.IMeasure['measure']['localIdentifier'];
+ alias: VisualizationObject.IMeasure['measure']['alias'];
+ format: VisualizationObject.IMeasure['measure']['format'];
+ title: VisualizationObject.IMeasure['measure']['title'];
+ };
+}
+
+export class MeasureBuilderBase implements IMeasureAux {
+ private static lastMeasureId = 0;
+ public measure: IMeasureAux['measure'];
+ constructor() {
+ this.measure = {
+ localIdentifier: `m_${MeasureBuilderBase.lastMeasureId++}`
+ } as any; // definition is added in subclass
+ }
+
+ public alias = (alias: string) => {
+ this.measure.alias = alias;
+ return this;
+ }
+
+ public format = (format: string) => {
+ this.measure.format = format;
+ return this;
+ }
+
+ public title = (title: string) => {
+ this.measure.title = title;
+ return this;
+ }
+
+ public localIdentifier = (localIdentifier: string) => {
+ this.measure.localIdentifier = localIdentifier;
+ return this;
+ }
+}
+
+export class MeasureBuilder extends MeasureBuilderBase {
+ constructor(identifier: string) {
+ super();
+ this.measure.definition = {
+ measureDefinition: {
+ item: getQualifierObject(identifier)
+ }
+ };
+ }
+
+ public aggregation = (aggregation: VisualizationObject.MeasureAggregation) => {
+ this.measure.definition.measureDefinition.aggregation = aggregation;
+ return this;
+ }
+
+ public ratio = () => {
+ this.measure.definition.measureDefinition.computeRatio = true;
+ return this;
+ }
+
+ public filters = (...filters: VisualizationObject.VisualizationObjectFilter[]) => {
+ this.measure.definition.measureDefinition.filters = filters;
+ return this;
+ }
+}
+
+export class ArithmeticMeasureBuilder extends MeasureBuilderBase {
+ constructor(measureIdentifiers: string[], operator: VisualizationObject.ArithmeticMeasureOperator) {
+ super();
+ this.measure.definition = {
+ arithmeticMeasure: {
+ measureIdentifiers,
+ operator
+ }
+ };
+ }
+}
+
+export class PoPMeasureBuilder extends MeasureBuilderBase {
+ constructor(measureIdentifier: string, popAttribute: string) {
+ super();
+ this.measure.definition = {
+ popMeasureDefinition: {
+ measureIdentifier,
+ popAttribute: getQualifierObject(popAttribute)
+ }
+ };
+ }
+}
+
+export class PreviousPeriodMeasureBuilder
+ extends MeasureBuilderBase {
+ constructor(measureIdentifier: string, dateDataSets: IPreviousPeriodDateDataSetSimple[]) {
+ super();
+ this.measure.definition = {
+ previousPeriodMeasure: {
+ measureIdentifier,
+ dateDataSets: dateDataSets.map((d): VisualizationObject.IPreviousPeriodDateDataSet =>
+ ({
+ ...d,
+ dataSet: typeof (d.dataSet) === 'string'
+ ? getQualifierObject(d.dataSet)
+ : d.dataSet
+ }))
+ }
+ };
+ }
+}
+
+export const measure = (identifier: string) => new MeasureBuilder(identifier);
+
+export const arithmeticMeasure = (
+ measureIdentifiers: string[],
+ operator: VisualizationObject.ArithmeticMeasureOperator
+) => new ArithmeticMeasureBuilder(measureIdentifiers, operator);
+
+export const popMeasure = (measureIdentifier: string, popAttribute: string) =>
+ new PoPMeasureBuilder(measureIdentifier, popAttribute);
+
+export const previousPeriodMeasure = (
+ measureIdentifier: string,
+ dateDataSets: IPreviousPeriodDateDataSetSimple[] = []
+) => new PreviousPeriodMeasureBuilder(measureIdentifier, dateDataSets);
diff --git a/src/helpers/bucketApi/sortBy.ts b/src/helpers/bucketApi/sortBy.ts
new file mode 100644
index 0000000000..d97bfa1e36
--- /dev/null
+++ b/src/helpers/bucketApi/sortBy.ts
@@ -0,0 +1,50 @@
+// (C) 2018 GoodData Corporation
+import { AFM } from '@gooddata/typings';
+
+export class AttributeSortItemBuilder implements AFM.IAttributeSortItem {
+ public attributeSortItem: AFM.IAttributeSortItem['attributeSortItem'];
+
+ constructor(attributeIdentifier: string, direction: AFM.SortDirection) {
+ this.attributeSortItem = {
+ attributeIdentifier,
+ direction
+ };
+ }
+
+ public aggregation = (aggregation: 'sum') => {
+ this.attributeSortItem.aggregation = aggregation;
+ return this;
+ }
+}
+
+export class MeasureSortItemBuilder implements AFM.IMeasureSortItem {
+ public measureSortItem: AFM.IMeasureSortItem['measureSortItem'];
+
+ constructor(measureIdentifier: AFM.Identifier, direction: AFM.SortDirection) {
+ this.measureSortItem = {
+ direction,
+ locators: [{
+ measureLocatorItem: {
+ measureIdentifier
+ }
+ }]
+ };
+ }
+
+ public attributeLocators = (...attributeLocators: Array) => {
+ this.measureSortItem.locators.splice(
+ -2,
+ 0,
+ ...attributeLocators.map(attributeLocatorItem => ({
+ attributeLocatorItem
+ }))
+ );
+ return this;
+ }
+}
+
+export const attributeSortItem = (attributeIdentifier: string, direction: AFM.SortDirection) =>
+ new AttributeSortItemBuilder(attributeIdentifier, direction);
+
+export const measureSortItem = (measureIdentifier: AFM.Identifier, direction: AFM.SortDirection) =>
+ new MeasureSortItemBuilder(measureIdentifier, direction);
diff --git a/src/helpers/bucketApi/tests/attributes.spec.ts b/src/helpers/bucketApi/tests/attributes.spec.ts
new file mode 100644
index 0000000000..caaf2befdb
--- /dev/null
+++ b/src/helpers/bucketApi/tests/attributes.spec.ts
@@ -0,0 +1,44 @@
+// (C) 2018 GoodData Corporation
+import { VisualizationObject } from '@gooddata/typings';
+import { visualizationAttribute } from '../attributes';
+
+describe('Attributes', () => {
+ describe('visualizationAttribute', () => {
+ it('should return a simple attribute', () => {
+ const expected: VisualizationObject.IVisualizationAttribute = {
+ visualizationAttribute: {
+ displayForm: {
+ identifier: 'foo'
+ },
+ localIdentifier: 'va_0'
+ }
+ };
+ expect(visualizationAttribute('foo')).toMatchObject(expected);
+ });
+
+ it('should return a simple attribute with alias', () => {
+ const expected: VisualizationObject.IVisualizationAttribute = {
+ visualizationAttribute: {
+ alias: 'alias',
+ displayForm: {
+ identifier: 'foo'
+ },
+ localIdentifier: 'va_1'
+ }
+ };
+ expect(visualizationAttribute('foo').alias('alias')).toMatchObject(expected);
+ });
+
+ it('should return a simple attribute with custom localIdentifier', () => {
+ const expected: VisualizationObject.IVisualizationAttribute = {
+ visualizationAttribute: {
+ displayForm: {
+ identifier: 'foo'
+ },
+ localIdentifier: 'custom'
+ }
+ };
+ expect(visualizationAttribute('foo').localIdentifier('custom')).toMatchObject(expected);
+ });
+ });
+});
diff --git a/src/helpers/bucketApi/tests/filters.spec.ts b/src/helpers/bucketApi/tests/filters.spec.ts
new file mode 100644
index 0000000000..f1c3ac4564
--- /dev/null
+++ b/src/helpers/bucketApi/tests/filters.spec.ts
@@ -0,0 +1,59 @@
+// (C) 2018 GoodData Corporation
+import { absoluteDateFilter, negativeAttributeFilter, positiveAttributeFilter, relativeDateFilter } from '../filters';
+
+describe('Filters', () => {
+ describe('positiveAttributeFilter', () => {
+ it('should generate correct filter', () => {
+ expect(positiveAttributeFilter('foo', ['bar', 'baz'])).toEqual({
+ positiveAttributeFilter: {
+ displayForm: {
+ identifier: 'foo'
+ },
+ in: ['bar', 'baz']
+ }
+ });
+ });
+ });
+
+ describe('negativeAttributeFilter', () => {
+ it('should generate correct filter', () => {
+ expect(negativeAttributeFilter('foo', ['bar', 'baz'])).toEqual({
+ negativeAttributeFilter: {
+ displayForm: {
+ identifier: 'foo'
+ },
+ notIn: ['bar', 'baz']
+ }
+ });
+ });
+ });
+
+ describe('absoluteDateFilter', () => {
+ it('should generate correct filter', () => {
+ expect(absoluteDateFilter('foo', '2018-01-01', '2018-12-31')).toEqual({
+ absoluteDateFilter: {
+ dataSet: {
+ identifier: 'foo'
+ },
+ from: '2018-01-01',
+ to: '2018-12-31'
+ }
+ });
+ });
+ });
+
+ describe('relativeDateFilter', () => {
+ it('should generate correct filter', () => {
+ expect(relativeDateFilter('foo', 'quarter', 1, 3)).toEqual({
+ relativeDateFilter: {
+ dataSet: {
+ identifier: 'foo'
+ },
+ granularity: 'quarter',
+ from: 1,
+ to: 3
+ }
+ });
+ });
+ });
+});
diff --git a/src/helpers/bucketApi/tests/measures.spec.ts b/src/helpers/bucketApi/tests/measures.spec.ts
new file mode 100644
index 0000000000..99992657c2
--- /dev/null
+++ b/src/helpers/bucketApi/tests/measures.spec.ts
@@ -0,0 +1,152 @@
+// (C) 2018 GoodData Corporation
+import { positiveAttributeFilter } from '../filters';
+import { measure, arithmeticMeasure, popMeasure, previousPeriodMeasure } from '../measures';
+
+describe('Measures', () => {
+ describe('measure', () => {
+ it('should return a simple measure', () => {
+ const expected = {
+ measure: {
+ definition: {
+ measureDefinition: {
+ item: {
+ identifier: 'foo'
+ }
+ }
+ }
+ }
+ };
+ expect(measure('foo')).toMatchObject(expected);
+ });
+ it('should return a measure with alias', () => {
+ const expected = {
+ measure: {
+ alias: 'bar',
+ definition: {
+ measureDefinition: {
+ item: {
+ identifier: 'foo'
+ }
+ }
+ }
+ }
+ };
+ expect(measure('foo').alias('bar')).toMatchObject(expected);
+ });
+ it('should return a measure with custom localIdentifier', () => {
+ const expected = {
+ measure: {
+ definition: {
+ measureDefinition: {
+ item: {
+ identifier: 'foo'
+ }
+ }
+ },
+ localIdentifier: 'custom'
+ }
+ };
+ expect(measure('foo').localIdentifier('custom')).toMatchObject(expected);
+ });
+ it('should return a measure with format', () => {
+ const expected = {
+ measure: {
+ definition: {
+ measureDefinition: {
+ item: {
+ identifier: 'foo'
+ }
+ }
+ },
+ format: 'bar'
+ }
+ };
+ expect(measure('foo').format('bar')).toMatchObject(expected);
+ });
+ it('should return a measure with a filter', () => {
+ const expected = {
+ measure: {
+ definition: {
+ measureDefinition: {
+ item: {
+ identifier: 'foo'
+ },
+ filters: [{
+ positiveAttributeFilter: {
+ displayForm: {
+ identifier: 'filter'
+ },
+ in: ['baz']
+ }
+ }]
+ }
+ }
+ }
+ };
+ expect(measure('foo').filters(positiveAttributeFilter('filter', ['baz']))).toMatchObject(expected);
+ });
+ });
+
+ describe('arithmeticMeasure', () => {
+ it('should return a simple arithmetic measure', () => {
+ const expected = {
+ measure: {
+ definition: {
+ arithmeticMeasure: {
+ measureIdentifiers: ['foo'],
+ operator: 'sum'
+ }
+ }
+ }
+ };
+ expect(arithmeticMeasure(['foo'], 'sum')).toMatchObject(expected);
+ });
+ });
+
+ describe('popMeasure', () => {
+ it('should return a simple PoP measure', () => {
+ const expected = {
+ measure: {
+ definition: {
+ popMeasureDefinition: {
+ measureIdentifier: 'foo',
+ popAttribute: { identifier: 'attr' }
+ }
+ }
+ }
+ };
+ expect(popMeasure('foo', 'attr')).toMatchObject(expected);
+ });
+ });
+
+ describe('previousPeriodMeasure', () => {
+ it('should return a simple PoP measure when supplied with ObjectQualifiers', () => {
+ const expected = {
+ measure: {
+ definition: {
+ previousPeriodMeasure: {
+ measureIdentifier: 'foo',
+ dateDataSets: [{ dataSet: { identifier: 'bar' }, periodsAgo: 3 }]
+ }
+ }
+ }
+ };
+ expect(previousPeriodMeasure('foo', [{ dataSet: { identifier: 'bar' }, periodsAgo: 3 }]))
+ .toMatchObject(expected);
+ });
+ it('should return a simple PoP measure when supplied with strings', () => {
+ const expected = {
+ measure: {
+ definition: {
+ previousPeriodMeasure: {
+ measureIdentifier: 'foo',
+ dateDataSets: [{ dataSet: { identifier: 'bar' }, periodsAgo: 3 }]
+ }
+ }
+ }
+ };
+ expect(previousPeriodMeasure('foo', [{ dataSet: 'bar', periodsAgo: 3 }]))
+ .toMatchObject(expected);
+ });
+ });
+});
diff --git a/src/helpers/bucketApi/tests/sortBy.spec.ts b/src/helpers/bucketApi/tests/sortBy.spec.ts
new file mode 100644
index 0000000000..4438d38bc0
--- /dev/null
+++ b/src/helpers/bucketApi/tests/sortBy.spec.ts
@@ -0,0 +1,69 @@
+// (C) 2018 GoodData Corporation
+import { AFM } from '@gooddata/typings';
+import { attributeSortItem, measureSortItem } from '../sortBy';
+
+describe('SortBy', () => {
+ describe('attributeSortItem', () => {
+ it('should return a simple sort item', () => {
+ const expected: AFM.IAttributeSortItem = {
+ attributeSortItem: {
+ attributeIdentifier: 'foo',
+ direction: 'asc'
+ }
+ };
+ expect(attributeSortItem('foo', 'asc')).toMatchObject(expected);
+ });
+
+ it('should return a simple sort item with aggregation', () => {
+ const expected: AFM.IAttributeSortItem = {
+ attributeSortItem: {
+ attributeIdentifier: 'foo',
+ direction: 'asc',
+ aggregation: 'sum'
+ }
+ };
+ expect(attributeSortItem('foo', 'asc').aggregation('sum')).toMatchObject(expected);
+ });
+ });
+
+ describe('measureSortItem', () => {
+ it('should return a simple sort item', () => {
+ const expected: AFM.IMeasureSortItem = {
+ measureSortItem: {
+ direction: 'asc',
+ locators: [{
+ measureLocatorItem: {
+ measureIdentifier: 'foo'
+ }
+ }]
+ }
+ };
+ expect(measureSortItem('foo', 'asc')).toMatchObject(expected);
+ });
+
+ it('should return a simple sort item', () => {
+ const expected: AFM.IMeasureSortItem = {
+ measureSortItem: {
+ direction: 'asc',
+ locators: [
+ {
+ attributeLocatorItem: {
+ attributeIdentifier: 'attr',
+ element: 'elem'
+ }
+ },
+ {
+ measureLocatorItem: {
+ measureIdentifier: 'foo'
+ }
+ }
+ ]
+ }
+ };
+ expect(
+ measureSortItem('foo', 'asc')
+ .attributeLocators({ attributeIdentifier: 'attr', element: 'elem' })
+ ).toMatchObject(expected);
+ });
+ });
+});
diff --git a/src/helpers/bucketApi/utils.ts b/src/helpers/bucketApi/utils.ts
new file mode 100644
index 0000000000..d88b1604c1
--- /dev/null
+++ b/src/helpers/bucketApi/utils.ts
@@ -0,0 +1,14 @@
+// (C) 2018 GoodData Corporation
+import { VisualizationObject } from '@gooddata/typings';
+import { DataLayer } from '@gooddata/gooddata-js';
+
+const { Uri: { isUri } } = DataLayer;
+
+export const getQualifierObject = (qualifierString: string): VisualizationObject.ObjQualifier =>
+ isUri(qualifierString)
+ ? {
+ uri: qualifierString
+ }
+ : {
+ identifier: qualifierString
+ };
diff --git a/src/index.ts b/src/index.ts
index e61fbdc108..1f433854ea 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -3,6 +3,7 @@ import * as AfmComponents from './components/afm/afmComponents';
import * as VisEvents from './interfaces/Events';
import CatalogHelper from './helpers/CatalogHelper';
import { isEmptyResult } from './helpers/errorHandlers';
+import * as BucketApi from './helpers/bucketApi';
import { BaseChart as CoreBaseChart, IBaseChartProps } from './components/core/base/BaseChart';
import { Table as CoreTable } from './components/core/Table';
import { Headline as CoreHeadline } from './components/core/Headline';
@@ -81,6 +82,7 @@ export {
AttributeElements,
AttributeFilter,
BarChart,
+ BucketApi,
BucketNames,
CatalogHelper,
ChartType,
diff --git a/stories/data/componentProps.ts b/stories/data/componentProps.ts
index bf8f0aab7d..3bd379e788 100644
--- a/stories/data/componentProps.ts
+++ b/stories/data/componentProps.ts
@@ -1,89 +1,34 @@
// (C) 2007-2018 GoodData Corporation
import { VisualizationObject, AFM } from '@gooddata/typings';
-
-export const MEASURE_1: VisualizationObject.IMeasure = {
- measure: {
- localIdentifier: 'm1',
- definition: {
- measureDefinition: {
- item: {
- uri: '/gdc/md/storybook/obj/1'
- }
- }
- }
- }
-};
-
-export const MEASURE_2: VisualizationObject.IMeasure = {
- measure: {
- localIdentifier: 'm2',
- definition: {
- measureDefinition: {
- item: {
- uri: '/gdc/md/storybook/obj/2'
- }
- }
- }
- }
-};
-
-export const MEASURE_AM_1_2: VisualizationObject.IMeasure = {
- measure: {
- localIdentifier: 'am1',
- definition: {
- arithmeticMeasure: {
- measureIdentifiers: ['m1', 'm2'],
- operator: 'sum'
- }
- }
- }
-};
-
-export const MEASURE_3: VisualizationObject.IMeasure = {
- measure: {
- localIdentifier: 'm3',
- definition: {
- measureDefinition: {
- item: {
- uri: '/gdc/md/storybook/obj/3'
- }
- }
- }
- }
-};
-
-export const MEASURE_1_POP: VisualizationObject.IMeasure = {
- measure: {
- localIdentifier: 'm1_pop',
- definition: {
- popMeasureDefinition: {
- measureIdentifier: 'm1',
- popAttribute: {
- uri: '/gdc/md/storybook/obj/3.df'
- }
- }
- },
- alias: 'Previous period'
- }
-};
-
-export const MEASURE_1_PREVIOUS_PERIOD: VisualizationObject.IMeasure = {
- measure: {
- localIdentifier: 'm1_previous_period',
- definition: {
- previousPeriodMeasure: {
- measureIdentifier: 'm1',
- dateDataSets: [{
- dataSet: {
- uri: '/gdc/md/storybook/obj/3.df'
- },
- periodsAgo: 1
- }]
- }
- },
- alias: 'Previous period'
- }
-};
+import {
+ arithmeticMeasure,
+ attributeSortItem,
+ measureSortItem,
+ popMeasure,
+ previousPeriodMeasure,
+ measure,
+ visualizationAttribute
+} from '../../src/helpers/bucketApi';
+
+export const MEASURE_1: VisualizationObject.IMeasure = measure('/gdc/md/storybook/obj/1').localIdentifier('m1');
+export const MEASURE_2: VisualizationObject.IMeasure = measure('/gdc/md/storybook/obj/2').localIdentifier('m2');
+export const MEASURE_3: VisualizationObject.IMeasure = measure('/gdc/md/storybook/obj/3').localIdentifier('m3');
+
+export const MEASURE_AM_1_2: VisualizationObject.IMeasure = arithmeticMeasure(['m1', 'm2'], 'sum')
+ .localIdentifier('am1');
+
+export const MEASURE_1_POP: VisualizationObject.IMeasure = popMeasure('m1', '/gdc/md/storybook/obj/3.df')
+ .localIdentifier('m1_pop')
+ .alias('Previous period');
+
+export const MEASURE_1_PREVIOUS_PERIOD: VisualizationObject.IMeasure = previousPeriodMeasure('m1', [{
+ dataSet: {
+ uri: '/gdc/md/storybook/obj/3.df'
+ },
+ periodsAgo: 1
+}])
+ .localIdentifier('m1_previous_period')
+ .alias('Previous period');
export const MEASURE_1_WITH_ALIAS: VisualizationObject.IMeasure = {
measure: {
@@ -92,112 +37,41 @@ export const MEASURE_1_WITH_ALIAS: VisualizationObject.IMeasure = {
}
};
-export const MEASURE_WITH_FORMAT: VisualizationObject.IMeasure = {
- measure: {
- localIdentifier: 'm3',
- definition: {
- measureDefinition: {
- item: {
- uri: '/gdc/md/storybook/obj/4'
- }
- }
- }
- }
-};
+export const MEASURE_WITH_FORMAT: VisualizationObject.IMeasure = measure('/gdc/md/storybook/obj/4')
+ .localIdentifier('m3');
-export const MEASURE_2_WITH_FORMAT: VisualizationObject.IMeasure = {
- measure: {
- localIdentifier: 'm2',
- definition: {
- measureDefinition: {
- item: {
- uri: '/gdc/md/storybook/obj/2'
- }
- }
- },
- format: '[backgroundColor=ffff00][green]#,##0.00 €'
- }
-};
+export const MEASURE_2_WITH_FORMAT: VisualizationObject.IMeasure = measure('/gdc/md/storybook/obj/2')
+ .localIdentifier('m2')
+ .format('[backgroundColor=ffff00][green]#,##0.00 €');
-export const MEASURE_WITH_NULLS: VisualizationObject.IMeasure = {
- measure: {
- localIdentifier: 'm4',
- definition: {
- measureDefinition: {
- item: {
- uri: '/gdc/md/storybook/obj/9'
- }
- }
- }
- }
-};
+export const MEASURE_WITH_NULLS: VisualizationObject.IMeasure = measure('/gdc/md/storybook/obj/9')
+ .localIdentifier('m4');
-export const ARITHMETIC_MEASURE_SIMPLE_OPERANDS: VisualizationObject.IMeasure = {
- measure: {
- localIdentifier: 'arithmetic_measure_1',
- definition: {
- arithmeticMeasure: {
- measureIdentifiers: ['m1', 'm2'],
- operator: 'sum'
- }
- },
- alias: 'Sum of m1 and m2'
- }
-};
+export const ARITHMETIC_MEASURE_SIMPLE_OPERANDS: VisualizationObject.IMeasure = arithmeticMeasure(['m1', 'm2'], 'sum')
+ .localIdentifier('arithmetic_measure_1')
+ .alias('Sum of m1 and m2');
-export const ARITHMETIC_MEASURE_USING_ARITHMETIC: VisualizationObject.IMeasure = {
- measure: {
- localIdentifier: 'arithmetic_measure_2',
- definition: {
- arithmeticMeasure: {
- measureIdentifiers: ['arithmetic_measure_1', 'm2'],
- operator: 'difference'
- }
- },
- alias: 'Difference of arithmetic_measure_1 and m2'
- }
-};
+export const ARITHMETIC_MEASURE_USING_ARITHMETIC: VisualizationObject.IMeasure =
+ arithmeticMeasure(['arithmetic_measure_1', 'm2'], 'difference')
+ .localIdentifier('arithmetic_measure_2')
+ .alias('Difference of arithmetic_measure_1 and m2');
-export const FORMATTED_ARITHMETIC_MEASURE: VisualizationObject.IMeasure = {
- measure: {
- localIdentifier: 'arithmetic_measure_3',
- definition: {
- arithmeticMeasure: {
- measureIdentifiers: ['m1', 'm2'],
- operator: 'sum'
- }
- },
- format: '[backgroundColor=ffff00][green]#,##0.00 €',
- alias: 'Formatted sum of m1 and m2'
- }
-};
+export const FORMATTED_ARITHMETIC_MEASURE: VisualizationObject.IMeasure = arithmeticMeasure(['m1', 'm2'], 'sum')
+ .localIdentifier('arithmetic_measure_3')
+ .format('[backgroundColor=ffff00][green]#,##0.00 €')
+ .alias('Formatted sum of m1 and m2');
-export const ATTRIBUTE_1: VisualizationObject.IVisualizationAttribute = {
- visualizationAttribute: {
- localIdentifier: 'a1',
- displayForm: {
- uri: '/gdc/md/storybook/obj/4.df'
- }
- }
-};
+export const ATTRIBUTE_1: VisualizationObject.IVisualizationAttribute =
+ visualizationAttribute('/gdc/md/storybook/obj/4.df')
+ .localIdentifier('a1');
-export const ATTRIBUTE_COUNTRY: VisualizationObject.IVisualizationAttribute = {
- visualizationAttribute: {
- localIdentifier: 'country',
- displayForm: {
- uri: '/gdc/md/storybook/obj/3.df'
- }
- }
-};
+export const ATTRIBUTE_COUNTRY: VisualizationObject.IVisualizationAttribute =
+ visualizationAttribute('/gdc/md/storybook/obj/3.df')
+ .localIdentifier('country');
-export const ATTRIBUTE_POPULARITY: VisualizationObject.IVisualizationAttribute = {
- visualizationAttribute: {
- localIdentifier: 'Popularity',
- displayForm: {
- uri: '/gdc/md/storybook/obj/5.df'
- }
- }
-};
+export const ATTRIBUTE_POPULARITY: VisualizationObject.IVisualizationAttribute =
+ visualizationAttribute('/gdc/md/storybook/obj/5.df')
+ .localIdentifier('Popularity');
export const ATTRIBUTE_1_WITH_ALIAS: VisualizationObject.IVisualizationAttribute = {
visualizationAttribute: {
@@ -206,23 +80,13 @@ export const ATTRIBUTE_1_WITH_ALIAS: VisualizationObject.IVisualizationAttribute
}
};
-export const ATTRIBUTE_2: VisualizationObject.IVisualizationAttribute = {
- visualizationAttribute: {
- localIdentifier: 'a2',
- displayForm: {
- uri: '/gdc/md/storybook/obj/5.df'
- }
- }
-};
+export const ATTRIBUTE_2: VisualizationObject.IVisualizationAttribute =
+ visualizationAttribute('/gdc/md/storybook/obj/5.df')
+ .localIdentifier('a2');
-export const ATTRIBUTE_3: VisualizationObject.IVisualizationAttribute = {
- visualizationAttribute: {
- localIdentifier: 'a3',
- displayForm: {
- uri: '/gdc/md/storybook/obj/6.df'
- }
- }
-};
+export const ATTRIBUTE_3: VisualizationObject.IVisualizationAttribute =
+ visualizationAttribute('/gdc/md/storybook/obj/6.df')
+ .localIdentifier('a3');
export const TOTAL_M1_A1: VisualizationObject.IVisualizationTotal = {
measureIdentifier: MEASURE_1.measure.localIdentifier,
@@ -236,20 +100,7 @@ export const TOTAL_M2_A1: VisualizationObject.IVisualizationTotal = {
attributeIdentifier: ATTRIBUTE_1.visualizationAttribute.localIdentifier
};
-export const ATTRIBUTE_1_SORT_ITEM: AFM.IAttributeSortItem = {
- attributeSortItem: {
- direction: 'asc',
- attributeIdentifier: ATTRIBUTE_1.visualizationAttribute.localIdentifier
- }
-};
+export const ATTRIBUTE_1_SORT_ITEM: AFM.IAttributeSortItem =
+ attributeSortItem(ATTRIBUTE_1.visualizationAttribute.localIdentifier, 'asc');
-export const MEASURE_2_SORT_ITEM: AFM.IMeasureSortItem = {
- measureSortItem: {
- direction: 'asc',
- locators: [{
- measureLocatorItem: {
- measureIdentifier: MEASURE_2.measure.localIdentifier
- }
- }]
- }
-};
+export const MEASURE_2_SORT_ITEM: AFM.IMeasureSortItem = measureSortItem(MEASURE_2.measure.localIdentifier, 'asc');