module.tsx 2.1 KB

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