reynoldmorel commented on code in PR #37229: URL: https://github.com/apache/superset/pull/37229#discussion_r2705416329
########## superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.test.ts: ########## @@ -0,0 +1,461 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { DatasourceType } from '@superset-ui/core'; +import transformProps from './transformProps'; +import { + EchartsTimeseriesChartProps, + EchartsTimeseriesSeriesType, + OrientationType, +} from './types'; +import { LegendOrientation, LegendType } from '../types'; + +const mockedProps = { + // Chart dimensions + width: 787, + height: 190.1953125, + + // Datasource metadata + datasource: { + id: 1, + name: 'test_datasource', + type: DatasourceType.Table, + columns: [ + { + column_name: 'ds', + type: 'TIMESTAMP', + type_generic: 2, + verbose_name: null, + }, + { + column_name: 'metric_col', + type: 'DOUBLE PRECISION', + type_generic: 0, + verbose_name: null, + }, + ], + metrics: [ + { + certification_details: null, + certified_by: null, + currency: null, + d3format: null, + description: null, + expression: 'COUNT(*)', + id: 34, + is_certified: false, + metric_name: 'testing_count', + uuid: '8ec0dc91-e0ef-43e9-b74d-3b4dc3688295', + verbose_name: 'Testing count', + warning_markdown: null, + warning_text: null, + }, + { + certification_details: null, + certified_by: null, + currency: null, + d3format: null, + description: null, + expression: 'COUNT(*)', + id: 17, + is_certified: false, + metric_name: 'count', + uuid: 'd8fc38ce-8938-4ae4-a032-8b3723f5fbd3', + verbose_name: 'COUNT(*)', + warning_markdown: '', + warning_text: null, + }, + ], + columnFormats: {}, + currencyFormats: {}, + verboseMap: { + ID: 'ID', + __timestamp: 'Time', + age: 'age', + bootcamp_attend: 'bootcamp_attend', + bootcamp_finished: 'bootcamp_finished', + bootcamp_have_loan: 'bootcamp_have_loan', + bootcamp_name: 'bootcamp_name', + bootcamp_recommend: 'bootcamp_recommend', + calc_first_time_dev: 'calc_first_time_dev', + codeevnt_coderdojo: 'codeevnt_coderdojo', + codeevnt_confs: 'codeevnt_confs', + codeevnt_djangogrls: 'codeevnt_djangogrls', + codeevnt_fcc: 'codeevnt_fcc', + codeevnt_gamejam: 'codeevnt_gamejam', + codeevnt_girldevit: 'codeevnt_girldevit', + codeevnt_hackthn: 'codeevnt_hackthn', + codeevnt_meetup: 'codeevnt_meetup', + codeevnt_nodeschl: 'codeevnt_nodeschl', + codeevnt_other: 'codeevnt_other', + codeevnt_railsbrdg: 'codeevnt_railsbrdg', + codeevnt_railsgrls: 'codeevnt_railsgrls', + codeevnt_startupwknd: 'codeevnt_startupwknd', + codeevnt_wkndbtcmp: 'codeevnt_wkndbtcmp', + codeevnt_womenwc: 'codeevnt_womenwc', + codeevnt_workshps: 'codeevnt_workshps', + communite_time: 'communite_time', + count: 'COUNT(*)', + country_citizen: 'country_citizen', + country_live: 'country_live', + curr_field: 'curr_field', + debt_amt: 'debt_amt', + developer_type: 'Developer Type', + do_finance_support: 'do_finance_support', + ethnic_minority: 'Ethnic Minority', + expected_earn: 'expected_earn', + first_time_developer: 'First Time Developer', + gender: 'gender', + gender_other: 'gender_other', + has_children: 'has_children', + has_finance_depends: 'has_finance_depends', + has_high_spd_ntnet: 'has_high_spd_ntnet', + has_served_military: 'has_served_military', + highest_degree_earned: 'Highest Degree Earned', + home_mrtg_has: 'home_mrtg_has', + home_mrtg_owe: 'home_mrtg_owe', + hours_learning: 'hours_learning', + is_ethnic_minority: 'is_ethnic_minority', + is_first_dev_job: 'is_first_dev_job', + is_recv_disab_bnft: 'is_recv_disab_bnft', + is_self_employed: 'is_self_employed', + is_software_dev: 'is_software_dev', + job_intr_backend: 'job_intr_backend', + job_intr_dataengn: 'job_intr_dataengn', + job_intr_datasci: 'job_intr_datasci', + job_intr_devops: 'job_intr_devops', + job_intr_fllstck: 'job_intr_fllstck', + job_intr_frntend: 'job_intr_frntend', + job_intr_gamedev: 'job_intr_gamedev', + job_intr_infosec: 'job_intr_infosec', + job_intr_mobile: 'job_intr_mobile', + job_intr_other: 'job_intr_other', + job_intr_projm: 'job_intr_projm', + job_intr_qa_engn: 'job_intr_qa_engn', + job_intr_teacher: 'job_intr_teacher', + job_intr_ux_engn: 'job_intr_ux_engn', + job_lctn_pref: 'job_lctn_pref', + job_location_preference: 'Job Location Preference', + job_pref: 'job_pref', + job_relocate: 'job_relocate', + lang_at_home: 'lang_at_home', + last_yr_income: 'last_yr_income', + live_city_population: 'live_city_population', + marital_status: 'marital_status', + money_for_learning: 'money_for_learning', + months_job_search: 'months_job_search', + months_programming: 'months_programming', + network_id: 'network_id', + num_children: 'num_children', + podcast_changelog: 'podcast_changelog', + podcast_codenewbie: 'podcast_codenewbie', + podcast_codepenrd: 'podcast_codepenrd', + podcast_codingblcks: 'podcast_codingblcks', + podcast_devtea: 'podcast_devtea', + podcast_fcc: 'podcast_fcc', + podcast_frnthppyhr: 'podcast_frnthppyhr', + podcast_fullstckrd: 'podcast_fullstckrd', + podcast_geekspeak: 'podcast_geekspeak', + podcast_hanselmnts: 'podcast_hanselmnts', + podcast_js_jabber: 'podcast_js_jabber', + podcast_ltcwm: 'podcast_ltcwm', + podcast_other: 'podcast_other', + podcast_progthrwdwn: 'podcast_progthrwdwn', + podcast_rubyrogues: 'podcast_rubyrogues', + podcast_sedaily: 'podcast_sedaily', + podcast_seradio: 'podcast_seradio', + podcast_shoptalk: 'podcast_shoptalk', + podcast_syntaxfm: 'podcast_syntaxfm', + podcast_talkpythonme: 'podcast_talkpythonme', + reasons_to_code: 'reasons_to_code', + reasons_to_code_other: 'reasons_to_code_other', + rsrc_code_wars: 'rsrc_code_wars', + rsrc_codeacdm: 'rsrc_codeacdm', + rsrc_coursera: 'rsrc_coursera', + rsrc_css_tricks: 'rsrc_css_tricks', + rsrc_edx: 'rsrc_edx', + rsrc_egghead: 'rsrc_egghead', + rsrc_fcc: 'rsrc_fcc', + rsrc_frntendmstr: 'rsrc_frntendmstr', + rsrc_hackerrank: 'rsrc_hackerrank', + rsrc_khan_acdm: 'rsrc_khan_acdm', + rsrc_lynda: 'rsrc_lynda', + rsrc_mdn: 'rsrc_mdn', + rsrc_other: 'rsrc_other', + rsrc_so: 'rsrc_so', + rsrc_treehouse: 'rsrc_treehouse', + rsrc_udacity: 'rsrc_udacity', + rsrc_udemy: 'rsrc_udemy', + school_degree: 'school_degree', + school_major: 'school_major', + student_debt_amt: 'student_debt_amt', + student_debt_has: 'student_debt_has', + testing_count: 'Testing count', + time_end: 'time_end', + time_start: 'time_start', + time_total_sec: 'time_total_sec', + when_appl_job: 'when_appl_job', + willing_to_relocate: 'Willing To Relocate', + yt_codingtrain: 'yt_codingtrain', + yt_codingtuts360: 'yt_codingtuts360', + yt_computerphile: 'yt_computerphile', + yt_cs_dojo: 'yt_cs_dojo', + yt_derekbanas: 'yt_derekbanas', + yt_devtips: 'yt_devtips', + yt_engn_truth: 'yt_engn_truth', + yt_fcc: 'yt_fcc', + yt_funfunfunct: 'yt_funfunfunct', + yt_googledevs: 'yt_googledevs', + yt_learncodeacdm: 'yt_learncodeacdm', + yt_lvluptuts: 'yt_lvluptuts', + yt_mit_ocw: 'yt_mit_ocw', + yt_mozillahacks: 'yt_mozillahacks', + yt_other: 'yt_other', + yt_simpleprog: 'yt_simpleprog', + yt_simplilearn: 'yt_simplilearn', + }, + }, + + // Query results + queriesData: [ + { + cache_key: + '31d61dc7e361c5625b82735b41ebf8a9d9829f73d119057cdb94aea77120ec82', + cached_dttm: '2026-01-18T05:01:57', + queried_dttm: '2026-01-18T05:01:57+00:00', + cache_timeout: 300, + applied_template_filters: [], + annotation_data: {}, + error: null, + is_cached: true, + query: + "SELECT DATE_TRUNC('day', time_start) AS time_start, sum(money_for_learning) AS \"SUM(money_for_learning)\", COUNT(*) AS testing_count \nFROM main.\"FCC 2018 Survey\" \nWHERE time_start >= '2018-08-01 00:00:00.000000' AND time_start < '2026-01-17 00:00:00.000000' GROUP BY DATE_TRUNC('day', time_start) ORDER BY \"SUM(money_for_learning)\" DESC \n LIMIT 10000;\n\nSELECT DATE_TRUNC('day', time_start) AS time_start, sum(money_for_learning) AS \"SUM(money_for_learning)\", COUNT(*) AS testing_count \nFROM main.\"FCC 2018 Survey\" \nWHERE time_start >= '2018-07-31 00:00:00.000000' AND time_start < '2026-01-16 00:00:00.000000' AND time_start >= '2018-07-31 00:00:00.000000' AND time_start < '2026-01-16 00:00:00.000000' GROUP BY DATE_TRUNC('day', time_start) ORDER BY \"SUM(money_for_learning)\" DESC \n LIMIT 50000;\n\nSELECT DATE_TRUNC('day', time_start) AS time_start, sum(money_for_learning) AS \"SUM(money_for_learning)\", COUNT(*) AS testing_count \nFROM main.\"FCC 2018 Survey\" \nW HERE time_start >= '2018-07-25 00:00:00.000000' AND time_start < '2026-01-10 00:00:00.000000' AND time_start >= '2018-07-25 00:00:00.000000' AND time_start < '2026-01-10 00:00:00.000000' GROUP BY DATE_TRUNC('day', time_start) ORDER BY \"SUM(money_for_learning)\" DESC \n LIMIT 50000;\n\nSELECT DATE_TRUNC('day', time_start) AS time_start, sum(money_for_learning) AS \"SUM(money_for_learning)\", COUNT(*) AS testing_count \nFROM main.\"FCC 2018 Survey\" \nWHERE time_start >= '2017-08-01 00:00:00.000000' AND time_start < '2025-01-17 00:00:00.000000' AND time_start >= '2017-08-01 00:00:00.000000' AND time_start < '2025-01-17 00:00:00.000000' GROUP BY DATE_TRUNC('day', time_start) ORDER BY \"SUM(money_for_learning)\" DESC \n LIMIT 50000;\n\n", + status: 'success', + stacktrace: null, + rowcount: 85, + sql_rowcount: 85, + from_dttm: 1533081600000, + to_dttm: 1768608000000, + label_map: { + time_start: ['time_start'], + 'SUM(money_for_learning)': ['SUM(money_for_learning)'], + 'SUM(money_for_learning), 1 day ago': [ + 'SUM(money_for_learning)', + '1 day ago', + ], + 'SUM(money_for_learning), 1 week ago': [ + 'SUM(money_for_learning)', + '1 week ago', + ], + 'SUM(money_for_learning), 1 year ago': [ + 'SUM(money_for_learning)', + '1 year ago', + ], + testing_count: ['testing_count'], + 'testing_count, 1 day ago': ['testing_count', '1 day ago'], + 'testing_count, 1 week ago': ['testing_count', '1 week ago'], + 'testing_count, 1 year ago': ['testing_count', '1 year ago'], + 'Testing count': ['testing_count'], + }, + colnames: [ + 'time_start', + 'SUM(money_for_learning)', + 'SUM(money_for_learning), 1 day ago', + 'SUM(money_for_learning), 1 week ago', + 'SUM(money_for_learning), 1 year ago', + 'testing_count', + 'testing_count, 1 day ago', + 'testing_count, 1 week ago', + 'testing_count, 1 year ago', + ], + indexnames: [0, 1, 2], + coltypes: [2, 0, 0, 0, 1, 0, 0, 0, 1], + data: [ + { + time_start: 1533081600000, + 'SUM(money_for_learning)': 100, + 'SUM(money_for_learning), 1 day ago': null, + 'SUM(money_for_learning), 1 week ago': null, + 'SUM(money_for_learning), 1 year ago': null, + testing_count: 1, + 'testing_count, 1 day ago': null, + 'testing_count, 1 week ago': null, + 'testing_count, 1 year ago': null, + }, + { + time_start: 1533168000000, + 'SUM(money_for_learning)': 5790, + 'SUM(money_for_learning), 1 day ago': 100, + 'SUM(money_for_learning), 1 week ago': null, + 'SUM(money_for_learning), 1 year ago': null, + testing_count: 13, + 'testing_count, 1 day ago': 1, + 'testing_count, 1 week ago': null, + 'testing_count, 1 year ago': null, + }, + ], + result_format: 'json', + applied_filters: [ + { + column: 'time_start', + }, + ], + rejected_filters: [], + }, + ] as unknown as EchartsTimeseriesChartProps['queriesData'], + + // Filter and legend state + filterState: { + selectedValues: [], + }, + legendState: {}, + + // Form data (chart configuration) + formData: { + area: false, + annotationLayers: [], + colorScheme: 'supersetColors', + forecastEnabled: false, + groupby: [], + legendOrientation: LegendOrientation.Top, + legendType: LegendType.Scroll, + legendMargin: 0, + legendSort: null, + logAxis: false, + markerEnabled: false, + markerSize: 6, + metrics: [ + { + aggregate: 'SUM', + column: { + column_name: 'money_for_learning', + description: null, + expression: null, + filterable: true, + groupby: true, + id: 460, + is_dttm: false, + python_date_format: null, + type: 'DOUBLE PRECISION', + type_generic: 0, + verbose_name: null, + }, + expressionType: 'SIMPLE', + hasCustomLabel: false, + label: 'SUM(money_for_learning)', + optionName: 'metric_olnflt1ak9g_z1vjg3dhmnf', + }, + 'testing_count', + ], + minorSplitLine: false, + minorTicks: false, + onlyTotal: false, + opacity: 0.2, + orientation: OrientationType.Vertical, + percentageThreshold: 0, + richTooltip: true, + seriesType: EchartsTimeseriesSeriesType.Line, + showLegend: true, + showValue: false, + sliceId: 1, + sortSeriesType: 'name', + sortSeriesAscending: true, + forceMaxInterval: false, + timeCompare: [], + stack: null, + tooltipTimeFormat: '%Y-%m-%d', + tooltipSortByMetric: false, + showTooltipTotal: false, + showTooltipPercentage: false, + truncateXAxis: false, + truncateYAxis: false, + xAxis: 'ds', + xAxisBounds: [null, null], + xAxisForceCategorical: false, + xAxisLabelRotation: 0, + xAxisLabelInterval: 0, + xAxisSort: 'asc', + xAxisSortAsc: true, + xAxisTimeFormat: '%Y-%m-%d', + xAxisNumberFormat: '.3~s', + xAxisTitle: '', + xAxisTitleMargin: 0, + yAxisBounds: [null, null], + yAxisFormat: '.3~s', + currencyFormat: null, + yAxisTitle: '', + yAxisTitleMargin: 0, + yAxisTitlePosition: 'Left', + zoomable: false, + } as unknown as EchartsTimeseriesChartProps['formData'], + + // Hooks + hooks: { + setDataMask: () => {}, + setControlValue: () => {}, + onContextMenu: () => {}, + onLegendStateChanged: () => {}, + onLegendScroll: () => {}, + }, + + // UI state + inContextMenu: false, + emitCrossFilters: true, + legendIndex: 0, + + // Raw form data (needed for additional validation) + rawFormData: { + datasource: '1__table', + viz_type: 'echarts_timeseries', + x_axis: 'ds', + time_compare: [], + } as unknown as EchartsTimeseriesChartProps['rawFormData'], + + // Theme + theme: {}, +} as unknown as EchartsTimeseriesChartProps; + +describe('Timeseries transformProps', () => { + it('Should transform props correctly', () => { + const result = transformProps(mockedProps); + + expect(result.coltypeMapping).toEqual({ + 'SUM(money_for_learning)': 0, + 'SUM(money_for_learning), 1 day ago': 0, + 'SUM(money_for_learning), 1 week ago': 0, + 'SUM(money_for_learning), 1 year ago': 1, + testing_count: 0, + 'testing_count, 1 day ago': 0, + 'testing_count, 1 week ago': 0, + 'testing_count, 1 year ago': 1, + time_start: 2, + }); + + expect(result.legendData).toEqual([ + 'SUM(money_for_learning)', + 'SUM(money_for_learning), 1 day ago', + 'SUM(money_for_learning), 1 week ago', + 'SUM(money_for_learning), 1 year ago', + 'Testing count', + 'Testing count, 1 day ago', + 'Testing count, 1 week ago', + 'Testing count, 1 year ago', + 'time_start', + ]); + }); Review Comment: same as above -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
