From 827394261ae35105240b75d7af81839c08a97a53 Mon Sep 17 00:00:00 2001 From: Krist Wongsuphasawat Date: Wed, 24 Apr 2019 11:18:06 -0700 Subject: [PATCH] feat: update data format returned from query api and add getGroupBys (#72) * fix: update data format returned from query api * fix: format * fix: remove unnecessary type * fix: remove hack prior to typescript 3.4 --- .../stories/preset-chart-xy/Line/data/data.js | 447 +++++++++--------- .../preset-chart-xy/Line/data/data2.js | 183 ++++--- .../preset-chart-xy/Line/stories/missing.tsx | 11 +- .../src/Line/Encoder.ts | 22 +- .../src/Line/Line.tsx | 9 +- .../src/Line/legacy/transformProps.ts | 17 +- .../src/components/ChartLegend.tsx | 2 +- .../src/encodeable/AbstractEncoder.ts | 17 + .../src/encodeable/ChannelEncoder.ts | 15 + .../src/encodeable/types/Data.ts | 5 +- 10 files changed, 367 insertions(+), 361 deletions(-) diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/preset-chart-xy/Line/data/data.js b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/preset-chart-xy/Line/data/data.js index f14581b7fdc1..17dfb0e7d3fd 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/preset-chart-xy/Line/data/data.js +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/preset-chart-xy/Line/data/data.js @@ -1,226 +1,223 @@ /* eslint-disable sort-keys, no-magic-numbers */ -export default { - keys: ['name', 'x', 'y'], - values: [ - { x: -157766400000, y: 24703, name: 'Christopher' }, - { x: -126230400000, y: 27861, name: 'Christopher' }, - { x: -94694400000, y: 29436, name: 'Christopher' }, - { x: -63158400000, y: 31463, name: 'Christopher' }, - { x: -31536000000, y: 35718, name: 'Christopher' }, - { x: 0, y: 41758, name: 'Christopher' }, - { x: 31536000000, y: 48172, name: 'Christopher' }, - { x: 63072000000, y: 52092, name: 'Christopher' }, - { x: 94694400000, y: 48217, name: 'Christopher' }, - { x: 126230400000, y: 48476, name: 'Christopher' }, - { x: 157766400000, y: 46438, name: 'Christopher' }, - { x: 189302400000, y: 45086, name: 'Christopher' }, - { x: 220924800000, y: 46610, name: 'Christopher' }, - { x: 252460800000, y: 47107, name: 'Christopher' }, - { x: 283996800000, y: 50514, name: 'Christopher' }, - { x: 315532800000, y: 48969, name: 'Christopher' }, - { x: 347155200000, y: 50108, name: 'Christopher' }, - { x: 378691200000, y: 59055, name: 'Christopher' }, - { x: 410227200000, y: 59188, name: 'Christopher' }, - { x: 441763200000, y: 59859, name: 'Christopher' }, - { x: 473385600000, y: 59516, name: 'Christopher' }, - { x: 504921600000, y: 56633, name: 'Christopher' }, - { x: 536457600000, y: 54466, name: 'Christopher' }, - { x: 567993600000, y: 52996, name: 'Christopher' }, - { x: 599616000000, y: 53205, name: 'Christopher' }, - { x: 631152000000, y: 52322, name: 'Christopher' }, - { x: 662688000000, y: 47109, name: 'Christopher' }, - { x: 694224000000, y: 42470, name: 'Christopher' }, - { x: 725846400000, y: 38257, name: 'Christopher' }, - { x: 757382400000, y: 34823, name: 'Christopher' }, - { x: 788918400000, y: 32728, name: 'Christopher' }, - { x: 820454400000, y: 30988, name: 'Christopher' }, - { x: 852076800000, y: 29179, name: 'Christopher' }, - { x: 883612800000, y: 27083, name: 'Christopher' }, - { x: 915148800000, y: 25700, name: 'Christopher' }, - { x: 946684800000, y: 24959, name: 'Christopher' }, - { x: 978307200000, y: 23180, name: 'Christopher' }, - { x: 1009843200000, y: 21731, name: 'Christopher' }, - { x: 1041379200000, y: 20793, name: 'Christopher' }, - { x: 1072915200000, y: 19739, name: 'Christopher' }, - { x: 1104537600000, y: 19190, name: 'Christopher' }, - { x: 1136073600000, y: 19674, name: 'Christopher' }, - { x: 1167609600000, y: 19986, name: 'Christopher' }, - { x: 1199145600000, y: 17771, name: 'Christopher' }, - { x: -157766400000, y: 67646, name: 'David' }, - { x: -126230400000, y: 66207, name: 'David' }, - { x: -94694400000, y: 66581, name: 'David' }, - { x: -63158400000, y: 63531, name: 'David' }, - { x: -31536000000, y: 63502, name: 'David' }, - { x: 0, y: 61570, name: 'David' }, - { x: 31536000000, y: 52948, name: 'David' }, - { x: 63072000000, y: 46218, name: 'David' }, - { x: 94694400000, y: 40968, name: 'David' }, - { x: 126230400000, y: 41654, name: 'David' }, - { x: 157766400000, y: 39019, name: 'David' }, - { x: 189302400000, y: 39165, name: 'David' }, - { x: 220924800000, y: 40407, name: 'David' }, - { x: 252460800000, y: 40533, name: 'David' }, - { x: 283996800000, y: 41898, name: 'David' }, - { x: 315532800000, y: 41743, name: 'David' }, - { x: 347155200000, y: 40486, name: 'David' }, - { x: 378691200000, y: 40283, name: 'David' }, - { x: 410227200000, y: 39048, name: 'David' }, - { x: 441763200000, y: 38346, name: 'David' }, - { x: 473385600000, y: 38395, name: 'David' }, - { x: 504921600000, y: 37021, name: 'David' }, - { x: 536457600000, y: 36672, name: 'David' }, - { x: 567993600000, y: 35214, name: 'David' }, - { x: 599616000000, y: 35139, name: 'David' }, - { x: 631152000000, y: 33661, name: 'David' }, - { x: 662688000000, y: 30347, name: 'David' }, - { x: 694224000000, y: 28344, name: 'David' }, - { x: 725846400000, y: 26947, name: 'David' }, - { x: 757382400000, y: 24784, name: 'David' }, - { x: 788918400000, y: 22967, name: 'David' }, - { x: 820454400000, y: 22941, name: 'David' }, - { x: 852076800000, y: 21824, name: 'David' }, - { x: 883612800000, y: 20816, name: 'David' }, - { x: 915148800000, y: 20267, name: 'David' }, - { x: 946684800000, y: 19695, name: 'David' }, - { x: 978307200000, y: 19281, name: 'David' }, - { x: 1009843200000, y: 18600, name: 'David' }, - { x: 1041379200000, y: 18557, name: 'David' }, - { x: 1072915200000, y: 18315, name: 'David' }, - { x: 1104537600000, y: 18017, name: 'David' }, - { x: 1136073600000, y: 17510, name: 'David' }, - { x: 1167609600000, y: 17400, name: 'David' }, - { x: 1199145600000, y: 16049, name: 'David' }, - { x: -157766400000, y: 67506, name: 'James' }, - { x: -126230400000, y: 65036, name: 'James' }, - { x: -94694400000, y: 61554, name: 'James' }, - { x: -63158400000, y: 60584, name: 'James' }, - { x: -31536000000, y: 59824, name: 'James' }, - { x: 0, y: 61597, name: 'James' }, - { x: 31536000000, y: 54463, name: 'James' }, - { x: 63072000000, y: 46960, name: 'James' }, - { x: 94694400000, y: 42782, name: 'James' }, - { x: 126230400000, y: 41258, name: 'James' }, - { x: 157766400000, y: 39471, name: 'James' }, - { x: 189302400000, y: 38203, name: 'James' }, - { x: 220924800000, y: 39916, name: 'James' }, - { x: 252460800000, y: 39783, name: 'James' }, - { x: 283996800000, y: 39237, name: 'James' }, - { x: 315532800000, y: 39185, name: 'James' }, - { x: 347155200000, y: 38176, name: 'James' }, - { x: 378691200000, y: 38750, name: 'James' }, - { x: 410227200000, y: 36228, name: 'James' }, - { x: 441763200000, y: 35728, name: 'James' }, - { x: 473385600000, y: 35750, name: 'James' }, - { x: 504921600000, y: 33955, name: 'James' }, - { x: 536457600000, y: 32552, name: 'James' }, - { x: 567993600000, y: 32418, name: 'James' }, - { x: 599616000000, y: 32658, name: 'James' }, - { x: 631152000000, y: 32288, name: 'James' }, - { x: 662688000000, y: 30460, name: 'James' }, - { x: 694224000000, y: 28450, name: 'James' }, - { x: 725846400000, y: 26193, name: 'James' }, - { x: 757382400000, y: 24706, name: 'James' }, - { x: 788918400000, y: 22691, name: 'James' }, - { x: 820454400000, y: 21122, name: 'James' }, - { x: 852076800000, y: 20368, name: 'James' }, - { x: 883612800000, y: 19651, name: 'James' }, - { x: 915148800000, y: 18508, name: 'James' }, - { x: 946684800000, y: 17939, name: 'James' }, - { x: 978307200000, y: 17023, name: 'James' }, - { x: 1009843200000, y: 16905, name: 'James' }, - { x: 1041379200000, y: 16832, name: 'James' }, - { x: 1072915200000, y: 16459, name: 'James' }, - { x: 1104537600000, y: 16046, name: 'James' }, - { x: 1136073600000, y: 16139, name: 'James' }, - { x: 1167609600000, y: 15821, name: 'James' }, - { x: 1199145600000, y: 14920, name: 'James' }, - { x: -157766400000, y: 71390, name: 'John' }, - { x: -126230400000, y: 64858, name: 'John' }, - { x: -94694400000, y: 61480, name: 'John' }, - { x: -63158400000, y: 60754, name: 'John' }, - { x: -31536000000, y: 58644, name: 'John' }, - { x: 0, y: 58348, name: 'John' }, - { x: 31536000000, y: 51382, name: 'John' }, - { x: 63072000000, y: 43028, name: 'John' }, - { x: 94694400000, y: 39061, name: 'John' }, - { x: 126230400000, y: 37553, name: 'John' }, - { x: 157766400000, y: 34970, name: 'John' }, - { x: 189302400000, y: 33876, name: 'John' }, - { x: 220924800000, y: 34103, name: 'John' }, - { x: 252460800000, y: 33895, name: 'John' }, - { x: 283996800000, y: 35305, name: 'John' }, - { x: 315532800000, y: 35131, name: 'John' }, - { x: 347155200000, y: 34761, name: 'John' }, - { x: 378691200000, y: 34560, name: 'John' }, - { x: 410227200000, y: 33047, name: 'John' }, - { x: 441763200000, y: 32484, name: 'John' }, - { x: 473385600000, y: 31397, name: 'John' }, - { x: 504921600000, y: 30103, name: 'John' }, - { x: 536457600000, y: 29462, name: 'John' }, - { x: 567993600000, y: 29301, name: 'John' }, - { x: 599616000000, y: 29751, name: 'John' }, - { x: 631152000000, y: 29011, name: 'John' }, - { x: 662688000000, y: 27727, name: 'John' }, - { x: 694224000000, y: 26156, name: 'John' }, - { x: 725846400000, y: 24918, name: 'John' }, - { x: 757382400000, y: 24119, name: 'John' }, - { x: 788918400000, y: 23174, name: 'John' }, - { x: 820454400000, y: 22104, name: 'John' }, - { x: 852076800000, y: 21330, name: 'John' }, - { x: 883612800000, y: 20556, name: 'John' }, - { x: 915148800000, y: 20280, name: 'John' }, - { x: 946684800000, y: 20032, name: 'John' }, - { x: 978307200000, y: 18839, name: 'John' }, - { x: 1009843200000, y: 17400, name: 'John' }, - { x: 1041379200000, y: 17170, name: 'John' }, - { x: 1072915200000, y: 16381, name: 'John' }, - { x: 1104537600000, y: 15692, name: 'John' }, - { x: 1136073600000, y: 15083, name: 'John' }, - { x: 1167609600000, y: 14348, name: 'John' }, - { x: 1199145600000, y: 13110, name: 'John' }, - { x: -157766400000, y: 80812, name: 'Michael' }, - { x: -126230400000, y: 79709, name: 'Michael' }, - { x: -94694400000, y: 82204, name: 'Michael' }, - { x: -63158400000, y: 81785, name: 'Michael' }, - { x: -31536000000, y: 84893, name: 'Michael' }, - { x: 0, y: 85015, name: 'Michael' }, - { x: 31536000000, y: 77321, name: 'Michael' }, - { x: 63072000000, y: 71197, name: 'Michael' }, - { x: 94694400000, y: 67598, name: 'Michael' }, - { x: 126230400000, y: 67304, name: 'Michael' }, - { x: 157766400000, y: 68149, name: 'Michael' }, - { x: 189302400000, y: 66686, name: 'Michael' }, - { x: 220924800000, y: 67344, name: 'Michael' }, - { x: 252460800000, y: 66875, name: 'Michael' }, - { x: 283996800000, y: 67473, name: 'Michael' }, - { x: 315532800000, y: 68375, name: 'Michael' }, - { x: 347155200000, y: 68467, name: 'Michael' }, - { x: 378691200000, y: 67904, name: 'Michael' }, - { x: 410227200000, y: 67708, name: 'Michael' }, - { x: 441763200000, y: 67457, name: 'Michael' }, - { x: 473385600000, y: 64667, name: 'Michael' }, - { x: 504921600000, y: 63959, name: 'Michael' }, - { x: 536457600000, y: 63442, name: 'Michael' }, - { x: 567993600000, y: 63924, name: 'Michael' }, - { x: 599616000000, y: 65233, name: 'Michael' }, - { x: 631152000000, y: 65138, name: 'Michael' }, - { x: 662688000000, y: 60646, name: 'Michael' }, - { x: 694224000000, y: 54216, name: 'Michael' }, - { x: 725846400000, y: 49443, name: 'Michael' }, - { x: 757382400000, y: 44361, name: 'Michael' }, - { x: 788918400000, y: 41311, name: 'Michael' }, - { x: 820454400000, y: 38284, name: 'Michael' }, - { x: 852076800000, y: 37459, name: 'Michael' }, - { x: 883612800000, y: 36525, name: 'Michael' }, - { x: 915148800000, y: 33820, name: 'Michael' }, - { x: 946684800000, y: 31956, name: 'Michael' }, - { x: 978307200000, y: 29612, name: 'Michael' }, - { x: 1009843200000, y: 28156, name: 'Michael' }, - { x: 1041379200000, y: 27031, name: 'Michael' }, - { x: 1072915200000, y: 25418, name: 'Michael' }, - { x: 1104537600000, y: 23678, name: 'Michael' }, - { x: 1136073600000, y: 22498, name: 'Michael' }, - { x: 1167609600000, y: 21805, name: 'Michael' }, - { x: 1199145600000, y: 20271, name: 'Michael' }, - ], -}; +export default [ + { x: -157766400000, y: 24703, name: 'Christopher' }, + { x: -126230400000, y: 27861, name: 'Christopher' }, + { x: -94694400000, y: 29436, name: 'Christopher' }, + { x: -63158400000, y: 31463, name: 'Christopher' }, + { x: -31536000000, y: 35718, name: 'Christopher' }, + { x: 0, y: 41758, name: 'Christopher' }, + { x: 31536000000, y: 48172, name: 'Christopher' }, + { x: 63072000000, y: 52092, name: 'Christopher' }, + { x: 94694400000, y: 48217, name: 'Christopher' }, + { x: 126230400000, y: 48476, name: 'Christopher' }, + { x: 157766400000, y: 46438, name: 'Christopher' }, + { x: 189302400000, y: 45086, name: 'Christopher' }, + { x: 220924800000, y: 46610, name: 'Christopher' }, + { x: 252460800000, y: 47107, name: 'Christopher' }, + { x: 283996800000, y: 50514, name: 'Christopher' }, + { x: 315532800000, y: 48969, name: 'Christopher' }, + { x: 347155200000, y: 50108, name: 'Christopher' }, + { x: 378691200000, y: 59055, name: 'Christopher' }, + { x: 410227200000, y: 59188, name: 'Christopher' }, + { x: 441763200000, y: 59859, name: 'Christopher' }, + { x: 473385600000, y: 59516, name: 'Christopher' }, + { x: 504921600000, y: 56633, name: 'Christopher' }, + { x: 536457600000, y: 54466, name: 'Christopher' }, + { x: 567993600000, y: 52996, name: 'Christopher' }, + { x: 599616000000, y: 53205, name: 'Christopher' }, + { x: 631152000000, y: 52322, name: 'Christopher' }, + { x: 662688000000, y: 47109, name: 'Christopher' }, + { x: 694224000000, y: 42470, name: 'Christopher' }, + { x: 725846400000, y: 38257, name: 'Christopher' }, + { x: 757382400000, y: 34823, name: 'Christopher' }, + { x: 788918400000, y: 32728, name: 'Christopher' }, + { x: 820454400000, y: 30988, name: 'Christopher' }, + { x: 852076800000, y: 29179, name: 'Christopher' }, + { x: 883612800000, y: 27083, name: 'Christopher' }, + { x: 915148800000, y: 25700, name: 'Christopher' }, + { x: 946684800000, y: 24959, name: 'Christopher' }, + { x: 978307200000, y: 23180, name: 'Christopher' }, + { x: 1009843200000, y: 21731, name: 'Christopher' }, + { x: 1041379200000, y: 20793, name: 'Christopher' }, + { x: 1072915200000, y: 19739, name: 'Christopher' }, + { x: 1104537600000, y: 19190, name: 'Christopher' }, + { x: 1136073600000, y: 19674, name: 'Christopher' }, + { x: 1167609600000, y: 19986, name: 'Christopher' }, + { x: 1199145600000, y: 17771, name: 'Christopher' }, + { x: -157766400000, y: 67646, name: 'David' }, + { x: -126230400000, y: 66207, name: 'David' }, + { x: -94694400000, y: 66581, name: 'David' }, + { x: -63158400000, y: 63531, name: 'David' }, + { x: -31536000000, y: 63502, name: 'David' }, + { x: 0, y: 61570, name: 'David' }, + { x: 31536000000, y: 52948, name: 'David' }, + { x: 63072000000, y: 46218, name: 'David' }, + { x: 94694400000, y: 40968, name: 'David' }, + { x: 126230400000, y: 41654, name: 'David' }, + { x: 157766400000, y: 39019, name: 'David' }, + { x: 189302400000, y: 39165, name: 'David' }, + { x: 220924800000, y: 40407, name: 'David' }, + { x: 252460800000, y: 40533, name: 'David' }, + { x: 283996800000, y: 41898, name: 'David' }, + { x: 315532800000, y: 41743, name: 'David' }, + { x: 347155200000, y: 40486, name: 'David' }, + { x: 378691200000, y: 40283, name: 'David' }, + { x: 410227200000, y: 39048, name: 'David' }, + { x: 441763200000, y: 38346, name: 'David' }, + { x: 473385600000, y: 38395, name: 'David' }, + { x: 504921600000, y: 37021, name: 'David' }, + { x: 536457600000, y: 36672, name: 'David' }, + { x: 567993600000, y: 35214, name: 'David' }, + { x: 599616000000, y: 35139, name: 'David' }, + { x: 631152000000, y: 33661, name: 'David' }, + { x: 662688000000, y: 30347, name: 'David' }, + { x: 694224000000, y: 28344, name: 'David' }, + { x: 725846400000, y: 26947, name: 'David' }, + { x: 757382400000, y: 24784, name: 'David' }, + { x: 788918400000, y: 22967, name: 'David' }, + { x: 820454400000, y: 22941, name: 'David' }, + { x: 852076800000, y: 21824, name: 'David' }, + { x: 883612800000, y: 20816, name: 'David' }, + { x: 915148800000, y: 20267, name: 'David' }, + { x: 946684800000, y: 19695, name: 'David' }, + { x: 978307200000, y: 19281, name: 'David' }, + { x: 1009843200000, y: 18600, name: 'David' }, + { x: 1041379200000, y: 18557, name: 'David' }, + { x: 1072915200000, y: 18315, name: 'David' }, + { x: 1104537600000, y: 18017, name: 'David' }, + { x: 1136073600000, y: 17510, name: 'David' }, + { x: 1167609600000, y: 17400, name: 'David' }, + { x: 1199145600000, y: 16049, name: 'David' }, + { x: -157766400000, y: 67506, name: 'James' }, + { x: -126230400000, y: 65036, name: 'James' }, + { x: -94694400000, y: 61554, name: 'James' }, + { x: -63158400000, y: 60584, name: 'James' }, + { x: -31536000000, y: 59824, name: 'James' }, + { x: 0, y: 61597, name: 'James' }, + { x: 31536000000, y: 54463, name: 'James' }, + { x: 63072000000, y: 46960, name: 'James' }, + { x: 94694400000, y: 42782, name: 'James' }, + { x: 126230400000, y: 41258, name: 'James' }, + { x: 157766400000, y: 39471, name: 'James' }, + { x: 189302400000, y: 38203, name: 'James' }, + { x: 220924800000, y: 39916, name: 'James' }, + { x: 252460800000, y: 39783, name: 'James' }, + { x: 283996800000, y: 39237, name: 'James' }, + { x: 315532800000, y: 39185, name: 'James' }, + { x: 347155200000, y: 38176, name: 'James' }, + { x: 378691200000, y: 38750, name: 'James' }, + { x: 410227200000, y: 36228, name: 'James' }, + { x: 441763200000, y: 35728, name: 'James' }, + { x: 473385600000, y: 35750, name: 'James' }, + { x: 504921600000, y: 33955, name: 'James' }, + { x: 536457600000, y: 32552, name: 'James' }, + { x: 567993600000, y: 32418, name: 'James' }, + { x: 599616000000, y: 32658, name: 'James' }, + { x: 631152000000, y: 32288, name: 'James' }, + { x: 662688000000, y: 30460, name: 'James' }, + { x: 694224000000, y: 28450, name: 'James' }, + { x: 725846400000, y: 26193, name: 'James' }, + { x: 757382400000, y: 24706, name: 'James' }, + { x: 788918400000, y: 22691, name: 'James' }, + { x: 820454400000, y: 21122, name: 'James' }, + { x: 852076800000, y: 20368, name: 'James' }, + { x: 883612800000, y: 19651, name: 'James' }, + { x: 915148800000, y: 18508, name: 'James' }, + { x: 946684800000, y: 17939, name: 'James' }, + { x: 978307200000, y: 17023, name: 'James' }, + { x: 1009843200000, y: 16905, name: 'James' }, + { x: 1041379200000, y: 16832, name: 'James' }, + { x: 1072915200000, y: 16459, name: 'James' }, + { x: 1104537600000, y: 16046, name: 'James' }, + { x: 1136073600000, y: 16139, name: 'James' }, + { x: 1167609600000, y: 15821, name: 'James' }, + { x: 1199145600000, y: 14920, name: 'James' }, + { x: -157766400000, y: 71390, name: 'John' }, + { x: -126230400000, y: 64858, name: 'John' }, + { x: -94694400000, y: 61480, name: 'John' }, + { x: -63158400000, y: 60754, name: 'John' }, + { x: -31536000000, y: 58644, name: 'John' }, + { x: 0, y: 58348, name: 'John' }, + { x: 31536000000, y: 51382, name: 'John' }, + { x: 63072000000, y: 43028, name: 'John' }, + { x: 94694400000, y: 39061, name: 'John' }, + { x: 126230400000, y: 37553, name: 'John' }, + { x: 157766400000, y: 34970, name: 'John' }, + { x: 189302400000, y: 33876, name: 'John' }, + { x: 220924800000, y: 34103, name: 'John' }, + { x: 252460800000, y: 33895, name: 'John' }, + { x: 283996800000, y: 35305, name: 'John' }, + { x: 315532800000, y: 35131, name: 'John' }, + { x: 347155200000, y: 34761, name: 'John' }, + { x: 378691200000, y: 34560, name: 'John' }, + { x: 410227200000, y: 33047, name: 'John' }, + { x: 441763200000, y: 32484, name: 'John' }, + { x: 473385600000, y: 31397, name: 'John' }, + { x: 504921600000, y: 30103, name: 'John' }, + { x: 536457600000, y: 29462, name: 'John' }, + { x: 567993600000, y: 29301, name: 'John' }, + { x: 599616000000, y: 29751, name: 'John' }, + { x: 631152000000, y: 29011, name: 'John' }, + { x: 662688000000, y: 27727, name: 'John' }, + { x: 694224000000, y: 26156, name: 'John' }, + { x: 725846400000, y: 24918, name: 'John' }, + { x: 757382400000, y: 24119, name: 'John' }, + { x: 788918400000, y: 23174, name: 'John' }, + { x: 820454400000, y: 22104, name: 'John' }, + { x: 852076800000, y: 21330, name: 'John' }, + { x: 883612800000, y: 20556, name: 'John' }, + { x: 915148800000, y: 20280, name: 'John' }, + { x: 946684800000, y: 20032, name: 'John' }, + { x: 978307200000, y: 18839, name: 'John' }, + { x: 1009843200000, y: 17400, name: 'John' }, + { x: 1041379200000, y: 17170, name: 'John' }, + { x: 1072915200000, y: 16381, name: 'John' }, + { x: 1104537600000, y: 15692, name: 'John' }, + { x: 1136073600000, y: 15083, name: 'John' }, + { x: 1167609600000, y: 14348, name: 'John' }, + { x: 1199145600000, y: 13110, name: 'John' }, + { x: -157766400000, y: 80812, name: 'Michael' }, + { x: -126230400000, y: 79709, name: 'Michael' }, + { x: -94694400000, y: 82204, name: 'Michael' }, + { x: -63158400000, y: 81785, name: 'Michael' }, + { x: -31536000000, y: 84893, name: 'Michael' }, + { x: 0, y: 85015, name: 'Michael' }, + { x: 31536000000, y: 77321, name: 'Michael' }, + { x: 63072000000, y: 71197, name: 'Michael' }, + { x: 94694400000, y: 67598, name: 'Michael' }, + { x: 126230400000, y: 67304, name: 'Michael' }, + { x: 157766400000, y: 68149, name: 'Michael' }, + { x: 189302400000, y: 66686, name: 'Michael' }, + { x: 220924800000, y: 67344, name: 'Michael' }, + { x: 252460800000, y: 66875, name: 'Michael' }, + { x: 283996800000, y: 67473, name: 'Michael' }, + { x: 315532800000, y: 68375, name: 'Michael' }, + { x: 347155200000, y: 68467, name: 'Michael' }, + { x: 378691200000, y: 67904, name: 'Michael' }, + { x: 410227200000, y: 67708, name: 'Michael' }, + { x: 441763200000, y: 67457, name: 'Michael' }, + { x: 473385600000, y: 64667, name: 'Michael' }, + { x: 504921600000, y: 63959, name: 'Michael' }, + { x: 536457600000, y: 63442, name: 'Michael' }, + { x: 567993600000, y: 63924, name: 'Michael' }, + { x: 599616000000, y: 65233, name: 'Michael' }, + { x: 631152000000, y: 65138, name: 'Michael' }, + { x: 662688000000, y: 60646, name: 'Michael' }, + { x: 694224000000, y: 54216, name: 'Michael' }, + { x: 725846400000, y: 49443, name: 'Michael' }, + { x: 757382400000, y: 44361, name: 'Michael' }, + { x: 788918400000, y: 41311, name: 'Michael' }, + { x: 820454400000, y: 38284, name: 'Michael' }, + { x: 852076800000, y: 37459, name: 'Michael' }, + { x: 883612800000, y: 36525, name: 'Michael' }, + { x: 915148800000, y: 33820, name: 'Michael' }, + { x: 946684800000, y: 31956, name: 'Michael' }, + { x: 978307200000, y: 29612, name: 'Michael' }, + { x: 1009843200000, y: 28156, name: 'Michael' }, + { x: 1041379200000, y: 27031, name: 'Michael' }, + { x: 1072915200000, y: 25418, name: 'Michael' }, + { x: 1104537600000, y: 23678, name: 'Michael' }, + { x: 1136073600000, y: 22498, name: 'Michael' }, + { x: 1167609600000, y: 21805, name: 'Michael' }, + { x: 1199145600000, y: 20271, name: 'Michael' }, +]; diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/preset-chart-xy/Line/data/data2.js b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/preset-chart-xy/Line/data/data2.js index fda02b8afb29..7b7c1dd39ddc 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/preset-chart-xy/Line/data/data2.js +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/preset-chart-xy/Line/data/data2.js @@ -1,94 +1,91 @@ /* eslint-disable sort-keys, no-magic-numbers */ -export default { - keys: ['snapshot', 'x', 'y'], - values: [ - { x: -157766400000, y: 24703, snapshot: 'Last year' }, - { x: -126230400000, y: 27861, snapshot: 'Last year' }, - { x: -94694400000, y: 29436, snapshot: 'Last year' }, - { x: -63158400000, y: 31463, snapshot: 'Last year' }, - { x: -31536000000, y: 35718, snapshot: 'Last year' }, - { x: 0, y: 41758, snapshot: 'Last year' }, - { x: 31536000000, y: 48172, snapshot: 'Last year' }, - { x: 63072000000, y: 52092, snapshot: 'Last year' }, - { x: 94694400000, y: 48217, snapshot: 'Last year' }, - { x: 126230400000, y: 48476, snapshot: 'Last year' }, - { x: 157766400000, y: 46438, snapshot: 'Last year' }, - { x: 189302400000, y: 45086, snapshot: 'Last year' }, - { x: 220924800000, y: 46610, snapshot: 'Last year' }, - { x: 252460800000, y: 47107, snapshot: 'Last year' }, - { x: 283996800000, y: 50514, snapshot: 'Last year' }, - { x: 315532800000, y: 48969, snapshot: 'Last year' }, - { x: 347155200000, y: 50108, snapshot: 'Last year' }, - { x: 378691200000, y: 59055, snapshot: 'Last year' }, - { x: 410227200000, y: 59188, snapshot: 'Last year' }, - { x: 441763200000, y: 59859, snapshot: 'Last year' }, - { x: 473385600000, y: 59516, snapshot: 'Last year' }, - { x: 504921600000, y: 56633, snapshot: 'Last year' }, - { x: 536457600000, y: 54466, snapshot: 'Last year' }, - { x: 567993600000, y: 52996, snapshot: 'Last year' }, - { x: 599616000000, y: 53205, snapshot: 'Last year' }, - { x: 631152000000, y: 52322, snapshot: 'Last year' }, - { x: 662688000000, y: 47109, snapshot: 'Last year' }, - { x: 694224000000, y: 42470, snapshot: 'Last year' }, - { x: 725846400000, y: 38257, snapshot: 'Last year' }, - { x: 757382400000, y: 34823, snapshot: 'Last year' }, - { x: 788918400000, y: 32728, snapshot: 'Last year' }, - { x: 820454400000, y: 30988, snapshot: 'Last year' }, - { x: 852076800000, y: 29179, snapshot: 'Last year' }, - { x: 883612800000, y: 27083, snapshot: 'Last year' }, - { x: 915148800000, y: 25700, snapshot: 'Last year' }, - { x: 946684800000, y: 24959, snapshot: 'Last year' }, - { x: 978307200000, y: 23180, snapshot: 'Last year' }, - { x: 1009843200000, y: 21731, snapshot: 'Last year' }, - { x: 1041379200000, y: 20793, snapshot: 'Last year' }, - { x: 1072915200000, y: 19739, snapshot: 'Last year' }, - { x: 1104537600000, y: 19190, snapshot: 'Last year' }, - { x: 1136073600000, y: 19674, snapshot: 'Last year' }, - { x: 1167609600000, y: 19986, snapshot: 'Last year' }, - { x: 1199145600000, y: 17771, snapshot: 'Last year' }, - { x: -157766400000, y: 80812, snapshot: 'Current' }, - { x: -126230400000, y: 79709, snapshot: 'Current' }, - { x: -94694400000, y: 82204, snapshot: 'Current' }, - { x: -63158400000, y: 81785, snapshot: 'Current' }, - { x: -31536000000, y: 84893, snapshot: 'Current' }, - { x: 0, y: 85015, snapshot: 'Current' }, - { x: 31536000000, y: 77321, snapshot: 'Current' }, - { x: 63072000000, y: 71197, snapshot: 'Current' }, - { x: 94694400000, y: 67598, snapshot: 'Current' }, - { x: 126230400000, y: 67304, snapshot: 'Current' }, - { x: 157766400000, y: 68149, snapshot: 'Current' }, - { x: 189302400000, y: 66686, snapshot: 'Current' }, - { x: 220924800000, y: 67344, snapshot: 'Current' }, - { x: 252460800000, y: 66875, snapshot: 'Current' }, - { x: 283996800000, y: 67473, snapshot: 'Current' }, - { x: 315532800000, y: 68375, snapshot: 'Current' }, - { x: 347155200000, y: 68467, snapshot: 'Current' }, - { x: 378691200000, y: 67904, snapshot: 'Current' }, - { x: 410227200000, y: 67708, snapshot: 'Current' }, - { x: 441763200000, y: 67457, snapshot: 'Current' }, - { x: 473385600000, y: 64667, snapshot: 'Current' }, - { x: 504921600000, y: 63959, snapshot: 'Current' }, - { x: 536457600000, y: 63442, snapshot: 'Current' }, - { x: 567993600000, y: 63924, snapshot: 'Current' }, - { x: 599616000000, y: 65233, snapshot: 'Current' }, - { x: 631152000000, y: 65138, snapshot: 'Current' }, - { x: 662688000000, y: 60646, snapshot: 'Current' }, - { x: 694224000000, y: 54216, snapshot: 'Current' }, - { x: 725846400000, y: 49443, snapshot: 'Current' }, - { x: 757382400000, y: 44361, snapshot: 'Current' }, - { x: 788918400000, y: 41311, snapshot: 'Current' }, - { x: 820454400000, y: 38284, snapshot: 'Current' }, - { x: 852076800000, y: 37459, snapshot: 'Current' }, - { x: 883612800000, y: 36525, snapshot: 'Current' }, - { x: 915148800000, y: 33820, snapshot: 'Current' }, - { x: 946684800000, y: 31956, snapshot: 'Current' }, - { x: 978307200000, y: 29612, snapshot: 'Current' }, - { x: 1009843200000, y: 28156, snapshot: 'Current' }, - { x: 1041379200000, y: 27031, snapshot: 'Current' }, - { x: 1072915200000, y: 25418, snapshot: 'Current' }, - { x: 1104537600000, y: 23678, snapshot: 'Current' }, - { x: 1136073600000, y: 22498, snapshot: 'Current' }, - { x: 1167609600000, y: 21805, snapshot: 'Current' }, - { x: 1199145600000, y: 20271, snapshot: 'Current' }, - ], -}; +export default [ + { x: -157766400000, y: 24703, snapshot: 'Last year' }, + { x: -126230400000, y: 27861, snapshot: 'Last year' }, + { x: -94694400000, y: 29436, snapshot: 'Last year' }, + { x: -63158400000, y: 31463, snapshot: 'Last year' }, + { x: -31536000000, y: 35718, snapshot: 'Last year' }, + { x: 0, y: 41758, snapshot: 'Last year' }, + { x: 31536000000, y: 48172, snapshot: 'Last year' }, + { x: 63072000000, y: 52092, snapshot: 'Last year' }, + { x: 94694400000, y: 48217, snapshot: 'Last year' }, + { x: 126230400000, y: 48476, snapshot: 'Last year' }, + { x: 157766400000, y: 46438, snapshot: 'Last year' }, + { x: 189302400000, y: 45086, snapshot: 'Last year' }, + { x: 220924800000, y: 46610, snapshot: 'Last year' }, + { x: 252460800000, y: 47107, snapshot: 'Last year' }, + { x: 283996800000, y: 50514, snapshot: 'Last year' }, + { x: 315532800000, y: 48969, snapshot: 'Last year' }, + { x: 347155200000, y: 50108, snapshot: 'Last year' }, + { x: 378691200000, y: 59055, snapshot: 'Last year' }, + { x: 410227200000, y: 59188, snapshot: 'Last year' }, + { x: 441763200000, y: 59859, snapshot: 'Last year' }, + { x: 473385600000, y: 59516, snapshot: 'Last year' }, + { x: 504921600000, y: 56633, snapshot: 'Last year' }, + { x: 536457600000, y: 54466, snapshot: 'Last year' }, + { x: 567993600000, y: 52996, snapshot: 'Last year' }, + { x: 599616000000, y: 53205, snapshot: 'Last year' }, + { x: 631152000000, y: 52322, snapshot: 'Last year' }, + { x: 662688000000, y: 47109, snapshot: 'Last year' }, + { x: 694224000000, y: 42470, snapshot: 'Last year' }, + { x: 725846400000, y: 38257, snapshot: 'Last year' }, + { x: 757382400000, y: 34823, snapshot: 'Last year' }, + { x: 788918400000, y: 32728, snapshot: 'Last year' }, + { x: 820454400000, y: 30988, snapshot: 'Last year' }, + { x: 852076800000, y: 29179, snapshot: 'Last year' }, + { x: 883612800000, y: 27083, snapshot: 'Last year' }, + { x: 915148800000, y: 25700, snapshot: 'Last year' }, + { x: 946684800000, y: 24959, snapshot: 'Last year' }, + { x: 978307200000, y: 23180, snapshot: 'Last year' }, + { x: 1009843200000, y: 21731, snapshot: 'Last year' }, + { x: 1041379200000, y: 20793, snapshot: 'Last year' }, + { x: 1072915200000, y: 19739, snapshot: 'Last year' }, + { x: 1104537600000, y: 19190, snapshot: 'Last year' }, + { x: 1136073600000, y: 19674, snapshot: 'Last year' }, + { x: 1167609600000, y: 19986, snapshot: 'Last year' }, + { x: 1199145600000, y: 17771, snapshot: 'Last year' }, + { x: -157766400000, y: 80812, snapshot: 'Current' }, + { x: -126230400000, y: 79709, snapshot: 'Current' }, + { x: -94694400000, y: 82204, snapshot: 'Current' }, + { x: -63158400000, y: 81785, snapshot: 'Current' }, + { x: -31536000000, y: 84893, snapshot: 'Current' }, + { x: 0, y: 85015, snapshot: 'Current' }, + { x: 31536000000, y: 77321, snapshot: 'Current' }, + { x: 63072000000, y: 71197, snapshot: 'Current' }, + { x: 94694400000, y: 67598, snapshot: 'Current' }, + { x: 126230400000, y: 67304, snapshot: 'Current' }, + { x: 157766400000, y: 68149, snapshot: 'Current' }, + { x: 189302400000, y: 66686, snapshot: 'Current' }, + { x: 220924800000, y: 67344, snapshot: 'Current' }, + { x: 252460800000, y: 66875, snapshot: 'Current' }, + { x: 283996800000, y: 67473, snapshot: 'Current' }, + { x: 315532800000, y: 68375, snapshot: 'Current' }, + { x: 347155200000, y: 68467, snapshot: 'Current' }, + { x: 378691200000, y: 67904, snapshot: 'Current' }, + { x: 410227200000, y: 67708, snapshot: 'Current' }, + { x: 441763200000, y: 67457, snapshot: 'Current' }, + { x: 473385600000, y: 64667, snapshot: 'Current' }, + { x: 504921600000, y: 63959, snapshot: 'Current' }, + { x: 536457600000, y: 63442, snapshot: 'Current' }, + { x: 567993600000, y: 63924, snapshot: 'Current' }, + { x: 599616000000, y: 65233, snapshot: 'Current' }, + { x: 631152000000, y: 65138, snapshot: 'Current' }, + { x: 662688000000, y: 60646, snapshot: 'Current' }, + { x: 694224000000, y: 54216, snapshot: 'Current' }, + { x: 725846400000, y: 49443, snapshot: 'Current' }, + { x: 757382400000, y: 44361, snapshot: 'Current' }, + { x: 788918400000, y: 41311, snapshot: 'Current' }, + { x: 820454400000, y: 38284, snapshot: 'Current' }, + { x: 852076800000, y: 37459, snapshot: 'Current' }, + { x: 883612800000, y: 36525, snapshot: 'Current' }, + { x: 915148800000, y: 33820, snapshot: 'Current' }, + { x: 946684800000, y: 31956, snapshot: 'Current' }, + { x: 978307200000, y: 29612, snapshot: 'Current' }, + { x: 1009843200000, y: 28156, snapshot: 'Current' }, + { x: 1041379200000, y: 27031, snapshot: 'Current' }, + { x: 1072915200000, y: 25418, snapshot: 'Current' }, + { x: 1104537600000, y: 23678, snapshot: 'Current' }, + { x: 1136073600000, y: 22498, snapshot: 'Current' }, + { x: 1167609600000, y: 21805, snapshot: 'Current' }, + { x: 1199145600000, y: 20271, snapshot: 'Current' }, +]; diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/preset-chart-xy/Line/stories/missing.tsx b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/preset-chart-xy/Line/stories/missing.tsx index 1da18ec62ed0..9f93a3622bf0 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/preset-chart-xy/Line/stories/missing.tsx +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/preset-chart-xy/Line/stories/missing.tsx @@ -4,13 +4,10 @@ import { SuperChart, ChartProps } from '@superset-ui/chart'; import data from '../data/data'; import { LINE_PLUGIN_TYPE } from '../constants'; -const missingData = { - keys: data.keys, - values: data.values.map(({ y, ...rest }) => ({ - ...rest, - y: Math.random() < 0.25 ? null : y, - })), -}; +const missingData = data.map(({ y, ...rest }) => ({ + ...rest, + y: Math.random() < 0.25 ? null : y, +})); export default [ { diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/Line/Encoder.ts b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/Line/Encoder.ts index 0b13b090029f..ee4f9a376716 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/Line/Encoder.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/Line/Encoder.ts @@ -5,21 +5,13 @@ import { EncodingFromChannelsAndOutputs } from '../encodeable/types/Channel'; /** * Define channel types */ -// This is a workaround until TypeScript 3.4 which has const context -// which will allow use to derive type from object literal -// without type widening (e.g. 'X' instead of string). -// Now we have to define class with readonly fields -// to be able to use "typeof" to infer strict types -// See more details from -// https://github.com/Microsoft/TypeScript/issues/20195 -// https://github.com/Microsoft/TypeScript/pull/29510 -const channelTypes = new (class Channels { - readonly x = 'X'; - readonly y = 'Y'; - readonly color = 'Color'; - readonly fill = 'Category'; - readonly strokeDasharray = 'Category'; -})(); +const channelTypes = { + color: 'Color', + fill: 'Category', + strokeDasharray: 'Category', + x: 'X', + y: 'Y', +} as const; export type ChannelTypes = typeof channelTypes; diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/Line/Line.tsx b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/Line/Line.tsx index 893351ba7760..2b7f845fcd0e 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/Line/Line.tsx +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/Line/Line.tsx @@ -81,15 +81,12 @@ class LineChart extends PureComponent { renderChart(dim: Dimension) { const { width, height } = dim; - const { data, encoding, margin, theme } = this.props; + const { data, margin, theme } = this.props; const { channels } = this.encoder; + const fieldNames = this.encoder.getGroupBys(); - const fieldNames = data.keys - .filter(k => k !== encoding.x.field && k !== encoding.y.field) - .sort((a, b) => a.localeCompare(b)); - - const groups = groupBy(data.values, row => fieldNames.map(f => `${f}=${row[f]}`).join(',')); + const groups = groupBy(data, row => fieldNames.map(f => `${f}=${row[f]}`).join(',')); const allSeries = values(groups).map(seriesData => { const firstDatum = seriesData[0]; diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/Line/legacy/transformProps.ts b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/Line/legacy/transformProps.ts index a9e07df78429..ad38a85df52f 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/Line/legacy/transformProps.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/Line/legacy/transformProps.ts @@ -16,17 +16,14 @@ export default function transformProps(chartProps: ChartProps) { const data = payload.data as DataRow[]; return { - data: { - keys: ['name', 'x', 'y'], - values: flatMap( - data.map((row: DataRow) => - row.values.map(v => ({ - ...v, - name: row.key[0], - })), - ), + data: flatMap( + data.map((row: DataRow) => + row.values.map(v => ({ + ...v, + name: row.key[0], + })), ), - }, + ), width, height, encoding: { diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/components/ChartLegend.tsx b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/components/ChartLegend.tsx index fb288ce83215..01f4d4326624 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/components/ChartLegend.tsx +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/components/ChartLegend.tsx @@ -47,7 +47,7 @@ export default class ChartLegend< const legends = Object.keys(encoder.legends).map((field: string) => { const channelNames = encoder.legends[field]; const channelEncoder = encoder.channels[channelNames[0]]; - const domain = Array.from(new Set(data.values.map(channelEncoder.get))); + const domain = Array.from(new Set(data.map(channelEncoder.get))); const scale = scaleOrdinal({ domain, range: domain.map((key: string) => channelEncoder.encodeValue(key)), diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/encodeable/AbstractEncoder.ts b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/encodeable/AbstractEncoder.ts index c30451c13bb6..7fd991110e5d 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/encodeable/AbstractEncoder.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/encodeable/AbstractEncoder.ts @@ -99,6 +99,23 @@ export default abstract class AbstractEncoder< }; } + getChannelNames() { + return Object.keys(this.channelTypes) as (keyof ChannelTypes)[]; + } + + getChannelsAsArray() { + return this.getChannelNames().map(name => this.channels[name]); + } + + getGroupBys() { + const fields = this.getChannelsAsArray() + .filter(c => c.isGroupBy()) + .map(c => (isFieldDef(c.definition) ? c.definition.field : '')) + .filter(field => field !== ''); + + return Array.from(new Set(fields)); + } + hasLegend() { return Object.keys(this.legends).length > 0; } diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/encodeable/ChannelEncoder.ts b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/encodeable/ChannelEncoder.ts index fe2403beeb98..43b2be13e973 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/encodeable/ChannelEncoder.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/encodeable/ChannelEncoder.ts @@ -11,6 +11,7 @@ import { isValueDef, isFieldDef, isNonValueDef, + isTypedFieldDef, } from './types/ChannelDef'; import isEnabled from './utils/isEnabled'; import isDisabled from './utils/isDisabled'; @@ -107,6 +108,20 @@ export default class ChannelEncoder, Output exten return isScaleFieldDef(this.definition); } + isGroupBy() { + if (isTypedFieldDef(this.definition)) { + return ( + this.type === 'XBand' || + this.type === 'YBand' || + this.type === 'Category' || + this.type === 'Text' || + (this.type === 'Color' && this.definition.type === 'nominal') + ); + } + + return false; + } + isX() { return this.type === 'X' || this.type === 'XBand'; } diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/encodeable/types/Data.ts b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/encodeable/types/Data.ts index d2c32d524ac3..9b09e14702a1 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/encodeable/types/Data.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/encodeable/types/Data.ts @@ -2,7 +2,4 @@ export type PlainObject = [key in Key]: Value }; -export type Dataset = { - keys: T[]; - values: Partial>[]; -}; +export type Dataset = Partial>[];