GraphPanelEditor.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //// Libraries
  2. import _ from 'lodash';
  3. import React, { PureComponent } from 'react';
  4. // Types
  5. import { PanelEditorProps, Switch, LegendOptions, StatID } from '@grafana/ui';
  6. import { Options, GraphOptions } from './types';
  7. import { GraphLegendEditor } from './GraphLegendEditor';
  8. export class GraphPanelEditor extends PureComponent<PanelEditorProps<Options>> {
  9. onGraphOptionsChange = (options: Partial<GraphOptions>) => {
  10. this.props.onOptionsChange({
  11. ...this.props.options,
  12. graph: {
  13. ...this.props.options.graph,
  14. ...options,
  15. },
  16. });
  17. };
  18. onLegendOptionsChange = (options: LegendOptions) => {
  19. this.props.onOptionsChange({ ...this.props.options, legend: options });
  20. };
  21. onToggleLines = () => {
  22. this.onGraphOptionsChange({ showLines: !this.props.options.graph.showLines });
  23. };
  24. onToggleBars = () => {
  25. this.onGraphOptionsChange({ showBars: !this.props.options.graph.showBars });
  26. };
  27. onTogglePoints = () => {
  28. this.onGraphOptionsChange({ showPoints: !this.props.options.graph.showPoints });
  29. };
  30. render() {
  31. const {
  32. graph: { showBars, showPoints, showLines },
  33. } = this.props.options;
  34. return (
  35. <>
  36. <div className="section gf-form-group">
  37. <h5 className="section-heading">Draw Modes</h5>
  38. <Switch label="Lines" labelClass="width-5" checked={showLines} onChange={this.onToggleLines} />
  39. <Switch label="Bars" labelClass="width-5" checked={showBars} onChange={this.onToggleBars} />
  40. <Switch label="Points" labelClass="width-5" checked={showPoints} onChange={this.onTogglePoints} />
  41. </div>
  42. <GraphLegendEditor
  43. stats={[StatID.min, StatID.max, StatID.mean, StatID.last, StatID.sum]}
  44. options={this.props.options.legend}
  45. onChange={this.onLegendOptionsChange}
  46. />
  47. </>
  48. );
  49. }
  50. }