Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud committed May 13, 2020
1 parent bde5206 commit 0cc5288
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const formData = {
metric: 'sum__SP_POP_TOTL',
showTrendLine: true,
startYAxisAtZero: true,
timeGrainSqla: 'P1Y',
vizType: 'big_number',
yAxisFormat: '.3s',
};
Expand Down Expand Up @@ -68,19 +69,29 @@ export const basicWithTrendline = () => (
/>
);

export const nullInTheMiddle = () => (
export const weeklyTimeGranularity = () => (
<SuperChart
chartType="big-number"
width={400}
height={400}
queryData={{ data: withNulls(testData, 3) }}
queryData={{ data: testData }}
formData={{
...formData,
timeGrainSqla: 'P1W', // weekly
timeGrainSqla: 'P1W',
}}
/>
);

export const nullInTheMiddle = () => (
<SuperChart
chartType="big-number"
width={400}
height={400}
queryData={{ data: withNulls(testData, 3) }}
formData={formData}
/>
);

export const fixedRange = () => (
<SuperChart
chartType="big-number"
Expand All @@ -93,7 +104,6 @@ export const fixedRange = () => (
}}
formData={{
...formData,
timeGrainSqla: 'P1Y',
timeRangeFixed: true,
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import TimeFormats from '../TimeFormats';
import { getTimeFormatter } from '../TimeFormatterRegistrySingleton';
import smartDateVerboseFormatter from '../formatters/smartDateVerbose';
import { TimeGranularity } from '../types';

// Translate time granularity to d3-format
const MINUTE = '%Y-%m-%d %H:%M';
Expand Down Expand Up @@ -47,23 +48,6 @@ const formats = {
'P1W/1970-01-04T00:00:00Z': MONDAY_BASED_WEEK, // 'week_ending_sunday'
};

export type TimeGranularity =
| 'date'
| 'PT1S'
| 'PT1M'
| 'PT5M'
| 'PT10M'
| 'PT15M'
| 'PT0.5H'
| 'PT1H'
| 'P1D'
| 'P1W'
| 'P0.25Y'
| 'P1Y'
| '1969-12-28T00:00:00Z/P1W'
| '1969-12-29T00:00:00Z/P1W'
| 'P1W/1970-01-03T00:00:00Z';

export default function getTimeFormatterForGranularity(granularity?: TimeGranularity) {
return granularity && granularity in formats
? getTimeFormatter(formats[granularity])
Expand Down
7 changes: 3 additions & 4 deletions packages/superset-ui-time-format/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ export {

export { default as createD3TimeFormatter } from './factories/createD3TimeFormatter';
export { default as createMultiFormatter } from './factories/createMultiFormatter';
export {
default as getTimeFormatterForGranularity,
TimeGranularity,
} from './factories/getTimeFormatterForGranularity';
export { default as getTimeFormatterForGranularity } from './factories/getTimeFormatterForGranularity';

export { default as smartDateFormatter } from './formatters/smartDate';
export { default as smartDateVerboseFormatter } from './formatters/smartDateVerbose';

export * from './types';
17 changes: 17 additions & 0 deletions packages/superset-ui-time-format/src/types.ts
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
export type TimeFormatFunction = (value: Date) => string;

export type TimeGranularity =
| 'date'
| 'PT1S'
| 'PT1M'
| 'PT5M'
| 'PT10M'
| 'PT15M'
| 'PT0.5H'
| 'PT1H'
| 'P1D'
| 'P1W'
| 'P0.25Y'
| 'P1Y'
| '1969-12-28T00:00:00Z/P1W'
| '1969-12-29T00:00:00Z/P1W'
| 'P1W/1970-01-03T00:00:00Z';

0 comments on commit 0cc5288

Please sign in to comment.