-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Period over Period Big Number comparison chart (#26908)
Co-authored-by: Fernando <[email protected]> Co-authored-by: Antonio Rivero <[email protected]>
- Loading branch information
1 parent
bd9afcd
commit a09e555
Showing
18 changed files
with
1,066 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
superset-frontend/plugins/plugin-chart-period-over-period-kpi/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/\*\* | ||
|
||
- 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. | ||
\*/ | ||
|
||
# custom-viz | ||
|
||
This plugin provides a BigNumber visualization with period over period time comparisons | ||
|
||
### Usage | ||
|
||
To build the plugin, run the following commands: | ||
|
||
``` | ||
npm ci | ||
npm run build | ||
``` | ||
|
||
Alternatively, to run the plugin in development mode (=rebuilding whenever changes are made), start the dev server with the following command: | ||
|
||
``` | ||
npm run dev | ||
``` | ||
|
||
To add the package to Superset, go to the `superset-frontend` subdirectory in your Superset source folder (assuming both the `custom-viz` plugin and `superset` repos are in the same root directory) and run | ||
|
||
``` | ||
npm i -S ../../plugin-chart-period-over-period-kpi | ||
``` | ||
|
||
If your Superset plugin exists in the `superset-frontend` directory and you wish to resolve TypeScript errors about `@superset-ui/core` not being resolved correctly, add the following to your `tsconfig.json` file: | ||
|
||
``` | ||
"references": [ | ||
{ | ||
"path": "../../packages/superset-ui-chart-controls" | ||
}, | ||
{ | ||
"path": "../../packages/superset-ui-core" | ||
} | ||
] | ||
``` | ||
|
||
You may also wish to add the following to the `include` array in `tsconfig.json` to make Superset types available to your plugin: | ||
|
||
``` | ||
"../../types/**/*" | ||
``` | ||
|
||
Finally, if you wish to ensure your plugin `tsconfig.json` is aligned with the root Superset project, you may add the following to your `tsconfig.json` file: | ||
|
||
``` | ||
"extends": "../../tsconfig.json", | ||
``` | ||
|
||
After this edit the `superset-frontend/src/visualizations/presets/MainPreset.js` and make the following changes: | ||
|
||
```js | ||
import { PopKPIPlugin } from '@superset-ui/plugin-chart-period-over-period-kpi'; | ||
``` | ||
|
||
to import the plugin and later add the following to the array that's passed to the `plugins` property: | ||
|
||
```js | ||
new PopKPIPlugin().configure({ key: 'pop_kpi' }), | ||
``` | ||
|
||
After that the plugin should show up when you run Superset, e.g. the development server: | ||
|
||
``` | ||
npm run dev-server | ||
``` |
33 changes: 33 additions & 0 deletions
33
superset-frontend/plugins/plugin-chart-period-over-period-kpi/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "@superset-ui/plugin-chart-period-over-period-kpi", | ||
"version": "0.1.0", | ||
"description": "Big Number with Time Period Comparison", | ||
"sideEffects": false, | ||
"main": "lib/index.js", | ||
"module": "esm/index.js", | ||
"files": [ | ||
"esm", | ||
"lib" | ||
], | ||
"private": true, | ||
"keywords": [ | ||
"superset" | ||
], | ||
"author": "Bytecodeio", | ||
"license": "Apache-2.0", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"moment": "^2.30.1" | ||
}, | ||
"peerDependencies": { | ||
"@superset-ui/chart-controls": "*", | ||
"@superset-ui/core": "*", | ||
"react": "^16.13.1" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^26.0.4", | ||
"jest": "^26.6.3" | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
superset-frontend/plugins/plugin-chart-period-over-period-kpi/src/PopKPI.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* 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. | ||
*/ | ||
import React, { createRef } from 'react'; | ||
import { css, styled, useTheme } from '@superset-ui/core'; | ||
import { PopKPIComparisonValueStyleProps, PopKPIProps } from './types'; | ||
|
||
const ComparisonValue = styled.div<PopKPIComparisonValueStyleProps>` | ||
${({ theme, subheaderFontSize }) => ` | ||
font-weight: ${theme.typography.weights.light}; | ||
width: 33%; | ||
display: table-cell; | ||
font-size: ${subheaderFontSize || 20}px; | ||
text-align: center; | ||
`} | ||
`; | ||
|
||
export default function PopKPI(props: PopKPIProps) { | ||
const { | ||
height, | ||
width, | ||
bigNumber, | ||
prevNumber, | ||
valueDifference, | ||
percentDifference, | ||
headerFontSize, | ||
subheaderFontSize, | ||
} = props; | ||
|
||
const rootElem = createRef<HTMLDivElement>(); | ||
const theme = useTheme(); | ||
|
||
const wrapperDivStyles = css` | ||
font-family: ${theme.typography.families.sansSerif}; | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
padding: ${theme.gridUnit * 4}px; | ||
border-radius: ${theme.gridUnit * 2}px; | ||
height: ${height}px; | ||
width: ${width}px; | ||
`; | ||
|
||
const bigValueContainerStyles = css` | ||
font-size: ${headerFontSize || 60}px; | ||
font-weight: ${theme.typography.weights.normal}; | ||
text-align: center; | ||
`; | ||
|
||
return ( | ||
<div ref={rootElem} css={wrapperDivStyles}> | ||
<div css={bigValueContainerStyles}>{bigNumber}</div> | ||
<div | ||
css={css` | ||
width: 100%; | ||
display: table; | ||
`} | ||
> | ||
<div | ||
css={css` | ||
display: table-row; | ||
`} | ||
> | ||
<ComparisonValue subheaderFontSize={subheaderFontSize}> | ||
{' '} | ||
#: {prevNumber} | ||
</ComparisonValue> | ||
<ComparisonValue subheaderFontSize={subheaderFontSize}> | ||
{' '} | ||
Δ: {valueDifference} | ||
</ComparisonValue> | ||
<ComparisonValue subheaderFontSize={subheaderFontSize}> | ||
{' '} | ||
%: {percentDifference} | ||
</ComparisonValue> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
Binary file added
BIN
+22.6 KB
...t-frontend/plugins/plugin-chart-period-over-period-kpi/src/images/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions
27
superset-frontend/plugins/plugin-chart-period-over-period-kpi/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* 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. | ||
*/ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export { default as PopKPIPlugin } from './plugin'; | ||
/** | ||
* Note: this file exports the default export from PopKPI.tsx. | ||
* If you want to export multiple visualization modules, you will need to | ||
* either add additional plugin folders (similar in structure to ./plugin) | ||
* OR export multiple instances of `ChartPlugin` extensions in ./plugin/index.ts | ||
* which in turn load exports from CustomViz.tsx | ||
*/ |
Oops, something went wrong.