module.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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, 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<Options> {
  37. onToggleLines = () => {
  38. const options = this.props as Options;
  39. this.props.onChange({
  40. ...options,
  41. showLines: !this.props.showLines,
  42. });
  43. };
  44. onTogglePoints = () => {
  45. const options = this.props as Options;
  46. this.props.onChange({
  47. ...options,
  48. showPoints: !this.props.showPoints,
  49. });
  50. };
  51. render() {
  52. const { showBars, showPoints, showLines } = this.props;
  53. return (
  54. <div>
  55. <div className="section gf-form-group">
  56. <h5 className="page-heading">Draw Modes</h5>
  57. <Switch label="Lines" labelClass="width-5" checked={showLines} onChange={this.onToggleLines} />
  58. <Switch label="Bars" labelClass="width-5" checked={showBars} onChange={this.onToggleLines} />
  59. <Switch label="Points" labelClass="width-5" checked={showPoints} onChange={this.onTogglePoints} />
  60. </div>
  61. </div>
  62. );
  63. }
  64. }
  65. export { Graph2 as PanelComponent, GraphOptions as PanelOptionsComponent };