diff --git a/src/charts/README.mdx b/src/charts/README.mdx index 1e16f3c0..8bdf5c4f 100644 --- a/src/charts/README.mdx +++ b/src/charts/README.mdx @@ -34,7 +34,7 @@ You can also provide a `name` prop for the tooltip value and an array of `labels color="highlight" />
- + ## SimpleGauge @@ -45,4 +45,6 @@ Takes a single `value` prop that must be a Number value between `0` and `1` whic
+
+ diff --git a/src/charts/SimpleGauge/StripesPattern.js b/src/charts/SimpleGauge/StripesPattern.js new file mode 100644 index 00000000..e8b59f87 --- /dev/null +++ b/src/charts/SimpleGauge/StripesPattern.js @@ -0,0 +1,46 @@ +import React from 'react'; +import styled from 'styled-components'; +import {getColorBlock} from '../../utils/colors'; + +const Wrapper = styled.div` + height: 0; + color: ${p => getColorBlock(p.color, p.theme)}; +`; + +function StripesPattern({id, color}) { + return ( + + + + + + + + + + + + + + + ); +} + +export default StripesPattern; diff --git a/src/charts/SimpleGauge/index.js b/src/charts/SimpleGauge/index.js index 2fe87e28..0be85905 100644 --- a/src/charts/SimpleGauge/index.js +++ b/src/charts/SimpleGauge/index.js @@ -4,9 +4,13 @@ import styled, {css} from 'styled-components'; import {pxToRem} from '../../utils/units'; import {getColorBlock} from '../../utils/colors'; +import CenterContent from '../../CenterContent'; + import useChartist from '../useChartist'; +import StripesPattern from './StripesPattern'; const Wrapper = styled.div` + position: relative; overflow: hidden; ${p => p.height && @@ -14,19 +18,25 @@ const Wrapper = styled.div` height: ${pxToRem(p.height)}; `} - color: ${p => getColorBlock(p.color, p.theme)}; - > svg { vertical-align: middle; + color: ${p => getColorBlock(p.color, p.theme)}; + ${p => + p.patternId && + ` + opacity: 0.2; + `} } .ct-slice-donut { + stroke: none; fill: none; } .ct-series-a { - stroke: currentColor; + fill: ${p => + p.patternId ? `url(#${p.patternId}) currentColor` : 'currentColor'}; } .ct-series-b { - stroke: currentColor; + fill: currentColor; opacity: 0.2; } `; @@ -34,16 +44,25 @@ const Wrapper = styled.div` const defaultOptions = { donut: true, donutWidth: '80%', + donutSolid: true, startAngle: 270, total: 200, showLabel: false, chartPadding: 0, }; -function SimpleGauge({value, height, color = 'links'}) { +function SimpleGauge({ + value, + height, + color = 'links', + isEmpty, + emptyContent = 'No data to display', +}) { const hostRef = useRef(null); - const fraction = value * 100; + const hasValue = typeof value !== 'undefined' && value !== null && !isEmpty; + + const fraction = (hasValue ? value : Math.random()) * 100; const options = { ...defaultOptions, @@ -58,7 +77,23 @@ function SimpleGauge({value, height, color = 'links'}) { options, }); - return ; + const patternId = `gauge-chart-${Math.random()}`; + + return ( + + {!hasValue && ( + + {emptyContent} + + + )} + + ); } export default SimpleGauge;