module.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import _ from 'lodash';
  2. import React, { PureComponent } from 'react';
  3. import Graph from 'app/viz/Graph';
  4. import { Switch } from 'app/core/components/Switch/Switch';
  5. import { getTimeSeriesVMs } from 'app/viz/state/timeSeries';
  6. import { PanelProps, PanelOptionsProps, NullValueMode } from 'app/types';
  7. // import { moduleMenu } from './moduleMenu';
  8. interface Options {
  9. showBars: boolean;
  10. showLines: boolean;
  11. showPoints: boolean;
  12. onChange: (options: Options) => void;
  13. }
  14. interface Props extends PanelProps<Options> {}
  15. export class Graph2 extends PureComponent<Props> {
  16. constructor(props) {
  17. super(props);
  18. }
  19. render() {
  20. const { timeSeries, timeRange } = this.props;
  21. const { showLines, showBars, showPoints } = this.props.options;
  22. const vmSeries = getTimeSeriesVMs({
  23. timeSeries: timeSeries,
  24. nullValueMode: NullValueMode.Ignore,
  25. });
  26. return (
  27. <Graph
  28. timeSeries={vmSeries}
  29. timeRange={timeRange}
  30. showLines={showLines}
  31. showPoints={showPoints}
  32. showBars={showBars}
  33. />
  34. );
  35. }
  36. }
  37. export class GraphOptions extends PureComponent<PanelOptionsProps<Options>> {
  38. onToggleLines = () => {
  39. this.props.onChange({ ...this.props.options, showLines: !this.props.options.showLines });
  40. };
  41. onToggleBars = () => {
  42. this.props.onChange({ ...this.props.options, showBars: !this.props.options.showBars });
  43. };
  44. onTogglePoints = () => {
  45. this.props.onChange({ ...this.props.options, showPoints: !this.props.options.showPoints });
  46. };
  47. render() {
  48. const { showBars, showPoints, showLines } = this.props.options;
  49. return (
  50. <div>
  51. <div className="section gf-form-group">
  52. <h5 className="page-heading">Draw Modes</h5>
  53. <Switch label="Lines" labelClass="width-5" checked={showLines} onChange={this.onToggleLines} />
  54. <Switch label="Bars" labelClass="width-5" checked={showBars} onChange={this.onToggleBars} />
  55. <Switch label="Points" labelClass="width-5" checked={showPoints} onChange={this.onTogglePoints} />
  56. </div>
  57. </div>
  58. );
  59. }
  60. }
  61. export { Graph2 as PanelComponent, GraphOptions as PanelOptionsComponent };
  62. export { moduleMenu } from './moduleMenu';