|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +import React from 'react'; |
| 20 | +import { t } from '@superset-ui/core'; |
| 21 | +import { |
| 22 | + ControlPanelConfig, |
| 23 | + D3_FORMAT_DOCS, |
| 24 | + D3_FORMAT_OPTIONS, |
| 25 | + D3_TIME_FORMAT_OPTIONS, |
| 26 | + sections, |
| 27 | +} from '@superset-ui/chart-controls'; |
| 28 | +import { DEFAULT_FORM_DATA } from './types'; |
| 29 | +import { LABEL_POSITION } from '../constants'; |
| 30 | + |
| 31 | +const { |
| 32 | + labelType, |
| 33 | + labelPosition, |
| 34 | + numberFormat, |
| 35 | + showLabels, |
| 36 | + showUpperLabels, |
| 37 | + dateFormat, |
| 38 | +} = DEFAULT_FORM_DATA; |
| 39 | + |
| 40 | +const config: ControlPanelConfig = { |
| 41 | + controlPanelSections: [ |
| 42 | + sections.legacyRegularTime, |
| 43 | + { |
| 44 | + label: t('Query'), |
| 45 | + expanded: true, |
| 46 | + controlSetRows: [ |
| 47 | + ['groupby'], |
| 48 | + ['metrics'], |
| 49 | + ['row_limit'], |
| 50 | + ['timeseries_limit_metric'], |
| 51 | + [ |
| 52 | + { |
| 53 | + name: 'order_desc', |
| 54 | + config: { |
| 55 | + type: 'CheckboxControl', |
| 56 | + label: t('Sort Descending'), |
| 57 | + default: true, |
| 58 | + description: t('Whether to sort descending or ascending'), |
| 59 | + }, |
| 60 | + }, |
| 61 | + ], |
| 62 | + ['adhoc_filters'], |
| 63 | + ], |
| 64 | + }, |
| 65 | + { |
| 66 | + label: t('Chart Options'), |
| 67 | + expanded: true, |
| 68 | + controlSetRows: [ |
| 69 | + ['color_scheme'], |
| 70 | + [<h1 className="section-header">{t('Labels')}</h1>], |
| 71 | + [ |
| 72 | + { |
| 73 | + name: 'show_labels', |
| 74 | + config: { |
| 75 | + type: 'CheckboxControl', |
| 76 | + label: t('Show Labels'), |
| 77 | + renderTrigger: true, |
| 78 | + default: showLabels, |
| 79 | + description: t('Whether to display the labels.'), |
| 80 | + }, |
| 81 | + }, |
| 82 | + ], |
| 83 | + [ |
| 84 | + { |
| 85 | + name: 'show_upper_labels', |
| 86 | + config: { |
| 87 | + type: 'CheckboxControl', |
| 88 | + label: t('Show Upper Labels'), |
| 89 | + renderTrigger: true, |
| 90 | + default: showUpperLabels, |
| 91 | + description: t('Show labels when the node has children.'), |
| 92 | + }, |
| 93 | + }, |
| 94 | + ], |
| 95 | + [ |
| 96 | + { |
| 97 | + name: 'label_type', |
| 98 | + config: { |
| 99 | + type: 'SelectControl', |
| 100 | + label: t('Label Type'), |
| 101 | + default: labelType, |
| 102 | + renderTrigger: true, |
| 103 | + choices: [ |
| 104 | + ['Key', 'Key'], |
| 105 | + ['value', 'Value'], |
| 106 | + ['key_value', 'Category and Value'], |
| 107 | + ], |
| 108 | + description: t('What should be shown on the label?'), |
| 109 | + }, |
| 110 | + }, |
| 111 | + ], |
| 112 | + [ |
| 113 | + { |
| 114 | + name: 'label_position', |
| 115 | + config: { |
| 116 | + type: 'SelectControl', |
| 117 | + freeForm: false, |
| 118 | + label: t('Label position'), |
| 119 | + renderTrigger: true, |
| 120 | + choices: LABEL_POSITION, |
| 121 | + default: labelPosition, |
| 122 | + description: D3_FORMAT_DOCS, |
| 123 | + }, |
| 124 | + }, |
| 125 | + ], |
| 126 | + [ |
| 127 | + { |
| 128 | + name: 'number_format', |
| 129 | + config: { |
| 130 | + type: 'SelectControl', |
| 131 | + freeForm: true, |
| 132 | + label: t('Number format'), |
| 133 | + renderTrigger: true, |
| 134 | + default: numberFormat, |
| 135 | + choices: D3_FORMAT_OPTIONS, |
| 136 | + description: `${t('D3 format syntax: https://github.com/d3/d3-format. ')} ${t( |
| 137 | + 'Only applies when "Label Type" is set to show values.', |
| 138 | + )}`, |
| 139 | + }, |
| 140 | + }, |
| 141 | + ], |
| 142 | + [ |
| 143 | + { |
| 144 | + name: 'date_format', |
| 145 | + config: { |
| 146 | + type: 'SelectControl', |
| 147 | + freeForm: true, |
| 148 | + label: t('Date format'), |
| 149 | + renderTrigger: true, |
| 150 | + choices: D3_TIME_FORMAT_OPTIONS, |
| 151 | + default: dateFormat, |
| 152 | + description: D3_FORMAT_DOCS, |
| 153 | + }, |
| 154 | + }, |
| 155 | + ], |
| 156 | + ], |
| 157 | + }, |
| 158 | + ], |
| 159 | +}; |
| 160 | + |
| 161 | +export default config; |
0 commit comments