Skip to content

Commit

Permalink
FEATURE: RAIL-763 add BucketApi helpers and use them in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
no23reason committed Dec 19, 2018
1 parent cf83a6a commit f5b96ce
Show file tree
Hide file tree
Showing 48 changed files with 1,080 additions and 1,888 deletions.
71 changes: 10 additions & 61 deletions examples/src/components/AreaChartExample.jsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -26,68 +26,17 @@ export class AreaChartExample 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 (
<div style={{ height: 300 }} className="s-area-chart">
Expand Down
52 changes: 17 additions & 35 deletions examples/src/components/ArithmeticMeasureChangeExample.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (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';

Expand All @@ -11,10 +11,6 @@ import {
monthDateDataSetAttributeIdentifier,
totalSalesIdentifier
} from '../utils/fixtures';
import {
createMeasureBucketItem,
createSamePeriodMeasureBucketItem
} from '../utils/helpers';

export class ArithmeticMeasureChangeExample extends Component {
onLoadingChanged(...params) {
Expand All @@ -28,42 +24,28 @@ export class ArithmeticMeasureChangeExample extends Component {
}

render() {
const totalSalesYearAgoBucketItem = createSamePeriodMeasureBucketItem(
'totalSales', monthDateDataSetAttributeIdentifier, '$ Total Sales - year ago'
);
const totalSalesBucketItem = createMeasureBucketItem(
totalSalesIdentifier, 'totalSales', '$ Total Sales'
);
const totalSalesYearAgoBucketItem = BucketApi.previousPeriodMeasure(
'totalSales', [{ dataSet: monthDateDataSetAttributeIdentifier, periodsAgo: 1 }]
).alias('$ Total Sales - year ago').localIdentifier('totalSales_sp');

const totalSalesBucketItem = BucketApi.measure(totalSalesIdentifier)
.localIdentifier('totalSales')
.alias('$ Total Sales');

const measures = [
totalSalesYearAgoBucketItem,
totalSalesBucketItem,
{
measure: {
localIdentifier: 'totalSalesChange',
title: '% Total Sales Change',
definition: {
arithmeticMeasure: {
measureIdentifiers: [
totalSalesBucketItem.measure.localIdentifier,
totalSalesYearAgoBucketItem.measure.localIdentifier
],
operator: 'change'
}
},
format: '#,##0%'
}
}
BucketApi.arithmeticMeasure([
totalSalesBucketItem.measure.localIdentifier,
totalSalesYearAgoBucketItem.measure.localIdentifier
], 'change')
.format('#,##0%')
.title('% Total Sales Change')
.localIdentifier('totalSalesChange')
];

const attributes = [
{
visualizationAttribute: {
displayForm: {
identifier: monthDateIdentifier
},
localIdentifier: 'month'
}
}
BucketApi.visualizationAttribute(monthDateIdentifier).localIdentifier('month')
];

return (
Expand Down
66 changes: 15 additions & 51 deletions examples/src/components/ArithmeticMeasureDrillingExample.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (C) 2007-2018 GoodData Corporation

import React, { Component } from 'react';
import { Table, HeaderPredicateFactory } from '@gooddata/react-components';
import { Table, HeaderPredicateFactory, BucketApi } from '@gooddata/react-components';

import '@gooddata/react-components/styles/css/main.css';

Expand Down Expand Up @@ -49,59 +49,23 @@ export class ArithmeticMeasureDrillingExample extends Component {
};

const measures = [
{
measure: {
localIdentifier: localIdentifiers.numberOfRestaurants,
definition: {
measureDefinition: {
item: {
identifier: numberOfRestaurantsIdentifier
}
}
},
format: '#,##0'
}
},
{
measure: {
localIdentifier: localIdentifiers.totalSales,
definition: {
measureDefinition: {
item: {
identifier: totalSalesIdentifier
}
}
},
format: '#,##0'
}
},
{
measure: {
localIdentifier: 'averageRestaurantSales',
title: '$ Avg Restaurant Sales',
definition: {
arithmeticMeasure: {
measureIdentifiers: [
localIdentifiers.totalSales,
localIdentifiers.numberOfRestaurants
],
operator: 'ratio'
}
},
format: '#,##0'
}
}
BucketApi.measure(numberOfRestaurantsIdentifier)
.localIdentifier(localIdentifiers.numberOfRestaurants)
.format('#,##0'),
BucketApi.measure(totalSalesIdentifier)
.localIdentifier(localIdentifiers.totalSales)
.format('#,##0'),
BucketApi.arithmeticMeasure([
localIdentifiers.totalSales,
localIdentifiers.numberOfRestaurants
], 'ratio')
.localIdentifier(localIdentifiers.averageRestaurantSales)
.format('#,##0')
.title('$ Avg Restaurant Sales')
];

const attributes = [
{
visualizationAttribute: {
displayForm: {
identifier: locationStateDisplayFormIdentifier
},
localIdentifier: 'month'
}
}
BucketApi.visualizationAttribute(locationStateDisplayFormIdentifier).localIdentifier('month')
];

const drillNotificationComponent = () => {
Expand Down
69 changes: 17 additions & 52 deletions examples/src/components/ArithmeticMeasureMultiplicationExample.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (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';

Expand All @@ -26,63 +26,28 @@ export class ArithmeticMeasureMultiplicationExample extends Component {
render() {
const localIdentifiers = {
numberOfRestaurants: 'numberOfRestaurants',
averageRestaurantDailyCosts: 'averageRestaurantDailyCosts'
averageRestaurantDailyCosts: 'averageRestaurantDailyCosts',
averageStateDailyCosts: 'averageStateDailyCosts'
};

const measures = [
{
measure: {
localIdentifier: localIdentifiers.numberOfRestaurants,
definition: {
measureDefinition: {
item: {
identifier: numberOfRestaurantsIdentifier
}
}
},
format: '#,##0'
}
},
{
measure: {
localIdentifier: localIdentifiers.averageRestaurantDailyCosts,
definition: {
measureDefinition: {
item: {
identifier: averageRestaurantDailyCostsIdentifier
}
}
},
format: '#,##0'
}
},
{
measure: {
localIdentifier: 'averageStateDailyCosts',
title: '$ Avg State Daily Costs',
definition: {
arithmeticMeasure: {
measureIdentifiers: [
localIdentifiers.numberOfRestaurants,
localIdentifiers.averageRestaurantDailyCosts
],
operator: 'multiplication'
}
},
format: '#,##0'
}
}
BucketApi.measure(numberOfRestaurantsIdentifier)
.localIdentifier(localIdentifiers.numberOfRestaurants)
.format('#,##0'),
BucketApi.measure(averageRestaurantDailyCostsIdentifier)
.localIdentifier(localIdentifiers.averageRestaurantDailyCosts)
.format('#,##0'),
BucketApi.arithmeticMeasure([
localIdentifiers.numberOfRestaurants,
localIdentifiers.averageRestaurantDailyCosts
], 'multiplication')
.localIdentifier(localIdentifiers.averageStateDailyCosts)
.format('#,##0')
.title('$ Avg State Daily Costs')
];

const attributes = [
{
visualizationAttribute: {
displayForm: {
identifier: locationStateDisplayFormIdentifier
},
localIdentifier: 'month'
}
}
BucketApi.visualizationAttribute(locationStateDisplayFormIdentifier).localIdentifier('month')
];

return (
Expand Down
Loading

0 comments on commit f5b96ce

Please sign in to comment.