axes_editor.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import kbn from 'app/core/utils/kbn';
  3. export class AxesEditorCtrl {
  4. panel: any;
  5. panelCtrl: any;
  6. unitFormats: any;
  7. logScales: any;
  8. xAxisModes: any;
  9. xAxisStatOptions: any;
  10. xNameSegment: any;
  11. /** @ngInject **/
  12. constructor(private $scope, private $q) {
  13. this.panelCtrl = $scope.ctrl;
  14. this.panel = this.panelCtrl.panel;
  15. $scope.ctrl = this;
  16. this.unitFormats = kbn.getUnitFormats();
  17. this.logScales = {
  18. 'linear': 1,
  19. 'log (base 2)': 2,
  20. 'log (base 10)': 10,
  21. 'log (base 32)': 32,
  22. 'log (base 1024)': 1024
  23. };
  24. this.xAxisModes = {
  25. 'Time': 'time',
  26. 'Series': 'series',
  27. // 'Data field': 'field',
  28. };
  29. this.xAxisStatOptions = [
  30. {text: 'Avg', value: 'avg'},
  31. {text: 'Min', value: 'min'},
  32. {text: 'Max', value: 'max'},
  33. {text: 'Total', value: 'total'},
  34. {text: 'Count', value: 'count'},
  35. {text: 'Current', value: 'current'},
  36. ];
  37. if (this.panel.xaxis.mode === 'custom') {
  38. if (!this.panel.xaxis.name) {
  39. this.panel.xaxis.name = 'specify field';
  40. }
  41. }
  42. }
  43. setUnitFormat(axis, subItem) {
  44. axis.format = subItem.value;
  45. this.panelCtrl.render();
  46. }
  47. render() {
  48. this.panelCtrl.render();
  49. }
  50. xAxisOptionChanged() {
  51. if (!this.panel.xaxis.values || !this.panel.xaxis.values[0]){
  52. this.panelCtrl.processor.setPanelDefaultsForNewXAxisMode();
  53. }
  54. this.panelCtrl.onDataReceived(this.panelCtrl.dataList);
  55. }
  56. getDataFieldNames(onlyNumbers) {
  57. var props = this.panelCtrl.processor.getDataFieldNames(this.panelCtrl.dataList, onlyNumbers);
  58. var items = props.map(prop => {
  59. return {text: prop, value: prop};
  60. });
  61. return this.$q.when(items);
  62. }
  63. }
  64. /** @ngInject **/
  65. export function axesEditorComponent() {
  66. 'use strict';
  67. return {
  68. restrict: 'E',
  69. scope: true,
  70. templateUrl: 'public/app/plugins/panel/graph/axes_editor.html',
  71. controller: AxesEditorCtrl,
  72. };
  73. }