From 8b4eefa768a1ab5d9a5948fba971835b6e45aa0e Mon Sep 17 00:00:00 2001 From: corpglory-dev Date: Fri, 15 Feb 2019 20:43:51 +0300 Subject: [PATCH] Initial commit --- .../src/components/Piechart/Piechart.tsx | 60 ++++++++++++++++++ packages/grafana-ui/src/components/index.ts | 1 + .../plugins/panel/piechart/PiechartPanel.tsx | 43 +++++++++++++ .../panel/piechart/PiechartPanelOptions.tsx | 30 +++++++++ .../plugins/panel/piechart/ValueOptions.tsx | 42 ++++++++++++ .../piechart/img/piechart_logo_large.png | Bin 0 -> 3723 bytes .../piechart/img/piechart_logo_small.png | Bin 0 -> 2629 bytes public/app/plugins/panel/piechart/module.tsx | 4 ++ public/app/plugins/panel/piechart/plugin.json | 18 ++++++ public/app/plugins/panel/piechart/types.ts | 7 ++ 10 files changed, 205 insertions(+) create mode 100644 packages/grafana-ui/src/components/Piechart/Piechart.tsx create mode 100644 public/app/plugins/panel/piechart/PiechartPanel.tsx create mode 100644 public/app/plugins/panel/piechart/PiechartPanelOptions.tsx create mode 100644 public/app/plugins/panel/piechart/ValueOptions.tsx create mode 100644 public/app/plugins/panel/piechart/img/piechart_logo_large.png create mode 100644 public/app/plugins/panel/piechart/img/piechart_logo_small.png create mode 100644 public/app/plugins/panel/piechart/module.tsx create mode 100644 public/app/plugins/panel/piechart/plugin.json create mode 100644 public/app/plugins/panel/piechart/types.ts diff --git a/packages/grafana-ui/src/components/Piechart/Piechart.tsx b/packages/grafana-ui/src/components/Piechart/Piechart.tsx new file mode 100644 index 00000000000..c57d4c43ce8 --- /dev/null +++ b/packages/grafana-ui/src/components/Piechart/Piechart.tsx @@ -0,0 +1,60 @@ +import React, { PureComponent } from 'react'; + +import { GrafanaThemeType } from '../../types'; +import { Themeable } from '../../index'; + +export interface Props extends Themeable { + height: number; + width: number; + + unit: string; + value: number; + pieType: string; + format: string; + stat: string; + strokeWidth: number; +} + +export class Piechart extends PureComponent { + canvasElement: any; + + static defaultProps = { + pieType: 'pie', + format: 'short', + valueName: 'current', + strokeWidth: 1, + theme: GrafanaThemeType.Dark, + }; + + componentDidMount() { + this.draw(); + } + + componentDidUpdate() { + this.draw(); + } + + draw() { + // const { width, height, theme, value } = this.props; + } + + render() { + const { height, width } = this.props; + + return ( +
+
(this.canvasElement = element)} + /> +
+ ); + } +} + +export default Piechart; diff --git a/packages/grafana-ui/src/components/index.ts b/packages/grafana-ui/src/components/index.ts index 86ce9347dad..329cbbfc9ba 100644 --- a/packages/grafana-ui/src/components/index.ts +++ b/packages/grafana-ui/src/components/index.ts @@ -24,3 +24,4 @@ export { ValueMappingsEditor } from './ValueMappingsEditor/ValueMappingsEditor'; export { Gauge } from './Gauge/Gauge'; export { Switch } from './Switch/Switch'; export { EmptySearchResult } from './EmptySearchResult/EmptySearchResult'; +export { Piechart } from './Piechart/Piechart'; diff --git a/public/app/plugins/panel/piechart/PiechartPanel.tsx b/public/app/plugins/panel/piechart/PiechartPanel.tsx new file mode 100644 index 00000000000..c3c15b35598 --- /dev/null +++ b/public/app/plugins/panel/piechart/PiechartPanel.tsx @@ -0,0 +1,43 @@ +// Libraries +import React, { PureComponent } from 'react'; + +// Services & Utils +import { processTimeSeries, ThemeContext } from '@grafana/ui'; + +// Components +import { Piechart } from '@grafana/ui'; + +// Types +import { PiechartOptions } from './types'; +import { PanelProps, NullValueMode, TimeSeriesValue } from '@grafana/ui/src/types'; + +interface Props extends PanelProps {} + +export class PiechartPanel extends PureComponent { + render() { + const { panelData, width, height, options } = this.props; + + let value: TimeSeriesValue; + + if (panelData.timeSeries) { + const vmSeries = processTimeSeries({ + timeSeries: panelData.timeSeries, + nullValueMode: NullValueMode.Null, + }); + + if (vmSeries[0]) { + value = vmSeries[0].stats[options.stat]; + } else { + value = null; + } + } else if (panelData.tableData) { + value = panelData.tableData.rows[0].find(prop => prop > 0); + } + + return ( + + {theme => } + + ); + } +} diff --git a/public/app/plugins/panel/piechart/PiechartPanelOptions.tsx b/public/app/plugins/panel/piechart/PiechartPanelOptions.tsx new file mode 100644 index 00000000000..43d7c2ab23d --- /dev/null +++ b/public/app/plugins/panel/piechart/PiechartPanelOptions.tsx @@ -0,0 +1,30 @@ +import React, { PureComponent } from 'react'; +import { PanelOptionsProps, PanelOptionsGrid } from '@grafana/ui'; + +import ValueOptions from './ValueOptions'; +import { PiechartOptions } from './types'; + +export const defaultProps = { + options: { + pieType: 'pie', + unit: 'short', + stat: 'current', + strokeWidth: 1, + }, +}; + +export default class PiechartPanelOptions extends PureComponent> { + static defaultProps = defaultProps; + + render() { + const { onChange, options } = this.props; + + return ( + <> + + + + + ); + } +} diff --git a/public/app/plugins/panel/piechart/ValueOptions.tsx b/public/app/plugins/panel/piechart/ValueOptions.tsx new file mode 100644 index 00000000000..e83e4686d13 --- /dev/null +++ b/public/app/plugins/panel/piechart/ValueOptions.tsx @@ -0,0 +1,42 @@ +import React, { PureComponent } from 'react'; +import { FormLabel, PanelOptionsProps, PanelOptionsGroup, Select } from '@grafana/ui'; +import UnitPicker from 'app/core/components/Select/UnitPicker'; +import { PiechartOptions } from './types'; + +const statOptions = [ + { value: 'min', label: 'Min' }, + { value: 'max', label: 'Max' }, + { value: 'avg', label: 'Average' }, + { value: 'current', label: 'Current' }, + { value: 'total', label: 'Total' }, +]; + +const labelWidth = 6; + +export default class ValueOptions extends PureComponent> { + onUnitChange = unit => this.props.onChange({ ...this.props.options, unit: unit.value }); + + onStatChange = stat => this.props.onChange({ ...this.props.options, stat: stat.value }); + + render() { + const { stat, unit } = this.props.options; + + return ( + +
+ Stat +