SuperChart.stories.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 { SuperChart } from '@superset-ui/core';
  20. import {
  21. DiligentChartPlugin,
  22. BuggyChartPlugin,
  23. ChartKeys,
  24. } from '../../../../superset-ui-core/test/chart/components/MockChartPlugins';
  25. import ResizableChartDemo from '../../shared/components/ResizableChartDemo';
  26. new DiligentChartPlugin().configure({ key: ChartKeys.DILIGENT }).register();
  27. new BuggyChartPlugin().configure({ key: ChartKeys.BUGGY }).register();
  28. const DEFAULT_QUERY_DATA = { data: ['foo', 'bar'] };
  29. export default {
  30. title: 'Others/SuperChart',
  31. decorators: [],
  32. };
  33. export const basic = ({ width, height }: { width: string; height: string }) => (
  34. <SuperChart
  35. chartType={ChartKeys.DILIGENT}
  36. width={width}
  37. height={height}
  38. queriesData={[DEFAULT_QUERY_DATA]}
  39. formData={{ hi: 1 }}
  40. />
  41. );
  42. basic.args = {
  43. width: '100%',
  44. height: '100%',
  45. };
  46. basic.argTypes = {
  47. width: { control: 'text', description: 'Vis width' },
  48. height: { control: 'text', description: 'Vis height' },
  49. };
  50. export const container50pct = ({
  51. width,
  52. height,
  53. }: {
  54. width: string;
  55. height: string;
  56. }) => (
  57. <SuperChart
  58. chartType={ChartKeys.DILIGENT}
  59. width={width}
  60. height={height}
  61. queriesData={[DEFAULT_QUERY_DATA]}
  62. formData={{ hi: 1 }}
  63. />
  64. );
  65. container50pct.storyName = '50% of container';
  66. container50pct.args = {
  67. width: '50%',
  68. height: '50%',
  69. };
  70. container50pct.argTypes = {
  71. width: { control: 'text', description: 'Vis width' },
  72. height: { control: 'text', description: 'Vis height' },
  73. };
  74. export const Resizable = () => (
  75. <ResizableChartDemo>
  76. {size => (
  77. <SuperChart
  78. chartType={ChartKeys.DILIGENT}
  79. width={size.width}
  80. height={size.height}
  81. queriesData={[DEFAULT_QUERY_DATA]}
  82. />
  83. )}
  84. </ResizableChartDemo>
  85. );
  86. export const fixedWidth100height = ({
  87. width,
  88. height,
  89. }: {
  90. width: string;
  91. height: string;
  92. }) => (
  93. <SuperChart
  94. chartType={ChartKeys.DILIGENT}
  95. height={height}
  96. width={width}
  97. queriesData={[DEFAULT_QUERY_DATA]}
  98. />
  99. );
  100. fixedWidth100height.storyName = 'fixed width, 100% height';
  101. fixedWidth100height.args = {
  102. width: '500',
  103. height: '100%',
  104. };
  105. fixedWidth100height.argTypes = {
  106. width: { control: 'text', description: 'Vis width' },
  107. height: { control: 'text', description: 'Vis height' },
  108. };
  109. export const fixedHeight100Width = ({
  110. width,
  111. height,
  112. }: {
  113. width: string;
  114. height: string;
  115. }) => (
  116. <SuperChart
  117. chartType={ChartKeys.DILIGENT}
  118. height={height}
  119. width={width}
  120. queriesData={[DEFAULT_QUERY_DATA]}
  121. />
  122. );
  123. fixedHeight100Width.storyName = 'fixed height, 100% width';
  124. fixedHeight100Width.args = {
  125. width: '100%',
  126. height: '300',
  127. };
  128. fixedHeight100Width.argTypes = {
  129. width: { control: 'text', description: 'Vis width' },
  130. height: { control: 'text', description: 'Vis height' },
  131. };
  132. export const withErrorBoundary = ({
  133. width,
  134. height,
  135. }: {
  136. width: string;
  137. height: string;
  138. }) => (
  139. <SuperChart
  140. chartType={ChartKeys.BUGGY}
  141. height={height}
  142. width={width}
  143. queriesData={[DEFAULT_QUERY_DATA]}
  144. />
  145. );
  146. withErrorBoundary.storyName = 'With Error Boundary';
  147. withErrorBoundary.args = {
  148. width: '500',
  149. height: '300',
  150. };
  151. withErrorBoundary.argTypes = {
  152. width: { control: 'text', description: 'Vis width' },
  153. height: { control: 'text', description: 'Vis height' },
  154. };
  155. export const withWrapper = ({
  156. width,
  157. height,
  158. }: {
  159. width: string;
  160. height: string;
  161. }) => (
  162. <SuperChart
  163. chartType={ChartKeys.DILIGENT}
  164. width={width}
  165. height={height}
  166. queriesData={[DEFAULT_QUERY_DATA]}
  167. Wrapper={({ children }) => (
  168. <div>
  169. <div style={{ margin: 10, position: 'fixed' }}>With wrapper!</div>
  170. {children}
  171. </div>
  172. )}
  173. />
  174. );
  175. withWrapper.storyName = 'With Wrapper';
  176. withWrapper.args = {
  177. width: '100%',
  178. height: '100%',
  179. };
  180. withWrapper.argTypes = {
  181. width: { control: 'text', description: 'Vis width' },
  182. height: { control: 'text', description: 'Vis height' },
  183. };
  184. export const withNoResults = ({
  185. width,
  186. height,
  187. }: {
  188. width: string;
  189. height: string;
  190. }) => (
  191. <SuperChart chartType={ChartKeys.DILIGENT} width={width} height={height} />
  192. );
  193. withNoResults.storyName = 'With no results';
  194. withNoResults.args = {
  195. width: '100%',
  196. height: '100%',
  197. };
  198. withNoResults.argTypes = {
  199. width: { control: 'text', description: 'Vis width' },
  200. height: { control: 'text', description: 'Vis height' },
  201. };
  202. export const withNoResultsAndMedium = ({
  203. width,
  204. height,
  205. }: {
  206. width: string;
  207. height: string;
  208. }) => (
  209. <SuperChart chartType={ChartKeys.DILIGENT} width={width} height={height} />
  210. );
  211. withNoResultsAndMedium.storyName = 'With no results and medium';
  212. withNoResultsAndMedium.args = {
  213. width: '400',
  214. height: '300',
  215. };
  216. withNoResultsAndMedium.argTypes = {
  217. width: { control: 'text', description: 'Vis width' },
  218. height: { control: 'text', description: 'Vis height' },
  219. };
  220. export const withNoResultsAndSmall = ({
  221. width,
  222. height,
  223. }: {
  224. width: string;
  225. height: string;
  226. }) => (
  227. <SuperChart chartType={ChartKeys.DILIGENT} width={width} height={height} />
  228. );
  229. withNoResultsAndSmall.storyName = 'With no results and small';
  230. withNoResultsAndSmall.args = {
  231. width: '150',
  232. height: '200',
  233. };
  234. withNoResultsAndSmall.argTypes = {
  235. width: { control: 'text', description: 'Vis width' },
  236. height: { control: 'text', description: 'Vis height' },
  237. };