controlPanel.tsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 { t } from '@superset-ui/core';
  20. import {
  21. ControlPanelConfig,
  22. ControlSubSectionHeader,
  23. D3_FORMAT_DOCS,
  24. D3_FORMAT_OPTIONS,
  25. D3_TIME_FORMAT_OPTIONS,
  26. sections,
  27. getStandardizedControls,
  28. } from '@superset-ui/chart-controls';
  29. const config: ControlPanelConfig = {
  30. controlPanelSections: [
  31. sections.legacyTimeseriesTime,
  32. {
  33. label: t('Query'),
  34. expanded: true,
  35. controlSetRows: [
  36. ['metrics'],
  37. ['adhoc_filters'],
  38. ['groupby'],
  39. ['limit', 'timeseries_limit_metric'],
  40. ['order_desc'],
  41. [
  42. {
  43. name: 'contribution',
  44. config: {
  45. type: 'CheckboxControl',
  46. label: t('Contribution'),
  47. default: false,
  48. description: t('Compute the contribution to the total'),
  49. },
  50. },
  51. ],
  52. ['row_limit', null],
  53. ],
  54. },
  55. {
  56. label: t('Chart Options'),
  57. expanded: true,
  58. controlSetRows: [
  59. ['color_scheme'],
  60. [
  61. {
  62. name: 'number_format',
  63. config: {
  64. type: 'SelectControl',
  65. freeForm: true,
  66. label: t('Number format'),
  67. renderTrigger: true,
  68. default: 'SMART_NUMBER',
  69. choices: D3_FORMAT_OPTIONS,
  70. description: D3_FORMAT_DOCS,
  71. },
  72. },
  73. {
  74. name: 'date_time_format',
  75. config: {
  76. type: 'SelectControl',
  77. freeForm: true,
  78. label: t('Date Time Format'),
  79. renderTrigger: true,
  80. default: 'smart_date',
  81. choices: D3_TIME_FORMAT_OPTIONS,
  82. description: D3_FORMAT_DOCS,
  83. },
  84. },
  85. ],
  86. [
  87. {
  88. name: 'rich_tooltip',
  89. config: {
  90. type: 'CheckboxControl',
  91. label: t('Rich Tooltip'),
  92. renderTrigger: true,
  93. default: true,
  94. description: t(
  95. 'The rich tooltip shows a list of all series for that point in time',
  96. ),
  97. },
  98. },
  99. {
  100. name: 'rose_area_proportion',
  101. config: {
  102. type: 'CheckboxControl',
  103. label: t('Use Area Proportions'),
  104. description: t(
  105. 'Check if the Rose Chart should use segment area instead of ' +
  106. 'segment radius for proportioning',
  107. ),
  108. default: false,
  109. renderTrigger: true,
  110. },
  111. },
  112. ],
  113. ],
  114. },
  115. {
  116. label: t('Advanced Analytics'),
  117. tabOverride: 'data',
  118. description: t(
  119. 'This section contains options ' +
  120. 'that allow for advanced analytical post processing ' +
  121. 'of query results',
  122. ),
  123. controlSetRows: [
  124. // eslint-disable-next-line react/jsx-key
  125. [
  126. <ControlSubSectionHeader>
  127. {t('Rolling Window')}
  128. </ControlSubSectionHeader>,
  129. ],
  130. [
  131. {
  132. name: 'rolling_type',
  133. config: {
  134. type: 'SelectControl',
  135. label: t('Rolling Function'),
  136. default: 'None',
  137. choices: [
  138. ['None', t('None')],
  139. ['mean', t('mean')],
  140. ['sum', t('sum')],
  141. ['std', t('std')],
  142. ['cumsum', t('cumsum')],
  143. ],
  144. description: t(
  145. 'Defines a rolling window function to apply, works along ' +
  146. 'with the [Periods] text box',
  147. ),
  148. },
  149. },
  150. ],
  151. [
  152. {
  153. name: 'rolling_periods',
  154. config: {
  155. type: 'TextControl',
  156. label: t('Periods'),
  157. isInt: true,
  158. description: t(
  159. 'Defines the size of the rolling window function, ' +
  160. 'relative to the time granularity selected',
  161. ),
  162. },
  163. },
  164. {
  165. name: 'min_periods',
  166. config: {
  167. type: 'TextControl',
  168. label: t('Min Periods'),
  169. isInt: true,
  170. description: t(
  171. 'The minimum number of rolling periods required to show ' +
  172. 'a value. For instance if you do a cumulative sum on 7 days ' +
  173. 'you may want your "Min Period" to be 7, so that all data points ' +
  174. 'shown are the total of 7 periods. This will hide the "ramp up" ' +
  175. 'taking place over the first 7 periods',
  176. ),
  177. },
  178. },
  179. ],
  180. // eslint-disable-next-line react/jsx-key
  181. [
  182. <ControlSubSectionHeader>
  183. {t('Time Comparison')}
  184. </ControlSubSectionHeader>,
  185. ],
  186. [
  187. {
  188. name: 'time_compare',
  189. config: {
  190. type: 'SelectControl',
  191. multi: true,
  192. freeForm: true,
  193. label: t('Time Shift'),
  194. choices: [
  195. ['1 day', t('1 day')],
  196. ['1 week', t('1 week')],
  197. ['28 days', t('28 days')],
  198. ['30 days', t('30 days')],
  199. ['52 weeks', t('52 weeks')],
  200. ['1 year', t('1 year')],
  201. ['104 weeks', t('104 weeks')],
  202. ['2 years', t('2 years')],
  203. ['156 weeks', t('156 weeks')],
  204. ['3 years', t('3 years')],
  205. ],
  206. description: t(
  207. 'Overlay one or more timeseries from a ' +
  208. 'relative time period. Expects relative time deltas ' +
  209. 'in natural language (example: 24 hours, 7 days, ' +
  210. '52 weeks, 365 days). Free text is supported.',
  211. ),
  212. },
  213. },
  214. {
  215. name: 'comparison_type',
  216. config: {
  217. type: 'SelectControl',
  218. label: t('Calculation type'),
  219. default: 'values',
  220. choices: [
  221. ['values', t('Actual Values')],
  222. ['absolute', t('Difference')],
  223. ['percentage', t('Percentage change')],
  224. ['ratio', t('Ratio')],
  225. ],
  226. description: t(
  227. 'How to display time shifts: as individual lines; as the ' +
  228. 'difference between the main time series and each time shift; ' +
  229. 'as the percentage change; or as the ratio between series and time shifts.',
  230. ),
  231. },
  232. },
  233. ],
  234. [<ControlSubSectionHeader>{t('Resample')}</ControlSubSectionHeader>],
  235. [
  236. {
  237. name: 'resample_rule',
  238. config: {
  239. type: 'SelectControl',
  240. freeForm: true,
  241. label: t('Rule'),
  242. default: null,
  243. choices: [
  244. ['1T', t('1T')],
  245. ['1H', t('1H')],
  246. ['1D', t('1D')],
  247. ['7D', t('7D')],
  248. ['1M', t('1M')],
  249. ['1AS', t('1AS')],
  250. ],
  251. description: t('Pandas resample rule'),
  252. },
  253. },
  254. {
  255. name: 'resample_method',
  256. config: {
  257. type: 'SelectControl',
  258. freeForm: true,
  259. label: t('Method'),
  260. default: null,
  261. choices: [
  262. ['asfreq', t('asfreq')],
  263. ['bfill', t('bfill')],
  264. ['ffill', t('ffill')],
  265. ['median', t('median')],
  266. ['mean', t('mean')],
  267. ['sum', t('sum')],
  268. ],
  269. description: t('Pandas resample method'),
  270. },
  271. },
  272. ],
  273. ],
  274. },
  275. ],
  276. formDataOverrides: formData => ({
  277. ...formData,
  278. groupby: getStandardizedControls().popAllColumns(),
  279. metrics: getStandardizedControls().popAllMetrics(),
  280. }),
  281. };
  282. export default config;