GraphPanelEditor.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //// Libraries
  2. import _ from 'lodash';
  3. import React, { PureComponent } from 'react';
  4. // Types
  5. import { PanelEditorProps, Switch, LegendOptions } 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 options={this.props.options.legend} onChange={this.onLegendOptionsChange} />
  43. </>
  44. );
  45. }
  46. }