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

feat: add calendar package and storybook #356

Merged
merged 4 commits into from
Apr 11, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@
"globals": {
"caches": true
},
"coverageThreshold": {
"global": {
"branches": 25,
"functions": 25,
"lines": 25,
"statements": 25
}
},
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less)$": "identity-obj-proxy"
Expand Down
31 changes: 31 additions & 0 deletions packages/superset-ui-demo/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { addParameters, addDecorator } from '@storybook/react';
import { jsxDecorator } from 'storybook-addon-jsx';
import categoricalD3 from '@superset-ui/color/esm/colorSchemes/categorical/d3';
import sequentialCommon from '@superset-ui/color/esm/colorSchemes/sequential/common';
import sequentialD3 from '@superset-ui/color/esm/colorSchemes/sequential/d3';
import { configure } from '@superset-ui/translation';
import { getCategoricalSchemeRegistry, getSequentialSchemeRegistry } from '@superset-ui/color';
import { getTimeFormatterRegistry, smartDateFormatter } from '@superset-ui/time-format';

import 'bootstrap/dist/css/bootstrap.min.css';
import './storybook.css';
Expand All @@ -26,3 +32,28 @@ addParameters({
},
},
});

// Superset setup

configure();

// Register color schemes
const categoricalSchemeRegistry = getCategoricalSchemeRegistry();
[categoricalD3].forEach(group => {
group.forEach(scheme => {
categoricalSchemeRegistry.registerValue(scheme.id, scheme);
});
});
categoricalSchemeRegistry.setDefaultKey('d3Category10');

const sequentialSchemeRegistry = getSequentialSchemeRegistry();
[sequentialCommon, sequentialD3].forEach(group => {
group.forEach(scheme => {
sequentialSchemeRegistry.registerValue(scheme.id, scheme);
});
});

getTimeFormatterRegistry()
.registerValue('smart_date', smartDateFormatter)
.setDefaultKey('smart_date');

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default { verboseMap: {} };
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function withNulls(origData: object[], nullPosition: number = 3) {
}

export default {
title: 'Legacy Preset|big-number',
title: 'Legacy Chart Presets|big-number',
};

export const basicWithTrendline = () => (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint-disable sort-keys, no-magic-numbers */
import React from 'react';
import { SuperChart } from '@superset-ui/chart';
import CalendarChartPlugin from '../../../../../../plugins/legacy-plugin-chart-calendar';
import data from './data';
// eslint-disable-next-line import/extensions
import dummyDatasource from '../../../shared/dummyDatasource';

new CalendarChartPlugin().configure({ key: 'calendar' }).register();

export default {
title: 'Legacy Chart Plugins|CalendarChartPlugin',
};

export const basic = () => (
<SuperChart
chartType="calendar"
width={400}
height={400}
datasource={dummyDatasource}
queryData={{ data }}
formData={{
cellSize: 10,
cellPadding: 2,
cellRadius: 0,
linearColorScheme: 'schemeRdYlBu',
steps: 10,
yAxisFormat: '.3s',
xAxisTimeFormat: 'smart_date',
showLegend: true,
showValues: false,
showMetricName: true,
}}
/>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* eslint-disable sort-keys */
export default {
data: {
count: {
'1518652800.0': 3,
'1518048000.0': 2,
'1518220800.0': 2,
'1523145600.0': 2,
'1529798400.0': 2,
'1534204800.0': 2,
'1541289600.0': 2,
'1542672000.0': 2,
'1543881600.0': 2,
'1517616000.0': 1,
'1517875200.0': 1,
'1517961600.0': 1,
'1518307200.0': 1,
'1518393600.0': 1,
'1519257600.0': 1,
'1519516800.0': 1,
'1519776000.0': 1,
'1520208000.0': 1,
'1520294400.0': 1,
'1520985600.0': 1,
'1521072000.0': 1,
'1521244800.0': 1,
'1521331200.0': 1,
'1521676800.0': 1,
'1522108800.0': 1,
'1522627200.0': 1,
'1522800000.0': 1,
'1522972800.0': 1,
'1523491200.0': 1,
'1524096000.0': 1,
'1524268800.0': 1,
'1524614400.0': 1,
'1524960000.0': 1,
'1525305600.0': 1,
'1525564800.0': 1,
'1525737600.0': 1,
'1525824000.0': 1,
'1525910400.0': 1,
'1526083200.0': 1,
'1526256000.0': 1,
'1526688000.0': 1,
'1527033600.0': 1,
'1527292800.0': 1,
'1527465600.0': 1,
'1527638400.0': 1,
'1528070400.0': 1,
'1528329600.0': 1,
'1529539200.0': 1,
'1529625600.0': 1,
'1529712000.0': 1,
'1529971200.0': 1,
'1530144000.0': 1,
'1530576000.0': 1,
'1531267200.0': 1,
'1531353600.0': 1,
'1531440000.0': 1,
'1532736000.0': 1,
'1533081600.0': 1,
'1533168000.0': 1,
'1533945600.0': 1,
'1534377600.0': 1,
'1534809600.0': 1,
'1535155200.0': 1,
'1535328000.0': 1,
'1535932800.0': 1,
'1536710400.0': 1,
'1537056000.0': 1,
'1537142400.0': 1,
'1537488000.0': 1,
'1537660800.0': 1,
'1538611200.0': 1,
'1538697600.0': 1,
'1539475200.0': 1,
'1540771200.0': 1,
'1541116800.0': 1,
'1541376000.0': 1,
'1541635200.0': 1,
'1542153600.0': 1,
'1542931200.0': 1,
'1543190400.0': 1,
'1545177600.0': 1,
'1545436800.0': 1,
'1545782400.0': 1,
'1545868800.0': 1,
'1546300800.0': 1,
'1546732800.0': 1,
'1547769600.0': 1,
'1547942400.0': 1,
'1548633600.0': 1,
},
},
start: 1517270400000.0,
domain: 'month',
range: 13,
subdomain: 'day',
};
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function loadData(props: SuperChartProps, pageSize = 50, targetSize = 2042) {
}

export default {
title: 'Legacy Plugin|table',
title: 'Legacy Chart Plugins|table',
};

export const basic = () => (
Expand Down
32 changes: 32 additions & 0 deletions plugins/legacy-plugin-chart-calendar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## @superset-ui/legacy-plugin-chart-calendar

[![Version](https://img.shields.io/npm/v/@superset-ui/legacy-plugin-chart-calendar.svg?style=flat-square)](https://img.shields.io/npm/v/@superset-ui/legacy-plugin-chart-calendar.svg?style=flat-square)
[![David (path)](https://img.shields.io/david/apache-superset/superset-ui-plugins.svg?path=packages%2Fsuperset-ui-legacy-plugin-chart-calendar&style=flat-square)](https://david-dm.org/apache-superset/superset-ui-plugins?path=packages/superset-ui-legacy-plugin-chart-calendar)

This plugin provides Calendar Heatmap for Superset.

### Usage

Configure `key`, which can be any `string`, and register the plugin. This `key` will be used to lookup this chart throughout the app.

```js
import CalendarChartPlugin from '@superset-ui/legacy-plugin-chart-calendar';

new CalendarChartPlugin()
.configure({ key: 'calendar' })
.register();
```

Then use it via `SuperChart`. See [storybook](https://apache-superset.github.io/superset-ui-plugins/?selectedKind=plugin-chart-calendar) for more details.

```js
<SuperChart
chartType="calendar"
width={600}
height={600}
formData={...}
queryData={{
data: {...},
}}
/>
```
43 changes: 43 additions & 0 deletions plugins/legacy-plugin-chart-calendar/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@superset-ui/legacy-plugin-chart-calendar",
"version": "0.11.15",
"description": "Superset Legacy Chart - Calendar Heatmap",
"sideEffects": [
"*.css"
],
"main": "lib/index.js",
"module": "esm/index.js",
"files": [
"esm",
"lib"
],
"repository": {
"type": "git",
"url": "git+https://github.com/apache-superset/superset-ui-plugins.git"
},
"keywords": [
"superset"
],
"author": "Superset",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/apache-superset/superset-ui-plugins/issues"
},
"homepage": "https://github.com/apache-superset/superset-ui-plugins#readme",
"publishConfig": {
"access": "public"
},
"dependencies": {
"d3-array": "^2.0.3",
"d3-selection": "^1.4.0",
"d3-tip": "^0.9.1",
"prop-types": "^15.6.2"
},
"peerDependencies": {
"@superset-ui/chart": "^0.12.0",
"@superset-ui/color": "^0.12.0",
"@superset-ui/number-format": "^0.12.0",
"@superset-ui/time-format": "^0.12.0",
"@superset-ui/translation": "^0.12.0"
}
}
29 changes: 29 additions & 0 deletions plugins/legacy-plugin-chart-calendar/src/Calendar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

.superset-legacy-chart-calendar {
padding: 10px;
position: static !important;
overflow: auto !important;
}

.superset-legacy-chart-calendar .ch-tooltip {
margin-left: 20px;
margin-top: 5px;
}
Loading