@devtable/dashboard 14.44.5 → 14.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/components/plugins/viz-components/regression-chart/migrators/index.d.ts +1 -0
  2. package/dist/components/plugins/viz-components/regression-chart/render/chart.d.ts +9 -0
  3. package/dist/components/plugins/viz-components/regression-chart/{viz-regression-chart.d.ts → render/index.d.ts} +1 -1
  4. package/dist/components/plugins/viz-components/regression-chart/render/option/index.d.ts +3 -0
  5. package/dist/components/plugins/viz-components/regression-chart/{option → render/option}/regression-series.d.ts +2 -2
  6. package/dist/components/plugins/viz-components/regression-chart/render/option/series.d.ts +5 -0
  7. package/dist/components/plugins/viz-components/regression-chart/render/option/tooltip.d.ts +2 -0
  8. package/dist/components/plugins/viz-components/regression-chart/render/toolbox/choose-data-keys/choose-data-keys.d.ts +8 -0
  9. package/dist/components/plugins/viz-components/regression-chart/render/toolbox/choose-data-keys/index.d.ts +1 -0
  10. package/dist/components/plugins/viz-components/regression-chart/render/toolbox/data-key-selector/data-key-selector.d.ts +8 -0
  11. package/dist/components/plugins/viz-components/regression-chart/render/toolbox/data-key-selector/index.d.ts +1 -0
  12. package/dist/components/plugins/viz-components/regression-chart/render/toolbox/index.d.ts +16 -0
  13. package/dist/components/plugins/viz-components/regression-chart/{toolbox → render/toolbox}/regression-description/desc.d.ts +3 -2
  14. package/dist/components/plugins/viz-components/regression-chart/render/toolbox/regression-description/index.d.ts +10 -0
  15. package/dist/components/plugins/viz-components/regression-chart/render/use-data-key.d.ts +6 -0
  16. package/dist/components/plugins/viz-components/regression-chart/type.d.ts +1 -14
  17. package/dist/components/plugins/viz-components/regression-chart/viz-regression-chart-editor.d.ts +1 -1
  18. package/dist/dashboard.es.js +6654 -6670
  19. package/dist/dashboard.umd.js +70 -70
  20. package/dist/stats.html +1 -1
  21. package/dist/utils/data.d.ts +8 -9
  22. package/dist/version.json +2 -2
  23. package/package.json +1 -1
  24. package/dist/components/plugins/viz-components/regression-chart/editors/x-axis.d.ts +0 -8
  25. package/dist/components/plugins/viz-components/regression-chart/editors/y-axis.d.ts +0 -8
  26. package/dist/components/plugins/viz-components/regression-chart/option/index.d.ts +0 -2
  27. package/dist/components/plugins/viz-components/regression-chart/option/series.d.ts +0 -4
  28. package/dist/components/plugins/viz-components/regression-chart/option/tooltip.d.ts +0 -2
  29. package/dist/components/plugins/viz-components/regression-chart/option/x-axis.d.ts +0 -2
  30. package/dist/components/plugins/viz-components/regression-chart/toolbox/index.d.ts +0 -2
  31. package/dist/components/plugins/viz-components/regression-chart/toolbox/regression-description/index.d.ts +0 -6
@@ -1,12 +1,12 @@
1
- (function(C,Se){typeof exports=="object"&&typeof module<"u"?Se(exports,require("i18next"),require("react-i18next"),require("i18next-browser-languagedetector"),require("intl-pluralrules"),require("lodash"),require("mobx"),require("eventemitter2"),require("react/jsx-runtime"),require("react"),require("chroma-js"),require("echarts-for-react/lib/core"),require("echarts-gl"),require("echarts/core"),require("ahooks"),require("@mantine/core"),require("@mantine/hooks"),require("popmotion"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("crypto-js"),require("dayjs"),require("numbro"),require("@tabler/icons-react"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("@mantine/dates"),require("@monaco-editor/react"),require("@tiptap/core"),require("d3-scale"),require("react-hook-form"),require("mobx-react-lite"),require("@dnd-kit/helpers"),require("@dnd-kit/react"),require("@dnd-kit/react/sortable"),require("uuid"),require("echarts/charts"),require("echarts/components"),require("echarts/renderers"),require("constrained-editor-plugin"),require("@mantine/notifications"),require("@mantine/emotion"),require("d3-regression"),require("@mantine/code-highlight"),require("@tanstack/react-table"),require("@tanstack/react-virtual"),require("axios"),require("dayjs/plugin/advancedFormat"),require("dayjs/plugin/arraySupport"),require("dayjs/plugin/buddhistEra"),require("dayjs/plugin/calendar"),require("dayjs/plugin/customParseFormat"),require("dayjs/plugin/dayOfYear"),require("dayjs/plugin/duration"),require("dayjs/plugin/isBetween"),require("dayjs/plugin/isLeapYear"),require("dayjs/plugin/isMoment"),require("dayjs/plugin/isoWeek"),require("dayjs/plugin/isoWeeksInYear"),require("dayjs/plugin/isSameOrAfter"),require("dayjs/plugin/isSameOrBefore"),require("dayjs/plugin/isToday"),require("dayjs/plugin/isTomorrow"),require("dayjs/plugin/isYesterday"),require("dayjs/plugin/localeData"),require("dayjs/plugin/localizedFormat"),require("dayjs/plugin/minMax"),require("dayjs/plugin/objectSupport"),require("dayjs/plugin/pluralGetSet"),require("dayjs/plugin/preParsePostFormat"),require("dayjs/plugin/quarterOfYear"),require("dayjs/plugin/relativeTime"),require("dayjs/plugin/timezone"),require("dayjs/plugin/toArray"),require("dayjs/plugin/toObject"),require("dayjs/plugin/updateLocale"),require("dayjs/plugin/utc"),require("dayjs/plugin/weekday"),require("dayjs/plugin/weekOfYear"),require("dayjs/plugin/weekYear"),require("mobx-state-tree"),require("dom-to-image-more"),require("file-saver"),require("jszip"),require("@json2csv/whatwg"),require("js-base64"),require("rc-tree-select"),require("performant-array-to-tree"),require("rc-select"),require("@mantine/modals"),require("react-dom"),require("react-grid-layout"),require("react-router-dom"),require("@mantine/spotlight"),require("@mantine/spotlight/styles.css"),require("reactflow"),require("reactflow/dist/style.css")):typeof define=="function"&&define.amd?define(["exports","i18next","react-i18next","i18next-browser-languagedetector","intl-pluralrules","lodash","mobx","eventemitter2","react/jsx-runtime","react","chroma-js","echarts-for-react/lib/core","echarts-gl","echarts/core","ahooks","@mantine/core","@mantine/hooks","popmotion","d3-array","mathjs","@faker-js/faker","crypto-js","dayjs","numbro","@tabler/icons-react","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","@mantine/dates","@monaco-editor/react","@tiptap/core","d3-scale","react-hook-form","mobx-react-lite","@dnd-kit/helpers","@dnd-kit/react","@dnd-kit/react/sortable","uuid","echarts/charts","echarts/components","echarts/renderers","constrained-editor-plugin","@mantine/notifications","@mantine/emotion","d3-regression","@mantine/code-highlight","@tanstack/react-table","@tanstack/react-virtual","axios","dayjs/plugin/advancedFormat","dayjs/plugin/arraySupport","dayjs/plugin/buddhistEra","dayjs/plugin/calendar","dayjs/plugin/customParseFormat","dayjs/plugin/dayOfYear","dayjs/plugin/duration","dayjs/plugin/isBetween","dayjs/plugin/isLeapYear","dayjs/plugin/isMoment","dayjs/plugin/isoWeek","dayjs/plugin/isoWeeksInYear","dayjs/plugin/isSameOrAfter","dayjs/plugin/isSameOrBefore","dayjs/plugin/isToday","dayjs/plugin/isTomorrow","dayjs/plugin/isYesterday","dayjs/plugin/localeData","dayjs/plugin/localizedFormat","dayjs/plugin/minMax","dayjs/plugin/objectSupport","dayjs/plugin/pluralGetSet","dayjs/plugin/preParsePostFormat","dayjs/plugin/quarterOfYear","dayjs/plugin/relativeTime","dayjs/plugin/timezone","dayjs/plugin/toArray","dayjs/plugin/toObject","dayjs/plugin/updateLocale","dayjs/plugin/utc","dayjs/plugin/weekday","dayjs/plugin/weekOfYear","dayjs/plugin/weekYear","mobx-state-tree","dom-to-image-more","file-saver","jszip","@json2csv/whatwg","js-base64","rc-tree-select","performant-array-to-tree","rc-select","@mantine/modals","react-dom","react-grid-layout","react-router-dom","@mantine/spotlight","@mantine/spotlight/styles.css","reactflow","reactflow/dist/style.css"],Se):(C=typeof globalThis<"u"?globalThis:C||self,Se(C.dashboard={},C.i18next,C["react-i18next"],C["i18next-browser-languagedetector"],C["intl-pluralrules"],C._,C.mobx,C.eventemitter2,C["react/jsx-runtime"],C.react,C["chroma-js"],C["echarts-for-react/lib/core"],C["echarts-gl"],C["echarts/core"],C.ahooks,C["@mantine/core"],C["@mantine/hooks"],C.popmotion,C["d3-array"],C.mathjs,C["@faker-js/faker"],C.CryptoJS,C.dayjs,C.numbro,C["@tabler/icons-react"],C["@mantine/tiptap"],C["@tiptap/extension-color"],C["@tiptap/extension-highlight"],C["@tiptap/extension-placeholder"],C["@tiptap/extension-subscript"],C["@tiptap/extension-superscript"],C["@tiptap/extension-table"],C["@tiptap/extension-table-cell"],C["@tiptap/extension-table-header"],C["@tiptap/extension-table-row"],C["@tiptap/extension-text-align"],C["@tiptap/extension-text-style"],C["@tiptap/extension-underline"],C["@tiptap/react"],C["@tiptap/starter-kit"],C["@mantine/dates"],C["@monaco-editor/react"],C["@tiptap/core"],C["d3-scale"],C["react-hook-form"],C["mobx-react-lite"],C["@dnd-kit/helpers"],C["@dnd-kit/react"],C["@dnd-kit/react/sortable"],C.uuid,C["echarts/charts"],C["echarts/components"],C["echarts/renderers"],C["constrained-editor-plugin"],C["@mantine/notifications"],C["@mantine/emotion"],C["d3-regression"],C["@mantine/code-highlight"],C["@tanstack/react-table"],C["@tanstack/react-virtual"],C.axios,C["dayjs/plugin/advancedFormat"],C["dayjs/plugin/arraySupport"],C["dayjs/plugin/buddhistEra"],C["dayjs/plugin/calendar"],C["dayjs/plugin/customParseFormat"],C["dayjs/plugin/dayOfYear"],C["dayjs/plugin/duration"],C["dayjs/plugin/isBetween"],C["dayjs/plugin/isLeapYear"],C["dayjs/plugin/isMoment"],C["dayjs/plugin/isoWeek"],C["dayjs/plugin/isoWeeksInYear"],C["dayjs/plugin/isSameOrAfter"],C["dayjs/plugin/isSameOrBefore"],C["dayjs/plugin/isToday"],C["dayjs/plugin/isTomorrow"],C["dayjs/plugin/isYesterday"],C["dayjs/plugin/localeData"],C["dayjs/plugin/localizedFormat"],C["dayjs/plugin/minMax"],C["dayjs/plugin/objectSupport"],C["dayjs/plugin/pluralGetSet"],C["dayjs/plugin/preParsePostFormat"],C["dayjs/plugin/quarterOfYear"],C["dayjs/plugin/relativeTime"],C["dayjs/plugin/timezone"],C["dayjs/plugin/toArray"],C["dayjs/plugin/toObject"],C["dayjs/plugin/updateLocale"],C["dayjs/plugin/utc"],C["dayjs/plugin/weekday"],C["dayjs/plugin/weekOfYear"],C["dayjs/plugin/weekYear"],C["mobx-state-tree"],C["dom-to-image-more"],C["file-saver"],C.jszip,C["@json2csv/whatwg"],C["js-base64"],C["rc-tree-select"],C["performant-array-to-tree"],C["rc-select"],C["@mantine/modals"],C["react-dom"],C["react-grid-layout"],C["react-router-dom"],C["@mantine/spotlight"],C["@mantine/spotlight/styles"].css,C.reactflow))})(this,function(C,Se,x,td,LD,y,Q,Xa,n,h,qe,he,qD,Za,O,s,te,ot,qt,nd,rd,Ja,M,Ye,S,G,Ha,Ra,es,ts,ns,rs,as,ss,ls,os,is,cs,ds,us,ps,Te,En,ad,b,T,hs,Bn,Ln,Ke,Xe,ct,sd,ld,Ze,dt,od,Oe,ge,id,ke,cd,dd,ud,pd,hd,gd,fd,bd,yd,vd,_d,xd,wd,md,Cd,Sd,Td,kd,zd,Dd,Id,Md,Ad,Pd,Vd,$d,Ed,Bd,Ld,qd,Od,Nd,Gd,g,gs,Xt,fs,Fd,bs,qn,jd,ys,ze,Qd,Zt,Wd,vt,OD,ie){"use strict";var ED=Object.defineProperty;var BD=(C,Se,x)=>Se in C?ED(C,Se,{enumerable:!0,configurable:!0,writable:!0,value:x}):C[Se]=x;var P=(C,Se,x)=>(BD(C,typeof Se!="symbol"?Se+"":Se,x),x);function _t(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const ce=_t(Za),Ud=_t(ot),vs=_t(qt),Ne=_t(nd),Yd=_t(Ja),Kd=_t(ad),ut=_t(od),Xd={translation:{filter:{label:"Filter",labels:"Filters",add:"Add a Filter",manage:"Manage Filters",delete:"Delete this filter",show_filters:"Show Filters",hide_filters:"Hide Filters",usage:{label:"Usage",unused_description:"This filter is not used by any query, SQL snippet or view"},field:{widget:"Widget",visible_in:"Visible in...",key_placeholder:"A unique key to refer",label_placeholder:"Label for this field",auto_submit:"Submit automatically",order:"Placement Order",custom_default_value:{trigger:"Custom default value",title:"Custom default value",tips:"Tips",tip_1:"Function has the highest priority of getting filter's default value",tip_2:"Leave this editor empty to disable this feature"}},widget:{names:{select:"Select",multi_select:"Multi Select",tree_select:"Tree Select",tree_single_select:"Tree Single Select",text_input:"Text Input",checkbox:"Checkbox",date_range:"Date Range"},common:{use_query_data_as_options:"Use query data as options",fetch_options_from_datasource:"Fetch options from datasource",or_fetch_options_from_datasource:"Or fetch options from datasource",selector_option_empty:"Not found",see_data_structure:"Click to see expected data structure",using_query:"Using query",default_selection_count:"Select first N options by default",min_width:"Min width",x_selected:"{{count}} selected",default_value_mode:{label:"When options change",intersect:"Preserve valid entries from current selection",reset:"Use new options"}},text_input:{default_value:"Default Value",required:"Required"},select:{width:"Width",required:"Required",clearable:"Clearable",configure_options:"Configure options",default_selection:"Default Selection",no_default_selection:"none",select_first_option_by_default:"Select the first option by default",preset_options:{apply:"Apply preset options",date_unit:"Date units"}},multi_select:{width_description:"At least 160px"},tree_select:{strictly:"Parent and children nodes are not associated"},tree_single_select:{select_first_option_by_default:"Select the first option by default"},checkbox:{description:"Description",default_checked:"Default checked"},date_range:{required:"Required",allow_single_date:"Allow choosing 1 day",display_format:"Display format",max_days:"Max days",one_day:"1 day",x_days:"{{count}} days",x_max_days:"{{max_days}} days max",default_value:"Default value",default_by_shortcut:"Default by shortcut",default_by_shortcut_placeholder:"Priors default value",start_date:"Start date",end_date:"End date",shortcut:{last:{label:"last",d:"yesterday",w:"week",m:"month",m2:"2 months",m3:"3 months",y:"year",full:{d:"yesterday",w:"last week",m:"last month",m2:"last 2 months",m3:"last 3 months",y:"last year"}},recent:{label:"recent",d7:"7 days",d30:"30 days",d60:"60 days",d90:"90 days",d180:"180 days",d365:"365 days",full:{d7:"recent 7 days",d30:"recent 30 days",d60:"recent 60 days",d90:"recent 90 days",d180:"recent 180 days",d365:"recent 365 days"}},this:{label:"this",d:"today",w:"week",m:"month",y:"year",full:{d:"today",w:"this week",m:"this month",y:"this year"}},this_so_far:{label:"this...so far",w:"week",m:"month",y:"year",full:{w:"this week so far",m:"this month so far",y:"this year so far"}}}}}},view:{label:"View",labels:"Views",add:"Add a View",delete:"Delete this View",download_schema:"Download this View",component:{div:{label:"Division"},tabs:{label:"Tabs",tabs_settings:"Tabs Settings",tab:{name:"Tab Name",view:"View",order:"Placement Order",color:"Color",delete:"Delete this tab",switch_to_view:"Swith to View: {{name}}"}},modal:{label:"Modal",modal_settings:"Modal settings",title:"Modal Title",custom_title:"Customize modal title",width:"Width",height:"Height"}}},interactions:{label:"Interactions",add:"Add an interaction",interactions_viewer:"Interactions Viewer",unavailable:"Unavailable",unavailable_reason:"This visualization does not have available interactions to choose from",trigger:{setup:"Setup Trigger",label:"Trigger",payload:"Payload"},operation:{setup:"Operation Settings",label:"Operation",settings:"Settings",variables:"Variables",console_log:{label:"console.log | debug",log_content:"log content"},open_link:{label:"Open Link",url:"URL",open_in_new_tab:"Open in new tab"},open_view:{label:"Open View",view:"View"},switch_tab:{label:"Switch Tab",view:"View",tab:"Tab"},scroll_to_panel:{label:"Scroll to Panel",panel:"Panel"},set_filter_values:{label:"Set Filter Values",set_filter:"Set filter",with:"with"},clear_filter_values:{label:"Clear Filter Values",select_filter:"Select filters to clear"}}},query_variable:{label:"Query Variable",labels:"Query Variables",add:"Add a Variable",guide:{tabs:{guide:"Guide",variables_in_this_dashboard:"Variables in this dashboard",global_sql_snippets:"Global SQL Snippets"}},open:"See Query Variables"},sql_snippet:{label:"SQL Snippet",labels:"SQL Snippets",add:"Add a SQL Snippet",delete:"Delete this SQL Snippet",delete_unused:"Delete unused SQL Snippets",manage:"Manage SQL Snippets",key:"Key",key_occupied:"This key is occupied by another snippet",edit_snippet:"Edit SQL Snippet",preview_snippet:"Preview SQL Snippet",usage:{label:"Usage"}},global_sql_snippet:{label:"Global SQL Snippet",labels:"Global SQL Snippets",description:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."},common:{titles:{settings:"Settings",edit:"Edit",config:"Config"},pagination:{label:"Pagination",page_size:"Page Size",total:"Total",total_rows:"Total {{total}} row(s)",to_previous_page:"To previous page",to_next_page:"To next page",showing_rows:"Showing {{start_row}} - {{end_row}} of {{total}} rows"},align:{horizontal:{label:"Horizontal Align",left:"left",center:"center",right:"right"},vertical:{label:"Vertical Align",top:"top",center:"center",bottom:"bottom"}},id:"ID",name:"Name",key:"Key",label:"Label",value:"Value",type:"Type",info:"Info",min:"Min",max:"Max",invalid:"Invalid",data_field:"Data Field",name_data_field:"Name Data Field",value_data_field:"Value Data Field",color_data_field:"Color Data Field",enabled:"Enabled",copied:"Copied to clipboard",action:"Action",actions:{search:"Search",reload:"Reload",actions:"Actions",open:"Open",close:"Close",save:"Save",save_changes:"Save Changes",revert:"Revert",revert_changes:"Revert Changes",reset_to_default:"Reset to default",init_with_default:"Init with default",select_all:"Select All",clear:"Clear",clear_selection:"Clear Selection",refresh:"Refresh",download_data:"Download Data",download_schema:"Download Schema",download_screenshot:"Screenshot",enter_fullscreen:"Full Screen",duplicate:"Duplicate",delete:"Delete",cancel:"Cancel",confirm:"Confirm",add_an_option:"Add an Option",edit:"Edit",end_editing:"End editing <0>{{name}}</0>"},tabs:{variant:{label:"Variant",default:"Default",outline:"Outline",pills:"Pills"},orientation:{label:"Orientation",horizontal:"Horizontal",vertical:"Vertical"},grow_tabs:"Grow Tabs"},choose_a_tab_first:"Please choose a tab first"},breakpoint:{label_one:"Screen size",label_other:"Screen sizes",add:"Add a screen size",manage:"Manage screen sizes",breakpoint:"Min Width"},context:{label:"Context"},mock_context:{label:"Mock Context",hint:"A valid json string is required"},panel:{label:"Panel",labels:"Panels",add:"Add a Panel",delete:"Delete This Panel",panel_name:"Panel Name",panel_description:"Description",panel_description_click:"Click to see description",show_title:"Show title",use_name_as_title:"Use name as title",settings:{change_view:"Move into Another View",change_view_title:"Move panel into another view",choose_queries:"Choose queries",need_to_choose_queries:"Choose at least 1 query for its data"},style:{label:"Style",width:"Width",width_postfix:"of 36 columns",height:"Height",height_postfix:"px",border:"Border"},variable:{label:"Variable",labels:"Variables",add:"Add a Variable",delete:"Delete this Variable",aggregation:{label:"Aggregation",fallback_value:"Fallback Value",fallback_value_description:"Used when data is empty or the aggregation yields NaN"},guide:{text:`-- You may reference dashboard state & panel variables in rich-text content or custom functions.
1
+ (function(C,me){typeof exports=="object"&&typeof module<"u"?me(exports,require("i18next"),require("react-i18next"),require("i18next-browser-languagedetector"),require("intl-pluralrules"),require("lodash"),require("mobx"),require("eventemitter2"),require("react/jsx-runtime"),require("react"),require("chroma-js"),require("echarts-for-react/lib/core"),require("echarts-gl"),require("echarts/core"),require("ahooks"),require("@mantine/core"),require("@mantine/hooks"),require("popmotion"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("crypto-js"),require("dayjs"),require("numbro"),require("@tabler/icons-react"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("@mantine/dates"),require("@monaco-editor/react"),require("@tiptap/core"),require("d3-scale"),require("react-hook-form"),require("mobx-react-lite"),require("@dnd-kit/helpers"),require("@dnd-kit/react"),require("@dnd-kit/react/sortable"),require("uuid"),require("echarts/charts"),require("echarts/components"),require("echarts/renderers"),require("constrained-editor-plugin"),require("@mantine/notifications"),require("@mantine/emotion"),require("d3-regression"),require("@mantine/code-highlight"),require("@tanstack/react-table"),require("@tanstack/react-virtual"),require("axios"),require("dayjs/plugin/advancedFormat"),require("dayjs/plugin/arraySupport"),require("dayjs/plugin/buddhistEra"),require("dayjs/plugin/calendar"),require("dayjs/plugin/customParseFormat"),require("dayjs/plugin/dayOfYear"),require("dayjs/plugin/duration"),require("dayjs/plugin/isBetween"),require("dayjs/plugin/isLeapYear"),require("dayjs/plugin/isMoment"),require("dayjs/plugin/isoWeek"),require("dayjs/plugin/isoWeeksInYear"),require("dayjs/plugin/isSameOrAfter"),require("dayjs/plugin/isSameOrBefore"),require("dayjs/plugin/isToday"),require("dayjs/plugin/isTomorrow"),require("dayjs/plugin/isYesterday"),require("dayjs/plugin/localeData"),require("dayjs/plugin/localizedFormat"),require("dayjs/plugin/minMax"),require("dayjs/plugin/objectSupport"),require("dayjs/plugin/pluralGetSet"),require("dayjs/plugin/preParsePostFormat"),require("dayjs/plugin/quarterOfYear"),require("dayjs/plugin/relativeTime"),require("dayjs/plugin/timezone"),require("dayjs/plugin/toArray"),require("dayjs/plugin/toObject"),require("dayjs/plugin/updateLocale"),require("dayjs/plugin/utc"),require("dayjs/plugin/weekday"),require("dayjs/plugin/weekOfYear"),require("dayjs/plugin/weekYear"),require("mobx-state-tree"),require("dom-to-image-more"),require("file-saver"),require("jszip"),require("@json2csv/whatwg"),require("js-base64"),require("rc-tree-select"),require("performant-array-to-tree"),require("rc-select"),require("@mantine/modals"),require("react-dom"),require("react-grid-layout"),require("react-router-dom"),require("@mantine/spotlight"),require("@mantine/spotlight/styles.css"),require("reactflow"),require("reactflow/dist/style.css")):typeof define=="function"&&define.amd?define(["exports","i18next","react-i18next","i18next-browser-languagedetector","intl-pluralrules","lodash","mobx","eventemitter2","react/jsx-runtime","react","chroma-js","echarts-for-react/lib/core","echarts-gl","echarts/core","ahooks","@mantine/core","@mantine/hooks","popmotion","d3-array","mathjs","@faker-js/faker","crypto-js","dayjs","numbro","@tabler/icons-react","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","@mantine/dates","@monaco-editor/react","@tiptap/core","d3-scale","react-hook-form","mobx-react-lite","@dnd-kit/helpers","@dnd-kit/react","@dnd-kit/react/sortable","uuid","echarts/charts","echarts/components","echarts/renderers","constrained-editor-plugin","@mantine/notifications","@mantine/emotion","d3-regression","@mantine/code-highlight","@tanstack/react-table","@tanstack/react-virtual","axios","dayjs/plugin/advancedFormat","dayjs/plugin/arraySupport","dayjs/plugin/buddhistEra","dayjs/plugin/calendar","dayjs/plugin/customParseFormat","dayjs/plugin/dayOfYear","dayjs/plugin/duration","dayjs/plugin/isBetween","dayjs/plugin/isLeapYear","dayjs/plugin/isMoment","dayjs/plugin/isoWeek","dayjs/plugin/isoWeeksInYear","dayjs/plugin/isSameOrAfter","dayjs/plugin/isSameOrBefore","dayjs/plugin/isToday","dayjs/plugin/isTomorrow","dayjs/plugin/isYesterday","dayjs/plugin/localeData","dayjs/plugin/localizedFormat","dayjs/plugin/minMax","dayjs/plugin/objectSupport","dayjs/plugin/pluralGetSet","dayjs/plugin/preParsePostFormat","dayjs/plugin/quarterOfYear","dayjs/plugin/relativeTime","dayjs/plugin/timezone","dayjs/plugin/toArray","dayjs/plugin/toObject","dayjs/plugin/updateLocale","dayjs/plugin/utc","dayjs/plugin/weekday","dayjs/plugin/weekOfYear","dayjs/plugin/weekYear","mobx-state-tree","dom-to-image-more","file-saver","jszip","@json2csv/whatwg","js-base64","rc-tree-select","performant-array-to-tree","rc-select","@mantine/modals","react-dom","react-grid-layout","react-router-dom","@mantine/spotlight","@mantine/spotlight/styles.css","reactflow","reactflow/dist/style.css"],me):(C=typeof globalThis<"u"?globalThis:C||self,me(C.dashboard={},C.i18next,C["react-i18next"],C["i18next-browser-languagedetector"],C["intl-pluralrules"],C._,C.mobx,C.eventemitter2,C["react/jsx-runtime"],C.react,C["chroma-js"],C["echarts-for-react/lib/core"],C["echarts-gl"],C["echarts/core"],C.ahooks,C["@mantine/core"],C["@mantine/hooks"],C.popmotion,C["d3-array"],C.mathjs,C["@faker-js/faker"],C.CryptoJS,C.dayjs,C.numbro,C["@tabler/icons-react"],C["@mantine/tiptap"],C["@tiptap/extension-color"],C["@tiptap/extension-highlight"],C["@tiptap/extension-placeholder"],C["@tiptap/extension-subscript"],C["@tiptap/extension-superscript"],C["@tiptap/extension-table"],C["@tiptap/extension-table-cell"],C["@tiptap/extension-table-header"],C["@tiptap/extension-table-row"],C["@tiptap/extension-text-align"],C["@tiptap/extension-text-style"],C["@tiptap/extension-underline"],C["@tiptap/react"],C["@tiptap/starter-kit"],C["@mantine/dates"],C["@monaco-editor/react"],C["@tiptap/core"],C["d3-scale"],C["react-hook-form"],C["mobx-react-lite"],C["@dnd-kit/helpers"],C["@dnd-kit/react"],C["@dnd-kit/react/sortable"],C.uuid,C["echarts/charts"],C["echarts/components"],C["echarts/renderers"],C["constrained-editor-plugin"],C["@mantine/notifications"],C["@mantine/emotion"],C["d3-regression"],C["@mantine/code-highlight"],C["@tanstack/react-table"],C["@tanstack/react-virtual"],C.axios,C["dayjs/plugin/advancedFormat"],C["dayjs/plugin/arraySupport"],C["dayjs/plugin/buddhistEra"],C["dayjs/plugin/calendar"],C["dayjs/plugin/customParseFormat"],C["dayjs/plugin/dayOfYear"],C["dayjs/plugin/duration"],C["dayjs/plugin/isBetween"],C["dayjs/plugin/isLeapYear"],C["dayjs/plugin/isMoment"],C["dayjs/plugin/isoWeek"],C["dayjs/plugin/isoWeeksInYear"],C["dayjs/plugin/isSameOrAfter"],C["dayjs/plugin/isSameOrBefore"],C["dayjs/plugin/isToday"],C["dayjs/plugin/isTomorrow"],C["dayjs/plugin/isYesterday"],C["dayjs/plugin/localeData"],C["dayjs/plugin/localizedFormat"],C["dayjs/plugin/minMax"],C["dayjs/plugin/objectSupport"],C["dayjs/plugin/pluralGetSet"],C["dayjs/plugin/preParsePostFormat"],C["dayjs/plugin/quarterOfYear"],C["dayjs/plugin/relativeTime"],C["dayjs/plugin/timezone"],C["dayjs/plugin/toArray"],C["dayjs/plugin/toObject"],C["dayjs/plugin/updateLocale"],C["dayjs/plugin/utc"],C["dayjs/plugin/weekday"],C["dayjs/plugin/weekOfYear"],C["dayjs/plugin/weekYear"],C["mobx-state-tree"],C["dom-to-image-more"],C["file-saver"],C.jszip,C["@json2csv/whatwg"],C["js-base64"],C["rc-tree-select"],C["performant-array-to-tree"],C["rc-select"],C["@mantine/modals"],C["react-dom"],C["react-grid-layout"],C["react-router-dom"],C["@mantine/spotlight"],C["@mantine/spotlight/styles"].css,C.reactflow))})(this,function(C,me,x,ad,N3,y,Q,Za,n,h,Be,he,G3,Ja,O,s,ne,ot,qt,sd,ld,Ha,M,We,S,G,Ra,es,ts,ns,rs,as,ss,ls,os,is,cs,ds,us,ps,hs,Ce,En,od,b,T,gs,Bn,Ln,Ue,Ke,ct,id,cd,Ye,dt,dd,Le,ge,ud,Se,pd,hd,gd,fd,bd,yd,vd,_d,xd,wd,md,Cd,Sd,Td,kd,zd,Dd,Id,Md,Vd,Pd,Ad,$d,Ed,Bd,Ld,qd,Od,Nd,Gd,Fd,jd,Qd,g,fs,Xt,bs,Wd,ys,qn,Ud,vs,Te,Kd,Zt,Yd,vt,F3,oe){"use strict";var q3=Object.defineProperty;var O3=(C,me,x)=>me in C?q3(C,me,{enumerable:!0,configurable:!0,writable:!0,value:x}):C[me]=x;var V=(C,me,x)=>(O3(C,typeof me!="symbol"?me+"":me,x),x);function _t(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const ie=_t(Ja),Xd=_t(ot),_s=_t(qt),qe=_t(sd),Zd=_t(Ha),Jd=_t(od),ut=_t(dd),Hd={translation:{filter:{label:"Filter",labels:"Filters",add:"Add a Filter",manage:"Manage Filters",delete:"Delete this filter",show_filters:"Show Filters",hide_filters:"Hide Filters",usage:{label:"Usage",unused_description:"This filter is not used by any query, SQL snippet or view"},field:{widget:"Widget",visible_in:"Visible in...",key_placeholder:"A unique key to refer",label_placeholder:"Label for this field",auto_submit:"Submit automatically",order:"Placement Order",custom_default_value:{trigger:"Custom default value",title:"Custom default value",tips:"Tips",tip_1:"Function has the highest priority of getting filter's default value",tip_2:"Leave this editor empty to disable this feature"}},widget:{names:{select:"Select",multi_select:"Multi Select",tree_select:"Tree Select",tree_single_select:"Tree Single Select",text_input:"Text Input",checkbox:"Checkbox",date_range:"Date Range"},common:{use_query_data_as_options:"Use query data as options",fetch_options_from_datasource:"Fetch options from datasource",or_fetch_options_from_datasource:"Or fetch options from datasource",selector_option_empty:"Not found",see_data_structure:"Click to see expected data structure",using_query:"Using query",default_selection_count:"Select first N options by default",min_width:"Min width",x_selected:"{{count}} selected",default_value_mode:{label:"When options change",intersect:"Preserve valid entries from current selection",reset:"Use new options"}},text_input:{default_value:"Default Value",required:"Required"},select:{width:"Width",required:"Required",clearable:"Clearable",configure_options:"Configure options",default_selection:"Default Selection",no_default_selection:"none",select_first_option_by_default:"Select the first option by default",preset_options:{apply:"Apply preset options",date_unit:"Date units"}},multi_select:{width_description:"At least 160px"},tree_select:{strictly:"Parent and children nodes are not associated"},tree_single_select:{select_first_option_by_default:"Select the first option by default"},checkbox:{description:"Description",default_checked:"Default checked"},date_range:{required:"Required",allow_single_date:"Allow choosing 1 day",display_format:"Display format",max_days:"Max days",one_day:"1 day",x_days:"{{count}} days",x_max_days:"{{max_days}} days max",default_value:"Default value",default_by_shortcut:"Default by shortcut",default_by_shortcut_placeholder:"Priors default value",start_date:"Start date",end_date:"End date",shortcut:{last:{label:"last",d:"yesterday",w:"week",m:"month",m2:"2 months",m3:"3 months",y:"year",full:{d:"yesterday",w:"last week",m:"last month",m2:"last 2 months",m3:"last 3 months",y:"last year"}},recent:{label:"recent",d7:"7 days",d30:"30 days",d60:"60 days",d90:"90 days",d180:"180 days",d365:"365 days",full:{d7:"recent 7 days",d30:"recent 30 days",d60:"recent 60 days",d90:"recent 90 days",d180:"recent 180 days",d365:"recent 365 days"}},this:{label:"this",d:"today",w:"week",m:"month",y:"year",full:{d:"today",w:"this week",m:"this month",y:"this year"}},this_so_far:{label:"this...so far",w:"week",m:"month",y:"year",full:{w:"this week so far",m:"this month so far",y:"this year so far"}}}}}},view:{label:"View",labels:"Views",add:"Add a View",delete:"Delete this View",download_schema:"Download this View",component:{div:{label:"Division"},tabs:{label:"Tabs",tabs_settings:"Tabs Settings",tab:{name:"Tab Name",view:"View",order:"Placement Order",color:"Color",delete:"Delete this tab",switch_to_view:"Swith to View: {{name}}"}},modal:{label:"Modal",modal_settings:"Modal settings",title:"Modal Title",custom_title:"Customize modal title",width:"Width",height:"Height"}}},interactions:{label:"Interactions",add:"Add an interaction",interactions_viewer:"Interactions Viewer",unavailable:"Unavailable",unavailable_reason:"This visualization does not have available interactions to choose from",trigger:{setup:"Setup Trigger",label:"Trigger",payload:"Payload"},operation:{setup:"Operation Settings",label:"Operation",settings:"Settings",variables:"Variables",console_log:{label:"console.log | debug",log_content:"log content"},open_link:{label:"Open Link",url:"URL",open_in_new_tab:"Open in new tab"},open_view:{label:"Open View",view:"View"},switch_tab:{label:"Switch Tab",view:"View",tab:"Tab"},scroll_to_panel:{label:"Scroll to Panel",panel:"Panel"},set_filter_values:{label:"Set Filter Values",set_filter:"Set filter",with:"with"},clear_filter_values:{label:"Clear Filter Values",select_filter:"Select filters to clear"}}},query_variable:{label:"Query Variable",labels:"Query Variables",add:"Add a Variable",guide:{tabs:{guide:"Guide",variables_in_this_dashboard:"Variables in this dashboard",global_sql_snippets:"Global SQL Snippets"}},open:"See Query Variables"},sql_snippet:{label:"SQL Snippet",labels:"SQL Snippets",add:"Add a SQL Snippet",delete:"Delete this SQL Snippet",delete_unused:"Delete unused SQL Snippets",manage:"Manage SQL Snippets",key:"Key",key_occupied:"This key is occupied by another snippet",edit_snippet:"Edit SQL Snippet",preview_snippet:"Preview SQL Snippet",usage:{label:"Usage"}},global_sql_snippet:{label:"Global SQL Snippet",labels:"Global SQL Snippets",description:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."},common:{titles:{settings:"Settings",edit:"Edit",config:"Config"},pagination:{label:"Pagination",page_size:"Page Size",total:"Total",total_rows:"Total {{total}} row(s)",to_previous_page:"To previous page",to_next_page:"To next page",showing_rows:"Showing {{start_row}} - {{end_row}} of {{total}} rows"},align:{horizontal:{label:"Horizontal Align",left:"left",center:"center",right:"right"},vertical:{label:"Vertical Align",top:"top",center:"center",bottom:"bottom"}},id:"ID",name:"Name",key:"Key",label:"Label",value:"Value",type:"Type",info:"Info",min:"Min",max:"Max",invalid:"Invalid",data_field:"Data Field",name_data_field:"Name Data Field",value_data_field:"Value Data Field",color_data_field:"Color Data Field",enabled:"Enabled",copied:"Copied to clipboard",action:"Action",actions:{search:"Search",reload:"Reload",actions:"Actions",open:"Open",close:"Close",save:"Save",save_changes:"Save Changes",revert:"Revert",revert_changes:"Revert Changes",reset_to_default:"Reset to default",init_with_default:"Init with default",select_all:"Select All",clear:"Clear",clear_selection:"Clear Selection",refresh:"Refresh",download_data:"Download Data",download_schema:"Download Schema",download_screenshot:"Screenshot",enter_fullscreen:"Full Screen",duplicate:"Duplicate",delete:"Delete",cancel:"Cancel",confirm:"Confirm",add_an_option:"Add an Option",edit:"Edit",end_editing:"End editing <0>{{name}}</0>"},tabs:{variant:{label:"Variant",default:"Default",outline:"Outline",pills:"Pills"},orientation:{label:"Orientation",horizontal:"Horizontal",vertical:"Vertical"},grow_tabs:"Grow Tabs"},choose_a_tab_first:"Please choose a tab first"},breakpoint:{label_one:"Screen size",label_other:"Screen sizes",add:"Add a screen size",manage:"Manage screen sizes",breakpoint:"Min Width"},context:{label:"Context"},mock_context:{label:"Mock Context",hint:"A valid json string is required"},panel:{label:"Panel",labels:"Panels",add:"Add a Panel",delete:"Delete This Panel",panel_name:"Panel Name",panel_description:"Description",panel_description_click:"Click to see description",show_title:"Show title",use_name_as_title:"Use name as title",settings:{change_view:"Move into Another View",change_view_title:"Move panel into another view",choose_queries:"Choose queries",need_to_choose_queries:"Choose at least 1 query for its data"},style:{label:"Style",width:"Width",width_postfix:"of 36 columns",height:"Height",height_postfix:"px",border:"Border"},variable:{label:"Variable",labels:"Variables",add:"Add a Variable",delete:"Delete this Variable",aggregation:{label:"Aggregation",fallback_value:"Fallback Value",fallback_value_description:"Used when data is empty or the aggregation yields NaN"},guide:{text:`-- You may reference dashboard state & panel variables in rich-text content or custom functions.
2
2
  -- use double curly brackets to wrap code in rich-text content.
3
3
  Project ID: {{ context.project_id }}
4
4
  Keyword: {{ filters.keyword }}
5
- Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel variables"}}}},style:{label:"Style",font_size:{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%..."},font_weight:{label:"Font Weight"},size:{xs:"xs",sm:"sm",md:"md",lg:"lg",xl:"xl"},flex:{justify_content:{label:"Justify Content",left:"Left",center:"Center",right:"Right",space_between:"Space Between",space_around:"Space Around",space_evenly:"Space Evenly"},align_items:{label:"Align Items",start:"Start",center:"Center",end:"End",stretch:"Stretch"}},color:{type:{label:"Color Type",static:"Static",interpolation:"Interpolation",none:"None"},interpolation:{setup:"Setup color interpolation",palette:{label:"Palette",category:{sequential:"Sequential",diverging:"Diverging"},red_green:"Red / Green",yellow_blue:"Yellow / Blue",red:"Red",green:"Green",blue:"Blue",orange:"Orange",mapping:{value_input_label:"Map a value to this color"}}}}},query:{label:"Query",labels:"Queries",add:"Add a Query",delete:"Delete this Query",cant_delete:"Can't delete this query for it's being used, check out Usage tab for details",delete_unused:"Delete unused queries",name:"Name",name_description:"A unique name",manage:"Manage Queries",open:"Open this query",configurations:"Configurations",basics:"Basics",conditions:"Conditions",run_by_condition:{label:"Run query when these are truthy",description:"Falsy: empty array / NaN / false / empty string / undefined / null",unset:"Leave it empty to always run this query on load"},re_run_condition:{label:"Re-run query when these changed",unset:"Leave it empty to never re-run this query"},dependency:{label:"Dependency",has_none:"This query has no dependency"},edit_sql:"Edit SQL",preview_sql:"Preview SQL",request:"Request",build_request:"Build Request",process_request:"Process Request",process_result:"Process Result",usage:{label:"Usage",in_views:"In View(s)",unused_description:"This query is not used by any filter or panel"},transform:{label:"Transform",full_label:"Transform Query",data_source:"Use other queries' data",guide:{pick_queries:"Pick queries for data input",write_function:"Write a function for making new data"}}},data:{label:"Data",preview_data:"Preview Data",empty_data:"Empty Data",requires_data:"Requires data"},data_source:{label:"Data Source",explore:"Explore Data Source",explorer:"Data Source Explorer",table_structure:"Table Structure",table_structure_short:"Structure",see_table_structure:"See Table Structure"},visualization:{label:"Visualization",component:"Visualization",label_short:"Viz"},numbro:{format:{label:"Format",absolute:"Absolute",absolute_description:"Non-negative",abbreviation:"Abbreviation",abbreviation_description:"like 1.23k, 1.23m",mantissa:"Mantissa",trim_mantissa:"Trim mantissa",trim_mantissa_description:"hide trailing zero(s)",preview:{open:"Open Preview",close:"Close Preview",input:"In",output:"Out"}}},import:{label:"Import...",title:"Import content with schema json",json_file:"JSON File",this_dashboard:"This dashboard",this_file:"This file"},function_utils:{trigger_text:"About parameter 'utils'",modal_title:"About FunctionUtils",description:"Parameter <code>utils</code> is <code>FunctionUtils</code>, which contains:",document:"Document"},aggregation:{option:{none:"None",sum:"Sum",mean:"Mean",median:"Median",min:"Min",max:"Max",cov:"Coefficient of Variation",std:"Standard Variation",quantile:{label:"Quantile",label_with_hint:"Quantile(99%, 95%, ...)"},custom:{label:"Custom",label_trigger:"Edit Function",title:"Custom Aggregation"},pick_record:{label:"Pick Record",method:{label:"Record",first:"First Record",last:"Last Record"}}}},rich_text:{label:"Rich Text",content:{label:"Content"},dynamic_color:{label:"Dynamic Color",edit:"Edit dynamic color",clear:"Clear dynamic color"},color_mapping:{label:"Color Mapping",edit:"Edit color mapping",clear:"Clear color mapping",choose_value_var:"Choose a variable for color mapping",min:{val:"Fallback value",var:"Min value variable"},max:{val:"Fallback value",var:"Max value variable"}}},chart:{chart_config:"Chart Config",data_field:"Data Field",groups:{merico_suite:"Merico suite",echarts_based_charts:"ECharts-based charts",others:"Others"},unit:{title:"Unit",text:{placeholder:"Unit text"},show_in_tooltip:"Show unit text in tooltip",show_in_legend:"Show unit text in legend"},series_order:{label:"Order series by...",name:"Name",value:"Value",raw:"Record order",asc:"Ascending",desc:"Descending"},label:{label:"Label",label_full:"Label",label_style:"Label Style",label_format:"Label Format"},label_position:{label:"Label Position",off:"Off",top:"Top",left:"Left",right:"Right",bottom:"Bottom",inside:"Inside",inside_top:"Inside Top",inside_left:"Inside Left",inside_center:"Inside Center",inside_right:"Inside Right",inside_bottom:"Inside Bottom",inside_top_left:"Inside Top Left",inside_top_right:"Inside Top Right",inside_bottom_left:"Inside Bottom Left",inside_bottom_right:"Inside Bottom Right",outside:"Outside"},visual_map:{label:"Visual Map",continuous:{label:"Continuous"},piecewise:{label:"Piecewise",mode:{pieces:"Pieces",categories:"Categories"},add_a_piece:"Add a piece",interval:"Interval",piece_label:"Label"},bar_width:"Bar Width",bar_height:"Bar Height",item_width:"Item Width",item_height:"Item Height",calculable:"Show drag handle",min_value:"Min Value",max_value:"Max Value",min_text:"Min Text",max_text:"Max Text",use_palette_x:'Use palette "{{x}}"',built_in_palettes:"Built-in Palettes",precision:"Data Precision",skip_range:{lt_min:"Color for smaller values than min value",min:"Color for min value",max:"Color for max value",gt_max:"Color for greater values than max value",follow_visual_map:"follow gradient rule"}},number_or_dynamic_value:{type:{static:"Static",dynamic:"Dynamic"},dynamic:{setup:"Setup",setup_title:"Setup dynamic value",guide:"Dyanmic by a custom function"}},orientation:{label:"Orientation",horizontal:"Horizontal",vertical:"Vertical"},symbol_size:{label:"Symbol Size",static:"Static",dynamic:"Dynamic",setup:{label:"Setup",title:"Setup dynamic size",description:"Dynamic by a custom function"}},series:{label:"Series",name:"Name",y_axis:"Y Axis",data_field:"Data Field",add:"Add a series",delete:"Delete this series",line:{label:"Line",line_settings:"Line Settings",line_style:"Line Style",type:{label:"Line Type",solid:"Solid",dashed:"Dashed",dotted:"Dotted"},line_width:"Line Width",step:{label:"Step",off:"Off",start:"Start",middle:"Middle",end:"End"},smooth_line:"Smooth Line",show_name_on_line:"Display Name on Line",show_symbol_on_line:"Show Symbol on Line",area_style:{label:"Area style",enabled:"Enable area style",color:"Area color",use_series_color:"Use series' color",origin:{label:"Origin position of the area",auto:{label:"Auto",description:"Fill between axis line and data (Default)"},start:{label:"Start",description:"Fill between min axis value and data"},end:{label:"End",description:"Fill between max axis value and data"}},shadow_blur:"Shadow Blur",shadow_color:"Shadow Color",shadow_offset_x:"Shadow Offset X",shadow_offset_y:"Shadow Offset Y",opacity:"Opacity"}},bar:{label:"Bar",stack:"Stack",stack_hint:"Stack bars by this ID",bar_gap:{label:"Bar Gap",no_gap:"No gap between bars",overlap:"Bars overlapping on each other"},bar_width:{min:"Bar Width(min)",exact:"Bar Width",max:"Bar Width(max)"}},scatter:{label:"Scatter"},group_by:{label:"Split into multiple seires by this field...",label_line:"Split into multiple lines by this field..."}},axis:{tick_label:"Tick Label",customize_label:"Customize Label",overflow:{label:"Overflow",max_width:"Max Width",truncate:"Truncate",break_line:"Break Line",break_word:"Break Word",ellipsis:"Ellipsis",section_title:{on_axis:"Overflow on Axis",in_tooltip:"Overflow in Tooltip"}},section_title:{label_format:"Label Format"},type:{value:"Value",category:"Category",time:"Time",log:"Log",click_to_learn_more:"Click <1>here</1> to learn more about these options"}},name_text:{align:{label:"Name Anchor",left:"Left",center:"Center",right:"Right"}},rotate:"Rotate",degree:"degree",padding:"Padding",content_template:{label:"Content Template",hint:"Average: ${avg}"},x_axis:{label:"X Axis",labels:"X Axes",label_format:"Label Format",add:"Add an X Axis",delete:"Delete this X Axis",x_axis_name:"X Axis Name",x_axis_data_field:"X Axis Data Field",x_axis_type:"X Axis Type",layout:"Layout",position:{label:"Position",top:"Top",bottom:"Bottom"},value_range:"Value Range",value_min:"Min",value_max:"Max",behavior:"Behavior",visible:"Visible"},y_axis:{label:"Y Axis",labels:"Y Axes",label_format:"Label Format",add:"Add a Y Axis",delete:"Delete this Y Axis",y_axis_name:"Y Axis Name",y_axis_name_anchor:"Name Anchor",y_axis_data_field:"Y Axis Data Field",inverse:"Inverse",layout:"Layout",position:{label:"Position",left:"Left",right:"Right"},value_range:"Value Range",value_min:"Min",value_max:"Max",behavior:"Behavior",visible:"Visible",mirror:{label:"Mirror"}},stats:{label:"Stats",template:{above_chart:"Stats above the chart",under_chart:"Stats under the chart"}},legend:{label:"Legend",show_legend:"Show Legend",show_in_legend:"Show in legend",hide_in_legend:"Hide in legend",orientation:{label:"Orientation",horizontal:"Horizontal",vertical:"Vertical"}},tooltip:{label:"Tooltip",additional_metrics:{description:"Set additional metrics to show in scatter's tooltip",add:"Add a metic",delete:"Delete this Metric"},trigger:{label:"Trigger",scatter_point:"Scatter Point",x_axis:"X Axis"}},style:{label:"Style"},color:{label:"Color",background_color:"Background Color",text_color:"Text Color",click_to_add_a_color:"Click to add a color",color_gradient:"Color Gradient",not_set:"Not set"},behavior:{label:"Behavior",invisible:"Invisible"},heatmap:{heatblock:{label:"Heat Block",show_label:"Show Label"}},reference_line:{label:"Reference Line",labels:"Reference Lines",add:"Add a reference line",name_placeholder:"Average Reference Line",delete:"Remove this Reference Line",orientation:{vertical_hint:"Works only when xAxis values are numbers"}},regression_line:{label:"Regression Line",labels:"Regression Lines",add:"Add a line",delete:"Delete this line",method:{label:"Method",linear:"Linear",exponential:"Exponential",logistic:"Logistic",polynomial:"Polynomial",polynomial_order:"Order"}},reference_area:{label:"Reference Area",labels:"Reference Areas",add:"Add a reference area",delete:"Remove this reference area",type:{label:"Type",rectangle:"Rectangle"},direction:{label:"Direction",horizontal:"Horizontal"},boundary:{upper:"Upper Boundary",lower:"Lower Boundary"},content:{label:"Content",content_text:"Content Text",text_position:"Text Position"},endpoint:{labels:"Endpoints",left_bottom_point:"Left-Bottom Point",right_top_point:"Right-Top Point"}},zooming:{label:"Zooming",scroll:{label:"Scroll to zoom",x_axis:"Enable on X Axis",y_axis:"Enable on Y Axis"},slider:{label:"Slider for zooming",x_axis:"Slider for X Axis",y_axis:"Slider for Y Axis",y_axis_disabled:"Not available for now, will overlap y-axis's label"}}},viz:{viz_config_banner:"Visualization Settings"},validation:{number:{require_a_number:"A number is required"}},spotlight:{trigger_text:"Search",main_group:"Main",placeholder:"Search to open...",not_found:"Nothing found..."}}},Zd={translation:{filter:{label:"筛选器",labels:"筛选器",add:"新增筛选器",manage:"管理筛选器",delete:"删除这个筛选器",show_filters:"展开筛选器",hide_filters:"收起筛选器",usage:{label:"使用情况",unused_description:"此筛选器未被任何查询、SQL片段或视图使用"},field:{widget:"控件",visible_in:"在...视图中可见",key_placeholder:"用于引用此筛选器,需保持唯一",label_placeholder:"用于展示的标签文案",auto_submit:"自动提交",order:"排列次序",custom_default_value:{trigger:"自定义默认值",title:"自定义默认值",tips:"提示",tip_1:"在指定筛选器默认值这事上,自定义函数具备最高优先级",tip_2:"清空下方编辑器来禁用本功能"}},widget:{names:{select:"单选",multi_select:"多选",tree_select:"树形选择器",tree_single_select:"树形单选器",text_input:"文本框",checkbox:"勾选框",date_range:"日期范围"},common:{use_query_data_as_options:"使用所查数据为选项",fetch_options_from_datasource:"从数据源查选项",or_fetch_options_from_datasource:"或从数据源查选项",selector_option_empty:"无选项可用",see_data_structure:"点击查看期望的数据格式",using_query:"在用查询获取选项",default_selection_count:"默认选中前N项",min_width:"控件最小宽度",x_selected:"已选数:{{count}}",default_value_mode:{label:"当选项变更时",intersect:"保持已选值的有效部分",reset:"忽略已选值,使用新选项"}},text_input:{default_value:"默认值",required:"必填"},select:{width:"控件宽度",required:"必选",clearable:"可取消选择",configure_options:"配置选项",default_selection:"默认选项",no_default_selection:"无",select_first_option_by_default:"默认选中第一个选项",preset_options:{apply:"使用预设选项列表",date_unit:"日期步长"}},multi_select:{width_description:"至少160px"},tree_select:{strictly:"枝叶节点不相关,各选各的"},tree_single_select:{select_first_option_by_default:"默认选中第一个选项"},checkbox:{description:"描述信息",default_checked:"默认勾选"},date_range:{required:"必选",allow_single_date:"允许选一天作为范围",display_format:"展示格式",max_days:"最大选择天数",one_day:"1天",x_days:"{{count}}天",x_max_days:"最多可选{{max_days}}天",default_value:"默认日期范围(具体)",default_by_shortcut:"默认日期范围(快捷方式)",default_by_shortcut_placeholder:"优先于左侧",start_date:"开始日期",end_date:"结束日期",shortcut:{last:{label:"过往整周期",d:"昨天",w:"周",m:"月",m2:"两个月",m3:"三个月",y:"年",full:{d:"昨天",w:"上周",m:"上个月",m2:"上两月",m3:"上三月",y:"去年"}},recent:{label:"最近",d7:"7天",d30:"30天",d60:"60天",d90:"90天",d180:"180天",d365:"365天",full:{d7:"近7天",d30:"近30天",d60:"近60天",d90:"近90天",d180:"近180天",d365:"近365天"}},this:{label:"当前整周期",d:"今天",w:"周",m:"月",y:"年",full:{d:"今天",w:"本周",m:"本月",y:"今年"}},this_so_far:{label:"至今",w:"周",m:"月",y:"年",full:{w:"本周至今",m:"本月至今",y:"本年至今"}}}}}},view:{label:"视图",labels:"视图",add:"新增视图",delete:"删除此视图",download_schema:"下载此视图描述文件",component:{div:{label:"内容"},tabs:{label:"标签页",tabs_settings:"标签页设置",tab:{name:"名称",view:"内容视图",order:"排列次序",color:"颜色",delete:"删除这个标签页",switch_to_view:"打开视图: {{name}}"}},modal:{label:"弹窗",modal_settings:"弹窗设置",title:"弹窗标题",custom_title:"自定义弹窗标题",width:"宽度",height:"高度"}}},interactions:{label:"交互",add:"新增交互",interactions_viewer:"纵览交互",unavailable:"不可用",unavailable_reason:"此可视化组件没有交互功能",trigger:{setup:"设置触发动作",label:"触发动作",payload:"触发时的参数"},operation:{setup:"操作设置",label:"操作",settings:"设置",variables:"变量",console_log:{label:"console.log | 调试用",log_content:"打印内容"},open_link:{label:"打开链接",url:"URL",open_in_new_tab:"在新标签页中打开"},open_view:{label:"唤出视图",view:"视图"},switch_tab:{label:"切换标签页",view:"视图",tab:"标签页"},scroll_to_panel:{label:"滚动到卡片",panel:"卡片"},set_filter_values:{label:"设置筛选器值",set_filter:"将筛选器的值",with:"设为"},clear_filter_values:{label:"清除筛选器值",select_filter:"选择筛选器以清除其值"}}},query_variable:{label:"查询变量",labels:"查询变量",add:"新增变量",guide:{tabs:{guide:"使用指南",variables_in_this_dashboard:"本看板中的查询变量",global_sql_snippets:"全局SQL片段"}},open:"查看查询变量"},sql_snippet:{label:"SQL片段",labels:"SQL片段",add:"新增SQL片段",delete:"删除这个SQL片段",delete_unused:"删除未用到的SQL片段",manage:"管理SQL片段",key:"键",key_occupied:"此键已被其他SQL片段占用",edit_snippet:"编辑SQL片段",preview_snippet:"预览SQL片段",usage:{label:"使用情况"}},global_sql_snippet:{label:"全局SQL片段",labels:"全局SQL片段",description:"管理员负责在系统设置中维护全局SQL片段"},common:{titles:{settings:"设置",edit:"编辑",config:"配置"},pagination:{label:"分页",page_size:"页容量",total:"共",total_rows:"共 {{total}} 行",to_previous_page:"上一页",to_next_page:"下一页",showing_rows:"第 {{start_row}} - {{end_row}} 行,共 {{total}} 行"},align:{horizontal:{label:"水平对齐",left:"居左",center:"居中",right:"居右"},vertical:{label:"垂直对齐",top:"居上",center:"居中",bottom:"居下"}},id:"ID",name:"名称",key:"键",label:"标签",value:"值",type:"类型",info:"信息",min:"最小值",max:"最大值",invalid:"无效的",data_field:"数据字段",name_data_field:"名称字段",value_data_field:"值字段",color_data_field:"颜色字段",enabled:"启用",copied:"已复制到剪切板",action:"操作",actions:{search:"查询",reload:"刷新",actions:"操作",open:"打开",close:"关闭",save:"保存",save_changes:"保存改动",revert:"还原",revert_changes:"还原改动",reset_to_default:"重置为初始值",init_with_default:"初始化",select_all:"全选",clear:"清除",clear_selection:"撤销选择",refresh:"刷新",download_data:"下载数据",download_schema:"下载描述文件",download_screenshot:"下载截图",enter_fullscreen:"全屏",duplicate:"复制",delete:"删除",cancel:"取消",confirm:"确认",add_an_option:"新增选项",edit:"编辑",end_editing:"结束编辑 <0>{{name}}</0>"},tabs:{variant:{label:"风格",default:"默认",outline:"轮廓",pills:"胶囊"},orientation:{label:"朝向",horizontal:"水平",vertical:"垂直"},grow_tabs:"拉伸标签卡宽度"},choose_a_tab_first:"请先选择一个标签页"},breakpoint:{label_one:"屏幕尺寸",label_other:"屏幕尺寸",add:"新增屏幕尺寸",manage:"管理屏幕尺寸",breakpoint:"最小宽度"},context:{label:"上下文"},mock_context:{label:"模拟上下文",hint:"内容格式为JSON"},panel:{label:"卡片",labels:"卡片",add:"新增卡片",delete:"删除这个卡片",panel_name:"卡片名",panel_description:"卡片描述",panel_description_click:"点击查看卡片描述",show_title:"展示卡片标题",use_name_as_title:"使用卡片名作为标题",settings:{change_view:"移至另一个视图下",change_view_title:"移动此卡片至另一个视图下",choose_queries:"关联查询",need_to_choose_queries:"请关联至少一个查询以使用其数据"},style:{label:"样式",width:"宽",width_postfix:"之 36 栏",height:"高",height_postfix:"px",border:"边框"},variable:{label:"变量",labels:"变量",add:"新增变量",delete:"删除此变量",aggregation:{label:"聚合",fallback_value:"兜底值",fallback_value_description:"当数据为空或聚合结果非数字时,使用此兜底值"},guide:{text:`-- 可以在富文本和自定义函数中,使用看板信息以及卡片的变量。
5
+ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel variables"}}}},style:{label:"Style",font_size:{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%..."},font_weight:{label:"Font Weight"},size:{xs:"xs",sm:"sm",md:"md",lg:"lg",xl:"xl"},flex:{justify_content:{label:"Justify Content",left:"Left",center:"Center",right:"Right",space_between:"Space Between",space_around:"Space Around",space_evenly:"Space Evenly"},align_items:{label:"Align Items",start:"Start",center:"Center",end:"End",stretch:"Stretch"}},color:{type:{label:"Color Type",static:"Static",interpolation:"Interpolation",none:"None"},interpolation:{setup:"Setup color interpolation",palette:{label:"Palette",category:{sequential:"Sequential",diverging:"Diverging"},red_green:"Red / Green",yellow_blue:"Yellow / Blue",red:"Red",green:"Green",blue:"Blue",orange:"Orange",mapping:{value_input_label:"Map a value to this color"}}}}},query:{label:"Query",labels:"Queries",add:"Add a Query",delete:"Delete this Query",cant_delete:"Can't delete this query for it's being used, check out Usage tab for details",delete_unused:"Delete unused queries",name:"Name",name_description:"A unique name",manage:"Manage Queries",open:"Open this query",configurations:"Configurations",basics:"Basics",conditions:"Conditions",run_by_condition:{label:"Run query when these are truthy",description:"Falsy: empty array / NaN / false / empty string / undefined / null",unset:"Leave it empty to always run this query on load"},re_run_condition:{label:"Re-run query when these changed",unset:"Leave it empty to never re-run this query"},dependency:{label:"Dependency",has_none:"This query has no dependency"},edit_sql:"Edit SQL",preview_sql:"Preview SQL",request:"Request",build_request:"Build Request",process_request:"Process Request",process_result:"Process Result",usage:{label:"Usage",in_views:"In View(s)",unused_description:"This query is not used by any filter or panel"},transform:{label:"Transform",full_label:"Transform Query",data_source:"Use other queries' data",guide:{pick_queries:"Pick queries for data input",write_function:"Write a function for making new data"}}},data:{label:"Data",preview_data:"Preview Data",empty_data:"Empty Data",requires_data:"Requires data"},data_source:{label:"Data Source",explore:"Explore Data Source",explorer:"Data Source Explorer",table_structure:"Table Structure",table_structure_short:"Structure",see_table_structure:"See Table Structure"},visualization:{label:"Visualization",component:"Visualization",label_short:"Viz"},numbro:{format:{label:"Format",absolute:"Absolute",absolute_description:"Non-negative",abbreviation:"Abbreviation",abbreviation_description:"like 1.23k, 1.23m",mantissa:"Mantissa",trim_mantissa:"Trim mantissa",trim_mantissa_description:"hide trailing zero(s)",preview:{open:"Open Preview",close:"Close Preview",input:"In",output:"Out"}}},import:{label:"Import...",title:"Import content with schema json",json_file:"JSON File",this_dashboard:"This dashboard",this_file:"This file"},function_utils:{trigger_text:"About parameter 'utils'",modal_title:"About FunctionUtils",description:"Parameter <code>utils</code> is <code>FunctionUtils</code>, which contains:",document:"Document"},aggregation:{option:{none:"None",sum:"Sum",mean:"Mean",median:"Median",min:"Min",max:"Max",cov:"Coefficient of Variation",std:"Standard Variation",quantile:{label:"Quantile",label_with_hint:"Quantile(99%, 95%, ...)"},custom:{label:"Custom",label_trigger:"Edit Function",title:"Custom Aggregation"},pick_record:{label:"Pick Record",method:{label:"Record",first:"First Record",last:"Last Record"}}}},rich_text:{label:"Rich Text",content:{label:"Content"},dynamic_color:{label:"Dynamic Color",edit:"Edit dynamic color",clear:"Clear dynamic color"},color_mapping:{label:"Color Mapping",edit:"Edit color mapping",clear:"Clear color mapping",choose_value_var:"Choose a variable for color mapping",min:{val:"Fallback value",var:"Min value variable"},max:{val:"Fallback value",var:"Max value variable"}}},chart:{chart_config:"Chart Config",data_field:"Data Field",groups:{merico_suite:"Merico suite",echarts_based_charts:"ECharts-based charts",others:"Others"},unit:{title:"Unit",text:{placeholder:"Unit text"},show_in_tooltip:"Show unit text in tooltip",show_in_legend:"Show unit text in legend"},series_order:{label:"Order series by...",name:"Name",value:"Value",raw:"Record order",asc:"Ascending",desc:"Descending"},label:{label:"Label",label_full:"Label",label_style:"Label Style",label_format:"Label Format"},label_position:{label:"Label Position",off:"Off",top:"Top",left:"Left",right:"Right",bottom:"Bottom",inside:"Inside",inside_top:"Inside Top",inside_left:"Inside Left",inside_center:"Inside Center",inside_right:"Inside Right",inside_bottom:"Inside Bottom",inside_top_left:"Inside Top Left",inside_top_right:"Inside Top Right",inside_bottom_left:"Inside Bottom Left",inside_bottom_right:"Inside Bottom Right",outside:"Outside"},visual_map:{label:"Visual Map",continuous:{label:"Continuous"},piecewise:{label:"Piecewise",mode:{pieces:"Pieces",categories:"Categories"},add_a_piece:"Add a piece",interval:"Interval",piece_label:"Label"},bar_width:"Bar Width",bar_height:"Bar Height",item_width:"Item Width",item_height:"Item Height",calculable:"Show drag handle",min_value:"Min Value",max_value:"Max Value",min_text:"Min Text",max_text:"Max Text",use_palette_x:'Use palette "{{x}}"',built_in_palettes:"Built-in Palettes",precision:"Data Precision",skip_range:{lt_min:"Color for smaller values than min value",min:"Color for min value",max:"Color for max value",gt_max:"Color for greater values than max value",follow_visual_map:"follow gradient rule"}},number_or_dynamic_value:{type:{static:"Static",dynamic:"Dynamic"},dynamic:{setup:"Setup",setup_title:"Setup dynamic value",guide:"Dyanmic by a custom function"}},orientation:{label:"Orientation",horizontal:"Horizontal",vertical:"Vertical"},symbol_size:{label:"Symbol Size",static:"Static",dynamic:"Dynamic",setup:{label:"Setup",title:"Setup dynamic size",description:"Dynamic by a custom function"}},series:{label:"Series",name:"Name",y_axis:"Y Axis",data_field:"Data Field",add:"Add a series",delete:"Delete this series",line:{label:"Line",line_settings:"Line Settings",line_style:"Line Style",type:{label:"Line Type",solid:"Solid",dashed:"Dashed",dotted:"Dotted"},line_width:"Line Width",step:{label:"Step",off:"Off",start:"Start",middle:"Middle",end:"End"},smooth_line:"Smooth Line",show_name_on_line:"Display Name on Line",show_symbol_on_line:"Show Symbol on Line",area_style:{label:"Area style",enabled:"Enable area style",color:"Area color",use_series_color:"Use series' color",origin:{label:"Origin position of the area",auto:{label:"Auto",description:"Fill between axis line and data (Default)"},start:{label:"Start",description:"Fill between min axis value and data"},end:{label:"End",description:"Fill between max axis value and data"}},shadow_blur:"Shadow Blur",shadow_color:"Shadow Color",shadow_offset_x:"Shadow Offset X",shadow_offset_y:"Shadow Offset Y",opacity:"Opacity"}},bar:{label:"Bar",stack:"Stack",stack_hint:"Stack bars by this ID",bar_gap:{label:"Bar Gap",no_gap:"No gap between bars",overlap:"Bars overlapping on each other"},bar_width:{min:"Bar Width(min)",exact:"Bar Width",max:"Bar Width(max)"}},scatter:{label:"Scatter"},group_by:{label:"Split into multiple seires by this field...",label_line:"Split into multiple lines by this field..."}},axis:{tick_label:"Tick Label",customize_label:"Customize Label",overflow:{label:"Overflow",max_width:"Max Width",truncate:"Truncate",break_line:"Break Line",break_word:"Break Word",ellipsis:"Ellipsis",section_title:{on_axis:"Overflow on Axis",in_tooltip:"Overflow in Tooltip"}},section_title:{label_format:"Label Format"},type:{value:"Value",category:"Category",time:"Time",log:"Log",click_to_learn_more:"Click <1>here</1> to learn more about these options"}},name_text:{align:{label:"Name Anchor",left:"Left",center:"Center",right:"Right"}},rotate:"Rotate",degree:"degree",padding:"Padding",content_template:{label:"Content Template",hint:"Average: ${avg}"},x_axis:{label:"X Axis",labels:"X Axes",label_format:"Label Format",add:"Add an X Axis",delete:"Delete this X Axis",x_axis_name:"X Axis Name",x_axis_data_field:"X Axis Data Field",x_axis_type:"X Axis Type",layout:"Layout",position:{label:"Position",top:"Top",bottom:"Bottom"},value_range:"Value Range",value_min:"Min",value_max:"Max",behavior:"Behavior",visible:"Visible"},y_axis:{label:"Y Axis",labels:"Y Axes",label_format:"Label Format",add:"Add a Y Axis",delete:"Delete this Y Axis",y_axis_name:"Y Axis Name",y_axis_name_anchor:"Name Anchor",y_axis_data_field:"Y Axis Data Field",inverse:"Inverse",layout:"Layout",position:{label:"Position",left:"Left",right:"Right"},value_range:"Value Range",value_min:"Min",value_max:"Max",behavior:"Behavior",visible:"Visible",mirror:{label:"Mirror"}},stats:{label:"Stats",template:{above_chart:"Stats above the chart",under_chart:"Stats under the chart"}},legend:{label:"Legend",show_legend:"Show Legend",show_in_legend:"Show in legend",hide_in_legend:"Hide in legend",orientation:{label:"Orientation",horizontal:"Horizontal",vertical:"Vertical"}},tooltip:{label:"Tooltip",additional_metrics:{description:"Set additional metrics to show in scatter's tooltip",add:"Add a metic",delete:"Delete this Metric"},trigger:{label:"Trigger",scatter_point:"Scatter Point",x_axis:"X Axis"}},style:{label:"Style"},color:{label:"Color",background_color:"Background Color",text_color:"Text Color",click_to_add_a_color:"Click to add a color",color_gradient:"Color Gradient",not_set:"Not set"},behavior:{label:"Behavior",invisible:"Invisible"},heatmap:{heatblock:{label:"Heat Block",show_label:"Show Label"}},reference_line:{label:"Reference Line",labels:"Reference Lines",add:"Add a reference line",name_placeholder:"Average Reference Line",delete:"Remove this Reference Line",orientation:{vertical_hint:"Works only when xAxis values are numbers"}},regression_line:{label:"Regression Line",labels:"Regression Lines",add:"Add a line",delete:"Delete this line",method:{label:"Method",linear:"Linear",exponential:"Exponential",logistic:"Logistic",polynomial:"Polynomial",polynomial_order:"Order"}},reference_area:{label:"Reference Area",labels:"Reference Areas",add:"Add a reference area",delete:"Remove this reference area",type:{label:"Type",rectangle:"Rectangle"},direction:{label:"Direction",horizontal:"Horizontal"},boundary:{upper:"Upper Boundary",lower:"Lower Boundary"},content:{label:"Content",content_text:"Content Text",text_position:"Text Position"},endpoint:{labels:"Endpoints",left_bottom_point:"Left-Bottom Point",right_top_point:"Right-Top Point"}},zooming:{label:"Zooming",scroll:{label:"Scroll to zoom",x_axis:"Enable on X Axis",y_axis:"Enable on Y Axis"},slider:{label:"Slider for zooming",x_axis:"Slider for X Axis",y_axis:"Slider for Y Axis",y_axis_disabled:"Not available for now, will overlap y-axis's label"}}},viz:{viz_config_banner:"Visualization Settings"},validation:{number:{require_a_number:"A number is required"}},spotlight:{trigger_text:"Search",main_group:"Main",placeholder:"Search to open...",not_found:"Nothing found..."}}},Rd={translation:{filter:{label:"筛选器",labels:"筛选器",add:"新增筛选器",manage:"管理筛选器",delete:"删除这个筛选器",show_filters:"展开筛选器",hide_filters:"收起筛选器",usage:{label:"使用情况",unused_description:"此筛选器未被任何查询、SQL片段或视图使用"},field:{widget:"控件",visible_in:"在...视图中可见",key_placeholder:"用于引用此筛选器,需保持唯一",label_placeholder:"用于展示的标签文案",auto_submit:"自动提交",order:"排列次序",custom_default_value:{trigger:"自定义默认值",title:"自定义默认值",tips:"提示",tip_1:"在指定筛选器默认值这事上,自定义函数具备最高优先级",tip_2:"清空下方编辑器来禁用本功能"}},widget:{names:{select:"单选",multi_select:"多选",tree_select:"树形选择器",tree_single_select:"树形单选器",text_input:"文本框",checkbox:"勾选框",date_range:"日期范围"},common:{use_query_data_as_options:"使用所查数据为选项",fetch_options_from_datasource:"从数据源查选项",or_fetch_options_from_datasource:"或从数据源查选项",selector_option_empty:"无选项可用",see_data_structure:"点击查看期望的数据格式",using_query:"在用查询获取选项",default_selection_count:"默认选中前N项",min_width:"控件最小宽度",x_selected:"已选数:{{count}}",default_value_mode:{label:"当选项变更时",intersect:"保持已选值的有效部分",reset:"忽略已选值,使用新选项"}},text_input:{default_value:"默认值",required:"必填"},select:{width:"控件宽度",required:"必选",clearable:"可取消选择",configure_options:"配置选项",default_selection:"默认选项",no_default_selection:"无",select_first_option_by_default:"默认选中第一个选项",preset_options:{apply:"使用预设选项列表",date_unit:"日期步长"}},multi_select:{width_description:"至少160px"},tree_select:{strictly:"枝叶节点不相关,各选各的"},tree_single_select:{select_first_option_by_default:"默认选中第一个选项"},checkbox:{description:"描述信息",default_checked:"默认勾选"},date_range:{required:"必选",allow_single_date:"允许选一天作为范围",display_format:"展示格式",max_days:"最大选择天数",one_day:"1天",x_days:"{{count}}天",x_max_days:"最多可选{{max_days}}天",default_value:"默认日期范围(具体)",default_by_shortcut:"默认日期范围(快捷方式)",default_by_shortcut_placeholder:"优先于左侧",start_date:"开始日期",end_date:"结束日期",shortcut:{last:{label:"过往整周期",d:"昨天",w:"周",m:"月",m2:"两个月",m3:"三个月",y:"年",full:{d:"昨天",w:"上周",m:"上个月",m2:"上两月",m3:"上三月",y:"去年"}},recent:{label:"最近",d7:"7天",d30:"30天",d60:"60天",d90:"90天",d180:"180天",d365:"365天",full:{d7:"近7天",d30:"近30天",d60:"近60天",d90:"近90天",d180:"近180天",d365:"近365天"}},this:{label:"当前整周期",d:"今天",w:"周",m:"月",y:"年",full:{d:"今天",w:"本周",m:"本月",y:"今年"}},this_so_far:{label:"至今",w:"周",m:"月",y:"年",full:{w:"本周至今",m:"本月至今",y:"本年至今"}}}}}},view:{label:"视图",labels:"视图",add:"新增视图",delete:"删除此视图",download_schema:"下载此视图描述文件",component:{div:{label:"内容"},tabs:{label:"标签页",tabs_settings:"标签页设置",tab:{name:"名称",view:"内容视图",order:"排列次序",color:"颜色",delete:"删除这个标签页",switch_to_view:"打开视图: {{name}}"}},modal:{label:"弹窗",modal_settings:"弹窗设置",title:"弹窗标题",custom_title:"自定义弹窗标题",width:"宽度",height:"高度"}}},interactions:{label:"交互",add:"新增交互",interactions_viewer:"纵览交互",unavailable:"不可用",unavailable_reason:"此可视化组件没有交互功能",trigger:{setup:"设置触发动作",label:"触发动作",payload:"触发时的参数"},operation:{setup:"操作设置",label:"操作",settings:"设置",variables:"变量",console_log:{label:"console.log | 调试用",log_content:"打印内容"},open_link:{label:"打开链接",url:"URL",open_in_new_tab:"在新标签页中打开"},open_view:{label:"唤出视图",view:"视图"},switch_tab:{label:"切换标签页",view:"视图",tab:"标签页"},scroll_to_panel:{label:"滚动到卡片",panel:"卡片"},set_filter_values:{label:"设置筛选器值",set_filter:"将筛选器的值",with:"设为"},clear_filter_values:{label:"清除筛选器值",select_filter:"选择筛选器以清除其值"}}},query_variable:{label:"查询变量",labels:"查询变量",add:"新增变量",guide:{tabs:{guide:"使用指南",variables_in_this_dashboard:"本看板中的查询变量",global_sql_snippets:"全局SQL片段"}},open:"查看查询变量"},sql_snippet:{label:"SQL片段",labels:"SQL片段",add:"新增SQL片段",delete:"删除这个SQL片段",delete_unused:"删除未用到的SQL片段",manage:"管理SQL片段",key:"键",key_occupied:"此键已被其他SQL片段占用",edit_snippet:"编辑SQL片段",preview_snippet:"预览SQL片段",usage:{label:"使用情况"}},global_sql_snippet:{label:"全局SQL片段",labels:"全局SQL片段",description:"管理员负责在系统设置中维护全局SQL片段"},common:{titles:{settings:"设置",edit:"编辑",config:"配置"},pagination:{label:"分页",page_size:"页容量",total:"共",total_rows:"共 {{total}} 行",to_previous_page:"上一页",to_next_page:"下一页",showing_rows:"第 {{start_row}} - {{end_row}} 行,共 {{total}} 行"},align:{horizontal:{label:"水平对齐",left:"居左",center:"居中",right:"居右"},vertical:{label:"垂直对齐",top:"居上",center:"居中",bottom:"居下"}},id:"ID",name:"名称",key:"键",label:"标签",value:"值",type:"类型",info:"信息",min:"最小值",max:"最大值",invalid:"无效的",data_field:"数据字段",name_data_field:"名称字段",value_data_field:"值字段",color_data_field:"颜色字段",enabled:"启用",copied:"已复制到剪切板",action:"操作",actions:{search:"查询",reload:"刷新",actions:"操作",open:"打开",close:"关闭",save:"保存",save_changes:"保存改动",revert:"还原",revert_changes:"还原改动",reset_to_default:"重置为初始值",init_with_default:"初始化",select_all:"全选",clear:"清除",clear_selection:"撤销选择",refresh:"刷新",download_data:"下载数据",download_schema:"下载描述文件",download_screenshot:"下载截图",enter_fullscreen:"全屏",duplicate:"复制",delete:"删除",cancel:"取消",confirm:"确认",add_an_option:"新增选项",edit:"编辑",end_editing:"结束编辑 <0>{{name}}</0>"},tabs:{variant:{label:"风格",default:"默认",outline:"轮廓",pills:"胶囊"},orientation:{label:"朝向",horizontal:"水平",vertical:"垂直"},grow_tabs:"拉伸标签卡宽度"},choose_a_tab_first:"请先选择一个标签页"},breakpoint:{label_one:"屏幕尺寸",label_other:"屏幕尺寸",add:"新增屏幕尺寸",manage:"管理屏幕尺寸",breakpoint:"最小宽度"},context:{label:"上下文"},mock_context:{label:"模拟上下文",hint:"内容格式为JSON"},panel:{label:"卡片",labels:"卡片",add:"新增卡片",delete:"删除这个卡片",panel_name:"卡片名",panel_description:"卡片描述",panel_description_click:"点击查看卡片描述",show_title:"展示卡片标题",use_name_as_title:"使用卡片名作为标题",settings:{change_view:"移至另一个视图下",change_view_title:"移动此卡片至另一个视图下",choose_queries:"关联查询",need_to_choose_queries:"请关联至少一个查询以使用其数据"},style:{label:"样式",width:"宽",width_postfix:"之 36 栏",height:"高",height_postfix:"px",border:"边框"},variable:{label:"变量",labels:"变量",add:"新增变量",delete:"删除此变量",aggregation:{label:"聚合",fallback_value:"兜底值",fallback_value_description:"当数据为空或聚合结果非数字时,使用此兜底值"},guide:{text:`-- 可以在富文本和自定义函数中,使用看板信息以及卡片的变量。
6
6
  -- 在富文本中,要使用双重花括号来包裹代码。
7
7
  项目ID:{{ context.project_id }}
8
8
  搜索关键字:{{ filters.keyword }}
9
- 我的卡片变量: {{ your_var }}`,tabs:{guide:"使用指南",vars:"看板信息与卡片的变量"}}}},style:{label:"样式",font_size:{label:"字号",placeholder:"10px, 1em, 1rem, 100%..."},font_weight:{label:"字重"},size:{xs:"特小",sm:"小",md:"中",lg:"大",xl:"特大"},flex:{justify_content:{label:"内容分布",left:"从左起",center:"居中",right:"从右起",space_between:"均匀分布,首尾顶格",space_around:"均匀分布,首尾留空一半",space_evenly:"均匀分布,首尾留空"},align_items:{label:"对齐位置",start:"起点对齐",center:"居中对齐",end:"末端对齐",stretch:"拉伸对齐"}},color:{type:{label:"颜色类型",static:"单色",interpolation:"插值取色",none:"无"},interpolation:{setup:"设置取色方案",palette:{label:"色板",category:{sequential:"单色渐变",diverging:"双色渐变"},red_green:"红 / 绿",yellow_blue:"黄 / 蓝",red:"红",green:"绿",blue:"蓝",orange:"橙",mapping:{value_input_label:"映射一个值到此颜色"}}}}},query:{label:"查询",labels:"查询",add:"新增查询",delete:"删除这个查询",cant_delete:"此查询在使用中,不能删除。请查看“使用情况”标签页以了解详情",delete_unused:"删除未用到的查询",name:"名称",name_description:"唯一名称",manage:"管理查询",open:"打开此查询",configurations:"配置",basics:"基本信息",conditions:"条件",run_by_condition:{label:"以下条件为真时,才运行本查询",description:"为假的情况: 空数组 / NaN / false / 空字符串 / undefined / null",unset:"留空则在看板加载时便运行本查询"},re_run_condition:{label:"当以下条件改变时,重新运行此查询",unset:"留空则永不重新运行此查询"},dependency:{label:"依赖",has_none:"此查询无依赖"},edit_sql:"编辑SQL",preview_sql:"预览SQL",request:"请求",build_request:"构造请求",process_request:"加工请求",process_result:"加工结果",usage:{label:"使用情况",in_views:"所在视图",unused_description:"此查询未被任何筛选器或卡片用到"},transform:{label:"查询变形",full_label:"查询变形",data_source:"基于其他查询的数据,加工出新数据",guide:{pick_queries:"选择一至多个查询作为数据输入",write_function:"编写函数,返回新数据"}}},data:{label:"数据",preview_data:"预览数据",empty_data:"无数据",requires_data:"请先关联查询"},data_source:{label:"数据源",explore:"查看数据源",explorer:"数据源查看器",table_structure:"数据表结构",table_structure_short:"表结构",see_table_structure:"查看数据表结构"},visualization:{label:"可视化",component:"可视化组件",label_short:"可视化"},numbro:{format:{label:"格式",absolute:"绝对值",absolute_description:"非负",abbreviation:"缩写",abbreviation_description:"如1.23k、1.23m",mantissa:"小数",trim_mantissa:"抹零",trim_mantissa_description:"省略末尾的零",preview:{open:"展开预览",close:"收起预览",input:"输入",output:"输出"}}},import:{label:"导入...",title:"自描述文件导入看板内容",json_file:"描述文件(JSON格式)",this_dashboard:"此看板",this_file:"此文件"},function_utils:{trigger_text:"关于utils参数",modal_title:"关于utils参数",description:"参数 <code>utils</code> 是 <code>FunctionUtils</code>,包含以下内容:",document:"文档"},aggregation:{option:{none:"无",sum:"和",mean:"平均值",median:"中位数",min:"最小值",max:"最大值",cov:"变异系数",std:"标准差",quantile:{label:"分位",label_with_hint:"分位(99%, 95%, ...)"},custom:{label:"自定义",label_trigger:"编写函数",title:"自定义聚合方式"},pick_record:{label:"直接选择数据",method:{label:"数据记录",first:"第一条",last:"最后一条"}}}},rich_text:{label:"富文本",content:{label:"内容"},dynamic_color:{label:"动态颜色",edit:"编辑动态颜色",clear:"清除动态颜色"},color_mapping:{label:"颜色映射",edit:"编辑颜色映射",clear:"清除颜色映射",choose_value_var:"选择用于映射颜色的变量",min:{val:"固定最小值",var:"动态最小值(优先)"},max:{val:"固定最大值",var:"动态最大值(优先)"}}},chart:{chart_config:"图表设置",data_field:"数据字段",groups:{merico_suite:"思码逸套件",echarts_based_charts:"基于ECharts的图表",others:"其他"},unit:{title:"单位",text:{placeholder:"单位文案"},show_in_tooltip:"在提示框中显示单位",show_in_legend:"在图例中显示单位"},series_order:{label:"排序依据",name:"名称",value:"值",raw:"不排序,保持数据本身的顺序",asc:"升序",desc:"降序"},label:{label:"文案",label_full:"标签文案",label_style:"标签文案样式",label_format:"标签文案格式"},label_position:{label:"文案位置",off:"不显示文案",top:"上",left:"左",right:"右",bottom:"下",inside:"内",inside_top:"内-上",inside_left:"内-左",inside_center:"内-中",inside_right:"内-右",inside_bottom:"内-下",inside_top_left:"内-上-左",inside_top_right:"内-上-右",inside_bottom_left:"内-下-左",inside_bottom_right:"内-下-右",outside:"外"},visual_map:{label:"视觉映射",continuous:{label:"连续型"},piecewise:{label:"分段型",mode:{pieces:"连续数据",categories:"离散数据"},add_a_piece:"加一个分段",interval:"值区间",piece_label:"文案"},bar_width:"长条的宽度",bar_height:"长条的高度",item_width:"小块的宽度",item_height:"小块的高度",calculable:"显示拖拽手柄",min_value:"最小值",max_value:"最大值",min_text:"最小值文案",max_text:"最大值文案",use_palette_x:'使用配色方案"{{x}}"',built_in_palettes:"内置配色方案",precision:"数据精度",skip_range:{lt_min:"小于最小值时的颜色",min:"最小值的颜色",max:"最大值的颜色",gt_max:"大于最大值时的颜色",follow_visual_map:"颜色跟随渐变规则"}},number_or_dynamic_value:{type:{static:"具体值",dynamic:"动态值"},dynamic:{setup:"设置",setup_title:"设置动态值",guide:"由函数确定动态值"}},orientation:{label:"朝向",horizontal:"水平",vertical:"垂直"},symbol_size:{label:"标记点大小",static:"固定值",dynamic:"动态值",setup:{label:"设置",title:"设置动态值",description:"由函数确定动态值"}},series:{label:"系列",name:"名称",y_axis:"Y轴",data_field:"数据字段",add:"增加一个系列",delete:"删除这个系列",line:{label:"线",line_settings:"线段设置",line_style:"线条样式",type:{label:"类型",solid:"实线",dashed:"方虚线",dotted:"圆点虚线"},line_width:"线宽",step:{label:"阶梯状",off:"不启用",start:"在当前点拐弯",middle:"在当前点与下个点中间拐弯",end:"在下个点拐弯"},smooth_line:"平滑曲线",show_name_on_line:"显示标签文案",show_symbol_on_line:"显示标记点",area_style:{label:"区域填充样式",enabled:"启用区域填充",color:"填充颜色",use_series_color:"沿用系列本色",origin:{label:"图形区域的起始位置",auto:{label:"自动",description:"填充坐标轴线到数据间的区域(默认)"},start:{label:"自下而上",description:"填充坐标轴底部到数据间的区域"},end:{label:"自上而下",description:"填充坐标轴顶部到数据间的区域"}},shadow_blur:"图形阴影的模糊大小",shadow_color:"图形阴影的颜色",shadow_offset_x:"阴影水平方向上的偏移距离",shadow_offset_y:"阴影垂直方向上的偏移距离",opacity:"图形透明度"}},bar:{label:"柱",stack:"堆放",stack_hint:"此值相同的柱系列会堆叠在一起",bar_gap:{label:"柱间隔",no_gap:"柱子之间无间隔",overlap:"柱子可互相重叠"},bar_width:{min:"最小柱宽",exact:"柱宽",max:"最大柱宽"}},scatter:{label:"散点"},group_by:{label:"按此字段拆分为多个系列",label_line:"按此字段拆分为多条线"}},axis:{tick_label:"刻度文案",customize_label:"自定义文案",overflow:{label:"溢出",max_width:"最大宽度",truncate:"截断",break_line:"换行",break_word:"断词换行",ellipsis:"省略符",section_title:{on_axis:"轴刻度上文案的溢出",in_tooltip:"提示框中的文案溢出"}},section_title:{label_format:"文案格式"},type:{value:"数值轴",category:"类目轴",time:"时间轴",log:"对数轴",click_to_learn_more:"点击 <1>这里</1> 以进一步了解这些选项"}},name_text:{align:{label:"名称贴靠侧",left:"左",center:"中",right:"右"}},rotate:"旋转",degree:"度",padding:"内间距",content_template:{label:"内容模板",hint:"均值: ${avg}"},x_axis:{label:"X轴",labels:"X轴",label_format:"刻度文案格式",add:"增加一条X轴",delete:"删除这条X轴",x_axis_name:"X轴名称",x_axis_data_field:"X轴数据字段",x_axis_type:"X轴类型",layout:"布局",position:{label:"位置",top:"上",bottom:"下"},value_range:"值范围",value_min:"最小值",value_max:"最大值",behavior:"表现",visible:"可见"},y_axis:{label:"Y轴",labels:"Y轴",label_format:"刻度文案格式",add:"增加一条Y轴",delete:"删除这条Y轴",y_axis_name:"Y轴名称",y_axis_name_anchor:"名称贴靠侧",y_axis_data_field:"Y轴数据字段",inverse:"反向坐标轴",layout:"布局",position:{label:"位置",left:"左",right:"右"},value_range:"值范围",value_min:"最小值",value_max:"最大值",behavior:"表现",visible:"可见",mirror:{label:"上下镜像"}},stats:{label:"统计内容",template:{above_chart:"统计内容(图表上方)",under_chart:"统计内容(图表下方)"}},legend:{label:"图例",show_legend:"显示图例",show_in_legend:"显示在图例中",hide_in_legend:"不显示在图例中",orientation:{label:"布局朝向",horizontal:"横向",vertical:"纵向"}},tooltip:{label:"提示框",additional_metrics:{description:"在此设置更多指标,来展示在散点的提示框",add:"增加一个指标",delete:"删除这个指标"},trigger:{label:"触发者",scatter_point:"散点",x_axis:"X轴"}},style:{label:"样式"},color:{label:"颜色",background_color:"背景色",text_color:"文字颜色",click_to_add_a_color:"点击增加一个颜色",color_gradient:"颜色渐变",not_set:"未设置"},behavior:{label:"表现",invisible:"隐藏不可见"},heatmap:{heatblock:{label:"热力块",show_label:"展示值文案"}},reference_line:{label:"参考线",labels:"参考线",add:"增加一条参考线",name_placeholder:"均值参考线",delete:"删除这条参考线",orientation:{vertical_hint:"仅当X轴值为数字时可绘制"}},regression_line:{label:"回归线",labels:"回归线",add:"增加一条回归线",delete:"删除这条回归线",method:{label:"方法",linear:"线性回归",exponential:"指数回归",logistic:"指数回归",polynomial:"多项式回归",polynomial_order:"次"}},reference_area:{label:"参考区域",labels:"参考区域",add:"增加一面参考区域",delete:"删除这面参考区域",type:{label:"形状",rectangle:"矩形"},direction:{label:"方向",horizontal:"水平"},boundary:{upper:"上边界",lower:"下边界"},content:{label:"内容",content_text:"内容文字",text_position:"文字位置"},endpoint:{labels:"端点",left_bottom_point:"左下点",right_top_point:"右上点"}},zooming:{label:"缩放",scroll:{label:"滚轮缩放",x_axis:"对X轴启用",y_axis:"对Y轴启用"},slider:{label:"滚动条缩放",x_axis:"对X轴启用",y_axis:"对Y轴启用",y_axis_disabled:"暂不可用,会与Y轴刻度文字重叠"}}},viz:{viz_config_banner:"可视化参数配置"},validation:{number:{require_a_number:"请填写一个数字"}},spotlight:{trigger_text:"搜索",main_group:"主要项",placeholder:"打开…",not_found:"无匹配项"}}};class Jt{constructor(t){P(this,"rootRef");this.rootRef=Q.observable({current:t})}async deleteItem(t){Q.runInAction(()=>{y.unset(this.rootRef.current,[t])})}getItem(t){const r=this.getValueFromRoot(t);return Promise.resolve(r)}getValueFromRoot(t){return t===null?Q.toJS(this.rootRef.current):y.get(this.rootRef.current,[t])}setItem(t,r){if(t===null)if(y.isObject(r))Q.runInAction(()=>{this.rootRef.current=r});else throw new Error("Cannot set root value to non-object");else Q.runInAction(()=>{y.set(this.rootRef.current,[t],r)});return Promise.resolve(this.getItem(t))}watchItem(t,r,a){return Q.reaction(()=>this.getValueFromRoot(t),(l,o)=>{r(l,o)},{requiresObservable:!0,fireImmediately:y.get(a,"fireImmediately",!1)})}}class Jd{constructor(){P(this,"channels",new Map);P(this,"globalChannel",new Xa)}getChannel(t){const r=this.channels.get(t);if(r)return r;const a=new Xa;return this.channels.set(t,a),a}}class Hd{constructor(t){P(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const r=this.instances.get(t.id);if(r)return r;const a={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new Jd,instanceData:new Jt(t.viz.conf)};return this.instances.set(t.id,a),a}}function _s(e,t,r,a){return{vizManager:r,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new Jt({}),colorPalette:{getColor(){return()=>""}},data:t,variables:a}}const Rd=e=>{const{panel:t,measure:r,vizManager:a,data:l,variables:o}=e,i=a.resolveComponent(t.viz.type),c=a.getOrCreateInstance(t),d={..._s(c,l,a,o),viewport:{width:r.w,height:r.h}},u=i.viewRender;return n.jsx(u,{context:d,instance:c,...y.omit(e,["panel","vizManager","data"])})},eu=e=>{const{vizManager:t,panel:r,data:a,variables:l}=e,o=t.resolveComponent(r.viz.type),i=t.getOrCreateInstance(r),c={..._s(i,a,t,l)},d=o.configRender;return n.jsx(d,{context:c,instance:i,...y.omit(e,["panel","vizManager","data"])})},xs=(e,t)=>{const r=qe.bezier(e),a=qe.bezier(t);return function(l){return l<50?r(l*2/100).hex():a((l-50)*2/100).hex()}},Ht=e=>{const t=qe.bezier(e);return function(r){return t(r/100).hex()}},tu={type:"interpolation",displayName:"style.color.interpolation.palette.red_green",getColor:xs(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},nu={type:"interpolation",displayName:"style.color.interpolation.palette.yellow_blue",getColor:xs(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},ru={type:"interpolation",displayName:"style.color.interpolation.palette.red",getColor:Ht(["#fff7f1","darkred"]),name:"red",category:"sequential"},au={type:"interpolation",displayName:"style.color.interpolation.palette.green",getColor:Ht(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},su={type:"interpolation",displayName:"style.color.interpolation.palette.blue",getColor:Ht(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},lu={type:"interpolation",displayName:"style.color.interpolation.palette.orange",getColor:Ht(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class ou{constructor(t){P(this,"symbol");this.symbol=Symbol(t)}}function Je(e){return new ou(e)}class On{constructor(){P(this,"parent");P(this,"factoryRegistry",new Map);P(this,"instanceRegistry",new Map)}createScoped(){const t=new On;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const r=this.factoryRegistry.get(t.symbol);if(r){const a=r(this);return this.instanceRegistry.set(t.symbol,a),a}if(this.parent)return this.parent.get(t)}provideFactory(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,r),this}provideValue(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>r),this}dispose(){this.instanceRegistry.forEach(t=>{const r=y.get(t,"dispose");y.isFunction(r)&&r.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}class iu{constructor(t){this.pluginManager=t}createPanelAddonNode(t){const a=this.pluginManager.installedPlugins.flatMap(l=>l.manifest.panelAddon).filter(l=>!!l).map(l=>h.createElement(l.addonRender,{...t,key:l.name}));return n.jsx(n.Fragment,{children:a})}}const ws=h.createContext({addonSlotId:null});function ms({children:e}){const t=`panel-addon-slot-${h.useId()}`;return n.jsxs(ws.Provider,{value:{addonSlotId:t},children:[n.jsx("div",{style:{position:"static",top:0,left:0},id:t}),e]})}function cu(){const{addonSlotId:e}=h.useContext(ws);return e?document.getElementById(e):null}const Cs="14.44.5",du=Object.freeze(Object.defineProperty({__proto__:null,version:Cs},Symbol.toStringTag,{value:"Module"}));class uu{constructor(t){P(this,"staticColors",new Map);P(this,"interpolations",new Map);t.installedPlugins.forEach(r=>{r.manifest.color.forEach(a=>{this.register(a)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const r=this.encodeColor(t);t.type==="single"?(this.staticColors.has(r)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(r,t)):t.type==="interpolation"&&(this.interpolations.has(r)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(r,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class pu{constructor(){P(this,"plugins",new Map);P(this,"vizComponents",new Map);P(this,"factory",{viz:t=>{const r=this.vizComponents.get(t);if(r)return r;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const r of t.manifest.viz){if(this.vizComponents.has(r.name))throw new Error(`Viz Component (${r.name}) has been installed before`);this.vizComponents.set(r.name,r)}}get installedPlugins(){return Array.from(this.plugins.values())}}class hu{constructor(){P(this,"migrations",[])}version(t,r){return this.migrations.push({version:t,handler:r}),this}run(t,r,a){var i;if(t.from===t.to)return r;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const l=this.migrations.filter(c=>c.version>t.from&&c.version<=t.to),o=y.orderBy(l,"version","asc");if(((i=y.last(o))==null?void 0:i.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((c,d)=>d.handler(c,a),r)}}class ee extends hu{constructor(){super(),this.configVersions()}version(t,r){return super.version(t,(a,l)=>({version:t,...r(a,l)}))}async migrate({configData:t,panelModel:r}){const a=await t.getItem(null),l=y.get(a,"version",0),o=this.run({from:l,to:this.VERSION},a,{panelModel:r});await t.setItem(null,o)}async needMigration({configData:t}){const r=await t.getItem(null);return y.get(r,"version",0)<this.VERSION}}const B=(e,t)=>{const[r,{setFalse:a}]=O.useBoolean(!0),[l,o]=h.useState();h.useEffect(()=>(e.getItem(t).then(c=>{o(c),a()}),e.watchItem(t,c=>{o(c)})));const i=h.useCallback(async c=>{await e.setItem(t,c),o(c)},[e,t]);return{loading:r,value:l,set:i}},ve={top:16,right:16,bottom:16,left:16},Ge=e=>Math.max(0,e-ve.left-ve.right),Fe=e=>Math.max(0,e-ve.top-ve.bottom),Ot=(e,t)=>({width:Ge(e),height:Fe(t)}),_e=({width:e,height:t,children:r})=>n.jsx(s.Box,{pt:ve.top,pr:ve.right,pb:ve.bottom,pl:ve.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:r});h.forwardRef(function({value:t,onChange:r,...a},l){return n.jsx(s.TextInput,{ref:l,value:t,onChange:r,...a})});class gu{constructor({valueRange:t,colorRange:r}){P(this,"mapper");this.mapper=ot.interpolate(t,r)}getColor(t){return this.mapper(t)}}function fu(e,t){if(e.type==="static")return e.staticColor;if(e.type==="continuous")try{const r=Number(t);if(Number.isNaN(r))throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${t}, parsed: ${r}`);return new gu(e).getColor(r)}catch(r){return console.error(r),"black"}return"black"}const bu=fu;function A(e){const[t,r]=e.split(".");return{queryID:t,columnKey:r}}function yu(e){return e.includes(".")?A(e):{queryID:"",columnKey:e}}function Ve(e,t){var l;const{queryID:r,columnKey:a}=A(t);return r?a?((l=e[r])==null?void 0:l.map(o=>o[a]))??[]:e[r]:[]}function Rt(e,t){const{queryID:r}=A(t);return r?e[r]:[]}function vu(e){return Object.values(e)[0]}function en(e,t){const{queryID:r,columnKey:a}=A(t);return e[a]}const je={CryptoJS:Ja,d3Array:vs,dayjs:M,lodash:y,numbro:Ye,mathjs:Ne,faker:rd.faker,popmotion:Ud},_u=[{name:"CryptoJS",url:"https://github.com/brix/crypto-js",version:"4.1.1"},{name:"d3Array",url:"https://github.com/d3/d3-array",version:"3.2.4"},{name:"dayjs",url:"https://day.js.org/",version:"1.11.6"},{name:"lodash",url:"https://lodash.com/docs/4.17.15",version:"4.17.21"},{name:"mathjs",url:"https://mathjs.org/",version:"11.12.0"},{name:"numbro",url:"https://numbrojs.com/",version:"2.3.6"},{name:"faker",url:"https://fakerjs.dev/",version:"7.6.0"},{name:"popmotion",url:"https://popmotion.io/",version:"11.0.3"}],xu=e=>`
9
+ 我的卡片变量: {{ your_var }}`,tabs:{guide:"使用指南",vars:"看板信息与卡片的变量"}}}},style:{label:"样式",font_size:{label:"字号",placeholder:"10px, 1em, 1rem, 100%..."},font_weight:{label:"字重"},size:{xs:"特小",sm:"小",md:"中",lg:"大",xl:"特大"},flex:{justify_content:{label:"内容分布",left:"从左起",center:"居中",right:"从右起",space_between:"均匀分布,首尾顶格",space_around:"均匀分布,首尾留空一半",space_evenly:"均匀分布,首尾留空"},align_items:{label:"对齐位置",start:"起点对齐",center:"居中对齐",end:"末端对齐",stretch:"拉伸对齐"}},color:{type:{label:"颜色类型",static:"单色",interpolation:"插值取色",none:"无"},interpolation:{setup:"设置取色方案",palette:{label:"色板",category:{sequential:"单色渐变",diverging:"双色渐变"},red_green:"红 / 绿",yellow_blue:"黄 / 蓝",red:"红",green:"绿",blue:"蓝",orange:"橙",mapping:{value_input_label:"映射一个值到此颜色"}}}}},query:{label:"查询",labels:"查询",add:"新增查询",delete:"删除这个查询",cant_delete:"此查询在使用中,不能删除。请查看“使用情况”标签页以了解详情",delete_unused:"删除未用到的查询",name:"名称",name_description:"唯一名称",manage:"管理查询",open:"打开此查询",configurations:"配置",basics:"基本信息",conditions:"条件",run_by_condition:{label:"以下条件为真时,才运行本查询",description:"为假的情况: 空数组 / NaN / false / 空字符串 / undefined / null",unset:"留空则在看板加载时便运行本查询"},re_run_condition:{label:"当以下条件改变时,重新运行此查询",unset:"留空则永不重新运行此查询"},dependency:{label:"依赖",has_none:"此查询无依赖"},edit_sql:"编辑SQL",preview_sql:"预览SQL",request:"请求",build_request:"构造请求",process_request:"加工请求",process_result:"加工结果",usage:{label:"使用情况",in_views:"所在视图",unused_description:"此查询未被任何筛选器或卡片用到"},transform:{label:"查询变形",full_label:"查询变形",data_source:"基于其他查询的数据,加工出新数据",guide:{pick_queries:"选择一至多个查询作为数据输入",write_function:"编写函数,返回新数据"}}},data:{label:"数据",preview_data:"预览数据",empty_data:"无数据",requires_data:"请先关联查询"},data_source:{label:"数据源",explore:"查看数据源",explorer:"数据源查看器",table_structure:"数据表结构",table_structure_short:"表结构",see_table_structure:"查看数据表结构"},visualization:{label:"可视化",component:"可视化组件",label_short:"可视化"},numbro:{format:{label:"格式",absolute:"绝对值",absolute_description:"非负",abbreviation:"缩写",abbreviation_description:"如1.23k、1.23m",mantissa:"小数",trim_mantissa:"抹零",trim_mantissa_description:"省略末尾的零",preview:{open:"展开预览",close:"收起预览",input:"输入",output:"输出"}}},import:{label:"导入...",title:"自描述文件导入看板内容",json_file:"描述文件(JSON格式)",this_dashboard:"此看板",this_file:"此文件"},function_utils:{trigger_text:"关于utils参数",modal_title:"关于utils参数",description:"参数 <code>utils</code> 是 <code>FunctionUtils</code>,包含以下内容:",document:"文档"},aggregation:{option:{none:"无",sum:"和",mean:"平均值",median:"中位数",min:"最小值",max:"最大值",cov:"变异系数",std:"标准差",quantile:{label:"分位",label_with_hint:"分位(99%, 95%, ...)"},custom:{label:"自定义",label_trigger:"编写函数",title:"自定义聚合方式"},pick_record:{label:"直接选择数据",method:{label:"数据记录",first:"第一条",last:"最后一条"}}}},rich_text:{label:"富文本",content:{label:"内容"},dynamic_color:{label:"动态颜色",edit:"编辑动态颜色",clear:"清除动态颜色"},color_mapping:{label:"颜色映射",edit:"编辑颜色映射",clear:"清除颜色映射",choose_value_var:"选择用于映射颜色的变量",min:{val:"固定最小值",var:"动态最小值(优先)"},max:{val:"固定最大值",var:"动态最大值(优先)"}}},chart:{chart_config:"图表设置",data_field:"数据字段",groups:{merico_suite:"思码逸套件",echarts_based_charts:"基于ECharts的图表",others:"其他"},unit:{title:"单位",text:{placeholder:"单位文案"},show_in_tooltip:"在提示框中显示单位",show_in_legend:"在图例中显示单位"},series_order:{label:"排序依据",name:"名称",value:"值",raw:"不排序,保持数据本身的顺序",asc:"升序",desc:"降序"},label:{label:"文案",label_full:"标签文案",label_style:"标签文案样式",label_format:"标签文案格式"},label_position:{label:"文案位置",off:"不显示文案",top:"上",left:"左",right:"右",bottom:"下",inside:"内",inside_top:"内-上",inside_left:"内-左",inside_center:"内-中",inside_right:"内-右",inside_bottom:"内-下",inside_top_left:"内-上-左",inside_top_right:"内-上-右",inside_bottom_left:"内-下-左",inside_bottom_right:"内-下-右",outside:"外"},visual_map:{label:"视觉映射",continuous:{label:"连续型"},piecewise:{label:"分段型",mode:{pieces:"连续数据",categories:"离散数据"},add_a_piece:"加一个分段",interval:"值区间",piece_label:"文案"},bar_width:"长条的宽度",bar_height:"长条的高度",item_width:"小块的宽度",item_height:"小块的高度",calculable:"显示拖拽手柄",min_value:"最小值",max_value:"最大值",min_text:"最小值文案",max_text:"最大值文案",use_palette_x:'使用配色方案"{{x}}"',built_in_palettes:"内置配色方案",precision:"数据精度",skip_range:{lt_min:"小于最小值时的颜色",min:"最小值的颜色",max:"最大值的颜色",gt_max:"大于最大值时的颜色",follow_visual_map:"颜色跟随渐变规则"}},number_or_dynamic_value:{type:{static:"具体值",dynamic:"动态值"},dynamic:{setup:"设置",setup_title:"设置动态值",guide:"由函数确定动态值"}},orientation:{label:"朝向",horizontal:"水平",vertical:"垂直"},symbol_size:{label:"标记点大小",static:"固定值",dynamic:"动态值",setup:{label:"设置",title:"设置动态值",description:"由函数确定动态值"}},series:{label:"系列",name:"名称",y_axis:"Y轴",data_field:"数据字段",add:"增加一个系列",delete:"删除这个系列",line:{label:"线",line_settings:"线段设置",line_style:"线条样式",type:{label:"类型",solid:"实线",dashed:"方虚线",dotted:"圆点虚线"},line_width:"线宽",step:{label:"阶梯状",off:"不启用",start:"在当前点拐弯",middle:"在当前点与下个点中间拐弯",end:"在下个点拐弯"},smooth_line:"平滑曲线",show_name_on_line:"显示标签文案",show_symbol_on_line:"显示标记点",area_style:{label:"区域填充样式",enabled:"启用区域填充",color:"填充颜色",use_series_color:"沿用系列本色",origin:{label:"图形区域的起始位置",auto:{label:"自动",description:"填充坐标轴线到数据间的区域(默认)"},start:{label:"自下而上",description:"填充坐标轴底部到数据间的区域"},end:{label:"自上而下",description:"填充坐标轴顶部到数据间的区域"}},shadow_blur:"图形阴影的模糊大小",shadow_color:"图形阴影的颜色",shadow_offset_x:"阴影水平方向上的偏移距离",shadow_offset_y:"阴影垂直方向上的偏移距离",opacity:"图形透明度"}},bar:{label:"柱",stack:"堆放",stack_hint:"此值相同的柱系列会堆叠在一起",bar_gap:{label:"柱间隔",no_gap:"柱子之间无间隔",overlap:"柱子可互相重叠"},bar_width:{min:"最小柱宽",exact:"柱宽",max:"最大柱宽"}},scatter:{label:"散点"},group_by:{label:"按此字段拆分为多个系列",label_line:"按此字段拆分为多条线"}},axis:{tick_label:"刻度文案",customize_label:"自定义文案",overflow:{label:"溢出",max_width:"最大宽度",truncate:"截断",break_line:"换行",break_word:"断词换行",ellipsis:"省略符",section_title:{on_axis:"轴刻度上文案的溢出",in_tooltip:"提示框中的文案溢出"}},section_title:{label_format:"文案格式"},type:{value:"数值轴",category:"类目轴",time:"时间轴",log:"对数轴",click_to_learn_more:"点击 <1>这里</1> 以进一步了解这些选项"}},name_text:{align:{label:"名称贴靠侧",left:"左",center:"中",right:"右"}},rotate:"旋转",degree:"度",padding:"内间距",content_template:{label:"内容模板",hint:"均值: ${avg}"},x_axis:{label:"X轴",labels:"X轴",label_format:"刻度文案格式",add:"增加一条X轴",delete:"删除这条X轴",x_axis_name:"X轴名称",x_axis_data_field:"X轴数据字段",x_axis_type:"X轴类型",layout:"布局",position:{label:"位置",top:"上",bottom:"下"},value_range:"值范围",value_min:"最小值",value_max:"最大值",behavior:"表现",visible:"可见"},y_axis:{label:"Y轴",labels:"Y轴",label_format:"刻度文案格式",add:"增加一条Y轴",delete:"删除这条Y轴",y_axis_name:"Y轴名称",y_axis_name_anchor:"名称贴靠侧",y_axis_data_field:"Y轴数据字段",inverse:"反向坐标轴",layout:"布局",position:{label:"位置",left:"左",right:"右"},value_range:"值范围",value_min:"最小值",value_max:"最大值",behavior:"表现",visible:"可见",mirror:{label:"上下镜像"}},stats:{label:"统计内容",template:{above_chart:"统计内容(图表上方)",under_chart:"统计内容(图表下方)"}},legend:{label:"图例",show_legend:"显示图例",show_in_legend:"显示在图例中",hide_in_legend:"不显示在图例中",orientation:{label:"布局朝向",horizontal:"横向",vertical:"纵向"}},tooltip:{label:"提示框",additional_metrics:{description:"在此设置更多指标,来展示在散点的提示框",add:"增加一个指标",delete:"删除这个指标"},trigger:{label:"触发者",scatter_point:"散点",x_axis:"X轴"}},style:{label:"样式"},color:{label:"颜色",background_color:"背景色",text_color:"文字颜色",click_to_add_a_color:"点击增加一个颜色",color_gradient:"颜色渐变",not_set:"未设置"},behavior:{label:"表现",invisible:"隐藏不可见"},heatmap:{heatblock:{label:"热力块",show_label:"展示值文案"}},reference_line:{label:"参考线",labels:"参考线",add:"增加一条参考线",name_placeholder:"均值参考线",delete:"删除这条参考线",orientation:{vertical_hint:"仅当X轴值为数字时可绘制"}},regression_line:{label:"回归线",labels:"回归线",add:"增加一条回归线",delete:"删除这条回归线",method:{label:"方法",linear:"线性回归",exponential:"指数回归",logistic:"逻辑回归",polynomial:"多项式回归",polynomial_order:"次"}},reference_area:{label:"参考区域",labels:"参考区域",add:"增加一面参考区域",delete:"删除这面参考区域",type:{label:"形状",rectangle:"矩形"},direction:{label:"方向",horizontal:"水平"},boundary:{upper:"上边界",lower:"下边界"},content:{label:"内容",content_text:"内容文字",text_position:"文字位置"},endpoint:{labels:"端点",left_bottom_point:"左下点",right_top_point:"右上点"}},zooming:{label:"缩放",scroll:{label:"滚轮缩放",x_axis:"对X轴启用",y_axis:"对Y轴启用"},slider:{label:"滚动条缩放",x_axis:"对X轴启用",y_axis:"对Y轴启用",y_axis_disabled:"暂不可用,会与Y轴刻度文字重叠"}}},viz:{viz_config_banner:"可视化参数配置"},validation:{number:{require_a_number:"请填写一个数字"}},spotlight:{trigger_text:"搜索",main_group:"主要项",placeholder:"打开…",not_found:"无匹配项"}}};class Jt{constructor(t){V(this,"rootRef");this.rootRef=Q.observable({current:t})}async deleteItem(t){Q.runInAction(()=>{y.unset(this.rootRef.current,[t])})}getItem(t){const r=this.getValueFromRoot(t);return Promise.resolve(r)}getValueFromRoot(t){return t===null?Q.toJS(this.rootRef.current):y.get(this.rootRef.current,[t])}setItem(t,r){if(t===null)if(y.isObject(r))Q.runInAction(()=>{this.rootRef.current=r});else throw new Error("Cannot set root value to non-object");else Q.runInAction(()=>{y.set(this.rootRef.current,[t],r)});return Promise.resolve(this.getItem(t))}watchItem(t,r,a){return Q.reaction(()=>this.getValueFromRoot(t),(l,o)=>{r(l,o)},{requiresObservable:!0,fireImmediately:y.get(a,"fireImmediately",!1)})}}class eu{constructor(){V(this,"channels",new Map);V(this,"globalChannel",new Za)}getChannel(t){const r=this.channels.get(t);if(r)return r;const a=new Za;return this.channels.set(t,a),a}}class tu{constructor(t){V(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const r=this.instances.get(t.id);if(r)return r;const a={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new eu,instanceData:new Jt(t.viz.conf)};return this.instances.set(t.id,a),a}}function xs(e,t,r,a){return{vizManager:r,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new Jt({}),colorPalette:{getColor(){return()=>""}},data:t,variables:a}}const nu=e=>{const{panel:t,measure:r,vizManager:a,data:l,variables:o}=e,i=a.resolveComponent(t.viz.type),c=a.getOrCreateInstance(t),d={...xs(c,l,a,o),viewport:{width:r.w,height:r.h}},u=i.viewRender;return n.jsx(u,{context:d,instance:c,...y.omit(e,["panel","vizManager","data"])})},ru=e=>{const{vizManager:t,panel:r,data:a,variables:l}=e,o=t.resolveComponent(r.viz.type),i=t.getOrCreateInstance(r),c={...xs(i,a,t,l)},d=o.configRender;return n.jsx(d,{context:c,instance:i,...y.omit(e,["panel","vizManager","data"])})},ws=(e,t)=>{const r=Be.bezier(e),a=Be.bezier(t);return function(l){return l<50?r(l*2/100).hex():a((l-50)*2/100).hex()}},Ht=e=>{const t=Be.bezier(e);return function(r){return t(r/100).hex()}},au={type:"interpolation",displayName:"style.color.interpolation.palette.red_green",getColor:ws(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},su={type:"interpolation",displayName:"style.color.interpolation.palette.yellow_blue",getColor:ws(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},lu={type:"interpolation",displayName:"style.color.interpolation.palette.red",getColor:Ht(["#fff7f1","darkred"]),name:"red",category:"sequential"},ou={type:"interpolation",displayName:"style.color.interpolation.palette.green",getColor:Ht(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},iu={type:"interpolation",displayName:"style.color.interpolation.palette.blue",getColor:Ht(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},cu={type:"interpolation",displayName:"style.color.interpolation.palette.orange",getColor:Ht(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class du{constructor(t){V(this,"symbol");this.symbol=Symbol(t)}}function Xe(e){return new du(e)}class On{constructor(){V(this,"parent");V(this,"factoryRegistry",new Map);V(this,"instanceRegistry",new Map)}createScoped(){const t=new On;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const r=this.factoryRegistry.get(t.symbol);if(r){const a=r(this);return this.instanceRegistry.set(t.symbol,a),a}if(this.parent)return this.parent.get(t)}provideFactory(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,r),this}provideValue(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>r),this}dispose(){this.instanceRegistry.forEach(t=>{const r=y.get(t,"dispose");y.isFunction(r)&&r.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}class uu{constructor(t){this.pluginManager=t}createPanelAddonNode(t){const a=this.pluginManager.installedPlugins.flatMap(l=>l.manifest.panelAddon).filter(l=>!!l).map(l=>h.createElement(l.addonRender,{...t,key:l.name}));return n.jsx(n.Fragment,{children:a})}}const ms=h.createContext({addonSlotId:null});function Cs({children:e}){const t=`panel-addon-slot-${h.useId()}`;return n.jsxs(ms.Provider,{value:{addonSlotId:t},children:[n.jsx("div",{style:{position:"static",top:0,left:0},id:t}),e]})}function pu(){const{addonSlotId:e}=h.useContext(ms);return e?document.getElementById(e):null}const Ss="14.45.0",hu=Object.freeze(Object.defineProperty({__proto__:null,version:Ss},Symbol.toStringTag,{value:"Module"}));class gu{constructor(t){V(this,"staticColors",new Map);V(this,"interpolations",new Map);t.installedPlugins.forEach(r=>{r.manifest.color.forEach(a=>{this.register(a)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const r=this.encodeColor(t);t.type==="single"?(this.staticColors.has(r)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(r,t)):t.type==="interpolation"&&(this.interpolations.has(r)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(r,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class fu{constructor(){V(this,"plugins",new Map);V(this,"vizComponents",new Map);V(this,"factory",{viz:t=>{const r=this.vizComponents.get(t);if(r)return r;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const r of t.manifest.viz){if(this.vizComponents.has(r.name))throw new Error(`Viz Component (${r.name}) has been installed before`);this.vizComponents.set(r.name,r)}}get installedPlugins(){return Array.from(this.plugins.values())}}class bu{constructor(){V(this,"migrations",[])}version(t,r){return this.migrations.push({version:t,handler:r}),this}run(t,r,a){var i;if(t.from===t.to)return r;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const l=this.migrations.filter(c=>c.version>t.from&&c.version<=t.to),o=y.orderBy(l,"version","asc");if(((i=y.last(o))==null?void 0:i.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((c,d)=>d.handler(c,a),r)}}class ee extends bu{constructor(){super(),this.configVersions()}version(t,r){return super.version(t,(a,l)=>({version:t,...r(a,l)}))}async migrate({configData:t,panelModel:r}){const a=await t.getItem(null),l=y.get(a,"version",0),o=this.run({from:l,to:this.VERSION},a,{panelModel:r});await t.setItem(null,o)}async needMigration({configData:t}){const r=await t.getItem(null);return y.get(r,"version",0)<this.VERSION}}const B=(e,t)=>{const[r,{setFalse:a}]=O.useBoolean(!0),[l,o]=h.useState();h.useEffect(()=>(e.getItem(t).then(c=>{o(c),a()}),e.watchItem(t,c=>{o(c)})));const i=h.useCallback(async c=>{await e.setItem(t,c),o(c)},[e,t]);return{loading:r,value:l,set:i}},ve={top:16,right:16,bottom:16,left:16},Oe=e=>Math.max(0,e-ve.left-ve.right),Ne=e=>Math.max(0,e-ve.top-ve.bottom),Ot=(e,t)=>({width:Oe(e),height:Ne(t)}),_e=({width:e,height:t,children:r})=>n.jsx(s.Box,{pt:ve.top,pr:ve.right,pb:ve.bottom,pl:ve.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:r});h.forwardRef(function({value:t,onChange:r,...a},l){return n.jsx(s.TextInput,{ref:l,value:t,onChange:r,...a})});class yu{constructor({valueRange:t,colorRange:r}){V(this,"mapper");this.mapper=ot.interpolate(t,r)}getColor(t){return this.mapper(t)}}function vu(e,t){if(e.type==="static")return e.staticColor;if(e.type==="continuous")try{const r=Number(t);if(Number.isNaN(r))throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${t}, parsed: ${r}`);return new yu(e).getColor(r)}catch(r){return console.error(r),"black"}return"black"}const _u=vu;function P(e){const[t,r]=e.split(".");return{queryID:t,columnKey:r}}function Ts(e){return!!e&&!!e.columnKey&&!!e.queryID}function xu(e){return e.includes(".")?P(e):{queryID:"",columnKey:e}}function Ae(e,t){var l;const{queryID:r,columnKey:a}=P(t);return r?a?((l=e[r])==null?void 0:l.map(o=>o[a]))??[]:e[r]:[]}function Rt(e,t){const{queryID:r}=P(t);return r?e[r]:[]}function wu(e){return Object.values(e)[0]}function en(e,t){const{queryID:r,columnKey:a}=P(t);return e[a]}const Ge={CryptoJS:Ha,d3Array:_s,dayjs:M,lodash:y,numbro:We,mathjs:qe,faker:ld.faker,popmotion:Xd},mu=[{name:"CryptoJS",url:"https://github.com/brix/crypto-js",version:"4.1.1"},{name:"d3Array",url:"https://github.com/d3/d3-array",version:"3.2.4"},{name:"dayjs",url:"https://day.js.org/",version:"1.11.6"},{name:"lodash",url:"https://lodash.com/docs/4.17.15",version:"4.17.21"},{name:"mathjs",url:"https://mathjs.org/",version:"11.12.0"},{name:"numbro",url:"https://numbrojs.com/",version:"2.3.6"},{name:"faker",url:"https://fakerjs.dev/",version:"7.6.0"},{name:"popmotion",url:"https://popmotion.io/",version:"11.0.3"}],Cu=e=>`
10
10
  <tr>
11
11
  <td><code>${e.name}</code></td>
12
12
  <td>
@@ -18,7 +18,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
18
18
  >
19
19
  </td>
20
20
  </tr>
21
- `,wu=e=>`
21
+ `,Su=e=>`
22
22
  <p>
23
23
  ${e("function_utils.description")}
24
24
  </p>
@@ -30,12 +30,12 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
30
30
  </tr>
31
31
  </thead>
32
32
  <tbody>
33
- ${_u.map(xu).join("")}
33
+ ${mu.map(Cu).join("")}
34
34
  </tbody>
35
35
  </table>
36
- `,Ss=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
37
- `),kt={type:"none",config:{},fallback:"0"};function mu(e){const t=Array.from(e).sort((a,l)=>a-l),r=Math.floor(t.length/2);return t.length%2===0?(t[r-1]+t[r])/2:t[r]}function Cu(e,t){switch(t.type){case"sum":return y.sum(e);case"mean":return y.mean(e);case"median":return mu(e);case"max":return y.max(e);case"min":return y.min(e);case"quantile":return qt.quantile(e,t.config.p);case"CV":if(e.length===0)return Number.NaN;const r=Ne.std(...e),a=Ne.mean(...e);return a?r/a:Number.NaN;case"std":return e.length===0?Number.NaN:Ne.std(...e);default:return e}}function Nn(e,t){const r=e.map(Number),a=Cu(r,t);return typeof a=="number"?Number.isFinite(a)?a:t.fallback:a??t.fallback}function Su(e,t,r){try{const a=Rt(e,t);return new Function(`return ${r.config.func}`)()({queryData:a},je)}catch(a){return console.error(a),a.message}}function Tu(e,t,r){try{const a=Ve(e,t),{method:l}=r.config;return y[l](a)}catch(a){return console.error(a),r.fallback}}function Gn(e,t,r){try{return r.type==="custom"?Su(e,t,r):r.type==="pick_record"?Tu(e,t,r):Nn(Ve(e,t),r)}catch(a){return console.error(a),null}}const Ts=h.createContext(null),Fn=Ts.Provider;function Nt(){const e=h.useContext(Ts);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const W=()=>Nt(),ks=()=>Nt(),zs=h.createContext({}),jn=zs.Provider;function Ds(){return h.useContext(zs)}const Qn=h.createContext(null),Wn=Qn.Provider;function Un(){const e=h.useContext(Qn);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const F=()=>Un(),ku={inEditMode:!1},Gt=h.createContext(ku),Is=h.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),Yn=Is.Provider;function Kn(){const e=h.useContext(Is);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const be=()=>Kn(),re=()=>Kn();function Ms(){try{return Kn(),!0}catch{return!1}}const As=()=>Ms(),Ps=()=>Ms(),zu={fullScreenPanelID:"",setFullScreenPanelID:y.noop},Xn=h.createContext(zu);function Vs(){const e=h.useContext(Xn);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const Du={en:"en",zh:"zh-cn"};function Zn({children:e}){const{i18n:t}=x.useTranslation(),r=h.useMemo(()=>{const a=t.language;return Du[a]??"en"},[t.language]);return n.jsx(ps.DatesProvider,{settings:{locale:r,firstDayOfWeek:1},children:e})}const J=()=>Un(),Jn={fontSize:"14px",lineHeight:"32px",color:"#3D3E45",ul:{paddingLeft:"2em",margin:"6px 0 0"},p:{margin:"0 !important"},a:{WebkitTapHighlightColor:"transparent",color:"rgb(34, 139, 230)",textDecoration:"none","&:hover":{textDecoration:"underline"},"&:active, &:hover":{outlineWidth:0}},table:{tr:{"th, td":{padding:"0 .5em"}}},"table.rich-text-table-render, div.tableWrapper table":{"th, td":{border:"1px solid #eaeaea"},"tr:last-of-type td":{borderBottom:"1px solid #eaeaea"}},".resize-cursor":{cursor:"col-resize"},details:{summary:{listStyle:"none",cursor:"pointer",transition:"color 300ms ease",userSelect:"none"},"summary::-webkit-details-marker":{display:"none"},"summary:hover":{color:"black","&::before":{opacity:1}},"summary::before":{content:'"►"',fontSize:"10px",margin:"0px 5px",opacity:.5,display:"inline-block",transition:"opacity 300ms ease, transform 300ms ease"}},"details[open] summary::before":{transform:"rotate(90deg)"},"details + details":{marginTop:"10px"},blockquote:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45",margin:"0 0 14px"}},Hn="grad_color_",Iu=new RegExp(`^(?!${Hn})(.+)$`);function $s(e){return e&&e.replace(Iu,`${Hn}$1`)}const Mu=e=>{const r="abcdefghijklmnopqrstuvwxyz",l=`1234567890${r}${r.toUpperCase()}`.split(""),o=new Uint8Array(e);crypto.getRandomValues(o);const i=o.reduce((c,d)=>`${c}${l[d&61]}`,"");return`${Hn}${i}`};function Au(e,t,r){try{if(!Number.isFinite(t)||!Number.isFinite(r))throw new Error(`[getColorMappingFunc] invalid interval with min[${t}] max[${r}]`);if(e.length<2)throw new Error("[getColorMappingFunc] expected at least 2 colors");const a=(r-t)/(e.length-1),l=vs.range(t,r+a,a);return Kd.scaleLinear(l,e)}catch(a){return console.error(a),()=>"inherit"}}function Es(e,t,r,a){const l=Number(e.getAttribute(r)),o=e.getAttribute(a);if(!o)return l;const i=Number(t[o]);return Number.isFinite(i)?i:l}function Pu(e,t){const r={};return e.querySelectorAll("color-mapping").forEach(l=>{const o=l.getAttribute(De.color),i=Es(l,t,De.min_val,De.min_var),c=Es(l,t,De.max_val,De.max_var),d=l.getAttribute(De.variable);if(!o||!Number.isFinite(i)||!Number.isFinite(c)||!d)return;const u=Number(t[d]);if(!Number.isFinite(u))return;const p=o.split(","),f=Au(p,i,c);r[`#${$s(l.id)}`]={color:f(u)}}),r}function Vu(e){const t=y.get(e,De.color,[]),r=y.get(e,De.min_val,""),a=y.get(e,De.min_var,""),l=y.get(e,De.max_val,""),o=y.get(e,De.max_var,""),i=y.get(e,De.variable,""),c=t.length===0&&[r,a,l,o,i].every(d=>d==="");return{colors:t,min_val:r,min_var:a,max_val:l,max_var:o,variable:i,empty:c}}const se={color:"data-colors",min_val:"data-min-val",min_var:"data-min-var",max_val:"data-max-val",max_var:"data-max-var",variable:"data-var"},De=se,Bs="colorMapping",Ls=En.Mark.create({name:Bs,addAttributes(){return{id:{default:Mu(6),parseHTML:e=>{const t=e.getAttribute("id");return $s(t)}},[se.color]:{default:[],parseHTML:e=>{const t=e.getAttribute(se.color);return t?t.split(","):[]}},[se.min_val]:{default:0,parseHTML:e=>e.getAttribute(se.min_val)},[se.min_var]:{default:"",parseHTML:e=>e.getAttribute(se.min_var)},[se.max_val]:{default:100,parseHTML:e=>e.getAttribute(se.max_val)},[se.max_var]:{default:"",parseHTML:e=>e.getAttribute(se.max_var)},[se.variable]:{default:"",parseHTML:e=>e.getAttribute(se.variable)}}},parseHTML(){return[{tag:"color-mapping",getAttrs:e=>typeof e=="string"?(console.debug(e),!1):Object.values(De).map(t=>e.getAttribute(t))}]},renderHTML({HTMLAttributes:e}){return["color-mapping",e,0]},addCommands(){return{setColorMapping:e=>({commands:t})=>{const{colors:r,min_val:a,min_var:l,max_val:o,max_var:i,variable:c}=e;return t.setMark(this.name,{[se.color]:r,[se.min_val]:a,[se.min_var]:l,[se.max_val]:o,[se.max_var]:i,[se.variable]:c})},unsetColorMapping:()=>({commands:e})=>e.unsetMark(this.name)}}}),He={grid:{axis:"#97999D",scope:"rgba(47,140,192,0.1)",boundary:"#789AB4",reference:"#CFCFD8"},graphics:{compared:{blueDark:"#3E7CAB",blue:"#6398C7",blueLight:"#7CB0DF",blue10:"#6398C71a",redDark:"#AF5F6B",red:"#CD7C88",redLight:"#E794A0",red10:"#CD7C881a"},gradient:{distributed:"linear-gradient(90deg, #1babe6 0%, #2fc8c8 28.63%, #98d44b 48.86%, #ffd057 67.53%, #f5ae53 80.6%, #e76441 91.18%, #b90000 100%)",protrude:"linear-gradient(180deg, #ec73734d 0%, #ec737300 100%)"},level:{lv0:"#6398C7",lv1:"#61B5BF",lv2:"#54D4BB",lv3:"#F5D277",lv4:"#E8BB7F",lv5:"#DB9E84",lv6:"#CB8089"},depth:{dp0:"#FFF7F8",dp1:"#FFE1E1",dp2:"#FDBCBC",dp3:"#F39494",dp4:"#FA4242",dp5:"#E21212"},multiple:{c1:"#66B4DB",c2:"#E46464",c3:"#EEBA00",c4:"#33A678",c5:"#9D88CB",c6:"#939943",c7:"#E49792",c8:"#09A2B8",c9:"#AF5F6B",c10:"#6CA157",c11:"#3E7CAB",c12:"#6398C7",c13:"#E692BA",c14:"#97B566",c15:"#8CACE2",c16:"#CA79AC",c17:"#6DBC80",c18:"#B08F4B",c19:"#39BFA2",c20:"#826BAF"}}};function $u(){ce.registerTheme("merico-light",{color:Object.values(He.graphics.multiple),visualMap:{color:Object.values(He.graphics.depth).reverse()},axes:[{type:"all",name:"通用坐标轴",axisLineColor:"#97999D",axisTickColor:"#97999D",axisLabelShow:!0,axisLabelColor:"#818388",splitLineShow:!0,splitLineColor:["#E0E6F1"]}]})}function qs(){$u()}function Eu(e){return({option:r,...a})=>{const{aggValue:l,formattedValue:o,label:i}=r,{hovered:c,ref:d}=te.useHover(),u=e==="aggregated"?l:o,p=e==="aggregated"?o:l;return n.jsx(s.Box,{ref:d,...a,children:n.jsxs(s.Group,{wrap:"nowrap",justify:"space-between",children:[n.jsx(s.Text,{size:"sm",sx:{flexGrow:1},children:i}),n.jsx(s.Text,{size:"xs",opacity:c?1:.65,sx:{flexShrink:0},children:c?p:u})]})})}}const Z=e=>(t,r)=>{t!==null&&e(t,r)},Rn=T.observer(h.forwardRef((e,t)=>{const{label:r,value:a,onChange:l,description:o,required:i,clearable:c=!0,sx:d,preview:u="formatted",zIndex:p=340}=e;x.useTranslation();const{panel:f}=re(),v=h.useMemo(()=>f.variableOptions(a,c),[a,c]);return v.length===0?n.jsx(s.TextInput,{ref:t,label:r,placeholder:a,readOnly:!0,disabled:!0}):n.jsx(s.Select,{ref:t,label:r,description:o,renderOption:Eu(u),data:v,value:a,required:i,sx:d,maxDropdownHeight:500,comboboxProps:{withinPortal:!0,zIndex:p},onChange:Z(l)})})),Os={static:{type:"static",value:10},dynamic:{type:"dynamic",value:["function getValue({ variables }, { lodash, interpolate }) {"," // your code goes here"," return 100;","}"].join(`
38
- `)}},Bu=({value:e,onChange:t})=>{const r=a=>{a&&t(a)};return n.jsx(s.Box,{children:n.jsx(Te,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Lu=({value:e,onChange:t})=>{const{t:r}=x.useTranslation(),[a,{setTrue:l,setFalse:o}]=O.useBoolean(),[i,c]=h.useState(e),d=()=>{o();const{type:v,value:_}=i,w={type:v,value:_};c(w),t(w)},u=()=>{o(),c(e)},p=v=>{c(_=>({..._,value:v}))},f=()=>{p(Os.dynamic.value)};return n.jsxs(n.Fragment,{children:[n.jsx(s.Box,{sx:{width:"50%"},children:n.jsx(s.Button,{color:"grape",variant:"filled",leftSection:n.jsx(S.IconMathFunction,{size:16}),mt:24,onClick:l,sx:{flexGrow:0},children:r("chart.number_or_dynamic_value.dynamic.setup")})}),n.jsx(s.Modal,{size:800,title:r("chart.number_or_dynamic_value.dynamic.setup_title"),opened:a,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:a&&n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mt:10,mb:-10,label:r("chart.number_or_dynamic_value.dynamic.guide"),labelPosition:"center",variant:"dashed"}),n.jsx(Bu,{value:i.value,onChange:p}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:f,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:r("common.actions.reset_to_default")}),n.jsxs(s.Group,{justify:"right",children:[n.jsx(s.Button,{onClick:u,variant:"subtle",children:r("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:d,children:r("common.actions.save")})]})]})]})})]})},qu=({value:e,onChange:t})=>e.type!=="dynamic"?null:n.jsx(Lu,{value:e,onChange:t}),Ou=({value:e,onChange:t})=>{if(e.type!=="static")return null;const r=a=>{t({...e,value:typeof a=="string"?"":a})};return n.jsx(s.NumberInput,{defaultValue:18,label:" ",hideControls:!0,value:e.value,onChange:r})},Ns=h.forwardRef(({label:e="Value",value:t,onChange:r},a)=>{const{t:l,i18n:o}=x.useTranslation(),i=d=>{d!=="static"&&d!=="dynamic"||r({...Os[d]})},c=h.useMemo(()=>[{label:l("chart.number_or_dynamic_value.type.static"),value:"static"},{label:l("chart.number_or_dynamic_value.type.dynamic"),value:"dynamic"}],[o.language]);return n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(s.Select,{ref:a,label:e,data:c,value:t.type,onChange:i,sx:{flexGrow:1}}),n.jsx(Ou,{value:t,onChange:r}),n.jsx(qu,{value:t,onChange:r})]})});function Gs(e,t,r){if(!e.type)return r;if(e.type==="static"){const{value:l}=e;return Number(l)}const{value:a}=e;try{const l=new Function(`return ${a}`)()({variables:t},{lodash:y,interpolate:ot.interpolate});return Number(l)}catch(l){return console.error(`[getNumberOrDynamicValue] failed parsing custom function, error: ${l.message}`),10}}function Fs(e){return{type:"continuous",id:"continuous-example",min:{type:"static",value:0},max:{type:"static",value:100},orient:"horizontal",left:"center",top:"top",text:["",""],calculable:!0,itemWidth:15,itemHeight:140,show:!0,inRange:{color:e??Object.values(He.graphics.depth)},skipRange:{lt_min:"",min:"",max:"",gt_max:""}}}function Nu(){return{type:"piecewise",piecewise_mode:"pieces",id:"piecewise-visualmap",min:{type:"static",value:0},max:{type:"static",value:100},align:"auto",orient:"horizontal",left:"center",top:"top",itemWidth:15,itemHeight:15,show:!0,precision:0,pieces:[js()],categories:[]}}function et(){return Fs()}function Gu(){return{compared:Object.values(He.graphics.compared),level:Object.values(He.graphics.level),depth:Object.values(He.graphics.depth),yellow_blue:["#8f531d","#ffd347","#e3efe3","#eefaee","#4ecbbf","#003f94"],blue:["#f9fcff","#48b3e9","#003f94"],darkgreen_pink:["#0c525a","#f21f99"],spectrum:["#ff0000","#ffff00","#00ff00","#00ffff","#0000ff","#ff00ff","#ff0000"]}}function tn(e,t){const{min:r,max:a}=e,l=Gs(r,t),o=Gs(a,t);if(e.type==="continuous"){const{skipRange:f,text:v,..._}=e;return{..._,min:l,max:o,text:[...v]}}const{piecewise_mode:i,pieces:c,categories:d,...u}=e,p={...u};return delete p.min,delete p.max,i==="pieces"?p.pieces=c.map(f=>{const v={};f.label&&(v.label=f.label),f.color&&(v.color=f.color);const _=Number(f.lower.value);f.lower.value===""?v[f.lower.symbol]=l:Number.isFinite(_)&&(v[f.lower.symbol]=_);const w=Number(f.upper.value);return f.upper.value===""?v[f.upper.symbol]=o:Number.isFinite(w)&&(v[f.upper.symbol]=w),v}):i==="categories"&&(p.categories=d),p}const zt=e=>({followVisualMap:!e,color:e});function er(e,t,r,a){if(a.type!=="continuous")return zt("");const{skipRange:l}=a;return e===t?zt(l.min):e===r?zt(l.max):e<t?zt(l.lt_min):e>r?zt(l.gt_max):zt("")}function js(){return{lower:{value:"0",symbol:"gt"},upper:{value:"",symbol:"lt"},label:"",color:""}}const Fu=Gu(),ju=({colors:e,applyPalette:t,zIndex:r=340})=>{const{t:a}=x.useTranslation(),l=`linear-gradient(to right, ${e.join(", ")})`;return n.jsxs(s.Menu,{shadow:"md",width:300,withinPortal:!0,zIndex:r,children:[n.jsx(s.Menu.Target,{children:n.jsxs(s.UnstyledButton,{children:[n.jsx(s.Text,{style:{display:"inline-block",fontSize:"0.875rem",fontWeight:500,color:"#212529",wordBreak:"break-word",cursor:"default"},children:a("chart.color.color_gradient")}),n.jsxs(s.Group,{style:{padding:"0.4375rem 0.625rem",border:"0.0625rem solid #ced4da",borderRadius:"0.25rem",columnGap:10},children:[n.jsx(s.Box,{style:{height:"20px",flexGrow:1,backgroundImage:l,borderRadius:4}}),n.jsx(S.IconSelector,{size:14,color:"rgb(134, 142, 150)"})]})]})}),n.jsxs(s.Menu.Dropdown,{children:[n.jsx(s.Menu.Label,{children:a("chart.visual_map.built_in_palettes")}),n.jsx(s.Menu.Divider,{}),Object.entries(Fu).map(([o,i])=>n.jsx(s.Tooltip,{label:a("chart.visual_map.use_palette_x",{x:o}),children:n.jsx(s.Menu.Item,{children:n.jsx(s.Box,{style:{height:"20px",width:"100%",backgroundImage:`linear-gradient(to right, ${i.join(", ")})`,borderRadius:4,boxShadow:"0 0 3px 0 #eee",cursor:"pointer"},onClick:()=>{t(i)},title:o})})},o))]})]})},Qu=({color:e,index:t,handleChange:r,handleRemove:a})=>{const[l,{setTrue:o,setFalse:i}]=O.useBoolean(!1),{ref:c,handleRef:d}=Ln.useSortable({id:e.id,index:t});return n.jsxs(s.Flex,{ref:c,gap:"sm",justify:"flex-start",align:"center",direction:"row",wrap:"nowrap",onMouseEnter:o,onMouseLeave:i,children:[n.jsx(s.Center,{style:{minWidth:"30px",maxWidth:"30px",flex:0},children:l?n.jsx(s.ActionIcon,{size:"xs",ref:d,variant:"subtle",children:n.jsx(S.IconGripVertical,{})}):n.jsx(s.Badge,{size:"sm",variant:"light",children:t+1})}),n.jsx("div",{style:{flex:1},children:n.jsx(s.ColorInput,{styles:{root:{flexGrow:1}},popoverProps:{withinPortal:!0,zIndex:340},size:"xs",value:e.value,onChange:r})}),n.jsx("div",{style:{minWidth:"40px",maxWidth:"40px",flex:0},children:n.jsx(s.CloseButton,{onClick:a,size:"sm"})})]})},Qs=h.forwardRef(({value:e,onChange:t,zIndex:r=340},a)=>{const{t:l}=x.useTranslation(),o=h.useMemo(()=>e.map(w=>({id:Ke.v4(),value:w})),[e]),i=w=>{t([...e,w])},c=w=>{const m=[...e];m.splice(w,1),t(m)},d=w=>{t([...w])},u=w=>m=>{const k=[...e];k[w]=m,t(k)},[p,f]=h.useState(""),v=()=>{p&&(i(p),f(""))},_=w=>{const{source:m,target:k}=w.operation,z=hs.move(o,m,k);t(z.map(D=>D.value))};return n.jsxs(s.Stack,{ref:a,children:[n.jsx(ju,{colors:e,applyPalette:d,zIndex:r}),n.jsx(Bn.DragDropProvider,{onDragEnd:_,children:o.map((w,m)=>n.jsx(Qu,{color:w,handleChange:u(m),handleRemove:()=>c(m),index:m},w.id))}),n.jsxs(s.Flex,{gap:"sm",justify:"flex-start",align:"center",direction:"row",wrap:"nowrap",children:[n.jsx("div",{style:{minWidth:"30px",maxWidth:"30px",flex:0}}),n.jsx("div",{style:{flex:1},children:n.jsx(s.ColorInput,{popoverProps:{withinPortal:!0,zIndex:r},placeholder:l("chart.color.click_to_add_a_color"),value:p,onChange:f,onBlur:v,size:"xs"})}),n.jsx("div",{style:{minWidth:"40px",maxWidth:"40px",flex:0}})]})]})}),Wu=({defaultValues:e,onSubmit:t,unset:r})=>{const{t:a}=x.useTranslation(),l=b.useForm({defaultValues:e}),{control:o,handleSubmit:i,reset:c}=l;h.useEffect(()=>{c(e)},[e]);const d=h.useCallback(()=>c(e),[c,e]);return n.jsxs(s.Box,{children:[n.jsx(s.Divider,{color:"rgb(206, 212, 218)",variant:"dotted",my:"1rem"}),n.jsxs(s.Box,{px:"1rem",children:[n.jsx(b.Controller,{control:o,name:"variable",render:({field:u})=>n.jsx(Rn,{label:a("rich_text.color_mapping.choose_value_var"),clearable:!1,preview:"aggregated",zIndex:340,...u})}),n.jsxs(s.Group,{grow:!0,justify:"space-between",children:[n.jsx(b.Controller,{name:"min_var",control:o,render:({field:u})=>n.jsx(Rn,{label:a("rich_text.color_mapping.min.var"),preview:"aggregated",sx:{flexGrow:1,maxWidth:"unset"},...u})}),n.jsx(b.Controller,{name:"min_val",control:o,render:({field:u})=>n.jsx(s.TextInput,{label:a("rich_text.color_mapping.min.val"),...u,sx:{maxWidth:"120px",flexGrow:0}})})]}),n.jsxs(s.Group,{grow:!0,justify:"space-between",children:[n.jsx(b.Controller,{name:"max_var",control:o,render:({field:u})=>n.jsx(Rn,{label:a("rich_text.color_mapping.max.var"),preview:"aggregated",sx:{flexGrow:1,maxWidth:"unset"},...u})}),n.jsx(b.Controller,{name:"max_val",control:o,render:({field:u})=>n.jsx(s.TextInput,{label:a("rich_text.color_mapping.max.val"),...u,sx:{maxWidth:"120px",flexGrow:0}})})]}),n.jsx(b.Controller,{control:o,name:"colors",render:({field:u})=>n.jsx(Qs,{...u})})]}),n.jsx(s.Divider,{color:"rgb(206, 212, 218)",variant:"dotted",my:"1rem"}),n.jsxs(s.Group,{justify:"space-between",px:"1rem",pb:"0.75rem",children:[n.jsxs(s.Group,{justify:"flex-start",children:[n.jsx(s.Button,{color:"red",size:"xs",onClick:r,leftSection:n.jsx(S.IconTrash,{size:18}),children:a("common.actions.clear")}),n.jsx(s.Button,{color:"orange",size:"xs",onClick:d,leftSection:n.jsx(S.IconArrowBackUp,{size:18}),children:a("common.actions.revert")})]}),n.jsx(s.Button,{color:"green",size:"xs",onClick:i(t),leftSection:n.jsx(S.IconDeviceFloppy,{size:18}),children:a("common.actions.save_changes")})]})]})};function Uu(e){if(e.length===0)return"";const t=r=>`${r/(e.length-1)*100}%`;return e.map((r,a)=>`${r} ${t(a)}`).join(", ")}function Ws(e,...t){return`linear-gradient(${e}deg, ${Uu(t)})`}const Yu=()=>n.jsx("div",{style:{width:"20px",height:"13px",borderRadius:"2px",background:Ws(90,...Object.values(He.graphics.depth))}}),Ku=({disabled:e})=>n.jsx(s.Box,{sx:{width:"16px",height:"10px",borderRadius:"2px",background:Ws(90,...Object.values(He.graphics.depth)),opacity:e?"0.5":1,position:"relative","&:after":{position:"absolute",content:"''",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"15px",height:"15px",background:`
36
+ `,ks=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
37
+ `),kt={type:"none",config:{},fallback:"0"};function Tu(e){const t=Array.from(e).sort((a,l)=>a-l),r=Math.floor(t.length/2);return t.length%2===0?(t[r-1]+t[r])/2:t[r]}function ku(e,t){switch(t.type){case"sum":return y.sum(e);case"mean":return y.mean(e);case"median":return Tu(e);case"max":return y.max(e);case"min":return y.min(e);case"quantile":return qt.quantile(e,t.config.p);case"CV":if(e.length===0)return Number.NaN;const r=qe.std(...e),a=qe.mean(...e);return a?r/a:Number.NaN;case"std":return e.length===0?Number.NaN:qe.std(...e);default:return e}}function Nn(e,t){const r=e.map(Number),a=ku(r,t);return typeof a=="number"?Number.isFinite(a)?a:t.fallback:a??t.fallback}function zu(e,t,r){try{const a=Rt(e,t);return new Function(`return ${r.config.func}`)()({queryData:a},Ge)}catch(a){return console.error(a),a.message}}function Du(e,t,r){try{const a=Ae(e,t),{method:l}=r.config;return y[l](a)}catch(a){return console.error(a),r.fallback}}function Gn(e,t,r){try{return r.type==="custom"?zu(e,t,r):r.type==="pick_record"?Du(e,t,r):Nn(Ae(e,t),r)}catch(a){return console.error(a),null}}const zs=h.createContext(null),Fn=zs.Provider;function Nt(){const e=h.useContext(zs);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const W=()=>Nt(),Ds=()=>Nt(),Is=h.createContext({}),jn=Is.Provider;function Ms(){return h.useContext(Is)}const Qn=h.createContext(null),Wn=Qn.Provider;function Un(){const e=h.useContext(Qn);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const F=()=>Un(),Iu={inEditMode:!1},Gt=h.createContext(Iu),Vs=h.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),Kn=Vs.Provider;function Yn(){const e=h.useContext(Vs);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const fe=()=>Yn(),re=()=>Yn();function Ps(){try{return Yn(),!0}catch{return!1}}const As=()=>Ps(),$s=()=>Ps(),Mu={fullScreenPanelID:"",setFullScreenPanelID:y.noop},Xn=h.createContext(Mu);function Es(){const e=h.useContext(Xn);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const Vu={en:"en",zh:"zh-cn"};function Zn({children:e}){const{i18n:t}=x.useTranslation(),r=h.useMemo(()=>{const a=t.language;return Vu[a]??"en"},[t.language]);return n.jsx(hs.DatesProvider,{settings:{locale:r,firstDayOfWeek:1},children:e})}const J=()=>Un(),Jn={fontSize:"14px",lineHeight:"32px",color:"#3D3E45",ul:{paddingLeft:"2em",margin:"6px 0 0"},p:{margin:"0 !important"},a:{WebkitTapHighlightColor:"transparent",color:"rgb(34, 139, 230)",textDecoration:"none","&:hover":{textDecoration:"underline"},"&:active, &:hover":{outlineWidth:0}},table:{tr:{"th, td":{padding:"0 .5em"}}},"table.rich-text-table-render, div.tableWrapper table":{"th, td":{border:"1px solid #eaeaea"},"tr:last-of-type td":{borderBottom:"1px solid #eaeaea"}},".resize-cursor":{cursor:"col-resize"},details:{summary:{listStyle:"none",cursor:"pointer",transition:"color 300ms ease",userSelect:"none"},"summary::-webkit-details-marker":{display:"none"},"summary:hover":{color:"black","&::before":{opacity:1}},"summary::before":{content:'"►"',fontSize:"10px",margin:"0px 5px",opacity:.5,display:"inline-block",transition:"opacity 300ms ease, transform 300ms ease"}},"details[open] summary::before":{transform:"rotate(90deg)"},"details + details":{marginTop:"10px"},blockquote:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45",margin:"0 0 14px"}},Hn="grad_color_",Pu=new RegExp(`^(?!${Hn})(.+)$`);function Bs(e){return e&&e.replace(Pu,`${Hn}$1`)}const Au=e=>{const r="abcdefghijklmnopqrstuvwxyz",l=`1234567890${r}${r.toUpperCase()}`.split(""),o=new Uint8Array(e);crypto.getRandomValues(o);const i=o.reduce((c,d)=>`${c}${l[d&61]}`,"");return`${Hn}${i}`};function $u(e,t,r){try{if(!Number.isFinite(t)||!Number.isFinite(r))throw new Error(`[getColorMappingFunc] invalid interval with min[${t}] max[${r}]`);if(e.length<2)throw new Error("[getColorMappingFunc] expected at least 2 colors");const a=(r-t)/(e.length-1),l=_s.range(t,r+a,a);return Jd.scaleLinear(l,e)}catch(a){return console.error(a),()=>"inherit"}}function Ls(e,t,r,a){const l=Number(e.getAttribute(r)),o=e.getAttribute(a);if(!o)return l;const i=Number(t[o]);return Number.isFinite(i)?i:l}function Eu(e,t){const r={};return e.querySelectorAll("color-mapping").forEach(l=>{const o=l.getAttribute(ke.color),i=Ls(l,t,ke.min_val,ke.min_var),c=Ls(l,t,ke.max_val,ke.max_var),d=l.getAttribute(ke.variable);if(!o||!Number.isFinite(i)||!Number.isFinite(c)||!d)return;const u=Number(t[d]);if(!Number.isFinite(u))return;const p=o.split(","),f=$u(p,i,c);r[`#${Bs(l.id)}`]={color:f(u)}}),r}function Bu(e){const t=y.get(e,ke.color,[]),r=y.get(e,ke.min_val,""),a=y.get(e,ke.min_var,""),l=y.get(e,ke.max_val,""),o=y.get(e,ke.max_var,""),i=y.get(e,ke.variable,""),c=t.length===0&&[r,a,l,o,i].every(d=>d==="");return{colors:t,min_val:r,min_var:a,max_val:l,max_var:o,variable:i,empty:c}}const se={color:"data-colors",min_val:"data-min-val",min_var:"data-min-var",max_val:"data-max-val",max_var:"data-max-var",variable:"data-var"},ke=se,qs="colorMapping",Os=En.Mark.create({name:qs,addAttributes(){return{id:{default:Au(6),parseHTML:e=>{const t=e.getAttribute("id");return Bs(t)}},[se.color]:{default:[],parseHTML:e=>{const t=e.getAttribute(se.color);return t?t.split(","):[]}},[se.min_val]:{default:0,parseHTML:e=>e.getAttribute(se.min_val)},[se.min_var]:{default:"",parseHTML:e=>e.getAttribute(se.min_var)},[se.max_val]:{default:100,parseHTML:e=>e.getAttribute(se.max_val)},[se.max_var]:{default:"",parseHTML:e=>e.getAttribute(se.max_var)},[se.variable]:{default:"",parseHTML:e=>e.getAttribute(se.variable)}}},parseHTML(){return[{tag:"color-mapping",getAttrs:e=>typeof e=="string"?(console.debug(e),!1):Object.values(ke).map(t=>e.getAttribute(t))}]},renderHTML({HTMLAttributes:e}){return["color-mapping",e,0]},addCommands(){return{setColorMapping:e=>({commands:t})=>{const{colors:r,min_val:a,min_var:l,max_val:o,max_var:i,variable:c}=e;return t.setMark(this.name,{[se.color]:r,[se.min_val]:a,[se.min_var]:l,[se.max_val]:o,[se.max_var]:i,[se.variable]:c})},unsetColorMapping:()=>({commands:e})=>e.unsetMark(this.name)}}}),Ze={grid:{axis:"#97999D",scope:"rgba(47,140,192,0.1)",boundary:"#789AB4",reference:"#CFCFD8"},graphics:{compared:{blueDark:"#3E7CAB",blue:"#6398C7",blueLight:"#7CB0DF",blue10:"#6398C71a",redDark:"#AF5F6B",red:"#CD7C88",redLight:"#E794A0",red10:"#CD7C881a"},gradient:{distributed:"linear-gradient(90deg, #1babe6 0%, #2fc8c8 28.63%, #98d44b 48.86%, #ffd057 67.53%, #f5ae53 80.6%, #e76441 91.18%, #b90000 100%)",protrude:"linear-gradient(180deg, #ec73734d 0%, #ec737300 100%)"},level:{lv0:"#6398C7",lv1:"#61B5BF",lv2:"#54D4BB",lv3:"#F5D277",lv4:"#E8BB7F",lv5:"#DB9E84",lv6:"#CB8089"},depth:{dp0:"#FFF7F8",dp1:"#FFE1E1",dp2:"#FDBCBC",dp3:"#F39494",dp4:"#FA4242",dp5:"#E21212"},multiple:{c1:"#66B4DB",c2:"#E46464",c3:"#EEBA00",c4:"#33A678",c5:"#9D88CB",c6:"#939943",c7:"#E49792",c8:"#09A2B8",c9:"#AF5F6B",c10:"#6CA157",c11:"#3E7CAB",c12:"#6398C7",c13:"#E692BA",c14:"#97B566",c15:"#8CACE2",c16:"#CA79AC",c17:"#6DBC80",c18:"#B08F4B",c19:"#39BFA2",c20:"#826BAF"}}};function Lu(){ie.registerTheme("merico-light",{color:Object.values(Ze.graphics.multiple),visualMap:{color:Object.values(Ze.graphics.depth).reverse()},axes:[{type:"all",name:"通用坐标轴",axisLineColor:"#97999D",axisTickColor:"#97999D",axisLabelShow:!0,axisLabelColor:"#818388",splitLineShow:!0,splitLineColor:["#E0E6F1"]}]})}function Ns(){Lu()}function qu(e){return({option:r,...a})=>{const{aggValue:l,formattedValue:o,label:i}=r,{hovered:c,ref:d}=ne.useHover(),u=e==="aggregated"?l:o,p=e==="aggregated"?o:l;return n.jsx(s.Box,{ref:d,...a,children:n.jsxs(s.Group,{wrap:"nowrap",justify:"space-between",children:[n.jsx(s.Text,{size:"sm",sx:{flexGrow:1},children:i}),n.jsx(s.Text,{size:"xs",opacity:c?1:.65,sx:{flexShrink:0},children:c?p:u})]})})}}const Z=e=>(t,r)=>{t!==null&&e(t,r)},Rn=T.observer(h.forwardRef((e,t)=>{const{label:r,value:a,onChange:l,description:o,required:i,clearable:c=!0,sx:d,preview:u="formatted",zIndex:p=340}=e;x.useTranslation();const{panel:f}=re(),v=h.useMemo(()=>f.variableOptions(a,c),[a,c]);return v.length===0?n.jsx(s.TextInput,{ref:t,label:r,placeholder:a,readOnly:!0,disabled:!0}):n.jsx(s.Select,{ref:t,label:r,description:o,renderOption:qu(u),data:v,value:a,required:i,sx:d,maxDropdownHeight:500,comboboxProps:{withinPortal:!0,zIndex:p},onChange:Z(l)})})),Gs={static:{type:"static",value:10},dynamic:{type:"dynamic",value:["function getValue({ variables }, { lodash, interpolate }) {"," // your code goes here"," return 100;","}"].join(`
38
+ `)}},Ou=({value:e,onChange:t})=>{const r=a=>{a&&t(a)};return n.jsx(s.Box,{children:n.jsx(Ce,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Nu=({value:e,onChange:t})=>{const{t:r}=x.useTranslation(),[a,{setTrue:l,setFalse:o}]=O.useBoolean(),[i,c]=h.useState(e),d=()=>{o();const{type:v,value:_}=i,w={type:v,value:_};c(w),t(w)},u=()=>{o(),c(e)},p=v=>{c(_=>({..._,value:v}))},f=()=>{p(Gs.dynamic.value)};return n.jsxs(n.Fragment,{children:[n.jsx(s.Box,{sx:{width:"50%"},children:n.jsx(s.Button,{color:"grape",variant:"filled",leftSection:n.jsx(S.IconMathFunction,{size:16}),mt:24,onClick:l,sx:{flexGrow:0},children:r("chart.number_or_dynamic_value.dynamic.setup")})}),n.jsx(s.Modal,{size:800,title:r("chart.number_or_dynamic_value.dynamic.setup_title"),opened:a,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:a&&n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mt:10,mb:-10,label:r("chart.number_or_dynamic_value.dynamic.guide"),labelPosition:"center",variant:"dashed"}),n.jsx(Ou,{value:i.value,onChange:p}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:f,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:r("common.actions.reset_to_default")}),n.jsxs(s.Group,{justify:"right",children:[n.jsx(s.Button,{onClick:u,variant:"subtle",children:r("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:d,children:r("common.actions.save")})]})]})]})})]})},Gu=({value:e,onChange:t})=>e.type!=="dynamic"?null:n.jsx(Nu,{value:e,onChange:t}),Fu=({value:e,onChange:t})=>{if(e.type!=="static")return null;const r=a=>{t({...e,value:typeof a=="string"?"":a})};return n.jsx(s.NumberInput,{defaultValue:18,label:" ",hideControls:!0,value:e.value,onChange:r})},Fs=h.forwardRef(({label:e="Value",value:t,onChange:r},a)=>{const{t:l,i18n:o}=x.useTranslation(),i=d=>{d!=="static"&&d!=="dynamic"||r({...Gs[d]})},c=h.useMemo(()=>[{label:l("chart.number_or_dynamic_value.type.static"),value:"static"},{label:l("chart.number_or_dynamic_value.type.dynamic"),value:"dynamic"}],[o.language]);return n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(s.Select,{ref:a,label:e,data:c,value:t.type,onChange:i,sx:{flexGrow:1}}),n.jsx(Fu,{value:t,onChange:r}),n.jsx(Gu,{value:t,onChange:r})]})});function js(e,t,r){if(!e.type)return r;if(e.type==="static"){const{value:l}=e;return Number(l)}const{value:a}=e;try{const l=new Function(`return ${a}`)()({variables:t},{lodash:y,interpolate:ot.interpolate});return Number(l)}catch(l){return console.error(`[getNumberOrDynamicValue] failed parsing custom function, error: ${l.message}`),10}}function Qs(e){return{type:"continuous",id:"continuous-example",min:{type:"static",value:0},max:{type:"static",value:100},orient:"horizontal",left:"center",top:"top",text:["",""],calculable:!0,itemWidth:15,itemHeight:140,show:!0,inRange:{color:e??Object.values(Ze.graphics.depth)},skipRange:{lt_min:"",min:"",max:"",gt_max:""}}}function ju(){return{type:"piecewise",piecewise_mode:"pieces",id:"piecewise-visualmap",min:{type:"static",value:0},max:{type:"static",value:100},align:"auto",orient:"horizontal",left:"center",top:"top",itemWidth:15,itemHeight:15,show:!0,precision:0,pieces:[Ws()],categories:[]}}function et(){return Qs()}function Qu(){return{compared:Object.values(Ze.graphics.compared),level:Object.values(Ze.graphics.level),depth:Object.values(Ze.graphics.depth),yellow_blue:["#8f531d","#ffd347","#e3efe3","#eefaee","#4ecbbf","#003f94"],blue:["#f9fcff","#48b3e9","#003f94"],darkgreen_pink:["#0c525a","#f21f99"],spectrum:["#ff0000","#ffff00","#00ff00","#00ffff","#0000ff","#ff00ff","#ff0000"]}}function tn(e,t){const{min:r,max:a}=e,l=js(r,t),o=js(a,t);if(e.type==="continuous"){const{skipRange:f,text:v,..._}=e;return{..._,min:l,max:o,text:[...v]}}const{piecewise_mode:i,pieces:c,categories:d,...u}=e,p={...u};return delete p.min,delete p.max,i==="pieces"?p.pieces=c.map(f=>{const v={};f.label&&(v.label=f.label),f.color&&(v.color=f.color);const _=Number(f.lower.value);f.lower.value===""?v[f.lower.symbol]=l:Number.isFinite(_)&&(v[f.lower.symbol]=_);const w=Number(f.upper.value);return f.upper.value===""?v[f.upper.symbol]=o:Number.isFinite(w)&&(v[f.upper.symbol]=w),v}):i==="categories"&&(p.categories=d),p}const zt=e=>({followVisualMap:!e,color:e});function er(e,t,r,a){if(a.type!=="continuous")return zt("");const{skipRange:l}=a;return e===t?zt(l.min):e===r?zt(l.max):e<t?zt(l.lt_min):e>r?zt(l.gt_max):zt("")}function Ws(){return{lower:{value:"0",symbol:"gt"},upper:{value:"",symbol:"lt"},label:"",color:""}}const Wu=Qu(),Uu=({colors:e,applyPalette:t,zIndex:r=340})=>{const{t:a}=x.useTranslation(),l=`linear-gradient(to right, ${e.join(", ")})`;return n.jsxs(s.Menu,{shadow:"md",width:300,withinPortal:!0,zIndex:r,children:[n.jsx(s.Menu.Target,{children:n.jsxs(s.UnstyledButton,{children:[n.jsx(s.Text,{style:{display:"inline-block",fontSize:"0.875rem",fontWeight:500,color:"#212529",wordBreak:"break-word",cursor:"default"},children:a("chart.color.color_gradient")}),n.jsxs(s.Group,{style:{padding:"0.4375rem 0.625rem",border:"0.0625rem solid #ced4da",borderRadius:"0.25rem",columnGap:10},children:[n.jsx(s.Box,{style:{height:"20px",flexGrow:1,backgroundImage:l,borderRadius:4}}),n.jsx(S.IconSelector,{size:14,color:"rgb(134, 142, 150)"})]})]})}),n.jsxs(s.Menu.Dropdown,{children:[n.jsx(s.Menu.Label,{children:a("chart.visual_map.built_in_palettes")}),n.jsx(s.Menu.Divider,{}),Object.entries(Wu).map(([o,i])=>n.jsx(s.Tooltip,{label:a("chart.visual_map.use_palette_x",{x:o}),children:n.jsx(s.Menu.Item,{children:n.jsx(s.Box,{style:{height:"20px",width:"100%",backgroundImage:`linear-gradient(to right, ${i.join(", ")})`,borderRadius:4,boxShadow:"0 0 3px 0 #eee",cursor:"pointer"},onClick:()=>{t(i)},title:o})})},o))]})]})},Ku=({color:e,index:t,handleChange:r,handleRemove:a})=>{const[l,{setTrue:o,setFalse:i}]=O.useBoolean(!1),{ref:c,handleRef:d}=Ln.useSortable({id:e.id,index:t});return n.jsxs(s.Flex,{ref:c,gap:"sm",justify:"flex-start",align:"center",direction:"row",wrap:"nowrap",onMouseEnter:o,onMouseLeave:i,children:[n.jsx(s.Center,{style:{minWidth:"30px",maxWidth:"30px",flex:0},children:l?n.jsx(s.ActionIcon,{size:"xs",ref:d,variant:"subtle",children:n.jsx(S.IconGripVertical,{})}):n.jsx(s.Badge,{size:"sm",variant:"light",children:t+1})}),n.jsx("div",{style:{flex:1},children:n.jsx(s.ColorInput,{styles:{root:{flexGrow:1}},popoverProps:{withinPortal:!0,zIndex:340},size:"xs",value:e.value,onChange:r})}),n.jsx("div",{style:{minWidth:"40px",maxWidth:"40px",flex:0},children:n.jsx(s.CloseButton,{onClick:a,size:"sm"})})]})},Us=h.forwardRef(({value:e,onChange:t,zIndex:r=340},a)=>{const{t:l}=x.useTranslation(),o=h.useMemo(()=>e.map(w=>({id:Ue.v4(),value:w})),[e]),i=w=>{t([...e,w])},c=w=>{const m=[...e];m.splice(w,1),t(m)},d=w=>{t([...w])},u=w=>m=>{const k=[...e];k[w]=m,t(k)},[p,f]=h.useState(""),v=()=>{p&&(i(p),f(""))},_=w=>{const{source:m,target:k}=w.operation,z=gs.move(o,m,k);t(z.map(D=>D.value))};return n.jsxs(s.Stack,{ref:a,children:[n.jsx(Uu,{colors:e,applyPalette:d,zIndex:r}),n.jsx(Bn.DragDropProvider,{onDragEnd:_,children:o.map((w,m)=>n.jsx(Ku,{color:w,handleChange:u(m),handleRemove:()=>c(m),index:m},w.id))}),n.jsxs(s.Flex,{gap:"sm",justify:"flex-start",align:"center",direction:"row",wrap:"nowrap",children:[n.jsx("div",{style:{minWidth:"30px",maxWidth:"30px",flex:0}}),n.jsx("div",{style:{flex:1},children:n.jsx(s.ColorInput,{popoverProps:{withinPortal:!0,zIndex:r},placeholder:l("chart.color.click_to_add_a_color"),value:p,onChange:f,onBlur:v,size:"xs"})}),n.jsx("div",{style:{minWidth:"40px",maxWidth:"40px",flex:0}})]})]})}),Yu=({defaultValues:e,onSubmit:t,unset:r})=>{const{t:a}=x.useTranslation(),l=b.useForm({defaultValues:e}),{control:o,handleSubmit:i,reset:c}=l;h.useEffect(()=>{c(e)},[e]);const d=h.useCallback(()=>c(e),[c,e]);return n.jsxs(s.Box,{children:[n.jsx(s.Divider,{color:"rgb(206, 212, 218)",variant:"dotted",my:"1rem"}),n.jsxs(s.Box,{px:"1rem",children:[n.jsx(b.Controller,{control:o,name:"variable",render:({field:u})=>n.jsx(Rn,{label:a("rich_text.color_mapping.choose_value_var"),clearable:!1,preview:"aggregated",zIndex:340,...u})}),n.jsxs(s.Group,{grow:!0,justify:"space-between",children:[n.jsx(b.Controller,{name:"min_var",control:o,render:({field:u})=>n.jsx(Rn,{label:a("rich_text.color_mapping.min.var"),preview:"aggregated",sx:{flexGrow:1,maxWidth:"unset"},...u})}),n.jsx(b.Controller,{name:"min_val",control:o,render:({field:u})=>n.jsx(s.TextInput,{label:a("rich_text.color_mapping.min.val"),...u,sx:{maxWidth:"120px",flexGrow:0}})})]}),n.jsxs(s.Group,{grow:!0,justify:"space-between",children:[n.jsx(b.Controller,{name:"max_var",control:o,render:({field:u})=>n.jsx(Rn,{label:a("rich_text.color_mapping.max.var"),preview:"aggregated",sx:{flexGrow:1,maxWidth:"unset"},...u})}),n.jsx(b.Controller,{name:"max_val",control:o,render:({field:u})=>n.jsx(s.TextInput,{label:a("rich_text.color_mapping.max.val"),...u,sx:{maxWidth:"120px",flexGrow:0}})})]}),n.jsx(b.Controller,{control:o,name:"colors",render:({field:u})=>n.jsx(Us,{...u})})]}),n.jsx(s.Divider,{color:"rgb(206, 212, 218)",variant:"dotted",my:"1rem"}),n.jsxs(s.Group,{justify:"space-between",px:"1rem",pb:"0.75rem",children:[n.jsxs(s.Group,{justify:"flex-start",children:[n.jsx(s.Button,{color:"red",size:"xs",onClick:r,leftSection:n.jsx(S.IconTrash,{size:18}),children:a("common.actions.clear")}),n.jsx(s.Button,{color:"orange",size:"xs",onClick:d,leftSection:n.jsx(S.IconArrowBackUp,{size:18}),children:a("common.actions.revert")})]}),n.jsx(s.Button,{color:"green",size:"xs",onClick:i(t),leftSection:n.jsx(S.IconDeviceFloppy,{size:18}),children:a("common.actions.save_changes")})]})]})};function Xu(e){if(e.length===0)return"";const t=r=>`${r/(e.length-1)*100}%`;return e.map((r,a)=>`${r} ${t(a)}`).join(", ")}function Ks(e,...t){return`linear-gradient(${e}deg, ${Xu(t)})`}const Zu=()=>n.jsx("div",{style:{width:"20px",height:"13px",borderRadius:"2px",background:Ks(90,...Object.values(Ze.graphics.depth))}}),Ju=({disabled:e})=>n.jsx(s.Box,{sx:{width:"16px",height:"10px",borderRadius:"2px",background:Ks(90,...Object.values(Ze.graphics.depth)),opacity:e?"0.5":1,position:"relative","&:after":{position:"absolute",content:"''",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"15px",height:"15px",background:`
39
39
  linear-gradient(to top right,
40
40
  rgba(0,0,0,0) 0%,
41
41
  rgba(0,0,0,0) calc(50% - 1.4px),
@@ -45,28 +45,28 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
45
45
  rgba(0,0,0,0) calc(50% + 0.8px),
46
46
  rgba(255,255,255,1) calc(50% + 1.4px),
47
47
  rgba(0,0,0,0) calc(50% + 1.4px),
48
- rgba(0,0,0,0) 100%)`}}}),Xu=({editor:e})=>{const{t}=x.useTranslation(),[r,{set:a,setTrue:l,setFalse:o,toggle:i}]=O.useBoolean(),c=e.getAttributes(Bs),{empty:d,...u}=h.useMemo(()=>Vu(c),[c]),p=h.useCallback(v=>{e.chain().focus().setColorMapping(v).run(),o()},[e]),f=h.useCallback(()=>{e.chain().focus().unsetColorMapping().run()},[e]);return n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{size:500,opened:r,onClose:o,shadow:"md",withinPortal:!0,zIndex:330,closeOnClickOutside:!1,closeOnEscape:!1,title:t("rich_text.color_mapping.edit"),styles:{header:{paddingBottom:0,minHeight:"unset"},body:{padding:0}},children:n.jsx(Wu,{defaultValues:u,unset:f,onSubmit:p})}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(s.Tooltip,{label:t("rich_text.color_mapping.label"),children:n.jsx(s.ActionIcon,{variant:"default","data-rich-text-editor-control":"true",sx:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important",color:"#000"},onClick:l,children:n.jsx(Yu,{})})}),n.jsx(s.Tooltip,{label:t("rich_text.color_mapping.clear"),children:n.jsx(s.ActionIcon,{variant:"default","data-rich-text-editor-control":"true",sx:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"},disabled:d,onClick:f,children:n.jsx(Ku,{disabled:d})})})]})]})},nn="function color({ variables }, { filters, context }, utils) {",Us="}",Zu=[nn,' return "red";',Us].join(`
49
- `);function Ju(e){if(!e)return[];const t=e.split(`
50
- `),r=t.length+1;let a=1;const l=t[t.length-1];return l&&(a=l.length+1),[{range:[2,1,r,a],label:"body",allowMultiline:!0}]}const Hu=e=>e&&e.replace(nn,"").replace(/(.*)\}$/,"$1"),Ys=e=>!e||e.startsWith(nn)?e:[nn,e,Us].join(`
51
- `),tr="dyn_color_",Ru=new RegExp(`^(?!${tr})(.+)$`);function Ks(e){return e&&e.replace(Ru,`${tr}$1`)}const Xs=e=>{const r="abcdefghijklmnopqrstuvwxyz",l=`1234567890${r}${r.toUpperCase()}`.split(""),o=new Uint8Array(e);crypto.getRandomValues(o);const i=o.reduce((c,d)=>`${c}${l[d&61]}`,"");return`${tr}${i}`};function ep(e,t,r){const a={},l=i=>new Function(`return ${Ys(i)}`)()({variables:r},t,je);return e.querySelectorAll("dynamic-color").forEach(i=>{const c=i.getAttribute("data-value");c&&(a[`#${Ks(i.id)}`]={color:l(c)})}),a}const Ft="data-value",tp=Ft,Zs="dynamicColor",Js=En.Mark.create({name:Zs,addAttributes(){return{id:{default:Xs(6),parseHTML:e=>{const t=e.getAttribute("id");return Ks(t)}},[Ft]:{default:null,parseHTML:e=>e.getAttribute(Ft)}}},parseHTML(){return[{tag:"dynamic-color",getAttrs:e=>typeof e=="string"?(console.debug(e),!1):[e.getAttribute(Ft)]}]},renderHTML({HTMLAttributes:e}){return["dynamic-color",e,0]},addCommands(){return{setDynamicColor:e=>({commands:t})=>{const r=Hu(e);return t.setMark(this.name,{[Ft]:r})},unsetDynamicColor:()=>({commands:e})=>e.unsetMark(this.name)}}}),np=({value:e,onChange:t,onMount:r})=>{const a=h.useRef(null),l=h.useRef(null),o=c=>{if(!c){t("");return}t(c)};h.useEffect(()=>{var d;const c=(d=a.current)==null?void 0:d.getModel();c&&(c.getValue()||c.setValue(e))},[e]);const i=(c,d)=>{a.current=c,l.current=d,r==null||r(c,d)};return n.jsx(Te,{className:"function-editor",height:"100%",defaultLanguage:"javascript",defaultValue:e,onChange:o,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}},onMount:i})},xt=h.forwardRef(({value:e,onChange:t,label:r,defaultValue:a,restrictions:l=[]},o)=>{const{t:i}=x.useTranslation(),[c,d]=h.useState(e),u=()=>{t(c)},p=()=>{d(e)},f=()=>{d(a)};h.useEffect(()=>{d(e)},[e]);const v=h.useCallback((m,k)=>{if(l.length===0)return;const z=ld.constrainedEditor(k),D=m.getModel();if(z.initializeIn(m),z.addRestrictionsTo(D,l),!!D&&!D._hasHighlight){z.toggleDevMode(),D.toggleHighlightOfEditableAreas();const I=D.getCurrentEditableRanges(),L=D.getValueInEditableRanges();console.debug({model:D,currentRanges:I,currentValue:L})}},[l]),_=c!==e,w=typeof c=="string"&&c.length===0;return n.jsxs(s.Stack,{gap:4,sx:{height:"100%",".editableArea--multi-line":{backgroundColor:"rgba(255,183,78, 0.1)"},".editableArea--single-line":{backgroundColor:"rgba(255,183,78, 0.1)"}},children:[n.jsxs(s.Group,{mb:6,justify:"space-between",sx:{flexShrink:0,flexGrow:0},children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(Rs,{})}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:f,size:"xs",variant:"default",leftSection:n.jsx(S.IconPlayerSkipBack,{size:16}),children:i("common.actions.reset_to_default")}),n.jsx(s.Button,{onClick:p,color:"red",size:"xs",disabled:!_,leftSection:n.jsx(S.IconRecycle,{size:16}),children:i("common.actions.revert_changes")}),n.jsx(s.Button,{color:"green",size:"xs",onClick:u,disabled:!_,leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),children:i("common.actions.save_changes")})]})]}),n.jsx(s.Text,{size:"14px",children:r}),n.jsxs(s.Box,{sx:{position:"relative",flexGrow:1},children:[w&&n.jsx(s.Overlay,{center:!0,color:"#fff",backgroundOpacity:.5,children:n.jsx(s.Button,{color:"blue",radius:"xl",onClick:f,children:i("common.actions.init_with_default")})}),n.jsx(np,{value:c,onChange:d,onMount:v})]})]})}),nr=h.forwardRef(({title:e,value:t,onChange:r,label:a,description:l=null,triggerLabel:o="Edit",triggerButtonProps:i={},renderTriggerButton:c,defaultValue:d,zIndex:u=320,restrictions:p},f)=>{const[v,{open:_,close:w}]=te.useDisclosure(!1);return n.jsxs(n.Fragment,{children:[n.jsxs(s.Modal,{opened:v,onClose:w,title:e,withinPortal:!0,zIndex:u,size:"900px",children:[l,n.jsx(s.Box,{h:600,children:n.jsx(xt,{value:t,onChange:r,defaultValue:d,label:a,restrictions:p})})]}),c==null?void 0:c({onClick:_}),!c&&n.jsx(s.Button,{onClick:_,...i,children:o})]})}),rp=({onClick:e})=>{const{t}=x.useTranslation();return n.jsx(s.Tooltip,{label:t("rich_text.dynamic_color.label"),children:n.jsx(s.ActionIcon,{variant:"default","data-rich-text-editor-control":"true",sx:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important",color:"rgb(190, 75, 219)"},onClick:e,children:n.jsx(S.IconMathFunction,{stroke:2,size:16})})})},ap=({editor:e})=>{const{t}=x.useTranslation(),r=e.getAttributes(Zs)[tp]??"",a=Ys(r),l=Ju(r);return n.jsxs(n.Fragment,{children:[n.jsx(nr,{title:t("rich_text.dynamic_color.edit"),label:"",triggerLabel:"",value:a,onChange:o=>{o?e.chain().focus().setDynamicColor(o).run():e.chain().focus().unsetDynamicColor().run()},defaultValue:Zu,renderTriggerButton:rp,restrictions:l,zIndex:340}),n.jsx(s.Tooltip,{label:t("rich_text.dynamic_color.clear"),children:n.jsx(s.ActionIcon,{variant:"default","data-rich-text-editor-control":"true",sx:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important",color:"#000"},disabled:!r,onClick:()=>e.chain().focus().unsetDynamicColor().run(),children:n.jsx(S.IconMathFunctionOff,{stroke:1.5,size:16})})})]})},Hs=En.Extension.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:e=>e.style.fontSize.replace(/['"]+/g,""),renderHTML:e=>e.fontSize?{style:`font-size: ${e.fontSize}; line-height: 1.2; overflow: auto`}:{}}}}]},addCommands(){return{setFontSize:e=>({chain:t})=>t().setMark("textStyle",{fontSize:e}).run(),unsetFontSize:()=>({chain:e})=>e().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),sp=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(e=>`${e}px`),lp=[{label:"auto",value:""}].concat(sp.map(e=>({label:e,value:e}))),op={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},ip=({editor:e})=>{const t=e.getAttributes("textStyle").fontSize;return n.jsx(G.RichTextEditor.ControlsGroup,{children:n.jsx(s.NativeSelect,{size:"xs",leftSection:n.jsx(S.IconTextSize,{stroke:1.5,size:16}),data:lp,styles:op,value:t||"",onChange:r=>{const a=r.currentTarget.value;a?e.chain().focus().setFontSize(a).run():e.chain().focus().unsetFontSize().run()}})})},Dt=h.forwardRef(({value:e,styles:t={},sx:r={},dashboardStateValues:a=sr(),variableAggValueMap:l={}},o)=>{const i=As(),c=h.useMemo(()=>{const _=[us,cs,G.Link,ns,ts,Ra,rs.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),ls,ss,as,os.configure({types:["heading","paragraph"]}),es.configure({placeholder:"This is placeholder"}),is,Ha.Color,Hs,Js];return i&&_.push(Ls),_},[i]),d=ds.useEditor({extensions:c,content:e,editable:!1});h.useEffect(()=>{d==null||d.commands.setContent(e)},[e,d]);const u=h.useMemo(()=>new DOMParser().parseFromString(e,"text/html"),[e]),p=h.useMemo(()=>ep(u,a,l),[u,a,l]),f=h.useMemo(()=>Pu(u,l),[u,l]),v=h.useMemo(()=>y.defaultsDeep({},{content:{...Jn,...p,...f}},t),[t,p,f]);return n.jsx(G.RichTextEditor,{editor:d,styles:v,sx:r,children:n.jsx(G.RichTextEditor.Content,{ref:o})})});function Rs(){const{t:e}=x.useTranslation(),[t,{open:r,close:a}]=te.useDisclosure(!1);return n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:t,onClose:a,title:e("function_utils.modal_title"),zIndex:330,withinPortal:!0,children:n.jsx(Dt,{value:wu(e),styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),n.jsx(s.Button,{variant:"light",color:"violet",size:"xs",onClick:r,leftSection:n.jsx(S.IconInfoCircle,{size:16}),children:e("function_utils.trigger_text")})]})}const rr=({option:e,checked:t,...r})=>{const{label:a,description:l}=e;return n.jsx("div",{...r,style:{flexGrow:1},children:n.jsxs(s.Group,{justify:"space-between",wrap:"nowrap",children:[n.jsxs(s.Group,{justify:"flex-start",gap:"0.5em",children:[t&&n.jsx(S.IconCheck,{size:16,color:"green"}),n.jsx(s.Text,{size:"sm",sx:{flexGrow:1},children:a})]}),n.jsx(s.Text,{size:"xs",c:"dimmed",children:l})]})})},ar=({value:e,onChange:t,height:r="200px",defaultLanguage:a="sql",theme:l="vs-dark"})=>{const o=c=>{t==null||t(c??"")},i=!t;return n.jsx(Te,{className:"minimal-monaco-editor",height:r,defaultLanguage:a,value:e,onChange:i?void 0:o,theme:l,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:i||!t,"semanticHighlighting.enabled":!0}})},cp=({color:e})=>h.forwardRef(({onClick:t},r)=>n.jsx(G.RichTextEditor.Control,{ref:r,onClick:t,children:n.jsx(s.ColorSwatch,{color:e,size:14})})),dp=({editor:e})=>{const t=s.useMantineTheme(),r=e.getAttributes("textStyle").color||t.black,a=h.useMemo(()=>nl(r),[r]),l=h.useCallback(i=>{e.chain().setColor(i).run()},[e]),o=h.useCallback(()=>{e.chain().focus().unsetColor().run()},[e]);return n.jsx(al,{value:a,onChange:l,clear:o,Trigger:cp({color:a})})},up={"dynamic-color":{position:"relative"},"dynamic-color:after":{content:'""',position:"absolute",bottom:"-2px",left:0,width:"100%",height:"1px",border:"double 1px purple"},"color-mapping":{position:"relative"},"color-mapping:after":{content:'""',position:"absolute",bottom:"-2px",left:0,width:"100%",height:"4px",opacity:.8,background:"linear-gradient(90deg, rgb(255, 225, 225) 0%, rgb(253, 188, 188) 40%, rgb(243, 148, 148) 60%, rgb(250, 66, 66) 80%, rgb(226, 18, 18) 100%)"}};function pp(){const{editor:e}=G.useRichTextEditorContext();return n.jsx(G.RichTextEditor.Control,{onClick:()=>e==null?void 0:e.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:n.jsx(S.IconBorderAll,{stroke:1.5,size:16})})}const pt=h.forwardRef(({value:e,onChange:t,styles:r={},label:a,autoSubmit:l,onSubmit:o},i)=>{const{t:c}=x.useTranslation(),d=Ps(),u=h.useMemo(()=>{const I=[us,cs,G.Link,ns,ts,Ra,rs.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),ls,ss,as,os.configure({types:["heading","paragraph"]}),es.configure({placeholder:"This is placeholder"}),is,Ha.Color,Hs,Js];return d&&I.push(Ls),I},[d]),[p,{setTrue:f,setFalse:v}]=O.useBoolean(!1),[_,w]=h.useState(e),m=ds.useEditor({extensions:u,content:e,onUpdate:({editor:I})=>{const L=I.getHTML();w(L)},onCreate:({editor:I})=>{I.view.dom.setAttribute("spellcheck","false"),I.view.dom.setAttribute("autocomplete","off"),I.view.dom.setAttribute("autocapitalize","off")},onFocus:f,onBlur:v});h.useEffect(()=>{w(e),m==null||m.commands.setContent(e)},[e]);const k=()=>{t(_),o==null||o()},z=e!==_;h.useEffect(()=>{!l||!p||k()},[l,z,p]);const D=h.useMemo(()=>y.defaultsDeep({},{content:{...Jn,...up}},r),[r]);return m?n.jsxs(s.Stack,{gap:4,sx:{flexGrow:1,position:"relative"},children:[n.jsxs(s.Group,{align:"center",children:[n.jsx(s.Text,{size:"14px",fw:500,children:a}),!l&&n.jsx(s.Button,{variant:"filled",color:"blue",size:"compact-xs",disabled:!z,onClick:k,leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),children:c("common.actions.save_changes")})]}),n.jsxs(G.RichTextEditor,{editor:m,styles:D,children:[n.jsxs(G.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[n.jsx(dp,{editor:m}),d&&n.jsx(Xu,{editor:m}),n.jsx(G.RichTextEditor.ControlsGroup,{children:n.jsx(ap,{editor:m})}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.Bold,{}),n.jsx(G.RichTextEditor.Italic,{}),n.jsx(G.RichTextEditor.Underline,{}),n.jsx(G.RichTextEditor.ClearFormatting,{}),n.jsx(G.RichTextEditor.Highlight,{}),n.jsx(G.RichTextEditor.Code,{})]}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.H1,{}),n.jsx(G.RichTextEditor.H2,{}),n.jsx(G.RichTextEditor.H3,{}),n.jsx(G.RichTextEditor.H4,{})]}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.Blockquote,{}),n.jsx(G.RichTextEditor.Hr,{}),n.jsx(G.RichTextEditor.BulletList,{}),n.jsx(G.RichTextEditor.OrderedList,{}),n.jsx(G.RichTextEditor.Subscript,{}),n.jsx(G.RichTextEditor.Superscript,{})]}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.Link,{}),n.jsx(G.RichTextEditor.Unlink,{})]}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.AlignLeft,{}),n.jsx(G.RichTextEditor.AlignCenter,{}),n.jsx(G.RichTextEditor.AlignJustify,{}),n.jsx(G.RichTextEditor.AlignRight,{})]}),n.jsx(G.RichTextEditor.ControlsGroup,{children:n.jsx(pp,{})}),n.jsx(ip,{editor:m})]}),n.jsx(G.RichTextEditor.Content,{})]})]}):null}),el={hex:/^#?([0-9A-F]{3}){1,2}$/i,fullHex:/^#?([0-9A-F]{6})$/i,hexa:/^#?([0-9A-F]{4}){1,2}$/i,rgb:/^rgb\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/i,rgba:/^rgba\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/i,hsl:/hsl\(\s*(\d+)\s*,\s*(\d+(?:\.\d+)?%)\s*,\s*(\d+(?:\.\d+)?%)\)/i,hsla:/^hsla\((\d+),\s*([\d.]+)%,\s*([\d.]+)%,\s*(\d*(?:\.\d+)?)\)$/i},hp=y.pick(el,"fullHex","rgb","rgba","hsl","hsla"),gp=y.pick(el,"fullHex","rgb","rgba","hsl","hsla");function fp(e){return Object.values(hp).some(t=>t.test(e))}function tl(e){return Object.values(gp).some(t=>t.test(e))}function nl(e){return tl(e)?e:qe.valid(e)?qe(e).css():e}const rl=({value:e})=>tl(e)?n.jsx(s.ColorSwatch,{ml:8,size:16,color:e}):n.jsx(s.ColorSwatch,{ml:8,size:16,color:""}),bp=({value:e,onChange:t,shouldPatch:r})=>{const{t:a}=x.useTranslation(),[l,o]=h.useState(e);h.useEffect(()=>{r&&o(e)},[e,r]);const i=h.useCallback(c=>{const d=c.currentTarget.value;o(d),fp(d)&&t(d)},[t]);return n.jsx(s.TextInput,{value:l,onChange:i,leftSection:n.jsx(rl,{value:l}),size:"xs",placeholder:a("chart.color.not_set"),styles:{root:{flexGrow:1},input:{fontFamily:"monospace",letterSpacing:2,textAlign:"center",textTransform:"uppercase"}}})},yp=["gray","red","grape","blue","cyan","green","yellow"],al=({Trigger:e,value:t,onChange:r,clear:a})=>{const{t:l}=x.useTranslation(),o=s.useMantineTheme(),[i,{set:c,setFalse:d,toggle:u}]=O.useBoolean(),[p,f]=h.useState(!1),v=h.useMemo(()=>{const z=[];return yp.forEach(D=>{const I=o.colors[D];I&&I.forEach(L=>{z.push(L)})}),z},[o.colors]),_=(z,D=!0)=>{r(z),D&&d()},w=h.useCallback(z=>{_(z,!1),f(!1)},[]),m=h.useCallback(z=>{_(z,!1),f(!0)},[]),k=()=>{a(),d()};return n.jsxs(s.Popover,{opened:i,onChange:c,shadow:"md",withinPortal:!0,zIndex:340,withArrow:!0,children:[n.jsx(s.Popover.Target,{children:n.jsx(e,{onClick:u})}),n.jsx(s.Popover.Dropdown,{children:n.jsxs(s.Stack,{gap:"xs",children:[n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(bp,{value:t,onChange:w,shouldPatch:p}),n.jsx(s.ActionIcon,{variant:"default",onClick:k,title:l("common.actions.clear"),children:n.jsx(S.IconCircleOff,{stroke:1.5,size:"1rem"})}),n.jsx(s.ActionIcon,{variant:"default",onClick:d,title:l("common.actions.close"),children:n.jsx(S.IconX,{stroke:1.5,size:"1rem"})})]}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(s.ColorPicker,{format:"hex",swatches:v,value:t,onChange:m,size:"sm",withPicker:!1,styles:{swatches:{marginTop:"0 !important"}}}),n.jsx(s.ColorPicker,{format:"hex",fullWidth:!0,value:t,onChange:m})]})]})})]})},vp=({color:e,label:t})=>h.forwardRef(({onClick:r},a)=>n.jsx(s.Button,{ref:a,size:"sm",variant:"default",leftSection:n.jsx(rl,{value:e}),onClick:r,children:t})),ye=h.forwardRef(({value:e="",onChange:t,label:r},a)=>{const l=h.useCallback(()=>{t("")},[t]),o=h.useMemo(()=>nl(e),[e]);return n.jsx(al,{value:o,onChange:t,clear:l,Trigger:vp({color:o,label:r})})}),le={mantissa:0,output:"number",trimMantissa:!1,average:!1,absolute:!1};function Y(e,{absolute:t,...r}){if(e===null)return String(e);try{let a=Ye(e).value();if(a===void 0||Number.isNaN(a))throw new Error(`[formatNumber]Not a number: ${e}`);return t&&(a=Math.abs(a)),Ye(a).format(r)}catch(a){return console.debug(a),String(e)}}function _p(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`Array(${e.length})`:e.toString()}function Re({data_field:e,aggregation:t},r){return Gn(r,e,t)}function $e({formatter:e,aggregation:t},r){if(typeof r!="string"&&typeof r!="number")return _p(r);if(t.type==="custom")return r;try{return Y(r,e)}catch(a){return console.error(a),r}}function It(e,t){return e.replaceAll(/(\$\{([^{\}]+(?=}))\})/g,(...a)=>{const l=a[2],o=t.variableStyleMap[l];if(!o)return`{{${l}}}`;const{variable:i,...c}=o,d=Object.entries(c).map(([v,_])=>`${v}:${_}`).join(";"),u=i.color;if(u.type!=="continuous")return`<span style="${d}">{{${l}}}</span>`;const p=Xs(6),f=`try {
48
+ rgba(0,0,0,0) 100%)`}}}),Hu=({editor:e})=>{const{t}=x.useTranslation(),[r,{set:a,setTrue:l,setFalse:o,toggle:i}]=O.useBoolean(),c=e.getAttributes(qs),{empty:d,...u}=h.useMemo(()=>Bu(c),[c]),p=h.useCallback(v=>{e.chain().focus().setColorMapping(v).run(),o()},[e]),f=h.useCallback(()=>{e.chain().focus().unsetColorMapping().run()},[e]);return n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{size:500,opened:r,onClose:o,shadow:"md",withinPortal:!0,zIndex:330,closeOnClickOutside:!1,closeOnEscape:!1,title:t("rich_text.color_mapping.edit"),styles:{header:{paddingBottom:0,minHeight:"unset"},body:{padding:0}},children:n.jsx(Yu,{defaultValues:u,unset:f,onSubmit:p})}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(s.Tooltip,{label:t("rich_text.color_mapping.label"),children:n.jsx(s.ActionIcon,{variant:"default","data-rich-text-editor-control":"true",sx:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important",color:"#000"},onClick:l,children:n.jsx(Zu,{})})}),n.jsx(s.Tooltip,{label:t("rich_text.color_mapping.clear"),children:n.jsx(s.ActionIcon,{variant:"default","data-rich-text-editor-control":"true",sx:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"},disabled:d,onClick:f,children:n.jsx(Ju,{disabled:d})})})]})]})},nn="function color({ variables }, { filters, context }, utils) {",Ys="}",Ru=[nn,' return "red";',Ys].join(`
49
+ `);function ep(e){if(!e)return[];const t=e.split(`
50
+ `),r=t.length+1;let a=1;const l=t[t.length-1];return l&&(a=l.length+1),[{range:[2,1,r,a],label:"body",allowMultiline:!0}]}const tp=e=>e&&e.replace(nn,"").replace(/(.*)\}$/,"$1"),Xs=e=>!e||e.startsWith(nn)?e:[nn,e,Ys].join(`
51
+ `),tr="dyn_color_",np=new RegExp(`^(?!${tr})(.+)$`);function Zs(e){return e&&e.replace(np,`${tr}$1`)}const Js=e=>{const r="abcdefghijklmnopqrstuvwxyz",l=`1234567890${r}${r.toUpperCase()}`.split(""),o=new Uint8Array(e);crypto.getRandomValues(o);const i=o.reduce((c,d)=>`${c}${l[d&61]}`,"");return`${tr}${i}`};function rp(e,t,r){const a={},l=i=>new Function(`return ${Xs(i)}`)()({variables:r},t,Ge);return e.querySelectorAll("dynamic-color").forEach(i=>{const c=i.getAttribute("data-value");c&&(a[`#${Zs(i.id)}`]={color:l(c)})}),a}const Ft="data-value",ap=Ft,Hs="dynamicColor",Rs=En.Mark.create({name:Hs,addAttributes(){return{id:{default:Js(6),parseHTML:e=>{const t=e.getAttribute("id");return Zs(t)}},[Ft]:{default:null,parseHTML:e=>e.getAttribute(Ft)}}},parseHTML(){return[{tag:"dynamic-color",getAttrs:e=>typeof e=="string"?(console.debug(e),!1):[e.getAttribute(Ft)]}]},renderHTML({HTMLAttributes:e}){return["dynamic-color",e,0]},addCommands(){return{setDynamicColor:e=>({commands:t})=>{const r=tp(e);return t.setMark(this.name,{[Ft]:r})},unsetDynamicColor:()=>({commands:e})=>e.unsetMark(this.name)}}}),sp=({value:e,onChange:t,onMount:r})=>{const a=h.useRef(null),l=h.useRef(null),o=c=>{if(!c){t("");return}t(c)};h.useEffect(()=>{var d;const c=(d=a.current)==null?void 0:d.getModel();c&&(c.getValue()||c.setValue(e))},[e]);const i=(c,d)=>{a.current=c,l.current=d,r==null||r(c,d)};return n.jsx(Ce,{className:"function-editor",height:"100%",defaultLanguage:"javascript",defaultValue:e,onChange:o,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}},onMount:i})},xt=h.forwardRef(({value:e,onChange:t,label:r,defaultValue:a,restrictions:l=[]},o)=>{const{t:i}=x.useTranslation(),[c,d]=h.useState(e),u=()=>{t(c)},p=()=>{d(e)},f=()=>{d(a)};h.useEffect(()=>{d(e)},[e]);const v=h.useCallback((m,k)=>{if(l.length===0)return;const z=cd.constrainedEditor(k),D=m.getModel();if(z.initializeIn(m),z.addRestrictionsTo(D,l),!!D&&!D._hasHighlight){z.toggleDevMode(),D.toggleHighlightOfEditableAreas();const I=D.getCurrentEditableRanges(),L=D.getValueInEditableRanges();console.debug({model:D,currentRanges:I,currentValue:L})}},[l]),_=c!==e,w=typeof c=="string"&&c.length===0;return n.jsxs(s.Stack,{gap:4,sx:{height:"100%",".editableArea--multi-line":{backgroundColor:"rgba(255,183,78, 0.1)"},".editableArea--single-line":{backgroundColor:"rgba(255,183,78, 0.1)"}},children:[n.jsxs(s.Group,{mb:6,justify:"space-between",sx:{flexShrink:0,flexGrow:0},children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(tl,{})}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:f,size:"xs",variant:"default",leftSection:n.jsx(S.IconPlayerSkipBack,{size:16}),children:i("common.actions.reset_to_default")}),n.jsx(s.Button,{onClick:p,color:"red",size:"xs",disabled:!_,leftSection:n.jsx(S.IconRecycle,{size:16}),children:i("common.actions.revert_changes")}),n.jsx(s.Button,{color:"green",size:"xs",onClick:u,disabled:!_,leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),children:i("common.actions.save_changes")})]})]}),n.jsx(s.Text,{size:"14px",children:r}),n.jsxs(s.Box,{sx:{position:"relative",flexGrow:1},children:[w&&n.jsx(s.Overlay,{center:!0,color:"#fff",backgroundOpacity:.5,children:n.jsx(s.Button,{color:"blue",radius:"xl",onClick:f,children:i("common.actions.init_with_default")})}),n.jsx(sp,{value:c,onChange:d,onMount:v})]})]})}),nr=h.forwardRef(({title:e,value:t,onChange:r,label:a,description:l=null,triggerLabel:o="Edit",triggerButtonProps:i={},renderTriggerButton:c,defaultValue:d,zIndex:u=320,restrictions:p},f)=>{const[v,{open:_,close:w}]=ne.useDisclosure(!1);return n.jsxs(n.Fragment,{children:[n.jsxs(s.Modal,{opened:v,onClose:w,title:e,withinPortal:!0,zIndex:u,size:"900px",children:[l,n.jsx(s.Box,{h:600,children:n.jsx(xt,{value:t,onChange:r,defaultValue:d,label:a,restrictions:p})})]}),c==null?void 0:c({onClick:_}),!c&&n.jsx(s.Button,{onClick:_,...i,children:o})]})}),lp=({onClick:e})=>{const{t}=x.useTranslation();return n.jsx(s.Tooltip,{label:t("rich_text.dynamic_color.label"),children:n.jsx(s.ActionIcon,{variant:"default","data-rich-text-editor-control":"true",sx:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important",color:"rgb(190, 75, 219)"},onClick:e,children:n.jsx(S.IconMathFunction,{stroke:2,size:16})})})},op=({editor:e})=>{const{t}=x.useTranslation(),r=e.getAttributes(Hs)[ap]??"",a=Xs(r),l=ep(r);return n.jsxs(n.Fragment,{children:[n.jsx(nr,{title:t("rich_text.dynamic_color.edit"),label:"",triggerLabel:"",value:a,onChange:o=>{o?e.chain().focus().setDynamicColor(o).run():e.chain().focus().unsetDynamicColor().run()},defaultValue:Ru,renderTriggerButton:lp,restrictions:l,zIndex:340}),n.jsx(s.Tooltip,{label:t("rich_text.dynamic_color.clear"),children:n.jsx(s.ActionIcon,{variant:"default","data-rich-text-editor-control":"true",sx:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important",color:"#000"},disabled:!r,onClick:()=>e.chain().focus().unsetDynamicColor().run(),children:n.jsx(S.IconMathFunctionOff,{stroke:1.5,size:16})})})]})},el=En.Extension.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:e=>e.style.fontSize.replace(/['"]+/g,""),renderHTML:e=>e.fontSize?{style:`font-size: ${e.fontSize}; line-height: 1.2; overflow: auto`}:{}}}}]},addCommands(){return{setFontSize:e=>({chain:t})=>t().setMark("textStyle",{fontSize:e}).run(),unsetFontSize:()=>({chain:e})=>e().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),ip=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(e=>`${e}px`),cp=[{label:"auto",value:""}].concat(ip.map(e=>({label:e,value:e}))),dp={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},up=({editor:e})=>{const t=e.getAttributes("textStyle").fontSize;return n.jsx(G.RichTextEditor.ControlsGroup,{children:n.jsx(s.NativeSelect,{size:"xs",leftSection:n.jsx(S.IconTextSize,{stroke:1.5,size:16}),data:cp,styles:dp,value:t||"",onChange:r=>{const a=r.currentTarget.value;a?e.chain().focus().setFontSize(a).run():e.chain().focus().unsetFontSize().run()}})})},Dt=h.forwardRef(({value:e,styles:t={},sx:r={},dashboardStateValues:a=sr(),variableAggValueMap:l={}},o)=>{const i=As(),c=h.useMemo(()=>{const _=[ps,ds,G.Link,rs,ns,es,as.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),os,ls,ss,is.configure({types:["heading","paragraph"]}),ts.configure({placeholder:"This is placeholder"}),cs,Ra.Color,el,Rs];return i&&_.push(Os),_},[i]),d=us.useEditor({extensions:c,content:e,editable:!1});h.useEffect(()=>{d==null||d.commands.setContent(e)},[e,d]);const u=h.useMemo(()=>new DOMParser().parseFromString(e,"text/html"),[e]),p=h.useMemo(()=>rp(u,a,l),[u,a,l]),f=h.useMemo(()=>Eu(u,l),[u,l]),v=h.useMemo(()=>y.defaultsDeep({},{content:{...Jn,...p,...f}},t),[t,p,f]);return n.jsx(G.RichTextEditor,{editor:d,styles:v,sx:r,children:n.jsx(G.RichTextEditor.Content,{ref:o})})});function tl(){const{t:e}=x.useTranslation(),[t,{open:r,close:a}]=ne.useDisclosure(!1);return n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:t,onClose:a,title:e("function_utils.modal_title"),zIndex:330,withinPortal:!0,children:n.jsx(Dt,{value:Su(e),styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),n.jsx(s.Button,{variant:"light",color:"violet",size:"xs",onClick:r,leftSection:n.jsx(S.IconInfoCircle,{size:16}),children:e("function_utils.trigger_text")})]})}const rr=({option:e,checked:t,...r})=>{const{label:a,description:l}=e;return n.jsx("div",{...r,style:{flexGrow:1},children:n.jsxs(s.Group,{justify:"space-between",wrap:"nowrap",children:[n.jsxs(s.Group,{justify:"flex-start",gap:"0.5em",children:[t&&n.jsx(S.IconCheck,{size:16,color:"green"}),n.jsx(s.Text,{size:"sm",sx:{flexGrow:1},children:a})]}),n.jsx(s.Text,{size:"xs",c:"dimmed",children:l})]})})},ar=({value:e,onChange:t,height:r="200px",defaultLanguage:a="sql",theme:l="vs-dark"})=>{const o=c=>{t==null||t(c??"")},i=!t;return n.jsx(Ce,{className:"minimal-monaco-editor",height:r,defaultLanguage:a,value:e,onChange:i?void 0:o,theme:l,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:i||!t,"semanticHighlighting.enabled":!0}})},pp=({color:e})=>h.forwardRef(({onClick:t},r)=>n.jsx(G.RichTextEditor.Control,{ref:r,onClick:t,children:n.jsx(s.ColorSwatch,{color:e,size:14})})),hp=({editor:e})=>{const t=s.useMantineTheme(),r=e.getAttributes("textStyle").color||t.black,a=h.useMemo(()=>al(r),[r]),l=h.useCallback(i=>{e.chain().setColor(i).run()},[e]),o=h.useCallback(()=>{e.chain().focus().unsetColor().run()},[e]);return n.jsx(ll,{value:a,onChange:l,clear:o,Trigger:pp({color:a})})},gp={"dynamic-color":{position:"relative"},"dynamic-color:after":{content:'""',position:"absolute",bottom:"-2px",left:0,width:"100%",height:"1px",border:"double 1px purple"},"color-mapping":{position:"relative"},"color-mapping:after":{content:'""',position:"absolute",bottom:"-2px",left:0,width:"100%",height:"4px",opacity:.8,background:"linear-gradient(90deg, rgb(255, 225, 225) 0%, rgb(253, 188, 188) 40%, rgb(243, 148, 148) 60%, rgb(250, 66, 66) 80%, rgb(226, 18, 18) 100%)"}};function fp(){const{editor:e}=G.useRichTextEditorContext();return n.jsx(G.RichTextEditor.Control,{onClick:()=>e==null?void 0:e.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:n.jsx(S.IconBorderAll,{stroke:1.5,size:16})})}const pt=h.forwardRef(({value:e,onChange:t,styles:r={},label:a,autoSubmit:l,onSubmit:o},i)=>{const{t:c}=x.useTranslation(),d=$s(),u=h.useMemo(()=>{const I=[ps,ds,G.Link,rs,ns,es,as.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),os,ls,ss,is.configure({types:["heading","paragraph"]}),ts.configure({placeholder:"This is placeholder"}),cs,Ra.Color,el,Rs];return d&&I.push(Os),I},[d]),[p,{setTrue:f,setFalse:v}]=O.useBoolean(!1),[_,w]=h.useState(e),m=us.useEditor({extensions:u,content:e,onUpdate:({editor:I})=>{const L=I.getHTML();w(L)},onCreate:({editor:I})=>{I.view.dom.setAttribute("spellcheck","false"),I.view.dom.setAttribute("autocomplete","off"),I.view.dom.setAttribute("autocapitalize","off")},onFocus:f,onBlur:v});h.useEffect(()=>{w(e),m==null||m.commands.setContent(e)},[e]);const k=()=>{t(_),o==null||o()},z=e!==_;h.useEffect(()=>{!l||!p||k()},[l,z,p]);const D=h.useMemo(()=>y.defaultsDeep({},{content:{...Jn,...gp}},r),[r]);return m?n.jsxs(s.Stack,{gap:4,sx:{flexGrow:1,position:"relative"},children:[n.jsxs(s.Group,{align:"center",children:[n.jsx(s.Text,{size:"14px",fw:500,children:a}),!l&&n.jsx(s.Button,{variant:"filled",color:"blue",size:"compact-xs",disabled:!z,onClick:k,leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),children:c("common.actions.save_changes")})]}),n.jsxs(G.RichTextEditor,{editor:m,styles:D,children:[n.jsxs(G.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[n.jsx(hp,{editor:m}),d&&n.jsx(Hu,{editor:m}),n.jsx(G.RichTextEditor.ControlsGroup,{children:n.jsx(op,{editor:m})}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.Bold,{}),n.jsx(G.RichTextEditor.Italic,{}),n.jsx(G.RichTextEditor.Underline,{}),n.jsx(G.RichTextEditor.ClearFormatting,{}),n.jsx(G.RichTextEditor.Highlight,{}),n.jsx(G.RichTextEditor.Code,{})]}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.H1,{}),n.jsx(G.RichTextEditor.H2,{}),n.jsx(G.RichTextEditor.H3,{}),n.jsx(G.RichTextEditor.H4,{})]}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.Blockquote,{}),n.jsx(G.RichTextEditor.Hr,{}),n.jsx(G.RichTextEditor.BulletList,{}),n.jsx(G.RichTextEditor.OrderedList,{}),n.jsx(G.RichTextEditor.Subscript,{}),n.jsx(G.RichTextEditor.Superscript,{})]}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.Link,{}),n.jsx(G.RichTextEditor.Unlink,{})]}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.AlignLeft,{}),n.jsx(G.RichTextEditor.AlignCenter,{}),n.jsx(G.RichTextEditor.AlignJustify,{}),n.jsx(G.RichTextEditor.AlignRight,{})]}),n.jsx(G.RichTextEditor.ControlsGroup,{children:n.jsx(fp,{})}),n.jsx(up,{editor:m})]}),n.jsx(G.RichTextEditor.Content,{})]})]}):null}),nl={hex:/^#?([0-9A-F]{3}){1,2}$/i,fullHex:/^#?([0-9A-F]{6})$/i,hexa:/^#?([0-9A-F]{4}){1,2}$/i,rgb:/^rgb\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/i,rgba:/^rgba\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/i,hsl:/hsl\(\s*(\d+)\s*,\s*(\d+(?:\.\d+)?%)\s*,\s*(\d+(?:\.\d+)?%)\)/i,hsla:/^hsla\((\d+),\s*([\d.]+)%,\s*([\d.]+)%,\s*(\d*(?:\.\d+)?)\)$/i},bp=y.pick(nl,"fullHex","rgb","rgba","hsl","hsla"),yp=y.pick(nl,"fullHex","rgb","rgba","hsl","hsla");function vp(e){return Object.values(bp).some(t=>t.test(e))}function rl(e){return Object.values(yp).some(t=>t.test(e))}function al(e){return rl(e)?e:Be.valid(e)?Be(e).css():e}const sl=({value:e})=>rl(e)?n.jsx(s.ColorSwatch,{ml:8,size:16,color:e}):n.jsx(s.ColorSwatch,{ml:8,size:16,color:""}),_p=({value:e,onChange:t,shouldPatch:r})=>{const{t:a}=x.useTranslation(),[l,o]=h.useState(e);h.useEffect(()=>{r&&o(e)},[e,r]);const i=h.useCallback(c=>{const d=c.currentTarget.value;o(d),vp(d)&&t(d)},[t]);return n.jsx(s.TextInput,{value:l,onChange:i,leftSection:n.jsx(sl,{value:l}),size:"xs",placeholder:a("chart.color.not_set"),styles:{root:{flexGrow:1},input:{fontFamily:"monospace",letterSpacing:2,textAlign:"center",textTransform:"uppercase"}}})},xp=["gray","red","grape","blue","cyan","green","yellow"],ll=({Trigger:e,value:t,onChange:r,clear:a})=>{const{t:l}=x.useTranslation(),o=s.useMantineTheme(),[i,{set:c,setFalse:d,toggle:u}]=O.useBoolean(),[p,f]=h.useState(!1),v=h.useMemo(()=>{const z=[];return xp.forEach(D=>{const I=o.colors[D];I&&I.forEach(L=>{z.push(L)})}),z},[o.colors]),_=(z,D=!0)=>{r(z),D&&d()},w=h.useCallback(z=>{_(z,!1),f(!1)},[]),m=h.useCallback(z=>{_(z,!1),f(!0)},[]),k=()=>{a(),d()};return n.jsxs(s.Popover,{opened:i,onChange:c,shadow:"md",withinPortal:!0,zIndex:340,withArrow:!0,children:[n.jsx(s.Popover.Target,{children:n.jsx(e,{onClick:u})}),n.jsx(s.Popover.Dropdown,{children:n.jsxs(s.Stack,{gap:"xs",children:[n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(_p,{value:t,onChange:w,shouldPatch:p}),n.jsx(s.ActionIcon,{variant:"default",onClick:k,title:l("common.actions.clear"),children:n.jsx(S.IconCircleOff,{stroke:1.5,size:"1rem"})}),n.jsx(s.ActionIcon,{variant:"default",onClick:d,title:l("common.actions.close"),children:n.jsx(S.IconX,{stroke:1.5,size:"1rem"})})]}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(s.ColorPicker,{format:"hex",swatches:v,value:t,onChange:m,size:"sm",withPicker:!1,styles:{swatches:{marginTop:"0 !important"}}}),n.jsx(s.ColorPicker,{format:"hex",fullWidth:!0,value:t,onChange:m})]})]})})]})},wp=({color:e,label:t})=>h.forwardRef(({onClick:r},a)=>n.jsx(s.Button,{ref:a,size:"sm",variant:"default",leftSection:n.jsx(sl,{value:e}),onClick:r,children:t})),be=h.forwardRef(({value:e="",onChange:t,label:r},a)=>{const l=h.useCallback(()=>{t("")},[t]),o=h.useMemo(()=>al(e),[e]);return n.jsx(ll,{value:o,onChange:t,clear:l,Trigger:wp({color:o,label:r})})}),ce={mantissa:0,output:"number",trimMantissa:!1,average:!1,absolute:!1};function Y(e,{absolute:t,...r}){if(e===null)return String(e);try{let a=We(e).value();if(a===void 0||Number.isNaN(a))throw new Error(`[formatNumber]Not a number: ${e}`);return t&&(a=Math.abs(a)),We(a).format(r)}catch(a){return console.debug(a),String(e)}}function mp(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`Array(${e.length})`:e.toString()}function Je({data_field:e,aggregation:t},r){return Gn(r,e,t)}function $e({formatter:e,aggregation:t},r){if(typeof r!="string"&&typeof r!="number")return mp(r);if(t.type==="custom")return r;try{return Y(r,e)}catch(a){return console.error(a),r}}function It(e,t){return e.replaceAll(/(\$\{([^{\}]+(?=}))\})/g,(...a)=>{const l=a[2],o=t.variableStyleMap[l];if(!o)return`{{${l}}}`;const{variable:i,...c}=o,d=Object.entries(c).map(([v,_])=>`${v}:${_}`).join(";"),u=i.color;if(u.type!=="continuous")return`<span style="${d}">{{${l}}}</span>`;const p=Js(6),f=`try {
52
52
  return utils.popmotion.interpolate(${JSON.stringify(u.valueRange)}, ${JSON.stringify(u.colorRange)})(variables["${l}"]);
53
53
  } catch (error) {
54
54
  console.error(error);
55
55
  return "black";
56
- }`;return`<span style="${d}"><dynamic-color id="${p}" data-value='${f}'>{{${l}}}</dynamic-color></span>`})}function xp(e,t){const{data_field:r,aggregation:a}=e,l=Gn(t,r,a);return $e(e,l)}function sl(e,t){const r={};return e.forEach(a=>{r[a.name]=xp(a,t)}),r}function jt(e,t,r){const a=sl(t,r),l=/^\{(.+)\}(.*)$/;return e.split("$").map(o=>{const i=l.exec(o);if(!i)return o;const c=a[i[1]];if(!c)return o;const d=i[2]??"";return`${c}${d}`}).join("")}function*wp(e){const t=He.graphics[e];if(!t)throw new Error("Invalid palette key provided");const r=Object.values(t);let a=0;for(;;)yield r[a%r.length],a++}function sr(){return{filters:{},context:{}}}function lr(e){const t=sr();if(!e)return sr();const{filters:r=t.filters,context:a=t.context}=e;return{filters:r,context:a}}class ne extends h.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const r=()=>{this.setState({error:null})};return n.jsxs(s.Box,{children:[n.jsx(s.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),n.jsx(s.Button,{variant:"subtle",mx:"auto",size:"compact-xs",sx:{display:"block"},onClick:r,children:"Retry"})]})}return this.props.children}}function ll(e,t={handleError:!0}){return r=>n.jsx(ne,{...t,children:n.jsx(e,{...r})})}function mp(e,t){return new Function(`return ${e}`)()(t,je)}function Cp(e,t,r){return mp(e,{context:t,filters:r})}function rn(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,je)}catch(r){return console.error(r),t}}function an(e,t){return new Function(`return ${e.config.processing.post}`)()(t,je)}function ol(e,t,r){return e?new Function(`return ${e}`)()(t,je,r):t}function il(){Za.use([sd.CanvasRenderer,Xe.BarChart,Xe.BoxplotChart,Xe.CustomChart,Xe.FunnelChart,Xe.HeatmapChart,Xe.LineChart,Xe.PieChart,Xe.RadarChart,Xe.ScatterChart,Xe.SunburstChart,ct.CalendarComponent,ct.DataZoomComponent,ct.GridComponent,ct.LegendComponent,ct.TooltipComponent,ct.MarkLineComponent,ct.MarkAreaComponent,ct.VisualMapComponent])}const tt=e=>y.cloneDeepWith(e,(t,r)=>{if(r!==void 0&&t)return Q.toJS(t)});function or(e,t){const r=Object.keys(t),a=Object.values(t);try{return new Function(...r,`return \`${e}\`;`)(...a)}catch(l){throw r.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):l}}function ir(e,t){try{return or(e,t)}catch(r){return console.error(r),r.message}}function Sp({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},je)}catch(r){throw console.error(r),r}}function Tp(e,t,r){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,je,r)}catch(a){throw console.error(a),a}}const Mt={sqlSnippet:new RegExp("(?<=sql_snippets\\.)([^\\?}.]+)","gm"),context:new RegExp("(?<=context\\.)([^\\?}.]+)","gm"),filter:new RegExp("(?<=filters\\.)([^\\?}.]+)","gm")};function kp(e,t){const r={};return e.forEach(a=>{const{name:l,data_field:o,aggregation:i}=a,c=Gn(t,o,i);r[l]=$e(a,c)}),r}function zp(e){const t=document.createElement("span");return t.innerHTML=e,t.innerText}function Dp(e,t,r){try{return new Function("payload",`
56
+ }`;return`<span style="${d}"><dynamic-color id="${p}" data-value='${f}'>{{${l}}}</dynamic-color></span>`})}function Cp(e,t){const{data_field:r,aggregation:a}=e,l=Gn(t,r,a);return $e(e,l)}function ol(e,t){const r={};return e.forEach(a=>{r[a.name]=Cp(a,t)}),r}function jt(e,t,r){const a=ol(t,r),l=/^\{(.+)\}(.*)$/;return e.split("$").map(o=>{const i=l.exec(o);if(!i)return o;const c=a[i[1]];if(!c)return o;const d=i[2]??"";return`${c}${d}`}).join("")}function*Sp(e){const t=Ze.graphics[e];if(!t)throw new Error("Invalid palette key provided");const r=Object.values(t);let a=0;for(;;)yield r[a%r.length],a++}function sr(){return{filters:{},context:{}}}function lr(e){const t=sr();if(!e)return sr();const{filters:r=t.filters,context:a=t.context}=e;return{filters:r,context:a}}class te extends h.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const r=()=>{this.setState({error:null})};return n.jsxs(s.Box,{children:[n.jsx(s.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),n.jsx(s.Button,{variant:"subtle",mx:"auto",size:"compact-xs",sx:{display:"block"},onClick:r,children:"Retry"})]})}return this.props.children}}function il(e,t={handleError:!0}){return r=>n.jsx(te,{...t,children:n.jsx(e,{...r})})}function Tp(e,t){return new Function(`return ${e}`)()(t,Ge)}function kp(e,t,r){return Tp(e,{context:t,filters:r})}function rn(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,Ge)}catch(r){return console.error(r),t}}function an(e,t){return new Function(`return ${e.config.processing.post}`)()(t,Ge)}function cl(e,t,r){return e?new Function(`return ${e}`)()(t,Ge,r):t}function dl(){Ja.use([id.CanvasRenderer,Ke.BarChart,Ke.BoxplotChart,Ke.CustomChart,Ke.FunnelChart,Ke.HeatmapChart,Ke.LineChart,Ke.PieChart,Ke.RadarChart,Ke.ScatterChart,Ke.SunburstChart,ct.CalendarComponent,ct.DataZoomComponent,ct.GridComponent,ct.LegendComponent,ct.TooltipComponent,ct.MarkLineComponent,ct.MarkAreaComponent,ct.VisualMapComponent])}const tt=e=>y.cloneDeepWith(e,(t,r)=>{if(r!==void 0&&t)return Q.toJS(t)});function or(e,t){const r=Object.keys(t),a=Object.values(t);try{return new Function(...r,`return \`${e}\`;`)(...a)}catch(l){throw r.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):l}}function ir(e,t){try{return or(e,t)}catch(r){return console.error(r),r.message}}function zp({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},Ge)}catch(r){throw console.error(r),r}}function Dp(e,t,r){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,Ge,r)}catch(a){throw console.error(a),a}}const Mt={sqlSnippet:new RegExp("(?<=sql_snippets\\.)([^\\?}.]+)","gm"),context:new RegExp("(?<=context\\.)([^\\?}.]+)","gm"),filter:new RegExp("(?<=filters\\.)([^\\?}.]+)","gm")};function Ip(e,t){const r={};return e.forEach(a=>{const{name:l,data_field:o,aggregation:i}=a,c=Gn(t,o,i);r[l]=$e(a,c)}),r}function Mp(e){const t=document.createElement("span");return t.innerHTML=e,t.innerText}function Vp(e,t,r){try{return new Function("payload",`
57
57
  const filters = payload.filters;
58
58
  const context = payload.context;
59
59
  ${Object.entries(t).map(([a,l])=>`const ${a} = '${l}';`).join(`
60
60
  `)}
61
61
  return ${e};
62
- `)(r)}catch(a){return console.error(a),console.log(e),e}}function ht(e,t,r,a){const l=kp(t,a);return e.replaceAll(/(\{\{([^{\}]+(?=}))\}\})/g,(...i)=>{const c=i[2];if(!c)return c;const d=l[c];if(d)return d;const u=zp(c);return Dp(u,l,r)})}const cr={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};function de(e,t){e.messageChannels.getChannel("viz").emit("rendered",t)}function Ip(e,t){return e.messageChannels.getChannel("viz").on("rendered",t),()=>{e.messageChannels.getChannel("viz").off("rendered",t)}}function Mp({context:e,instance:t}){const{value:r}=B(e.instanceData,"config"),a=e.data,{width:l,height:o}=e.viewport,{x_axis_data_key:i,y_axis_data_key:c,z_axis_data_key:d,xAxis3D:u,yAxis3D:p,zAxis3D:f}=y.defaults({},r,cr),v=h.useMemo(()=>Rt(a,i),[a,i]),{x:_,y:w,z:m}=h.useMemo(()=>({x:A(i),y:A(c),z:A(d)}),[i,c,d]),{min:k,max:z}=h.useMemo(()=>{const E=y.minBy(v,N=>N[m.columnKey]),K=y.maxBy(v,N=>N[m.columnKey]);return{min:y.get(E,m.columnKey),max:y.get(K,m.columnKey)}},[v,m]),D=h.useRef(null),I=h.useMemo(()=>({finished:()=>{var K;const E=(K=D.current)==null?void 0:K.getEchartsInstance();E&&de(t,E.getOption())}}),[]),L={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:k,max:z,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:u,yAxis3D:p,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:v.map(E=>[E[_.columnKey],E[w.columnKey],E[m.columnKey]])}]};return r?n.jsx(_e,{width:l,height:o,children:n.jsx(he,{echarts:ce,ref:D,option:L,style:Ot(l,o),notMerge:!0,onEvents:I,theme:"merico-light"})}):null}const q=T.observer(h.forwardRef(({label:e,required:t,description:r,value:a,onChange:l,queryID:o,clearable:i=!1,sx:c,...d},u)=>{const{panel:p}=re(),f=h.useMemo(()=>p.dataFieldOptionGroups(a,i,o),[a,i,o]);if(f.length===0){const v=p.explainDataKey(a);return n.jsxs(s.HoverCard,{shadow:"md",position:"bottom-start",withinPortal:!0,zIndex:320,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Box,{children:n.jsx(s.TextInput,{label:e,required:t,defaultValue:v.columnKey,readOnly:!0,disabled:!0})})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsxs(s.Group,{justify:"flex-start",gap:0,children:[n.jsx(s.Text,{size:"xs",c:v.queryName?"black":"red",ff:"monospace",children:v.queryName??v.queryID}),n.jsx(s.Text,{size:"xs",c:"black",ff:"monospace",children:"."}),n.jsx(s.Text,{size:"xs",c:"red",ff:"monospace",children:v.columnKey})]})})]})}return n.jsx(s.Select,{ref:u,label:e,description:r,data:f,value:a,onChange:Z(l),required:t,sx:c,maxDropdownHeight:500,...d})}));function Ap({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),a=y.defaults({},t,cr),{control:l,handleSubmit:o,reset:i}=b.useForm({defaultValues:a});return h.useEffect(()=>{i(a)},[t]),t?n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:o(r),children:[n.jsx(s.Text,{size:"sm",children:"X Axis"}),n.jsxs(s.Group,{justify:"space-between",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n.jsx(b.Controller,{name:"x_axis_data_key",control:l,render:({field:c})=>n.jsx(q,{label:"Data Field",required:!0,...c})}),n.jsx(b.Controller,{name:"xAxis3D.name",control:l,render:({field:c})=>n.jsx(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),n.jsx(s.Text,{mt:"lg",size:"sm",children:"Y Axis"}),n.jsxs(s.Group,{justify:"space-between",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n.jsx(b.Controller,{name:"y_axis_data_key",control:l,render:({field:c})=>n.jsx(q,{label:"Data Field",required:!0,...c})}),n.jsx(b.Controller,{name:"yAxis3D.name",control:l,render:({field:c})=>n.jsx(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),n.jsx(s.Text,{mt:"lg",size:"sm",children:"Z Axis"}),n.jsxs(s.Group,{justify:"space-between",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n.jsx(b.Controller,{name:"z_axis_data_key",control:l,render:({field:c})=>n.jsx(q,{label:"Data Field",required:!0,...c})}),n.jsx(b.Controller,{name:"zAxis3D.name",control:l,render:({field:c})=>n.jsx(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),n.jsx(s.Group,{justify:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:n.jsxs(s.Button,{color:"blue",type:"submit",children:[n.jsx(S.IconDeviceFloppy,{size:20}),n.jsx(s.Text,{ml:"md",size:"sm",children:"Save"})]})})]})}):null}const Pp=[{lang:"en",resources:{bar_chart_3d:{viz_name:"Bar Chart(3D)"}}},{lang:"zh",resources:{bar_chart_3d:{viz_name:"柱图(3D)"}}}];function Vp(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{x_axis_data_key:l,y_axis_data_key:o,z_axis_data_key:i,...c}=e;return{...c,x_axis_data_key:a(l),y_axis_data_key:a(o),z_axis_data_key:a(i)}}catch(r){throw console.error("[Migration failed]",r),r}}class $p extends ee{constructor(){super(...arguments);P(this,"VERSION",2)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,(r,a)=>{const{config:l}=r;return{...r,version:2,config:Vp(l,a)}})}}const Ep={displayName:"viz.bar_chart_3d.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new $p,name:"bar-3d",viewRender:Mp,configRender:Ap,createConfig(){return{version:2,config:y.cloneDeep(cr)}},translation:Pp},Bp=({disabled:e,value:t,onChange:r})=>{const a=l=>{l&&r(l)};return n.jsxs(s.Box,{sx:{position:"relative"},children:[e&&n.jsx(s.Overlay,{backgroundOpacity:.6,color:"#fff",zIndex:5,blur:2}),n.jsx(Te,{height:"500px",defaultLanguage:"javascript",value:t,onChange:a,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})};function xe({enabled:e,func_content:t}){return(r,a)=>{if(!e)return r;try{return new Function(`return ${t}`)()(r,a)}catch(l){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${l.message}`),r}}}function fe(){return{enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
63
- `)}}const Qe=h.forwardRef(({value:e,onChange:t,triggerButtonText:r},a)=>{const{t:l}=x.useTranslation(),[o,{setTrue:i,setFalse:c}]=O.useBoolean(),[d,u]=h.useState(e);h.useEffect(()=>{u(e)},[e]);const p=k=>{u({...d,enabled:k})},f=()=>{c();const{enabled:k,func_content:z}=d,D={enabled:k,func_content:z};u(D),t(D)},v=()=>{c(),u(e)},_=k=>{u(z=>({...z,func_content:k}))},w=()=>{_(fe().func_content)},m=r??l("chart.axis.customize_label");return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{variant:"filled",color:"grape",leftSection:n.jsx(S.IconMathFunction,{size:16}),mt:24,onClick:i,sx:{flexGrow:0},children:m}),n.jsx(s.Modal,{size:800,title:m,opened:o,onClose:c,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:o&&n.jsxs(s.Stack,{children:[n.jsx(s.Checkbox,{mt:10,label:l("common.enabled"),checked:d.enabled,onChange:k=>p(k.currentTarget.checked)}),n.jsx(Bp,{value:d.func_content,onChange:_,disabled:!d.enabled}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:w,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:l("common.actions.reset_to_default")}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:v,variant:"subtle",children:l("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:f,children:l("common.actions.save")})]})]})]})})]})}),wt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1};function cl(){return y.cloneDeep(wt)}const Lp=[{lang:"en",resources:{boxplot:{viz_name:"Boxplot Chart",box:"Box",outlier:"Outlier",scatter:"Scatter",click_series:{label:"Click box, scatter or outlier"}}}},{lang:"zh",resources:{boxplot:{viz_name:"箱线图",box:"箱体",outlier:"异常点",scatter:"散点",click_series:{label:"点击箱体、散点或异常点"}}}}],dl={id:"builtin:echarts:click-echart:series",displayName:"viz.boxplot.click_series.label",nameRender:Op,configRender:qp,payload:[{name:"type",description:"Always 'click'",valueType:"string"},{name:"seriesType",description:"'boxplot'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"Record of 'name', 'min', 'q1', 'median', 'q3', 'max'",valueType:"object"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function qp(e){return n.jsx(n.Fragment,{})}function Op(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.boxplot.click_series.label")})}const sn=h.forwardRef(({sectionTitle:e,value:t,onChange:r},a)=>{const{t:l,i18n:o}=x.useTranslation(),i=d=>u=>{const p=y.cloneDeep(t);y.set(p,d,u),r(p)},c=h.useMemo(()=>[{label:l("chart.axis.overflow.truncate"),value:"truncate"},{label:l("chart.axis.overflow.break_line"),value:"break"},{label:l("chart.axis.overflow.break_word"),value:"breakAll"}],[o.language]);return n.jsxs(s.Stack,{gap:0,children:[e&&n.jsx(s.Divider,{mb:-5,mt:5,variant:"dotted",label:e,labelPosition:"right",styles:{label:{color:"dimmed"}}}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(s.NumberInput,{label:l("chart.axis.overflow.max_width"),hideControls:!0,value:t.width,onChange:i("width")}),n.jsx(s.Select,{label:l("chart.axis.overflow.label"),data:c,value:t.overflow,onChange:i("overflow")}),n.jsx(s.TextInput,{label:l("chart.axis.overflow.ellipsis"),value:t.ellipsis,disabled:!0})]})]})}),We=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a}=x.useTranslation(),l=i=>{t({...e,on_axis:i})},o=i=>{t({...e,in_tooltip:i})};return n.jsxs(s.Stack,{ref:r,gap:0,children:[n.jsx(sn,{sectionTitle:a("chart.axis.overflow.section_title.on_axis"),value:e.on_axis,onChange:l}),n.jsx(sn,{sectionTitle:a("chart.axis.overflow.section_title.in_tooltip"),value:e.in_tooltip,onChange:o})]})});function we(){return{on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}}}function Ee({overflow:e,width:t}){const r={truncate:"initial",break:"break-all",breakAll:"break-word"}[e],a=e==="truncate"?"nowrap":"initial",l={truncate:"ellipsis",break:"clip",breakAll:"clip"}[e];return`
62
+ `)(r)}catch(a){return console.error(a),console.log(e),e}}function ht(e,t,r,a){const l=Ip(t,a);return e.replaceAll(/(\{\{([^{\}]+(?=}))\}\})/g,(...i)=>{const c=i[2];if(!c)return c;const d=l[c];if(d)return d;const u=Mp(c);return Vp(u,l,r)})}const cr={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};function de(e,t){e.messageChannels.getChannel("viz").emit("rendered",t)}function Pp(e,t){return e.messageChannels.getChannel("viz").on("rendered",t),()=>{e.messageChannels.getChannel("viz").off("rendered",t)}}function Ap({context:e,instance:t}){const{value:r}=B(e.instanceData,"config"),a=e.data,{width:l,height:o}=e.viewport,{x_axis_data_key:i,y_axis_data_key:c,z_axis_data_key:d,xAxis3D:u,yAxis3D:p,zAxis3D:f}=y.defaults({},r,cr),v=h.useMemo(()=>Rt(a,i),[a,i]),{x:_,y:w,z:m}=h.useMemo(()=>({x:P(i),y:P(c),z:P(d)}),[i,c,d]),{min:k,max:z}=h.useMemo(()=>{const E=y.minBy(v,N=>N[m.columnKey]),K=y.maxBy(v,N=>N[m.columnKey]);return{min:y.get(E,m.columnKey),max:y.get(K,m.columnKey)}},[v,m]),D=h.useRef(null),I=h.useMemo(()=>({finished:()=>{var K;const E=(K=D.current)==null?void 0:K.getEchartsInstance();E&&de(t,E.getOption())}}),[]),L={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:k,max:z,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:u,yAxis3D:p,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:v.map(E=>[E[_.columnKey],E[w.columnKey],E[m.columnKey]])}]};return r?n.jsx(_e,{width:l,height:o,children:n.jsx(he,{echarts:ie,ref:D,option:L,style:Ot(l,o),notMerge:!0,onEvents:I,theme:"merico-light"})}):null}const q=T.observer(h.forwardRef(({label:e,required:t,description:r,value:a,onChange:l,queryID:o,clearable:i=!1,sx:c,...d},u)=>{const{panel:p}=re(),f=h.useMemo(()=>p.dataFieldOptionGroups(a,i,o),[a,i,o]);if(f.length===0){const v=p.explainDataKey(a);return n.jsxs(s.HoverCard,{shadow:"md",position:"bottom-start",withinPortal:!0,zIndex:320,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Box,{children:n.jsx(s.TextInput,{label:e,required:t,defaultValue:v.columnKey,readOnly:!0,disabled:!0})})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsxs(s.Group,{justify:"flex-start",gap:0,children:[n.jsx(s.Text,{size:"xs",c:v.queryName?"black":"red",ff:"monospace",children:v.queryName??v.queryID}),n.jsx(s.Text,{size:"xs",c:"black",ff:"monospace",children:"."}),n.jsx(s.Text,{size:"xs",c:"red",ff:"monospace",children:v.columnKey})]})})]})}return n.jsx(s.Select,{ref:u,label:e,description:r,data:f,value:a,onChange:Z(l),required:t,sx:c,maxDropdownHeight:500,...d})}));function $p({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),a=y.defaults({},t,cr),{control:l,handleSubmit:o,reset:i}=b.useForm({defaultValues:a});return h.useEffect(()=>{i(a)},[t]),t?n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:o(r),children:[n.jsx(s.Text,{size:"sm",children:"X Axis"}),n.jsxs(s.Group,{justify:"space-between",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n.jsx(b.Controller,{name:"x_axis_data_key",control:l,render:({field:c})=>n.jsx(q,{label:"Data Field",required:!0,...c})}),n.jsx(b.Controller,{name:"xAxis3D.name",control:l,render:({field:c})=>n.jsx(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),n.jsx(s.Text,{mt:"lg",size:"sm",children:"Y Axis"}),n.jsxs(s.Group,{justify:"space-between",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n.jsx(b.Controller,{name:"y_axis_data_key",control:l,render:({field:c})=>n.jsx(q,{label:"Data Field",required:!0,...c})}),n.jsx(b.Controller,{name:"yAxis3D.name",control:l,render:({field:c})=>n.jsx(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),n.jsx(s.Text,{mt:"lg",size:"sm",children:"Z Axis"}),n.jsxs(s.Group,{justify:"space-between",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n.jsx(b.Controller,{name:"z_axis_data_key",control:l,render:({field:c})=>n.jsx(q,{label:"Data Field",required:!0,...c})}),n.jsx(b.Controller,{name:"zAxis3D.name",control:l,render:({field:c})=>n.jsx(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),n.jsx(s.Group,{justify:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:n.jsxs(s.Button,{color:"blue",type:"submit",children:[n.jsx(S.IconDeviceFloppy,{size:20}),n.jsx(s.Text,{ml:"md",size:"sm",children:"Save"})]})})]})}):null}const Ep=[{lang:"en",resources:{bar_chart_3d:{viz_name:"Bar Chart(3D)"}}},{lang:"zh",resources:{bar_chart_3d:{viz_name:"柱图(3D)"}}}];function Bp(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{x_axis_data_key:l,y_axis_data_key:o,z_axis_data_key:i,...c}=e;return{...c,x_axis_data_key:a(l),y_axis_data_key:a(o),z_axis_data_key:a(i)}}catch(r){throw console.error("[Migration failed]",r),r}}class Lp extends ee{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,(r,a)=>{const{config:l}=r;return{...r,version:2,config:Bp(l,a)}})}}const qp={displayName:"viz.bar_chart_3d.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new Lp,name:"bar-3d",viewRender:Ap,configRender:$p,createConfig(){return{version:2,config:y.cloneDeep(cr)}},translation:Ep},Op=({disabled:e,value:t,onChange:r})=>{const a=l=>{l&&r(l)};return n.jsxs(s.Box,{sx:{position:"relative"},children:[e&&n.jsx(s.Overlay,{backgroundOpacity:.6,color:"#fff",zIndex:5,blur:2}),n.jsx(Ce,{height:"500px",defaultLanguage:"javascript",value:t,onChange:a,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})};function ze({enabled:e,func_content:t}){return(r,a)=>{if(!e)return r;try{return new Function(`return ${t}`)()(r,a)}catch(l){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${l.message}`),r}}}function ye(){return{enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
63
+ `)}}const He=h.forwardRef(({value:e,onChange:t,triggerButtonText:r},a)=>{const{t:l}=x.useTranslation(),[o,{setTrue:i,setFalse:c}]=O.useBoolean(),[d,u]=h.useState(e);h.useEffect(()=>{u(e)},[e]);const p=k=>{u({...d,enabled:k})},f=()=>{c();const{enabled:k,func_content:z}=d,D={enabled:k,func_content:z};u(D),t(D)},v=()=>{c(),u(e)},_=k=>{u(z=>({...z,func_content:k}))},w=()=>{_(ye().func_content)},m=r??l("chart.axis.customize_label");return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{variant:"filled",color:"grape",leftSection:n.jsx(S.IconMathFunction,{size:16}),mt:24,onClick:i,sx:{flexGrow:0},children:m}),n.jsx(s.Modal,{size:800,title:m,opened:o,onClose:c,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:o&&n.jsxs(s.Stack,{children:[n.jsx(s.Checkbox,{mt:10,label:l("common.enabled"),checked:d.enabled,onChange:k=>p(k.currentTarget.checked)}),n.jsx(Op,{value:d.func_content,onChange:_,disabled:!d.enabled}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:w,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:l("common.actions.reset_to_default")}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:v,variant:"subtle",children:l("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:f,children:l("common.actions.save")})]})]})]})})]})}),wt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1};function ul(){return y.cloneDeep(wt)}const Np=[{lang:"en",resources:{boxplot:{viz_name:"Boxplot Chart",box:"Box",outlier:"Outlier",scatter:"Scatter",click_series:{label:"Click box, scatter or outlier"}}}},{lang:"zh",resources:{boxplot:{viz_name:"箱线图",box:"箱体",outlier:"异常点",scatter:"散点",click_series:{label:"点击箱体、散点或异常点"}}}}],pl={id:"builtin:echarts:click-echart:series",displayName:"viz.boxplot.click_series.label",nameRender:Fp,configRender:Gp,payload:[{name:"type",description:"Always 'click'",valueType:"string"},{name:"seriesType",description:"'boxplot'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"Record of 'name', 'min', 'q1', 'median', 'q3', 'max'",valueType:"object"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Gp(e){return n.jsx(n.Fragment,{})}function Fp(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.boxplot.click_series.label")})}const sn=h.forwardRef(({sectionTitle:e,value:t,onChange:r},a)=>{const{t:l,i18n:o}=x.useTranslation(),i=d=>u=>{const p=y.cloneDeep(t);y.set(p,d,u),r(p)},c=h.useMemo(()=>[{label:l("chart.axis.overflow.truncate"),value:"truncate"},{label:l("chart.axis.overflow.break_line"),value:"break"},{label:l("chart.axis.overflow.break_word"),value:"breakAll"}],[o.language]);return n.jsxs(s.Stack,{gap:0,children:[e&&n.jsx(s.Divider,{mb:-5,mt:5,variant:"dotted",label:e,labelPosition:"right",styles:{label:{color:"dimmed"}}}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(s.NumberInput,{label:l("chart.axis.overflow.max_width"),hideControls:!0,value:t.width,onChange:i("width")}),n.jsx(s.Select,{label:l("chart.axis.overflow.label"),data:c,value:t.overflow,onChange:i("overflow")}),n.jsx(s.TextInput,{label:l("chart.axis.overflow.ellipsis"),value:t.ellipsis,disabled:!0})]})]})}),Re=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a}=x.useTranslation(),l=i=>{t({...e,on_axis:i})},o=i=>{t({...e,in_tooltip:i})};return n.jsxs(s.Stack,{ref:r,gap:0,children:[n.jsx(sn,{sectionTitle:a("chart.axis.overflow.section_title.on_axis"),value:e.on_axis,onChange:l}),n.jsx(sn,{sectionTitle:a("chart.axis.overflow.section_title.in_tooltip"),value:e.in_tooltip,onChange:o})]})});function De(){return{on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}}}function Ee({overflow:e,width:t}){const r={truncate:"initial",break:"break-all",breakAll:"break-word"}[e],a=e==="truncate"?"nowrap":"initial",l={truncate:"ellipsis",break:"clip",breakAll:"clip"}[e];return`
64
64
  max-width: ${t}px;
65
65
  word-break: ${r};
66
66
  white-space: ${a};
67
67
  overflow: hidden;
68
68
  text-overflow: ${l};
69
- `}function Be(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}const ue=h.forwardRef(({value:e,onChange:t,hiddenFileds:r},a)=>{const{t:l}=x.useTranslation(),o=h.useMemo(()=>new Set(r??[]),[r]),i=c=>d=>{t({...e,[c]:d})};return n.jsxs(s.Stack,{ref:a,gap:"sm",children:[n.jsx(s.Divider,{mb:-10,label:l("chart.unit.title"),labelPosition:"center",variant:"dashed"}),!o.has("text")&&n.jsx(s.TextInput,{size:"xs",placeholder:l("chart.unit.text.placeholder"),value:e.text,onChange:c=>i("text")(c.currentTarget.value)}),n.jsxs(s.Group,{grow:!0,children:[!o.has("show_in_tooltip")&&n.jsx(s.Checkbox,{size:"xs",label:l("chart.unit.show_in_tooltip"),checked:e.show_in_tooltip,onChange:c=>i("show_in_tooltip")(c.currentTarget.checked)}),!o.has("show_in_legend")&&n.jsx(s.Checkbox,{size:"xs",label:l("chart.unit.show_in_legend"),checked:e.show_in_legend,onChange:c=>i("show_in_legend")(c.currentTarget.checked)})]})]})});function U(){return{text:"",show_in_tooltip:!1,show_in_legend:!1}}const dr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:fe(),overflow:we()}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:le,unit:U()},tooltip:{metrics:[]},color:"rgba(99, 152, 199, 0.10)",reference_lines:[],legend:{show:!0,top:"10",right:"0",left:"auto",bottom:"auto",orient:"vertical",type:"scroll"},dataZoom:cl()};function mt(e,t){return h.useMemo(()=>{const{queryID:r,columnKey:a}=A(t);return y.keyBy(e[r],a)},[e,t])}const Ie=(e,t)=>{const[r,a]=h.useState([]);return h.useEffect(()=>e.watchTriggerSnapshotList(l=>a(l.filter(o=>o.schemaRef===t))),[]),r},ur=h.createContext(null);function ln(e){const t=h.useContext(ur),r=O.useCreation(()=>e.configure(t||new On),[e.configure]),a=O.usePrevious(r);return a&&a!==r&&a.dispose(),n.jsx(ur.Provider,{value:r,children:e.children})}function Qt(){return h.useContext(ur)}const Me=({})=>Qt().getRequired(R.instanceScope.interactionManager),ul=e=>{const{t}=x.useTranslation(),{title:r="Variables",variables:a}=e,l=te.useClipboard(),o=i=>{l.copy(i),Ze.showNotification({color:"green",message:t("common.copied")})};return n.jsxs(s.Paper,{withBorder:!0,p:"sm",children:[n.jsx(s.Text,{size:"xs",c:"dimmed",mb:"sm",children:r}),n.jsx(s.Stack,{style:{maxHeight:"500px"},children:a.map(i=>n.jsxs(s.Text,{size:"sm",children:[n.jsxs(s.Code,{color:"teal",children:["// ",i.description]}),n.jsx("br",{}),n.jsxs(s.Code,{onClick:()=>o(i.name),style:{cursor:"pointer"},children:[i.name," : ",i.valueType]})]},i.name))})]})};class Np{constructor(t,r){P(this,"operationId");P(this,"operation");P(this,"operationSchema");P(this,"variables",[]);this.operationManager=t,this.instance=r,Q.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,r){const a=await this.operationManager.retrieveTrigger(t),l=this.operationManager.getOperationSchemaList().find(o=>o.id===(a==null?void 0:a.schemaRef));Q.runInAction(()=>{this.operationId=t,this.operation=a,this.operationSchema=l,this.variables=r})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function Gp(e){return!!e.operationId}const Fp=T.observer(({model:e,onClick:t})=>{var l;const{t:r}=x.useTranslation(),a=(l=e.operationSchema)==null?void 0:l.displayName;return n.jsx(s.Button,{variant:"outline",onClick:t,children:r(a)})}),pl=T.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return h.createElement(e.operationSchema.configRender,t)}),jp=T.observer(({model:e})=>{const{t,i18n:r}=x.useTranslation(),a=e.schemaList,l=h.useMemo(()=>a.map(i=>({label:t(i.displayName),value:i.id})),[a,r.language]);async function o(i){await e.changeSchema(a.find(c=>c.id===i))}return n.jsx(s.Select,{label:t("interactions.operation.label"),data:l,onChange:Z(o),value:e.operationSchema.id,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500})}),Qp=T.observer(e=>{const{t}=x.useTranslation(),[r,{setTrue:a,setFalse:l}]=O.useBoolean(!1),{operationManager:o,operationId:i,instance:c,variables:d}=e,u=O.useCreation(()=>new Np(o,c),[o,c]);return O.useAsyncEffect(async()=>{await u.configOperation(i,d)},[i,u]),Gp(u)?n.jsxs(n.Fragment,{children:[n.jsx(Fp,{model:u,onClick:a}),n.jsx(s.Modal,{size:600,opened:r,onClose:l,title:t("interactions.operation.setup"),zIndex:320,children:n.jsxs(s.Stack,{children:[n.jsx(jp,{model:u}),u.variables.length>0?n.jsxs(s.Tabs,{defaultValue:"settings",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"settings",children:t("interactions.operation.settings")}),n.jsx(s.Tabs.Tab,{value:"variables",children:t("interactions.operation.variables")})]}),n.jsx(s.Tabs.Panel,{value:"settings",pt:10,children:n.jsx(pl,{model:u})}),n.jsx(s.Tabs.Panel,{value:"variables",pt:10,children:n.jsx(ul,{title:t("interactions.operation.variables"),variables:u.variables})})]}):n.jsx(pl,{model:u})]})})]}):null});class Wp{constructor(t,r){P(this,"triggerId");P(this,"trigger");P(this,"triggerSchema");P(this,"sampleData");this.triggerManager=t,this.instance=r,Q.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,r){const a=await this.triggerManager.retrieveTrigger(t),l=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(a==null?void 0:a.schemaRef));Q.runInAction(()=>{this.triggerId=t,this.trigger=a,this.triggerSchema=l,this.sampleData=r})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return Up(this)}}function Up(e){return!!e.triggerId&&!!e.triggerSchema}function Yp(e,t){return O.useCreation(()=>new Wp(e,t),[e,t])}const Kp=T.observer(({model:e,onClick:t})=>{const r=e.triggerSchema.nameRender,a={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return n.jsx(s.Button,{variant:"outline",onClick:t,children:h.createElement(r,a)})}),Xp=T.observer(({model:e})=>{const{t,i18n:r}=x.useTranslation(),a=e.schemaList,l=h.useMemo(()=>a.map(i=>({label:t(i.displayName),value:i.id})),[a,r.language]);async function o(i){await e.changeSchema(a.find(c=>c.id===i))}return n.jsx(s.Select,{label:t("interactions.trigger.label"),data:l,value:e.triggerSchema.id,onChange:Z(o)})}),Zp=T.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return h.createElement(e.triggerSchema.configRender,t)}),Jp=T.observer(e=>{const{t}=x.useTranslation(),[r,{setTrue:a,setFalse:l}]=O.useBoolean(!1),o=e.model;return n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:r,onClose:l,title:t("interactions.trigger.setup"),zIndex:320,children:n.jsxs(s.Stack,{children:[n.jsx(Xp,{model:o}),n.jsx(Zp,{model:o}),n.jsx(ul,{title:t("interactions.trigger.payload"),variables:o.triggerSchema.payload})]})}),n.jsx(Kp,{onClick:a,model:o})]})});class At{constructor(t,r){this.root=t,this.path=r}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,y.omit(r,t))}async getItem(t){const r=await this.root.getItem(this.path);return t===null?r:y.get(r,t)}async setItem(t,r){if(t===null)await this.root.setItem(this.path,r);else{const a=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...a,[t]:r})}return await this.getItem(t)}watchItem(t,r,a){return t===null?this.root.watchItem(this.path,(l,o)=>{r(l,o)},a):this.root.watchItem(this.path,(l,o)=>{const i=y.get(l,t),c=y.get(o,t);i!==c&&r(i,c)},a)}}const Hp={"builtin:op:debug":1,"builtin:op:clear_filter_values":2,"builtin:op:set_filter_values":3,"builtin:op:open_view":4,"builtin:op:open-link":5};class pr{constructor(t,r,a){P(this,"attachmentStorage");this.instance=t,this.attachmentKey=r,this.constructInstance=a,this.attachmentStorage=new At(t.instanceData,r)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new At(this.attachmentStorage,t))}async create(t,r){return await this.attachmentStorage.setItem(t,r),this.constructInstance(new At(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null),r=y.orderBy(y.values(t),a=>Hp[a.schemaRef]??10);return Promise.all(r.map(a=>this.constructInstance(new At(this.attachmentStorage,a.id))))}}function Rp(e,t){const{value:r,set:a}=B(e.operation.operationData,"config"),[l,o]=h.useState(y.defaults({},r,t)),i=async()=>{await a(l)};return h.useEffect(()=>{o(y.defaults({},r,t))},[r]),{config:l,setConfig:o,commit:i}}function eh(e){const{t}=x.useTranslation(),{config:r,setConfig:a,commit:l}=Rp(e,{urlTemplate:"",openInNewTab:!0});async function o(){await l()}async function i(d){a({...r,openInNewTab:d}),await l()}const c=d=>a({...r,urlTemplate:d.currentTarget.value});return n.jsxs(s.Stack,{children:[n.jsx(s.TextInput,{label:t("interactions.operation.open_link.url"),value:r.urlTemplate,onChange:c,onBlur:o}),n.jsx(s.Switch,{label:t("interactions.operation.open_link.open_in_new_tab"),checked:r.openInNewTab,onChange:d=>i(d.currentTarget.checked)})]})}async function th(e,t){const{urlTemplate:r,openInNewTab:a}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:r,openInNewTab:a,payload:e}}))}class nh extends ee{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,r=>r)}}const rh={displayName:"interactions.operation.open_link.label",id:"builtin:op:open-link",configRender:eh,run:th,migrator:new nh,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function ah(e){const{value:t,set:r}=B(e.operationData,"config"),a=l=>void r({template:l});return[(t==null?void 0:t.template)||"",a]}function sh(e){const{t}=x.useTranslation(),[r,a]=ah(e.operation);return n.jsx(s.TextInput,{defaultValue:r,onBlur:l=>a(l.currentTarget.value),label:t("interactions.operation.console_log.log_content")})}async function lh(e,t){const r=await t.operationData.getItem("config"),a=y.template(r.template||"");console.log("run with payload",e),console.log(a(e))}const oh={displayName:"interactions.operation.console_log.label",id:"builtin:op:debug",configRender:sh,run:lh},ih=T.observer(e=>{const{t}=x.useTranslation(),r=F(),{value:a,set:l}=B(e.operation.operationData,"config"),o=(a==null?void 0:a.viewID)||"",i=c=>void l({viewID:c});return n.jsx(s.Select,{defaultValue:o,value:o,onChange:Z(i),label:t("interactions.operation.open_view.view"),data:r.views.options,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500})});async function ch(e,t){const a=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:a}}))}const dh={displayName:"interactions.operation.open_view.label",id:"builtin:op:open_view",configRender:ih,run:ch},uh={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},ph=({value:e="",onChange:t})=>{const[r,a]=h.useState(e);h.useEffect(()=>{a(e)},[e]);const l=()=>{t(r)};return n.jsx(s.TextInput,{size:"xs",label:"",value:r,onChange:o=>a(o.currentTarget.value),sx:{flexGrow:1},rightSection:n.jsx(s.ActionIcon,{color:"green",size:"xs",onClick:l,disabled:r===e,children:n.jsx(S.IconDeviceFloppy,{})})})},hh={dictionary:{}},gh=T.observer(e=>{const{t}=x.useTranslation(),r=F(),{value:a=hh,set:l}=B(e.operation.operationData,"config"),{dictionary:o={}}=a;console.log({value:{...a},dictionary:{...o},filters:[...r.filters.keyLabelOptions]});const i=(c,d)=>{if(d===""){const u={...o};delete u[c],l({dictionary:u});return}l({dictionary:{...o,[c]:d}})};return n.jsxs(s.Table,{sx:uh,children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:t("interactions.operation.set_filter_values.set_filter")}),n.jsx(s.Table.Th,{children:t("interactions.operation.set_filter_values.with")})]})}),n.jsx(s.Table.Tbody,{children:[...r.filters.keyLabelOptions].map(c=>{const d=c.value in o;return n.jsxs(s.Table.Tr,{"data-affected":d,children:[n.jsx(s.Table.Td,{children:c.label}),n.jsx(s.Table.Td,{children:n.jsx(ph,{value:o[c.value],onChange:u=>i(c.value,u)})})]},c.value)})})]})});async function fh(e,t){const a=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:a,payload:e}}))}const bh={displayName:"interactions.operation.set_filter_values.label",id:"builtin:op:set_filter_values",configRender:gh,run:fh},yh={filter_keys:[]},vh=T.observer(e=>{const{t}=x.useTranslation(),r=F(),{value:a=yh,set:l}=B(e.operation.operationData,"config"),{filter_keys:o=[]}=a,i=d=>{l({filter_keys:[...d]})},c=h.useMemo(()=>r.filters.current.map(d=>({label:d.label,value:d.key})),[r.filters.values]);return n.jsx(s.Stack,{gap:10,children:n.jsx(s.MultiSelect,{label:t("interactions.operation.clear_filter_values.select_filter"),data:c,value:o,onChange:i})})});async function _h(e,t){const a=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:a,payload:e}}))}const xh={displayName:"interactions.operation.clear_filter_values.label",id:"builtin:op:clear_filter_values",configRender:vh,run:_h},wh=({option:e,checked:t})=>{var l;const{t:r}=x.useTranslation(),a=e;return n.jsxs(s.Group,{justify:"space-between",flex:"1",gap:"xs",children:[n.jsx(s.Text,{size:"xs",children:a.label}),n.jsx(s.Text,{size:"xs",children:r((l=ko[a.viz_type])==null?void 0:l.displayName)??a.viz_type})]})},mh=T.observer(e=>{const{t}=x.useTranslation(),r=F(),{value:a,set:l}=B(e.operation.operationData,"config"),o=(a==null?void 0:a.panelID)||"",i=c=>void l({panelID:c});return n.jsx(s.Select,{defaultValue:o,value:o,onChange:Z(i),label:t("interactions.operation.scroll_to_panel.panel"),data:r.panels.options,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500,renderOption:wh})});async function Ch(e,t){const a=(await t.operationData.getItem("config")).panelID;window.dispatchEvent(new CustomEvent("scroll_to_panel",{detail:{panelID:a}}))}const Sh={displayName:"interactions.operation.scroll_to_panel.label",id:"builtin:op:scroll_to_panel",configRender:mh,run:Ch},Th=T.observer(e=>{const{t}=x.useTranslation(),r=F(),{value:a,set:l}=B(e.operation.operationData,"config"),{viewID:o="",tab:i=""}=a??{},c=u=>void l({viewID:u,tab:i}),d=u=>void l({viewID:o,tab:u});return n.jsxs(s.Stack,{gap:"xs",children:[n.jsx(s.Select,{defaultValue:o,value:o,onChange:Z(c),label:t("interactions.operation.switch_tab.view"),data:r.views.tabViewOptions,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500}),n.jsx(s.Select,{defaultValue:i,value:i,onChange:Z(d),label:t("interactions.operation.switch_tab.tab"),data:r.views.tabOptions(o),comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500})]})});async function kh(e,t){const r=await t.operationData.getItem("config"),{viewID:a,tab:l}=r;window.dispatchEvent(new CustomEvent("switch_tab",{detail:{viewID:a,tab:l}}))}const hr=[oh,rh,dh,Sh,bh,{displayName:"interactions.operation.switch_tab.label",id:"builtin:op:switch_tab",configRender:Th,run:kh},xh];class zh{constructor(t,r=hr){P(this,"attachments");this.operations=r;const a=async l=>{const{id:o,schemaRef:i}=await l.getItem(null);return{id:o,schemaRef:i,operationData:new At(l,"data")}};this.attachments=new pr(t,"__OPERATIONS",a)}async runOperation(t,r){const a=await this.attachments.getInstance(t);if(!a){console.warn(`Operation '${t}' is not defined`);return}const l=this.tryGetSchema(a.schemaRef);if(!l){console.warn(`Operation schema '${a.schemaRef}' is not defined`);return}await l.run(r,a)}tryGetSchema(t){return this.operations.find(r=>r.id===t)}async needMigration(){const r=(await this.attachments.list()).map(async a=>{const l={configData:a.operationData},o=this.tryGetSchema(a.schemaRef),i=o==null?void 0:o.migrator;return i&&await i.needMigration(l)});return(await Promise.all(r)).some(a=>a)}async runMigration(){const r=(await this.attachments.list()).map(async a=>{const l={configData:a.operationData},o=this.tryGetSchema(a.schemaRef),i=o==null?void 0:o.migrator;i&&await i.needMigration(l)&&await i.migrate(l)});await Promise.all(r)}async createOrGetOperation(t,r){var i;if(!this.getOperationSchemaList().some(c=>c.id===r.id))throw new Error(`Operation schema '${r.id}' is not defined`);const l=await this.attachments.getInstance(t);return!l||l.schemaRef!==r.id?await this.attachments.create(t,{id:t,schemaRef:r.id,data:((i=r.createDefaultConfig)==null?void 0:i.call(r))??{}}):l}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}const hl="__TRIGGERS";class Dh{constructor(t,r){P(this,"attachments");this.instance=t,this.component=r;const a=async l=>{const{id:o,schemaRef:i}=await l.getItem(null);return{id:o,schemaRef:i,triggerData:new At(l,"data")}};this.attachments=new pr(t,hl,a)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(hl,r=>{const a=y.values(r).map(l=>({id:y.get(l,"id"),schemaRef:y.get(l,"schemaRef"),config:Q.toJS(y.get(l,"data.config"))}));t(a)},{fireImmediately:!0})}async createOrGetTrigger(t,r,a={recreate:!1}){var c;if(!this.getTriggerSchemaList().some(d=>d.id===r.id))throw new Error(`Trigger schema '${r.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(t);return!o||a.recreate||o.schemaRef!==r.id?await this.attachments.create(t,{id:t,schemaRef:r.id,data:((c=r==null?void 0:r.createDefaultConfig)==null?void 0:c.call(r))||{}}):o}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(t){await this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}async getMigrationTasks(){const r=(await this.getTriggerList()).map(async a=>{const l=this.getTriggerSchemaList().find(c=>c.id===a.schemaRef),o=l==null?void 0:l.migrator,i={configData:a.triggerData};return o&&await o.needMigration(i)?()=>o.migrate(i):null});return Promise.all(r).then(a=>a.filter(l=>l))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(r=>r()))}}class gl{constructor(t,r,a){P(this,"operationManager");P(this,"triggerManager");P(this,"attachments");this.operationManager=new zh(t,a),this.triggerManager=new Dh(t,r);const l=async o=>{const{id:i,triggerRef:c,operationRef:d}=await o.getItem(null);return{id:i,triggerRef:c,operationRef:d}};this.attachments=new pr(t,"__INTERACTIONS",l)}async addInteraction(t,r){const a=t.id,l=r.id,o=`[${a}]:[${l}]`;await this.attachments.create(o,{id:o,triggerRef:a,operationRef:l})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const r=await this.attachments.getInstance(t);if(!r)return;const{triggerRef:a,operationRef:l}=r;await this.getTriggerRefCount(a)<=1&&await this.triggerManager.removeTrigger(a),await this.getOperationRefCount(l)<=1&&await this.operationManager.removeOperation(l),await this.attachments.remove(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(a=>a.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(a=>a.triggerRef===t).length}async runInteraction(t,r){const l=(await this.getInteractionList()).filter(o=>o.triggerRef===t);for(let o of l)try{await this.operationManager.runOperation(o.operationRef,r)}catch(i){console.warn(`Failed to run operation '${o.operationRef}'`,i)}}}function Ih(e,t){const[r,a]=h.useState([]);return O.useAsyncEffect(async()=>{const l=await e.getInteractionList();a(l)},[t,e]),r}const Mh=T.observer(({item:e,manager:t,instance:r,sampleData:a,variables:l,onRemove:o})=>{const{triggerRef:i,operationRef:c}=e,d=Yp(t.triggerManager,r);if(O.useAsyncEffect(async()=>{await d.configTrigger(i,a)},[d,i,a]),d.isReady()){const u=[...d.triggerSchema.payload,...l];return n.jsxs(s.Group,{children:[n.jsx(Jp,{model:d}),n.jsx(Qp,{instance:r,operationId:c,variables:u,operationManager:t.operationManager}),n.jsx(s.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:n.jsx(S.IconTrash,{size:16})})]})}return null}),Ah=e=>{const{t}=x.useTranslation(),[r,a]=h.useState(0),{interactionManager:l,instance:o,sampleData:i,variables:c}=e,d=Ih(l,r),u=async()=>{const _=await l.triggerManager.createOrGetTrigger(te.randomId(),l.triggerManager.getTriggerSchemaList()[0]),w=await l.operationManager.createOrGetOperation(te.randomId(),l.operationManager.getOperationSchemaList()[0]);await l.addInteraction(_,w),a(m=>m+1)};async function p(_){await l.removeInteraction(_.id),a(w=>w+1)}const{data:f=0,loading:v}=O.useRequest(async()=>{try{return(await l.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return n.jsxs(s.Stack,{children:[n.jsx(s.LoadingOverlay,{visible:v}),f===0&&n.jsx(s.Alert,{icon:n.jsx(S.IconAlertCircle,{size:16}),title:t("interactions.unavailable"),color:"gray",children:t("interactions.unavailable_reason")}),d.map(_=>n.jsx(Mh,{onRemove:p,instance:o,sampleData:i,variables:c,item:_,manager:e.interactionManager},_.id)),n.jsx(s.Button,{style:{width:"fit-content"},onClick:()=>u(),disabled:f===0,children:t("interactions.add")})]})},Ph=()=>{const{panel:e,data:t}=be(),r=e.viz,{vizManager:a}=h.useContext(rt),l=e.json,o=O.useCreation(()=>a.getOrCreateInstance(l),[a,l]),i=O.useCreation(()=>new gl(o,a.resolveComponent(r.type),hr),[o,r.type]);return h.useEffect(()=>o.instanceData.watchItem(null,y.throttle(c=>{e.viz.setConf(c)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:a,interactionManager:i,sampleData:t,variables:[]}},Vh=()=>{const e=Ph();return n.jsx(Ah,{...e})},fl={axisTick:{show:!0,alignWithLabel:!0,lineStyle:{width:2}},axisLine:{show:!0,lineStyle:{width:3}},splitLine:{show:!1},z:3};function $h(e){return y.defaultsDeep({},e,fl)}const Eh=Object.freeze(Object.defineProperty({__proto__:null,getXAxis:$h,xAxis:fl},Symbol.toStringTag,{value:"Module"})),bl={axisTick:{show:!1},axisLine:{show:!1,lineStyle:{width:3}},splitLine:{show:!0,lineStyle:{type:"dashed"}}};function Bh(e){return y.defaultsDeep({},e,bl)}const Lh=Object.freeze(Object.defineProperty({__proto__:null,getYAxis:Bh,yAxis:bl},Symbol.toStringTag,{value:"Module"})),yl={confine:!0,appendToBody:!0};function qh(e){return y.defaultsDeep({},e,yl)}const X={...Eh,...Lh,...Object.freeze(Object.defineProperty({__proto__:null,getTooltip:qh,tooltip:yl},Symbol.toStringTag,{value:"Module"}))};function Oh(e,t){const r=[],a=[];return{boxplotData:Object.entries(e).map(([o,i])=>{const c=i.map(z=>z[t]).sort((z,D)=>z-D),d=qt.quantile(c,.25)??0,u=qt.quantile(c,.5)??0,p=qt.quantile(c,.75)??0,f=p-d,v=d-1.5*f,_=p+1.5*f,w=Math.max(c[0],v),m=Math.min(y.last(c)??0,_);return i.filter(z=>{const D=z[t];return D<w||D>m}).forEach(z=>r.push([o,z[t],z])),i.filter(z=>{const D=z[t];return D>=w&&D<=m}).forEach(z=>a.push([o,z[t],z])),{name:o,min:w,q1:d,median:u,q3:p,max:m}}),outliersData:r,scatterData:a}}function Nh(e,t){const{x_axis:r,y_axis:a}=e;if(!r.data_key||!a.data_key)return[];const l=A(r.data_key),o=A(a.data_key);if(l.queryID!==o.queryID)throw new Error("Please use the same query for X & Y axis");const i=y.groupBy(t[l.queryID],l.columnKey),{boxplotData:c,outliersData:d,scatterData:u}=Oh(i,o.columnKey);return[{source:c},{source:d},{source:u}]}function Gh(e){const t={top:35,left:20,right:15,bottom:25,containLabel:!0};return e.legend.orient==="vertical"&&(t.right=80),e.dataZoom.x_axis_slider&&(t.top=50),t}function Fh({config:e,seriesNames:t}){const r={...e.legend,data:[{name:t.Box,icon:"roundRect",itemStyle:{color:e.color}},{name:t.Scatter,icon:"circle",itemStyle:{color:"#ED6A45",opacity:.5}},{name:t.Outlier,icon:"circle",itemStyle:{color:"#ED6A45"}}]};return e.legend.orient==="horizontal"&&e.dataZoom.x_axis_slider&&(r.top=15),r}function jh(e,t,r){const a=t.reduce((l,o)=>{const i=Re(o,r);return l[o.name]=$e(o,i),l},{});return e.map(l=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:l.name,yAxis:Number(a[l.variable_key])}],silent:!0,symbol:["none","triangle"],symbolRotate:90,symbolSize:[10,8],label:{formatter:function(){return jt(l.template,t,r)},position:"insideEndTop"}}}))}const gr=["max","q3","median","q1","min"],fr=[10,40];function br(e){return e.barLayout({barMinWidth:fr[0],barMaxWidth:fr[1],count:2})}function Qh(e,t,r){const{itemStyle:{color:a,borderColor:l,borderWidth:o}}=r,i=br(t),c=t.value(0),d=e.source[c],{min:u,q1:p,median:f,q3:v,max:_}=d,w={min:t.coord([c,u]),q1:t.coord([c,p]),median:t.coord([c,f]),q3:t.coord([c,v]),max:t.coord([c,_])},m={left:i[1].offset,center:(i[1].offset+i[1].width)/2,right:i[1].width},k={type:"group",children:[]},z=[{x1:w.max[0]+m.left,x2:w.max[0]+m.right,y1:w.max[1],y2:w.max[1]},{x1:w.median[0]+m.left,x2:w.median[0]+m.right,y1:w.median[1],y2:w.median[1]},{x1:w.min[0]+m.left,x2:w.min[0]+m.right,y1:w.min[1],y2:w.min[1]},{x1:w.min[0]+m.center,x2:w.min[0]+m.center,y1:w.min[1],y2:w.q1[1]},{x1:w.max[0]+m.center,x2:w.max[0]+m.center,y1:w.max[1],y2:w.q3[1]}],D={stroke:l,lineWidth:o};return z.forEach(I=>{k.children.push({type:"line",shape:I,style:D})}),k.children.push({type:"rect",shape:{x:w.q1[0]+m.left,y:w.q1[1],width:m.right-m.left,height:w.q3[1]-w.q1[1]},style:{fill:a,stroke:l,lineWidth:o}}),k}function Wh(e,t){const{color:r}=t,a={name:"Box",type:"custom",itemStyle:{color:r,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:fr,datasetIndex:0};return a.renderItem=(l,o)=>Qh(e,o,a),a}function Uh(e){const t=br(e),r=t[0].width,a=e.value(0),l=e.value(1),[o,i]=e.coord([a,l]),d=o+t[0].offset+Math.random()*r;return{type:"circle",transition:["shape"],x:d,y:i,shape:{cx:0,cy:0,r:2},style:{fill:e.visual("color"),opacity:.5}}}function Yh(){const e={name:"Scatter",type:"custom",itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:2};return e.renderItem=(t,r)=>Uh(r),e}function Kh(e,t){const r=br(e),a=r[0].width,l=e.value(0),o=e.value(1),[i,c]=e.coord([l,o]),u=i+r[0].offset+Math.random()*a;return{type:"circle",transition:["shape"],x:u,y:c,shape:{cx:0,cy:0,r:3},style:{fill:e.visual("color")}}}function Xh(){const e={name:"Outlier",type:"custom",itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:1};return e.renderItem=(t,r)=>Kh(r),e}function Zh(e,t){const r=t[0],a=Wh(r,e),l=Yh(),o=Xh();return[{name:"Placeholder Box",type:"boxplot",ignore:!0,silent:!0,itemStyle:{color:"none",borderColor:"none",opacity:0},boxWidth:[20,80],datasetIndex:0,encode:{y:gr,x:"name",itemName:["name"],tooltip:gr}},{name:"Outlier",type:"scatter",symbolSize:7,itemStyle:{color:"transparent"},ignore:!0,silent:!0,emphasis:{disabled:!0},datasetIndex:1},a,l,o]}const Jh=(e,t)=>{const r=gr.map(o=>`
69
+ `}function Fe(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}const ue=h.forwardRef(({value:e,onChange:t,hiddenFileds:r},a)=>{const{t:l}=x.useTranslation(),o=h.useMemo(()=>new Set(r??[]),[r]),i=c=>d=>{t({...e,[c]:d})};return n.jsxs(s.Stack,{ref:a,gap:"sm",children:[n.jsx(s.Divider,{mb:-10,label:l("chart.unit.title"),labelPosition:"center",variant:"dashed"}),!o.has("text")&&n.jsx(s.TextInput,{size:"xs",placeholder:l("chart.unit.text.placeholder"),value:e.text,onChange:c=>i("text")(c.currentTarget.value)}),n.jsxs(s.Group,{grow:!0,children:[!o.has("show_in_tooltip")&&n.jsx(s.Checkbox,{size:"xs",label:l("chart.unit.show_in_tooltip"),checked:e.show_in_tooltip,onChange:c=>i("show_in_tooltip")(c.currentTarget.checked)}),!o.has("show_in_legend")&&n.jsx(s.Checkbox,{size:"xs",label:l("chart.unit.show_in_legend"),checked:e.show_in_legend,onChange:c=>i("show_in_legend")(c.currentTarget.checked)})]})]})});function U(){return{text:"",show_in_tooltip:!1,show_in_legend:!1}}const dr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:ye(),overflow:De()}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:ce,unit:U()},tooltip:{metrics:[]},color:"rgba(99, 152, 199, 0.10)",reference_lines:[],legend:{show:!0,top:"10",right:"0",left:"auto",bottom:"auto",orient:"vertical",type:"scroll"},dataZoom:ul()};function mt(e,t){return h.useMemo(()=>{const{queryID:r,columnKey:a}=P(t);return y.keyBy(e[r],a)},[e,t])}const Ie=(e,t)=>{const[r,a]=h.useState([]);return h.useEffect(()=>e.watchTriggerSnapshotList(l=>a(l.filter(o=>o.schemaRef===t))),[]),r},ur=h.createContext(null);function ln(e){const t=h.useContext(ur),r=O.useCreation(()=>e.configure(t||new On),[e.configure]),a=O.usePrevious(r);return a&&a!==r&&a.dispose(),n.jsx(ur.Provider,{value:r,children:e.children})}function Qt(){return h.useContext(ur)}const Me=({})=>Qt().getRequired(R.instanceScope.interactionManager),hl=e=>{const{t}=x.useTranslation(),{title:r="Variables",variables:a}=e,l=ne.useClipboard(),o=i=>{l.copy(i),Ye.showNotification({color:"green",message:t("common.copied")})};return n.jsxs(s.Paper,{withBorder:!0,p:"sm",children:[n.jsx(s.Text,{size:"xs",c:"dimmed",mb:"sm",children:r}),n.jsx(s.Stack,{style:{maxHeight:"500px"},children:a.map(i=>n.jsxs(s.Text,{size:"sm",children:[n.jsxs(s.Code,{color:"teal",children:["// ",i.description]}),n.jsx("br",{}),n.jsxs(s.Code,{onClick:()=>o(i.name),style:{cursor:"pointer"},children:[i.name," : ",i.valueType]})]},i.name))})]})};class jp{constructor(t,r){V(this,"operationId");V(this,"operation");V(this,"operationSchema");V(this,"variables",[]);this.operationManager=t,this.instance=r,Q.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,r){const a=await this.operationManager.retrieveTrigger(t),l=this.operationManager.getOperationSchemaList().find(o=>o.id===(a==null?void 0:a.schemaRef));Q.runInAction(()=>{this.operationId=t,this.operation=a,this.operationSchema=l,this.variables=r})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function Qp(e){return!!e.operationId}const Wp=T.observer(({model:e,onClick:t})=>{var l;const{t:r}=x.useTranslation(),a=(l=e.operationSchema)==null?void 0:l.displayName;return n.jsx(s.Button,{variant:"outline",onClick:t,children:r(a)})}),gl=T.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return h.createElement(e.operationSchema.configRender,t)}),Up=T.observer(({model:e})=>{const{t,i18n:r}=x.useTranslation(),a=e.schemaList,l=h.useMemo(()=>a.map(i=>({label:t(i.displayName),value:i.id})),[a,r.language]);async function o(i){await e.changeSchema(a.find(c=>c.id===i))}return n.jsx(s.Select,{label:t("interactions.operation.label"),data:l,onChange:Z(o),value:e.operationSchema.id,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500})}),Kp=T.observer(e=>{const{t}=x.useTranslation(),[r,{setTrue:a,setFalse:l}]=O.useBoolean(!1),{operationManager:o,operationId:i,instance:c,variables:d}=e,u=O.useCreation(()=>new jp(o,c),[o,c]);return O.useAsyncEffect(async()=>{await u.configOperation(i,d)},[i,u]),Qp(u)?n.jsxs(n.Fragment,{children:[n.jsx(Wp,{model:u,onClick:a}),n.jsx(s.Modal,{size:600,opened:r,onClose:l,title:t("interactions.operation.setup"),zIndex:320,children:n.jsxs(s.Stack,{children:[n.jsx(Up,{model:u}),u.variables.length>0?n.jsxs(s.Tabs,{defaultValue:"settings",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"settings",children:t("interactions.operation.settings")}),n.jsx(s.Tabs.Tab,{value:"variables",children:t("interactions.operation.variables")})]}),n.jsx(s.Tabs.Panel,{value:"settings",pt:10,children:n.jsx(gl,{model:u})}),n.jsx(s.Tabs.Panel,{value:"variables",pt:10,children:n.jsx(hl,{title:t("interactions.operation.variables"),variables:u.variables})})]}):n.jsx(gl,{model:u})]})})]}):null});class Yp{constructor(t,r){V(this,"triggerId");V(this,"trigger");V(this,"triggerSchema");V(this,"sampleData");this.triggerManager=t,this.instance=r,Q.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,r){const a=await this.triggerManager.retrieveTrigger(t),l=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(a==null?void 0:a.schemaRef));Q.runInAction(()=>{this.triggerId=t,this.trigger=a,this.triggerSchema=l,this.sampleData=r})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return Xp(this)}}function Xp(e){return!!e.triggerId&&!!e.triggerSchema}function Zp(e,t){return O.useCreation(()=>new Yp(e,t),[e,t])}const Jp=T.observer(({model:e,onClick:t})=>{const r=e.triggerSchema.nameRender,a={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return n.jsx(s.Button,{variant:"outline",onClick:t,children:h.createElement(r,a)})}),Hp=T.observer(({model:e})=>{const{t,i18n:r}=x.useTranslation(),a=e.schemaList,l=h.useMemo(()=>a.map(i=>({label:t(i.displayName),value:i.id})),[a,r.language]);async function o(i){await e.changeSchema(a.find(c=>c.id===i))}return n.jsx(s.Select,{label:t("interactions.trigger.label"),data:l,value:e.triggerSchema.id,onChange:Z(o)})}),Rp=T.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return h.createElement(e.triggerSchema.configRender,t)}),eh=T.observer(e=>{const{t}=x.useTranslation(),[r,{setTrue:a,setFalse:l}]=O.useBoolean(!1),o=e.model;return n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:r,onClose:l,title:t("interactions.trigger.setup"),zIndex:320,children:n.jsxs(s.Stack,{children:[n.jsx(Hp,{model:o}),n.jsx(Rp,{model:o}),n.jsx(hl,{title:t("interactions.trigger.payload"),variables:o.triggerSchema.payload})]})}),n.jsx(Jp,{onClick:a,model:o})]})});class Vt{constructor(t,r){this.root=t,this.path=r}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,y.omit(r,t))}async getItem(t){const r=await this.root.getItem(this.path);return t===null?r:y.get(r,t)}async setItem(t,r){if(t===null)await this.root.setItem(this.path,r);else{const a=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...a,[t]:r})}return await this.getItem(t)}watchItem(t,r,a){return t===null?this.root.watchItem(this.path,(l,o)=>{r(l,o)},a):this.root.watchItem(this.path,(l,o)=>{const i=y.get(l,t),c=y.get(o,t);i!==c&&r(i,c)},a)}}const th={"builtin:op:debug":1,"builtin:op:clear_filter_values":2,"builtin:op:set_filter_values":3,"builtin:op:open_view":4,"builtin:op:open-link":5};class pr{constructor(t,r,a){V(this,"attachmentStorage");this.instance=t,this.attachmentKey=r,this.constructInstance=a,this.attachmentStorage=new Vt(t.instanceData,r)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new Vt(this.attachmentStorage,t))}async create(t,r){return await this.attachmentStorage.setItem(t,r),this.constructInstance(new Vt(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null),r=y.orderBy(y.values(t),a=>th[a.schemaRef]??10);return Promise.all(r.map(a=>this.constructInstance(new Vt(this.attachmentStorage,a.id))))}}function nh(e,t){const{value:r,set:a}=B(e.operation.operationData,"config"),[l,o]=h.useState(y.defaults({},r,t)),i=async()=>{await a(l)};return h.useEffect(()=>{o(y.defaults({},r,t))},[r]),{config:l,setConfig:o,commit:i}}function rh(e){const{t}=x.useTranslation(),{config:r,setConfig:a,commit:l}=nh(e,{urlTemplate:"",openInNewTab:!0});async function o(){await l()}async function i(d){a({...r,openInNewTab:d}),await l()}const c=d=>a({...r,urlTemplate:d.currentTarget.value});return n.jsxs(s.Stack,{children:[n.jsx(s.TextInput,{label:t("interactions.operation.open_link.url"),value:r.urlTemplate,onChange:c,onBlur:o}),n.jsx(s.Switch,{label:t("interactions.operation.open_link.open_in_new_tab"),checked:r.openInNewTab,onChange:d=>i(d.currentTarget.checked)})]})}async function ah(e,t){const{urlTemplate:r,openInNewTab:a}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:r,openInNewTab:a,payload:e}}))}class sh extends ee{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,r=>r)}}const lh={displayName:"interactions.operation.open_link.label",id:"builtin:op:open-link",configRender:rh,run:ah,migrator:new sh,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function oh(e){const{value:t,set:r}=B(e.operationData,"config"),a=l=>void r({template:l});return[(t==null?void 0:t.template)||"",a]}function ih(e){const{t}=x.useTranslation(),[r,a]=oh(e.operation);return n.jsx(s.TextInput,{defaultValue:r,onBlur:l=>a(l.currentTarget.value),label:t("interactions.operation.console_log.log_content")})}async function ch(e,t){const r=await t.operationData.getItem("config"),a=y.template(r.template||"");console.log("run with payload",e),console.log(a(e))}const dh={displayName:"interactions.operation.console_log.label",id:"builtin:op:debug",configRender:ih,run:ch},uh=T.observer(e=>{const{t}=x.useTranslation(),r=F(),{value:a,set:l}=B(e.operation.operationData,"config"),o=(a==null?void 0:a.viewID)||"",i=c=>void l({viewID:c});return n.jsx(s.Select,{defaultValue:o,value:o,onChange:Z(i),label:t("interactions.operation.open_view.view"),data:r.views.options,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500})});async function ph(e,t){const a=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:a}}))}const hh={displayName:"interactions.operation.open_view.label",id:"builtin:op:open_view",configRender:uh,run:ph},gh={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},fh=({value:e="",onChange:t})=>{const[r,a]=h.useState(e);h.useEffect(()=>{a(e)},[e]);const l=()=>{t(r)};return n.jsx(s.TextInput,{size:"xs",label:"",value:r,onChange:o=>a(o.currentTarget.value),sx:{flexGrow:1},rightSection:n.jsx(s.ActionIcon,{color:"green",size:"xs",onClick:l,disabled:r===e,children:n.jsx(S.IconDeviceFloppy,{})})})},bh={dictionary:{}},yh=T.observer(e=>{const{t}=x.useTranslation(),r=F(),{value:a=bh,set:l}=B(e.operation.operationData,"config"),{dictionary:o={}}=a;console.log({value:{...a},dictionary:{...o},filters:[...r.filters.keyLabelOptions]});const i=(c,d)=>{if(d===""){const u={...o};delete u[c],l({dictionary:u});return}l({dictionary:{...o,[c]:d}})};return n.jsxs(s.Table,{sx:gh,children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:t("interactions.operation.set_filter_values.set_filter")}),n.jsx(s.Table.Th,{children:t("interactions.operation.set_filter_values.with")})]})}),n.jsx(s.Table.Tbody,{children:[...r.filters.keyLabelOptions].map(c=>{const d=c.value in o;return n.jsxs(s.Table.Tr,{"data-affected":d,children:[n.jsx(s.Table.Td,{children:c.label}),n.jsx(s.Table.Td,{children:n.jsx(fh,{value:o[c.value],onChange:u=>i(c.value,u)})})]},c.value)})})]})});async function vh(e,t){const a=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:a,payload:e}}))}const _h={displayName:"interactions.operation.set_filter_values.label",id:"builtin:op:set_filter_values",configRender:yh,run:vh},xh={filter_keys:[]},wh=T.observer(e=>{const{t}=x.useTranslation(),r=F(),{value:a=xh,set:l}=B(e.operation.operationData,"config"),{filter_keys:o=[]}=a,i=d=>{l({filter_keys:[...d]})},c=h.useMemo(()=>r.filters.current.map(d=>({label:d.label,value:d.key})),[r.filters.values]);return n.jsx(s.Stack,{gap:10,children:n.jsx(s.MultiSelect,{label:t("interactions.operation.clear_filter_values.select_filter"),data:c,value:o,onChange:i})})});async function mh(e,t){const a=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:a,payload:e}}))}const Ch={displayName:"interactions.operation.clear_filter_values.label",id:"builtin:op:clear_filter_values",configRender:wh,run:mh},Sh=({option:e,checked:t})=>{var l;const{t:r}=x.useTranslation(),a=e;return n.jsxs(s.Group,{justify:"space-between",flex:"1",gap:"xs",children:[n.jsx(s.Text,{size:"xs",children:a.label}),n.jsx(s.Text,{size:"xs",children:r((l=Io[a.viz_type])==null?void 0:l.displayName)??a.viz_type})]})},Th=T.observer(e=>{const{t}=x.useTranslation(),r=F(),{value:a,set:l}=B(e.operation.operationData,"config"),o=(a==null?void 0:a.panelID)||"",i=c=>void l({panelID:c});return n.jsx(s.Select,{defaultValue:o,value:o,onChange:Z(i),label:t("interactions.operation.scroll_to_panel.panel"),data:r.panels.options,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500,renderOption:Sh})});async function kh(e,t){const a=(await t.operationData.getItem("config")).panelID;window.dispatchEvent(new CustomEvent("scroll_to_panel",{detail:{panelID:a}}))}const zh={displayName:"interactions.operation.scroll_to_panel.label",id:"builtin:op:scroll_to_panel",configRender:Th,run:kh},Dh=T.observer(e=>{const{t}=x.useTranslation(),r=F(),{value:a,set:l}=B(e.operation.operationData,"config"),{viewID:o="",tab:i=""}=a??{},c=u=>void l({viewID:u,tab:i}),d=u=>void l({viewID:o,tab:u});return n.jsxs(s.Stack,{gap:"xs",children:[n.jsx(s.Select,{defaultValue:o,value:o,onChange:Z(c),label:t("interactions.operation.switch_tab.view"),data:r.views.tabViewOptions,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500}),n.jsx(s.Select,{defaultValue:i,value:i,onChange:Z(d),label:t("interactions.operation.switch_tab.tab"),data:r.views.tabOptions(o),comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500})]})});async function Ih(e,t){const r=await t.operationData.getItem("config"),{viewID:a,tab:l}=r;window.dispatchEvent(new CustomEvent("switch_tab",{detail:{viewID:a,tab:l}}))}const hr=[dh,lh,hh,zh,_h,{displayName:"interactions.operation.switch_tab.label",id:"builtin:op:switch_tab",configRender:Dh,run:Ih},Ch];class Mh{constructor(t,r=hr){V(this,"attachments");this.operations=r;const a=async l=>{const{id:o,schemaRef:i}=await l.getItem(null);return{id:o,schemaRef:i,operationData:new Vt(l,"data")}};this.attachments=new pr(t,"__OPERATIONS",a)}async runOperation(t,r){const a=await this.attachments.getInstance(t);if(!a){console.warn(`Operation '${t}' is not defined`);return}const l=this.tryGetSchema(a.schemaRef);if(!l){console.warn(`Operation schema '${a.schemaRef}' is not defined`);return}await l.run(r,a)}tryGetSchema(t){return this.operations.find(r=>r.id===t)}async needMigration(){const r=(await this.attachments.list()).map(async a=>{const l={configData:a.operationData},o=this.tryGetSchema(a.schemaRef),i=o==null?void 0:o.migrator;return i&&await i.needMigration(l)});return(await Promise.all(r)).some(a=>a)}async runMigration(){const r=(await this.attachments.list()).map(async a=>{const l={configData:a.operationData},o=this.tryGetSchema(a.schemaRef),i=o==null?void 0:o.migrator;i&&await i.needMigration(l)&&await i.migrate(l)});await Promise.all(r)}async createOrGetOperation(t,r){var i;if(!this.getOperationSchemaList().some(c=>c.id===r.id))throw new Error(`Operation schema '${r.id}' is not defined`);const l=await this.attachments.getInstance(t);return!l||l.schemaRef!==r.id?await this.attachments.create(t,{id:t,schemaRef:r.id,data:((i=r.createDefaultConfig)==null?void 0:i.call(r))??{}}):l}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}const fl="__TRIGGERS";class Vh{constructor(t,r){V(this,"attachments");this.instance=t,this.component=r;const a=async l=>{const{id:o,schemaRef:i}=await l.getItem(null);return{id:o,schemaRef:i,triggerData:new Vt(l,"data")}};this.attachments=new pr(t,fl,a)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(fl,r=>{const a=y.values(r).map(l=>({id:y.get(l,"id"),schemaRef:y.get(l,"schemaRef"),config:Q.toJS(y.get(l,"data.config"))}));t(a)},{fireImmediately:!0})}async createOrGetTrigger(t,r,a={recreate:!1}){var c;if(!this.getTriggerSchemaList().some(d=>d.id===r.id))throw new Error(`Trigger schema '${r.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(t);return!o||a.recreate||o.schemaRef!==r.id?await this.attachments.create(t,{id:t,schemaRef:r.id,data:((c=r==null?void 0:r.createDefaultConfig)==null?void 0:c.call(r))||{}}):o}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(t){await this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}async getMigrationTasks(){const r=(await this.getTriggerList()).map(async a=>{const l=this.getTriggerSchemaList().find(c=>c.id===a.schemaRef),o=l==null?void 0:l.migrator,i={configData:a.triggerData};return o&&await o.needMigration(i)?()=>o.migrate(i):null});return Promise.all(r).then(a=>a.filter(l=>l))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(r=>r()))}}class bl{constructor(t,r,a){V(this,"operationManager");V(this,"triggerManager");V(this,"attachments");this.operationManager=new Mh(t,a),this.triggerManager=new Vh(t,r);const l=async o=>{const{id:i,triggerRef:c,operationRef:d}=await o.getItem(null);return{id:i,triggerRef:c,operationRef:d}};this.attachments=new pr(t,"__INTERACTIONS",l)}async addInteraction(t,r){const a=t.id,l=r.id,o=`[${a}]:[${l}]`;await this.attachments.create(o,{id:o,triggerRef:a,operationRef:l})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const r=await this.attachments.getInstance(t);if(!r)return;const{triggerRef:a,operationRef:l}=r;await this.getTriggerRefCount(a)<=1&&await this.triggerManager.removeTrigger(a),await this.getOperationRefCount(l)<=1&&await this.operationManager.removeOperation(l),await this.attachments.remove(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(a=>a.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(a=>a.triggerRef===t).length}async runInteraction(t,r){const l=(await this.getInteractionList()).filter(o=>o.triggerRef===t);for(let o of l)try{await this.operationManager.runOperation(o.operationRef,r)}catch(i){console.warn(`Failed to run operation '${o.operationRef}'`,i)}}}function Ph(e,t){const[r,a]=h.useState([]);return O.useAsyncEffect(async()=>{const l=await e.getInteractionList();a(l)},[t,e]),r}const Ah=T.observer(({item:e,manager:t,instance:r,sampleData:a,variables:l,onRemove:o})=>{const{triggerRef:i,operationRef:c}=e,d=Zp(t.triggerManager,r);if(O.useAsyncEffect(async()=>{await d.configTrigger(i,a)},[d,i,a]),d.isReady()){const u=[...d.triggerSchema.payload,...l];return n.jsxs(s.Group,{children:[n.jsx(eh,{model:d}),n.jsx(Kp,{instance:r,operationId:c,variables:u,operationManager:t.operationManager}),n.jsx(s.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:n.jsx(S.IconTrash,{size:16})})]})}return null}),$h=e=>{const{t}=x.useTranslation(),[r,a]=h.useState(0),{interactionManager:l,instance:o,sampleData:i,variables:c}=e,d=Ph(l,r),u=async()=>{const _=await l.triggerManager.createOrGetTrigger(ne.randomId(),l.triggerManager.getTriggerSchemaList()[0]),w=await l.operationManager.createOrGetOperation(ne.randomId(),l.operationManager.getOperationSchemaList()[0]);await l.addInteraction(_,w),a(m=>m+1)};async function p(_){await l.removeInteraction(_.id),a(w=>w+1)}const{data:f=0,loading:v}=O.useRequest(async()=>{try{return(await l.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return n.jsxs(s.Stack,{children:[n.jsx(s.LoadingOverlay,{visible:v}),f===0&&n.jsx(s.Alert,{icon:n.jsx(S.IconAlertCircle,{size:16}),title:t("interactions.unavailable"),color:"gray",children:t("interactions.unavailable_reason")}),d.map(_=>n.jsx(Ah,{onRemove:p,instance:o,sampleData:i,variables:c,item:_,manager:e.interactionManager},_.id)),n.jsx(s.Button,{style:{width:"fit-content"},onClick:()=>u(),disabled:f===0,children:t("interactions.add")})]})},Eh=()=>{const{panel:e,data:t}=fe(),r=e.viz,{vizManager:a}=h.useContext(rt),l=e.json,o=O.useCreation(()=>a.getOrCreateInstance(l),[a,l]),i=O.useCreation(()=>new bl(o,a.resolveComponent(r.type),hr),[o,r.type]);return h.useEffect(()=>o.instanceData.watchItem(null,y.throttle(c=>{e.viz.setConf(c)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:a,interactionManager:i,sampleData:t,variables:[]}},Bh=()=>{const e=Eh();return n.jsx($h,{...e})},yl={axisTick:{show:!0,alignWithLabel:!0,lineStyle:{width:2}},axisLine:{show:!0,lineStyle:{width:3}},splitLine:{show:!1},z:3};function Lh(e){return y.defaultsDeep({},e,yl)}const qh=Object.freeze(Object.defineProperty({__proto__:null,getXAxis:Lh,xAxis:yl},Symbol.toStringTag,{value:"Module"})),vl={axisTick:{show:!1},axisLine:{show:!1,lineStyle:{width:3}},splitLine:{show:!0,lineStyle:{type:"dashed"}}};function Oh(e){return y.defaultsDeep({},e,vl)}const Nh=Object.freeze(Object.defineProperty({__proto__:null,getYAxis:Oh,yAxis:vl},Symbol.toStringTag,{value:"Module"})),_l={confine:!0,appendToBody:!0};function Gh(e){return y.defaultsDeep({},e,_l)}const X={...qh,...Nh,...Object.freeze(Object.defineProperty({__proto__:null,getTooltip:Gh,tooltip:_l},Symbol.toStringTag,{value:"Module"}))};function Fh(e,t){const r=[],a=[];return{boxplotData:Object.entries(e).map(([o,i])=>{const c=i.map(z=>z[t]).sort((z,D)=>z-D),d=qt.quantile(c,.25)??0,u=qt.quantile(c,.5)??0,p=qt.quantile(c,.75)??0,f=p-d,v=d-1.5*f,_=p+1.5*f,w=Math.max(c[0],v),m=Math.min(y.last(c)??0,_);return i.filter(z=>{const D=z[t];return D<w||D>m}).forEach(z=>r.push([o,z[t],z])),i.filter(z=>{const D=z[t];return D>=w&&D<=m}).forEach(z=>a.push([o,z[t],z])),{name:o,min:w,q1:d,median:u,q3:p,max:m}}),outliersData:r,scatterData:a}}function jh(e,t){const{x_axis:r,y_axis:a}=e;if(!r.data_key||!a.data_key)return[];const l=P(r.data_key),o=P(a.data_key);if(l.queryID!==o.queryID)throw new Error("Please use the same query for X & Y axis");const i=y.groupBy(t[l.queryID],l.columnKey),{boxplotData:c,outliersData:d,scatterData:u}=Fh(i,o.columnKey);return[{source:c},{source:d},{source:u}]}function Qh(e){const t={top:35,left:20,right:15,bottom:25,containLabel:!0};return e.legend.orient==="vertical"&&(t.right=80),e.dataZoom.x_axis_slider&&(t.top=50),t}function Wh({config:e,seriesNames:t}){const r={...e.legend,data:[{name:t.Box,icon:"roundRect",itemStyle:{color:e.color}},{name:t.Scatter,icon:"circle",itemStyle:{color:"#ED6A45",opacity:.5}},{name:t.Outlier,icon:"circle",itemStyle:{color:"#ED6A45"}}]};return e.legend.orient==="horizontal"&&e.dataZoom.x_axis_slider&&(r.top=15),r}function Uh(e,t,r){const a=t.reduce((l,o)=>{const i=Je(o,r);return l[o.name]=$e(o,i),l},{});return e.map(l=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:l.name,yAxis:Number(a[l.variable_key])}],silent:!0,symbol:["none","triangle"],symbolRotate:90,symbolSize:[10,8],label:{formatter:function(){return jt(l.template,t,r)},position:"insideEndTop"}}}))}const gr=["max","q3","median","q1","min"],fr=[10,40];function br(e){return e.barLayout({barMinWidth:fr[0],barMaxWidth:fr[1],count:2})}function Kh(e,t,r){const{itemStyle:{color:a,borderColor:l,borderWidth:o}}=r,i=br(t),c=t.value(0),d=e.source[c],{min:u,q1:p,median:f,q3:v,max:_}=d,w={min:t.coord([c,u]),q1:t.coord([c,p]),median:t.coord([c,f]),q3:t.coord([c,v]),max:t.coord([c,_])},m={left:i[1].offset,center:(i[1].offset+i[1].width)/2,right:i[1].width},k={type:"group",children:[]},z=[{x1:w.max[0]+m.left,x2:w.max[0]+m.right,y1:w.max[1],y2:w.max[1]},{x1:w.median[0]+m.left,x2:w.median[0]+m.right,y1:w.median[1],y2:w.median[1]},{x1:w.min[0]+m.left,x2:w.min[0]+m.right,y1:w.min[1],y2:w.min[1]},{x1:w.min[0]+m.center,x2:w.min[0]+m.center,y1:w.min[1],y2:w.q1[1]},{x1:w.max[0]+m.center,x2:w.max[0]+m.center,y1:w.max[1],y2:w.q3[1]}],D={stroke:l,lineWidth:o};return z.forEach(I=>{k.children.push({type:"line",shape:I,style:D})}),k.children.push({type:"rect",shape:{x:w.q1[0]+m.left,y:w.q1[1],width:m.right-m.left,height:w.q3[1]-w.q1[1]},style:{fill:a,stroke:l,lineWidth:o}}),k}function Yh(e,t){const{color:r}=t,a={name:"Box",type:"custom",itemStyle:{color:r,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:fr,datasetIndex:0};return a.renderItem=(l,o)=>Kh(e,o,a),a}function Xh(e){const t=br(e),r=t[0].width,a=e.value(0),l=e.value(1),[o,i]=e.coord([a,l]),d=o+t[0].offset+Math.random()*r;return{type:"circle",transition:["shape"],x:d,y:i,shape:{cx:0,cy:0,r:2},style:{fill:e.visual("color"),opacity:.5}}}function Zh(){const e={name:"Scatter",type:"custom",itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:2};return e.renderItem=(t,r)=>Xh(r),e}function Jh(e,t){const r=br(e),a=r[0].width,l=e.value(0),o=e.value(1),[i,c]=e.coord([l,o]),u=i+r[0].offset+Math.random()*a;return{type:"circle",transition:["shape"],x:u,y:c,shape:{cx:0,cy:0,r:3},style:{fill:e.visual("color")}}}function Hh(){const e={name:"Outlier",type:"custom",itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:1};return e.renderItem=(t,r)=>Jh(r),e}function Rh(e,t){const r=t[0],a=Yh(r,e),l=Zh(),o=Hh();return[{name:"Placeholder Box",type:"boxplot",ignore:!0,silent:!0,itemStyle:{color:"none",borderColor:"none",opacity:0},boxWidth:[20,80],datasetIndex:0,encode:{y:gr,x:"name",itemName:["name"],tooltip:gr}},{name:"Outlier",type:"scatter",symbolSize:7,itemStyle:{color:"transparent"},ignore:!0,silent:!0,emphasis:{disabled:!0},datasetIndex:1},a,l,o]}const eg=(e,t)=>{const r=gr.map(o=>`
70
70
  <tr>
71
71
  <th style="text-align: right; padding: 0 1em;">${y.capitalize(o)}</th>
72
72
  <td style="text-align: left; padding: 0 1em;">
@@ -81,19 +81,19 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
81
81
  ${r.join("")}
82
82
  </tbody>
83
83
  </table>
84
- `},Hh=e=>Y(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function vl(e,t){const r=e.tooltip.metrics.reduce((a,{unit:l,name:o})=>(l.show_in_tooltip&&(a[o]=l.text),a),{});return e.tooltip.metrics.map(a=>{const l=A(a.data_key),o=r[a.name]??"";return`
84
+ `},tg=e=>Y(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function xl(e,t){const r=e.tooltip.metrics.reduce((a,{unit:l,name:o})=>(l.show_in_tooltip&&(a[o]=l.text),a),{});return e.tooltip.metrics.map(a=>{const l=P(a.data_key),o=r[a.name]??"";return`
85
85
  <tr>
86
86
  <th style="text-align: right; padding: 0 1em;">${a.name}</th>
87
- <td style="text-align: left; padding: 0 2px 0 1em;">${Hh(t[l.columnKey])}</td>
87
+ <td style="text-align: left; padding: 0 2px 0 1em;">${tg(t[l.columnKey])}</td>
88
88
  <th style="text-align: left; padding: 0;">
89
89
  ${o??""}
90
90
  </th>
91
- </tr>`})}function Rh(e,t){const r=Ee(e.x_axis.axisLabel.overflow.in_tooltip),a=e.y_axis.unit.show_in_tooltip?e.y_axis.unit.text:"",l=[`<tr>
91
+ </tr>`})}function ng(e,t){const r=Ee(e.x_axis.axisLabel.overflow.in_tooltip),a=e.y_axis.unit.show_in_tooltip?e.y_axis.unit.text:"",l=[`<tr>
92
92
  <th style="text-align: right; padding: 0 1em;">${e.y_axis.name}</th>
93
93
  <td style="text-align: left; padding: 0 2px 0 1em;">${t[1]}</td>
94
94
  <th style="text-align: left; padding: 0;">${a??""}</th>
95
95
  </tr>
96
- `],o=vl(e,t[2]);return l.push(...o),`
96
+ `],o=xl(e,t[2]);return l.push(...o),`
97
97
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
98
98
  <div style="${r}">${t[0]}</div>
99
99
  </div>
@@ -102,12 +102,12 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
102
102
  ${l.join("")}
103
103
  </tbody>
104
104
  </table>
105
- `}function eg(e,t){const r=e.y_axis.unit.show_in_tooltip?e.y_axis.unit.text:"",a=Ee(e.x_axis.axisLabel.overflow.in_tooltip),l=[`<tr>
105
+ `}function rg(e,t){const r=e.y_axis.unit.show_in_tooltip?e.y_axis.unit.text:"",a=Ee(e.x_axis.axisLabel.overflow.in_tooltip),l=[`<tr>
106
106
  <th style="text-align: right; padding: 0 1em;">${e.y_axis.name}</th>
107
107
  <td style="text-align: left; padding: 0 2px 0 1em;">${t[1]}</td>
108
108
  <th style="text-align: left; padding: 0;">${r??""}</th>
109
109
  </tr>
110
- `],o=vl(e,t[2]);return l.push(...o),`
110
+ `],o=xl(e,t[2]);return l.push(...o),`
111
111
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
112
112
  <div style="${a}">${t[0]}</div>
113
113
  </div>
@@ -116,7 +116,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
116
116
  ${l.join("")}
117
117
  </tbody>
118
118
  </table>
119
- `}const tg=(e,t)=>r=>{const{seriesName:a,value:l}=r;switch(a){case t.Box:return Jh(e,l);case t.Outlier:return Rh(e,l);case t.Scatter:return eg(e,l)}};function ng({config:e,seriesNames:t}){return X.getTooltip({trigger:"item",formatter:tg(e,t)})}function on(e,t){t||(t="none");const r=[];return e.x_axis_scroll&&r.push({type:"inside",xAxisIndex:[0],filterMode:t,minSpan:1}),e.y_axis_scroll&&r.push({type:"inside",yAxisIndex:[0],filterMode:t,minSpan:1}),e.x_axis_slider&&r.push({type:"slider",xAxisIndex:[0],filterMode:t,bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),r}function rg({min:e,max:t}){if(e<=110)return Math.min(0,e);if(e<=200)return 100;const r=Ne.floor(Ne.log10(e)),a=Math.pow(10,r),l=Math.pow(10,r-1);return e/a<=2?y.round(e,-1*(r-1))-l:y.round(e,-1*r)-a}function ag(e){return{Box:e("viz.boxplot.box"),Scatter:e("viz.boxplot.scatter"),Outlier:e("viz.boxplot.outlier")}}function sg({config:e,data:t,variables:r,t:a}){const{x_axis:l,y_axis:o,reference_lines:i}=e,c=Nh(e,t),d=Be(l.axisLabel.overflow.on_axis),u=ag(a),p=Zh(e,c).map(f=>({...f,name:y.get(u,f.name,f.name)}));return{dataZoom:on(e.dataZoom,"filter"),grid:Gh(e),dataset:c,legend:Fh({config:e,seriesNames:u}),tooltip:ng({config:e,seriesNames:u}),xAxis:[X.getXAxis({type:"category",name:l.name,nameGap:25,nameLocation:"center",nameTextStyle:{align:"center"},axisLabel:{...l.axisLabel,...d,formatter:xe(l.axisLabel.formatter)}})],yAxis:[X.getYAxis({name:o.name,minInterval:1,axisLabel:{formatter:function(f){return Y(f,o.label_formatter)}},min:rg})],series:[...p,...jh(i,r,t)]}}function lg({context:e,instance:t}){const{t:r}=x.useTranslation(),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=e.data,{width:i,height:c}=e.viewport,d=y.defaults({},a,dr),u=Me({vizManager:e.vizManager,instance:t}),p=Ie(u.triggerManager,dl.id),f=mt(o,d.x_axis.data_key),v=h.useCallback(z=>{const D=y.get(f,z.name,{error:"rowData is not found"});p.forEach(I=>{u.runInteraction(I.id,{...z,rowData:D})})},[f,p,u]),_=h.useRef(null),w=h.useCallback(()=>{var D;const z=(D=_.current)==null?void 0:D.getEchartsInstance();z&&de(t,z.getOption())},[]),m=h.useMemo(()=>({click:v,finished:w}),[v,w]),k=h.useMemo(()=>sg({config:d,data:o,variables:l,t:r}),[d,o,l,r]);return!a||!i||!c?null:n.jsx(_e,{width:i,height:c,children:n.jsx(he,{echarts:ce,option:k,ref:_,style:Ot(i,c),onEvents:m,notMerge:!0,theme:"merico-light"})})}function ae({canSubmit:e,buttonRef:t}){const{t:r}=x.useTranslation();return n.jsxs(s.Group,{justify:"flex-start",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n.jsx(s.Text,{size:"sm",children:r("viz.viz_config_banner")}),n.jsx(s.ActionIcon,{ref:t,type:"submit",mr:5,variant:"filled",color:"blue",disabled:!e,children:n.jsx(S.IconDeviceFloppy,{size:20})})]})}const yr=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>[{label:o("common.align.horizontal.left"),value:"left"},{label:o("common.align.horizontal.center"),value:"center"},{label:o("common.align.horizontal.right"),value:"right"}],[i.language]);return n.jsx(s.Select,{ref:l,label:e??o("common.align.horizontal.label"),data:c,value:t,onChange:Z(r),sx:a})}),_l=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>[{label:o("common.align.vertical.top"),value:"top"},{label:o("common.align.vertical.center"),value:"center"},{label:o("common.align.vertical.bottom"),value:"bottom"}],[i.language]);return n.jsx(s.Select,{ref:l,label:e??o("common.align.vertical.label"),data:c,value:t,onChange:Z(r),sx:a})}),xl=dt.createStyles(()=>({palette:{display:"flex",flexFlow:"row nowrap"},paletteItem:{".palette-value":{height:24,overflow:"visible",width:36},".palette-item":{width:"36px",height:36*.618,cursor:"pointer",transition:"transform 100ms ease-in-out","&:hover":{boxShadow:"0 0 0 2px var(--shadow-color)",borderRadius:2,transform:"scale(1.2)"}}}})),og=[{from:0,to:0},{from:100,to:100}];class ig{constructor(){P(this,"steps",new Map);P(this,"interpolation");P(this,"onChange");Q.makeAutoObservable(this,{steps:Q.observable},{deep:!1}),Q.reaction(()=>Q.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(t){for(const r of t)this.steps.set(r.to,r.from)}notifyStepChange(){var t;(t=this.onChange)==null||t.call(this,Array.from(this.steps.entries()).map(([r,a])=>({to:r,from:a})).sort((r,a)=>r.to-a.to||r.from-a.from))}fromProps(t){t.steps.length<2?this.setSteps(og):this.setSteps(t.steps),this.interpolation=t.interpolation,this.onChange=t.onChange}changeStep(t,r){t==null?this.steps.delete(r):this.steps.set(r,t)}getStepFromValue(t){return this.steps.get(t)}}function wl(e){if(typeof e=="number")return String(e)}function cg(e){const{t}=x.useTranslation(),{onChange:r,color:a,index:l,value:o}=e,{classes:i}=xl(),[c,d]=h.useState(wl(o)),[u,{setTrue:p,setFalse:f}]=O.useBoolean(!1),v=l%2===1,_=v&&o!=null,w=!v&&o!=null,m=`map ${o} to color ${l}`,k=()=>{d(wl(o)),f()},z=()=>{f(),r==null||r(Number(c))},D=()=>{f(),r==null||r(null)},I=Y(o??null,{output:"number",mantissa:10,trimMantissa:!0,average:!0,absolute:!1}),L=!c||Number.isNaN(Number(c));return n.jsxs("div",{"data-testid":`palette-item-${l}`,className:i.paletteItem,children:[n.jsx(s.Text,{title:m,style:{opacity:_?1:0},c:"dimmed",size:"sm",className:"palette-value--up palette-value",children:I}),n.jsxs(s.Popover,{width:240,trapFocus:!0,opened:u,onClose:f,zIndex:340,withinPortal:!0,children:[n.jsx(s.Popover.Target,{children:n.jsx("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:p,style:{"--shadow-color":qe(a).alpha(.5).hex(),backgroundColor:a}})}),n.jsxs(s.Popover.Dropdown,{children:[n.jsx(s.Tooltip,{withinPortal:!0,zIndex:340,label:t("common.actions.close"),children:n.jsx(s.CloseButton,{"data-testid":"palette-item-cancel",size:"sm",color:"gray",onClick:k,style:{position:"absolute",top:"0.5em",right:"0.8em"}})}),n.jsxs(s.Stack,{children:[n.jsx(s.TextInput,{size:"xs",label:t("style.color.interpolation.palette.mapping.value_input_label"),value:c,onChange:E=>{const K=E.currentTarget.value;d(K)},error:c&&L}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{variant:"light",color:"red",size:"xs",onClick:D,leftSection:n.jsx(S.IconTrash,{size:16}),children:t("common.actions.delete")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),"data-testid":"palette-item-ok",size:"xs",onClick:z,disabled:L,children:t("common.actions.save")})]})]})]})]}),n.jsx(s.Text,{title:m,style:{opacity:w?1:0},c:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:I})]})}const dg=T.observer(({model:e})=>{const{classes:t}=xl(),r=y.range(0,13,1).map(a=>100/12*a).map(a=>[e.interpolation.getColor(a),a]);return n.jsx("div",{className:t.palette,children:r.map(([a,l],o)=>n.jsx(cg,{index:o,color:a,value:e.getStepFromValue(l),onChange:i=>e.changeStep(i,l)},a))})}),ug=T.observer(function(t){const r=O.useCreation(()=>new ig,[]);return h.useEffect(()=>{r.fromProps(t)}),r.interpolation==null?null:n.jsx(dg,{model:r})}),pg=e=>{const{t,i18n:r}=x.useTranslation(),{value:a,onChange:l,colorManager:o}=e,i=o.getColorInterpolations(),[c,d]=h.useState(a),u=o.decodeInterpolation(c.interpolation)||i[0],[p,{setTrue:f,setFalse:v}]=O.useBoolean(),_=h.useMemo(()=>{const D=y.groupBy(i,"category");return Object.entries(D).map(([I,L])=>({group:t(`style.color.interpolation.palette.category.${I}`),items:L.map(E=>({label:t(E.displayName),value:o.encodeColor(E)}))}))},[r.language]);function w(D){D&&d(I=>({...I,interpolation:D}))}const m=()=>{v(),l==null||l(Q.toJS(c))};function k(D){d(I=>({...I,steps:D}))}const z=()=>{v(),d(a)};return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{variant:"outline",onClick:f,children:t(u==null?void 0:u.displayName)}),n.jsx(s.Modal,{size:508,title:t("style.color.interpolation.setup"),opened:p,onClose:v,zIndex:320,children:p&&n.jsxs(s.Stack,{"data-testid":"color-interpolation-modal",children:[n.jsx(s.Select,{label:t("style.color.interpolation.palette.label"),value:c.interpolation,data:_,onChange:w,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500}),n.jsx(ug,{steps:c.steps,interpolation:u,onChange:k}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:z,variant:"subtle",children:t("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:m,children:t("common.actions.save")})]})]})})]})},hg=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>[{label:o("style.color.type.static"),value:"static"},{label:o("style.color.type.interpolation"),value:"interpolation"},{label:o("style.color.type.none"),value:"none"}],[i.language]);return n.jsx(s.Select,{ref:l,label:e??o("style.color.type.label"),data:c,value:t,onChange:Z(r),sx:a})}),gg=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>[{label:o("style.flex.justify_content.left"),value:"left"},{label:o("style.flex.justify_content.center"),value:"center"},{label:o("style.flex.justify_content.right"),value:"right"},{label:o("style.flex.justify_content.space_between"),value:"space-between"},{label:o("style.flex.justify_content.space_around"),value:"space-around"},{label:o("style.flex.justify_content.space_evenly"),value:"space-evenly"}],[i.language]);return n.jsx(s.Select,{ref:l,label:e??o("style.flex.justify_content.label"),data:c,value:t,onChange:Z(r),sx:a})}),fg=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>[{label:o("style.flex.align_items.start"),value:"start"},{label:o("style.flex.align_items.center"),value:"center"},{label:o("style.flex.align_items.end"),value:"end"},{label:o("style.flex.align_items.stretch"),value:"stretch"}],[i.language]);return n.jsx(s.Select,{ref:l,label:e??o("style.flex.align_items.label"),data:c,value:t,onChange:Z(r),sx:a})}),bg=({value:e,index:t,children:r})=>{const[a,{setTrue:l,setFalse:o}]=O.useBoolean(!1),{ref:i,handleRef:c}=Ln.useSortable({id:e,index:t});return n.jsx(s.Tabs.Tab,{ref:i,value:e,leftSection:n.jsx(S.IconGripHorizontal,{size:14,color:a||t===0?"rgb(34, 139, 230)":"transparent"}),onMouseEnter:l,onMouseLeave:o,children:r})},yg=({fieldArray:e,add:t,addButtonText:r,renderTabName:a,controlledFields:l})=>{const o=i=>{const{source:c,target:d}=i.operation,u=l.findIndex(f=>f.id===c.id),p=d.index;e.move(u,p)};return n.jsxs(s.Tabs.List,{children:[n.jsx(Bn.DragDropProvider,{onDragEnd:o,children:l.map((i,c)=>n.jsx(bg,{value:i.id,index:c,children:a(i,c)},i.id))}),n.jsx(s.Tabs.Tab,{onClick:t,value:"add",children:n.jsx(s.Tooltip,{label:r,children:n.jsx(s.Center,{children:n.jsx(S.IconPlus,{size:18,color:"#228be6"})})})})]})},vg={tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},H=({control:e,watch:t,name:r,getItem:a,children:l,addButtonText:o,deleteButtonText:i,renderTabName:c,deleteDisalbed:d})=>{var L;const u=b.useFieldArray({control:e,name:r}),{fields:p,append:f,remove:v}=u,_=t(r),w=p.map((E,K)=>({...E,..._[K]})),m=((L=y.last(w))==null?void 0:L.id)??null,[k,z]=h.useState(m),D=E=>{E!=="add"&&z(E)};h.useEffect(()=>{z(E=>m===E?E:m)},[m]);const I=()=>{const E=a();u.append(E),z(E.id)};return n.jsxs(s.Tabs,{value:k,onChange:D,styles:vg,children:[n.jsx(yg,{fieldArray:u,add:I,addButtonText:o,renderTabName:c,controlledFields:w}),w.map((E,K)=>n.jsx(s.Tabs.Panel,{value:E.id,children:n.jsxs(s.Stack,{children:[l({field:E,index:K}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed"}),n.jsx(s.Button,{leftSection:n.jsx(S.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>v(K),sx:{top:15,right:5},disabled:d==null?void 0:d({field:E,index:K,fields:w}),children:i})]})},E.id))]})},cn=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a}=x.useTranslation(),l=o=>i=>{t({...e,[o]:i})};return n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{variant:"dashed",label:a("chart.zooming.scroll.label"),labelPosition:"center"}),n.jsxs(s.Group,{children:[n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.zooming.scroll.x_axis"),checked:e.x_axis_scroll,onChange:o=>l("x_axis_scroll")(o.currentTarget.checked)})}),n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.zooming.scroll.y_axis"),checked:e.y_axis_scroll,onChange:o=>l("y_axis_scroll")(o.currentTarget.checked)})})]}),n.jsx(s.Divider,{variant:"dashed",label:a("chart.zooming.slider.label"),labelPosition:"center"}),n.jsxs(s.Group,{children:[n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.zooming.slider.x_axis"),checked:e.x_axis_slider,onChange:o=>l("x_axis_slider")(o.currentTarget.checked)})}),n.jsx(s.Tooltip,{label:a("chart.zooming.slider.y_axis_disabled"),children:n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.zooming.slider.y_axis"),disabled:!e.y_axis_slider,checked:e.y_axis_slider,onChange:o=>l("y_axis_slider")(o.currentTarget.checked)})})})]})]})}),gt=h.forwardRef(({label:e,value:t,onChange:r,sx:a={},disabled:l},o)=>{const{t:i,i18n:c}=x.useTranslation(),d=h.useMemo(()=>[{label:i("chart.orientation.horizontal"),value:"horizontal"},{label:i("chart.orientation.vertical"),value:"vertical"}],[c.language]);return n.jsx(s.Select,{ref:o,label:e??i("chart.orientation.label"),data:d,value:t,onChange:Z(r),sx:a,disabled:l})}),_g=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=t("legend"),l=(o,i)=>{const c={...a,orient:o};o==="horizontal"?(c.top="0",c.left="auto",c.right="10",c.bottom="auto"):(c.top="10",c.left="auto",c.right="0",c.bottom="auto"),i(c)};return n.jsxs(s.Stack,{children:[n.jsx(s.Group,{grow:!0,wrap:"nowrap",mt:20,children:n.jsx(b.Controller,{name:"legend.show",control:e,render:({field:o})=>n.jsx(s.Switch,{label:r("chart.legend.show_legend"),sx:{flex:1},checked:o.value,onChange:i=>o.onChange(i.currentTarget.checked)})})}),n.jsx(s.Group,{children:n.jsx(b.Controller,{name:"legend",control:e,render:({field:o})=>n.jsx(gt,{sx:{flex:1},value:o.value.orient,onChange:i=>{l(i,o.onChange)},disabled:!a.show})})})]})};function xg({control:e,index:t,variableOptions:r}){const{t:a}=x.useTranslation();return n.jsxs(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:l})=>n.jsx(s.TextInput,{label:a("common.name"),placeholder:a("chart.reference_line.name_placeholder"),required:!0,sx:{flex:1},...l})}),n.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:l})=>n.jsx(s.Select,{label:a("common.value"),required:!0,data:r,sx:{flex:1},...l})})]}),n.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:l})=>n.jsx(s.TextInput,{label:a("chart.content_template.label"),placeholder:a("chart.content_template.placeholder"),required:!0,sx:{flex:1},...l})})]})}function wg({control:e,watch:t,variables:r}){const{t:a}=x.useTranslation(),l=()=>({name:"",template:"",variable_key:""}),o=h.useMemo(()=>r.map(c=>({label:c.name,value:c.name})),[r]),i=(c,d)=>{const u=c.name.trim();return u||d+1};return n.jsx(H,{control:e,watch:t,name:"reference_lines",getItem:l,addButtonText:a("chart.reference_line.add"),deleteButtonText:a("chart.reference_line.delete"),renderTabName:i,children:({field:c,index:d})=>n.jsx(xg,{control:e,index:d,variableOptions:o})})}const mg=({control:e,index:t})=>{const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("chart.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.unit`,control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})})]})},Cg=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>({id:Date.now().toString(),data_key:"",name:"",unit:U()}),l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:r("chart.tooltip.additional_metrics.description")})]}),n.jsx(H,{control:e,watch:t,name:"tooltip.metrics",getItem:a,addButtonText:r("chart.tooltip.additional_metrics.add"),deleteButtonText:r("chart.tooltip.additional_metrics.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(mg,{control:e,index:i})})]})};function Sg({control:e,watch:t}){return n.jsx(s.Stack,{children:n.jsx(Cg,{control:e,watch:t})})}const nt=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o}=x.useTranslation();return n.jsx(s.NumberInput,{ref:l,label:e??o("chart.rotate"),hideControls:!0,min:-90,max:90,rightSection:n.jsx(s.Text,{size:"xs",c:"dimmed",children:o("chart.degree")}),sx:a,styles:{section:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},value:t,onChange:i=>{typeof i!="string"&&r(i)}})}),Tg=({control:e,watch:t})=>{const{t:r}=x.useTranslation();return t(["x_axis"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.x_axis.x_axis_name"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("chart.x_axis.x_axis_data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(s.Divider,{mb:-15,label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:a})=>n.jsx(nt,{sx:{width:"48%"},...a})}),n.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(Qe,{...a})})]}),n.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(We,{...a})})]})},vr={root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}},kg=["123456789","1234","1234.56789","1.234","0.123456789","-0.123456789"];function zg({format:e}){const{t}=x.useTranslation(),[r,{toggle:a}]=te.useDisclosure(!1);return n.jsxs(s.Box,{children:[n.jsx(s.Button,{variant:"subtle",w:"100%",size:"compact-sm",onClick:a,leftSection:r?n.jsx(S.IconChevronUp,{size:14}):n.jsx(S.IconChevronDown,{size:14}),children:t(r?"numbro.format.preview.close":"numbro.format.preview.open")}),n.jsx(s.Collapse,{in:r,children:r&&n.jsxs(s.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:t("numbro.format.preview.input")}),n.jsx(s.Table.Th,{children:t("numbro.format.preview.output")})]})}),n.jsx(s.Table.Tbody,{children:kg.map(l=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:l}),n.jsx(s.Table.Td,{children:n.jsx(ne,{children:Y(l,e)})})]},l))})]})})]})}function Dg({value:e,onChange:t},r){const{t:a}=x.useTranslation(),l=u=>{t({...e,output:u})},o=u=>{if(typeof u=="string")return;const p=u===0?!1:e.trimMantissa;t({...e,mantissa:u,trimMantissa:p})},i=u=>{t({...e,trimMantissa:u.currentTarget.checked})},c=u=>{t({...e,average:u.currentTarget.checked})},d=u=>{const p={...e,absolute:u.currentTarget.checked};t(p)};return n.jsxs(s.Stack,{ref:r,children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.Select,{label:a("numbro.format.label"),data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:Z(l),sx:{flexGrow:1}}),n.jsx(s.Switch,{label:n.jsxs(s.Stack,{gap:0,children:[n.jsx(s.Text,{size:"sm",children:a("numbro.format.absolute")}),n.jsx(s.Text,{size:"12px",c:"gray",children:a("numbro.format.absolute_description")})]}),checked:e.absolute,onChange:d,sx:{flexGrow:1},styles:vr}),n.jsx(s.Switch,{label:n.jsxs(s.Stack,{gap:0,children:[n.jsx(s.Text,{size:"sm",children:a("numbro.format.abbreviation")}),n.jsx(s.Text,{size:"12px",c:"gray",children:a("numbro.format.abbreviation_description")})]}),checked:e.average,onChange:c,disabled:e.output!=="number",sx:{flexGrow:1},styles:vr})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.NumberInput,{label:a("numbro.format.mantissa"),defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:o}),n.jsx(s.Switch,{label:n.jsxs(s.Stack,{gap:0,children:[n.jsx(s.Text,{size:"sm",children:a("numbro.format.trim_mantissa")}),n.jsx(s.Text,{size:"12px",c:"gray",children:a("numbro.format.trim_mantissa_description")})]}),checked:e.trimMantissa,onChange:i,disabled:e.mantissa===0,styles:vr}),n.jsx(s.Box,{})]}),n.jsx(zg,{format:e})]})}const Le=h.forwardRef(Dg),Ig=({control:e,watch:t})=>{const{t:r}=x.useTranslation();return t(["y_axis"]),n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.y_axis.y_axis_name"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("chart.y_axis.y_axis_data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:"y_axis.unit",control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mt:10,mb:-15,variant:"dashed",label:r("chart.axis.section_title.label_format"),labelPosition:"center"}),n.jsx(b.Controller,{name:"y_axis.label_formatter",control:e,render:({field:a})=>n.jsx(Le,{...a})})]})]})};function Mg({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},r,dr),[r]),{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=b.useForm({defaultValues:o});return h.useEffect(()=>{p(o)},[o]),d(["x_axis","y_axis","reference_lines","color","dataZoom"]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:c(a),children:[n.jsx(ae,{canSubmit:u.isDirty}),n.jsxs(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axis",children:t("chart.x_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Y Axis",children:t("chart.y_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Legend",children:t("chart.legend.label")}),n.jsx(s.Tabs.Tab,{value:"Tooltip",children:t("chart.tooltip.label")}),n.jsx(s.Tabs.Tab,{value:"Style",children:t("chart.style.label")}),n.jsx(s.Tabs.Tab,{value:"Reference Lines",children:t("chart.reference_line.labels")}),n.jsx(s.Tabs.Tab,{value:"Zooming",children:t("chart.zooming.label")})]}),n.jsx(s.Tabs.Panel,{value:"X Axis",children:n.jsx(Tg,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Y Axis",children:n.jsx(Ig,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Legend",children:n.jsx(_g,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Tooltip",children:n.jsx(Sg,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Style",children:n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:"color",control:i,render:({field:f})=>n.jsx(ye,{label:t("chart.color.label"),...f})})})}),n.jsx(s.Tabs.Panel,{value:"Reference Lines",children:n.jsx(wg,{variables:l,control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Zooming",children:n.jsx(b.Controller,{name:"dataZoom",control:i,render:({field:f})=>n.jsx(cn,{...f})})})]})]})})}function Ag(e){return y.omit(e,"variables")}function Pg(e){const{label_formatter:t=le,...r}=e.y_axis;return{...e,y_axis:{...r,label_formatter:t}}}function Vg(e){const t={rotate:0,formatter:fe()},{axisLabel:r=t,...a}=e.x_axis;return{...e,x_axis:{...a,axisLabel:r}}}function $g(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(t,e)}function Eg(e){delete e.config;const{x_axis:t,tooltip:r}=e.x_axis.axisLabel.overflow,a={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:r}}}};return y.defaultsDeep(a,e)}function Bg(e){const t={tooltip:{metrics:[]}};return y.defaultsDeep(t,e)}function Lg(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{x_axis:l,y_axis:o,tooltip:i,...c}=e;return{...c,x_axis:{...l,data_key:a(l.data_key)},y_axis:{...o,data_key:a(o.data_key)},tooltip:{...i,metrics:i.metrics.map(d=>({...d,data_key:a(d.data_key)}))}}}catch(r){throw console.error("[Migration failed]",r),r}}function qg(e){const t={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return y.defaultsDeep(t,e)}function Og(e){const{dataZoom:t,...r}=e;return{...r,dataZoom:t??cl()}}function Ng(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??U()}))}}}function Gg(e){const{y_axis:t}=e;return{...e,y_axis:{...t,unit:t.unit??U()}}}class Fg extends ee{constructor(){super(...arguments);P(this,"VERSION",12)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,(r,{panelModel:a})=>{const{config:l}=r;return(l.variables||[]).forEach(i=>{a.variables.find(c=>c.name===i.name)||a.addVariable(i)}),{...r,version:2,config:Ag(l)}}),this.version(3,r=>{const{config:a}=r;return{...r,version:3,config:Pg(a)}}),this.version(4,r=>{const{config:a}=r;return{...r,version:4,config:Vg(a)}}),this.version(5,r=>{const{config:a}=r;return{...r,version:5,config:$g(a)}}),this.version(6,r=>{const{config:a}=r;return{...r,version:6,config:Eg(a)}}),this.version(7,r=>{const{config:a}=r;return{...r,version:7,config:Bg(a)}}),this.version(8,(r,a)=>{const{config:l}=r;return{...r,version:8,config:Lg(l,a)}}),this.version(9,r=>{const{config:a}=r;return{...r,version:9,config:qg(a)}}),this.version(10,r=>{const{config:a}=r;return{...r,version:10,config:Og(a)}}),this.version(11,r=>{const{config:a}=r;return{...r,version:11,config:Ng(a)}}),this.version(12,r=>{const{config:a}=r;return{...r,version:12,config:Gg(a)}})}}const jg={displayName:"viz.boxplot.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new Fg,name:"boxplot",viewRender:lg,configRender:Mg,createConfig(){return{version:12,config:y.cloneDeep(dr)}},triggers:[dl],translation:Lp},ml={id:"builtin:button:click-button",displayName:"viz.button.click.label",nameRender:Wg,configRender:Qg,payload:[]};function Qg(e){return n.jsx(n.Fragment,{})}function Wg(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.button.click.label")})}const _r={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},Ug={left:"flex-start",center:"center",right:"flex-end"},Yg={top:"flex-start",center:"center",bottom:"flex-end"},Kg=T.observer(({context:e,instance:t})=>{const r=Me({vizManager:e.vizManager,instance:t}),a=Ie(r.triggerManager,ml.id),l=J(),{value:o}=B(e.instanceData,"config"),i=h.useMemo(()=>y.defaultsDeep({},o,_r),[o]),{content:c,horizontal_align:d,vertical_align:u,compact:p,size:f,...v}=i,{width:_,height:w}=e.viewport,m=l.payloadForSQL,k=()=>{a.forEach(D=>{r.runInteraction(D.id,{})})},z=p?`compact-${f}`:f;return n.jsx(s.Center,{sx:{width:_,height:w,justifyContent:Ug[d],alignItems:Yg[u]},children:n.jsx(s.Button,{size:z,...v,onClick:k,children:y.template(c)(m)})})}),Xg=({value:e,onChange:t,label:r})=>{const a=s.useMantineTheme(),l=h.useCallback(i=>()=>t(i),[t]),o=i=>e===i;return n.jsxs(s.Stack,{gap:2,children:[n.jsx(s.Text,{size:"14px",fw:500,children:r}),n.jsx(s.Group,{justify:"flex-start",gap:"xs",children:Object.keys(a.colors).map(i=>{const c=a.colors[i][6];return n.jsx(s.ColorSwatch,{color:c,onClick:l(i),radius:4,size:26,sx:{cursor:"pointer"},children:o(i)&&n.jsx(s.CheckIcon,{width:10,color:"white"})},i)})})]})},Zg=["xs","sm","md","lg","xl"],xr=h.forwardRef(({label:e,value:t,onChange:r,sx:a,disabled:l},o)=>{const{t:i,i18n:c}=x.useTranslation(),d=h.useMemo(()=>Zg.map(u=>({label:i(`style.size.${u}`),value:u})),[c.language]);return n.jsx(s.Select,{ref:o,data:d,label:e,value:t,onChange:Z(r),sx:a,disabled:!0})}),Jg=[{label:"Filled",value:"filled"},{label:"Outline",value:"outline"},{label:"Light",value:"light"},{label:"White",value:"white"},{label:"Default",value:"default"},{label:"Subtle",value:"subtle"},{label:"Gradient",value:"gradient",disabled:!0}];function Hg({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaultsDeep({},t,_r),[t]),l=a;h.useEffect(()=>{!y.isEqual(a,l)&&(console.log("config malformed, resetting to defaults",a,l),r(l))},[a,l]);const{control:o,handleSubmit:i,watch:c,formState:d,reset:u}=b.useForm({defaultValues:l});return h.useEffect(()=>{u(l)},[l]),c(["content","variant","color","size","compact","horizontal_align","vertical_align"]),n.jsxs("form",{onSubmit:i(r),children:[n.jsx(ae,{canSubmit:d.isDirty}),n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{control:o,name:"content",render:({field:p})=>n.jsx(s.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...p,required:!0})}),n.jsx(s.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(b.Controller,{control:o,name:"variant",render:({field:p})=>n.jsx(s.Select,{label:"Variant",data:Jg,...p})}),n.jsx(b.Controller,{control:o,name:"color",render:({field:p})=>n.jsx(Xg,{label:"Theme",...p})})]}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(b.Controller,{control:o,name:"size",render:({field:p})=>n.jsx(xr,{label:"Size",...p})}),n.jsx(b.Controller,{control:o,name:"compact",render:({field:p})=>n.jsx(s.Checkbox,{label:"Compact",checked:p.value,onChange:f=>p.onChange(f.currentTarget.checked),mt:26})})]}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(b.Controller,{control:o,name:"horizontal_align",render:({field:p})=>n.jsx(yr,{...p})}),n.jsx(b.Controller,{control:o,name:"vertical_align",render:({field:p})=>n.jsx(_l,{...p})})]})]})]})}const Rg=[{lang:"en",resources:{button:{viz_name:"Button",click:{label:"Click this button"}}}},{lang:"zh",resources:{button:{viz_name:"按钮",click:{label:"点击此按钮"}}}}];class ef extends ee{constructor(){super(...arguments);P(this,"VERSION",2)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>{const{horizontal_align:a="left",vertical_align:l="center",...o}=r.config;return{...r,version:2,config:{...o,horizontal_align:a,vertical_align:l}}})}}const tf={displayName:"viz.button.viz_name",displayGroup:"chart.groups.others",migrator:new ef,name:"button",viewRender:Kg,configRender:Hg,createConfig(){return{version:2,config:y.cloneDeep(_r)}},triggers:[ml],translation:Rg},nf=({option:e,...t})=>{const{label:r,description:a}=e;return n.jsx(s.Box,{...t,children:n.jsxs(s.Stack,{gap:"0",children:[n.jsx(s.Text,{size:"sm",children:r}),n.jsx(s.Text,{size:"xs",opacity:.65,children:a})]})})},rf=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a,i18n:l}=x.useTranslation(),o=h.useMemo(()=>[{label:a("chart.series.line.area_style.origin.auto.label"),description:a("chart.series.line.area_style.origin.auto.description"),value:"auto"},{label:a("chart.series.line.area_style.origin.start.label"),description:a("chart.series.line.area_style.origin.start.description"),value:"start"},{label:a("chart.series.line.area_style.origin.end.label"),description:a("chart.series.line.area_style.origin.end.description"),value:"end"}],[l.language]);return n.jsx(s.Select,{ref:r,label:a("chart.series.line.area_style.origin.label"),data:o,value:e,onChange:Z(t),renderOption:nf,size:"xs"})}),Cl=h.forwardRef(({value:e,onChange:t,label:r,placeholder:a},l)=>n.jsx(s.ColorInput,{ref:l,label:r,placeholder:a,value:e,onChange:t,size:"xs",popoverProps:{withinPortal:!0,zIndex:340},rightSection:e?n.jsx(s.CloseButton,{size:"sm",onClick:()=>{t("")}}):null})),af=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a}=x.useTranslation(),l=o=>i=>{const c=y.cloneDeep(e);y.set(c,o,i),t(c)};return n.jsxs(s.Stack,{ref:r,children:[n.jsx(s.Divider,{mt:10,mb:-10,variant:"dashed",label:n.jsxs(s.Group,{gap:6,children:[n.jsx(S.IconChartAreaLineFilled,{size:14,style:{color:"#999"}}),a("chart.series.line.area_style.label")]}),labelPosition:"center"}),n.jsx(s.Switch,{label:a("chart.series.line.area_style.enabled"),checked:e.enabled,onChange:o=>l("enabled")(o.currentTarget.checked)}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(Cl,{label:a("chart.series.line.area_style.color"),placeholder:a("chart.series.line.area_style.use_series_color"),value:e.color,onChange:l("color")}),n.jsx(s.NumberInput,{size:"xs",label:a("chart.series.line.area_style.opacity"),value:e.opacity,onChange:l("opacity"),step:.1,decimalScale:1,min:0,max:1})]}),n.jsx(rf,{value:e.origin,onChange:l("origin")}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(Cl,{label:a("chart.series.line.area_style.shadow_color"),value:e.shadowColor,onChange:l("shadowColor")}),n.jsx(s.NumberInput,{size:"xs",label:a("chart.series.line.area_style.shadow_blur"),value:e.shadowBlur,onChange:l("shadowBlur")})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.NumberInput,{size:"xs",label:a("chart.series.line.area_style.shadow_offset_x"),value:e.shadowOffsetX,onChange:l("shadowOffsetX")}),n.jsx(s.NumberInput,{size:"xs",label:a("chart.series.line.area_style.shadow_offset_y"),value:e.shadowOffsetY,onChange:l("shadowOffsetY")})]})]})});function Sl(){return{enabled:!1,color:"",origin:"auto",shadowBlur:0,shadowColor:"",shadowOffsetX:0,shadowOffsetY:0,opacity:.7}}const Tl=h.forwardRef(({label:e,value:t,onChange:r,hiddenKeys:a},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>{let _=[{label:o("chart.series_order.name"),value:"name"},{label:o("chart.series_order.value"),value:"value"},{label:o("chart.series_order.raw"),value:""}];if(a&&Array.isArray(a)&&a.length>0){const w=new Set(a);_=_.filter(m=>!w.has(m.value))}return _},[i.language,a]),d=h.useMemo(()=>[{label:o("chart.series_order.asc"),value:"asc"},{label:o("chart.series_order.desc"),value:"desc"}],[i.language,a]),{key:u,order:p}=t,f=_=>{_!==null&&r({key:_,order:p})},v=_=>{_&&r({key:u,order:_})};return n.jsxs(s.Group,{gap:"xs",grow:!0,align:"flex-end",children:[n.jsx(s.Select,{ref:l,label:e,data:c,value:u,onChange:f}),u!==""&&n.jsx(s.SegmentedControl,{size:"sm",data:d,value:p,onChange:v})]})}),dn=()=>({key:"",order:"desc"});function sf(e){const t=y.cloneDeep(y.omit(e,"variables"));return t.stats=y.omit(t.stats,"variables"),t}function lf(e){const{rotate:t,formatter:r=fe()}=e.x_axis.axisLabel;return{...e,x_axis:{...e.x_axis,axisLabel:{rotate:t,formatter:r}}}}function of(e){const{dataZoom:t=wt,...r}=e;return{...r,dataZoom:t}}function cf(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(t,e)}function df(e){const t=e.reference_lines.map(r=>{const{lineStyle:a={type:"dashed",width:1,color:qe.random().css()},show_in_legend:l=!1}=r;return{...r,lineStyle:a,show_in_legend:l}});return{...e,reference_lines:t}}function uf(e){const t=e.reference_lines.map(r=>{const{yAxisIndex:a=0}=r;return{...r,yAxisIndex:a}});return{...e,reference_lines:t}}function pf(e){const t=e.series.map(r=>{const{aggregation_on_group:a=kt}=r;return{...r,aggregation_on_group:a}});return{...e,series:t}}function hf(e){const t=e.series.map(r=>{const{aggregation_on_value:a=kt}=r;return{...r,aggregation_on_value:a}});return{...e,series:t}}function gf(e){delete e.config;const{x_axis:t,tooltip:r}=e.x_axis.axisLabel.overflow,a={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:r}}}};return y.defaultsDeep(a,e)}function ff(e){const{series:t,...r}=e;return{...r,series:t.map(a=>{const{barMinWidth:l,barWidth:o,barMaxWidth:i}=a;return l?{...a,barMinWidth:l,barWidth:"",barMaxWidth:i??o}:{...a,barMinWidth:"",barWidth:o,barMaxWidth:""}})}}function bf(e){const{y_axes:t,...r}=e;return{...r,y_axes:t.map(a=>{const{min:l="",max:o=""}=a;return{...a,min:l,max:o}})}}function yf(e){const{y_axes:t,...r}=e;return{...r,y_axes:t.map(a=>{const{nameAlignment:l="left"}=a;return{...a,nameAlignment:l}})}}function vf(e){const{y_axes:t,...r}=e;return{...r,y_axes:t.map(a=>{const{show:l=!0}=a;return{...a,show:l}})}}function _f(e){const{regressions:t,...r}=e;return{...r,regressions:t.map(a=>{const{group_by_key:l=""}=a;return{...a,group_by_key:l}})}}function xf(e){const{series:t,y_axes:r,...a}=e;return{...a,series:t.map(l=>{const{hide_in_legend:o=!1,aggregation_on_value:i=kt}=l;return{...l,hide_in_legend:o,aggregation_on_value:i}}),y_axes:r.map(l=>{const{min:o="",max:i="",show:c=!0}=l;return{...l,min:o,max:i,show:c}})}}function wf(e){const{type:t="category",...r}=e.x_axis;return{...e,x_axis:{...r,type:t}}}function mf(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{x_axis_data_key:l,series:o,regressions:i,...c}=e;return{...c,x_axis_data_key:a(l),series:o.map(d=>({...d,y_axis_data_key:a(d.y_axis_data_key),group_by_key:a(d.group_by_key)})),regressions:i.map(d=>({...d,y_axis_data_key:a(d.y_axis_data_key),group_by_key:a(d.group_by_key)}))}}catch(r){throw console.error("[Migration failed]",r),r}}function Cf(e){const{tooltip:t={metrics:[]},...r}=e;return{...e,tooltip:t}}function Sf(e,t){const{stats:r,...a}=e,l=It(r.templates.top,t),o=It(r.templates.bottom,t);return{stats:{top:l??"",bottom:o??""},...a}}function Tf(e){const{series:t,...r}=e,a=t.map(l=>{const{areaStyle:o=Sl(),...i}=l;return{...i,areaStyle:o}});return{...r,series:a}}function kf(e){const{series:t,...r}=e,a=t.map(l=>{const{order_in_group:o=dn(),...i}=l;return{...i,order_in_group:o}});return{...r,series:a}}function zf(e){const{series:t,...r}=e,a=t.map(l=>{const{unit:o=U(),...i}=l;return{...i,unit:o}});return{...r,series:a}}function Df(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??U()}))}}}class If extends ee{constructor(){super(...arguments);P(this,"VERSION",24)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,(r,{panelModel:a})=>{const{config:l}=r;return(l.variables||[]).forEach(c=>{a.variables.find(d=>d.name===c.name)||a.addVariable(c)}),(y.get(l,"stats.variables")||[]).forEach(c=>{a.variables.find(d=>d.name===c.name)||a.addVariable(c)}),{...r,version:2,config:sf(l)}}),this.version(3,r=>({...r,version:3,config:lf(r.config)})),this.version(4,r=>({...r,version:4,config:of(r.config)})),this.version(5,r=>({...r,version:5,config:cf(r.config)})),this.version(6,r=>({...r,version:6,config:df(r.config)})),this.version(7,r=>({...r,version:7,config:uf(r.config)})),this.version(8,r=>({...r,version:8,config:pf(r.config)})),this.version(9,r=>({...r,version:9,config:hf(r.config)})),this.version(10,r=>({...r,version:10,config:gf(r.config)})),this.version(11,r=>({...r,version:11,config:ff(r.config)})),this.version(12,r=>({...r,version:12,config:bf(r.config)})),this.version(13,r=>({...r,version:13,config:yf(r.config)})),this.version(14,r=>({...r,version:14,config:vf(r.config)})),this.version(15,r=>({...r,version:15,config:_f(r.config)})),this.version(16,r=>({...r,version:16,config:xf(r.config)})),this.version(17,r=>({...r,version:17,config:wf(r.config)})),this.version(18,(r,a)=>({...r,version:18,config:mf(r.config,a)})),this.version(19,r=>({...r,version:19,config:Cf(r.config)})),this.version(20,(r,a)=>({...r,version:20,config:Sf(r.config,a.panelModel)})),this.version(21,(r,a)=>({...r,version:21,config:Tf(r.config)})),this.version(22,(r,a)=>({...r,version:22,config:kf(r.config)})),this.version(23,(r,a)=>({...r,version:23,config:zf(r.config)})),this.version(24,(r,a)=>({...r,version:24,config:Df(r.config)}))}}const Mf=[{lang:"en",resources:{cartesian_chart:{viz_name:"Cartesian Chart",series:{aggregation:{label:"Aggregation on Value"}},click_series:{label:"Click bar, line or scatter"}}}},{lang:"zh",resources:{cartesian_chart:{viz_name:"复合图",series:{aggregation:{label:"聚合数据"}},click_series:{label:"点击柱、线或散点"}}}}],wr={id:"builtin:echarts:click-echart:series",displayName:"viz.cartesian_chart.click_series.label",nameRender:Pf,configRender:Af,payload:[{name:"seriesType",description:"'line' | 'scatter' | 'bar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Af(e){return n.jsx(n.Fragment,{})}function Pf(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.cartesian_chart.click_series.label")})}const kl={regressions:[],series:[],stats:{bottom:"",top:""},x_axis:{type:"category",axisLabel:{rotate:0,formatter:fe(),overflow:we()}},tooltip:{metrics:[]},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:le,mirror:!1}],reference_lines:[],reference_areas:[],dataZoom:wt},un=T.observer(({value:e,context:t,onHeightChange:r})=>{var f;const{ref:a}=te.useElementSize(),l=J(),{panel:o}=be(),{variables:i,data:c}=t,d=h.useMemo(()=>ht(e,i,l.payloadForViz,c),[e,i,c]),u=((f=a.current)==null?void 0:f.textContent)==="";h.useEffect(()=>{if(!r||!a.current)return;const v=u?0:a.current.offsetHeight;r(v)},[u,a.current]);const p=h.useMemo(()=>u?"none":"block",[u]);return n.jsx(s.Box,{sx:{display:p},children:n.jsx(Dt,{ref:a,value:d,styles:{root:{margin:"0 8px",border:"none",maxWidth:"100%","&.mantine-RichTextEditor-root":{overflow:"auto !important"}},content:{"&.mantine-RichTextEditor-content .ProseMirror":{padding:0},"&.mantine-RichTextEditor-content .ProseMirror > p":{fontSize:"12px",lineHeight:"20px"}}},dashboardStateValues:l.dashboardStateValues,variableAggValueMap:o.variableAggValueMap})})});function Vf(e){const t=e.y_axes.some(l=>!!l.name);let r=15;t&&(r+=20),e.dataZoom.x_axis_slider&&(r+=20);let a=5;return e.x_axis_name&&(a+=15),e.series.some(l=>!l.hide_in_legend)&&(a+=20),{top:r,right:15,bottom:a,left:20,containLabel:!0}}function $f(e){return e!=="line"?{}:{itemStyle:{opacity:0}}}function Ef(e){switch(e){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function Bf(e,t){const r=e.series.reduce((l,{unit:o,name:i})=>(o.show_in_legend&&(l[i]=o.text),l),{}),a={show:!0,bottom:0,left:"center",type:"scroll",formatter:l=>{const o=r[l];return o?`${l}(${o})`:l}};return a.data=t.filter(l=>!l.hide_in_legend).map(({name:l,type:o})=>({name:l,icon:Ef(o),...$f(o)})),a}function pn(e,t){switch(e.config.method){case"linear":return[...ut.regressionLinear()(t)];case"exponential":return[...ut.regressionExp()(t)];case"logistic":return[...ut.regressionLog()(t)];case"polynomial":return[...ut.regressionPoly().order(e.config.order)(t)];default:return[]}}function Lf(e,t,r,a){const{transform:l,plot:o}=e,i={...o,name:t,data:pn(l,a),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return r&&(i.custom={type:"regression-line",targetSeries:r}),i}function qf({regressions:e=[],x_axis_data_key:t},r){const a=[];if(Object.keys(r).length===0)return a;function l(o,i,c,d){const u=Lf(o,i,c,d);a.push(u)}return e.forEach(o=>{const{name:i,group_by_key:c}=o;if(!c||c===t){const f=Ve(r,o.y_axis_data_key).map((v,_)=>[_,Number(v)]);l(o,i,"",f);return}const{columnKey:d}=A(o.y_axis_data_key),u=y.groupBy(Rt(r,o.y_axis_data_key),c);Object.entries(u).forEach(([p,f])=>{const v=f.map((w,m)=>[m,Number(w[d])]);l(o,p,p,v)})}),a}function Of(e,t){return e.map(r=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:r.color},data:[[{yAxis:t[r.y_keys.upper]},{yAxis:t[r.y_keys.lower]}]],silent:!0}}))}function Nf(e,t,r,a){return t?a==="value"?[[r[0],e]]:[e]:[]}function Gf(e,t,r,a,l,o){return e.map(i=>{const c=r[i.variable_key],d=i.orientation==="horizontal",u=d?"yAxis":"xAxis",p=d?"insideEndTop":"end",f=Nf(c,d,l,o);return{name:i.name,type:"scatter",hide_in_legend:!i.show_in_legend,xAxisId:"main-x-axis",yAxisIndex:i.yAxisIndex,data:f,symbol:"none",silent:!0,tooltip:{show:!1},markLine:{data:[{name:i.name,[u]:c}],silent:!0,symbol:["none","none"],lineStyle:i.lineStyle,label:{formatter:function(){return i.template?jt(i.template,t,a):""},position:p}}}})}function mr(e,t,r){const a=Ve(e,t),l=Ve(e,r);return y.zip(a,l)}function Ff(e,t,r,a){const l=mr(t,r,a);return y.unionBy(l,e,0)}function jf({dataTemplate:e,data:t,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:l}){return l?Ff(e,t,r,a):Ve(t,a)}function Qf({dataTemplate:e,data:t,aggregation_on_value:r,x_axis_data_key:a,y_axis_data_key:l,valueTypedXAxis:o}){if(!r||r.type==="none")return jf({dataTemplate:e,data:t,x_axis_data_key:a,y_axis_data_key:l,valueTypedXAxis:o});const i=mr(t,a,l),c=y.groupBy(i,"0");return e.map(([u])=>{const f=c[u].map(_=>_[1]),v=Nn(f,r);return[u,v]})}function Wf({group_by_key:e,data:t,x_axis_data_key:r,y_axis_data_key:a}){const{queryID:l,columnKey:o}=A(e),i=y.groupBy(t[l],o);return Object.entries(i).forEach(([c,d])=>{i[c]=mr({[l]:d},r,a)}),i}function Uf({type:e,...t},r,a,l){if(!e)return 10;if(e==="static"){const{size:u}=t;return u}const{func_content:o}=t,{queryID:i,columnKey:c}=A(a),d=y.keyBy(Rt(r,i),c);return(u,p)=>{let f;p.name?f=d[p.name]:f=r[p.dataIndex];try{return new Function(`return ${o}`)()({rowData:f,params:p,variables:l},{lodash:y,interpolate:ot.interpolate})}catch(v){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${v.message}`),10}}}function Yf({x_axis_data_key:e,x_axis:t},{y_axis_data_key:r,yAxisIndex:a,label_position:l,name:o,unit:i,group_by_key:c,order_in_group:d,aggregation_on_value:u,stack:p,color:f,display_name_on_line:v,symbolSize:_,hide_in_legend:w,areaStyle:m,...k},z,D,I,L){const E=t.type!=="category",K={label:{show:!!l,position:l,formatter:L[a??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:a,stack:p,color:f,symbolSize:Uf(_,D,e,I),hide_in_legend:w,labelLayout:{hideOverlap:!0},...k};if(k.type==="line"&&(K.lineStyle={width:k.lineStyle.width,type:k.lineStyle.type,shadowColor:"rgba(255,255,255,1)",shadowBlur:0,shadowOffsetX:0,shadowOffsetY:y.clamp(k.lineStyle.width,1,3)},m.enabled)){K.lineStyle.shadowColor="transparent";const{enabled:me,...lt}=m;K.areaStyle={...lt,color:lt.color||f}}if(v&&(K.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!c||c===e)return K.data=Qf({dataTemplate:z,data:D,aggregation_on_value:u,x_axis_data_key:e,y_axis_data_key:r,valueTypedXAxis:E}),K;const N=Wf({group_by_key:c,data:D,x_axis_data_key:e,y_axis_data_key:r});let oe=Object.entries(N);return d.key==="name"&&(oe=y.orderBy(Object.entries(N),0,[d.order])),oe.map(([me,lt])=>{const yt=y.cloneDeep(K);return yt.name=me,yt.color=void 0,"areaStyle"in yt&&(yt.areaStyle.color=void 0),yt.data=lt,yt})}function Kf(e,t,r,a,l,o){const i=t.map(d=>[d,0]);return e.series.map(d=>Yf(e,d,i,r,o,a)).flat().concat(Gf(e.reference_lines,l,o,r,t,e.x_axis.type)).concat(Of(e.reference_areas,o))}function Xf(e,t){const r=e.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!r)return"";const{axisValue:a,axisIndex:l}=r;return xe(t.x_axis.axisLabel.formatter)(a,l)}const Zf=e=>Y(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function Jf(e,t,r,a){const l=r.reduce((c,{yAxisIndex:d,name:u})=>(c[u]=d,c),{}),o=e.series.reduce((c,{unit:d,name:u})=>(d.show_in_tooltip&&(c[u]=d.text),c),{}),i=e.tooltip.metrics.reduce((c,{unit:d,name:u})=>(d.show_in_tooltip&&(c[u]=d.text),c),{});return X.getTooltip({trigger:"axis",formatter:function(c){const d=Array.isArray(c)?c:[c];if(d.length===0)return"";const u=d.map(({seriesName:_,marker:w,value:m})=>{if(Array.isArray(m)&&m.length===2&&(m=m[1]),!_)return m;const k=o[_]??"",z=l[_],D=a[z]??a.default;return`
119
+ `}const ag=(e,t)=>r=>{const{seriesName:a,value:l}=r;switch(a){case t.Box:return eg(e,l);case t.Outlier:return ng(e,l);case t.Scatter:return rg(e,l)}};function sg({config:e,seriesNames:t}){return X.getTooltip({trigger:"item",formatter:ag(e,t)})}function on(e,t){t||(t="none");const r=[];return e.x_axis_scroll&&r.push({type:"inside",xAxisIndex:[0],filterMode:t,minSpan:1}),e.y_axis_scroll&&r.push({type:"inside",yAxisIndex:[0],filterMode:t,minSpan:1}),e.x_axis_slider&&r.push({type:"slider",xAxisIndex:[0],filterMode:t,bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),r}function lg({min:e,max:t}){if(e<=110)return Math.min(0,e);if(e<=200)return 100;const r=qe.floor(qe.log10(e)),a=Math.pow(10,r),l=Math.pow(10,r-1);return e/a<=2?y.round(e,-1*(r-1))-l:y.round(e,-1*r)-a}function og(e){return{Box:e("viz.boxplot.box"),Scatter:e("viz.boxplot.scatter"),Outlier:e("viz.boxplot.outlier")}}function ig({config:e,data:t,variables:r,t:a}){const{x_axis:l,y_axis:o,reference_lines:i}=e,c=jh(e,t),d=Fe(l.axisLabel.overflow.on_axis),u=og(a),p=Rh(e,c).map(f=>({...f,name:y.get(u,f.name,f.name)}));return{dataZoom:on(e.dataZoom,"filter"),grid:Qh(e),dataset:c,legend:Wh({config:e,seriesNames:u}),tooltip:sg({config:e,seriesNames:u}),xAxis:[X.getXAxis({type:"category",name:l.name,nameGap:25,nameLocation:"center",nameTextStyle:{align:"center"},axisLabel:{...l.axisLabel,...d,formatter:ze(l.axisLabel.formatter)}})],yAxis:[X.getYAxis({name:o.name,minInterval:1,axisLabel:{formatter:function(f){return Y(f,o.label_formatter)}},min:lg})],series:[...p,...Uh(i,r,t)]}}function cg({context:e,instance:t}){const{t:r}=x.useTranslation(),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=e.data,{width:i,height:c}=e.viewport,d=y.defaults({},a,dr),u=Me({vizManager:e.vizManager,instance:t}),p=Ie(u.triggerManager,pl.id),f=mt(o,d.x_axis.data_key),v=h.useCallback(z=>{const D=y.get(f,z.name,{error:"rowData is not found"});p.forEach(I=>{u.runInteraction(I.id,{...z,rowData:D})})},[f,p,u]),_=h.useRef(null),w=h.useCallback(()=>{var D;const z=(D=_.current)==null?void 0:D.getEchartsInstance();z&&de(t,z.getOption())},[]),m=h.useMemo(()=>({click:v,finished:w}),[v,w]),k=h.useMemo(()=>ig({config:d,data:o,variables:l,t:r}),[d,o,l,r]);return!a||!i||!c?null:n.jsx(_e,{width:i,height:c,children:n.jsx(he,{echarts:ie,option:k,ref:_,style:Ot(i,c),onEvents:m,notMerge:!0,theme:"merico-light"})})}function ae({canSubmit:e,buttonRef:t}){const{t:r}=x.useTranslation();return n.jsxs(s.Group,{justify:"flex-start",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n.jsx(s.Text,{size:"sm",children:r("viz.viz_config_banner")}),n.jsx(s.ActionIcon,{ref:t,type:"submit",mr:5,variant:"filled",color:"blue",disabled:!e,children:n.jsx(S.IconDeviceFloppy,{size:20})})]})}const yr=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>[{label:o("common.align.horizontal.left"),value:"left"},{label:o("common.align.horizontal.center"),value:"center"},{label:o("common.align.horizontal.right"),value:"right"}],[i.language]);return n.jsx(s.Select,{ref:l,label:e??o("common.align.horizontal.label"),data:c,value:t,onChange:Z(r),sx:a})}),wl=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>[{label:o("common.align.vertical.top"),value:"top"},{label:o("common.align.vertical.center"),value:"center"},{label:o("common.align.vertical.bottom"),value:"bottom"}],[i.language]);return n.jsx(s.Select,{ref:l,label:e??o("common.align.vertical.label"),data:c,value:t,onChange:Z(r),sx:a})}),ml=dt.createStyles(()=>({palette:{display:"flex",flexFlow:"row nowrap"},paletteItem:{".palette-value":{height:24,overflow:"visible",width:36},".palette-item":{width:"36px",height:36*.618,cursor:"pointer",transition:"transform 100ms ease-in-out","&:hover":{boxShadow:"0 0 0 2px var(--shadow-color)",borderRadius:2,transform:"scale(1.2)"}}}})),dg=[{from:0,to:0},{from:100,to:100}];class ug{constructor(){V(this,"steps",new Map);V(this,"interpolation");V(this,"onChange");Q.makeAutoObservable(this,{steps:Q.observable},{deep:!1}),Q.reaction(()=>Q.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(t){for(const r of t)this.steps.set(r.to,r.from)}notifyStepChange(){var t;(t=this.onChange)==null||t.call(this,Array.from(this.steps.entries()).map(([r,a])=>({to:r,from:a})).sort((r,a)=>r.to-a.to||r.from-a.from))}fromProps(t){t.steps.length<2?this.setSteps(dg):this.setSteps(t.steps),this.interpolation=t.interpolation,this.onChange=t.onChange}changeStep(t,r){t==null?this.steps.delete(r):this.steps.set(r,t)}getStepFromValue(t){return this.steps.get(t)}}function Cl(e){if(typeof e=="number")return String(e)}function pg(e){const{t}=x.useTranslation(),{onChange:r,color:a,index:l,value:o}=e,{classes:i}=ml(),[c,d]=h.useState(Cl(o)),[u,{setTrue:p,setFalse:f}]=O.useBoolean(!1),v=l%2===1,_=v&&o!=null,w=!v&&o!=null,m=`map ${o} to color ${l}`,k=()=>{d(Cl(o)),f()},z=()=>{f(),r==null||r(Number(c))},D=()=>{f(),r==null||r(null)},I=Y(o??null,{output:"number",mantissa:10,trimMantissa:!0,average:!0,absolute:!1}),L=!c||Number.isNaN(Number(c));return n.jsxs("div",{"data-testid":`palette-item-${l}`,className:i.paletteItem,children:[n.jsx(s.Text,{title:m,style:{opacity:_?1:0},c:"dimmed",size:"sm",className:"palette-value--up palette-value",children:I}),n.jsxs(s.Popover,{width:240,trapFocus:!0,opened:u,onClose:f,zIndex:340,withinPortal:!0,children:[n.jsx(s.Popover.Target,{children:n.jsx("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:p,style:{"--shadow-color":Be(a).alpha(.5).hex(),backgroundColor:a}})}),n.jsxs(s.Popover.Dropdown,{children:[n.jsx(s.Tooltip,{withinPortal:!0,zIndex:340,label:t("common.actions.close"),children:n.jsx(s.CloseButton,{"data-testid":"palette-item-cancel",size:"sm",color:"gray",onClick:k,style:{position:"absolute",top:"0.5em",right:"0.8em"}})}),n.jsxs(s.Stack,{children:[n.jsx(s.TextInput,{size:"xs",label:t("style.color.interpolation.palette.mapping.value_input_label"),value:c,onChange:E=>{const K=E.currentTarget.value;d(K)},error:c&&L}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{variant:"light",color:"red",size:"xs",onClick:D,leftSection:n.jsx(S.IconTrash,{size:16}),children:t("common.actions.delete")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),"data-testid":"palette-item-ok",size:"xs",onClick:z,disabled:L,children:t("common.actions.save")})]})]})]})]}),n.jsx(s.Text,{title:m,style:{opacity:w?1:0},c:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:I})]})}const hg=T.observer(({model:e})=>{const{classes:t}=ml(),r=y.range(0,13,1).map(a=>100/12*a).map(a=>[e.interpolation.getColor(a),a]);return n.jsx("div",{className:t.palette,children:r.map(([a,l],o)=>n.jsx(pg,{index:o,color:a,value:e.getStepFromValue(l),onChange:i=>e.changeStep(i,l)},a))})}),gg=T.observer(function(t){const r=O.useCreation(()=>new ug,[]);return h.useEffect(()=>{r.fromProps(t)}),r.interpolation==null?null:n.jsx(hg,{model:r})}),fg=e=>{const{t,i18n:r}=x.useTranslation(),{value:a,onChange:l,colorManager:o}=e,i=o.getColorInterpolations(),[c,d]=h.useState(a),u=o.decodeInterpolation(c.interpolation)||i[0],[p,{setTrue:f,setFalse:v}]=O.useBoolean(),_=h.useMemo(()=>{const D=y.groupBy(i,"category");return Object.entries(D).map(([I,L])=>({group:t(`style.color.interpolation.palette.category.${I}`),items:L.map(E=>({label:t(E.displayName),value:o.encodeColor(E)}))}))},[r.language]);function w(D){D&&d(I=>({...I,interpolation:D}))}const m=()=>{v(),l==null||l(Q.toJS(c))};function k(D){d(I=>({...I,steps:D}))}const z=()=>{v(),d(a)};return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{variant:"outline",onClick:f,children:t(u==null?void 0:u.displayName)}),n.jsx(s.Modal,{size:508,title:t("style.color.interpolation.setup"),opened:p,onClose:v,zIndex:320,children:p&&n.jsxs(s.Stack,{"data-testid":"color-interpolation-modal",children:[n.jsx(s.Select,{label:t("style.color.interpolation.palette.label"),value:c.interpolation,data:_,onChange:w,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500}),n.jsx(gg,{steps:c.steps,interpolation:u,onChange:k}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:z,variant:"subtle",children:t("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:m,children:t("common.actions.save")})]})]})})]})},bg=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>[{label:o("style.color.type.static"),value:"static"},{label:o("style.color.type.interpolation"),value:"interpolation"},{label:o("style.color.type.none"),value:"none"}],[i.language]);return n.jsx(s.Select,{ref:l,label:e??o("style.color.type.label"),data:c,value:t,onChange:Z(r),sx:a})}),yg=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>[{label:o("style.flex.justify_content.left"),value:"left"},{label:o("style.flex.justify_content.center"),value:"center"},{label:o("style.flex.justify_content.right"),value:"right"},{label:o("style.flex.justify_content.space_between"),value:"space-between"},{label:o("style.flex.justify_content.space_around"),value:"space-around"},{label:o("style.flex.justify_content.space_evenly"),value:"space-evenly"}],[i.language]);return n.jsx(s.Select,{ref:l,label:e??o("style.flex.justify_content.label"),data:c,value:t,onChange:Z(r),sx:a})}),vg=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>[{label:o("style.flex.align_items.start"),value:"start"},{label:o("style.flex.align_items.center"),value:"center"},{label:o("style.flex.align_items.end"),value:"end"},{label:o("style.flex.align_items.stretch"),value:"stretch"}],[i.language]);return n.jsx(s.Select,{ref:l,label:e??o("style.flex.align_items.label"),data:c,value:t,onChange:Z(r),sx:a})}),_g=({value:e,index:t,children:r})=>{const[a,{setTrue:l,setFalse:o}]=O.useBoolean(!1),{ref:i,handleRef:c}=Ln.useSortable({id:e,index:t});return n.jsx(s.Tabs.Tab,{ref:i,value:e,leftSection:n.jsx(S.IconGripHorizontal,{size:14,color:a||t===0?"rgb(34, 139, 230)":"transparent"}),onMouseEnter:l,onMouseLeave:o,children:r})},xg=({fieldArray:e,add:t,addButtonText:r,renderTabName:a,controlledFields:l})=>{const o=i=>{const{source:c,target:d}=i.operation,u=l.findIndex(f=>f.id===c.id),p=d.index;e.move(u,p)};return n.jsxs(s.Tabs.List,{children:[n.jsx(Bn.DragDropProvider,{onDragEnd:o,children:l.map((i,c)=>n.jsx(_g,{value:i.id,index:c,children:a(i,c)},i.id))}),n.jsx(s.Tabs.Tab,{onClick:t,value:"add",children:n.jsx(s.Tooltip,{label:r,children:n.jsx(s.Center,{children:n.jsx(S.IconPlus,{size:18,color:"#228be6"})})})})]})},wg={tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},H=({control:e,watch:t,name:r,getItem:a,children:l,addButtonText:o,deleteButtonText:i,renderTabName:c,deleteDisalbed:d})=>{var L;const u=b.useFieldArray({control:e,name:r}),{fields:p,append:f,remove:v}=u,_=t(r),w=p.map((E,K)=>({...E,..._[K]})),m=((L=y.last(w))==null?void 0:L.id)??null,[k,z]=h.useState(m),D=E=>{E!=="add"&&z(E)};h.useEffect(()=>{z(E=>m===E?E:m)},[m]);const I=()=>{const E=a();u.append(E),z(E.id)};return n.jsxs(s.Tabs,{value:k,onChange:D,styles:wg,children:[n.jsx(xg,{fieldArray:u,add:I,addButtonText:o,renderTabName:c,controlledFields:w}),w.map((E,K)=>n.jsx(s.Tabs.Panel,{value:E.id,children:n.jsxs(s.Stack,{children:[l({field:E,index:K}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed"}),n.jsx(s.Button,{leftSection:n.jsx(S.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>v(K),sx:{top:15,right:5},disabled:d==null?void 0:d({field:E,index:K,fields:w}),children:i})]})},E.id))]})},cn=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a}=x.useTranslation(),l=o=>i=>{t({...e,[o]:i})};return n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{variant:"dashed",label:a("chart.zooming.scroll.label"),labelPosition:"center"}),n.jsxs(s.Group,{children:[n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.zooming.scroll.x_axis"),checked:e.x_axis_scroll,onChange:o=>l("x_axis_scroll")(o.currentTarget.checked)})}),n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.zooming.scroll.y_axis"),checked:e.y_axis_scroll,onChange:o=>l("y_axis_scroll")(o.currentTarget.checked)})})]}),n.jsx(s.Divider,{variant:"dashed",label:a("chart.zooming.slider.label"),labelPosition:"center"}),n.jsxs(s.Group,{children:[n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.zooming.slider.x_axis"),checked:e.x_axis_slider,onChange:o=>l("x_axis_slider")(o.currentTarget.checked)})}),n.jsx(s.Tooltip,{label:a("chart.zooming.slider.y_axis_disabled"),children:n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.zooming.slider.y_axis"),disabled:!e.y_axis_slider,checked:e.y_axis_slider,onChange:o=>l("y_axis_slider")(o.currentTarget.checked)})})})]})]})}),gt=h.forwardRef(({label:e,value:t,onChange:r,sx:a={},disabled:l},o)=>{const{t:i,i18n:c}=x.useTranslation(),d=h.useMemo(()=>[{label:i("chart.orientation.horizontal"),value:"horizontal"},{label:i("chart.orientation.vertical"),value:"vertical"}],[c.language]);return n.jsx(s.Select,{ref:o,label:e??i("chart.orientation.label"),data:d,value:t,onChange:Z(r),sx:a,disabled:l})}),mg=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=t("legend"),l=(o,i)=>{const c={...a,orient:o};o==="horizontal"?(c.top="0",c.left="auto",c.right="10",c.bottom="auto"):(c.top="10",c.left="auto",c.right="0",c.bottom="auto"),i(c)};return n.jsxs(s.Stack,{children:[n.jsx(s.Group,{grow:!0,wrap:"nowrap",mt:20,children:n.jsx(b.Controller,{name:"legend.show",control:e,render:({field:o})=>n.jsx(s.Switch,{label:r("chart.legend.show_legend"),sx:{flex:1},checked:o.value,onChange:i=>o.onChange(i.currentTarget.checked)})})}),n.jsx(s.Group,{children:n.jsx(b.Controller,{name:"legend",control:e,render:({field:o})=>n.jsx(gt,{sx:{flex:1},value:o.value.orient,onChange:i=>{l(i,o.onChange)},disabled:!a.show})})})]})};function Cg({control:e,index:t,variableOptions:r}){const{t:a}=x.useTranslation();return n.jsxs(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:l})=>n.jsx(s.TextInput,{label:a("common.name"),placeholder:a("chart.reference_line.name_placeholder"),required:!0,sx:{flex:1},...l})}),n.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:l})=>n.jsx(s.Select,{label:a("common.value"),required:!0,data:r,sx:{flex:1},...l})})]}),n.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:l})=>n.jsx(s.TextInput,{label:a("chart.content_template.label"),placeholder:a("chart.content_template.placeholder"),required:!0,sx:{flex:1},...l})})]})}function Sg({control:e,watch:t,variables:r}){const{t:a}=x.useTranslation(),l=()=>({name:"",template:"",variable_key:""}),o=h.useMemo(()=>r.map(c=>({label:c.name,value:c.name})),[r]),i=(c,d)=>{const u=c.name.trim();return u||d+1};return n.jsx(H,{control:e,watch:t,name:"reference_lines",getItem:l,addButtonText:a("chart.reference_line.add"),deleteButtonText:a("chart.reference_line.delete"),renderTabName:i,children:({field:c,index:d})=>n.jsx(Cg,{control:e,index:d,variableOptions:o})})}const Tg=({control:e,index:t})=>{const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("chart.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.unit`,control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})})]})},kg=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>({id:Date.now().toString(),data_key:"",name:"",unit:U()}),l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:r("chart.tooltip.additional_metrics.description")})]}),n.jsx(H,{control:e,watch:t,name:"tooltip.metrics",getItem:a,addButtonText:r("chart.tooltip.additional_metrics.add"),deleteButtonText:r("chart.tooltip.additional_metrics.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(Tg,{control:e,index:i})})]})};function zg({control:e,watch:t}){return n.jsx(s.Stack,{children:n.jsx(kg,{control:e,watch:t})})}const nt=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o}=x.useTranslation();return n.jsx(s.NumberInput,{ref:l,label:e??o("chart.rotate"),hideControls:!0,min:-90,max:90,rightSection:n.jsx(s.Text,{size:"xs",c:"dimmed",children:o("chart.degree")}),sx:a,styles:{section:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},value:t,onChange:i=>{typeof i!="string"&&r(i)}})}),Dg=({control:e,watch:t})=>{const{t:r}=x.useTranslation();return t(["x_axis"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.x_axis.x_axis_name"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("chart.x_axis.x_axis_data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(s.Divider,{mb:-15,label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:a})=>n.jsx(nt,{sx:{width:"48%"},...a})}),n.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(He,{...a})})]}),n.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(Re,{...a})})]})},vr={root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}},Ig=["123456789","1234","1234.56789","1.234","0.123456789","-0.123456789"];function Mg({format:e}){const{t}=x.useTranslation(),[r,{toggle:a}]=ne.useDisclosure(!1);return n.jsxs(s.Box,{children:[n.jsx(s.Button,{variant:"subtle",w:"100%",size:"compact-sm",onClick:a,leftSection:r?n.jsx(S.IconChevronUp,{size:14}):n.jsx(S.IconChevronDown,{size:14}),children:t(r?"numbro.format.preview.close":"numbro.format.preview.open")}),n.jsx(s.Collapse,{in:r,children:r&&n.jsxs(s.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:t("numbro.format.preview.input")}),n.jsx(s.Table.Th,{children:t("numbro.format.preview.output")})]})}),n.jsx(s.Table.Tbody,{children:Ig.map(l=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:l}),n.jsx(s.Table.Td,{children:n.jsx(te,{children:Y(l,e)})})]},l))})]})})]})}function Vg({value:e,onChange:t},r){const{t:a}=x.useTranslation(),l=u=>{t({...e,output:u})},o=u=>{if(typeof u=="string")return;const p=u===0?!1:e.trimMantissa;t({...e,mantissa:u,trimMantissa:p})},i=u=>{t({...e,trimMantissa:u.currentTarget.checked})},c=u=>{t({...e,average:u.currentTarget.checked})},d=u=>{const p={...e,absolute:u.currentTarget.checked};t(p)};return n.jsxs(s.Stack,{ref:r,children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.Select,{label:a("numbro.format.label"),data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:Z(l),sx:{flexGrow:1}}),n.jsx(s.Switch,{label:n.jsxs(s.Stack,{gap:0,children:[n.jsx(s.Text,{size:"sm",children:a("numbro.format.absolute")}),n.jsx(s.Text,{size:"12px",c:"gray",children:a("numbro.format.absolute_description")})]}),checked:e.absolute,onChange:d,sx:{flexGrow:1},styles:vr}),n.jsx(s.Switch,{label:n.jsxs(s.Stack,{gap:0,children:[n.jsx(s.Text,{size:"sm",children:a("numbro.format.abbreviation")}),n.jsx(s.Text,{size:"12px",c:"gray",children:a("numbro.format.abbreviation_description")})]}),checked:e.average,onChange:c,disabled:e.output!=="number",sx:{flexGrow:1},styles:vr})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.NumberInput,{label:a("numbro.format.mantissa"),defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:o}),n.jsx(s.Switch,{label:n.jsxs(s.Stack,{gap:0,children:[n.jsx(s.Text,{size:"sm",children:a("numbro.format.trim_mantissa")}),n.jsx(s.Text,{size:"12px",c:"gray",children:a("numbro.format.trim_mantissa_description")})]}),checked:e.trimMantissa,onChange:i,disabled:e.mantissa===0,styles:vr}),n.jsx(s.Box,{})]}),n.jsx(Mg,{format:e})]})}const je=h.forwardRef(Vg),Pg=({control:e,watch:t})=>{const{t:r}=x.useTranslation();return t(["y_axis"]),n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.y_axis.y_axis_name"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("chart.y_axis.y_axis_data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:"y_axis.unit",control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mt:10,mb:-15,variant:"dashed",label:r("chart.axis.section_title.label_format"),labelPosition:"center"}),n.jsx(b.Controller,{name:"y_axis.label_formatter",control:e,render:({field:a})=>n.jsx(je,{...a})})]})]})};function Ag({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},r,dr),[r]),{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=b.useForm({defaultValues:o});return h.useEffect(()=>{p(o)},[o]),d(["x_axis","y_axis","reference_lines","color","dataZoom"]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:c(a),children:[n.jsx(ae,{canSubmit:u.isDirty}),n.jsxs(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axis",children:t("chart.x_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Y Axis",children:t("chart.y_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Legend",children:t("chart.legend.label")}),n.jsx(s.Tabs.Tab,{value:"Tooltip",children:t("chart.tooltip.label")}),n.jsx(s.Tabs.Tab,{value:"Style",children:t("chart.style.label")}),n.jsx(s.Tabs.Tab,{value:"Reference Lines",children:t("chart.reference_line.labels")}),n.jsx(s.Tabs.Tab,{value:"Zooming",children:t("chart.zooming.label")})]}),n.jsx(s.Tabs.Panel,{value:"X Axis",children:n.jsx(Dg,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Y Axis",children:n.jsx(Pg,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Legend",children:n.jsx(mg,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Tooltip",children:n.jsx(zg,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Style",children:n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:"color",control:i,render:({field:f})=>n.jsx(be,{label:t("chart.color.label"),...f})})})}),n.jsx(s.Tabs.Panel,{value:"Reference Lines",children:n.jsx(Sg,{variables:l,control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Zooming",children:n.jsx(b.Controller,{name:"dataZoom",control:i,render:({field:f})=>n.jsx(cn,{...f})})})]})]})})}function $g(e){return y.omit(e,"variables")}function Eg(e){const{label_formatter:t=ce,...r}=e.y_axis;return{...e,y_axis:{...r,label_formatter:t}}}function Bg(e){const t={rotate:0,formatter:ye()},{axisLabel:r=t,...a}=e.x_axis;return{...e,x_axis:{...a,axisLabel:r}}}function Lg(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(t,e)}function qg(e){delete e.config;const{x_axis:t,tooltip:r}=e.x_axis.axisLabel.overflow,a={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:r}}}};return y.defaultsDeep(a,e)}function Og(e){const t={tooltip:{metrics:[]}};return y.defaultsDeep(t,e)}function Ng(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{x_axis:l,y_axis:o,tooltip:i,...c}=e;return{...c,x_axis:{...l,data_key:a(l.data_key)},y_axis:{...o,data_key:a(o.data_key)},tooltip:{...i,metrics:i.metrics.map(d=>({...d,data_key:a(d.data_key)}))}}}catch(r){throw console.error("[Migration failed]",r),r}}function Gg(e){const t={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return y.defaultsDeep(t,e)}function Fg(e){const{dataZoom:t,...r}=e;return{...r,dataZoom:t??ul()}}function jg(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??U()}))}}}function Qg(e){const{y_axis:t}=e;return{...e,y_axis:{...t,unit:t.unit??U()}}}class Wg extends ee{constructor(){super(...arguments);V(this,"VERSION",12)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,(r,{panelModel:a})=>{const{config:l}=r;return(l.variables||[]).forEach(i=>{a.variables.find(c=>c.name===i.name)||a.addVariable(i)}),{...r,version:2,config:$g(l)}}),this.version(3,r=>{const{config:a}=r;return{...r,version:3,config:Eg(a)}}),this.version(4,r=>{const{config:a}=r;return{...r,version:4,config:Bg(a)}}),this.version(5,r=>{const{config:a}=r;return{...r,version:5,config:Lg(a)}}),this.version(6,r=>{const{config:a}=r;return{...r,version:6,config:qg(a)}}),this.version(7,r=>{const{config:a}=r;return{...r,version:7,config:Og(a)}}),this.version(8,(r,a)=>{const{config:l}=r;return{...r,version:8,config:Ng(l,a)}}),this.version(9,r=>{const{config:a}=r;return{...r,version:9,config:Gg(a)}}),this.version(10,r=>{const{config:a}=r;return{...r,version:10,config:Fg(a)}}),this.version(11,r=>{const{config:a}=r;return{...r,version:11,config:jg(a)}}),this.version(12,r=>{const{config:a}=r;return{...r,version:12,config:Qg(a)}})}}const Ug={displayName:"viz.boxplot.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new Wg,name:"boxplot",viewRender:cg,configRender:Ag,createConfig(){return{version:12,config:y.cloneDeep(dr)}},triggers:[pl],translation:Np},Sl={id:"builtin:button:click-button",displayName:"viz.button.click.label",nameRender:Yg,configRender:Kg,payload:[]};function Kg(e){return n.jsx(n.Fragment,{})}function Yg(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.button.click.label")})}const _r={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},Xg={left:"flex-start",center:"center",right:"flex-end"},Zg={top:"flex-start",center:"center",bottom:"flex-end"},Jg=T.observer(({context:e,instance:t})=>{const r=Me({vizManager:e.vizManager,instance:t}),a=Ie(r.triggerManager,Sl.id),l=J(),{value:o}=B(e.instanceData,"config"),i=h.useMemo(()=>y.defaultsDeep({},o,_r),[o]),{content:c,horizontal_align:d,vertical_align:u,compact:p,size:f,...v}=i,{width:_,height:w}=e.viewport,m=l.payloadForSQL,k=()=>{a.forEach(D=>{r.runInteraction(D.id,{})})},z=p?`compact-${f}`:f;return n.jsx(s.Center,{sx:{width:_,height:w,justifyContent:Xg[d],alignItems:Zg[u]},children:n.jsx(s.Button,{size:z,...v,onClick:k,children:y.template(c)(m)})})}),Hg=({value:e,onChange:t,label:r})=>{const a=s.useMantineTheme(),l=h.useCallback(i=>()=>t(i),[t]),o=i=>e===i;return n.jsxs(s.Stack,{gap:2,children:[n.jsx(s.Text,{size:"14px",fw:500,children:r}),n.jsx(s.Group,{justify:"flex-start",gap:"xs",children:Object.keys(a.colors).map(i=>{const c=a.colors[i][6];return n.jsx(s.ColorSwatch,{color:c,onClick:l(i),radius:4,size:26,sx:{cursor:"pointer"},children:o(i)&&n.jsx(s.CheckIcon,{width:10,color:"white"})},i)})})]})},Rg=["xs","sm","md","lg","xl"],xr=h.forwardRef(({label:e,value:t,onChange:r,sx:a,disabled:l},o)=>{const{t:i,i18n:c}=x.useTranslation(),d=h.useMemo(()=>Rg.map(u=>({label:i(`style.size.${u}`),value:u})),[c.language]);return n.jsx(s.Select,{ref:o,data:d,label:e,value:t,onChange:Z(r),sx:a,disabled:!0})}),ef=[{label:"Filled",value:"filled"},{label:"Outline",value:"outline"},{label:"Light",value:"light"},{label:"White",value:"white"},{label:"Default",value:"default"},{label:"Subtle",value:"subtle"},{label:"Gradient",value:"gradient",disabled:!0}];function tf({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaultsDeep({},t,_r),[t]),l=a;h.useEffect(()=>{!y.isEqual(a,l)&&(console.log("config malformed, resetting to defaults",a,l),r(l))},[a,l]);const{control:o,handleSubmit:i,watch:c,formState:d,reset:u}=b.useForm({defaultValues:l});return h.useEffect(()=>{u(l)},[l]),c(["content","variant","color","size","compact","horizontal_align","vertical_align"]),n.jsxs("form",{onSubmit:i(r),children:[n.jsx(ae,{canSubmit:d.isDirty}),n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{control:o,name:"content",render:({field:p})=>n.jsx(s.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...p,required:!0})}),n.jsx(s.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(b.Controller,{control:o,name:"variant",render:({field:p})=>n.jsx(s.Select,{label:"Variant",data:ef,...p})}),n.jsx(b.Controller,{control:o,name:"color",render:({field:p})=>n.jsx(Hg,{label:"Theme",...p})})]}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(b.Controller,{control:o,name:"size",render:({field:p})=>n.jsx(xr,{label:"Size",...p})}),n.jsx(b.Controller,{control:o,name:"compact",render:({field:p})=>n.jsx(s.Checkbox,{label:"Compact",checked:p.value,onChange:f=>p.onChange(f.currentTarget.checked),mt:26})})]}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(b.Controller,{control:o,name:"horizontal_align",render:({field:p})=>n.jsx(yr,{...p})}),n.jsx(b.Controller,{control:o,name:"vertical_align",render:({field:p})=>n.jsx(wl,{...p})})]})]})]})}const nf=[{lang:"en",resources:{button:{viz_name:"Button",click:{label:"Click this button"}}}},{lang:"zh",resources:{button:{viz_name:"按钮",click:{label:"点击此按钮"}}}}];class rf extends ee{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>{const{horizontal_align:a="left",vertical_align:l="center",...o}=r.config;return{...r,version:2,config:{...o,horizontal_align:a,vertical_align:l}}})}}const af={displayName:"viz.button.viz_name",displayGroup:"chart.groups.others",migrator:new rf,name:"button",viewRender:Jg,configRender:tf,createConfig(){return{version:2,config:y.cloneDeep(_r)}},triggers:[Sl],translation:nf},sf=({option:e,...t})=>{const{label:r,description:a}=e;return n.jsx(s.Box,{...t,children:n.jsxs(s.Stack,{gap:"0",children:[n.jsx(s.Text,{size:"sm",children:r}),n.jsx(s.Text,{size:"xs",opacity:.65,children:a})]})})},lf=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a,i18n:l}=x.useTranslation(),o=h.useMemo(()=>[{label:a("chart.series.line.area_style.origin.auto.label"),description:a("chart.series.line.area_style.origin.auto.description"),value:"auto"},{label:a("chart.series.line.area_style.origin.start.label"),description:a("chart.series.line.area_style.origin.start.description"),value:"start"},{label:a("chart.series.line.area_style.origin.end.label"),description:a("chart.series.line.area_style.origin.end.description"),value:"end"}],[l.language]);return n.jsx(s.Select,{ref:r,label:a("chart.series.line.area_style.origin.label"),data:o,value:e,onChange:Z(t),renderOption:sf,size:"xs"})}),Tl=h.forwardRef(({value:e,onChange:t,label:r,placeholder:a},l)=>n.jsx(s.ColorInput,{ref:l,label:r,placeholder:a,value:e,onChange:t,size:"xs",popoverProps:{withinPortal:!0,zIndex:340},rightSection:e?n.jsx(s.CloseButton,{size:"sm",onClick:()=>{t("")}}):null})),of=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a}=x.useTranslation(),l=o=>i=>{const c=y.cloneDeep(e);y.set(c,o,i),t(c)};return n.jsxs(s.Stack,{ref:r,children:[n.jsx(s.Divider,{mt:10,mb:-10,variant:"dashed",label:n.jsxs(s.Group,{gap:6,children:[n.jsx(S.IconChartAreaLineFilled,{size:14,style:{color:"#999"}}),a("chart.series.line.area_style.label")]}),labelPosition:"center"}),n.jsx(s.Switch,{label:a("chart.series.line.area_style.enabled"),checked:e.enabled,onChange:o=>l("enabled")(o.currentTarget.checked)}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(Tl,{label:a("chart.series.line.area_style.color"),placeholder:a("chart.series.line.area_style.use_series_color"),value:e.color,onChange:l("color")}),n.jsx(s.NumberInput,{size:"xs",label:a("chart.series.line.area_style.opacity"),value:e.opacity,onChange:l("opacity"),step:.1,decimalScale:1,min:0,max:1})]}),n.jsx(lf,{value:e.origin,onChange:l("origin")}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(Tl,{label:a("chart.series.line.area_style.shadow_color"),value:e.shadowColor,onChange:l("shadowColor")}),n.jsx(s.NumberInput,{size:"xs",label:a("chart.series.line.area_style.shadow_blur"),value:e.shadowBlur,onChange:l("shadowBlur")})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.NumberInput,{size:"xs",label:a("chart.series.line.area_style.shadow_offset_x"),value:e.shadowOffsetX,onChange:l("shadowOffsetX")}),n.jsx(s.NumberInput,{size:"xs",label:a("chart.series.line.area_style.shadow_offset_y"),value:e.shadowOffsetY,onChange:l("shadowOffsetY")})]})]})});function kl(){return{enabled:!1,color:"",origin:"auto",shadowBlur:0,shadowColor:"",shadowOffsetX:0,shadowOffsetY:0,opacity:.7}}const zl=h.forwardRef(({label:e,value:t,onChange:r,hiddenKeys:a},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>{let _=[{label:o("chart.series_order.name"),value:"name"},{label:o("chart.series_order.value"),value:"value"},{label:o("chart.series_order.raw"),value:""}];if(a&&Array.isArray(a)&&a.length>0){const w=new Set(a);_=_.filter(m=>!w.has(m.value))}return _},[i.language,a]),d=h.useMemo(()=>[{label:o("chart.series_order.asc"),value:"asc"},{label:o("chart.series_order.desc"),value:"desc"}],[i.language,a]),{key:u,order:p}=t,f=_=>{_!==null&&r({key:_,order:p})},v=_=>{_&&r({key:u,order:_})};return n.jsxs(s.Group,{gap:"xs",grow:!0,align:"flex-end",children:[n.jsx(s.Select,{ref:l,label:e,data:c,value:u,onChange:f}),u!==""&&n.jsx(s.SegmentedControl,{size:"sm",data:d,value:p,onChange:v})]})}),dn=()=>({key:"",order:"desc"});function cf(e){const t=y.cloneDeep(y.omit(e,"variables"));return t.stats=y.omit(t.stats,"variables"),t}function df(e){const{rotate:t,formatter:r=ye()}=e.x_axis.axisLabel;return{...e,x_axis:{...e.x_axis,axisLabel:{rotate:t,formatter:r}}}}function uf(e){const{dataZoom:t=wt,...r}=e;return{...r,dataZoom:t}}function pf(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(t,e)}function hf(e){const t=e.reference_lines.map(r=>{const{lineStyle:a={type:"dashed",width:1,color:Be.random().css()},show_in_legend:l=!1}=r;return{...r,lineStyle:a,show_in_legend:l}});return{...e,reference_lines:t}}function gf(e){const t=e.reference_lines.map(r=>{const{yAxisIndex:a=0}=r;return{...r,yAxisIndex:a}});return{...e,reference_lines:t}}function ff(e){const t=e.series.map(r=>{const{aggregation_on_group:a=kt}=r;return{...r,aggregation_on_group:a}});return{...e,series:t}}function bf(e){const t=e.series.map(r=>{const{aggregation_on_value:a=kt}=r;return{...r,aggregation_on_value:a}});return{...e,series:t}}function yf(e){delete e.config;const{x_axis:t,tooltip:r}=e.x_axis.axisLabel.overflow,a={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:r}}}};return y.defaultsDeep(a,e)}function vf(e){const{series:t,...r}=e;return{...r,series:t.map(a=>{const{barMinWidth:l,barWidth:o,barMaxWidth:i}=a;return l?{...a,barMinWidth:l,barWidth:"",barMaxWidth:i??o}:{...a,barMinWidth:"",barWidth:o,barMaxWidth:""}})}}function _f(e){const{y_axes:t,...r}=e;return{...r,y_axes:t.map(a=>{const{min:l="",max:o=""}=a;return{...a,min:l,max:o}})}}function xf(e){const{y_axes:t,...r}=e;return{...r,y_axes:t.map(a=>{const{nameAlignment:l="left"}=a;return{...a,nameAlignment:l}})}}function wf(e){const{y_axes:t,...r}=e;return{...r,y_axes:t.map(a=>{const{show:l=!0}=a;return{...a,show:l}})}}function mf(e){const{regressions:t,...r}=e;return{...r,regressions:t.map(a=>{const{group_by_key:l=""}=a;return{...a,group_by_key:l}})}}function Cf(e){const{series:t,y_axes:r,...a}=e;return{...a,series:t.map(l=>{const{hide_in_legend:o=!1,aggregation_on_value:i=kt}=l;return{...l,hide_in_legend:o,aggregation_on_value:i}}),y_axes:r.map(l=>{const{min:o="",max:i="",show:c=!0}=l;return{...l,min:o,max:i,show:c}})}}function Sf(e){const{type:t="category",...r}=e.x_axis;return{...e,x_axis:{...r,type:t}}}function Tf(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{x_axis_data_key:l,series:o,regressions:i,...c}=e;return{...c,x_axis_data_key:a(l),series:o.map(d=>({...d,y_axis_data_key:a(d.y_axis_data_key),group_by_key:a(d.group_by_key)})),regressions:i.map(d=>({...d,y_axis_data_key:a(d.y_axis_data_key),group_by_key:a(d.group_by_key)}))}}catch(r){throw console.error("[Migration failed]",r),r}}function kf(e){const{tooltip:t={metrics:[]},...r}=e;return{...e,tooltip:t}}function zf(e,t){const{stats:r,...a}=e,l=It(r.templates.top,t),o=It(r.templates.bottom,t);return{stats:{top:l??"",bottom:o??""},...a}}function Df(e){const{series:t,...r}=e,a=t.map(l=>{const{areaStyle:o=kl(),...i}=l;return{...i,areaStyle:o}});return{...r,series:a}}function If(e){const{series:t,...r}=e,a=t.map(l=>{const{order_in_group:o=dn(),...i}=l;return{...i,order_in_group:o}});return{...r,series:a}}function Mf(e){const{series:t,...r}=e,a=t.map(l=>{const{unit:o=U(),...i}=l;return{...i,unit:o}});return{...r,series:a}}function Vf(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??U()}))}}}class Pf extends ee{constructor(){super(...arguments);V(this,"VERSION",24)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,(r,{panelModel:a})=>{const{config:l}=r;return(l.variables||[]).forEach(c=>{a.variables.find(d=>d.name===c.name)||a.addVariable(c)}),(y.get(l,"stats.variables")||[]).forEach(c=>{a.variables.find(d=>d.name===c.name)||a.addVariable(c)}),{...r,version:2,config:cf(l)}}),this.version(3,r=>({...r,version:3,config:df(r.config)})),this.version(4,r=>({...r,version:4,config:uf(r.config)})),this.version(5,r=>({...r,version:5,config:pf(r.config)})),this.version(6,r=>({...r,version:6,config:hf(r.config)})),this.version(7,r=>({...r,version:7,config:gf(r.config)})),this.version(8,r=>({...r,version:8,config:ff(r.config)})),this.version(9,r=>({...r,version:9,config:bf(r.config)})),this.version(10,r=>({...r,version:10,config:yf(r.config)})),this.version(11,r=>({...r,version:11,config:vf(r.config)})),this.version(12,r=>({...r,version:12,config:_f(r.config)})),this.version(13,r=>({...r,version:13,config:xf(r.config)})),this.version(14,r=>({...r,version:14,config:wf(r.config)})),this.version(15,r=>({...r,version:15,config:mf(r.config)})),this.version(16,r=>({...r,version:16,config:Cf(r.config)})),this.version(17,r=>({...r,version:17,config:Sf(r.config)})),this.version(18,(r,a)=>({...r,version:18,config:Tf(r.config,a)})),this.version(19,r=>({...r,version:19,config:kf(r.config)})),this.version(20,(r,a)=>({...r,version:20,config:zf(r.config,a.panelModel)})),this.version(21,(r,a)=>({...r,version:21,config:Df(r.config)})),this.version(22,(r,a)=>({...r,version:22,config:If(r.config)})),this.version(23,(r,a)=>({...r,version:23,config:Mf(r.config)})),this.version(24,(r,a)=>({...r,version:24,config:Vf(r.config)}))}}const Af=[{lang:"en",resources:{cartesian_chart:{viz_name:"Cartesian Chart",series:{aggregation:{label:"Aggregation on Value"}},click_series:{label:"Click bar, line or scatter"}}}},{lang:"zh",resources:{cartesian_chart:{viz_name:"复合图",series:{aggregation:{label:"聚合数据"}},click_series:{label:"点击柱、线或散点"}}}}],wr={id:"builtin:echarts:click-echart:series",displayName:"viz.cartesian_chart.click_series.label",nameRender:Ef,configRender:$f,payload:[{name:"seriesType",description:"'line' | 'scatter' | 'bar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function $f(e){return n.jsx(n.Fragment,{})}function Ef(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.cartesian_chart.click_series.label")})}const Dl={regressions:[],series:[],stats:{bottom:"",top:""},x_axis:{type:"category",axisLabel:{rotate:0,formatter:ye(),overflow:De()}},tooltip:{metrics:[]},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:ce,mirror:!1}],reference_lines:[],reference_areas:[],dataZoom:wt},un=T.observer(({value:e,context:t,onHeightChange:r})=>{var f;const{ref:a}=ne.useElementSize(),l=J(),{panel:o}=fe(),{variables:i,data:c}=t,d=h.useMemo(()=>ht(e,i,l.payloadForViz,c),[e,i,c]),u=((f=a.current)==null?void 0:f.textContent)==="";h.useEffect(()=>{if(!r||!a.current)return;const v=u?0:a.current.offsetHeight;r(v)},[u,a.current]);const p=h.useMemo(()=>u?"none":"block",[u]);return n.jsx(s.Box,{sx:{display:p},children:n.jsx(Dt,{ref:a,value:d,styles:{root:{margin:"0 8px",border:"none",maxWidth:"100%","&.mantine-RichTextEditor-root":{overflow:"auto !important"}},content:{"&.mantine-RichTextEditor-content .ProseMirror":{padding:0},"&.mantine-RichTextEditor-content .ProseMirror > p":{fontSize:"12px",lineHeight:"20px"}}},dashboardStateValues:l.dashboardStateValues,variableAggValueMap:o.variableAggValueMap})})});function Bf(e){const t=e.y_axes.some(l=>!!l.name);let r=15;t&&(r+=20),e.dataZoom.x_axis_slider&&(r+=20);let a=5;return e.x_axis_name&&(a+=15),e.series.some(l=>!l.hide_in_legend)&&(a+=20),{top:r,right:15,bottom:a,left:20,containLabel:!0}}function Lf(e){return e!=="line"?{}:{itemStyle:{opacity:0}}}function qf(e){switch(e){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function Of(e,t){const r=e.series.reduce((l,{unit:o,name:i})=>(o.show_in_legend&&(l[i]=o.text),l),{}),a={show:!0,bottom:0,left:"center",type:"scroll",formatter:l=>{const o=r[l];return o?`${l}(${o})`:l}};return a.data=t.filter(l=>!l.hide_in_legend).map(({name:l,type:o})=>({name:l,icon:qf(o),...Lf(o)})),a}function pn(e,t){switch(e.config.method){case"linear":return[...ut.regressionLinear()(t)];case"exponential":return[...ut.regressionExp()(t)];case"logistic":return[...ut.regressionLog()(t)];case"polynomial":return[...ut.regressionPoly().order(e.config.order)(t)];default:return[]}}function Nf(e,t,r,a){const{transform:l,plot:o}=e,i={...o,name:t,data:pn(l,a),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return r&&(i.custom={type:"regression-line",targetSeries:r}),i}function Gf({regressions:e=[],x_axis_data_key:t},r){const a=[];if(Object.keys(r).length===0)return a;function l(o,i,c,d){const u=Nf(o,i,c,d);a.push(u)}return e.forEach(o=>{const{name:i,group_by_key:c}=o;if(!c||c===t){const f=Ae(r,o.y_axis_data_key).map((v,_)=>[_,Number(v)]);l(o,i,"",f);return}const{columnKey:d}=P(o.y_axis_data_key),u=y.groupBy(Rt(r,o.y_axis_data_key),c);Object.entries(u).forEach(([p,f])=>{const v=f.map((w,m)=>[m,Number(w[d])]);l(o,p,p,v)})}),a}function Ff(e,t){return e.map(r=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:r.color},data:[[{yAxis:t[r.y_keys.upper]},{yAxis:t[r.y_keys.lower]}]],silent:!0}}))}function jf(e,t,r,a){return t?a==="value"?[[r[0],e]]:[e]:[]}function Qf(e,t,r,a,l,o){return e.map(i=>{const c=r[i.variable_key],d=i.orientation==="horizontal",u=d?"yAxis":"xAxis",p=d?"insideEndTop":"end",f=jf(c,d,l,o);return{name:i.name,type:"scatter",hide_in_legend:!i.show_in_legend,xAxisId:"main-x-axis",yAxisIndex:i.yAxisIndex,data:f,symbol:"none",silent:!0,tooltip:{show:!1},markLine:{data:[{name:i.name,[u]:c}],silent:!0,symbol:["none","none"],lineStyle:i.lineStyle,label:{formatter:function(){return i.template?jt(i.template,t,a):""},position:p}}}})}function mr(e,t,r){const a=Ae(e,t),l=Ae(e,r);return y.zip(a,l)}function Wf(e,t,r,a){const l=mr(t,r,a);return y.unionBy(l,e,0)}function Uf({dataTemplate:e,data:t,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:l}){return l?Wf(e,t,r,a):Ae(t,a)}function Kf({dataTemplate:e,data:t,aggregation_on_value:r,x_axis_data_key:a,y_axis_data_key:l,valueTypedXAxis:o}){if(!r||r.type==="none")return Uf({dataTemplate:e,data:t,x_axis_data_key:a,y_axis_data_key:l,valueTypedXAxis:o});const i=mr(t,a,l),c=y.groupBy(i,"0");return e.map(([u])=>{const f=c[u].map(_=>_[1]),v=Nn(f,r);return[u,v]})}function Yf({group_by_key:e,data:t,x_axis_data_key:r,y_axis_data_key:a}){const{queryID:l,columnKey:o}=P(e),i=y.groupBy(t[l],o);return Object.entries(i).forEach(([c,d])=>{i[c]=mr({[l]:d},r,a)}),i}function Xf({type:e,...t},r,a,l){if(!e)return 10;if(e==="static"){const{size:u}=t;return u}const{func_content:o}=t,{queryID:i,columnKey:c}=P(a),d=y.keyBy(Rt(r,i),c);return(u,p)=>{let f;p.name?f=d[p.name]:f=r[p.dataIndex];try{return new Function(`return ${o}`)()({rowData:f,params:p,variables:l},{lodash:y,interpolate:ot.interpolate})}catch(v){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${v.message}`),10}}}function Zf({x_axis_data_key:e,x_axis:t},{y_axis_data_key:r,yAxisIndex:a,label_position:l,name:o,unit:i,group_by_key:c,order_in_group:d,aggregation_on_value:u,stack:p,color:f,display_name_on_line:v,symbolSize:_,hide_in_legend:w,areaStyle:m,...k},z,D,I,L){const E=t.type!=="category",K={label:{show:!!l,position:l,formatter:L[a??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:a,stack:p,color:f,symbolSize:Xf(_,D,e,I),hide_in_legend:w,labelLayout:{hideOverlap:!0},...k};if(k.type==="line"&&(K.lineStyle={width:k.lineStyle.width,type:k.lineStyle.type,shadowColor:"rgba(255,255,255,1)",shadowBlur:0,shadowOffsetX:0,shadowOffsetY:y.clamp(k.lineStyle.width,1,3)},m.enabled)){K.lineStyle.shadowColor="transparent";const{enabled:xe,...lt}=m;K.areaStyle={...lt,color:lt.color||f}}if(v&&(K.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!c||c===e)return K.data=Kf({dataTemplate:z,data:D,aggregation_on_value:u,x_axis_data_key:e,y_axis_data_key:r,valueTypedXAxis:E}),K;const N=Yf({group_by_key:c,data:D,x_axis_data_key:e,y_axis_data_key:r});let le=Object.entries(N);return d.key==="name"&&(le=y.orderBy(Object.entries(N),0,[d.order])),le.map(([xe,lt])=>{const yt=y.cloneDeep(K);return yt.name=xe,yt.color=void 0,"areaStyle"in yt&&(yt.areaStyle.color=void 0),yt.data=lt,yt})}function Jf(e,t,r,a,l,o){const i=t.map(d=>[d,0]);return e.series.map(d=>Zf(e,d,i,r,o,a)).flat().concat(Qf(e.reference_lines,l,o,r,t,e.x_axis.type)).concat(Ff(e.reference_areas,o))}function Hf(e,t){const r=e.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!r)return"";const{axisValue:a,axisIndex:l}=r;return ze(t.x_axis.axisLabel.formatter)(a,l)}const Rf=e=>Y(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function eb(e,t,r,a){const l=r.reduce((c,{yAxisIndex:d,name:u})=>(c[u]=d,c),{}),o=e.series.reduce((c,{unit:d,name:u})=>(d.show_in_tooltip&&(c[u]=d.text),c),{}),i=e.tooltip.metrics.reduce((c,{unit:d,name:u})=>(d.show_in_tooltip&&(c[u]=d.text),c),{});return X.getTooltip({trigger:"axis",formatter:function(c){const d=Array.isArray(c)?c:[c];if(d.length===0)return"";const u=d.map(({seriesName:_,marker:w,value:m})=>{if(Array.isArray(m)&&m.length===2&&(m=m[1]),!_)return m;const k=o[_]??"",z=l[_],D=a[z]??a.default;return`
120
120
  <tr>
121
121
  <td>${w}</td>
122
122
  <th style="text-align: right; padding: 0 1em;">${_}</th>
@@ -127,15 +127,15 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
127
127
  ${k??""}
128
128
  </th>
129
129
  </tr>
130
- `}),p=e.tooltip.metrics.map(_=>{const w=Ve(t,_.data_key),m=y.uniq(d.map(({dataIndex:z})=>w[z])),k=i[_.name]??"";return`
130
+ `}),p=e.tooltip.metrics.map(_=>{const w=Ae(t,_.data_key),m=y.uniq(d.map(({dataIndex:z})=>w[z])),k=i[_.name]??"";return`
131
131
  <tr>
132
132
  <td />
133
133
  <th style="text-align: right; padding: 0 1em;">${_.name}</th>
134
- ${m.map(z=>`<td style="text-align: left; padding: 0 2px 0 1em;" >${Zf(z)}</td>`)}
134
+ ${m.map(z=>`<td style="text-align: left; padding: 0 2px 0 1em;" >${Rf(z)}</td>`)}
135
135
  <th style="text-align: left; padding: 0;">
136
136
  ${k??""}
137
137
  </th>
138
- </tr>`});u.push(...p);const f=Ee(e.x_axis.axisLabel.overflow.in_tooltip),v=Xf(d,e);return`
138
+ </tr>`});u.push(...p);const f=Ee(e.x_axis.axisLabel.overflow.in_tooltip),v=Hf(d,e);return`
139
139
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
140
140
  <div style="${f}">${v}</div>
141
141
  </div>
@@ -144,8 +144,8 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
144
144
  ${u.join("")}
145
145
  </tbody>
146
146
  </table>
147
- `}})}function Hf(e){return e.y_axes.reduce((r,{label_formatter:a},l)=>(r[l]=function(i){let c=i;if(typeof i=="object"&&(Array.isArray(i.value)&&i.value.length===2?c=i.value[1]:c=i.value),!a)return c;try{return Y(c,a)}catch(d){return console.error(d),c}},r),{default:({value:r})=>r})}function Cr(e,t){const r={};return t.map(a=>{const l=Re(a,e);r[a.name]=$e(a,l)}),r}function Rf(e,t){const{overflow:r,...a}=e.x_axis.axisLabel,l=Be(r.on_axis),o=t.length===0;return[X.getXAxis({data:t,name:e.x_axis_name??"",nameGap:o?5:void 0,id:"main-x-axis",type:e.x_axis.type,axisLabel:{...a,...l,formatter:xe(a.formatter)}})]}function eb(e){var t;if(!e)return[];try{return Array.isArray(e[0])&&((t=e[0])==null?void 0:t.length)>=2?e.map(a=>Number(a[1])):[...e]}catch(r){return console.error(r),[...e]}}function tb(e){if(e.length===0)return{};const t={},r={};return e.forEach(a=>{const l=eb(a.data);if(!r[a.yAxisIndex]){r[a.yAxisIndex]=l;return}r[a.yAxisIndex]=r[a.yAxisIndex].concat(l)}),Object.entries(r).forEach(([a,l])=>{const o=y.minBy(l)??0,i=y.maxBy(l)??0;o==0&&i==0&&(t[a]=1)}),t}function zl(e,t,r,a,l){return a?o=>{const i=t&&Number.isFinite(Number(t))?Math.abs(Number(t)):Math.abs(o.min),c=r&&Number.isFinite(Number(r))?Math.abs(Number(r)):Math.abs(o.max),d=Math.max(i,c,0);return l*d}:e||void 0}function nb(e,t,r){const a=tb(r);return e.y_axes.map(({nameAlignment:l,min:o,max:i,show:c,mirror:d,...u},p)=>{let f=u.position;return f||(f=p>0?"right":"left"),X.getYAxis({...u,minInterval:a[p]??0,show:c,alignTicks:d,min:zl(o,o,i,d,-1),max:zl(i,o,i,d,1),position:f,axisLabel:{show:c,formatter:t[p]??t.default},nameTextStyle:{align:l},nameLocation:"end",nameGap:c?15:0,splitLine:{show:p===0}})})}const rb={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function ab(e,t,r){const a=Cr(t,r),l=Hf(e),o=y.uniq(Ve(t,e.x_axis_data_key)),i=Kf(e,o,t,l,r,a),c=qf(e,t),d={xAxis:Rf(e,o),yAxis:nb(e,l,i),series:[...i,...c],tooltip:Jf(e,t,i,l),grid:Vf(e),legend:Bf(e,i),dataZoom:on(e.dataZoom)};return y.defaultsDeep({},d,rb)}function Dl(e){const t=e.getModel(),r=t.getSeries().map(a=>{if(!a.option.custom)return a.option;const l=t.getColorFromPalette(a.option.custom.targetSeries,null);return a.option.color=l,a.option});e.setOption({...e.getOption(),series:r})}function sb({conf:e,data:t,width:r,height:a,interactionManager:l,variables:o,onChartRenderFinished:i}){const c=mt(t,e.x_axis_data_key),d=Ie(l.triggerManager,wr.id),u=h.useCallback(k=>{const z=y.get(c,k.name,{error:"rowData is not found"});d.forEach(D=>{l.runInteraction(D.id,{...k,rowData:z})})},[c,d,l]),p=h.useMemo(()=>ab(e,t,o),[e,t]),f=h.useRef(),v=O.useLatest(i),_=h.useCallback(()=>{var k;v.current((k=f.current)==null?void 0:k.getOption())},[]),w=h.useMemo(()=>({click:u,finished:_}),[u]),m=k=>{f.current=k,Dl(k)};return h.useEffect(()=>{f.current&&Dl(f.current)},[p]),!r||!a?null:n.jsx(he,{echarts:ce,option:p,style:{width:r,height:a},onEvents:w,onChartReady:m,notMerge:!0,theme:"merico-light"})}const lb=T.observer(({context:e,instance:t})=>{const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},a,kl),[a]),i=e.data,{width:c,height:d}=e.viewport,[u,p]=h.useState(0),[f,v]=h.useState(0),_=Math.max(0,Fe(d)-u-f),w=Ge(c),m=J();function k(z){const D=ht(o.stats.top,e.variables,m.payloadForViz,e.data),I=ht(o.stats.bottom,e.variables,m.payloadForViz,e.data);de(t,{...z,statsAboveViz:D,statsBelowViz:I})}return n.jsxs(_e,{width:c,height:d,children:[n.jsx(un,{onHeightChange:p,value:o.stats.top,context:e}),n.jsx(sb,{onChartRenderFinished:k,variables:l,width:w,height:_,data:i,conf:o,interactionManager:r}),n.jsx(un,{onHeightChange:v,value:o.stats.bottom,context:e})]})});function ob({control:e,index:t,variableOptions:r}){const{t:a,i18n:l}=x.useTranslation(),o=h.useMemo(()=>[{label:a("chart.reference_area.type.rectangle"),value:"rectangle"}],[l.language]),i=h.useMemo(()=>[{label:a("chart.reference_area.direction.horizontal"),value:"horizontal"}],[l.language]);return n.jsxs(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`reference_areas.${t}.name`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.reference_area.label"),required:!0,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`reference_areas.${t}.color`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.color.label"),required:!0,sx:{flex:1},...c})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`reference_areas.${t}.type`,control:e,render:({field:c})=>n.jsx(s.Select,{label:a("chart.reference_area.type.label"),required:!0,data:o,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`reference_areas.${t}.direction`,control:e,render:({field:c})=>n.jsx(s.Select,{label:a("chart.reference_area.direction.label"),required:!0,data:i,sx:{flex:1},...c})})]}),n.jsx(s.Divider,{variant:"dashed",label:a("data.label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`reference_areas.${t}.y_keys.upper`,control:e,render:({field:c})=>n.jsx(s.Select,{label:a("chart.reference_area.boundary.upper"),required:!0,data:r,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`reference_areas.${t}.y_keys.lower`,control:e,render:({field:c})=>n.jsx(s.Select,{label:a("chart.reference_area.boundary.lower"),required:!0,data:r,sx:{flex:1},...c})})]})]})}function ib({control:e,watch:t,variables:r}){const{t:a}=x.useTranslation(),l=()=>({name:"",color:"rgba(0,0,0,0.1)",type:"rectangle",direction:"horizontal",y_keys:{upper:"",lower:""}}),o=(c,d)=>{const u=c.name.trim();return u||d+1},i=h.useMemo(()=>r.map(c=>({label:c.name,value:c.name})),[r]);return n.jsx(H,{control:e,watch:t,name:"reference_areas",getItem:l,addButtonText:a("chart.reference_area.add"),deleteButtonText:a("chart.reference_area.delete"),renderTabName:o,children:({field:c,index:d})=>n.jsx(ob,{control:e,index:d,variableOptions:i})})}const Pt=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>[{label:o("chart.series.line.type.solid"),value:"solid"},{label:o("chart.series.line.type.dashed"),value:"dashed"},{label:o("chart.series.line.type.dotted"),value:"dotted"}],[i.language]);return n.jsx(s.Select,{ref:l,label:e??o("chart.series.line.type.label"),data:c,value:t,onChange:Z(r),sx:a})});function cb({control:e,index:t,watch:r,variableOptions:a,yAxisOptions:l}){const{t:o}=x.useTranslation(),i=r(`reference_lines.${t}.orientation`);return n.jsxs(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:o("common.name"),placeholder:o("chart.reference_line.name_placeholder"),required:!0,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:c})=>n.jsx(s.Select,{label:o("common.data_field"),required:!0,data:a,sx:{flex:1},...c})})]}),n.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:o("chart.content_template.label"),placeholder:o("chart.content_template.hint"),sx:{flex:1},...c})}),n.jsxs(s.Group,{grow:!0,children:[n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:c})=>n.jsx(gt,{label:o("chart.orientation.label"),sx:{flex:1},...c})}),i==="vertical"&&n.jsx(s.Text,{mt:-10,c:"dimmed",size:"12px",children:o("chart.reference_line.orientation.vertical_hint")})]}),i==="horizontal"&&n.jsx(b.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:c,onChange:d,...u}})=>n.jsx(s.Select,{label:o("chart.y_axis.label"),data:l,disabled:l.length===0,...u,value:(c==null?void 0:c.toString())??"",onChange:p=>{if(!p){d(0);return}d(Number(p))},sx:{flex:1}})})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:o("chart.style.label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:c})=>n.jsx(Pt,{sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:c})=>n.jsx(s.NumberInput,{label:o("chart.series.line.line_width"),min:1,max:10,sx:{flexGrow:1},...c})})]}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:c})=>n.jsx(ye,{label:o("chart.color.label"),...c})})}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:o("chart.behavior.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:c})=>n.jsx(s.Checkbox,{label:o("chart.legend.show_in_legend"),checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})]})}function db({control:e,watch:t,variables:r}){const{t:a}=x.useTranslation(),l=()=>({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0}),o=(u,p)=>{const f=u.name.trim();return f||p+1},i=h.useMemo(()=>r.map(u=>({label:u.name,value:u.name})),[r]),c=t("y_axes"),d=h.useMemo(()=>c.map(({name:u},p)=>({label:u,value:p.toString()})),[c]);return n.jsx(H,{control:e,watch:t,name:"reference_lines",getItem:l,addButtonText:a("chart.reference_line.add"),deleteButtonText:a("chart.reference_line.delete"),renderTabName:o,children:({field:u,index:p})=>n.jsx(cb,{control:e,index:p,watch:t,variableOptions:i,yAxisOptions:d})})}function ub({control:e,regressionItem:t,index:r,yAxisOptions:a}){const{t:l,i18n:o}=x.useTranslation(),i=h.useMemo(()=>[{label:l("chart.regression_line.method.linear"),value:"linear"},{label:l("chart.regression_line.method.exponential"),value:"exponential"},{label:l("chart.regression_line.method.logistic"),value:"logistic"},{label:l("chart.regression_line.method.polynomial"),value:"polynomial"}],[o.language]),c=t.transform.config.method;return n.jsxs(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`regressions.${r}.name`,control:e,render:({field:d})=>n.jsx(s.TextInput,{label:l("common.name"),required:!0,sx:{flex:1},...d})}),n.jsx(b.Controller,{name:`regressions.${r}.group_by_key`,control:e,render:({field:d})=>n.jsx(q,{label:l("chart.series.group_by.label_line"),clearable:!0,sx:{flex:1},...d})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`regressions.${r}.y_axis_data_key`,control:e,render:({field:d})=>n.jsx(q,{label:l("common.data_field"),required:!0,sx:{flex:1},...d})}),n.jsx(b.Controller,{name:`regressions.${r}.plot.yAxisIndex`,control:e,render:({field:{value:d,onChange:u,...p}})=>n.jsx(s.Select,{label:l("chart.y_axis.label"),data:a,disabled:a.length===0,...p,value:(d==null?void 0:d.toString())??"",onChange:f=>{if(!f){u(0);return}u(Number(f))},sx:{flex:1}})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`regressions.${r}.transform.config.method`,control:e,render:({field:d})=>n.jsx(s.Select,{label:l("chart.regression_line.method.label"),data:i,sx:{flex:1},...d})}),c==="polynomial"&&n.jsx(b.Controller,{name:`regressions.${r}.transform.config.order`,control:e,render:({field:d})=>n.jsx(s.NumberInput,{label:l("chart.regression_line.method.polynomial_order"),sx:{flex:1},...d})})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:l("chart.series.line.line_style"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`regressions.${r}.plot.lineStyle.type`,control:e,render:({field:d})=>n.jsx(Pt,{sx:{flexGrow:1},...d})}),n.jsx(b.Controller,{name:`regressions.${r}.plot.lineStyle.width`,control:e,render:({field:d})=>n.jsx(s.NumberInput,{label:l("chart.series.line.line_width"),min:1,max:10,sx:{flexGrow:1},...d})})]}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:`regressions.${r}.plot.color`,control:e,render:({field:d})=>n.jsx(ye,{label:l("chart.color.label"),...d})})})]})}function pb({control:e,watch:t}){const{t:r}=x.useTranslation(),a=t("y_axes"),l=h.useMemo(()=>a.map(({name:c},d)=>({label:c,value:d.toString()})),[a]),o=()=>({transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},group_by_key:"",name:"",y_axis_data_key:"",plot:{type:"line",yAxisIndex:0,color:"#666666",lineStyle:{type:"solid",width:1}}}),i=(c,d)=>{const u=c.name.trim();return u||d+1};return n.jsx(H,{control:e,watch:t,name:"regressions",getItem:o,addButtonText:r("chart.regression_line.add"),deleteButtonText:r("chart.regression_line.delete"),renderTabName:i,children:({field:c,index:d})=>n.jsx(ub,{regressionItem:c,control:e,index:d,yAxisOptions:l})})}const hb=({value:e,onChange:t})=>{const r=a=>{a&&t(a)};return n.jsx(s.Box,{children:n.jsx(Te,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Sr={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
148
- `)}},gb=({value:e,onChange:t})=>{const{t:r}=x.useTranslation(),[a,{setTrue:l,setFalse:o}]=O.useBoolean(),[i,c]=h.useState(e),d=()=>{o();const{type:v,func_content:_}=i,w={type:v,func_content:_};c(w),t(w)},u=()=>{o(),c(e)},p=v=>{c(_=>({..._,func_content:v}))},f=()=>{p(Sr.dynamic.func_content)};return n.jsxs(n.Fragment,{children:[n.jsx(s.Box,{sx:{width:"50%"},children:n.jsx(s.Button,{color:"grape",variant:"filled",mt:24,onClick:l,sx:{flexGrow:0},leftSection:n.jsx(S.IconMathFunction,{size:16}),children:r("chart.symbol_size.setup.label")})}),n.jsx(s.Modal,{size:800,title:r("chart.symbol_size.setup.title"),opened:a,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:a&&n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mt:10,mb:-10,label:r("chart.symbol_size.setup.description"),labelPosition:"center",variant:"dashed"}),n.jsx(hb,{value:i.func_content,onChange:p}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:f,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:r("common.actions.reset_to_default")}),n.jsxs(s.Group,{justify:"right",children:[n.jsx(s.Button,{onClick:u,variant:"subtle",children:r("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:d,children:r("common.actions.save")})]})]})]})})]})},fb=({value:e,onChange:t})=>e.type!=="dynamic"?null:n.jsx(gb,{value:e,onChange:t}),bb=({value:e,onChange:t})=>{if(e.type!=="static")return null;const r=a=>{typeof a!="string"&&t({...e,size:a})};return n.jsx(n.Fragment,{children:n.jsx(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:r})})},Tr=h.forwardRef(({label:e,value:t,onChange:r},a)=>{const{t:l,i18n:o}=x.useTranslation(),i=h.useMemo(()=>[{label:l("chart.symbol_size.static"),value:"static"},{label:l("chart.symbol_size.dynamic"),value:"dynamic"}],[o.language]),c=d=>{d!=="static"&&d!=="dynamic"||r({...Sr[d]})};return n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(s.Select,{ref:a,label:e??l("chart.symbol_size.label"),data:i,value:t.type,onChange:c,sx:{flexGrow:1}}),n.jsx(bb,{value:t,onChange:r}),n.jsx(fb,{value:t,onChange:r})]})});function yb({label:e,value:t,onChange:r,pt:a="sm",withFallback:l},o){const{t:i,i18n:c}=x.useTranslation();h.useEffect(()=>{typeof t=="string"&&r({type:t,config:{},fallback:"0"})},[t,r]);const d=w=>{if(w===null)return;const m=w;switch(m){case"quantile":return r({type:"quantile",config:{p:.99},fallback:t.fallback});case"custom":return r({type:"custom",config:{func:Ss},fallback:t.fallback});case"pick_record":return r({type:"pick_record",config:{method:"first"},fallback:t.fallback});default:return r({type:m,config:{},fallback:t.fallback})}},u=w=>{const m=Number(w);Number.isNaN(m)||r({type:"quantile",config:{p:m},fallback:t.fallback})},p=w=>{r({type:"custom",config:{func:w},fallback:t.fallback})},f=w=>{w!=="first"&&w!=="last"||r({type:"pick_record",config:{method:w},fallback:t.fallback})},v=w=>{r({...t,fallback:w.currentTarget.value})},_=h.useMemo(()=>[{label:i("aggregation.option.none"),value:"none"},{label:i("aggregation.option.sum"),value:"sum"},{label:i("aggregation.option.min"),value:"min"},{label:i("aggregation.option.mean"),value:"mean"},{label:i("aggregation.option.median"),value:"median"},{label:i("aggregation.option.max"),value:"max"},{label:i("aggregation.option.cov"),value:"CV"},{label:i("aggregation.option.std"),value:"std"},{label:i("aggregation.option.quantile.label_with_hint"),value:"quantile"},{label:i("aggregation.option.pick_record.label"),value:"pick_record"},{label:i("aggregation.option.custom.label"),value:"custom"}],[c.language]);return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",pt:a,children:[n.jsx(s.Select,{ref:o,label:e,data:_,value:t.type,onChange:d,maxDropdownHeight:600}),t.type==="quantile"&&n.jsx(s.NumberInput,{label:"p",value:t.config.p,onChange:u,decimalScale:2,min:.05,step:.05,max:1}),t.type==="pick_record"&&n.jsx(s.Select,{label:i("aggregation.option.pick_record.method.label"),value:t.config.method,onChange:f,data:[{label:i("aggregation.option.pick_record.method.first"),value:"first"},{label:i("aggregation.option.pick_record.method.last"),value:"last"}]}),t.type==="custom"&&n.jsx(nr,{title:i("aggregation.option.custom.title"),label:"",triggerLabel:i("aggregation.option.custom.label_trigger"),value:t.config.func,onChange:p,defaultValue:Ss,triggerButtonProps:{size:"xs",sx:{flexGrow:0,alignSelf:"center",marginTop:"22px"},leftSection:n.jsx(S.IconMathFunction,{size:16}),color:"grape"}})]}),l&&n.jsx(s.TextInput,{label:i("panel.variable.aggregation.fallback_value"),description:i("panel.variable.aggregation.fallback_value_description"),value:t.fallback,onChange:v})]})}const kr=h.forwardRef(yb),Vt=h.forwardRef(({label:e,value:t,onChange:r,options:a,withOffOption:l=!1},o)=>{const{t:i,i18n:c}=x.useTranslation(),d=h.useMemo(()=>{if(a)return a;const u=[{label:i("chart.label_position.top"),value:"top"},{label:i("chart.label_position.left"),value:"left"},{label:i("chart.label_position.right"),value:"right"},{label:i("chart.label_position.bottom"),value:"bottom"},{label:i("chart.label_position.outside"),value:"outside"},{label:i("chart.label_position.inside"),value:"inside"},{label:i("chart.label_position.inside_left"),value:"insideLeft"},{label:i("chart.label_position.inside_right"),value:"insideRight"},{label:i("chart.label_position.inside_top"),value:"insideTop"},{label:i("chart.label_position.inside_bottom"),value:"insideBottom"},{label:i("chart.label_position.inside_top_left"),value:"insideTopLeft"},{label:i("chart.label_position.inside_bottom_left"),value:"insideBottomLeft"},{label:i("chart.label_position.inside_top_right"),value:"insideTopRight"},{label:i("chart.label_position.inside_bottom_right"),value:"insideBottomRight"}];return l&&u.unshift({label:i("chart.label_position.off"),value:""}),u},[c.language,a,l]);return n.jsx(s.Select,{ref:o,label:e,data:d,value:t,onChange:r})});function vb({control:e,index:t,seriesItem:r}){const{t:a,i18n:l}=x.useTranslation(),o=!!r.barWidth.trim(),i=h.useMemo(()=>[{label:a("chart.series.bar.bar_gap.no_gap"),value:"0%"},{label:a("chart.series.bar.bar_gap.overlap"),value:"-100%"}],[l.language]);return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${t}.stack`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.stack"),placeholder:a("chart.series.bar.stack_hint"),sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.barGap`,control:e,render:({field:c})=>n.jsx(s.Select,{label:a("chart.series.bar.bar_gap.label"),data:i,sx:{flexGrow:1},...c})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.bar_width.min"),disabled:o,sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.bar_width.exact"),sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.bar_width.max"),disabled:o,sx:{flexGrow:1},...c})})]})]})}function _b({control:e,index:t,seriesItem:r}){const{t:a,i18n:l}=x.useTranslation(),o=r.showSymbol,i=h.useMemo(()=>[{label:a("chart.series.line.step.off"),value:"false"},{label:a("chart.series.line.step.start"),value:"start"},{label:a("chart.series.line.step.middle"),value:"middle"},{label:a("chart.series.line.step.end"),value:"end"}],[l.language]);return n.jsxs(n.Fragment,{children:[n.jsx(b.Controller,{name:`series.${t}.stack`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.stack"),placeholder:a("chart.series.bar.stack_hint"),sx:{flexGrow:1},...c})}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:a("chart.series.line.line_settings"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`series.${t}.lineStyle.type`,control:e,render:({field:c})=>n.jsx(Pt,{sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.lineStyle.width`,control:e,render:({field:c})=>n.jsx(s.NumberInput,{label:a("chart.series.line.line_width"),min:1,max:10,sx:{flexGrow:1},...c})})]}),n.jsxs(s.Group,{grow:!0,align:"center",children:[n.jsx(b.Controller,{name:`series.${t}.step`,control:e,render:({field:c})=>n.jsx(s.Select,{label:a("chart.series.line.step.label"),data:i,sx:{flexGrow:1,maxWidth:"48%"},...c,value:String(c.value),onChange:Z(d=>{const u=d==="false"?!1:d;c.onChange(u)})})}),n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:`series.${t}.smooth`,control:e,render:({field:c})=>n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.series.line.smooth_line"),checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})}),n.jsx(b.Controller,{name:`series.${t}.display_name_on_line`,control:e,render:({field:c})=>n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.series.line.show_name_on_line"),checked:c.value??!1,onChange:d=>c.onChange(d.currentTarget.checked)})})})]})]}),n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:`series.${t}.showSymbol`,control:e,render:({field:c})=>n.jsx(s.Box,{mt:10,mb:-10,sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.series.line.show_symbol_on_line"),checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})}),o&&n.jsx(b.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:c})=>n.jsx(Tr,{...c})})]}),n.jsx(b.Controller,{name:`series.${t}.areaStyle`,control:e,render:({field:c})=>n.jsx(af,{...c})})]})}function xb({control:e,index:t}){return n.jsx(b.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:r})=>n.jsx(Tr,{label:"Size",...r})})}function wb({control:e,index:t,seriesItem:r,yAxisOptions:a}){const{t:l}=x.useTranslation(),o=r.type,i=r.group_by_key;return n.jsxs(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[n.jsx(s.Stack,{children:n.jsx(b.Controller,{name:`series.${t}.type`,control:e,render:({field:c})=>n.jsx(s.SegmentedControl,{data:[{label:l("chart.series.line.label"),value:"line"},{label:l("chart.series.bar.label"),value:"bar"},{label:l("chart.series.scatter.label"),value:"scatter"}],...c})})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${t}.name`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:l("chart.series.name"),required:!0,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.yAxisIndex`,control:e,render:({field:{value:c,onChange:d,...u}})=>n.jsx(s.Select,{label:l("chart.series.y_axis"),data:a,disabled:a.length===0,...u,value:(c==null?void 0:c.toString())??"",onChange:p=>{if(!p){d(0);return}d(Number(p))},sx:{flex:1}})})]}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(b.Controller,{name:`series.${t}.y_axis_data_key`,control:e,render:({field:c})=>n.jsx(q,{label:l("chart.series.data_field"),required:!0,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:c})=>n.jsx(kr,{label:l("viz.cartesian_chart.series.aggregation.label"),value:c.value??kt,onChange:c.onChange,pt:0,withFallback:!1})})]}),n.jsx(s.Group,{grow:!0,children:n.jsx(b.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:c})=>n.jsx(q,{label:l("chart.series.group_by.label"),clearable:!0,sx:{flex:1},...c})})}),!!i&&n.jsx(b.Controller,{name:`series.${t}.order_in_group`,control:e,render:({field:c})=>n.jsx(Tl,{label:l("chart.series_order.label"),hiddenKeys:["value"],...c})}),n.jsx(b.Controller,{name:`series.${t}.unit`,control:e,render:({field:c})=>n.jsx(ue,{...c})}),o==="line"&&n.jsx(_b,{index:t,control:e,seriesItem:r}),o==="bar"&&n.jsx(vb,{index:t,control:e,seriesItem:r}),o==="scatter"&&n.jsx(xb,{index:t,control:e}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:l("chart.style.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:`series.${t}.label_position`,control:e,render:({field:c})=>n.jsx(Vt,{label:l("chart.label_position.label"),withOffOption:!0,...c})}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:`series.${t}.color`,control:e,render:({field:c})=>n.jsx(ye,{label:l("chart.color.label"),...c})})}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:l("chart.behavior.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:c})=>n.jsx(s.Checkbox,{label:l("chart.legend.hide_in_legend"),checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})]})}function mb({control:e,watch:t}){const{t:r}=x.useTranslation(),a=()=>({type:"bar",name:te.randomId(),unit:U(),showSymbol:!1,symbolSize:Sr.static,y_axis_data_key:"value",yAxisIndex:0,label_position:"top",display_name_on_line:!1,stack:"",color:"#000",step:!1,smooth:!1,barMinWidth:"1",barWidth:"10%",barMaxWidth:"10",barGap:"0%",lineStyle:{type:"solid",width:1},hide_in_legend:!1,group_by_key:"",order_in_group:dn(),areaStyle:Sl()}),l=(c,d)=>{const u=c.name.trim();return u||d+1},o=t("y_axes"),i=h.useMemo(()=>o.map(({name:c},d)=>({label:c,value:d.toString()})),[o]);return n.jsx(H,{control:e,watch:t,name:"series",getItem:a,addButtonText:r("chart.series.add"),deleteButtonText:r("chart.series.delete"),renderTabName:l,children:({field:c,index:d})=>n.jsx(wb,{control:e,index:d,seriesItem:c,yAxisOptions:i})})}const Cb=T.observer(({control:e,watch:t})=>{const{panel:r}=re(),{t:a}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:"stats.top",control:e,render:({field:l})=>n.jsx(pt,{label:a("chart.stats.template.above_chart"),styles:{root:{flexGrow:1,minHeight:"240px"}},autoSubmit:!0,...l},`${r.id}.stats.top`)}),n.jsx(b.Controller,{name:"stats.bottom",control:e,render:({field:l})=>n.jsx(pt,{label:a("chart.stats.template.under_chart"),styles:{root:{flexGrow:1,minHeight:"240px"}},autoSubmit:!0,...l},`${r.id}.stats.bottom`)})]})}),Sb=({control:e,index:t})=>{const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.unit`,control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})})]})},Tb=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>({id:Date.now().toString(),data_key:"",name:"",unit:U()}),l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:r("chart.tooltip.additional_metrics.description")})]}),n.jsx(H,{control:e,watch:t,name:"tooltip.metrics",getItem:a,addButtonText:r("chart.tooltip.additional_metrics.add"),deleteButtonText:r("chart.tooltip.additional_metrics.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(Sb,{control:e,index:i})})]})};function kb({control:e,watch:t}){return n.jsx(s.Stack,{children:n.jsx(Tb,{control:e,watch:t})})}const zb=()=>{const{t:e}=x.useTranslation();return n.jsxs(s.Group,{sx:{display:"inline-flex"},gap:6,mr:14,children:[n.jsx(s.Text,{size:"sm",children:e("chart.x_axis.x_axis_type")}),n.jsxs(s.HoverCard,{width:340,shadow:"md",position:"top",children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.ActionIcon,{size:"xs",variant:"subtle",sx:{transform:"none !important"},children:n.jsx(S.IconInfoCircle,{})})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(s.Text,{size:"sm",children:n.jsxs(x.Trans,{i18nKey:"chart.axis.type.click_to_learn_more",children:["Click",n.jsx(s.Anchor,{href:"https://echarts.apache.org/en/option.html#xAxis.type",target:"_blank",mx:3,children:"here"}),"to learn more about these options"]})})})]})]})};function Db({control:e,watch:t}){const{t:r,i18n:a}=x.useTranslation();t(["x_axis_data_key","x_axis_name","x_axis"]);const l=h.useMemo(()=>[{label:r("chart.axis.type.value"),value:"value"},{label:r("chart.axis.type.category"),value:"category"},{label:r("chart.axis.type.time"),value:"time"},{label:r("chart.axis.type.log"),value:"log"}],[a.language]);return n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:"x_axis_name",control:e,render:({field:o})=>n.jsx(s.TextInput,{label:r("chart.x_axis.x_axis_name"),sx:{flex:1},...o})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis_data_key",control:e,render:({field:o})=>n.jsx(q,{label:r("chart.x_axis.x_axis_data_field"),required:!0,sx:{flex:1},...o})}),n.jsx(b.Controller,{name:"x_axis.type",control:e,render:({field:o})=>n.jsx(s.Select,{label:n.jsx(zb,{}),required:!0,data:l,sx:{flex:1},...o})})]}),n.jsx(s.Divider,{mb:-15,label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:o})=>n.jsx(nt,{sx:{width:"48%"},...o})}),n.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:o})=>n.jsx(Qe,{...o})})]}),n.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:o})=>n.jsx(We,{...o})})]})}const ft=h.forwardRef(({label:e,value:t,onChange:r,sx:a={},disabled:l},o)=>{const{t:i,i18n:c}=x.useTranslation(),d=h.useMemo(()=>[{label:i("chart.name_text.align.left"),value:"left"},{label:i("chart.name_text.align.center"),value:"center"},{label:i("chart.name_text.align.right"),value:"right"}],[c.language]);return n.jsx(s.Select,{ref:o,label:e??i("chart.name_text.align.label"),data:d,value:t,onChange:Z(r),sx:a,disabled:l})}),Il=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>[{label:o("chart.y_axis.position.left"),value:"left"},{label:o("chart.y_axis.position.right"),value:"right"}],[i.language]);return n.jsx(s.Select,{ref:l,label:e??o("chart.y_axis.position.label"),data:c,value:t,onChange:Z(r),sx:a})});function Ib({control:e,index:t}){const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[n.jsx(s.Divider,{mb:-15,mt:15,variant:"dashed",label:r("common.name"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.y_axis.y_axis_name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:a})=>n.jsx(ft,{sx:{flex:1},...a})})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.y_axis.layout"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:a})=>n.jsx(Il,{sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`y_axes.${t}.mirror`,control:e,render:({field:a})=>n.jsx(s.Checkbox,{pt:20,label:r("chart.y_axis.mirror.label"),checked:a.value,onChange:l=>a.onChange(l.currentTarget.checked)})})]}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.y_axis.label_format"),labelPosition:"center"}),n.jsx(b.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:a})=>n.jsx(Le,{...a})})]}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.y_axis.value_range"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.y_axis.value_min"),...a})}),n.jsx(b.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.y_axis.value_max"),...a})})]})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:r("chart.y_axis.behavior"),labelPosition:"center"}),n.jsx(b.Controller,{name:`y_axes.${t}.show`,control:e,render:({field:a})=>n.jsx(s.Checkbox,{label:r("chart.y_axis.visible"),checked:a.value,onChange:l=>a.onChange(l.currentTarget.checked)})})]})}function Mb({control:e,watch:t}){const{t:r}=x.useTranslation(),a=()=>({name:"",position:"left",nameAlignment:"left",label_formatter:le,min:"",max:"",show:!0,mirror:!1}),l=(i,c)=>{const d=i.name.trim();return d||c+1},o=({field:i,index:c,fields:d})=>d.length<=1;return n.jsx(H,{control:e,watch:t,name:"y_axes",getItem:a,addButtonText:r("chart.y_axis.add"),deleteButtonText:r("chart.y_axis.delete"),renderTabName:l,deleteDisalbed:o,children:({field:i,index:c})=>n.jsx(Ib,{control:e,index:c})})}function Ab({conf:e,setConf:t,context:r}){const{t:a}=x.useTranslation(),{variables:l}=r,o=h.useMemo(()=>y.defaults({},e),[e]),{control:i,handleSubmit:c,watch:d,reset:u,formState:p}=b.useForm({defaultValues:o});return h.useEffect(()=>{u(o)},[o]),d(["dataZoom"]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:c(t),children:[n.jsx(ae,{canSubmit:p.isDirty}),n.jsxs(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axis",children:a("chart.x_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Y Axes",children:a("chart.y_axis.labels")}),n.jsx(s.Tabs.Tab,{value:"Series",children:a("chart.series.label")}),n.jsx(s.Tabs.Tab,{value:"Regression Lines",children:a("chart.regression_line.labels")}),n.jsx(s.Tabs.Tab,{value:"Tooltip",children:a("chart.tooltip.label")}),n.jsx(s.Tabs.Tab,{value:"Stats",children:a("chart.stats.label")}),n.jsx(s.Tabs.Tab,{value:"Reference Lines",children:a("chart.reference_line.labels")}),n.jsx(s.Tabs.Tab,{value:"Reference Areas",children:a("chart.reference_area.labels")}),n.jsx(s.Tabs.Tab,{value:"Zooming",children:a("chart.zooming.label")})]}),n.jsx(s.Tabs.Panel,{value:"X Axis",children:n.jsx(Db,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Y Axes",children:n.jsx(Mb,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Series",children:n.jsx(mb,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Regression Lines",children:n.jsx(pb,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Tooltip",children:n.jsx(kb,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Stats",children:n.jsx(Cb,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Reference Lines",children:n.jsx(db,{variables:l,control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Reference Areas",children:n.jsx(ib,{variables:l,control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Zooming",children:n.jsx(b.Controller,{name:"dataZoom",control:i,render:({field:f})=>n.jsx(cn,{...f})})})]})]})})}function Pb(e){const{value:t,set:r}=B(e.context.instanceData,"config");return t?n.jsx(Ab,{conf:t,setConf:r,...e}):null}const Vb={displayName:"viz.cartesian_chart.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new If,name:"cartesian",viewRender:lb,configRender:Pb,createConfig(){return{version:24,config:y.cloneDeep(kl)}},triggers:[wr],translation:Mf};function $b(e){if(e.enable_value)return e.value}function Eb(e){if(e.enable_value)return e.value}function Bb(e){const t=e.axisLabel.overflow.on_axis.width,r=e.axisLabel.position,a={top:5,left:5,right:5,bottom:5};return e.orient==="vertical"&&y.get(a,r)&&r===e.funnelAlign&&y.set(a,r,t),a}function Lb(e,t){return e.series.map(r=>{const{level_name_data_key:a,level_value_data_key:l,axisLabel:o,min:i,max:c,funnelAlign:d,orient:u,...p}=r;if(!a||!l)return{};const f=A(a),v=A(l),_=t[f.queryID].map(m=>({name:m[f.columnKey],value:m[v.columnKey]})),w=Be(o.overflow.on_axis);return{type:"funnel",...Bb(r),min:$b(i),max:Eb(c),minSize:i.size,maxSize:c.size,...p,label:{show:!0,position:o.position,...w},orient:u,funnelAlign:u==="horizontal"?"center":d,data:_}})}function qb({conf:e,params:t,max:r}){const{name:a,value:l}=t.data,o=Y(l/r,{output:"percent",mantissa:2,trimMantissa:!0,absolute:!1});return[{label:`${t.marker} ${a}`,value:`${l} (${o})`,style:{label:"",value:""}}]}function Ob(e,t){var o;const r=A(e.series[0].level_name_data_key),a=A(e.series[0].level_value_data_key),l=(o=y.maxBy(t[r.queryID],a.columnKey))==null?void 0:o[a.columnKey];return i=>{const d=qb({conf:e,params:i,max:l}).map(p=>`
147
+ `}})}function tb(e){return e.y_axes.reduce((r,{label_formatter:a},l)=>(r[l]=function(i){let c=i;if(typeof i=="object"&&(Array.isArray(i.value)&&i.value.length===2?c=i.value[1]:c=i.value),!a)return c;try{return Y(c,a)}catch(d){return console.error(d),c}},r),{default:({value:r})=>r})}function Cr(e,t){const r={};return t.map(a=>{const l=Je(a,e);r[a.name]=$e(a,l)}),r}function nb(e,t){const{overflow:r,...a}=e.x_axis.axisLabel,l=Fe(r.on_axis),o=t.length===0;return[X.getXAxis({data:t,name:e.x_axis_name??"",nameGap:o?5:void 0,id:"main-x-axis",type:e.x_axis.type,axisLabel:{...a,...l,formatter:ze(a.formatter)}})]}function rb(e){var t;if(!e)return[];try{return Array.isArray(e[0])&&((t=e[0])==null?void 0:t.length)>=2?e.map(a=>Number(a[1])):[...e]}catch(r){return console.error(r),[...e]}}function ab(e){if(e.length===0)return{};const t={},r={};return e.forEach(a=>{const l=rb(a.data);if(!r[a.yAxisIndex]){r[a.yAxisIndex]=l;return}r[a.yAxisIndex]=r[a.yAxisIndex].concat(l)}),Object.entries(r).forEach(([a,l])=>{const o=y.minBy(l)??0,i=y.maxBy(l)??0;o==0&&i==0&&(t[a]=1)}),t}function Il(e,t,r,a,l){return a?o=>{const i=t&&Number.isFinite(Number(t))?Math.abs(Number(t)):Math.abs(o.min),c=r&&Number.isFinite(Number(r))?Math.abs(Number(r)):Math.abs(o.max),d=Math.max(i,c,0);return l*d}:e||void 0}function sb(e,t,r){const a=ab(r);return e.y_axes.map(({nameAlignment:l,min:o,max:i,show:c,mirror:d,...u},p)=>{let f=u.position;return f||(f=p>0?"right":"left"),X.getYAxis({...u,minInterval:a[p]??0,show:c,alignTicks:d,min:Il(o,o,i,d,-1),max:Il(i,o,i,d,1),position:f,axisLabel:{show:c,formatter:t[p]??t.default},nameTextStyle:{align:l},nameLocation:"end",nameGap:c?15:0,splitLine:{show:p===0}})})}const lb={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function ob(e,t,r){const a=Cr(t,r),l=tb(e),o=y.uniq(Ae(t,e.x_axis_data_key)),i=Jf(e,o,t,l,r,a),c=Gf(e,t),d={xAxis:nb(e,o),yAxis:sb(e,l,i),series:[...i,...c],tooltip:eb(e,t,i,l),grid:Bf(e),legend:Of(e,i),dataZoom:on(e.dataZoom)};return y.defaultsDeep({},d,lb)}function Ml(e){const t=e.getModel(),r=t.getSeries().map(a=>{if(!a.option.custom)return a.option;const l=t.getColorFromPalette(a.option.custom.targetSeries,null);return a.option.color=l,a.option});e.setOption({...e.getOption(),series:r})}function ib({conf:e,data:t,width:r,height:a,interactionManager:l,variables:o,onChartRenderFinished:i}){const c=mt(t,e.x_axis_data_key),d=Ie(l.triggerManager,wr.id),u=h.useCallback(k=>{const z=y.get(c,k.name,{error:"rowData is not found"});d.forEach(D=>{l.runInteraction(D.id,{...k,rowData:z})})},[c,d,l]),p=h.useMemo(()=>ob(e,t,o),[e,t]),f=h.useRef(),v=O.useLatest(i),_=h.useCallback(()=>{var k;v.current((k=f.current)==null?void 0:k.getOption())},[]),w=h.useMemo(()=>({click:u,finished:_}),[u]),m=k=>{f.current=k,Ml(k)};return h.useEffect(()=>{f.current&&Ml(f.current)},[p]),!r||!a?null:n.jsx(he,{echarts:ie,option:p,style:{width:r,height:a},onEvents:w,onChartReady:m,notMerge:!0,theme:"merico-light"})}const cb=T.observer(({context:e,instance:t})=>{const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},a,Dl),[a]),i=e.data,{width:c,height:d}=e.viewport,[u,p]=h.useState(0),[f,v]=h.useState(0),_=Math.max(0,Ne(d)-u-f),w=Oe(c),m=J();function k(z){const D=ht(o.stats.top,e.variables,m.payloadForViz,e.data),I=ht(o.stats.bottom,e.variables,m.payloadForViz,e.data);de(t,{...z,statsAboveViz:D,statsBelowViz:I})}return n.jsxs(_e,{width:c,height:d,children:[n.jsx(un,{onHeightChange:p,value:o.stats.top,context:e}),n.jsx(ib,{onChartRenderFinished:k,variables:l,width:w,height:_,data:i,conf:o,interactionManager:r}),n.jsx(un,{onHeightChange:v,value:o.stats.bottom,context:e})]})});function db({control:e,index:t,variableOptions:r}){const{t:a,i18n:l}=x.useTranslation(),o=h.useMemo(()=>[{label:a("chart.reference_area.type.rectangle"),value:"rectangle"}],[l.language]),i=h.useMemo(()=>[{label:a("chart.reference_area.direction.horizontal"),value:"horizontal"}],[l.language]);return n.jsxs(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`reference_areas.${t}.name`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.reference_area.label"),required:!0,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`reference_areas.${t}.color`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.color.label"),required:!0,sx:{flex:1},...c})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`reference_areas.${t}.type`,control:e,render:({field:c})=>n.jsx(s.Select,{label:a("chart.reference_area.type.label"),required:!0,data:o,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`reference_areas.${t}.direction`,control:e,render:({field:c})=>n.jsx(s.Select,{label:a("chart.reference_area.direction.label"),required:!0,data:i,sx:{flex:1},...c})})]}),n.jsx(s.Divider,{variant:"dashed",label:a("data.label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`reference_areas.${t}.y_keys.upper`,control:e,render:({field:c})=>n.jsx(s.Select,{label:a("chart.reference_area.boundary.upper"),required:!0,data:r,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`reference_areas.${t}.y_keys.lower`,control:e,render:({field:c})=>n.jsx(s.Select,{label:a("chart.reference_area.boundary.lower"),required:!0,data:r,sx:{flex:1},...c})})]})]})}function ub({control:e,watch:t,variables:r}){const{t:a}=x.useTranslation(),l=()=>({name:"",color:"rgba(0,0,0,0.1)",type:"rectangle",direction:"horizontal",y_keys:{upper:"",lower:""}}),o=(c,d)=>{const u=c.name.trim();return u||d+1},i=h.useMemo(()=>r.map(c=>({label:c.name,value:c.name})),[r]);return n.jsx(H,{control:e,watch:t,name:"reference_areas",getItem:l,addButtonText:a("chart.reference_area.add"),deleteButtonText:a("chart.reference_area.delete"),renderTabName:o,children:({field:c,index:d})=>n.jsx(db,{control:e,index:d,variableOptions:i})})}const Pt=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>[{label:o("chart.series.line.type.solid"),value:"solid"},{label:o("chart.series.line.type.dashed"),value:"dashed"},{label:o("chart.series.line.type.dotted"),value:"dotted"}],[i.language]);return n.jsx(s.Select,{ref:l,label:e??o("chart.series.line.type.label"),data:c,value:t,onChange:Z(r),sx:a})});function pb({control:e,index:t,watch:r,variableOptions:a,yAxisOptions:l}){const{t:o}=x.useTranslation(),i=r(`reference_lines.${t}.orientation`);return n.jsxs(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:o("common.name"),placeholder:o("chart.reference_line.name_placeholder"),required:!0,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:c})=>n.jsx(s.Select,{label:o("common.data_field"),required:!0,data:a,sx:{flex:1},...c})})]}),n.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:o("chart.content_template.label"),placeholder:o("chart.content_template.hint"),sx:{flex:1},...c})}),n.jsxs(s.Group,{grow:!0,children:[n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:c})=>n.jsx(gt,{label:o("chart.orientation.label"),sx:{flex:1},...c})}),i==="vertical"&&n.jsx(s.Text,{mt:-10,c:"dimmed",size:"12px",children:o("chart.reference_line.orientation.vertical_hint")})]}),i==="horizontal"&&n.jsx(b.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:c,onChange:d,...u}})=>n.jsx(s.Select,{label:o("chart.y_axis.label"),data:l,disabled:l.length===0,...u,value:(c==null?void 0:c.toString())??"",onChange:p=>{if(!p){d(0);return}d(Number(p))},sx:{flex:1}})})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:o("chart.style.label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:c})=>n.jsx(Pt,{sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:c})=>n.jsx(s.NumberInput,{label:o("chart.series.line.line_width"),min:1,max:10,sx:{flexGrow:1},...c})})]}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:c})=>n.jsx(be,{label:o("chart.color.label"),...c})})}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:o("chart.behavior.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:c})=>n.jsx(s.Checkbox,{label:o("chart.legend.show_in_legend"),checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})]})}function hb({control:e,watch:t,variables:r}){const{t:a}=x.useTranslation(),l=()=>({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0}),o=(u,p)=>{const f=u.name.trim();return f||p+1},i=h.useMemo(()=>r.map(u=>({label:u.name,value:u.name})),[r]),c=t("y_axes"),d=h.useMemo(()=>c.map(({name:u},p)=>({label:u,value:p.toString()})),[c]);return n.jsx(H,{control:e,watch:t,name:"reference_lines",getItem:l,addButtonText:a("chart.reference_line.add"),deleteButtonText:a("chart.reference_line.delete"),renderTabName:o,children:({field:u,index:p})=>n.jsx(pb,{control:e,index:p,watch:t,variableOptions:i,yAxisOptions:d})})}function gb({control:e,regressionItem:t,index:r,yAxisOptions:a}){const{t:l,i18n:o}=x.useTranslation(),i=h.useMemo(()=>[{label:l("chart.regression_line.method.linear"),value:"linear"},{label:l("chart.regression_line.method.exponential"),value:"exponential"},{label:l("chart.regression_line.method.logistic"),value:"logistic"},{label:l("chart.regression_line.method.polynomial"),value:"polynomial"}],[o.language]),c=t.transform.config.method;return n.jsxs(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`regressions.${r}.name`,control:e,render:({field:d})=>n.jsx(s.TextInput,{label:l("common.name"),required:!0,sx:{flex:1},...d})}),n.jsx(b.Controller,{name:`regressions.${r}.group_by_key`,control:e,render:({field:d})=>n.jsx(q,{label:l("chart.series.group_by.label_line"),clearable:!0,sx:{flex:1},...d})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`regressions.${r}.y_axis_data_key`,control:e,render:({field:d})=>n.jsx(q,{label:l("common.data_field"),required:!0,sx:{flex:1},...d})}),n.jsx(b.Controller,{name:`regressions.${r}.plot.yAxisIndex`,control:e,render:({field:{value:d,onChange:u,...p}})=>n.jsx(s.Select,{label:l("chart.y_axis.label"),data:a,disabled:a.length===0,...p,value:(d==null?void 0:d.toString())??"",onChange:f=>{if(!f){u(0);return}u(Number(f))},sx:{flex:1}})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`regressions.${r}.transform.config.method`,control:e,render:({field:d})=>n.jsx(s.Select,{label:l("chart.regression_line.method.label"),data:i,sx:{flex:1},...d})}),c==="polynomial"&&n.jsx(b.Controller,{name:`regressions.${r}.transform.config.order`,control:e,render:({field:d})=>n.jsx(s.NumberInput,{label:l("chart.regression_line.method.polynomial_order"),sx:{flex:1},...d})})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:l("chart.series.line.line_style"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`regressions.${r}.plot.lineStyle.type`,control:e,render:({field:d})=>n.jsx(Pt,{sx:{flexGrow:1},...d})}),n.jsx(b.Controller,{name:`regressions.${r}.plot.lineStyle.width`,control:e,render:({field:d})=>n.jsx(s.NumberInput,{label:l("chart.series.line.line_width"),min:1,max:10,sx:{flexGrow:1},...d})})]}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:`regressions.${r}.plot.color`,control:e,render:({field:d})=>n.jsx(be,{label:l("chart.color.label"),...d})})})]})}function fb({control:e,watch:t}){const{t:r}=x.useTranslation(),a=t("y_axes"),l=h.useMemo(()=>a.map(({name:c},d)=>({label:c,value:d.toString()})),[a]),o=()=>({transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},group_by_key:"",name:"",y_axis_data_key:"",plot:{type:"line",yAxisIndex:0,color:"#666666",lineStyle:{type:"solid",width:1}}}),i=(c,d)=>{const u=c.name.trim();return u||d+1};return n.jsx(H,{control:e,watch:t,name:"regressions",getItem:o,addButtonText:r("chart.regression_line.add"),deleteButtonText:r("chart.regression_line.delete"),renderTabName:i,children:({field:c,index:d})=>n.jsx(gb,{regressionItem:c,control:e,index:d,yAxisOptions:l})})}const bb=({value:e,onChange:t})=>{const r=a=>{a&&t(a)};return n.jsx(s.Box,{children:n.jsx(Ce,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Sr={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
148
+ `)}},yb=({value:e,onChange:t})=>{const{t:r}=x.useTranslation(),[a,{setTrue:l,setFalse:o}]=O.useBoolean(),[i,c]=h.useState(e),d=()=>{o();const{type:v,func_content:_}=i,w={type:v,func_content:_};c(w),t(w)},u=()=>{o(),c(e)},p=v=>{c(_=>({..._,func_content:v}))},f=()=>{p(Sr.dynamic.func_content)};return n.jsxs(n.Fragment,{children:[n.jsx(s.Box,{sx:{width:"50%"},children:n.jsx(s.Button,{color:"grape",variant:"filled",mt:24,onClick:l,sx:{flexGrow:0},leftSection:n.jsx(S.IconMathFunction,{size:16}),children:r("chart.symbol_size.setup.label")})}),n.jsx(s.Modal,{size:800,title:r("chart.symbol_size.setup.title"),opened:a,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:a&&n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mt:10,mb:-10,label:r("chart.symbol_size.setup.description"),labelPosition:"center",variant:"dashed"}),n.jsx(bb,{value:i.func_content,onChange:p}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:f,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:r("common.actions.reset_to_default")}),n.jsxs(s.Group,{justify:"right",children:[n.jsx(s.Button,{onClick:u,variant:"subtle",children:r("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:d,children:r("common.actions.save")})]})]})]})})]})},vb=({value:e,onChange:t})=>e.type!=="dynamic"?null:n.jsx(yb,{value:e,onChange:t}),_b=({value:e,onChange:t})=>{if(e.type!=="static")return null;const r=a=>{typeof a!="string"&&t({...e,size:a})};return n.jsx(n.Fragment,{children:n.jsx(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:r})})},Tr=h.forwardRef(({label:e,value:t,onChange:r},a)=>{const{t:l,i18n:o}=x.useTranslation(),i=h.useMemo(()=>[{label:l("chart.symbol_size.static"),value:"static"},{label:l("chart.symbol_size.dynamic"),value:"dynamic"}],[o.language]),c=d=>{d!=="static"&&d!=="dynamic"||r({...Sr[d]})};return n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(s.Select,{ref:a,label:e??l("chart.symbol_size.label"),data:i,value:t.type,onChange:c,sx:{flexGrow:1}}),n.jsx(_b,{value:t,onChange:r}),n.jsx(vb,{value:t,onChange:r})]})});function xb({label:e,value:t,onChange:r,pt:a="sm",withFallback:l},o){const{t:i,i18n:c}=x.useTranslation();h.useEffect(()=>{typeof t=="string"&&r({type:t,config:{},fallback:"0"})},[t,r]);const d=w=>{if(w===null)return;const m=w;switch(m){case"quantile":return r({type:"quantile",config:{p:.99},fallback:t.fallback});case"custom":return r({type:"custom",config:{func:ks},fallback:t.fallback});case"pick_record":return r({type:"pick_record",config:{method:"first"},fallback:t.fallback});default:return r({type:m,config:{},fallback:t.fallback})}},u=w=>{const m=Number(w);Number.isNaN(m)||r({type:"quantile",config:{p:m},fallback:t.fallback})},p=w=>{r({type:"custom",config:{func:w},fallback:t.fallback})},f=w=>{w!=="first"&&w!=="last"||r({type:"pick_record",config:{method:w},fallback:t.fallback})},v=w=>{r({...t,fallback:w.currentTarget.value})},_=h.useMemo(()=>[{label:i("aggregation.option.none"),value:"none"},{label:i("aggregation.option.sum"),value:"sum"},{label:i("aggregation.option.min"),value:"min"},{label:i("aggregation.option.mean"),value:"mean"},{label:i("aggregation.option.median"),value:"median"},{label:i("aggregation.option.max"),value:"max"},{label:i("aggregation.option.cov"),value:"CV"},{label:i("aggregation.option.std"),value:"std"},{label:i("aggregation.option.quantile.label_with_hint"),value:"quantile"},{label:i("aggregation.option.pick_record.label"),value:"pick_record"},{label:i("aggregation.option.custom.label"),value:"custom"}],[c.language]);return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",pt:a,children:[n.jsx(s.Select,{ref:o,label:e,data:_,value:t.type,onChange:d,maxDropdownHeight:600}),t.type==="quantile"&&n.jsx(s.NumberInput,{label:"p",value:t.config.p,onChange:u,decimalScale:2,min:.05,step:.05,max:1}),t.type==="pick_record"&&n.jsx(s.Select,{label:i("aggregation.option.pick_record.method.label"),value:t.config.method,onChange:f,data:[{label:i("aggregation.option.pick_record.method.first"),value:"first"},{label:i("aggregation.option.pick_record.method.last"),value:"last"}]}),t.type==="custom"&&n.jsx(nr,{title:i("aggregation.option.custom.title"),label:"",triggerLabel:i("aggregation.option.custom.label_trigger"),value:t.config.func,onChange:p,defaultValue:ks,triggerButtonProps:{size:"xs",sx:{flexGrow:0,alignSelf:"center",marginTop:"22px"},leftSection:n.jsx(S.IconMathFunction,{size:16}),color:"grape"}})]}),l&&n.jsx(s.TextInput,{label:i("panel.variable.aggregation.fallback_value"),description:i("panel.variable.aggregation.fallback_value_description"),value:t.fallback,onChange:v})]})}const kr=h.forwardRef(xb),At=h.forwardRef(({label:e,value:t,onChange:r,options:a,withOffOption:l=!1},o)=>{const{t:i,i18n:c}=x.useTranslation(),d=h.useMemo(()=>{if(a)return a;const u=[{label:i("chart.label_position.top"),value:"top"},{label:i("chart.label_position.left"),value:"left"},{label:i("chart.label_position.right"),value:"right"},{label:i("chart.label_position.bottom"),value:"bottom"},{label:i("chart.label_position.outside"),value:"outside"},{label:i("chart.label_position.inside"),value:"inside"},{label:i("chart.label_position.inside_left"),value:"insideLeft"},{label:i("chart.label_position.inside_right"),value:"insideRight"},{label:i("chart.label_position.inside_top"),value:"insideTop"},{label:i("chart.label_position.inside_bottom"),value:"insideBottom"},{label:i("chart.label_position.inside_top_left"),value:"insideTopLeft"},{label:i("chart.label_position.inside_bottom_left"),value:"insideBottomLeft"},{label:i("chart.label_position.inside_top_right"),value:"insideTopRight"},{label:i("chart.label_position.inside_bottom_right"),value:"insideBottomRight"}];return l&&u.unshift({label:i("chart.label_position.off"),value:""}),u},[c.language,a,l]);return n.jsx(s.Select,{ref:o,label:e,data:d,value:t,onChange:r})});function wb({control:e,index:t,seriesItem:r}){const{t:a,i18n:l}=x.useTranslation(),o=!!r.barWidth.trim(),i=h.useMemo(()=>[{label:a("chart.series.bar.bar_gap.no_gap"),value:"0%"},{label:a("chart.series.bar.bar_gap.overlap"),value:"-100%"}],[l.language]);return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${t}.stack`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.stack"),placeholder:a("chart.series.bar.stack_hint"),sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.barGap`,control:e,render:({field:c})=>n.jsx(s.Select,{label:a("chart.series.bar.bar_gap.label"),data:i,sx:{flexGrow:1},...c})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.bar_width.min"),disabled:o,sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.bar_width.exact"),sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.bar_width.max"),disabled:o,sx:{flexGrow:1},...c})})]})]})}function mb({control:e,index:t,seriesItem:r}){const{t:a,i18n:l}=x.useTranslation(),o=r.showSymbol,i=h.useMemo(()=>[{label:a("chart.series.line.step.off"),value:"false"},{label:a("chart.series.line.step.start"),value:"start"},{label:a("chart.series.line.step.middle"),value:"middle"},{label:a("chart.series.line.step.end"),value:"end"}],[l.language]);return n.jsxs(n.Fragment,{children:[n.jsx(b.Controller,{name:`series.${t}.stack`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.stack"),placeholder:a("chart.series.bar.stack_hint"),sx:{flexGrow:1},...c})}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:a("chart.series.line.line_settings"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`series.${t}.lineStyle.type`,control:e,render:({field:c})=>n.jsx(Pt,{sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.lineStyle.width`,control:e,render:({field:c})=>n.jsx(s.NumberInput,{label:a("chart.series.line.line_width"),min:1,max:10,sx:{flexGrow:1},...c})})]}),n.jsxs(s.Group,{grow:!0,align:"center",children:[n.jsx(b.Controller,{name:`series.${t}.step`,control:e,render:({field:c})=>n.jsx(s.Select,{label:a("chart.series.line.step.label"),data:i,sx:{flexGrow:1,maxWidth:"48%"},...c,value:String(c.value),onChange:Z(d=>{const u=d==="false"?!1:d;c.onChange(u)})})}),n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:`series.${t}.smooth`,control:e,render:({field:c})=>n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.series.line.smooth_line"),checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})}),n.jsx(b.Controller,{name:`series.${t}.display_name_on_line`,control:e,render:({field:c})=>n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.series.line.show_name_on_line"),checked:c.value??!1,onChange:d=>c.onChange(d.currentTarget.checked)})})})]})]}),n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:`series.${t}.showSymbol`,control:e,render:({field:c})=>n.jsx(s.Box,{mt:10,mb:-10,sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.series.line.show_symbol_on_line"),checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})}),o&&n.jsx(b.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:c})=>n.jsx(Tr,{...c})})]}),n.jsx(b.Controller,{name:`series.${t}.areaStyle`,control:e,render:({field:c})=>n.jsx(of,{...c})})]})}function Cb({control:e,index:t}){return n.jsx(b.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:r})=>n.jsx(Tr,{label:"Size",...r})})}function Sb({control:e,index:t,seriesItem:r,yAxisOptions:a}){const{t:l}=x.useTranslation(),o=r.type,i=r.group_by_key;return n.jsxs(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[n.jsx(s.Stack,{children:n.jsx(b.Controller,{name:`series.${t}.type`,control:e,render:({field:c})=>n.jsx(s.SegmentedControl,{data:[{label:l("chart.series.line.label"),value:"line"},{label:l("chart.series.bar.label"),value:"bar"},{label:l("chart.series.scatter.label"),value:"scatter"}],...c})})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${t}.name`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:l("chart.series.name"),required:!0,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.yAxisIndex`,control:e,render:({field:{value:c,onChange:d,...u}})=>n.jsx(s.Select,{label:l("chart.series.y_axis"),data:a,disabled:a.length===0,...u,value:(c==null?void 0:c.toString())??"",onChange:p=>{if(!p){d(0);return}d(Number(p))},sx:{flex:1}})})]}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(b.Controller,{name:`series.${t}.y_axis_data_key`,control:e,render:({field:c})=>n.jsx(q,{label:l("chart.series.data_field"),required:!0,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:c})=>n.jsx(kr,{label:l("viz.cartesian_chart.series.aggregation.label"),value:c.value??kt,onChange:c.onChange,pt:0,withFallback:!1})})]}),n.jsx(s.Group,{grow:!0,children:n.jsx(b.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:c})=>n.jsx(q,{label:l("chart.series.group_by.label"),clearable:!0,sx:{flex:1},...c})})}),!!i&&n.jsx(b.Controller,{name:`series.${t}.order_in_group`,control:e,render:({field:c})=>n.jsx(zl,{label:l("chart.series_order.label"),hiddenKeys:["value"],...c})}),n.jsx(b.Controller,{name:`series.${t}.unit`,control:e,render:({field:c})=>n.jsx(ue,{...c})}),o==="line"&&n.jsx(mb,{index:t,control:e,seriesItem:r}),o==="bar"&&n.jsx(wb,{index:t,control:e,seriesItem:r}),o==="scatter"&&n.jsx(Cb,{index:t,control:e}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:l("chart.style.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:`series.${t}.label_position`,control:e,render:({field:c})=>n.jsx(At,{label:l("chart.label_position.label"),withOffOption:!0,...c})}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:`series.${t}.color`,control:e,render:({field:c})=>n.jsx(be,{label:l("chart.color.label"),...c})})}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:l("chart.behavior.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:c})=>n.jsx(s.Checkbox,{label:l("chart.legend.hide_in_legend"),checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})]})}function Tb({control:e,watch:t}){const{t:r}=x.useTranslation(),a=()=>({type:"bar",name:ne.randomId(),unit:U(),showSymbol:!1,symbolSize:Sr.static,y_axis_data_key:"value",yAxisIndex:0,label_position:"top",display_name_on_line:!1,stack:"",color:"#000",step:!1,smooth:!1,barMinWidth:"1",barWidth:"10%",barMaxWidth:"10",barGap:"0%",lineStyle:{type:"solid",width:1},hide_in_legend:!1,group_by_key:"",order_in_group:dn(),areaStyle:kl()}),l=(c,d)=>{const u=c.name.trim();return u||d+1},o=t("y_axes"),i=h.useMemo(()=>o.map(({name:c},d)=>({label:c,value:d.toString()})),[o]);return n.jsx(H,{control:e,watch:t,name:"series",getItem:a,addButtonText:r("chart.series.add"),deleteButtonText:r("chart.series.delete"),renderTabName:l,children:({field:c,index:d})=>n.jsx(Sb,{control:e,index:d,seriesItem:c,yAxisOptions:i})})}const kb=T.observer(({control:e,watch:t})=>{const{panel:r}=re(),{t:a}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:"stats.top",control:e,render:({field:l})=>n.jsx(pt,{label:a("chart.stats.template.above_chart"),styles:{root:{flexGrow:1,minHeight:"240px"}},autoSubmit:!0,...l},`${r.id}.stats.top`)}),n.jsx(b.Controller,{name:"stats.bottom",control:e,render:({field:l})=>n.jsx(pt,{label:a("chart.stats.template.under_chart"),styles:{root:{flexGrow:1,minHeight:"240px"}},autoSubmit:!0,...l},`${r.id}.stats.bottom`)})]})}),zb=({control:e,index:t})=>{const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.unit`,control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})})]})},Db=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>({id:Date.now().toString(),data_key:"",name:"",unit:U()}),l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:r("chart.tooltip.additional_metrics.description")})]}),n.jsx(H,{control:e,watch:t,name:"tooltip.metrics",getItem:a,addButtonText:r("chart.tooltip.additional_metrics.add"),deleteButtonText:r("chart.tooltip.additional_metrics.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(zb,{control:e,index:i})})]})};function Ib({control:e,watch:t}){return n.jsx(s.Stack,{children:n.jsx(Db,{control:e,watch:t})})}const Mb=()=>{const{t:e}=x.useTranslation();return n.jsxs(s.Group,{sx:{display:"inline-flex"},gap:6,mr:14,children:[n.jsx(s.Text,{size:"sm",children:e("chart.x_axis.x_axis_type")}),n.jsxs(s.HoverCard,{width:340,shadow:"md",position:"top",children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.ActionIcon,{size:"xs",variant:"subtle",sx:{transform:"none !important"},children:n.jsx(S.IconInfoCircle,{})})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(s.Text,{size:"sm",children:n.jsxs(x.Trans,{i18nKey:"chart.axis.type.click_to_learn_more",children:["Click",n.jsx(s.Anchor,{href:"https://echarts.apache.org/en/option.html#xAxis.type",target:"_blank",mx:3,children:"here"}),"to learn more about these options"]})})})]})]})};function Vb({control:e,watch:t}){const{t:r,i18n:a}=x.useTranslation();t(["x_axis_data_key","x_axis_name","x_axis"]);const l=h.useMemo(()=>[{label:r("chart.axis.type.value"),value:"value"},{label:r("chart.axis.type.category"),value:"category"},{label:r("chart.axis.type.time"),value:"time"},{label:r("chart.axis.type.log"),value:"log"}],[a.language]);return n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:"x_axis_name",control:e,render:({field:o})=>n.jsx(s.TextInput,{label:r("chart.x_axis.x_axis_name"),sx:{flex:1},...o})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis_data_key",control:e,render:({field:o})=>n.jsx(q,{label:r("chart.x_axis.x_axis_data_field"),required:!0,sx:{flex:1},...o})}),n.jsx(b.Controller,{name:"x_axis.type",control:e,render:({field:o})=>n.jsx(s.Select,{label:n.jsx(Mb,{}),required:!0,data:l,sx:{flex:1},...o})})]}),n.jsx(s.Divider,{mb:-15,label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:o})=>n.jsx(nt,{sx:{width:"48%"},...o})}),n.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:o})=>n.jsx(He,{...o})})]}),n.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:o})=>n.jsx(Re,{...o})})]})}const ft=h.forwardRef(({label:e,value:t,onChange:r,sx:a={},disabled:l},o)=>{const{t:i,i18n:c}=x.useTranslation(),d=h.useMemo(()=>[{label:i("chart.name_text.align.left"),value:"left"},{label:i("chart.name_text.align.center"),value:"center"},{label:i("chart.name_text.align.right"),value:"right"}],[c.language]);return n.jsx(s.Select,{ref:o,label:e??i("chart.name_text.align.label"),data:d,value:t,onChange:Z(r),sx:a,disabled:l})}),Vl=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>[{label:o("chart.y_axis.position.left"),value:"left"},{label:o("chart.y_axis.position.right"),value:"right"}],[i.language]);return n.jsx(s.Select,{ref:l,label:e??o("chart.y_axis.position.label"),data:c,value:t,onChange:Z(r),sx:a})});function Pb({control:e,index:t}){const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[n.jsx(s.Divider,{mb:-15,mt:15,variant:"dashed",label:r("common.name"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.y_axis.y_axis_name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:a})=>n.jsx(ft,{sx:{flex:1},...a})})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.y_axis.layout"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:a})=>n.jsx(Vl,{sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`y_axes.${t}.mirror`,control:e,render:({field:a})=>n.jsx(s.Checkbox,{pt:20,label:r("chart.y_axis.mirror.label"),checked:a.value,onChange:l=>a.onChange(l.currentTarget.checked)})})]}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.y_axis.label_format"),labelPosition:"center"}),n.jsx(b.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:a})=>n.jsx(je,{...a})})]}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.y_axis.value_range"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.y_axis.value_min"),...a})}),n.jsx(b.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.y_axis.value_max"),...a})})]})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:r("chart.y_axis.behavior"),labelPosition:"center"}),n.jsx(b.Controller,{name:`y_axes.${t}.show`,control:e,render:({field:a})=>n.jsx(s.Checkbox,{label:r("chart.y_axis.visible"),checked:a.value,onChange:l=>a.onChange(l.currentTarget.checked)})})]})}function Ab({control:e,watch:t}){const{t:r}=x.useTranslation(),a=()=>({name:"",position:"left",nameAlignment:"left",label_formatter:ce,min:"",max:"",show:!0,mirror:!1}),l=(i,c)=>{const d=i.name.trim();return d||c+1},o=({field:i,index:c,fields:d})=>d.length<=1;return n.jsx(H,{control:e,watch:t,name:"y_axes",getItem:a,addButtonText:r("chart.y_axis.add"),deleteButtonText:r("chart.y_axis.delete"),renderTabName:l,deleteDisalbed:o,children:({field:i,index:c})=>n.jsx(Pb,{control:e,index:c})})}function $b({conf:e,setConf:t,context:r}){const{t:a}=x.useTranslation(),{variables:l}=r,o=h.useMemo(()=>y.defaults({},e),[e]),{control:i,handleSubmit:c,watch:d,reset:u,formState:p}=b.useForm({defaultValues:o});return h.useEffect(()=>{u(o)},[o]),d(["dataZoom"]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:c(t),children:[n.jsx(ae,{canSubmit:p.isDirty}),n.jsxs(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axis",children:a("chart.x_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Y Axes",children:a("chart.y_axis.labels")}),n.jsx(s.Tabs.Tab,{value:"Series",children:a("chart.series.label")}),n.jsx(s.Tabs.Tab,{value:"Regression Lines",children:a("chart.regression_line.labels")}),n.jsx(s.Tabs.Tab,{value:"Tooltip",children:a("chart.tooltip.label")}),n.jsx(s.Tabs.Tab,{value:"Stats",children:a("chart.stats.label")}),n.jsx(s.Tabs.Tab,{value:"Reference Lines",children:a("chart.reference_line.labels")}),n.jsx(s.Tabs.Tab,{value:"Reference Areas",children:a("chart.reference_area.labels")}),n.jsx(s.Tabs.Tab,{value:"Zooming",children:a("chart.zooming.label")})]}),n.jsx(s.Tabs.Panel,{value:"X Axis",children:n.jsx(Vb,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Y Axes",children:n.jsx(Ab,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Series",children:n.jsx(Tb,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Regression Lines",children:n.jsx(fb,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Tooltip",children:n.jsx(Ib,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Stats",children:n.jsx(kb,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Reference Lines",children:n.jsx(hb,{variables:l,control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Reference Areas",children:n.jsx(ub,{variables:l,control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Zooming",children:n.jsx(b.Controller,{name:"dataZoom",control:i,render:({field:f})=>n.jsx(cn,{...f})})})]})]})})}function Eb(e){const{value:t,set:r}=B(e.context.instanceData,"config");return t?n.jsx($b,{conf:t,setConf:r,...e}):null}const Bb={displayName:"viz.cartesian_chart.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new Pf,name:"cartesian",viewRender:cb,configRender:Eb,createConfig(){return{version:24,config:y.cloneDeep(Dl)}},triggers:[wr],translation:Af};function Lb(e){if(e.enable_value)return e.value}function qb(e){if(e.enable_value)return e.value}function Ob(e){const t=e.axisLabel.overflow.on_axis.width,r=e.axisLabel.position,a={top:5,left:5,right:5,bottom:5};return e.orient==="vertical"&&y.get(a,r)&&r===e.funnelAlign&&y.set(a,r,t),a}function Nb(e,t){return e.series.map(r=>{const{level_name_data_key:a,level_value_data_key:l,axisLabel:o,min:i,max:c,funnelAlign:d,orient:u,...p}=r;if(!a||!l)return{};const f=P(a),v=P(l),_=t[f.queryID].map(m=>({name:m[f.columnKey],value:m[v.columnKey]})),w=Fe(o.overflow.on_axis);return{type:"funnel",...Ob(r),min:Lb(i),max:qb(c),minSize:i.size,maxSize:c.size,...p,label:{show:!0,position:o.position,...w},orient:u,funnelAlign:u==="horizontal"?"center":d,data:_}})}function Gb({conf:e,params:t,max:r}){const{name:a,value:l}=t.data,o=Y(l/r,{output:"percent",mantissa:2,trimMantissa:!0,absolute:!1});return[{label:`${t.marker} ${a}`,value:`${l} (${o})`,style:{label:"",value:""}}]}function Fb(e,t){var o;const r=P(e.series[0].level_name_data_key),a=P(e.series[0].level_value_data_key),l=(o=y.maxBy(t[r.queryID],a.columnKey))==null?void 0:o[a.columnKey];return i=>{const d=Gb({conf:e,params:i,max:l}).map(p=>`
149
149
  <tr>
150
150
  <th style="text-align: right;">
151
151
  <div style="${p.style.label}">${p.label}</div>
@@ -161,7 +161,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
161
161
  <table style="width: auto">
162
162
  <tbody>${d.join("")}</tbody>
163
163
  </table>
164
- `}}function Nb(e,t){return X.getTooltip({trigger:"item",formatter:Ob(e,t)})}function Gb(e,t){return{grid:{top:0,left:0,right:0,bottom:0},tooltip:Nb(e,t),series:Lb(e,t)}}function Fb(e){return e||(e=Date.now().toString()),{id:e,name:e,level_name_data_key:"",level_value_data_key:"",min:{value:0,enable_value:!1,size:"0%"},max:{value:0,enable_value:!1,size:"100%"},gap:2,axisLabel:{show:!0,position:"inside",overflow:we()},sort:"descending",orient:"vertical",funnelAlign:"center"}}const zr={series:[Fb("Funnel")]};function jb({conf:e,data:t,width:r,height:a,instance:l}){const o=h.useMemo(()=>Gb(e,t),[e,t]),i=h.useRef(null),c=h.useCallback(()=>{var p;const u=(p=i.current)==null?void 0:p.getEchartsInstance();u&&de(l,u.getOption())},[l]),d=h.useMemo(()=>({finished:c}),[c]);return n.jsx(he,{ref:i,onEvents:d,echarts:ce,option:o,style:{width:r,height:a},notMerge:!0,theme:"merico-light"})}function Qb({context:e,instance:t}){const{value:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaults({},r,zr),[r]),l=e.data,{width:o,height:i}=e.viewport;return!o||!i?null:n.jsx(_e,{width:o,height:i,children:n.jsx(jb,{instance:t,width:Ge(o),height:Fe(i),data:l,conf:a})})}const Wb=({item:e,control:t,index:r,remove:a})=>{const{t:l,i18n:o}=x.useTranslation(),i=e.min.enable_value,c=e.max.enable_value,{orient:d}=e,u=h.useMemo(()=>({horizontal:[{label:l("chart.label_position.top"),value:"top"},{label:l("chart.label_position.inside_center"),value:"inside"},{label:l("chart.label_position.bottom"),value:"bottom"}],vertical:[{label:l("chart.label_position.left"),value:"left"},{label:l("chart.label_position.inside_left"),value:"insideLeft"},{label:l("chart.label_position.inside_center"),value:"inside"},{label:l("chart.label_position.inside_right"),value:"insideRight"},{label:l("chart.label_position.right"),value:"right"}]}),[o.language]),p=h.useMemo(()=>[{label:l("viz.funnel_chart.sort.ascending"),value:"ascending"},{label:l("viz.funnel_chart.sort.descending"),value:"descending"},{label:l("viz.funnel_chart.sort.none"),value:"0"}],[o.language]);return n.jsxs(s.Stack,{children:[n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:`series.${r}.name`,control:t,render:({field:f})=>n.jsx(s.TextInput,{label:l("viz.funnel_chart.series_name"),...f})})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${r}.level_name_data_key`,control:t,render:({field:f})=>n.jsx(q,{label:l("viz.funnel_chart.level_name_field"),...f})}),n.jsx(b.Controller,{name:`series.${r}.level_value_data_key`,control:t,render:({field:f})=>n.jsx(q,{label:l("viz.funnel_chart.level_value_field"),...f})})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:l("viz.funnel_chart.funnel_style"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${r}.min.value`,control:t,render:({field:f})=>n.jsx(s.NumberInput,{disabled:!i,labelProps:{display:"block"},label:n.jsxs(s.Group,{justify:"space-between",pr:6,sx:{width:"100%"},children:[n.jsx(s.Text,{size:"sm",children:l("viz.funnel_chart.min_value")}),n.jsx(s.Tooltip,{label:l("viz.funnel_chart.min_value_checkbox_tip"),children:n.jsx(s.Box,{children:n.jsx(b.Controller,{name:`series.${r}.min.enable_value`,control:t,render:({field:v})=>n.jsx(s.Checkbox,{size:"xs",checked:v.value,onChange:_=>v.onChange(_.currentTarget.checked)})})})})]}),...f})}),n.jsx(b.Controller,{name:`series.${r}.min.size`,control:t,render:({field:f})=>n.jsx(s.TextInput,{placeholder:"0%",label:l("viz.funnel_chart.min_size"),...f})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${r}.max.value`,control:t,render:({field:f})=>n.jsx(s.NumberInput,{disabled:!c,labelProps:{display:"block"},label:n.jsxs(s.Group,{justify:"space-between",pr:6,sx:{width:"100%"},children:[n.jsx(s.Text,{size:"sm",children:l("viz.funnel_chart.max_value")}),n.jsx(s.Tooltip,{label:l("viz.funnel_chart.max_value_checkbox_tip"),children:n.jsx(s.Box,{children:n.jsx(b.Controller,{name:`series.${r}.max.enable_value`,control:t,render:({field:v})=>n.jsx(s.Checkbox,{size:"xs",checked:v.value,onChange:_=>v.onChange(_.currentTarget.checked)})})})})]}),...f})}),n.jsx(b.Controller,{name:`series.${r}.max.size`,control:t,render:({field:f})=>n.jsx(s.TextInput,{placeholder:"100%",label:l("viz.funnel_chart.max_size"),...f})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${r}.orient`,control:t,render:({field:f})=>n.jsx(gt,{...f})}),n.jsx(b.Controller,{name:`series.${r}.sort`,control:t,render:({field:f})=>n.jsx(s.Select,{label:l("viz.funnel_chart.sort.label"),data:p,...f})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${r}.funnelAlign`,control:t,render:({field:f})=>n.jsx(ft,{label:l("viz.funnel_chart.align"),disabled:d==="horizontal",...f})}),n.jsx(b.Controller,{name:`series.${r}.gap`,control:t,render:({field:f})=>n.jsx(s.NumberInput,{placeholder:"0, 5, 10...",label:l("viz.funnel_chart.gap"),...f})})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:l("chart.label.label_style"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${r}.axisLabel.position`,control:t,render:({field:f})=>n.jsx(Vt,{label:l("chart.label_position.label"),options:u[d],...f})}),n.jsx(s.Box,{})]}),n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:`series.${r}.axisLabel.overflow`,control:t,render:({field:f})=>n.jsx(We,{...f})})})]})},Ub=({control:e,watch:t})=>{const{fields:r,append:a,remove:l}=b.useFieldArray({control:e,name:"series"}),o=t("series"),i=r.map((p,f)=>({...p,...o[f]})),c=y.get(i,"0.id"),[d,u]=h.useState(c??null);return h.useEffect(()=>{c&&u(p=>p!==null?p:c)},[c]),n.jsxs(s.Tabs,{value:d,onChange:p=>u(p),styles:{panel:{padding:"0px",paddingTop:"6px"}},children:[n.jsxs(s.Tabs.List,{children:[i.map((p,f)=>n.jsx(s.Tabs.Tab,{value:p.id,children:p.name},p.id)),n.jsx(s.Tabs.Tab,{value:"add",disabled:!0,children:n.jsx(s.Tooltip,{label:"todo",children:n.jsx(s.Center,{children:n.jsx(S.IconPlus,{size:18,color:"#228be6"})})})})]}),i.map((p,f)=>n.jsx(s.Tabs.Panel,{value:p.id,children:n.jsx(Wb,{item:p,control:e,index:f,remove:l})},p.id))]})};function Yb({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaultsDeep({},t,zr),[t]),{control:l,handleSubmit:o,watch:i,formState:c,reset:d}=b.useForm({defaultValues:a});return h.useEffect(()=>{d(a)},[a]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:o(r),children:[n.jsx(ae,{canSubmit:c.isDirty}),n.jsx(Ub,{control:l,watch:i})]})})}const Kb=[{lang:"en",resources:{funnel_chart:{viz_name:"Funnel Chart",series_name:"Series Name",level_name_field:"Level Name Field",level_value_field:"Level Value Field",funnel_style:"Funnel Style",min_value:"Min Value",min_value_checkbox_tip:"Check to enable specific min value",max_value:"Max Value",max_value_checkbox_tip:"Check to enable specific max value",min_size:"Min Size",max_size:"Max Size",sort:{label:"Sort",ascending:"Ascending",descending:"Descending",none:"Use original data order"},gap:"Gap",align:"Align"}}},{lang:"zh",resources:{funnel_chart:{viz_name:"漏斗图",series_name:"系列名称",level_name_field:"层名字段",level_value_field:"层值字段",funnel_style:"漏斗样式",min_value:"最小值",min_value_checkbox_tip:"勾选以启用最小值设置",max_value:"最大值",max_value_checkbox_tip:"勾选以启用最大值设置",min_size:"最小尺寸",max_size:"最大尺寸",sort:{label:"排序",ascending:"升序",descending:"降序",none:"依原始数据的顺序"},gap:"间距",align:"对齐"}}}];function Xb(e){return{series:e.series.map(t=>{const{min:r,minSize:a,max:l,maxSize:o,...i}=t;return{...i,min:{value:r,use_data_min:!1,size:a},max:{value:l,use_data_max:!1,size:o}}})}}function Zb(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=i=>i&&`${r}.${i}`,{series:l,...o}=e;return{...o,series:l.map(i=>({...i,level_name_data_key:a(i.level_name_data_key),level_value_data_key:a(i.level_value_data_key)}))}}catch(r){throw console.error("[Migration failed]",r),r}}class Jb extends ee{constructor(){super(...arguments);P(this,"VERSION",3)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>{const{config:a}=r;return{...r,version:2,config:Xb(a)}}),this.version(3,(r,a)=>{const{config:l}=r;return{...r,version:3,config:Zb(l,a)}})}}const Hb={displayName:"viz.funnel_chart.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new Jb,name:"funnel",viewRender:Qb,configRender:Yb,createConfig:()=>({version:3,config:zr}),translation:Kb},Rb=({page:e,setPage:t,totalPages:r})=>n.jsx(s.Pagination,{size:"xs",withControls:!1,siblings:1,color:"gray",value:e,onChange:t,total:r}),ey=({page:e,setPage:t,totalPages:r})=>{const a=h.useMemo(()=>Array.from(new Array(r),(l,o)=>({label:String(o+1),value:String(o+1)})),[r]);return n.jsx(s.NativeSelect,{size:"xs",value:e,onChange:l=>{t(Number(l.currentTarget.value))},data:a})},ty=e=>e.totalPages<=1?null:n.jsx(s.Box,{sx:{position:"absolute",top:"calc(1rem + 5px)",right:"calc(1rem + 5px)",zIndex:2},children:e.width>600?n.jsx(Rb,{...e}):n.jsx(ey,{...e})});function ny(e){const t=xe(e.x_axis.axisLabel.formatter),r=xe(e.y_axis.axisLabel.formatter);return{x_axis:t,y_axis:r}}function ry(e){return{heat_block:function(a){if(!e.heat_block.value_formatter)return a;try{return Y(a,e.heat_block.value_formatter)}catch(l){return console.error(l),a}}}}function ay(e){let t=0;return e.x_axis.name&&(t+=20),{show:!0,top:45,left:5,right:5,bottom:t,containLabel:!0,borderColor:"none",backgroundColor:"#E7E7E9",z:1}}function sy(e,t,r){const{heat_block:a}=e;return{type:"heatmap",name:a.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderColor:"white",borderWidth:r},data:t,label:a.label,labelLayout:{hideOverlap:!0},z:2}}const ly=e=>Y(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function oy({conf:e,labelFormatters:t,valueFormatters:r,dataDict:a,params:l,metricUnitMap:o}){const{value:i,dataIndex:c}=l,[d,u,p]=i,f={label:e.x_axis.name?e.x_axis.name:"X Axis",value:t.x_axis(d,c),style:{label:"",value:Ee(e.x_axis.axisLabel.overflow.in_tooltip)},unit:""},v={label:e.y_axis.name?e.y_axis.name:"Y Axis",value:t.y_axis(u,c),style:{label:"",value:Ee(e.y_axis.axisLabel.overflow.in_tooltip)},unit:""},_={label:e.heat_block.name,value:r.heat_block(p),style:{label:"",value:""},unit:e.heat_block.unit.show_in_tooltip?e.heat_block.unit.text:""},w=[f,v,_],m=a[`${d}---${u}`];return m&&e.tooltip.metrics.forEach(k=>{const z=A(k.data_key),D=o[k.name];w.push({label:k.name,value:ly(y.get(m,z.columnKey,"")),style:{label:"",value:""},unit:D})}),w}function iy(e,t,r,a){const{x_axis:l,y_axis:o,heat_block:i}=e,c=A(l.data_key),d=A(o.data_key);A(i.data_key);const u=y.keyBy(t[c.queryID],f=>`${f[c.columnKey]}---${f[d.columnKey]}`),p=e.tooltip.metrics.reduce((f,{unit:v,name:_})=>(v.show_in_tooltip&&(f[_]=v.text),f),{});return X.getTooltip({formatter:function(f){const _=oy({conf:e,labelFormatters:r,valueFormatters:a,dataDict:u,params:f,metricUnitMap:p}).map(m=>`
164
+ `}}function jb(e,t){return X.getTooltip({trigger:"item",formatter:Fb(e,t)})}function Qb(e,t){return{grid:{top:0,left:0,right:0,bottom:0},tooltip:jb(e,t),series:Nb(e,t)}}function Wb(e){return e||(e=Date.now().toString()),{id:e,name:e,level_name_data_key:"",level_value_data_key:"",min:{value:0,enable_value:!1,size:"0%"},max:{value:0,enable_value:!1,size:"100%"},gap:2,axisLabel:{show:!0,position:"inside",overflow:De()},sort:"descending",orient:"vertical",funnelAlign:"center"}}const zr={series:[Wb("Funnel")]};function Ub({conf:e,data:t,width:r,height:a,instance:l}){const o=h.useMemo(()=>Qb(e,t),[e,t]),i=h.useRef(null),c=h.useCallback(()=>{var p;const u=(p=i.current)==null?void 0:p.getEchartsInstance();u&&de(l,u.getOption())},[l]),d=h.useMemo(()=>({finished:c}),[c]);return n.jsx(he,{ref:i,onEvents:d,echarts:ie,option:o,style:{width:r,height:a},notMerge:!0,theme:"merico-light"})}function Kb({context:e,instance:t}){const{value:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaults({},r,zr),[r]),l=e.data,{width:o,height:i}=e.viewport;return!o||!i?null:n.jsx(_e,{width:o,height:i,children:n.jsx(Ub,{instance:t,width:Oe(o),height:Ne(i),data:l,conf:a})})}const Yb=({item:e,control:t,index:r,remove:a})=>{const{t:l,i18n:o}=x.useTranslation(),i=e.min.enable_value,c=e.max.enable_value,{orient:d}=e,u=h.useMemo(()=>({horizontal:[{label:l("chart.label_position.top"),value:"top"},{label:l("chart.label_position.inside_center"),value:"inside"},{label:l("chart.label_position.bottom"),value:"bottom"}],vertical:[{label:l("chart.label_position.left"),value:"left"},{label:l("chart.label_position.inside_left"),value:"insideLeft"},{label:l("chart.label_position.inside_center"),value:"inside"},{label:l("chart.label_position.inside_right"),value:"insideRight"},{label:l("chart.label_position.right"),value:"right"}]}),[o.language]),p=h.useMemo(()=>[{label:l("viz.funnel_chart.sort.ascending"),value:"ascending"},{label:l("viz.funnel_chart.sort.descending"),value:"descending"},{label:l("viz.funnel_chart.sort.none"),value:"0"}],[o.language]);return n.jsxs(s.Stack,{children:[n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:`series.${r}.name`,control:t,render:({field:f})=>n.jsx(s.TextInput,{label:l("viz.funnel_chart.series_name"),...f})})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${r}.level_name_data_key`,control:t,render:({field:f})=>n.jsx(q,{label:l("viz.funnel_chart.level_name_field"),...f})}),n.jsx(b.Controller,{name:`series.${r}.level_value_data_key`,control:t,render:({field:f})=>n.jsx(q,{label:l("viz.funnel_chart.level_value_field"),...f})})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:l("viz.funnel_chart.funnel_style"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${r}.min.value`,control:t,render:({field:f})=>n.jsx(s.NumberInput,{disabled:!i,labelProps:{display:"block"},label:n.jsxs(s.Group,{justify:"space-between",pr:6,sx:{width:"100%"},children:[n.jsx(s.Text,{size:"sm",children:l("viz.funnel_chart.min_value")}),n.jsx(s.Tooltip,{label:l("viz.funnel_chart.min_value_checkbox_tip"),children:n.jsx(s.Box,{children:n.jsx(b.Controller,{name:`series.${r}.min.enable_value`,control:t,render:({field:v})=>n.jsx(s.Checkbox,{size:"xs",checked:v.value,onChange:_=>v.onChange(_.currentTarget.checked)})})})})]}),...f})}),n.jsx(b.Controller,{name:`series.${r}.min.size`,control:t,render:({field:f})=>n.jsx(s.TextInput,{placeholder:"0%",label:l("viz.funnel_chart.min_size"),...f})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${r}.max.value`,control:t,render:({field:f})=>n.jsx(s.NumberInput,{disabled:!c,labelProps:{display:"block"},label:n.jsxs(s.Group,{justify:"space-between",pr:6,sx:{width:"100%"},children:[n.jsx(s.Text,{size:"sm",children:l("viz.funnel_chart.max_value")}),n.jsx(s.Tooltip,{label:l("viz.funnel_chart.max_value_checkbox_tip"),children:n.jsx(s.Box,{children:n.jsx(b.Controller,{name:`series.${r}.max.enable_value`,control:t,render:({field:v})=>n.jsx(s.Checkbox,{size:"xs",checked:v.value,onChange:_=>v.onChange(_.currentTarget.checked)})})})})]}),...f})}),n.jsx(b.Controller,{name:`series.${r}.max.size`,control:t,render:({field:f})=>n.jsx(s.TextInput,{placeholder:"100%",label:l("viz.funnel_chart.max_size"),...f})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${r}.orient`,control:t,render:({field:f})=>n.jsx(gt,{...f})}),n.jsx(b.Controller,{name:`series.${r}.sort`,control:t,render:({field:f})=>n.jsx(s.Select,{label:l("viz.funnel_chart.sort.label"),data:p,...f})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${r}.funnelAlign`,control:t,render:({field:f})=>n.jsx(ft,{label:l("viz.funnel_chart.align"),disabled:d==="horizontal",...f})}),n.jsx(b.Controller,{name:`series.${r}.gap`,control:t,render:({field:f})=>n.jsx(s.NumberInput,{placeholder:"0, 5, 10...",label:l("viz.funnel_chart.gap"),...f})})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:l("chart.label.label_style"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${r}.axisLabel.position`,control:t,render:({field:f})=>n.jsx(At,{label:l("chart.label_position.label"),options:u[d],...f})}),n.jsx(s.Box,{})]}),n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:`series.${r}.axisLabel.overflow`,control:t,render:({field:f})=>n.jsx(Re,{...f})})})]})},Xb=({control:e,watch:t})=>{const{fields:r,append:a,remove:l}=b.useFieldArray({control:e,name:"series"}),o=t("series"),i=r.map((p,f)=>({...p,...o[f]})),c=y.get(i,"0.id"),[d,u]=h.useState(c??null);return h.useEffect(()=>{c&&u(p=>p!==null?p:c)},[c]),n.jsxs(s.Tabs,{value:d,onChange:p=>u(p),styles:{panel:{padding:"0px",paddingTop:"6px"}},children:[n.jsxs(s.Tabs.List,{children:[i.map((p,f)=>n.jsx(s.Tabs.Tab,{value:p.id,children:p.name},p.id)),n.jsx(s.Tabs.Tab,{value:"add",disabled:!0,children:n.jsx(s.Tooltip,{label:"todo",children:n.jsx(s.Center,{children:n.jsx(S.IconPlus,{size:18,color:"#228be6"})})})})]}),i.map((p,f)=>n.jsx(s.Tabs.Panel,{value:p.id,children:n.jsx(Yb,{item:p,control:e,index:f,remove:l})},p.id))]})};function Zb({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaultsDeep({},t,zr),[t]),{control:l,handleSubmit:o,watch:i,formState:c,reset:d}=b.useForm({defaultValues:a});return h.useEffect(()=>{d(a)},[a]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:o(r),children:[n.jsx(ae,{canSubmit:c.isDirty}),n.jsx(Xb,{control:l,watch:i})]})})}const Jb=[{lang:"en",resources:{funnel_chart:{viz_name:"Funnel Chart",series_name:"Series Name",level_name_field:"Level Name Field",level_value_field:"Level Value Field",funnel_style:"Funnel Style",min_value:"Min Value",min_value_checkbox_tip:"Check to enable specific min value",max_value:"Max Value",max_value_checkbox_tip:"Check to enable specific max value",min_size:"Min Size",max_size:"Max Size",sort:{label:"Sort",ascending:"Ascending",descending:"Descending",none:"Use original data order"},gap:"Gap",align:"Align"}}},{lang:"zh",resources:{funnel_chart:{viz_name:"漏斗图",series_name:"系列名称",level_name_field:"层名字段",level_value_field:"层值字段",funnel_style:"漏斗样式",min_value:"最小值",min_value_checkbox_tip:"勾选以启用最小值设置",max_value:"最大值",max_value_checkbox_tip:"勾选以启用最大值设置",min_size:"最小尺寸",max_size:"最大尺寸",sort:{label:"排序",ascending:"升序",descending:"降序",none:"依原始数据的顺序"},gap:"间距",align:"对齐"}}}];function Hb(e){return{series:e.series.map(t=>{const{min:r,minSize:a,max:l,maxSize:o,...i}=t;return{...i,min:{value:r,use_data_min:!1,size:a},max:{value:l,use_data_max:!1,size:o}}})}}function Rb(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=i=>i&&`${r}.${i}`,{series:l,...o}=e;return{...o,series:l.map(i=>({...i,level_name_data_key:a(i.level_name_data_key),level_value_data_key:a(i.level_value_data_key)}))}}catch(r){throw console.error("[Migration failed]",r),r}}class ey extends ee{constructor(){super(...arguments);V(this,"VERSION",3)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>{const{config:a}=r;return{...r,version:2,config:Hb(a)}}),this.version(3,(r,a)=>{const{config:l}=r;return{...r,version:3,config:Rb(l,a)}})}}const ty={displayName:"viz.funnel_chart.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new ey,name:"funnel",viewRender:Kb,configRender:Zb,createConfig:()=>({version:3,config:zr}),translation:Jb},ny=({page:e,setPage:t,totalPages:r})=>n.jsx(s.Pagination,{size:"xs",withControls:!1,siblings:1,color:"gray",value:e,onChange:t,total:r}),ry=({page:e,setPage:t,totalPages:r})=>{const a=h.useMemo(()=>Array.from(new Array(r),(l,o)=>({label:String(o+1),value:String(o+1)})),[r]);return n.jsx(s.NativeSelect,{size:"xs",value:e,onChange:l=>{t(Number(l.currentTarget.value))},data:a})},ay=e=>e.totalPages<=1?null:n.jsx(s.Box,{sx:{position:"absolute",top:"calc(1rem + 5px)",right:"calc(1rem + 5px)",zIndex:2},children:e.width>600?n.jsx(ny,{...e}):n.jsx(ry,{...e})});function sy(e){const t=ze(e.x_axis.axisLabel.formatter),r=ze(e.y_axis.axisLabel.formatter);return{x_axis:t,y_axis:r}}function ly(e){return{heat_block:function(a){if(!e.heat_block.value_formatter)return a;try{return Y(a,e.heat_block.value_formatter)}catch(l){return console.error(l),a}}}}function oy(e){let t=0;return e.x_axis.name&&(t+=20),{show:!0,top:45,left:5,right:5,bottom:t,containLabel:!0,borderColor:"none",backgroundColor:"#E7E7E9",z:1}}function iy(e,t,r){const{heat_block:a}=e;return{type:"heatmap",name:a.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderColor:"white",borderWidth:r},data:t,label:a.label,labelLayout:{hideOverlap:!0},z:2}}const cy=e=>Y(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function dy({conf:e,labelFormatters:t,valueFormatters:r,dataDict:a,params:l,metricUnitMap:o}){const{value:i,dataIndex:c}=l,[d,u,p]=i,f={label:e.x_axis.name?e.x_axis.name:"X Axis",value:t.x_axis(d,c),style:{label:"",value:Ee(e.x_axis.axisLabel.overflow.in_tooltip)},unit:""},v={label:e.y_axis.name?e.y_axis.name:"Y Axis",value:t.y_axis(u,c),style:{label:"",value:Ee(e.y_axis.axisLabel.overflow.in_tooltip)},unit:""},_={label:e.heat_block.name,value:r.heat_block(p),style:{label:"",value:""},unit:e.heat_block.unit.show_in_tooltip?e.heat_block.unit.text:""},w=[f,v,_],m=a[`${d}---${u}`];return m&&e.tooltip.metrics.forEach(k=>{const z=P(k.data_key),D=o[k.name];w.push({label:k.name,value:cy(y.get(m,z.columnKey,"")),style:{label:"",value:""},unit:D})}),w}function uy(e,t,r,a){const{x_axis:l,y_axis:o,heat_block:i}=e,c=P(l.data_key),d=P(o.data_key);P(i.data_key);const u=y.keyBy(t[c.queryID],f=>`${f[c.columnKey]}---${f[d.columnKey]}`),p=e.tooltip.metrics.reduce((f,{unit:v,name:_})=>(v.show_in_tooltip&&(f[_]=v.text),f),{});return X.getTooltip({formatter:function(f){const _=dy({conf:e,labelFormatters:r,valueFormatters:a,dataDict:u,params:f,metricUnitMap:p}).map(m=>`
165
165
  <tr>
166
166
  <th style="text-align: right; padding: 0 1em;">
167
167
  <div style="${m.style.label}">${m.label}</div>
@@ -185,7 +185,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
185
185
  </thead>
186
186
  <tbody>${_.join("")}</tbody>
187
187
  </table>
188
- `}})}function cy(e,t,r,a){const{overflow:l,rotate:o}=e.x_axis.axisLabel,i=Be(l.on_axis);return X.getXAxis({id:"main-x-axis",type:"category",data:t,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:o,...i,formatter:r},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:a>0,interval:0,lineStyle:{type:"solid",color:"white"}},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:3})}function dy(e,t,r){const{nameAlignment:a,data_key:l,inverse:o,...i}=e.y_axis,{overflow:c,rotate:d}=e.y_axis.axisLabel,u=Be(c.on_axis);return X.getYAxis({...i,type:"category",axisLabel:{rotate:d,...u,formatter:t},axisTick:{show:!0,alignWithLabel:!0},axisLine:{show:!0,lineStyle:{width:3}},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:r>0,interval:0,lineStyle:{type:"solid",color:"white"}},nameTextStyle:{fontWeight:"bold",align:a},nameLocation:o?"start":"end",nameGap:15,inverse:o,z:3})}const hn=({label:e,field:t})=>{const{t:r}=x.useTranslation();return n.jsx(s.ColorInput,{label:e,placeholder:r("chart.visual_map.skip_range.follow_visual_map"),size:"xs",popoverProps:{withinPortal:!0,zIndex:340},rightSection:t.value?n.jsx(s.CloseButton,{size:"sm",onClick:()=>{t.onChange("")}}):null,...t})},uy=({form:e})=>{const{t}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{control:e.control,name:"visualMap.skipRange.lt_min",render:({field:r})=>n.jsx(hn,{field:r,label:t("chart.visual_map.skip_range.lt_min")})}),n.jsx(b.Controller,{control:e.control,name:"visualMap.skipRange.min",render:({field:r})=>n.jsx(hn,{field:r,label:t("chart.visual_map.skip_range.min")})}),n.jsx(b.Controller,{control:e.control,name:"visualMap.skipRange.max",render:({field:r})=>n.jsx(hn,{field:r,label:t("chart.visual_map.skip_range.max")})}),n.jsx(b.Controller,{control:e.control,name:"visualMap.skipRange.gt_max",render:({field:r})=>n.jsx(hn,{field:r,label:t("chart.visual_map.skip_range.gt_max")})})]})},py=({form:e})=>{const{t,i18n:r}=x.useTranslation(),a=e.control,l=e.watch("visualMap"),{type:o,orient:i}=l,c=i==="horizontal",d=u=>p=>{typeof p!="string"&&u(p)};return o!=="continuous"?null:n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:"visualMap.text.1",control:a,render:({field:u})=>n.jsx(s.TextInput,{label:t("chart.visual_map.min_text"),...u})}),n.jsx(b.Controller,{name:"visualMap.text.0",control:a,render:({field:u})=>n.jsx(s.TextInput,{label:t("chart.visual_map.max_text"),...u})})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:"visualMap.orient",control:a,render:({field:u})=>n.jsx(gt,{sx:{flex:1},...u})}),n.jsx(b.Controller,{name:"visualMap.calculable",control:a,render:({field:u})=>n.jsx(s.Checkbox,{label:t("chart.visual_map.calculable"),checked:u.value,onChange:p=>u.onChange(p.currentTarget.checked),styles:{root:{transform:"translateY(12px)"}}})})]}),n.jsxs(s.Group,{grow:!0,styles:{root:{flexDirection:c?"row-reverse":"row"}},children:[n.jsx(b.Controller,{name:"visualMap.itemWidth",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t(c?"chart.visual_map.bar_height":"chart.visual_map.bar_width"),...u,onChange:d(u.onChange)})}),n.jsx(b.Controller,{name:"visualMap.itemHeight",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t(c?"chart.visual_map.bar_width":"chart.visual_map.bar_height"),...u,onChange:d(u.onChange)})})]}),n.jsx(b.Controller,{name:"visualMap.inRange.color",control:a,render:({field:u})=>n.jsx(Qs,{...u})}),n.jsx(uy,{form:e})]})},hy=({visualMap:e})=>{const{orient:t,itemWidth:r,itemHeight:a}=e,o=t==="horizontal"?r:a,{panel:i}=re(),c=tn(e,i.variableValueMap);return n.jsx(ne,{children:n.jsx(he,{echarts:ce,option:{visualMap:c},style:{width:"100%",height:`${o+40}px`},notMerge:!0,theme:"merico-light"})})},Ml={lower:[{label:"<",value:"gt"},{label:"≤",value:"gte"}],upper:[{label:">",value:"lt"},{label:"≥",value:"lte"}]},Al={gt:"(",gte:"[",lt:")",lte:"]"},Pl=(e,t)=>e===""?t:Number.isNaN(Number(e))?"INVALID VALUE":e,gy=({form:e,index:t})=>{const{t:r}=x.useTranslation(),{control:a,watch:l}=e,o=l(`visualMap.pieces.${t}`),{lower:i,upper:c}=o,d=[Al[i.symbol],Pl(i.value,r("chart.visual_map.min_value")),",",Pl(c.value,r("chart.visual_map.max_value")),Al[c.symbol]].join(""),[u,p]=h.useState(!1);return n.jsx(s.Group,{wrap:"nowrap",children:n.jsxs(s.Popover,{width:400,position:"bottom",withArrow:!0,shadow:"md",opened:u,onChange:p,withinPortal:!0,zIndex:340,children:[n.jsx(s.Popover.Target,{children:n.jsx(s.Button,{variant:"subtle",size:"compact-sm",px:0,onClick:()=>p(f=>!f),fw:"normal",ff:"monospace",children:d})}),n.jsx(s.Popover.Dropdown,{children:n.jsxs(s.Group,{wrap:"nowrap",gap:8,children:[n.jsx(b.Controller,{name:`visualMap.pieces.${t}.lower.value`,control:a,render:({field:f})=>n.jsx(s.TextInput,{...f,placeholder:r("chart.visual_map.min_value"),size:"xs",onChange:v=>f.onChange(v.currentTarget.value),error:f.value!==""&&Number.isNaN(Number(f.value))})}),n.jsx(b.Controller,{name:`visualMap.pieces.${t}.lower.symbol`,control:a,render:({field:f})=>n.jsx(s.Select,{size:"xs",data:Ml.lower,...f,onChange:Z(v=>f.onChange(v))})}),n.jsx(s.Text,{c:"dimmed",size:"sm",sx:{userSelect:"none",cursor:"default"},children:r("common.value").toLowerCase()}),n.jsx(b.Controller,{name:`visualMap.pieces.${t}.upper.symbol`,control:a,render:({field:f})=>n.jsx(s.Select,{size:"xs",data:Ml.upper,...f,onChange:Z(v=>f.onChange(v))})}),n.jsx(b.Controller,{name:`visualMap.pieces.${t}.upper.value`,control:a,render:({field:f})=>n.jsx(s.TextInput,{...f,size:"xs",placeholder:r("chart.visual_map.max_value"),onChange:v=>f.onChange(v.currentTarget.value),error:f.value!==""&&Number.isNaN(Number(f.value))})})]})})]})})},fy=({form:e,index:t,remove:r})=>{const{control:a}=e,{t:l}=x.useTranslation();return n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:(t+1).toString()}),n.jsx(s.Table.Td,{children:n.jsx(gy,{form:e,index:t})}),n.jsx(s.Table.Td,{children:n.jsx(b.Controller,{name:`visualMap.pieces.${t}.label`,control:a,render:({field:o})=>n.jsx(s.TextInput,{size:"xs",placeholder:"",...o,onChange:i=>o.onChange(i.currentTarget.value)})})}),n.jsx(s.Table.Td,{children:n.jsx(b.Controller,{name:`visualMap.pieces.${t}.color`,control:a,render:({field:o})=>n.jsx(s.ColorInput,{label:l(""),placeholder:l("chart.color.label"),size:"xs",popoverProps:{withinPortal:!0,zIndex:340},rightSection:o.value?n.jsx(s.CloseButton,{size:"sm",onClick:()=>{o.onChange("")}}):null,...o})})}),n.jsx(s.Table.Td,{children:n.jsx(s.CloseButton,{size:"sm",onClick:()=>r(t)})})]})},by=({form:e})=>{const{t,i18n:r}=x.useTranslation(),{fields:a,append:l,remove:o}=b.useFieldArray({control:e.control,name:"visualMap.pieces"}),i=e.watch("visualMap.pieces"),c=a.map((u,p)=>({...u,...i[p]})),d=()=>{l(js())};return n.jsx(s.Stack,{children:n.jsxs(s.Table,{children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"40px"}}),n.jsx(s.Table.Th,{children:t("chart.visual_map.piecewise.interval")}),n.jsx(s.Table.Th,{children:t("chart.visual_map.piecewise.piece_label")}),n.jsx(s.Table.Th,{children:t("chart.color.label")}),n.jsx(s.Table.Th,{style:{width:"40px"}})]})}),n.jsx(s.Table.Tbody,{children:c.map((u,p)=>n.jsx(fy,{index:p,form:e,remove:o},u.id))}),n.jsx(s.Table.Tfoot,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{}),n.jsx(s.Table.Td,{colSpan:3,children:n.jsx(s.Button,{mt:10,size:"xs",color:"blue",leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),onClick:d,sx:{width:"50%"},mx:"auto",children:t("chart.visual_map.piecewise.add_a_piece")})}),n.jsx(s.Table.Td,{})]})})]})})},yy=({form:e})=>{const{t,i18n:r}=x.useTranslation(),a=e.control,l=e.watch("visualMap");h.useMemo(()=>[{label:t("chart.visual_map.piecewise.mode.pieces"),value:"pieces"},{label:t("chart.visual_map.piecewise.mode.categories"),value:"categories"}],[r.language]);const{type:o,orient:i,piecewise_mode:c}=l,d=u=>p=>{typeof p!="string"&&u(p)};return o!=="piecewise"?null:n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:"visualMap.precision",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t("chart.visual_map.precision"),...u,onChange:d(u.onChange)})}),n.jsx(b.Controller,{name:"visualMap.orient",control:a,render:({field:u})=>n.jsx(gt,{sx:{flex:1},...u})}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:"visualMap.itemWidth",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t("chart.visual_map.item_width"),...u,onChange:d(u.onChange)})}),n.jsx(b.Controller,{name:"visualMap.itemHeight",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t("chart.visual_map.item_height"),...u,onChange:d(u.onChange)})})]}),c==="pieces"&&n.jsx(by,{form:e})]})},Dr=({form:e})=>{const{t,i18n:r}=x.useTranslation(),a=e.control,l=e.watch("visualMap"),o=h.useMemo(()=>[{label:t("chart.visual_map.continuous.label"),value:"continuous"},{label:t("chart.visual_map.piecewise.label"),value:"piecewise"}],[r.language]),i=c=>{switch(c){case"continuous":e.setValue("visualMap",Fs());break;case"piecewise":e.setValue("visualMap",Nu());break;default:return}};return n.jsx(ne,{children:n.jsxs(s.Stack,{children:[n.jsx(hy,{visualMap:l}),n.jsx(b.Controller,{name:"visualMap.type",control:a,render:({field:c})=>n.jsx(s.SegmentedControl,{mt:-10,data:o,sx:{flex:1},...c,onChange:i})}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:"visualMap.min",control:a,render:({field:c})=>n.jsx(Ns,{label:t("chart.visual_map.min_value"),...c})}),n.jsx(b.Controller,{name:"visualMap.max",control:a,render:({field:c})=>n.jsx(Ns,{label:t("chart.visual_map.max_value"),...c})})]}),n.jsx(s.Divider,{variant:"dashed"}),n.jsx(py,{form:e}),n.jsx(yy,{form:e})]})})};function vy(e,t,r,a){return r<e*10||a<t*10?0:r<e*20||a<t*20?1:2}function Vl(e,t,r,a,l,o){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const i=a.reduce((I,L)=>{const E=Re(L,t);return I[L.name]=$e(L,E),I},{}),c=tn(e.visualMap,i),{min:d,max:u}=c,p=ny(e),f=ry(e),v=A(e.x_axis.data_key),_=A(e.y_axis.data_key),w=y.uniq(t[v.queryID].map(I=>I[v.columnKey])),m=y.uniq(t[v.queryID].map(I=>I[_.columnKey])),k=r.map(I=>{const L=y.clone(I),{followVisualMap:E,color:K}=er(L.value[2],d,u,e.visualMap);return E||(L.visualMap=!1,L.itemStyle={color:K}),L}),z=vy(w.length,m.length,l,o);return{xAxis:cy(e,w,p.x_axis,z),yAxis:dy(e,p.y_axis,z),series:sy(e,k,z),tooltip:iy(e,t,p,f),grid:ay(e),visualMap:c}}function _y(e,t){const r=h.useMemo(()=>A(t.x_axis.data_key),[t.x_axis.data_key]),a=h.useMemo(()=>A(t.y_axis.data_key),[t.y_axis.data_key]),l=h.useMemo(()=>A(t.heat_block.data_key),[t.heat_block.data_key]),o=h.useMemo(()=>{const c=e[r.queryID];if(!c)return{};const d=c.map(u=>{const p=y.get(u,r.columnKey),f=y.get(u,a.columnKey),v=y.get(u,l.columnKey);return{value:[p,f,v]}});return y.groupBy(d,"value.1")},[e,r,a,l]);return{totalPages:h.useMemo(()=>{const c=Object.keys(o).length;return t.pagination.page_size===0?c:y.ceil(c/t.pagination.page_size)},[o,t.pagination.page_size]),groupedFullData:o}}function xy(e,t,r){return h.useMemo(()=>{const l=Object.values(e);if(t.pagination.page_size===0)return l.flat();const o=(r-1)*t.pagination.page_size,i=r*t.pagination.page_size;return l.slice(o,i).flat()},[e,r,t.pagination.page_size])}function wy(e){return n.jsx(n.Fragment,{})}function my(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.merico_heatmap.click_heatmap.heatblock.label")})}const $l={id:"builtin:echarts:click-heatmap:heat-block",displayName:"viz.merico_heatmap.click_heatmap.heatblock.label",nameRender:my,configRender:wy,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function El({page_size:e=20}){return{page_size:e}}const Ir={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:we(),formatter:fe()}},y_axis:{name:"Y Axis",inverse:!1,data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:we(),formatter:fe()}},heat_block:{name:"Value",data_key:"",unit:U(),value_formatter:le,label:{show:!1,fontSize:10}},tooltip:{metrics:[]},visualMap:et(),pagination:El({page_size:20})};function Cy({conf:e,data:t,seriesData:r,width:a,height:l,interactionManager:o,variables:i}){const c=h.useMemo(()=>{const _=A(e.x_axis.data_key),w=A(e.y_axis.data_key);return y.keyBy(t[_.queryID],m=>`${m[_.columnKey]}---${m[w.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),d=Ie(o.triggerManager,$l.id),u=h.useCallback(_=>{const[w,m]=_.value,k=y.get(c,`${w}---${m}`,{error:"rowData is not found"});d.forEach(z=>{o.runInteraction(z.id,{..._,rowData:k})})},[c,d,o]),p=h.useRef(null),f=h.useMemo(()=>({click:u}),[u]),v=h.useMemo(()=>Vl(e,t,r,i,a,l),[e,t,r,a,l]);return n.jsx(he,{echarts:ce,option:v,style:{width:a,height:l},ref:p,onEvents:f,notMerge:!0,theme:"merico-light"})}function Sy({context:e,instance:t}){const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},a,Ir),[a]),i=e.data,{width:c,height:d}=e.viewport,{totalPages:u,groupedFullData:p}=_y(i,o);h.useEffect(()=>{const w=y.values(p).flat();de(t,Vl(o,i,w,l,c,d))},[p]);const[f,v]=h.useState(1),_=xy(p,o,f);return!c||!d?null:n.jsxs(_e,{width:c,height:d,children:[o.pagination.page_size>0&&n.jsx(ty,{page:f,setPage:v,totalPages:u,width:c}),n.jsx(Cy,{instance:t,variables:l,width:Ge(c),height:Fe(d),data:i,seriesData:_,conf:o,interactionManager:r})]})}function Ty({control:e,watch:t}){const{t:r}=x.useTranslation();t(["heat_block"]);const a=t("heat_block.label.show");return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"heat_block.data_key",control:e,render:({field:l})=>n.jsx(q,{label:r("common.data_field"),sx:{flex:1},...l})}),n.jsx(b.Controller,{name:"heat_block.name",control:e,render:({field:l})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...l})})]}),n.jsx(b.Controller,{name:"heat_block.unit",control:e,render:({field:l})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...l})}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("numbro.format.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"heat_block.value_formatter",control:e,render:({field:l})=>n.jsx(Le,{...l})}),n.jsx(s.Divider,{mb:-5,variant:"dashed",label:r("chart.label.label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"heat_block.label.show",control:e,render:({field:l})=>n.jsx(s.Switch,{label:r("chart.heatmap.heatblock.show_label"),checked:l.value,onChange:o=>l.onChange(o.currentTarget.checked),sx:{flexGrow:1}})}),n.jsx(b.Controller,{name:"heat_block.label.fontSize",control:e,render:({field:l})=>n.jsx(s.NumberInput,{size:"xs",leftSection:n.jsx(S.IconTextSize,{size:16}),disabled:!a,...l})})]})]})}function ky({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["pagination"]),n.jsx(s.Stack,{children:n.jsx(b.Controller,{name:"pagination.page_size",control:e,render:({field:a})=>n.jsx(s.NumberInput,{label:r("common.pagination.page_size"),description:r("viz.heatmap.pagination.page_size_hint"),sx:{flex:1},...a,onChange:l=>{typeof l!="string"&&a.onChange(l)}})})})}const zy=({control:e,index:t})=>{const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.unit`,control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})})]})},Dy=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>({id:Date.now().toString(),data_key:"",name:"",unit:U()}),l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:r("chart.tooltip.additional_metrics.description")})]}),n.jsx(s.Divider,{variant:"dashed",my:10}),n.jsx(H,{control:e,watch:t,name:"tooltip.metrics",getItem:a,addButtonText:r("chart.tooltip.additional_metrics.add"),deleteButtonText:r("chart.tooltip.additional_metrics.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(zy,{control:e,index:i})})]})};function Iy({control:e,watch:t}){return n.jsx(Dy,{control:e,watch:t})}function My({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["x_axis"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(We,{...a})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:a})=>n.jsx(nt,{sx:{width:"48%"},...a})}),n.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(Qe,{...a})})]})]})}function Ay({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["y_axis"]),n.jsxs(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})})]}),n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:"y_axis.nameAlignment",control:e,render:({field:a})=>n.jsx(ft,{sx:{flex:1},...a})})}),n.jsx(b.Controller,{name:"y_axis.inverse",control:e,render:({field:a})=>n.jsx(s.Checkbox,{size:"sm",checked:a.value,onChange:l=>a.onChange(l.currentTarget.checked),label:r("chart.y_axis.inverse"),styles:{root:{transform:"translateY(6px)"},label:{cursor:"pointer",userSelect:"none"},input:{cursor:"pointer"}}})}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(We,{...a})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"y_axis.axisLabel.rotate",control:e,render:({field:a})=>n.jsx(nt,{sx:{width:"48%"},...a})}),n.jsx(b.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(Qe,{...a})})]})]})}function Py({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),l=h.useMemo(()=>r?y.defaults({},r):Ir,[r]),o=h.useMemo(()=>y.cloneDeep(l),[l]);h.useEffect(()=>{!y.isEqual(l,o)&&(console.log("config malformed, resetting to defaults",l,o),a(o))},[l,o]);const i=b.useForm({defaultValues:o}),{control:c,handleSubmit:d,watch:u,formState:p,reset:f}=i;return h.useEffect(()=>{f(o)},[o]),n.jsx("form",{onSubmit:d(a),style:{flexGrow:1},children:n.jsxs(s.Stack,{gap:"xs",sx:{height:"100%"},children:[n.jsx(ae,{canSubmit:p.isDirty}),n.jsxs(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{root:{flexGrow:1},tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axis",children:t("chart.x_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Y Axis",children:t("chart.y_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Heat Block",children:t("chart.heatmap.heatblock.label")}),n.jsx(s.Tabs.Tab,{value:"Visual Map",children:t("chart.visual_map.label")}),n.jsx(s.Tabs.Tab,{value:"Tooltip",children:t("chart.tooltip.label")}),n.jsx(s.Tabs.Tab,{value:"Pagination",children:t("common.pagination.label")})]}),n.jsx(s.Tabs.Panel,{value:"X Axis",children:n.jsx(My,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Y Axis",children:n.jsx(Ay,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Heat Block",children:n.jsx(Ty,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Visual Map",children:n.jsx(Dr,{form:i})}),n.jsx(s.Tabs.Panel,{value:"Tooltip",children:n.jsx(Iy,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Pagination",children:n.jsx(ky,{control:c,watch:u})})]})]})})}const Vy=[{lang:"en",resources:{heatmap:{viz_name:"Heatmap",click_heatmap:{heatblock:{label:"Click heat block"}},pagination:{page_size_hint:"Set 0 to disable pagination"}}}},{lang:"zh",resources:{heatmap:{viz_name:"热力图",click_heatmap:{heatblock:{label:"点击热力块"}},pagination:{page_size_hint:"设为0以禁用分页"}}}}];function $y(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=u=>u&&`${r}.${u}`,{x_axis:l,y_axis:o,heat_block:i,tooltip:c,...d}=e;return{...d,x_axis:{...l,data_key:a(l.data_key)},y_axis:{...o,data_key:a(o.data_key)},heat_block:{...i,data_key:a(i.data_key)},tooltip:{...c,metrics:c.metrics.map(u=>({...u,data_key:a(u.data_key)}))}}}catch(r){throw console.error("[Migration failed]",r),r}}function Ey(e){return y.defaultsDeep({},e,{heat_block:{label:{show:!1,fontSize:10}}})}function By(e){const{heat_block:t}=e;let{min:r,max:a}=t;return typeof r!="number"&&(r=0),typeof a!="number"&&(a=100),{...e,heat_block:{...t,min:{type:"static",value:r},max:{type:"static",value:a}}}}function Ly(e){const{visualMap:t=et(),heat_block:{min:r,max:a,...l},...o}=e;return{...o,heat_block:l,visualMap:{...et(),min:r,max:a}}}function qy(e){const{pagination:t=El({page_size:20}),...r}=e;return{...r,pagination:t}}function Oy(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??U()}))}}}function Ny(e){const{heat_block:t}=e;return{...e,heat_block:{...t,unit:t.unit??U()}}}class Gy extends ee{constructor(){super(...arguments);P(this,"VERSION",8)}configVersions(){this.version(1,r=>(console.log("🟥 unexpected calling"),{version:1,config:r})),this.version(2,(r,a)=>({...r,version:2,config:$y(r.config,a)})),this.version(3,r=>({...r,version:3,config:Ey(r.config)})),this.version(4,r=>({...r,version:4,config:By(r.config)})),this.version(5,r=>({...r,version:5,config:Ly(r.config)})),this.version(6,r=>({...r,version:6,config:qy(r.config)})),this.version(7,r=>({...r,version:7,config:Oy(r.config)})),this.version(8,r=>({...r,version:8,config:Ny(r.config)}))}}const Fy={displayName:"viz.heatmap.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new Gy,name:"heatmap",viewRender:Sy,configRender:Py,createConfig:()=>({version:8,config:Ir}),triggers:[$l],translation:Vy},jy=[{lang:"en",resources:{pareto_chart:{viz_name:"Pareto Chart",line_80_20:{label:"80-20 Line",label_template:"Label Template",click_to_see_params:"Click to see params for Label Template",param_section_note_1:"80-20 line stuff",param_section_note_2:"chart configs"},click_series:{label:"Click chart series"}}}},{lang:"zh",resources:{pareto_chart:{viz_name:"帕累托图",line_80_20:{label:"80/20线",label_template:"线上文案模板",click_to_see_params:"点击查看线上文案模板的参数",param_section_note_1:"80-20线相关",param_section_note_2:"图表配置信息"},click_series:{label:"点击柱或线"}}}}],Bl={id:"builtin:echarts:click-echart:series",displayName:"viz.pareto_chart.click_series.label",nameRender:Wy,configRender:Qy,payload:[{name:"type",description:"Always 'click'",valueType:"string"},{name:"seriesType",description:"'line' | 'bar'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Qy(e){return n.jsx(n.Fragment,{})}function Wy(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.pareto_chart.click_series.label")})}const Ll={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"#789AB4"},Mr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:fe(),overflow:we()}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:le,unit:U()},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:wt,markLine:Ll,reference_lines:[]};function gn(e){return Y(e,{output:"percent",mantissa:0,absolute:!1})}function Uy(e){const t=e.value[1];try{return gn(t)}catch(r){return console.error(r),t}}function Yy(e){function t(r){let a=r;if(typeof r=="object"&&(Array.isArray(r.value)&&r.value.length===2?a=r.value[1]:a=r.value),!e.bar.label_formatter)return a;try{return Y(a,e.bar.label_formatter)}catch(l){return console.error(l),a}}return{bar:t,line:Uy,lineValue:gn}}function Ky(e,t,r){const{label_template:a}=e.markLine;if(!a)return"";const l={...e,percentage:t,count:r},o=Object.keys(l),i=Object.values(l);return new Function(...o,`return \`${a}\`;`)(...i)}function Xy(e){const t=Number(Ye(e).format({output:"number",mantissa:2}));return t<.33?"left":t>.66?"right":"center"}function Zy(e,t){if(t.length===0)return{};const r=t.findIndex(d=>d[1]>=.8);if(r===-1)return{};const a=t[r],l=(r+1)/t.length,o={x:gn(l),y:gn(a[1])},i={left:r+1,right:t.length-r-1},c=a[0];return c?{markLine:{name:"",silent:!0,symbol:"triangle",symbolRotate:180,symbolSize:[10,8],data:[{name:"",symbol:"none",xAxis:c,lineStyle:{color:e.markLine.color},label:{formatter:Ky(e,o,i),position:"end",align:Xy(l)}}]},markArea:{name:"",silent:!0,itemStyle:{color:"rgba(47, 140, 192, 0.05)"},data:[[{coord:["min",0]},{xAxis:c}]]}}:{}}function Jy(e,t,r){const a=t.reduce((c,d)=>c+d[1],0),l=t.reduce((c,d,u)=>{const p=u===0?0:c[u-1][1];return c.push([d[0],p+d[1]]),c},[]).map(c=>[c[0],c[1]/a]),{markLine:o,markArea:i}=Zy(e,l);return[{name:e.bar.name,type:"bar",barMaxWidth:20,itemStyle:{color:e.bar.color},label:{show:!1,position:"top",formatter:r.bar},yAxisIndex:0,data:t},{name:e.line.name,type:"line",itemStyle:{color:e.line.color},symbolSize:2,lineStyle:{width:1,shadowColor:"rgba(255,255,255,1)",shadowBlur:0,shadowOffsetX:0,shadowOffsetY:1},label:{show:!1,position:"top",formatter:r.line},yAxisIndex:1,data:l,markLine:o,markArea:i}]}function Hy(e){const t=e.bar.unit;return t.show_in_tooltip?t.text:""}const Ry=(e,t)=>r=>{const a=Array.isArray(r)?r:[r];if(a.length===0)return"";const l=Hy(e),o=a.map(d=>{const{seriesName:u,componentSubType:p}=d,[f,v]=d.value;return u?p==="bar"?`
188
+ `}})}function py(e,t,r,a){const{overflow:l,rotate:o}=e.x_axis.axisLabel,i=Fe(l.on_axis);return X.getXAxis({id:"main-x-axis",type:"category",data:t,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:o,...i,formatter:r},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:a>0,interval:0,lineStyle:{type:"solid",color:"white"}},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:3})}function hy(e,t,r){const{nameAlignment:a,data_key:l,inverse:o,...i}=e.y_axis,{overflow:c,rotate:d}=e.y_axis.axisLabel,u=Fe(c.on_axis);return X.getYAxis({...i,type:"category",axisLabel:{rotate:d,...u,formatter:t},axisTick:{show:!0,alignWithLabel:!0},axisLine:{show:!0,lineStyle:{width:3}},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:r>0,interval:0,lineStyle:{type:"solid",color:"white"}},nameTextStyle:{fontWeight:"bold",align:a},nameLocation:o?"start":"end",nameGap:15,inverse:o,z:3})}const hn=({label:e,field:t})=>{const{t:r}=x.useTranslation();return n.jsx(s.ColorInput,{label:e,placeholder:r("chart.visual_map.skip_range.follow_visual_map"),size:"xs",popoverProps:{withinPortal:!0,zIndex:340},rightSection:t.value?n.jsx(s.CloseButton,{size:"sm",onClick:()=>{t.onChange("")}}):null,...t})},gy=({form:e})=>{const{t}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{control:e.control,name:"visualMap.skipRange.lt_min",render:({field:r})=>n.jsx(hn,{field:r,label:t("chart.visual_map.skip_range.lt_min")})}),n.jsx(b.Controller,{control:e.control,name:"visualMap.skipRange.min",render:({field:r})=>n.jsx(hn,{field:r,label:t("chart.visual_map.skip_range.min")})}),n.jsx(b.Controller,{control:e.control,name:"visualMap.skipRange.max",render:({field:r})=>n.jsx(hn,{field:r,label:t("chart.visual_map.skip_range.max")})}),n.jsx(b.Controller,{control:e.control,name:"visualMap.skipRange.gt_max",render:({field:r})=>n.jsx(hn,{field:r,label:t("chart.visual_map.skip_range.gt_max")})})]})},fy=({form:e})=>{const{t,i18n:r}=x.useTranslation(),a=e.control,l=e.watch("visualMap"),{type:o,orient:i}=l,c=i==="horizontal",d=u=>p=>{typeof p!="string"&&u(p)};return o!=="continuous"?null:n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:"visualMap.text.1",control:a,render:({field:u})=>n.jsx(s.TextInput,{label:t("chart.visual_map.min_text"),...u})}),n.jsx(b.Controller,{name:"visualMap.text.0",control:a,render:({field:u})=>n.jsx(s.TextInput,{label:t("chart.visual_map.max_text"),...u})})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:"visualMap.orient",control:a,render:({field:u})=>n.jsx(gt,{sx:{flex:1},...u})}),n.jsx(b.Controller,{name:"visualMap.calculable",control:a,render:({field:u})=>n.jsx(s.Checkbox,{label:t("chart.visual_map.calculable"),checked:u.value,onChange:p=>u.onChange(p.currentTarget.checked),styles:{root:{transform:"translateY(12px)"}}})})]}),n.jsxs(s.Group,{grow:!0,styles:{root:{flexDirection:c?"row-reverse":"row"}},children:[n.jsx(b.Controller,{name:"visualMap.itemWidth",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t(c?"chart.visual_map.bar_height":"chart.visual_map.bar_width"),...u,onChange:d(u.onChange)})}),n.jsx(b.Controller,{name:"visualMap.itemHeight",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t(c?"chart.visual_map.bar_width":"chart.visual_map.bar_height"),...u,onChange:d(u.onChange)})})]}),n.jsx(b.Controller,{name:"visualMap.inRange.color",control:a,render:({field:u})=>n.jsx(Us,{...u})}),n.jsx(gy,{form:e})]})},by=({visualMap:e})=>{const{orient:t,itemWidth:r,itemHeight:a}=e,o=t==="horizontal"?r:a,{panel:i}=re(),c=tn(e,i.variableValueMap);return n.jsx(te,{children:n.jsx(he,{echarts:ie,option:{visualMap:c},style:{width:"100%",height:`${o+40}px`},notMerge:!0,theme:"merico-light"})})},Pl={lower:[{label:"<",value:"gt"},{label:"≤",value:"gte"}],upper:[{label:">",value:"lt"},{label:"≥",value:"lte"}]},Al={gt:"(",gte:"[",lt:")",lte:"]"},$l=(e,t)=>e===""?t:Number.isNaN(Number(e))?"INVALID VALUE":e,yy=({form:e,index:t})=>{const{t:r}=x.useTranslation(),{control:a,watch:l}=e,o=l(`visualMap.pieces.${t}`),{lower:i,upper:c}=o,d=[Al[i.symbol],$l(i.value,r("chart.visual_map.min_value")),",",$l(c.value,r("chart.visual_map.max_value")),Al[c.symbol]].join(""),[u,p]=h.useState(!1);return n.jsx(s.Group,{wrap:"nowrap",children:n.jsxs(s.Popover,{width:400,position:"bottom",withArrow:!0,shadow:"md",opened:u,onChange:p,withinPortal:!0,zIndex:340,children:[n.jsx(s.Popover.Target,{children:n.jsx(s.Button,{variant:"subtle",size:"compact-sm",px:0,onClick:()=>p(f=>!f),fw:"normal",ff:"monospace",children:d})}),n.jsx(s.Popover.Dropdown,{children:n.jsxs(s.Group,{wrap:"nowrap",gap:8,children:[n.jsx(b.Controller,{name:`visualMap.pieces.${t}.lower.value`,control:a,render:({field:f})=>n.jsx(s.TextInput,{...f,placeholder:r("chart.visual_map.min_value"),size:"xs",onChange:v=>f.onChange(v.currentTarget.value),error:f.value!==""&&Number.isNaN(Number(f.value))})}),n.jsx(b.Controller,{name:`visualMap.pieces.${t}.lower.symbol`,control:a,render:({field:f})=>n.jsx(s.Select,{size:"xs",data:Pl.lower,...f,onChange:Z(v=>f.onChange(v))})}),n.jsx(s.Text,{c:"dimmed",size:"sm",sx:{userSelect:"none",cursor:"default"},children:r("common.value").toLowerCase()}),n.jsx(b.Controller,{name:`visualMap.pieces.${t}.upper.symbol`,control:a,render:({field:f})=>n.jsx(s.Select,{size:"xs",data:Pl.upper,...f,onChange:Z(v=>f.onChange(v))})}),n.jsx(b.Controller,{name:`visualMap.pieces.${t}.upper.value`,control:a,render:({field:f})=>n.jsx(s.TextInput,{...f,size:"xs",placeholder:r("chart.visual_map.max_value"),onChange:v=>f.onChange(v.currentTarget.value),error:f.value!==""&&Number.isNaN(Number(f.value))})})]})})]})})},vy=({form:e,index:t,remove:r})=>{const{control:a}=e,{t:l}=x.useTranslation();return n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:(t+1).toString()}),n.jsx(s.Table.Td,{children:n.jsx(yy,{form:e,index:t})}),n.jsx(s.Table.Td,{children:n.jsx(b.Controller,{name:`visualMap.pieces.${t}.label`,control:a,render:({field:o})=>n.jsx(s.TextInput,{size:"xs",placeholder:"",...o,onChange:i=>o.onChange(i.currentTarget.value)})})}),n.jsx(s.Table.Td,{children:n.jsx(b.Controller,{name:`visualMap.pieces.${t}.color`,control:a,render:({field:o})=>n.jsx(s.ColorInput,{label:l(""),placeholder:l("chart.color.label"),size:"xs",popoverProps:{withinPortal:!0,zIndex:340},rightSection:o.value?n.jsx(s.CloseButton,{size:"sm",onClick:()=>{o.onChange("")}}):null,...o})})}),n.jsx(s.Table.Td,{children:n.jsx(s.CloseButton,{size:"sm",onClick:()=>r(t)})})]})},_y=({form:e})=>{const{t,i18n:r}=x.useTranslation(),{fields:a,append:l,remove:o}=b.useFieldArray({control:e.control,name:"visualMap.pieces"}),i=e.watch("visualMap.pieces"),c=a.map((u,p)=>({...u,...i[p]})),d=()=>{l(Ws())};return n.jsx(s.Stack,{children:n.jsxs(s.Table,{children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"40px"}}),n.jsx(s.Table.Th,{children:t("chart.visual_map.piecewise.interval")}),n.jsx(s.Table.Th,{children:t("chart.visual_map.piecewise.piece_label")}),n.jsx(s.Table.Th,{children:t("chart.color.label")}),n.jsx(s.Table.Th,{style:{width:"40px"}})]})}),n.jsx(s.Table.Tbody,{children:c.map((u,p)=>n.jsx(vy,{index:p,form:e,remove:o},u.id))}),n.jsx(s.Table.Tfoot,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{}),n.jsx(s.Table.Td,{colSpan:3,children:n.jsx(s.Button,{mt:10,size:"xs",color:"blue",leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),onClick:d,sx:{width:"50%"},mx:"auto",children:t("chart.visual_map.piecewise.add_a_piece")})}),n.jsx(s.Table.Td,{})]})})]})})},xy=({form:e})=>{const{t,i18n:r}=x.useTranslation(),a=e.control,l=e.watch("visualMap");h.useMemo(()=>[{label:t("chart.visual_map.piecewise.mode.pieces"),value:"pieces"},{label:t("chart.visual_map.piecewise.mode.categories"),value:"categories"}],[r.language]);const{type:o,orient:i,piecewise_mode:c}=l,d=u=>p=>{typeof p!="string"&&u(p)};return o!=="piecewise"?null:n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:"visualMap.precision",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t("chart.visual_map.precision"),...u,onChange:d(u.onChange)})}),n.jsx(b.Controller,{name:"visualMap.orient",control:a,render:({field:u})=>n.jsx(gt,{sx:{flex:1},...u})}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:"visualMap.itemWidth",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t("chart.visual_map.item_width"),...u,onChange:d(u.onChange)})}),n.jsx(b.Controller,{name:"visualMap.itemHeight",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t("chart.visual_map.item_height"),...u,onChange:d(u.onChange)})})]}),c==="pieces"&&n.jsx(_y,{form:e})]})},Dr=({form:e})=>{const{t,i18n:r}=x.useTranslation(),a=e.control,l=e.watch("visualMap"),o=h.useMemo(()=>[{label:t("chart.visual_map.continuous.label"),value:"continuous"},{label:t("chart.visual_map.piecewise.label"),value:"piecewise"}],[r.language]),i=c=>{switch(c){case"continuous":e.setValue("visualMap",Qs());break;case"piecewise":e.setValue("visualMap",ju());break;default:return}};return n.jsx(te,{children:n.jsxs(s.Stack,{children:[n.jsx(by,{visualMap:l}),n.jsx(b.Controller,{name:"visualMap.type",control:a,render:({field:c})=>n.jsx(s.SegmentedControl,{mt:-10,data:o,sx:{flex:1},...c,onChange:i})}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:"visualMap.min",control:a,render:({field:c})=>n.jsx(Fs,{label:t("chart.visual_map.min_value"),...c})}),n.jsx(b.Controller,{name:"visualMap.max",control:a,render:({field:c})=>n.jsx(Fs,{label:t("chart.visual_map.max_value"),...c})})]}),n.jsx(s.Divider,{variant:"dashed"}),n.jsx(fy,{form:e}),n.jsx(xy,{form:e})]})})};function wy(e,t,r,a){return r<e*10||a<t*10?0:r<e*20||a<t*20?1:2}function El(e,t,r,a,l,o){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const i=a.reduce((I,L)=>{const E=Je(L,t);return I[L.name]=$e(L,E),I},{}),c=tn(e.visualMap,i),{min:d,max:u}=c,p=sy(e),f=ly(e),v=P(e.x_axis.data_key),_=P(e.y_axis.data_key),w=y.uniq(t[v.queryID].map(I=>I[v.columnKey])),m=y.uniq(t[v.queryID].map(I=>I[_.columnKey])),k=r.map(I=>{const L=y.clone(I),{followVisualMap:E,color:K}=er(L.value[2],d,u,e.visualMap);return E||(L.visualMap=!1,L.itemStyle={color:K}),L}),z=wy(w.length,m.length,l,o);return{xAxis:py(e,w,p.x_axis,z),yAxis:hy(e,p.y_axis,z),series:iy(e,k,z),tooltip:uy(e,t,p,f),grid:oy(e),visualMap:c}}function my(e,t){const r=h.useMemo(()=>P(t.x_axis.data_key),[t.x_axis.data_key]),a=h.useMemo(()=>P(t.y_axis.data_key),[t.y_axis.data_key]),l=h.useMemo(()=>P(t.heat_block.data_key),[t.heat_block.data_key]),o=h.useMemo(()=>{const c=e[r.queryID];if(!c)return{};const d=c.map(u=>{const p=y.get(u,r.columnKey),f=y.get(u,a.columnKey),v=y.get(u,l.columnKey);return{value:[p,f,v]}});return y.groupBy(d,"value.1")},[e,r,a,l]);return{totalPages:h.useMemo(()=>{const c=Object.keys(o).length;return t.pagination.page_size===0?c:y.ceil(c/t.pagination.page_size)},[o,t.pagination.page_size]),groupedFullData:o}}function Cy(e,t,r){return h.useMemo(()=>{const l=Object.values(e);if(t.pagination.page_size===0)return l.flat();const o=(r-1)*t.pagination.page_size,i=r*t.pagination.page_size;return l.slice(o,i).flat()},[e,r,t.pagination.page_size])}function Sy(e){return n.jsx(n.Fragment,{})}function Ty(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.merico_heatmap.click_heatmap.heatblock.label")})}const Bl={id:"builtin:echarts:click-heatmap:heat-block",displayName:"viz.merico_heatmap.click_heatmap.heatblock.label",nameRender:Ty,configRender:Sy,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Ll({page_size:e=20}){return{page_size:e}}const Ir={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:De(),formatter:ye()}},y_axis:{name:"Y Axis",inverse:!1,data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:De(),formatter:ye()}},heat_block:{name:"Value",data_key:"",unit:U(),value_formatter:ce,label:{show:!1,fontSize:10}},tooltip:{metrics:[]},visualMap:et(),pagination:Ll({page_size:20})};function ky({conf:e,data:t,seriesData:r,width:a,height:l,interactionManager:o,variables:i}){const c=h.useMemo(()=>{const _=P(e.x_axis.data_key),w=P(e.y_axis.data_key);return y.keyBy(t[_.queryID],m=>`${m[_.columnKey]}---${m[w.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),d=Ie(o.triggerManager,Bl.id),u=h.useCallback(_=>{const[w,m]=_.value,k=y.get(c,`${w}---${m}`,{error:"rowData is not found"});d.forEach(z=>{o.runInteraction(z.id,{..._,rowData:k})})},[c,d,o]),p=h.useRef(null),f=h.useMemo(()=>({click:u}),[u]),v=h.useMemo(()=>El(e,t,r,i,a,l),[e,t,r,a,l]);return n.jsx(he,{echarts:ie,option:v,style:{width:a,height:l},ref:p,onEvents:f,notMerge:!0,theme:"merico-light"})}function zy({context:e,instance:t}){const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},a,Ir),[a]),i=e.data,{width:c,height:d}=e.viewport,{totalPages:u,groupedFullData:p}=my(i,o);h.useEffect(()=>{const w=y.values(p).flat();de(t,El(o,i,w,l,c,d))},[p]);const[f,v]=h.useState(1),_=Cy(p,o,f);return!c||!d?null:n.jsxs(_e,{width:c,height:d,children:[o.pagination.page_size>0&&n.jsx(ay,{page:f,setPage:v,totalPages:u,width:c}),n.jsx(ky,{instance:t,variables:l,width:Oe(c),height:Ne(d),data:i,seriesData:_,conf:o,interactionManager:r})]})}function Dy({control:e,watch:t}){const{t:r}=x.useTranslation();t(["heat_block"]);const a=t("heat_block.label.show");return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"heat_block.data_key",control:e,render:({field:l})=>n.jsx(q,{label:r("common.data_field"),sx:{flex:1},...l})}),n.jsx(b.Controller,{name:"heat_block.name",control:e,render:({field:l})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...l})})]}),n.jsx(b.Controller,{name:"heat_block.unit",control:e,render:({field:l})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...l})}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("numbro.format.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"heat_block.value_formatter",control:e,render:({field:l})=>n.jsx(je,{...l})}),n.jsx(s.Divider,{mb:-5,variant:"dashed",label:r("chart.label.label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"heat_block.label.show",control:e,render:({field:l})=>n.jsx(s.Switch,{label:r("chart.heatmap.heatblock.show_label"),checked:l.value,onChange:o=>l.onChange(o.currentTarget.checked),sx:{flexGrow:1}})}),n.jsx(b.Controller,{name:"heat_block.label.fontSize",control:e,render:({field:l})=>n.jsx(s.NumberInput,{size:"xs",leftSection:n.jsx(S.IconTextSize,{size:16}),disabled:!a,...l})})]})]})}function Iy({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["pagination"]),n.jsx(s.Stack,{children:n.jsx(b.Controller,{name:"pagination.page_size",control:e,render:({field:a})=>n.jsx(s.NumberInput,{label:r("common.pagination.page_size"),description:r("viz.heatmap.pagination.page_size_hint"),sx:{flex:1},...a,onChange:l=>{typeof l!="string"&&a.onChange(l)}})})})}const My=({control:e,index:t})=>{const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.unit`,control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})})]})},Vy=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>({id:Date.now().toString(),data_key:"",name:"",unit:U()}),l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:r("chart.tooltip.additional_metrics.description")})]}),n.jsx(s.Divider,{variant:"dashed",my:10}),n.jsx(H,{control:e,watch:t,name:"tooltip.metrics",getItem:a,addButtonText:r("chart.tooltip.additional_metrics.add"),deleteButtonText:r("chart.tooltip.additional_metrics.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(My,{control:e,index:i})})]})};function Py({control:e,watch:t}){return n.jsx(Vy,{control:e,watch:t})}function Ay({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["x_axis"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(Re,{...a})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:a})=>n.jsx(nt,{sx:{width:"48%"},...a})}),n.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(He,{...a})})]})]})}function $y({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["y_axis"]),n.jsxs(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})})]}),n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:"y_axis.nameAlignment",control:e,render:({field:a})=>n.jsx(ft,{sx:{flex:1},...a})})}),n.jsx(b.Controller,{name:"y_axis.inverse",control:e,render:({field:a})=>n.jsx(s.Checkbox,{size:"sm",checked:a.value,onChange:l=>a.onChange(l.currentTarget.checked),label:r("chart.y_axis.inverse"),styles:{root:{transform:"translateY(6px)"},label:{cursor:"pointer",userSelect:"none"},input:{cursor:"pointer"}}})}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(Re,{...a})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"y_axis.axisLabel.rotate",control:e,render:({field:a})=>n.jsx(nt,{sx:{width:"48%"},...a})}),n.jsx(b.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(He,{...a})})]})]})}function Ey({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),l=h.useMemo(()=>r?y.defaults({},r):Ir,[r]),o=h.useMemo(()=>y.cloneDeep(l),[l]);h.useEffect(()=>{!y.isEqual(l,o)&&(console.log("config malformed, resetting to defaults",l,o),a(o))},[l,o]);const i=b.useForm({defaultValues:o}),{control:c,handleSubmit:d,watch:u,formState:p,reset:f}=i;return h.useEffect(()=>{f(o)},[o]),n.jsx("form",{onSubmit:d(a),style:{flexGrow:1},children:n.jsxs(s.Stack,{gap:"xs",sx:{height:"100%"},children:[n.jsx(ae,{canSubmit:p.isDirty}),n.jsxs(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{root:{flexGrow:1},tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axis",children:t("chart.x_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Y Axis",children:t("chart.y_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Heat Block",children:t("chart.heatmap.heatblock.label")}),n.jsx(s.Tabs.Tab,{value:"Visual Map",children:t("chart.visual_map.label")}),n.jsx(s.Tabs.Tab,{value:"Tooltip",children:t("chart.tooltip.label")}),n.jsx(s.Tabs.Tab,{value:"Pagination",children:t("common.pagination.label")})]}),n.jsx(s.Tabs.Panel,{value:"X Axis",children:n.jsx(Ay,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Y Axis",children:n.jsx($y,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Heat Block",children:n.jsx(Dy,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Visual Map",children:n.jsx(Dr,{form:i})}),n.jsx(s.Tabs.Panel,{value:"Tooltip",children:n.jsx(Py,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Pagination",children:n.jsx(Iy,{control:c,watch:u})})]})]})})}const By=[{lang:"en",resources:{heatmap:{viz_name:"Heatmap",click_heatmap:{heatblock:{label:"Click heat block"}},pagination:{page_size_hint:"Set 0 to disable pagination"}}}},{lang:"zh",resources:{heatmap:{viz_name:"热力图",click_heatmap:{heatblock:{label:"点击热力块"}},pagination:{page_size_hint:"设为0以禁用分页"}}}}];function Ly(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=u=>u&&`${r}.${u}`,{x_axis:l,y_axis:o,heat_block:i,tooltip:c,...d}=e;return{...d,x_axis:{...l,data_key:a(l.data_key)},y_axis:{...o,data_key:a(o.data_key)},heat_block:{...i,data_key:a(i.data_key)},tooltip:{...c,metrics:c.metrics.map(u=>({...u,data_key:a(u.data_key)}))}}}catch(r){throw console.error("[Migration failed]",r),r}}function qy(e){return y.defaultsDeep({},e,{heat_block:{label:{show:!1,fontSize:10}}})}function Oy(e){const{heat_block:t}=e;let{min:r,max:a}=t;return typeof r!="number"&&(r=0),typeof a!="number"&&(a=100),{...e,heat_block:{...t,min:{type:"static",value:r},max:{type:"static",value:a}}}}function Ny(e){const{visualMap:t=et(),heat_block:{min:r,max:a,...l},...o}=e;return{...o,heat_block:l,visualMap:{...et(),min:r,max:a}}}function Gy(e){const{pagination:t=Ll({page_size:20}),...r}=e;return{...r,pagination:t}}function Fy(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??U()}))}}}function jy(e){const{heat_block:t}=e;return{...e,heat_block:{...t,unit:t.unit??U()}}}class Qy extends ee{constructor(){super(...arguments);V(this,"VERSION",8)}configVersions(){this.version(1,r=>(console.log("🟥 unexpected calling"),{version:1,config:r})),this.version(2,(r,a)=>({...r,version:2,config:Ly(r.config,a)})),this.version(3,r=>({...r,version:3,config:qy(r.config)})),this.version(4,r=>({...r,version:4,config:Oy(r.config)})),this.version(5,r=>({...r,version:5,config:Ny(r.config)})),this.version(6,r=>({...r,version:6,config:Gy(r.config)})),this.version(7,r=>({...r,version:7,config:Fy(r.config)})),this.version(8,r=>({...r,version:8,config:jy(r.config)}))}}const Wy={displayName:"viz.heatmap.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new Qy,name:"heatmap",viewRender:zy,configRender:Ey,createConfig:()=>({version:8,config:Ir}),triggers:[Bl],translation:By},Uy=[{lang:"en",resources:{pareto_chart:{viz_name:"Pareto Chart",line_80_20:{label:"80-20 Line",label_template:"Label Template",click_to_see_params:"Click to see params for Label Template",param_section_note_1:"80-20 line stuff",param_section_note_2:"chart configs"},click_series:{label:"Click chart series"}}}},{lang:"zh",resources:{pareto_chart:{viz_name:"帕累托图",line_80_20:{label:"80/20线",label_template:"线上文案模板",click_to_see_params:"点击查看线上文案模板的参数",param_section_note_1:"80-20线相关",param_section_note_2:"图表配置信息"},click_series:{label:"点击柱或线"}}}}],ql={id:"builtin:echarts:click-echart:series",displayName:"viz.pareto_chart.click_series.label",nameRender:Yy,configRender:Ky,payload:[{name:"type",description:"Always 'click'",valueType:"string"},{name:"seriesType",description:"'line' | 'bar'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Ky(e){return n.jsx(n.Fragment,{})}function Yy(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.pareto_chart.click_series.label")})}const Ol={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"#789AB4"},Mr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:ye(),overflow:De()}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:ce,unit:U()},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:wt,markLine:Ol,reference_lines:[]};function gn(e){return Y(e,{output:"percent",mantissa:0,absolute:!1})}function Xy(e){const t=e.value[1];try{return gn(t)}catch(r){return console.error(r),t}}function Zy(e){function t(r){let a=r;if(typeof r=="object"&&(Array.isArray(r.value)&&r.value.length===2?a=r.value[1]:a=r.value),!e.bar.label_formatter)return a;try{return Y(a,e.bar.label_formatter)}catch(l){return console.error(l),a}}return{bar:t,line:Xy,lineValue:gn}}function Jy(e,t,r){const{label_template:a}=e.markLine;if(!a)return"";const l={...e,percentage:t,count:r},o=Object.keys(l),i=Object.values(l);return new Function(...o,`return \`${a}\`;`)(...i)}function Hy(e){const t=Number(We(e).format({output:"number",mantissa:2}));return t<.33?"left":t>.66?"right":"center"}function Ry(e,t){if(t.length===0)return{};const r=t.findIndex(d=>d[1]>=.8);if(r===-1)return{};const a=t[r],l=(r+1)/t.length,o={x:gn(l),y:gn(a[1])},i={left:r+1,right:t.length-r-1},c=a[0];return c?{markLine:{name:"",silent:!0,symbol:"triangle",symbolRotate:180,symbolSize:[10,8],data:[{name:"",symbol:"none",xAxis:c,lineStyle:{color:e.markLine.color},label:{formatter:Jy(e,o,i),position:"end",align:Hy(l)}}]},markArea:{name:"",silent:!0,itemStyle:{color:"rgba(47, 140, 192, 0.05)"},data:[[{coord:["min",0]},{xAxis:c}]]}}:{}}function ev(e,t,r){const a=t.reduce((c,d)=>c+d[1],0),l=t.reduce((c,d,u)=>{const p=u===0?0:c[u-1][1];return c.push([d[0],p+d[1]]),c},[]).map(c=>[c[0],c[1]/a]),{markLine:o,markArea:i}=Ry(e,l);return[{name:e.bar.name,type:"bar",barMaxWidth:20,itemStyle:{color:e.bar.color},label:{show:!1,position:"top",formatter:r.bar},yAxisIndex:0,data:t},{name:e.line.name,type:"line",itemStyle:{color:e.line.color},symbolSize:2,lineStyle:{width:1,shadowColor:"rgba(255,255,255,1)",shadowBlur:0,shadowOffsetX:0,shadowOffsetY:1},label:{show:!1,position:"top",formatter:r.line},yAxisIndex:1,data:l,markLine:o,markArea:i}]}function tv(e){const t=e.bar.unit;return t.show_in_tooltip?t.text:""}const nv=(e,t)=>r=>{const a=Array.isArray(r)?r:[r];if(a.length===0)return"";const l=tv(e),o=a.map(d=>{const{seriesName:u,componentSubType:p}=d,[f,v]=d.value;return u?p==="bar"?`
189
189
  <tr>
190
190
  <th style="text-align: right; padding: 0 1em;">${u}</th>
191
191
  <td style="text-align: left; padding: 0 2px 0 1em;">${t.bar(v)}</td>
@@ -205,7 +205,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
205
205
  ${o.join("")}
206
206
  </tbody>
207
207
  </table>
208
- `};function ev(e,t){return X.getTooltip({trigger:"axis",formatter:Ry(e,t)})}function tv(e,t){const{name:r,axisLabel:a}=e.x_axis,l=Be(a.overflow.on_axis);return[X.getXAxis({type:"category",id:"main-x-axis",name:r,nameLocation:"middle",nameGap:30,nameTextStyle:{align:"right"},axisLabel:{...a,...l,formatter:xe(a.formatter)},data:t})]}function nv(e,t){return[X.getYAxis({name:e.bar.name,nameGap:20,minInterval:1,nameTextStyle:{align:e.bar.nameAlignment},position:"left",axisLabel:{show:!0,formatter:t.bar},splitLine:{show:!1}}),X.getYAxis({name:e.line.name,nameGap:20,nameTextStyle:{align:e.line.nameAlignment},position:"right",axisLabel:{show:!0,formatter:t.lineValue}})]}function rv(e,t){return t?[e]:[]}function av(e,t,r,a){return e.map(l=>{const o=r[l.variable_key],i=l.orientation==="horizontal",c=i?"yAxis":"xAxis",d=i?"insideEndTop":"end",u=rv(o,i);return{name:l.name,type:"scatter",hide_in_legend:!l.show_in_legend,xAxisId:"main-x-axis",yAxisIndex:l.yAxisIndex,data:u,symbol:"none",silent:!0,tooltip:{show:!1},markLine:{data:[{name:l.name,[c]:o}],silent:!0,symbol:["none","none"],lineStyle:l.lineStyle,label:{formatter:function(){return l.template?jt(l.template,t,a):""},position:d}}}})}const ql=()=>({top:50,left:30,right:15,bottom:5,containLabel:!0});function sv(e,t,r){const a=Cr(t,r),l=Yy(e),{x_axis:o,data_key:i}=e;if(!o.data_key||!i)return{series:[],grid:ql()};const c=A(o.data_key),d=A(i);if(c.queryID!==d.queryID)throw new Error("Please use the same query for X & Y axis");const u=t[c.queryID].map(v=>[v[c.columnKey],Number(v[d.columnKey])]).sort((v,_)=>_[1]-v[1]),p=u.map(v=>v[0]);return{dataZoom:on(e.dataZoom),tooltip:ev(e,l),xAxis:tv(e,p),yAxis:nv(e,l),series:[...Jy(e,u,l),...av(e.reference_lines,r,a,t)],grid:ql()}}function lv({context:e,instance:t}){const{variables:r}=e,{value:a}=B(e.instanceData,"config"),l=e.data,{width:o,height:i}=e.viewport,c=y.defaults({},a,Mr),d=sv(c,l,r),u=Me({vizManager:e.vizManager,instance:t}),p=Ie(u.triggerManager,Bl.id),f=mt(l,c.x_axis.data_key),v=h.useCallback(k=>{const z=y.get(f,k.name,{error:"rowData is not found"});p.forEach(D=>{u.runInteraction(D.id,{...k,rowData:z})})},[f,p,u]),_=h.useRef(null),w=h.useCallback(()=>{var z;const k=(z=_.current)==null?void 0:z.getEchartsInstance();k&&de(t,k.getOption())},[t]),m=h.useMemo(()=>({click:v,finished:w}),[v,w]);return!c||!o||!i?null:n.jsx(_e,{width:o,height:i,children:n.jsx(he,{echarts:ce,option:d,ref:_,style:Ot(o,i),onEvents:m,notMerge:!0,theme:"merico-light"})})}function ov({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["bar"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:"bar.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"bar.nameAlignment",control:e,render:({field:a})=>n.jsx(ft,{sx:{flex:1},...a})})]}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:"bar.color",control:e,render:({field:a})=>n.jsx(ye,{label:r("chart.color.label"),...a})})}),n.jsx(b.Controller,{name:"bar.unit",control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.label.label_format"),labelPosition:"center"}),n.jsx(b.Controller,{name:"bar.label_formatter",control:e,render:({field:a})=>n.jsx(Le,{...a})})]})]})}function iv({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["line"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:"line.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"line.nameAlignment",control:e,render:({field:a})=>n.jsx(ft,{sx:{flex:1},...a})})]}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:"line.color",control:e,render:({field:a})=>n.jsx(ye,{label:r("chart.color.label"),...a})})})]})}const cv=(e,t)=>`
208
+ `};function rv(e,t){return X.getTooltip({trigger:"axis",formatter:nv(e,t)})}function av(e,t){const{name:r,axisLabel:a}=e.x_axis,l=Fe(a.overflow.on_axis);return[X.getXAxis({type:"category",id:"main-x-axis",name:r,nameLocation:"middle",nameGap:30,nameTextStyle:{align:"right"},axisLabel:{...a,...l,formatter:ze(a.formatter)},data:t})]}function sv(e,t){return[X.getYAxis({name:e.bar.name,nameGap:20,minInterval:1,nameTextStyle:{align:e.bar.nameAlignment},position:"left",axisLabel:{show:!0,formatter:t.bar},splitLine:{show:!1}}),X.getYAxis({name:e.line.name,nameGap:20,nameTextStyle:{align:e.line.nameAlignment},position:"right",axisLabel:{show:!0,formatter:t.lineValue}})]}function lv(e,t){return t?[e]:[]}function ov(e,t,r,a){return e.map(l=>{const o=r[l.variable_key],i=l.orientation==="horizontal",c=i?"yAxis":"xAxis",d=i?"insideEndTop":"end",u=lv(o,i);return{name:l.name,type:"scatter",hide_in_legend:!l.show_in_legend,xAxisId:"main-x-axis",yAxisIndex:l.yAxisIndex,data:u,symbol:"none",silent:!0,tooltip:{show:!1},markLine:{data:[{name:l.name,[c]:o}],silent:!0,symbol:["none","none"],lineStyle:l.lineStyle,label:{formatter:function(){return l.template?jt(l.template,t,a):""},position:d}}}})}const Nl=()=>({top:50,left:30,right:15,bottom:5,containLabel:!0});function iv(e,t,r){const a=Cr(t,r),l=Zy(e),{x_axis:o,data_key:i}=e;if(!o.data_key||!i)return{series:[],grid:Nl()};const c=P(o.data_key),d=P(i);if(c.queryID!==d.queryID)throw new Error("Please use the same query for X & Y axis");const u=t[c.queryID].map(v=>[v[c.columnKey],Number(v[d.columnKey])]).sort((v,_)=>_[1]-v[1]),p=u.map(v=>v[0]);return{dataZoom:on(e.dataZoom),tooltip:rv(e,l),xAxis:av(e,p),yAxis:sv(e,l),series:[...ev(e,u,l),...ov(e.reference_lines,r,a,t)],grid:Nl()}}function cv({context:e,instance:t}){const{variables:r}=e,{value:a}=B(e.instanceData,"config"),l=e.data,{width:o,height:i}=e.viewport,c=y.defaults({},a,Mr),d=iv(c,l,r),u=Me({vizManager:e.vizManager,instance:t}),p=Ie(u.triggerManager,ql.id),f=mt(l,c.x_axis.data_key),v=h.useCallback(k=>{const z=y.get(f,k.name,{error:"rowData is not found"});p.forEach(D=>{u.runInteraction(D.id,{...k,rowData:z})})},[f,p,u]),_=h.useRef(null),w=h.useCallback(()=>{var z;const k=(z=_.current)==null?void 0:z.getEchartsInstance();k&&de(t,k.getOption())},[t]),m=h.useMemo(()=>({click:v,finished:w}),[v,w]);return!c||!o||!i?null:n.jsx(_e,{width:o,height:i,children:n.jsx(he,{echarts:ie,option:d,ref:_,style:Ot(o,i),onEvents:m,notMerge:!0,theme:"merico-light"})})}function dv({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["bar"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:"bar.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"bar.nameAlignment",control:e,render:({field:a})=>n.jsx(ft,{sx:{flex:1},...a})})]}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:"bar.color",control:e,render:({field:a})=>n.jsx(be,{label:r("chart.color.label"),...a})})}),n.jsx(b.Controller,{name:"bar.unit",control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.label.label_format"),labelPosition:"center"}),n.jsx(b.Controller,{name:"bar.label_formatter",control:e,render:({field:a})=>n.jsx(je,{...a})})]})]})}function uv({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["line"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:"line.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"line.nameAlignment",control:e,render:({field:a})=>n.jsx(ft,{sx:{flex:1},...a})})]}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:"line.color",control:e,render:({field:a})=>n.jsx(be,{label:r("chart.color.label"),...a})})})]})}const pv=(e,t)=>`
209
209
  {
210
210
  // ${e}
211
211
  percentage: {
@@ -228,8 +228,8 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
228
228
  name: string;
229
229
  };
230
230
  }
231
- `,dv=()=>{const{t:e,i18n:t}=x.useTranslation(),[r,a]=h.useState(!1),l=h.useMemo(()=>cv(e("viz.pareto_chart.line_80_20.param_section_note_1"),e("viz.pareto_chart.line_80_20.param_section_note_2")),[t.language]);return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{variant:"subtle",size:"compact-sm",onClick:()=>a(o=>!o),children:e(r?"common.actions.close":"viz.pareto_chart.line_80_20.click_to_see_params")}),n.jsx(s.Collapse,{in:r,children:n.jsx(Oe.CodeHighlight,{language:"typescript",withCopyButton:!1,code:l})})]})};function uv({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["markLine"]),n.jsxs(s.Stack,{children:[n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:"markLine.color",control:e,render:({field:a})=>n.jsx(ye,{label:r("chart.color.label"),...a})})}),n.jsxs(s.Stack,{gap:4,children:[n.jsx(b.Controller,{name:"markLine.label_template",control:e,render:({field:a})=>n.jsx(s.Textarea,{autosize:!0,minRows:2,maxRows:4,label:r("viz.pareto_chart.line_80_20.label_template"),sx:{flex:1},...a})}),n.jsx(dv,{})]})]})}function pv({control:e,index:t,watch:r,variableOptions:a,yAxisOptions:l}){const{t:o}=x.useTranslation(),i=r(`reference_lines.${t}.orientation`);return n.jsxs(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:o("common.name"),placeholder:o("chart.reference_line.name_placeholder"),required:!0,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:c})=>n.jsx(s.Select,{label:o("common.data_field"),required:!0,data:a,sx:{flex:1},...c})})]}),n.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:o("chart.content_template.label"),placeholder:o("chart.content_template.hint"),sx:{flex:1},...c})}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.Stack,{children:n.jsx(b.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:c})=>n.jsx(gt,{label:o("chart.orientation.label"),sx:{flex:1},...c})})}),i==="horizontal"&&n.jsx(b.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:c,onChange:d,...u}})=>n.jsx(s.Select,{label:o("chart.y_axis.label"),data:l,disabled:l.length===0,...u,value:(c==null?void 0:c.toString())??"",onChange:p=>{if(!p){d(0);return}d(Number(p))},sx:{flex:1}})})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:o("chart.style.label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:c})=>n.jsx(Pt,{sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:c})=>n.jsx(s.NumberInput,{label:o("chart.series.line.line_width"),min:1,max:10,sx:{flexGrow:1},...c})})]}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:c})=>n.jsx(ye,{label:o("chart.color.label"),...c})})})]})}function hv({control:e,watch:t,variables:r}){const{t:a}=x.useTranslation(),l=()=>({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0}),o=(u,p)=>{const f=u.name.trim();return f||p+1},i=h.useMemo(()=>r.map(u=>({label:u.name,value:u.name})),[r]),c=t(["bar.name","line.name"]),d=h.useMemo(()=>c.map((u,p)=>({label:u,value:p.toString()})),[c]);return n.jsx(H,{control:e,watch:t,name:"reference_lines",getItem:l,addButtonText:a("chart.reference_line.add"),deleteButtonText:a("chart.reference_line.delete"),renderTabName:o,children:({field:u,index:p})=>n.jsx(pv,{control:e,index:p,watch:t,variableOptions:i,yAxisOptions:d})})}function gv({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["x_axis"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(s.Divider,{mb:-15,label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:a})=>n.jsx(nt,{sx:{width:"48%"},...a})}),n.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(Qe,{...a})})]}),n.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(We,{...a})})]})}function fv({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["data_key"]),n.jsx(s.Stack,{children:n.jsx(b.Controller,{name:"data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("chart.y_axis.y_axis_data_field"),required:!0,sx:{flex:1},...a})})})}function bv({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},r,Mr),[r]),{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=b.useForm({defaultValues:o});return h.useEffect(()=>{p(o)},[o]),d(["x_axis","data_key","bar","line","dataZoom"]),n.jsxs("form",{onSubmit:c(a),children:[n.jsx(ae,{canSubmit:u.isDirty}),n.jsxs(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axis",children:t("chart.x_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Y Axis",children:t("chart.y_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Bar",children:t("chart.series.bar.label")}),n.jsx(s.Tabs.Tab,{value:"Line",children:t("chart.series.line.label")}),n.jsx(s.Tabs.Tab,{value:"80-20 Line",children:t("viz.pareto_chart.line_80_20.label")}),n.jsx(s.Tabs.Tab,{value:"Reference Lines",children:t("chart.reference_line.labels")}),n.jsx(s.Tabs.Tab,{value:"Zooming",children:t("chart.zooming.label")})]}),n.jsx(s.Tabs.Panel,{value:"X Axis",children:n.jsx(gv,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Y Axis",children:n.jsx(fv,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Bar",children:n.jsx(ov,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Line",children:n.jsx(iv,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"80-20 Line",children:n.jsx(uv,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Reference Lines",children:n.jsx(hv,{variables:l,control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Zooming",children:n.jsx(b.Controller,{name:"dataZoom",control:i,render:({field:f})=>n.jsx(cn,{...f})})})]})]})}function yv(e){const{dataZoom:t=wt,...r}=e;return{...r,dataZoom:t}}function vv(e){const{markLine:t=Ll,...r}=e;return{...r,markLine:t}}function _v(e){const t=y.defaultsDeep({},e.x_axis.axisLabel,{rotate:0,formatter:fe()});return{...e,x_axis:{...e.x_axis,axisLabel:t}}}function xv(e){const{label_formatter:t=le}=e.bar;return{...e,bar:{...e.bar,label_formatter:t}}}function wv(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(t,e)}function mv(e){const t={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return y.defaultsDeep(t,e)}function Cv(e){console.log(e);const{x_axis:t,tooltip:r}=e.x_axis.axisLabel.overflow,a={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:r}}}};return y.defaultsDeep(a,e)}function Sv(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=c=>c&&`${r}.${c}`,{x_axis:l,data_key:o,...i}=e;return{...i,x_axis:{...l,data_key:a(l.data_key)},data_key:a(o)}}catch(r){throw console.error("[Migration failed]",r),r}}function Tv(e){const t=e.bar,{unit:r=U()}=t;return{...e,bar:{...t,unit:r}}}class kv extends ee{constructor(){super(...arguments);P(this,"VERSION",10)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>({...r,version:2,config:yv(r.config)})),this.version(3,r=>({...r,version:3,config:vv(r.config)})),this.version(4,r=>({...r,version:4,config:_v(r.config)})),this.version(5,r=>({...r,version:5,config:xv(r.config)})),this.version(6,r=>({...r,version:6,config:wv(r.config)})),this.version(7,r=>({...r,version:7,config:mv(r.config)})),this.version(8,r=>({...r,version:8,config:Cv(r.config)})),this.version(9,(r,a)=>({...r,version:9,config:Sv(r.config,a)})),this.version(10,r=>({...r,version:10,config:Tv(r.config)}))}}const zv={displayName:"viz.pareto_chart.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new kv,name:"paretoChart",viewRender:lv,configRender:bv,createConfig(){return{version:10,config:y.cloneDeep(Mr)}},triggers:[Bl],translation:jy};function Dv(e,t,r,a){const l=a[r];return l||(t?e[t]:void 0)}function Iv(e){const t=Ne.sum(e.map(r=>r.value));return e.map(r=>{const a=Ne.divide(r.value,t),l=Ye(a).format({output:"percent",mantissa:2,trimMantissa:!0});return{...r,ratio:a,percentage:l}})}function Mv(e,t,r){const{label:a,threshold:l}=e;if(!a||!l)return t;const o=Ye(`${l}%`).format({output:"number",mantissa:8,trimMantissa:!0}),i={name:a,value:0,ratio:0,percentage:"",items:[],color:r.next().value},c=[];return t.forEach(d=>{Ne.larger(d.ratio,o)?c.push(d):(i.value=Ne.add(i.value,d.value),i.ratio=Ne.add(i.ratio,d.ratio),i.percentage=Ye(i.ratio).format({output:"percent",mantissa:2,trimMantissa:!0}),i.items.push(d))}),c.push(i),c}const Av=(e,t)=>{const{label_field:r,value_field:a,series_order:l,color_field:o,color:i,others_sector:c}=e;if(!r||!a)return{source:[]};const d=A(r),u=A(a),p=A(o),f=i.map.reduce((w,m)=>{const{name:k,color:z}=m;return!k||!z||(w[k]=z),w},{}),v=wp("multiple");let _=t[d.queryID].map(w=>{const m=w[d.columnKey],k=Dv(w,p.columnKey,m,f)||v.next().value;return{name:m,value:Number(w[u.columnKey]),ratio:0,percentage:"",color:k}});return l&&(_=y.orderBy(_,[l.key],[l.order])),_=Iv(_),_=Mv(c,_,v),{source:_}};function Pv(e,t,r){return{type:"pie",name:"pie",radius:e.radius,itemStyle:{color:({data:a})=>a.color},label:{position:"outer",alignTo:"edge",formatter:`{name|{b}}
232
- {p|{@percentage}}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{p:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(a){const l=a.labelRect.x<r/2,o=a.labelLinePoints;return y.set(o,[2,0],l?a.labelRect.x:a.labelRect.x+a.labelRect.width),{labelLinePoints:o}},top:10,bottom:10,left:10,right:10}}function Vv(e,t){const{name:r,color:a}=t,o=t.data.items.map(c=>`
231
+ `,hv=()=>{const{t:e,i18n:t}=x.useTranslation(),[r,a]=h.useState(!1),l=h.useMemo(()=>pv(e("viz.pareto_chart.line_80_20.param_section_note_1"),e("viz.pareto_chart.line_80_20.param_section_note_2")),[t.language]);return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{variant:"subtle",size:"compact-sm",onClick:()=>a(o=>!o),children:e(r?"common.actions.close":"viz.pareto_chart.line_80_20.click_to_see_params")}),n.jsx(s.Collapse,{in:r,children:n.jsx(Le.CodeHighlight,{language:"typescript",withCopyButton:!1,code:l})})]})};function gv({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["markLine"]),n.jsxs(s.Stack,{children:[n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:"markLine.color",control:e,render:({field:a})=>n.jsx(be,{label:r("chart.color.label"),...a})})}),n.jsxs(s.Stack,{gap:4,children:[n.jsx(b.Controller,{name:"markLine.label_template",control:e,render:({field:a})=>n.jsx(s.Textarea,{autosize:!0,minRows:2,maxRows:4,label:r("viz.pareto_chart.line_80_20.label_template"),sx:{flex:1},...a})}),n.jsx(hv,{})]})]})}function fv({control:e,index:t,watch:r,variableOptions:a,yAxisOptions:l}){const{t:o}=x.useTranslation(),i=r(`reference_lines.${t}.orientation`);return n.jsxs(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:o("common.name"),placeholder:o("chart.reference_line.name_placeholder"),required:!0,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:c})=>n.jsx(s.Select,{label:o("common.data_field"),required:!0,data:a,sx:{flex:1},...c})})]}),n.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:o("chart.content_template.label"),placeholder:o("chart.content_template.hint"),sx:{flex:1},...c})}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.Stack,{children:n.jsx(b.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:c})=>n.jsx(gt,{label:o("chart.orientation.label"),sx:{flex:1},...c})})}),i==="horizontal"&&n.jsx(b.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:c,onChange:d,...u}})=>n.jsx(s.Select,{label:o("chart.y_axis.label"),data:l,disabled:l.length===0,...u,value:(c==null?void 0:c.toString())??"",onChange:p=>{if(!p){d(0);return}d(Number(p))},sx:{flex:1}})})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:o("chart.style.label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:c})=>n.jsx(Pt,{sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:c})=>n.jsx(s.NumberInput,{label:o("chart.series.line.line_width"),min:1,max:10,sx:{flexGrow:1},...c})})]}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:c})=>n.jsx(be,{label:o("chart.color.label"),...c})})})]})}function bv({control:e,watch:t,variables:r}){const{t:a}=x.useTranslation(),l=()=>({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0}),o=(u,p)=>{const f=u.name.trim();return f||p+1},i=h.useMemo(()=>r.map(u=>({label:u.name,value:u.name})),[r]),c=t(["bar.name","line.name"]),d=h.useMemo(()=>c.map((u,p)=>({label:u,value:p.toString()})),[c]);return n.jsx(H,{control:e,watch:t,name:"reference_lines",getItem:l,addButtonText:a("chart.reference_line.add"),deleteButtonText:a("chart.reference_line.delete"),renderTabName:o,children:({field:u,index:p})=>n.jsx(fv,{control:e,index:p,watch:t,variableOptions:i,yAxisOptions:d})})}function yv({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["x_axis"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(s.Divider,{mb:-15,label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:a})=>n.jsx(nt,{sx:{width:"48%"},...a})}),n.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(He,{...a})})]}),n.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(Re,{...a})})]})}function vv({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["data_key"]),n.jsx(s.Stack,{children:n.jsx(b.Controller,{name:"data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("chart.y_axis.y_axis_data_field"),required:!0,sx:{flex:1},...a})})})}function _v({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},r,Mr),[r]),{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=b.useForm({defaultValues:o});return h.useEffect(()=>{p(o)},[o]),d(["x_axis","data_key","bar","line","dataZoom"]),n.jsxs("form",{onSubmit:c(a),children:[n.jsx(ae,{canSubmit:u.isDirty}),n.jsxs(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axis",children:t("chart.x_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Y Axis",children:t("chart.y_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Bar",children:t("chart.series.bar.label")}),n.jsx(s.Tabs.Tab,{value:"Line",children:t("chart.series.line.label")}),n.jsx(s.Tabs.Tab,{value:"80-20 Line",children:t("viz.pareto_chart.line_80_20.label")}),n.jsx(s.Tabs.Tab,{value:"Reference Lines",children:t("chart.reference_line.labels")}),n.jsx(s.Tabs.Tab,{value:"Zooming",children:t("chart.zooming.label")})]}),n.jsx(s.Tabs.Panel,{value:"X Axis",children:n.jsx(yv,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Y Axis",children:n.jsx(vv,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Bar",children:n.jsx(dv,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Line",children:n.jsx(uv,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"80-20 Line",children:n.jsx(gv,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Reference Lines",children:n.jsx(bv,{variables:l,control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Zooming",children:n.jsx(b.Controller,{name:"dataZoom",control:i,render:({field:f})=>n.jsx(cn,{...f})})})]})]})}function xv(e){const{dataZoom:t=wt,...r}=e;return{...r,dataZoom:t}}function wv(e){const{markLine:t=Ol,...r}=e;return{...r,markLine:t}}function mv(e){const t=y.defaultsDeep({},e.x_axis.axisLabel,{rotate:0,formatter:ye()});return{...e,x_axis:{...e.x_axis,axisLabel:t}}}function Cv(e){const{label_formatter:t=ce}=e.bar;return{...e,bar:{...e.bar,label_formatter:t}}}function Sv(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(t,e)}function Tv(e){const t={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return y.defaultsDeep(t,e)}function kv(e){console.log(e);const{x_axis:t,tooltip:r}=e.x_axis.axisLabel.overflow,a={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:r}}}};return y.defaultsDeep(a,e)}function zv(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=c=>c&&`${r}.${c}`,{x_axis:l,data_key:o,...i}=e;return{...i,x_axis:{...l,data_key:a(l.data_key)},data_key:a(o)}}catch(r){throw console.error("[Migration failed]",r),r}}function Dv(e){const t=e.bar,{unit:r=U()}=t;return{...e,bar:{...t,unit:r}}}class Iv extends ee{constructor(){super(...arguments);V(this,"VERSION",10)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>({...r,version:2,config:xv(r.config)})),this.version(3,r=>({...r,version:3,config:wv(r.config)})),this.version(4,r=>({...r,version:4,config:mv(r.config)})),this.version(5,r=>({...r,version:5,config:Cv(r.config)})),this.version(6,r=>({...r,version:6,config:Sv(r.config)})),this.version(7,r=>({...r,version:7,config:Tv(r.config)})),this.version(8,r=>({...r,version:8,config:kv(r.config)})),this.version(9,(r,a)=>({...r,version:9,config:zv(r.config,a)})),this.version(10,r=>({...r,version:10,config:Dv(r.config)}))}}const Mv={displayName:"viz.pareto_chart.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new Iv,name:"paretoChart",viewRender:cv,configRender:_v,createConfig(){return{version:10,config:y.cloneDeep(Mr)}},triggers:[ql],translation:Uy};function Vv(e,t,r,a){const l=a[r];return l||(t?e[t]:void 0)}function Pv(e){const t=qe.sum(e.map(r=>r.value));return e.map(r=>{const a=qe.divide(r.value,t),l=We(a).format({output:"percent",mantissa:2,trimMantissa:!0});return{...r,ratio:a,percentage:l}})}function Av(e,t,r){const{label:a,threshold:l}=e;if(!a||!l)return t;const o=We(`${l}%`).format({output:"number",mantissa:8,trimMantissa:!0}),i={name:a,value:0,ratio:0,percentage:"",items:[],color:r.next().value},c=[];return t.forEach(d=>{qe.larger(d.ratio,o)?c.push(d):(i.value=qe.add(i.value,d.value),i.ratio=qe.add(i.ratio,d.ratio),i.percentage=We(i.ratio).format({output:"percent",mantissa:2,trimMantissa:!0}),i.items.push(d))}),c.push(i),c}const $v=(e,t)=>{const{label_field:r,value_field:a,series_order:l,color_field:o,color:i,others_sector:c}=e;if(!r||!a)return{source:[]};const d=P(r),u=P(a),p=P(o),f=i.map.reduce((w,m)=>{const{name:k,color:z}=m;return!k||!z||(w[k]=z),w},{}),v=Sp("multiple");let _=t[d.queryID].map(w=>{const m=w[d.columnKey],k=Vv(w,p.columnKey,m,f)||v.next().value;return{name:m,value:Number(w[u.columnKey]),ratio:0,percentage:"",color:k}});return l&&(_=y.orderBy(_,[l.key],[l.order])),_=Pv(_),_=Av(c,_,v),{source:_}};function Ev(e,t,r){return{type:"pie",name:"pie",radius:e.radius,itemStyle:{color:({data:a})=>a.color},label:{position:"outer",alignTo:"edge",formatter:`{name|{b}}
232
+ {p|{@percentage}}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{p:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(a){const l=a.labelRect.x<r/2,o=a.labelLinePoints;return y.set(o,[2,0],l?a.labelRect.x:a.labelRect.x+a.labelRect.width),{labelLinePoints:o}},top:10,bottom:10,left:10,right:10}}function Bv(e,t){const{name:r,color:a}=t,o=t.data.items.map(c=>`
233
233
  <tr>
234
234
  <th style="text-align: right; padding: 0 1em;">${c.name}</th>
235
235
  <td style="text-align: left; padding: 0 1em; font-family: monospace;">
@@ -255,7 +255,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
255
255
  ${o}
256
256
  </tbody>
257
257
  </table>
258
- `}function $v(e){return t=>{const{name:r,color:a,data:l}=t,{value:o,percentage:i}=t.value;return"items"in l?Vv(e,t):`
258
+ `}function Lv(e){return t=>{const{name:r,color:a,data:l}=t,{value:o,percentage:i}=t.value;return"items"in l?Bv(e,t):`
259
259
  <table style="width: auto">
260
260
  <thead>
261
261
  <tr colspan="2">
@@ -273,7 +273,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
273
273
  </tr>
274
274
  </tbody>
275
275
  </table>
276
- `}}function Ev(e){const t=e.unit.show_in_tooltip?e.unit.text:"";return X.getTooltip({trigger:"item",formatter:$v(t)})}function Bv(e,t,r){return{dataset:Av(e,t),tooltip:Ev(e),series:Pv(e,t,r)}}const Ol={id:"builtin:echarts:click-pie-chart:series",displayName:"viz.pie_chart.click_series.label",nameRender:qv,configRender:Lv,payload:[{name:"seriesType",description:"'line' | 'scatter' | 'bar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"Value of the series clicked",valueType:"number"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Lv(e){return n.jsx(n.Fragment,{})}function qv(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.pie_chart.click_series.label")})}const Nl=()=>({label:null,threshold:null}),Gl={label_field:"",value_field:"",color_field:"",radius:["50%","80%"],color:{map:[]},unit:U(),series_order:dn(),others_sector:Nl()};function Ov({conf:e,data:t,width:r,height:a,interactionManager:l,instance:o}){const i=mt(t,e.label_field),c=Ie(l.triggerManager,Ol.id),d=h.useCallback(_=>{const w=y.get(i,_.name,{error:"rowData is not found"});c.forEach(m=>{l.runInteraction(m.id,{..._,rowData:w})})},[i,c,l]),u=h.useRef(null),p=h.useCallback(()=>{var w;const _=(w=u.current)==null?void 0:w.getEchartsInstance();_&&de(o,_.getOption())},[o]),f=h.useMemo(()=>Bv(e,t,r),[e,t,r]),v=h.useMemo(()=>({click:d,finished:p}),[d,p]);return!r||!a||!f.series.name?null:n.jsx(he,{echarts:ce,option:f,ref:u,style:{width:r,height:a},onEvents:v,notMerge:!0,theme:"merico-light"})}function Nv({context:e,instance:t}){const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),l=h.useMemo(()=>y.defaults({},a,Gl),[a]),o=e.data,{width:i,height:c}=e.viewport;return!i||!c||!l.label_field||!l.value_field?null:n.jsx(_e,{width:i,height:c,children:n.jsx(Ov,{instance:t,conf:l,width:Ge(i),height:Fe(c),data:o,interactionManager:r})})}function Gv(e){const[t,r]=e;return[Number(t.replace("%","")),Number(r.replace("%",""))]}function Fv(e){const[t,r]=e;return[Number.isFinite(t)?`${t}%`:"",Number.isFinite(r)?`${r}%`:""]}const jv=h.forwardRef(({label:e,value:t,onChange:r},a)=>{const[l,o]=h.useState(Gv(t)),i=h.useCallback(c=>{r(Fv(c))},[r]);return n.jsxs(s.Stack,{gap:4,mt:2,mb:"1rem",children:[n.jsx("label",{className:"form-field-label required",children:e}),n.jsx(s.RangeSlider,{value:l,onChange:o,onChangeEnd:i,label:c=>`${c}%`})]})}),Qv=({row:e,index:t,handleChange:r,handleRemove:a,names:l})=>{const{t:o}=x.useTranslation(),[i,{setTrue:c}]=O.useBoolean(!1),[d,{setTrue:u,setFalse:p}]=O.useBoolean(!1),{ref:f,handleRef:v}=Ln.useSortable({id:e.id,index:t}),_=m=>{r({...e,name:m})},w=m=>{r({...e,color:m})};return n.jsxs(s.Flex,{ref:f,gap:"sm",justify:"flex-start",align:"center",direction:"row",wrap:"nowrap",onMouseEnter:u,onMouseLeave:p,children:[n.jsx(s.Center,{style:{minWidth:"30px",maxWidth:"30px",flex:0},children:d?n.jsx(s.ActionIcon,{size:"xs",ref:v,variant:"subtle",children:n.jsx(S.IconGripVertical,{})}):n.jsx(s.Badge,{size:"sm",variant:"light",children:t+1})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",style:{flex:1},children:[n.jsx(s.Autocomplete,{size:"xs",value:e.name,placeholder:o("viz.pie_chart.color.map.name"),onChange:_,onClick:c,error:i&&!e.name,data:l,maxDropdownHeight:500}),n.jsx(s.ColorInput,{styles:{root:{flexGrow:1}},popoverProps:{withinPortal:!0,zIndex:340},size:"xs",value:e.color,onChange:w,onClick:c,error:i&&!e.color})]}),n.jsx("div",{style:{minWidth:"40px",maxWidth:"40px",flex:0},children:n.jsx(s.CloseButton,{onClick:a,size:"sm"})})]})},Wv=({append:e})=>{const{t}=x.useTranslation(),r=()=>{e({name:"",color:""})};return n.jsxs(s.Flex,{gap:"sm",justify:"flex-start",align:"center",direction:"row",wrap:"nowrap",children:[n.jsx("div",{style:{minWidth:"30px",maxWidth:"30px",flex:0}}),n.jsx(s.Group,{wrap:"nowrap",style:{flex:1},children:n.jsx(s.Button,{size:"xs",variant:"subtle",onClick:r,leftSection:n.jsx(S.IconPlus,{size:14}),children:t("viz.pie_chart.color.map.add_a_row")})}),n.jsx("div",{style:{minWidth:"40px",maxWidth:"40px",flex:0}})]})},Uv=Object.entries(y.pick(He.graphics,["compared","level","depth","multiple"])).map(([e,t])=>({name:e,colors:Object.values(t)}));function Yv(e){const t=e.length;if(t===0)return"";const r={output:"percent",mantissa:4,trimMantissa:!0},a=y.divide(1,t),l=[];return e.forEach((i,c)=>{l.push(`${i} ${Ye(c*a).format(r)}`),l.push(`${i} ${Ye((c+1)*a).format(r)}`)}),`linear-gradient(90deg, ${l.join(",")})`}const Kv=({value:e,onChange:t})=>{const{t:r,i18n:a}=x.useTranslation(),l=o=>{const i=e.map((c,d)=>({name:c.name,color:o[d]}));for(let c=i.length-1;c<o.length;c++)i.push({name:"",color:o[c]});t(i)};return n.jsxs(s.Menu,{withArrow:!0,shadow:"md",width:400,styles:{item:{overflowX:"hidden"}},children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Button,{size:"compact-xs",variant:"subtle",rightSection:n.jsx(s.Combobox.Chevron,{size:"xs"}),children:r("viz.pie_chart.color.map.use_a_palette")})}),n.jsxs(s.Menu.Dropdown,{children:[n.jsx(s.Menu.Label,{children:r("viz.pie_chart.color.map.click_to_apply_palette")}),n.jsx(s.Menu.Divider,{}),Uv.map(o=>n.jsx(s.Menu.Item,{onClick:()=>l(o.colors),children:n.jsx(s.Box,{h:28,style:{backgroundImage:Yv(o.colors)}})},o.name))]})]})},Xv=h.forwardRef(({value:e,onChange:t,zIndex:r=340,names:a},l)=>{const{t:o}=x.useTranslation(),i=h.useMemo(()=>e.map(f=>({id:Ke.v4(),...f})),[e]),c=f=>{t([...e,f])},d=f=>{const v=[...e];v.splice(f,1),t(v)},u=f=>v=>{const _=[...e];_[f]=v,t(_)},p=f=>{const{source:v,target:_}=f.operation,w=hs.move(i,v,_);t(w.map(m=>y.omit(m,"id")))};return n.jsxs(s.Stack,{ref:l,pt:4,children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Text,{size:"sm",fw:"500",mb:-4,children:o("viz.pie_chart.color.map.label")}),n.jsx(Kv,{value:e,onChange:t})]}),n.jsx(Bn.DragDropProvider,{onDragEnd:p,children:i.map((f,v)=>n.jsx(Qv,{row:f,handleChange:u(v),handleRemove:()=>d(v),index:v,names:a},f.id))}),n.jsx(Wv,{append:c})]})});function Zv({conf:e,setConf:t,context:r}){const{t:a}=x.useTranslation(),l=h.useMemo(()=>y.defaults({},e),[e]),{control:o,handleSubmit:i,watch:c,formState:d,reset:u}=b.useForm({defaultValues:l});h.useEffect(()=>{u(l)},[l]);const[p]=c(["label_field","value_field","color_field","color"]),{panel:f}=re(),v=h.useMemo(()=>{if(!p)return[];const _=Ve(f.data,p);return y.uniq(_)},[p,f.data]);return n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:i(t),children:[n.jsx(ae,{canSubmit:d.isDirty}),n.jsxs(s.Stack,{mt:"md",gap:"xs",p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{control:o,name:"label_field",render:({field:_})=>n.jsx(q,{label:a("common.name_data_field"),required:!0,..._})}),n.jsx(b.Controller,{control:o,name:"value_field",render:({field:_})=>n.jsx(q,{label:a("common.value_data_field"),required:!0,..._})})]}),n.jsx(b.Controller,{name:"unit",control:o,render:({field:_})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],..._})}),n.jsx(s.Divider,{variant:"dashed"}),n.jsx(b.Controller,{control:o,name:"series_order",render:({field:_})=>n.jsx(Tl,{label:a("chart.series_order.label"),..._})}),n.jsx(b.Controller,{control:o,name:"radius",render:({field:_})=>n.jsx(jv,{label:a("viz.pie_chart.radius.label"),..._})}),n.jsx(s.Divider,{label:a("viz.pie_chart.others_sector.title"),labelPosition:"center",variant:"dashed"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{control:o,name:"others_sector.label",render:({field:_})=>n.jsx(s.TextInput,{size:"xs",label:a("viz.pie_chart.others_sector.label"),..._,value:_.value??""})}),n.jsx(b.Controller,{control:o,name:"others_sector.threshold",render:({field:_})=>n.jsx(s.NumberInput,{size:"xs",label:a("viz.pie_chart.others_sector.threshold"),suffix:"%",..._,value:_.value??""})})]}),n.jsx(s.Divider,{label:a("chart.color.label"),labelPosition:"center",variant:"dashed"}),n.jsx(b.Controller,{control:o,name:"color_field",render:({field:_})=>n.jsx(q,{label:a("common.color_data_field"),clearable:!0,..._})}),n.jsx(b.Controller,{control:o,name:"color.map",render:({field:_})=>n.jsx(Xv,{names:v,..._})})]})]})})}function Jv(e){const{value:t,set:r}=B(e.context.instanceData,"config");return t?n.jsx(Zv,{conf:t,setConf:r,...e}):null}const Hv=[{lang:"en",resources:{pie_chart:{viz_name:"Pie Chart",click_series:{label:"Click pie series"},radius:{label:"Radius",inner:"Inner",outer:"Outer"},color:{map:{label:"Color Map",name:"Record name",add_a_row:"Add a mapping rule",use_a_palette:"Use a palette",click_to_apply_palette:"Click to apply palette"}},others_sector:{title:"Sector for small values",label:"Sector name",threshold:"Threshold"}}}},{lang:"zh",resources:{pie_chart:{viz_name:"饼图",click_series:{label:"点击饼瓣"},radius:{label:"内外半径",inner:"内",outer:"外"},color:{map:{label:"颜色映射表",name:"数据名称",add_a_row:"增加一条映射规则",use_a_palette:"使用预设配色方案",click_to_apply_palette:"点击应用配色方案"}},others_sector:{title:"合并小值为一个扇区",label:"扇区名称",threshold:"阈值"}}}}];function Rv(e){const{color_field:t="",...r}=e;return{...r,color_field:t}}function e_(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=c=>c&&`${r}.${c}`,{label_field:l,value_field:o,color_field:i}=e;return{label_field:a(l),value_field:a(o),color_field:a(i)}}catch(r){throw console.error("[Migration failed]",r),r}}function t_(e){const{radius:t=["50%","80%"],...r}=e;return{...r,radius:t}}function n_(e){const{color:t={map:[]},...r}=e;return{...r,color:{...t,map:t.map??[]}}}function r_(e){const{series_order:t=dn(),...r}=e;return{...r,series_order:t}}function a_(e){const{others_sector:t=Nl(),...r}=e;return{...r,others_sector:t}}function s_(e){const{unit:t}=e;return{...e,unit:t??U()}}class l_ extends ee{constructor(){super(...arguments);P(this,"VERSION",8)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>({...r,version:2,config:Rv(r.config)})),this.version(3,(r,a)=>({...r,version:3,config:e_(r.config,a)})),this.version(4,r=>({...r,version:4,config:t_(r.config)})),this.version(5,r=>({...r,version:5,config:n_(r.config)})),this.version(6,r=>({...r,version:6,config:r_(r.config)})),this.version(7,r=>({...r,version:7,config:a_(r.config)})),this.version(8,r=>({...r,version:8,config:s_(r.config)}))}}const o_={displayName:"viz.pie_chart.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new l_,name:"pie",viewRender:Nv,configRender:Jv,createConfig(){return{version:8,config:y.cloneDeep(Gl)}},triggers:[Ol],translation:Hv};function i_(e){return n.jsx(n.Fragment,{})}function c_(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.radar_chart.click_series.label")})}const Fl={id:"builtin:echarts:click-radar-chart:series",displayName:"viz.radar_chart.click_series.label",nameRender:c_,configRender:i_,payload:[{name:"seriesType",description:"'radar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]},fn={series_name_key:"",additional_series:[],background:{enabled:!0},label:{enabled:!0},dimensions:[]};function jl(e){return e?t=>{try{return Y(t,e)}catch(r){return console.error(r),t}}:t=>t}function Ql(e){return{show:e.label.enabled,formatter:({dimensionIndex:t,value:r})=>jl(e.dimensions[t].formatter)(r)}}function Wl(e,t){return t.map(({data_key:r})=>{const a=A(r);return e[a.columnKey]})}function d_(e,t,r){const a=A(t);return e[a.queryID].map(l=>({value:Wl(l,r),name:l[a.columnKey]}))}function u_(e,t){const{series_name_key:r,dimensions:a}=t;return[{type:"radar",name:"main-radar",data:d_(e,r,a),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:Ql(t)}]}function p_(e,t){const{additional_series:r,dimensions:a}=t;return r.map(o=>{const i=A(o.name_key),c=A(o.color_key);return{type:"radar",colorBy:"data",data:e[i.queryID].map(p=>{const f=p[i.columnKey],v=p[c.columnKey];return{name:f,value:Wl(p,a),itemStyle:{color:v}}}),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:Ql(t)}}).flat()}function h_(e,t){return[...u_(e,t),...p_(e,t)]}function g_(e){return({name:t,marker:r,value:a})=>{if(a.length===0)return"";const l=a.map((o,i)=>{const c=e.dimensions[i],d=jl(c.formatter);return`
276
+ `}}function qv(e){const t=e.unit.show_in_tooltip?e.unit.text:"";return X.getTooltip({trigger:"item",formatter:Lv(t)})}function Ov(e,t,r){return{dataset:$v(e,t),tooltip:qv(e),series:Ev(e,t,r)}}const Gl={id:"builtin:echarts:click-pie-chart:series",displayName:"viz.pie_chart.click_series.label",nameRender:Gv,configRender:Nv,payload:[{name:"seriesType",description:"'line' | 'scatter' | 'bar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"Value of the series clicked",valueType:"number"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Nv(e){return n.jsx(n.Fragment,{})}function Gv(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.pie_chart.click_series.label")})}const Fl=()=>({label:null,threshold:null}),jl={label_field:"",value_field:"",color_field:"",radius:["50%","80%"],color:{map:[]},unit:U(),series_order:dn(),others_sector:Fl()};function Fv({conf:e,data:t,width:r,height:a,interactionManager:l,instance:o}){const i=mt(t,e.label_field),c=Ie(l.triggerManager,Gl.id),d=h.useCallback(_=>{const w=y.get(i,_.name,{error:"rowData is not found"});c.forEach(m=>{l.runInteraction(m.id,{..._,rowData:w})})},[i,c,l]),u=h.useRef(null),p=h.useCallback(()=>{var w;const _=(w=u.current)==null?void 0:w.getEchartsInstance();_&&de(o,_.getOption())},[o]),f=h.useMemo(()=>Ov(e,t,r),[e,t,r]),v=h.useMemo(()=>({click:d,finished:p}),[d,p]);return!r||!a||!f.series.name?null:n.jsx(he,{echarts:ie,option:f,ref:u,style:{width:r,height:a},onEvents:v,notMerge:!0,theme:"merico-light"})}function jv({context:e,instance:t}){const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),l=h.useMemo(()=>y.defaults({},a,jl),[a]),o=e.data,{width:i,height:c}=e.viewport;return!i||!c||!l.label_field||!l.value_field?null:n.jsx(_e,{width:i,height:c,children:n.jsx(Fv,{instance:t,conf:l,width:Oe(i),height:Ne(c),data:o,interactionManager:r})})}function Qv(e){const[t,r]=e;return[Number(t.replace("%","")),Number(r.replace("%",""))]}function Wv(e){const[t,r]=e;return[Number.isFinite(t)?`${t}%`:"",Number.isFinite(r)?`${r}%`:""]}const Uv=h.forwardRef(({label:e,value:t,onChange:r},a)=>{const[l,o]=h.useState(Qv(t)),i=h.useCallback(c=>{r(Wv(c))},[r]);return n.jsxs(s.Stack,{gap:4,mt:2,mb:"1rem",children:[n.jsx("label",{className:"form-field-label required",children:e}),n.jsx(s.RangeSlider,{value:l,onChange:o,onChangeEnd:i,label:c=>`${c}%`})]})}),Kv=({row:e,index:t,handleChange:r,handleRemove:a,names:l})=>{const{t:o}=x.useTranslation(),[i,{setTrue:c}]=O.useBoolean(!1),[d,{setTrue:u,setFalse:p}]=O.useBoolean(!1),{ref:f,handleRef:v}=Ln.useSortable({id:e.id,index:t}),_=m=>{r({...e,name:m})},w=m=>{r({...e,color:m})};return n.jsxs(s.Flex,{ref:f,gap:"sm",justify:"flex-start",align:"center",direction:"row",wrap:"nowrap",onMouseEnter:u,onMouseLeave:p,children:[n.jsx(s.Center,{style:{minWidth:"30px",maxWidth:"30px",flex:0},children:d?n.jsx(s.ActionIcon,{size:"xs",ref:v,variant:"subtle",children:n.jsx(S.IconGripVertical,{})}):n.jsx(s.Badge,{size:"sm",variant:"light",children:t+1})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",style:{flex:1},children:[n.jsx(s.Autocomplete,{size:"xs",value:e.name,placeholder:o("viz.pie_chart.color.map.name"),onChange:_,onClick:c,error:i&&!e.name,data:l,maxDropdownHeight:500}),n.jsx(s.ColorInput,{styles:{root:{flexGrow:1}},popoverProps:{withinPortal:!0,zIndex:340},size:"xs",value:e.color,onChange:w,onClick:c,error:i&&!e.color})]}),n.jsx("div",{style:{minWidth:"40px",maxWidth:"40px",flex:0},children:n.jsx(s.CloseButton,{onClick:a,size:"sm"})})]})},Yv=({append:e})=>{const{t}=x.useTranslation(),r=()=>{e({name:"",color:""})};return n.jsxs(s.Flex,{gap:"sm",justify:"flex-start",align:"center",direction:"row",wrap:"nowrap",children:[n.jsx("div",{style:{minWidth:"30px",maxWidth:"30px",flex:0}}),n.jsx(s.Group,{wrap:"nowrap",style:{flex:1},children:n.jsx(s.Button,{size:"xs",variant:"subtle",onClick:r,leftSection:n.jsx(S.IconPlus,{size:14}),children:t("viz.pie_chart.color.map.add_a_row")})}),n.jsx("div",{style:{minWidth:"40px",maxWidth:"40px",flex:0}})]})},Xv=Object.entries(y.pick(Ze.graphics,["compared","level","depth","multiple"])).map(([e,t])=>({name:e,colors:Object.values(t)}));function Zv(e){const t=e.length;if(t===0)return"";const r={output:"percent",mantissa:4,trimMantissa:!0},a=y.divide(1,t),l=[];return e.forEach((i,c)=>{l.push(`${i} ${We(c*a).format(r)}`),l.push(`${i} ${We((c+1)*a).format(r)}`)}),`linear-gradient(90deg, ${l.join(",")})`}const Jv=({value:e,onChange:t})=>{const{t:r,i18n:a}=x.useTranslation(),l=o=>{const i=e.map((c,d)=>({name:c.name,color:o[d]}));for(let c=i.length-1;c<o.length;c++)i.push({name:"",color:o[c]});t(i)};return n.jsxs(s.Menu,{withArrow:!0,shadow:"md",width:400,styles:{item:{overflowX:"hidden"}},children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Button,{size:"compact-xs",variant:"subtle",rightSection:n.jsx(s.Combobox.Chevron,{size:"xs"}),children:r("viz.pie_chart.color.map.use_a_palette")})}),n.jsxs(s.Menu.Dropdown,{children:[n.jsx(s.Menu.Label,{children:r("viz.pie_chart.color.map.click_to_apply_palette")}),n.jsx(s.Menu.Divider,{}),Xv.map(o=>n.jsx(s.Menu.Item,{onClick:()=>l(o.colors),children:n.jsx(s.Box,{h:28,style:{backgroundImage:Zv(o.colors)}})},o.name))]})]})},Hv=h.forwardRef(({value:e,onChange:t,zIndex:r=340,names:a},l)=>{const{t:o}=x.useTranslation(),i=h.useMemo(()=>e.map(f=>({id:Ue.v4(),...f})),[e]),c=f=>{t([...e,f])},d=f=>{const v=[...e];v.splice(f,1),t(v)},u=f=>v=>{const _=[...e];_[f]=v,t(_)},p=f=>{const{source:v,target:_}=f.operation,w=gs.move(i,v,_);t(w.map(m=>y.omit(m,"id")))};return n.jsxs(s.Stack,{ref:l,pt:4,children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Text,{size:"sm",fw:"500",mb:-4,children:o("viz.pie_chart.color.map.label")}),n.jsx(Jv,{value:e,onChange:t})]}),n.jsx(Bn.DragDropProvider,{onDragEnd:p,children:i.map((f,v)=>n.jsx(Kv,{row:f,handleChange:u(v),handleRemove:()=>d(v),index:v,names:a},f.id))}),n.jsx(Yv,{append:c})]})});function Rv({conf:e,setConf:t,context:r}){const{t:a}=x.useTranslation(),l=h.useMemo(()=>y.defaults({},e),[e]),{control:o,handleSubmit:i,watch:c,formState:d,reset:u}=b.useForm({defaultValues:l});h.useEffect(()=>{u(l)},[l]);const[p]=c(["label_field","value_field","color_field","color"]),{panel:f}=re(),v=h.useMemo(()=>{if(!p)return[];const _=Ae(f.data,p);return y.uniq(_)},[p,f.data]);return n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:i(t),children:[n.jsx(ae,{canSubmit:d.isDirty}),n.jsxs(s.Stack,{mt:"md",gap:"xs",p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{control:o,name:"label_field",render:({field:_})=>n.jsx(q,{label:a("common.name_data_field"),required:!0,..._})}),n.jsx(b.Controller,{control:o,name:"value_field",render:({field:_})=>n.jsx(q,{label:a("common.value_data_field"),required:!0,..._})})]}),n.jsx(b.Controller,{name:"unit",control:o,render:({field:_})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],..._})}),n.jsx(s.Divider,{variant:"dashed"}),n.jsx(b.Controller,{control:o,name:"series_order",render:({field:_})=>n.jsx(zl,{label:a("chart.series_order.label"),..._})}),n.jsx(b.Controller,{control:o,name:"radius",render:({field:_})=>n.jsx(Uv,{label:a("viz.pie_chart.radius.label"),..._})}),n.jsx(s.Divider,{label:a("viz.pie_chart.others_sector.title"),labelPosition:"center",variant:"dashed"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{control:o,name:"others_sector.label",render:({field:_})=>n.jsx(s.TextInput,{size:"xs",label:a("viz.pie_chart.others_sector.label"),..._,value:_.value??""})}),n.jsx(b.Controller,{control:o,name:"others_sector.threshold",render:({field:_})=>n.jsx(s.NumberInput,{size:"xs",label:a("viz.pie_chart.others_sector.threshold"),suffix:"%",..._,value:_.value??""})})]}),n.jsx(s.Divider,{label:a("chart.color.label"),labelPosition:"center",variant:"dashed"}),n.jsx(b.Controller,{control:o,name:"color_field",render:({field:_})=>n.jsx(q,{label:a("common.color_data_field"),clearable:!0,..._})}),n.jsx(b.Controller,{control:o,name:"color.map",render:({field:_})=>n.jsx(Hv,{names:v,..._})})]})]})})}function e_(e){const{value:t,set:r}=B(e.context.instanceData,"config");return t?n.jsx(Rv,{conf:t,setConf:r,...e}):null}const t_=[{lang:"en",resources:{pie_chart:{viz_name:"Pie Chart",click_series:{label:"Click pie series"},radius:{label:"Radius",inner:"Inner",outer:"Outer"},color:{map:{label:"Color Map",name:"Record name",add_a_row:"Add a mapping rule",use_a_palette:"Use a palette",click_to_apply_palette:"Click to apply palette"}},others_sector:{title:"Sector for small values",label:"Sector name",threshold:"Threshold"}}}},{lang:"zh",resources:{pie_chart:{viz_name:"饼图",click_series:{label:"点击饼瓣"},radius:{label:"内外半径",inner:"内",outer:"外"},color:{map:{label:"颜色映射表",name:"数据名称",add_a_row:"增加一条映射规则",use_a_palette:"使用预设配色方案",click_to_apply_palette:"点击应用配色方案"}},others_sector:{title:"合并小值为一个扇区",label:"扇区名称",threshold:"阈值"}}}}];function n_(e){const{color_field:t="",...r}=e;return{...r,color_field:t}}function r_(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=c=>c&&`${r}.${c}`,{label_field:l,value_field:o,color_field:i}=e;return{label_field:a(l),value_field:a(o),color_field:a(i)}}catch(r){throw console.error("[Migration failed]",r),r}}function a_(e){const{radius:t=["50%","80%"],...r}=e;return{...r,radius:t}}function s_(e){const{color:t={map:[]},...r}=e;return{...r,color:{...t,map:t.map??[]}}}function l_(e){const{series_order:t=dn(),...r}=e;return{...r,series_order:t}}function o_(e){const{others_sector:t=Fl(),...r}=e;return{...r,others_sector:t}}function i_(e){const{unit:t}=e;return{...e,unit:t??U()}}class c_ extends ee{constructor(){super(...arguments);V(this,"VERSION",8)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>({...r,version:2,config:n_(r.config)})),this.version(3,(r,a)=>({...r,version:3,config:r_(r.config,a)})),this.version(4,r=>({...r,version:4,config:a_(r.config)})),this.version(5,r=>({...r,version:5,config:s_(r.config)})),this.version(6,r=>({...r,version:6,config:l_(r.config)})),this.version(7,r=>({...r,version:7,config:o_(r.config)})),this.version(8,r=>({...r,version:8,config:i_(r.config)}))}}const d_={displayName:"viz.pie_chart.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new c_,name:"pie",viewRender:jv,configRender:e_,createConfig(){return{version:8,config:y.cloneDeep(jl)}},triggers:[Gl],translation:t_};function u_(e){return n.jsx(n.Fragment,{})}function p_(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.radar_chart.click_series.label")})}const Ql={id:"builtin:echarts:click-radar-chart:series",displayName:"viz.radar_chart.click_series.label",nameRender:p_,configRender:u_,payload:[{name:"seriesType",description:"'radar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]},fn={series_name_key:"",additional_series:[],background:{enabled:!0},label:{enabled:!0},dimensions:[]};function Wl(e){return e?t=>{try{return Y(t,e)}catch(r){return console.error(r),t}}:t=>t}function Ul(e){return{show:e.label.enabled,formatter:({dimensionIndex:t,value:r})=>Wl(e.dimensions[t].formatter)(r)}}function Kl(e,t){return t.map(({data_key:r})=>{const a=P(r);return e[a.columnKey]})}function h_(e,t,r){const a=P(t);return e[a.queryID].map(l=>({value:Kl(l,r),name:l[a.columnKey]}))}function g_(e,t){const{series_name_key:r,dimensions:a}=t;return[{type:"radar",name:"main-radar",data:h_(e,r,a),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:Ul(t)}]}function f_(e,t){const{additional_series:r,dimensions:a}=t;return r.map(o=>{const i=P(o.name_key),c=P(o.color_key);return{type:"radar",colorBy:"data",data:e[i.queryID].map(p=>{const f=p[i.columnKey],v=p[c.columnKey];return{name:f,value:Kl(p,a),itemStyle:{color:v}}}),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:Ul(t)}}).flat()}function b_(e,t){return[...g_(e,t),...f_(e,t)]}function y_(e){return({name:t,marker:r,value:a})=>{if(a.length===0)return"";const l=a.map((o,i)=>{const c=e.dimensions[i],d=Wl(c.formatter);return`
277
277
  <tr>
278
278
  <td style="padding-left: 18px;">${c.name}</td>
279
279
  <td style="text-align: right; "><strong>${d(o)}</strong></td>
@@ -301,27 +301,27 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
301
301
  ${l.join("")}
302
302
  </tbody>
303
303
  </table>
304
- `}}const f_={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},b_=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function y_(e,t){const{series_name_key:r,dimensions:a,additional_series:l}=e;if(!r||a.length===0)return{};const i={radar:{indicator:a.map(({name:c,max:d})=>({name:c,max:d})),splitArea:{show:!1}},tooltip:X.getTooltip({backgroundColor:"rgba(255,255,255,0.6)",formatter:g_(e)}),legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:h_(t,e),color:b_};return y.merge({},f_,i)}function v_({conf:e,data:t,width:r,height:a,interactionManager:l,variables:o,instance:i}){const c=h.useMemo(()=>{const{queryID:w,columnKey:m}=A(e.series_name_key),k=y.keyBy(t[w],m),z=e.additional_series.reduce((D,I)=>{const L=A(I.name_key),E=y.keyBy(t[L.queryID],L.columnKey);return{...D,...E}},k);return{...k,...z}},[t,e.series_name_key,e.additional_series]),d=Ie(l.triggerManager,Fl.id),u=h.useRef(null),p=h.useCallback(()=>{var m;const w=(m=u.current)==null?void 0:m.getEchartsInstance();w&&de(i,w.getOption())},[i]),f=h.useCallback(w=>{const m=y.get(c,w.name,{error:"rowData is not found"});d.forEach(k=>{l.runInteraction(k.id,{...w,rowData:m})})},[c,d,l]),v=h.useMemo(()=>({click:f,finished:p}),[f]),_=h.useMemo(()=>y_(y.defaultsDeep({},e,fn),t),[e,t]);return!r||!a?null:n.jsx(he,{echarts:ce,option:_,ref:u,style:{width:r,height:a},onEvents:v,notMerge:!0,theme:"merico-light"})}function __({context:e,instance:t}){const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},a,fn),[a]),i=e.data,{width:c,height:d}=e.viewport;return!c||!d||!o||y.isEmpty(o==null?void 0:o.dimensions)?null:n.jsx(_e,{width:c,height:d,children:n.jsx(v_,{instance:t,variables:l,width:Ge(c),height:Fe(d),data:i,conf:o,interactionManager:r})})}function x_({control:e,index:t}){const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:`additional_series.${t}.name_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("viz.radar_chart.series.series_name_field"),required:!0,sx:{flex:1},...a})})}),n.jsx(s.Stack,{children:n.jsx(b.Controller,{name:`additional_series.${t}.color_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("viz.radar_chart.style.color_field"),required:!0,clearable:!0,sx:{flex:1},...a})})})]})}function w_({control:e,watch:t}){const{t:r}=x.useTranslation(),a=()=>({id:new Date().getTime().toString(),name_key:"",color_key:""}),l=(o,i)=>i+1;return n.jsxs(n.Fragment,{children:[n.jsx(s.Alert,{icon:n.jsx(S.IconInfoCircle,{size:16}),title:r("viz.radar_chart.additional_series.label"),children:n.jsxs(x.Trans,{i18nKey:"viz.radar_chart.additional_series.intro",children:["By setting ",n.jsx(s.Mark,{children:"Series Name Key"}),", you may add series from more queries to the chart."]})}),n.jsx(H,{control:e,watch:t,name:"additional_series",getItem:a,addButtonText:r("viz.radar_chart.additional_series.add"),deleteButtonText:r("viz.radar_chart.additional_series.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(x_,{control:e,index:i})})]})}function m_({control:e,index:t}){const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",align:"top",children:[n.jsx(b.Controller,{name:`dimensions.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`dimensions.${t}.data_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`dimensions.${t}.max`,control:e,rules:{validate:a=>{if(Number.isNaN(Number(a)))return r("validation.number.require_a_number")}},render:({field:a,fieldState:l})=>{var o;return n.jsx(s.TextInput,{label:r("common.max"),required:!0,sx:{flex:1},...a,error:(o=l.error)==null?void 0:o.message})}})]}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("viz.radar_chart.metric.value_formatter"),labelPosition:"center"}),n.jsx(b.Controller,{name:`dimensions.${t}.formatter`,control:e,render:({field:a})=>n.jsx(Le,{...a})})]})]})}function C_({control:e,watch:t}){const{t:r}=x.useTranslation(),a=()=>{const o=new Date().getTime().toString();return{id:o,name:o,data_key:"",max:"100",formatter:le}},l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsx(n.Fragment,{children:n.jsx(H,{control:e,watch:t,name:"dimensions",getItem:a,addButtonText:r("viz.radar_chart.metric.add"),deleteButtonText:r("viz.radar_chart.metric.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(m_,{control:e,index:i})})})}function S_({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),l=h.useMemo(()=>y.defaultsDeep({},r,fn),[r]),{control:o,handleSubmit:i,watch:c,reset:d,formState:u}=b.useForm({defaultValues:l,mode:"all"});return h.useEffect(()=>{d(l)},[l]),c(["series_name_key","background","label"]),n.jsx("form",{onSubmit:i(a),children:n.jsxs(s.Stack,{gap:"xs",children:[n.jsx(ae,{canSubmit:u.isDirty&&u.isValid}),n.jsxs(s.Tabs,{defaultValue:"series",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"series",children:t("chart.series.label")}),n.jsx(s.Tabs.Tab,{value:"metrics",children:t("viz.radar_chart.metric.labels")}),n.jsx(s.Tabs.Tab,{value:"style",children:t("chart.style.label")}),n.jsx(s.Tabs.Tab,{value:"additional_series",ml:"auto",children:t("viz.radar_chart.additional_series.label")})]}),n.jsx(s.Tabs.Panel,{value:"series",p:"md",children:n.jsx(b.Controller,{name:"series_name_key",control:o,render:({field:p})=>n.jsx(q,{label:t("viz.radar_chart.series.series_name_field"),required:!0,sx:{flex:1},...p})})}),n.jsx(s.Tabs.Panel,{value:"metrics",p:"md",children:n.jsx(C_,{control:o,watch:c})}),n.jsx(s.Tabs.Panel,{value:"style",p:"md",children:n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"background.enabled",control:o,render:({field:p})=>n.jsx(s.Checkbox,{label:t("viz.radar_chart.style.show_background"),checked:p.value,onChange:f=>p.onChange(f.currentTarget.checked)})}),n.jsx(b.Controller,{name:"label.enabled",control:o,render:({field:p})=>n.jsx(s.Checkbox,{label:t("viz.radar_chart.style.show_value_label"),checked:p.value,onChange:f=>p.onChange(f.currentTarget.checked)})})]})}),n.jsx(s.Tabs.Panel,{value:"additional_series",p:"md",children:n.jsx(w_,{control:o,watch:c})})]})]})})}const T_=[{lang:"en",resources:{radar_chart:{viz_name:"Radar Chart",series:{series_name_field:"Series Name Field"},metric:{labels:"Metrics",value_formatter:"Value Formatter",add:"Add a metric",delete:"Delete this metric"},additional_series:{label:"Additional Series",intro:"By setting <1>Series Name Field</1>, you may add series from more queries to the chart.",add:"Add a series",delete:"Delete"},style:{show_background:"Show background",show_value_label:"Show value label",color_field:"Color Field"},click_series:{label:"Click radar chart series"}}}},{lang:"zh",resources:{radar_chart:{viz_name:"雷达图",series:{series_name_field:"系列名字段"},metric:{labels:"维度",value_formatter:"数据格式",add:"增加一个维度",delete:"删除这个维度"},additional_series:{label:"扩展系列",intro:"在<1>系列名字段</1>中选择不同查询中的字段,从而实现图表系列的扩展",add:"增加一个扩展系列",delete:"删除这个扩展系列"},style:{show_background:"显示背景",show_value_label:"显示标签文案",color_field:"颜色字段"},click_series:{label:"点击雷达系列"}}}}];function k_(e){const{dimensions:t=[],...r}=e;function a({name:l="",data_key:o="",max:i=10,formatter:c=le}){return{name:l,data_key:o,max:i,formatter:c}}return{...r,dimensions:t.map(a)}}function z_(e){const{dimensions:t=[],...r}=e;return{...r,dimensions:t.map(a=>({...a,id:a.id??a.name}))}}function D_(e){const t={background:{enabled:!0},label:{enabled:!0}};return y.defaultsDeep(t,e)}function I_(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=c=>c&&`${r}.${c}`,{series_name_key:l,dimensions:o,...i}=e;return{...i,series_name_key:a(l),dimensions:o.map(c=>({...c,data_key:a(c.data_key)}))}}catch(r){throw console.error("[Migration failed]",r),r}}function M_(e){const t={additional_series:[]};return y.defaultsDeep(t,e)}function A_(e){const t={...e,dimensions:e.dimensions.map(r=>({...r,max:String(r.max)}))};return delete t.additionalSeries,t}class P_ extends ee{constructor(){super(...arguments);P(this,"VERSION",7)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>{const{config:a}=r;return{...r,version:2,config:k_(a)}}),this.version(3,r=>{const{config:a}=r;return{...r,version:3,config:z_(a)}}),this.version(4,r=>{const{config:a}=r;return{...r,version:4,config:D_(a)}}),this.version(5,(r,a)=>{const{config:l}=r;return{...r,version:5,config:I_(l,a)}}),this.version(6,r=>{const{config:a}=r;return{...r,version:6,config:M_(a)}}),this.version(7,r=>{const{config:a}=r;return{...r,version:7,config:A_(a)}})}}const V_={displayName:"viz.radar_chart.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new P_,name:"radar",viewRender:__,configRender:S_,createConfig:()=>({version:7,config:fn}),triggers:[Fl],translation:T_};function $_(e,t){const{plot:r,transform:a}=e.regression;return t.map(l=>({...r,id:`reg-for-${l.name}`,name:l.name,data:pn(a,l.data),color:l.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:l.name}}))}function Ul(e,t){const r=A(e.x_axis.data_key),a=A(e.regression.y_axis_data_key);return y.uniqBy(t.map(l=>[l[r.columnKey],l[a.columnKey]]),0)}function E_(e,t){const{plot:r,transform:a}=e.regression,l=Ul(e,t);return[{type:"scatter",name:e.y_axis.name,data:l,symbolSize:4,color:"red",markLine:{...r,data:[pn(a,l)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function B_(e,t){const{plot:r,transform:a,group_by_key:l}=e.regression,o=A(l),i=y.groupBy(t,o.columnKey);return Object.entries(i).map(([c,d])=>{const u=Ul(e,d);return{type:"scatter",name:c,data:u,symbolSize:4,markLine:{...r,data:[pn(a,u)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function L_(e,t){if(t.length===0)return[];const{group_by_key:r}=e.regression;return r?B_(e,t):E_(e,t)}function q_(e){return Array.isArray(e)||(e=[e]),e.map(t=>({marker:t.marker,label:t.seriesName,x:t.value[0],y:t.value[1]}))}function O_(e){return X.getTooltip({trigger:"axis",formatter:t=>{const r=q_(t);return r.length===0?"":`
304
+ `}}const v_={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},__=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function x_(e,t){const{series_name_key:r,dimensions:a,additional_series:l}=e;if(!r||a.length===0)return{};const i={radar:{indicator:a.map(({name:c,max:d})=>({name:c,max:d})),splitArea:{show:!1}},tooltip:X.getTooltip({backgroundColor:"rgba(255,255,255,0.6)",formatter:y_(e)}),legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:b_(t,e),color:__};return y.merge({},v_,i)}function w_({conf:e,data:t,width:r,height:a,interactionManager:l,variables:o,instance:i}){const c=h.useMemo(()=>{const{queryID:w,columnKey:m}=P(e.series_name_key),k=y.keyBy(t[w],m),z=e.additional_series.reduce((D,I)=>{const L=P(I.name_key),E=y.keyBy(t[L.queryID],L.columnKey);return{...D,...E}},k);return{...k,...z}},[t,e.series_name_key,e.additional_series]),d=Ie(l.triggerManager,Ql.id),u=h.useRef(null),p=h.useCallback(()=>{var m;const w=(m=u.current)==null?void 0:m.getEchartsInstance();w&&de(i,w.getOption())},[i]),f=h.useCallback(w=>{const m=y.get(c,w.name,{error:"rowData is not found"});d.forEach(k=>{l.runInteraction(k.id,{...w,rowData:m})})},[c,d,l]),v=h.useMemo(()=>({click:f,finished:p}),[f]),_=h.useMemo(()=>x_(y.defaultsDeep({},e,fn),t),[e,t]);return!r||!a?null:n.jsx(he,{echarts:ie,option:_,ref:u,style:{width:r,height:a},onEvents:v,notMerge:!0,theme:"merico-light"})}function m_({context:e,instance:t}){const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},a,fn),[a]),i=e.data,{width:c,height:d}=e.viewport;return!c||!d||!o||y.isEmpty(o==null?void 0:o.dimensions)?null:n.jsx(_e,{width:c,height:d,children:n.jsx(w_,{instance:t,variables:l,width:Oe(c),height:Ne(d),data:i,conf:o,interactionManager:r})})}function C_({control:e,index:t}){const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:`additional_series.${t}.name_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("viz.radar_chart.series.series_name_field"),required:!0,sx:{flex:1},...a})})}),n.jsx(s.Stack,{children:n.jsx(b.Controller,{name:`additional_series.${t}.color_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("viz.radar_chart.style.color_field"),required:!0,clearable:!0,sx:{flex:1},...a})})})]})}function S_({control:e,watch:t}){const{t:r}=x.useTranslation(),a=()=>({id:new Date().getTime().toString(),name_key:"",color_key:""}),l=(o,i)=>i+1;return n.jsxs(n.Fragment,{children:[n.jsx(s.Alert,{icon:n.jsx(S.IconInfoCircle,{size:16}),title:r("viz.radar_chart.additional_series.label"),children:n.jsxs(x.Trans,{i18nKey:"viz.radar_chart.additional_series.intro",children:["By setting ",n.jsx(s.Mark,{children:"Series Name Key"}),", you may add series from more queries to the chart."]})}),n.jsx(H,{control:e,watch:t,name:"additional_series",getItem:a,addButtonText:r("viz.radar_chart.additional_series.add"),deleteButtonText:r("viz.radar_chart.additional_series.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(C_,{control:e,index:i})})]})}function T_({control:e,index:t}){const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",align:"top",children:[n.jsx(b.Controller,{name:`dimensions.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`dimensions.${t}.data_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`dimensions.${t}.max`,control:e,rules:{validate:a=>{if(Number.isNaN(Number(a)))return r("validation.number.require_a_number")}},render:({field:a,fieldState:l})=>{var o;return n.jsx(s.TextInput,{label:r("common.max"),required:!0,sx:{flex:1},...a,error:(o=l.error)==null?void 0:o.message})}})]}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("viz.radar_chart.metric.value_formatter"),labelPosition:"center"}),n.jsx(b.Controller,{name:`dimensions.${t}.formatter`,control:e,render:({field:a})=>n.jsx(je,{...a})})]})]})}function k_({control:e,watch:t}){const{t:r}=x.useTranslation(),a=()=>{const o=new Date().getTime().toString();return{id:o,name:o,data_key:"",max:"100",formatter:ce}},l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsx(n.Fragment,{children:n.jsx(H,{control:e,watch:t,name:"dimensions",getItem:a,addButtonText:r("viz.radar_chart.metric.add"),deleteButtonText:r("viz.radar_chart.metric.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(T_,{control:e,index:i})})})}function z_({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),l=h.useMemo(()=>y.defaultsDeep({},r,fn),[r]),{control:o,handleSubmit:i,watch:c,reset:d,formState:u}=b.useForm({defaultValues:l,mode:"all"});return h.useEffect(()=>{d(l)},[l]),c(["series_name_key","background","label"]),n.jsx("form",{onSubmit:i(a),children:n.jsxs(s.Stack,{gap:"xs",children:[n.jsx(ae,{canSubmit:u.isDirty&&u.isValid}),n.jsxs(s.Tabs,{defaultValue:"series",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"series",children:t("chart.series.label")}),n.jsx(s.Tabs.Tab,{value:"metrics",children:t("viz.radar_chart.metric.labels")}),n.jsx(s.Tabs.Tab,{value:"style",children:t("chart.style.label")}),n.jsx(s.Tabs.Tab,{value:"additional_series",ml:"auto",children:t("viz.radar_chart.additional_series.label")})]}),n.jsx(s.Tabs.Panel,{value:"series",p:"md",children:n.jsx(b.Controller,{name:"series_name_key",control:o,render:({field:p})=>n.jsx(q,{label:t("viz.radar_chart.series.series_name_field"),required:!0,sx:{flex:1},...p})})}),n.jsx(s.Tabs.Panel,{value:"metrics",p:"md",children:n.jsx(k_,{control:o,watch:c})}),n.jsx(s.Tabs.Panel,{value:"style",p:"md",children:n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"background.enabled",control:o,render:({field:p})=>n.jsx(s.Checkbox,{label:t("viz.radar_chart.style.show_background"),checked:p.value,onChange:f=>p.onChange(f.currentTarget.checked)})}),n.jsx(b.Controller,{name:"label.enabled",control:o,render:({field:p})=>n.jsx(s.Checkbox,{label:t("viz.radar_chart.style.show_value_label"),checked:p.value,onChange:f=>p.onChange(f.currentTarget.checked)})})]})}),n.jsx(s.Tabs.Panel,{value:"additional_series",p:"md",children:n.jsx(S_,{control:o,watch:c})})]})]})})}const D_=[{lang:"en",resources:{radar_chart:{viz_name:"Radar Chart",series:{series_name_field:"Series Name Field"},metric:{labels:"Metrics",value_formatter:"Value Formatter",add:"Add a metric",delete:"Delete this metric"},additional_series:{label:"Additional Series",intro:"By setting <1>Series Name Field</1>, you may add series from more queries to the chart.",add:"Add a series",delete:"Delete"},style:{show_background:"Show background",show_value_label:"Show value label",color_field:"Color Field"},click_series:{label:"Click radar chart series"}}}},{lang:"zh",resources:{radar_chart:{viz_name:"雷达图",series:{series_name_field:"系列名字段"},metric:{labels:"维度",value_formatter:"数据格式",add:"增加一个维度",delete:"删除这个维度"},additional_series:{label:"扩展系列",intro:"在<1>系列名字段</1>中选择不同查询中的字段,从而实现图表系列的扩展",add:"增加一个扩展系列",delete:"删除这个扩展系列"},style:{show_background:"显示背景",show_value_label:"显示标签文案",color_field:"颜色字段"},click_series:{label:"点击雷达系列"}}}}];function I_(e){const{dimensions:t=[],...r}=e;function a({name:l="",data_key:o="",max:i=10,formatter:c=ce}){return{name:l,data_key:o,max:i,formatter:c}}return{...r,dimensions:t.map(a)}}function M_(e){const{dimensions:t=[],...r}=e;return{...r,dimensions:t.map(a=>({...a,id:a.id??a.name}))}}function V_(e){const t={background:{enabled:!0},label:{enabled:!0}};return y.defaultsDeep(t,e)}function P_(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=c=>c&&`${r}.${c}`,{series_name_key:l,dimensions:o,...i}=e;return{...i,series_name_key:a(l),dimensions:o.map(c=>({...c,data_key:a(c.data_key)}))}}catch(r){throw console.error("[Migration failed]",r),r}}function A_(e){const t={additional_series:[]};return y.defaultsDeep(t,e)}function $_(e){const t={...e,dimensions:e.dimensions.map(r=>({...r,max:String(r.max)}))};return delete t.additionalSeries,t}class E_ extends ee{constructor(){super(...arguments);V(this,"VERSION",7)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>{const{config:a}=r;return{...r,version:2,config:I_(a)}}),this.version(3,r=>{const{config:a}=r;return{...r,version:3,config:M_(a)}}),this.version(4,r=>{const{config:a}=r;return{...r,version:4,config:V_(a)}}),this.version(5,(r,a)=>{const{config:l}=r;return{...r,version:5,config:P_(l,a)}}),this.version(6,r=>{const{config:a}=r;return{...r,version:6,config:A_(a)}}),this.version(7,r=>{const{config:a}=r;return{...r,version:7,config:$_(a)}})}}const B_={displayName:"viz.radar_chart.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new E_,name:"radar",viewRender:m_,configRender:z_,createConfig:()=>({version:7,config:fn}),triggers:[Ql],translation:D_};function L_(e){const t={x_axis:{axisLabel:{rotate:0,format:ce,overflow:De(),formatter:ye()}},regression:{group_by_key:""}};return y.defaultsDeep(t,e)}function q_(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=c=>c&&`${r}.${c}`,{x_axis:l,regression:o,...i}=e;return{...i,x_axis:{...l,data_key:a(l.data_key)},regression:{...o,group_by_key:a(o.group_by_key),y_axis_data_key:a(o.y_axis_data_key)}}}catch(r){throw console.error("[Migration failed]",r),r}}function O_(e){return{x_axis:{data_key:e.x_axis.data_key},regression:e.regression}}const Yl=()=>({x_axis:{data_key:""},regression:{transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},plot:{type:"line",yAxisIndex:0,color:"#228be6",lineStyle:{type:"solid",width:1}},name:"regression",group_by_key:"",y_axis_data_key:"value"}});function N_(e,t){const{plot:r,transform:a}=e.regression;return t.map(l=>({...r,id:`reg-for-${l.name}`,name:l.name,data:pn(a,l.data),color:l.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:l.name}}))}function Xl(e,t,r,a){return y.uniqBy(t.map(l=>[l[r.columnKey],l[a.columnKey]]),0)}function G_(e,t,r,a){const{plot:l,transform:o}=e.regression,i=Xl(e,t,r,a);return[{type:"scatter",name:"",data:i,symbolSize:4,color:"red",markLine:{...l,data:[pn(o,i)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function F_(e,t,r,a,l){const{plot:o,transform:i}=e.regression,c=y.groupBy(t,l.columnKey);return Object.entries(c).map(([d,u])=>{const p=Xl(e,u,r,a);return{type:"scatter",name:d,data:p,symbolSize:4,markLine:{...o,data:[pn(i,p)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function j_(e,t,r,a,l){const o=t[r.queryID];return!l.columnKey||!l.queryID?G_(e,o,r,a):F_(e,o,r,a,l)}function Q_(e){return Array.isArray(e)||(e=[e]),e.map(t=>({marker:t.marker,label:t.seriesName,x:t.value[0],y:t.value[1]}))}function W_(e,t){return X.getTooltip({trigger:"axis",formatter:r=>{const a=Q_(r);return a.length===0?"":`
305
305
  <table style="width: auto">
306
306
  <thead>
307
307
  <tr>
308
308
  <th/>
309
- ${r.map(({marker:l,label:o})=>`<th style="padding: 0 .5em;">${l} ${o}</th>`).join("")}
309
+ ${a.map(({marker:o,label:i})=>`<th style="padding: 0 .5em;">${o} ${i}</th>`).join("")}
310
310
  </tr>
311
311
  </thead>
312
312
  <tbody>
313
313
  <tr>
314
- <th style="text-align: left; padding: 0 .5em;">${e.x_axis.name}</th>
315
- ${r.map(({x:l})=>`<td style="text-align: right; padding: 0 .5em;">${l}</td>`).join("")}
314
+ <th style="text-align: left; padding: 0 .5em;">${e.columnKey}</th>
315
+ ${a.map(({x:o})=>`<td style="text-align: right; padding: 0 .5em;">${o}</td>`).join("")}
316
316
  </tr>
317
317
  <tr>
318
- <th style="text-align: left; padding: 0 .5em;">${e.y_axis.name}</th>
319
- ${r.map(({y:l})=>`<td style="text-align: right; padding: 0 .5em;">${l}</td>`).join("")}
318
+ <th style="text-align: left; padding: 0 .5em;">${t.columnKey}</th>
319
+ ${a.map(({y:o})=>`<td style="text-align: right; padding: 0 .5em;">${o}</td>`).join("")}
320
320
  </tr>
321
321
  </tbody>
322
322
  </table>
323
- `}})}function N_(e){const{overflow:t,format:r,formatter:a,...l}=e.x_axis.axisLabel,o=Be(t.on_axis);return X.getXAxis({type:"value",name:e.x_axis.name??"",nameLocation:"middle",nameGap:25,axisLabel:{...l,...o,formatter:(i,c)=>{let d=i;try{d=Y(i,r)}catch{}return xe(a)(d,c)}}})}const G_={tooltip:{trigger:"axis"},grid:{top:50,left:5,right:10,bottom:20,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function F_(e,t){const r=L_(e,t),a=$_(e,r),l={xAxis:N_(e),yAxis:X.getYAxis({name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"left"},nameGap:5}),series:[...r,...a],tooltip:O_(e),legend:{show:!0,type:"scroll",orient:"horizontal",align:"left",right:0,top:0,left:"auto",itemGap:20,padding:[4,8,0,140],data:r.map(o=>o.name)}};return y.defaultsDeep({},l,G_)}const Yl={output:"number",mantissa:2,trimMantissa:!0,absolute:!1};function bn(e,t,r){return 1-(1-e)*(t-1)/(t-r-1)}function j_(e,t,r,a){const{x_axis:l,y_axis:o}=a,i=ut.regressionLinear()(r),{a:c,b:d,rSquared:u}=i;return{name:e,expression:n.jsxs(s.Group,{justify:"center",wrap:"nowrap",gap:10,children:[n.jsx(s.Text,{size:"sm",children:o.name}),n.jsx(s.Text,{size:"sm",children:"="}),n.jsx(s.Text,{size:"sm",fw:"bold",c:"red",children:Y(d,Yl)}),n.jsx(s.Text,{size:"sm",children:"+"}),n.jsx(s.Text,{size:"sm",fw:"bold",c:"red",children:Y(c,Yl)}),n.jsx(s.Text,{size:"sm",children:"×"}),n.jsx(s.Text,{size:"sm",children:l.name})]}),rSquared:u,adjustedRSquared:bn(u,t.length,1)}}function Q_(e,t,r,a){const{x_axis:l,y_axis:o}=a,{a:i,b:c,rSquared:d}=ut.regressionExp()(r);return{name:e,expression:n.jsxs(s.Group,{justify:"center",wrap:"nowrap",gap:10,children:[n.jsx(s.Text,{size:"sm",children:o.name}),n.jsx(s.Text,{size:"sm",children:"="}),n.jsx(s.Text,{size:"sm",fw:"bold",c:"gray",children:i}),n.jsx(s.Text,{size:"sm",children:"×"}),n.jsxs(s.Group,{justify:"flex-start",wrap:"nowrap",gap:2,children:[n.jsx(s.Text,{size:"sm",children:"Math.exp("}),n.jsx(s.Text,{size:"sm",fw:"bold",c:"gray",children:c}),n.jsx(s.Text,{size:"sm",children:"×"}),n.jsx(s.Text,{size:"sm",children:l.name}),n.jsx(s.Text,{size:"sm",children:")"})]})]}),rSquared:d,adjustedRSquared:bn(d,t.length,1)}}function W_(e,t,r,a){const{x_axis:l,y_axis:o}=a,{a:i,b:c,rSquared:d}=ut.regressionLog()(r);return{name:e,expression:n.jsxs(s.Group,{justify:"center",wrap:"nowrap",gap:10,children:[n.jsx(s.Text,{size:"sm",children:o.name}),n.jsx(s.Text,{size:"sm",children:"="}),n.jsx(s.Text,{size:"sm",fw:"bold",c:"gray",children:i}),n.jsx(s.Text,{size:"sm",children:"×"}),n.jsxs(s.Group,{justify:"flex-start",wrap:"nowrap",gap:2,children:[n.jsx(s.Text,{size:"sm",children:"Math.log("}),n.jsx(s.Text,{size:"sm",children:l.name}),n.jsx(s.Text,{size:"sm",children:")"}),n.jsx(s.Text,{size:"sm",children:"+"}),n.jsx(s.Text,{size:"sm",fw:"bold",c:"gray",children:c})]})]}),rSquared:d,adjustedRSquared:bn(d,t.length,1)}}function U_(e,t,r,a){const{x_axis:l,y_axis:o,regression:i}=a,c=ut.regressionPoly().order(i.transform.config.order)(r),{rSquared:d}=c;return console.log(c),{name:e,expression:"",rSquared:d,adjustedRSquared:bn(d,t.length,1)}}function Kl(e,t,r){const{regression:a,x_axis:l}=r,o=A(l.data_key),i=A(a.y_axis_data_key),c=t.map(d=>[d[o.columnKey],d[i.columnKey]]);return a.transform.config.method==="linear"?j_(e,t,c,r):a.transform.config.method==="exponential"?Q_(e,t,c,r):a.transform.config.method==="logistic"?W_(e,t,c,r):a.transform.config.method==="polynomial"?U_(e,t,c,r):{name:e,expression:"",rSquared:0,adjustedRSquared:0}}function Y_(e,t){if(!t)return[{name:"",expression:"",rSquared:0,adjustedRSquared:0}];if(!t.regression.group_by_key)return[Kl("",e,t)];const r=A(t.regression.group_by_key),a=y.groupBy(e,r.columnKey);return Object.entries(a).map(([l,o])=>Kl(l,o,t))}const K_={marginTop:"10px","tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Xl({desc:e}){const{t}=x.useTranslation(),{expression:r,rSquared:a,adjustedRSquared:l}=e;return r?n.jsx(s.Table,{fz:14,sx:K_,children:n.jsxs(s.Table.Tbody,{children:[n.jsx(s.Table.Tr,{children:n.jsx(s.Table.Td,{colSpan:2,children:n.jsx(s.Text,{size:"sm",ta:"center",children:r})})}),n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:t("viz.regression_chart.r_sq")}),n.jsx(s.Table.Td,{style:{textAlign:"right"},children:Y(a,{output:"percent",mantissa:1,absolute:!1})})]}),n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:t("viz.regression_chart.r_sq_adjusted")}),n.jsx(s.Table.Td,{style:{textAlign:"right"},children:Y(l,{output:"percent",mantissa:1,absolute:!1})})]})]})}):n.jsx(s.Text,{size:"sm",children:"Unavailable for this regression method"})}function X_({conf:e,queryData:t}){var a;const r=h.useMemo(()=>Y_(t,e),[e,t]);return e.regression.group_by_key?(console.log(r),n.jsxs(s.Tabs,{defaultValue:(a=r[0])==null?void 0:a.name,color:"gray",children:[n.jsx(s.Tabs.List,{grow:!0,children:r.map(l=>n.jsx(s.Tabs.Tab,{value:l.name,children:l.name},l.name))}),r.map(l=>n.jsx(s.Tabs.Panel,{value:l.name,children:n.jsx(Xl,{desc:l})},l.name))]})):n.jsx(Xl,{desc:r[0]})}function Z_({conf:e,queryData:t}){const{t:r}=x.useTranslation();return n.jsxs(s.HoverCard,{shadow:"md",withinPortal:!0,zIndex:320,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Button,{variant:"subtle",size:"compact-xs",leftSection:n.jsx(S.IconInfoCircle,{size:14}),children:r("viz.regression_chart.regression_info")})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(ne,{children:n.jsx(X_,{conf:e,queryData:t})})})]})}function J_(e){return n.jsx(s.Group,{justify:"space-between",sx:{position:"absolute",top:0,left:ve.left,right:ve.right,height:"22px",zIndex:1},children:n.jsx(Z_,{...e})})}const Ar={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:le,overflow:we(),formatter:fe()}},y_axis:{name:"Y Axis"},regression:{transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},plot:{type:"line",yAxisIndex:0,color:"#228be6",lineStyle:{type:"solid",width:1}},name:"regression",group_by_key:"",y_axis_data_key:"value"}};function H_({context:e,instance:t}){const{value:r}=B(e.instanceData,"config"),{width:a,height:l}=e.viewport,o=h.useMemo(()=>{var k;const f=e.data,v=r==null?void 0:r.x_axis.data_key,_=(k=r==null?void 0:r.regression)==null?void 0:k.y_axis_data_key;if(!v||!_)return[];const w=A(v),m=A(_);return f[w.queryID].map(z=>typeof z[m.columnKey]=="number"?z:{...z,[m.columnKey]:Number(z[m.columnKey])})},[e.data,r==null?void 0:r.regression.y_axis_data_key]),i=h.useMemo(()=>F_(y.defaultsDeep({},r,Ar),o),[r,o]),c=h.useRef(null),d=f=>{c.current=f},u=h.useCallback(()=>{const f=c.current;f&&de(t,f.getOption())},[t]),p=h.useMemo(()=>({finished:u}),[u]);return!a||!l||!r?null:n.jsxs(_e,{width:a,height:l,children:[n.jsx(J_,{conf:r,queryData:o}),n.jsx(he,{echarts:ce,onChartReady:d,option:i,onEvents:p,style:Ot(a,l),notMerge:!0,theme:"merico-light"})]})}function R_({control:e,watch:t}){const{t:r,i18n:a}=x.useTranslation();t("regression");const l=t("regression.transform.config.method"),o=t("regression.group_by_key"),i=h.useMemo(()=>[{label:r("chart.regression_line.method.linear"),value:"linear"},{label:r("chart.regression_line.method.exponential"),value:"exponential"},{label:r("chart.regression_line.method.logistic"),value:"logistic"},{label:r("chart.regression_line.method.polynomial"),value:"polynomial"}],[a.language]);return n.jsxs(s.Stack,{children:[n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:"regression.name",control:e,render:({field:c})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...c})})}),n.jsx(b.Controller,{name:"regression.group_by_key",control:e,render:({field:c})=>n.jsx(q,{label:r("chart.series.group_by.label"),clearable:!0,sx:{flex:1},...c})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"regression.transform.config.method",control:e,render:({field:c})=>n.jsx(s.Select,{label:r("chart.regression_line.method.label"),data:i,sx:{flex:1},...c})}),l==="polynomial"&&n.jsx(b.Controller,{name:"regression.transform.config.order",control:e,render:({field:c})=>n.jsx(s.NumberInput,{label:r("chart.regression_line.method.polynomial_order"),sx:{flex:1},...c})})]}),!o&&n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:"regression.plot.color",control:e,render:({field:c})=>n.jsx(ye,{label:r("chart.color.label"),...c})})})]})}function ex({control:e,watch:t}){return t(["x_axis"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:r})=>n.jsx(s.TextInput,{label:"X轴名称",sx:{flex:1},...r})}),n.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:r})=>n.jsx(q,{label:"X轴数据字段",required:!0,sx:{flex:1},...r})})]}),n.jsx(s.Divider,{variant:"dashed",labelPosition:"center",label:"格式化数据"}),n.jsx(s.Stack,{children:n.jsx(b.Controller,{name:"x_axis.axisLabel.format",control:e,render:({field:r})=>n.jsx(Le,{...r})})}),n.jsx(s.Divider,{variant:"dashed",labelPosition:"center",label:"标签文案样式"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:r})=>n.jsx(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:n.jsx(s.Text,{c:"dimmed",size:"sm",children:"度"}),sx:{width:"48%"},styles:{section:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...r})}),n.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:r})=>n.jsx(Qe,{triggerButtonText:"自定义标签文案内容",...r})})]}),n.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:r})=>n.jsx(We,{...r})})]})}function tx({control:e,watch:t}){return t(["y_axis","regression.y_axis_data_key"]),n.jsx(s.Stack,{children:n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:r})=>n.jsx(s.TextInput,{label:"Y轴名称",sx:{flex:1},...r})}),n.jsx(b.Controller,{name:"regression.y_axis_data_key",control:e,render:({field:r})=>n.jsx(q,{label:"Y轴数据字段",required:!0,sx:{flex:1},...r})})]})})}function nx({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaults({},t,Ar),[t]),{control:l,handleSubmit:o,watch:i,formState:c,reset:d}=b.useForm({defaultValues:a});return h.useEffect(()=>{d(a)},[a]),i(["x_axis","y_axis","regression"]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:o(r),children:[n.jsx(ae,{canSubmit:c.isDirty}),n.jsxs(s.Tabs,{defaultValue:"X轴",orientation:"vertical",styles:{panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X轴",children:"X轴"}),n.jsx(s.Tabs.Tab,{value:"Y轴",children:"Y轴"}),n.jsx(s.Tabs.Tab,{value:"回归",children:"回归"})]}),n.jsx(s.Tabs.Panel,{value:"X轴",children:n.jsx(ex,{watch:i,control:l})}),n.jsx(s.Tabs.Panel,{value:"Y轴",children:n.jsx(tx,{watch:i,control:l})}),n.jsx(s.Tabs.Panel,{value:"回归",children:n.jsx(R_,{control:l,watch:i})})]})]})})}function rx(e){const t={x_axis:{axisLabel:{rotate:0,format:le,overflow:we(),formatter:fe()}},regression:{group_by_key:""}};return y.defaultsDeep(t,e)}function ax(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=c=>c&&`${r}.${c}`,{x_axis:l,regression:o,...i}=e;return{...i,x_axis:{...l,data_key:a(l.data_key)},regression:{...o,group_by_key:a(o.group_by_key),y_axis_data_key:a(o.y_axis_data_key)}}}catch(r){throw console.error("[Migration failed]",r),r}}const sx=[{lang:"en",resources:{regression_chart:{viz_name:"Regression Chart",regression_info:"Regression Info",r_sq:"R-Sq",r_sq_adjusted:"R-Sq(Adjusted)"}}},{lang:"zh",resources:{regression_chart:{viz_name:"回归分析图",regression_info:"回归信息",r_sq:"R方",r_sq_adjusted:"R方(调整)"}}}];class lx extends ee{constructor(){super(...arguments);P(this,"VERSION",3)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>({...r,version:2,config:rx(r.config)})),this.version(3,(r,a)=>{const{config:l}=r;return{...r,version:3,config:ax(l,a)}})}}const ox={displayName:"viz.regression_chart.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new lx,name:"regressionChart",viewRender:H_,configRender:nx,createConfig(){return{version:3,config:y.cloneDeep(Ar)}},translation:sx},yn={content:""},ix=T.observer(({context:e})=>{const t=J(),{panel:r}=be(),{value:a}=B(e.instanceData,"config"),{variables:l,data:o}=e,i=h.useMemo(()=>{const c=y.defaults({},a,yn);return c.content?ht(c.content,l,t.payloadForViz,o):""},[o,a,l,t.payloadForViz]);return i?n.jsx(Dt,{value:i,styles:{root:{border:"none",height:"100%"},content:{padding:0}},dashboardStateValues:t.dashboardStateValues,variableAggValueMap:r.variableAggValueMap}):null}),cx=T.observer(({context:e})=>{const{panel:t}=re(),{t:r}=x.useTranslation(),{value:a,set:l}=B(e.instanceData,"config"),o=h.useMemo(()=>y.defaults({},a,yn),[a]),{control:i,handleSubmit:c,watch:d,reset:u}=b.useForm({defaultValues:o});d("content"),h.useEffect(()=>{u(o)},[o]);const p=h.useRef(null),f=()=>{var v;return(v=p.current)==null?void 0:v.click()};return n.jsx("form",{onSubmit:c(l),style:{flexGrow:1,display:"flex",flexDirection:"column"},children:n.jsxs(s.Stack,{gap:"xs",sx:{flexGrow:1},children:[n.jsxs(s.Group,{justify:"flex-start",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",display:"none"},children:[n.jsx(s.Text,{size:"sm",children:r("rich_text.content.label")}),n.jsx(s.ActionIcon,{ref:p,type:"submit",mr:5,variant:"filled",color:"blue",children:n.jsx(S.IconDeviceFloppy,{size:20})})]}),n.jsx(b.Controller,{name:"content",control:i,render:({field:v})=>h.createElement(pt,{...v,key:t.id,styles:{root:{flexGrow:1}},label:r("rich_text.content.label"),onSubmit:f})})]})})}),dx=[{lang:"en",resources:{rich_text:{viz_name:"Rich Text"}}},{lang:"zh",resources:{rich_text:{viz_name:"富文本"}}}];class ux extends ee{constructor(){super(...arguments);P(this,"VERSION",1)}fixMalformedConfig(r){return y.defaults({},r,yn)}configVersions(){this.version(1,r=>({version:1,config:this.fixMalformedConfig(r)}))}}const px={displayName:"viz.rich_text.viz_name",displayGroup:"chart.groups.others",migrator:new ux,name:"richText",viewRender:ix,configRender:cx,createConfig(){return{version:1,config:y.cloneDeep(yn)}},translation:dx},Wt={static:{type:"static",color:qe.random().css()},dynamic:{type:"dynamic",func_content:["function getColor({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here",' // return "blue"',"}"].join(`
324
- `)}};function Zl(){const{on_axis:e,in_tooltip:t}=we();return{label:e,tooltip:t}}const Jl={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},unit:U(),color:Wt.static,label_position:"right",label_overflow:Zl()},stats:{top:"",bottom:""},x_axis:{name:"",data_key:"",unit:U(),axisLabel:{rotate:0,formatter:fe(),overflow:we()}},y_axes:[{name:"Y Axis",position:"left",nameAlignment:"center",label_formatter:le,min:"",max:"",show:!0,mirror:!1}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:wt};function hx(e){const{dataZoom:t=wt,...r}=e;return{...r,dataZoom:t}}function gx(e){const t={scatter:{label_overflow:Zl()}};return y.defaultsDeep(t,e)}function fx(e){const{color:t}=e.scatter;return typeof t=="string"?{...e,scatter:{...e.scatter,color:{...Wt.static,color:t}}}:e}function bx(e){const t=e.reference_lines.map(r=>{const{lineStyle:a={type:"dashed",width:1,color:qe.random().css()},show_in_legend:l=!1,yAxisIndex:o=0}=r;return{...r,lineStyle:a,show_in_legend:l,yAxisIndex:o}});return{...e,reference_lines:t}}function yx(e){const t={tooltip:{trigger:"item"}};return y.defaultsDeep({},e,t)}function vx(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{x_axis:l,scatter:o,tooltip:i,...c}=e;return{...c,x_axis:{...l,data_key:a(l.data_key)},scatter:{...o,y_data_key:a(o.y_data_key),name_data_key:a(o.name_data_key)},tooltip:{...i,metrics:i.metrics.map(d=>({...d,data_key:a(d.data_key)}))}}}catch(r){throw console.error("[Migration failed]",r),r}}function _x(e){const t={x_axis:{axisLabel:{overflow:we()}}};return y.defaultsDeep(t,e)}function xx(e,t){const{stats:r,...a}=e,l=It(r.templates.top,t),o=It(r.templates.bottom,t);return{stats:{top:l??"",bottom:o??""},...a}}function wx(e){const{tooltip:t,...r}=e,a=t.metrics;return{...r,tooltip:{...t,metrics:a.map(l=>({...l,unit:l.unit??U()}))}}}function mx(e){const{scatter:t,x_axis:r}=e;return{...e,x_axis:{...r,unit:r.unit??U()},scatter:{...t,unit:t.unit??U()}}}class Cx extends ee{constructor(){super(...arguments);P(this,"VERSION",13)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>{const{tooltip:a={metrics:[]},...l}=r.config;return{...r,version:2,config:{...l,tooltip:a}}}),this.version(3,r=>({...r,version:3,config:hx(r.config)})),this.version(4,r=>{const{config:a}=r;return{...r,version:5,config:gx(a)}}),this.version(6,r=>{const{config:a}=r;return{...r,version:6,config:fx(a)}}),this.version(7,r=>{const{config:a}=r;return{...r,version:7,config:bx(a)}}),this.version(8,r=>{const{config:a}=r;return{...r,version:8,config:yx(a)}}),this.version(9,(r,a)=>{const{config:l}=r;return{...r,version:9,config:vx(l,a)}}),this.version(10,(r,a)=>{const{config:l}=r;return{...r,version:10,config:_x(l)}}),this.version(11,(r,a)=>{const{config:l}=r;return{...r,version:11,config:xx(l,a.panelModel)}}),this.version(12,r=>{const{config:a}=r;return{...r,version:12,config:wx(a)}}),this.version(13,r=>{const{config:a}=r;return{...r,version:13,config:mx(a)}})}}const Sx=[{lang:"en",resources:{scatter_chart:{viz_name:"Scatter Chart",color:{type:{static:"Static",dynamic:"Dynamic"},dynamic:{setup:"Setup",setup_title:"Setup dynamic color"}},click_scatter:{trigger:"Click Scatter"}}}},{lang:"zh",resources:{scatter_chart:{viz_name:"散点图",color:{type:{static:"具体颜色",dynamic:"动态计算颜色"},dynamic:{setup:"设置",setup_title:"设置动态计算颜色的逻辑"}},click_scatter:{trigger:"点击散点"}}}}],Hl={id:"builtin:echarts:click-scatter-chart:series",displayName:"viz.scatter_chart.click_scatter.trigger",nameRender:kx,configRender:Tx,payload:[{name:"seriesType",description:'"scatter"',valueType:"string"},{name:"componentType",description:'"series"',valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Tx(e){return n.jsx(n.Fragment,{})}function kx(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.scatter_chart.click_scatter.trigger")})}function zx(e,t){if(!e.x_axis.data_key)return[];const r=A(e.x_axis.data_key);return[{source:t[r.queryID]}]}function Dx(e){const t=e.y_axes.some(l=>!!l.name);let r=15;t&&(r+=20),e.dataZoom.x_axis_slider&&(r+=20);let a=5;return e.x_axis.name&&(a+=15),{top:r,bottom:a}}function Ix(){return{show:!1,bottom:0,left:"center",type:"scroll"}}function vn(e,t){if(e)return t[e]??void 0}function Mx({reference_areas:e,variableValueMap:t}){const r=e.map(a=>[{name:a.content.text,value:a.content.text,itemStyle:a.itemStyle,label:a.label,xAxis:vn(a.leftBottomPoint.x_data_key,t),yAxis:vn(a.leftBottomPoint.y_data_key,t)},{xAxis:vn(a.rightTopPoint.x_data_key,t),yAxis:vn(a.rightTopPoint.y_data_key,t)}]);return{type:"scatter",name:"ref_areas",silent:!0,data:[],markArea:{data:r}}}function Ax({type:e,...t},r){if(!e)return 10;if(e==="static"){const{size:l}=t;return l}const{func_content:a}=t;return(l,o)=>{const i=o.data;try{return new Function(`return ${a}`)()({rowData:i,params:o,variables:r},{lodash:y,interpolate:ot.interpolate})}catch(c){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${c.message}`),10}}}function Px({type:e,...t},r){if(!e)return Wt.static.color;if(e==="static"){const{color:l}=t;return l}const{func_content:a}=t;return({value:l})=>{try{return new Function(`return ${a}`)()({rowData:l,variables:r},{lodash:y,interpolate:ot.interpolate})}catch(o){return console.error(`[getSeriesColor] failed parsing custom function, error: ${o.message}`),10}}}function Vx(e,t,r,a){return e.map(l=>{const o=l.orientation==="horizontal",i=o?"yAxis":"xAxis",c=o?"insideEndTop":"end";return{name:l.name,type:"line",hide_in_legend:!l.show_in_legend,yAxisIndex:l.yAxisIndex,data:[],lineStyle:l.lineStyle,markLine:{data:[{name:l.name,[i]:Number(r[l.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:l.lineStyle,label:{formatter:function(){return l.template?jt(l.template,t,a):""},position:c}}}})}function $x({x_axis:e,scatter:t},r){const a=A(e.data_key),l=A(t.y_data_key),o=A(t.name_data_key);return{label:{show:!!t.label_position,position:t.label_position,...Be(t.label_overflow.label),formatter:({value:i})=>i[o.columnKey]},type:"scatter",name:"",xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{color:Px(t.color,r)},symbolSize:Ax(t.symbolSize,r),encode:{x:a.columnKey,y:l.columnKey}}}function Ex(e,t,r,a){return[$x(e,a)].concat(Vx(e.reference_lines,r,a,t)).concat(Mx({reference_areas:e.reference_areas,variableValueMap:a}))}function Rl(e,t,r){const{x_axis:a}=r;return a.axisLabel.formatter.enabled?xe(a.axisLabel.formatter)(e,t):e}function Bx(e,t){const{x_axis:r,tooltip:a}=t;if(a.trigger==="item"){const c=en(e[0].data,r.data_key);return Rl(c,0,t)}const l=e.find(c=>c.axisDim==="x"&&c.axisId==="main-x-axis");if(!l)return"";const{axisValue:o,axisIndex:i}=l;return Rl(o,i,t)}const Lx=e=>Y(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function qx(e,t){const{scatter:r,x_axis:a,y_axes:l,tooltip:o}=e,i=a.unit.show_in_tooltip?a.unit.text:"",c=r.unit.show_in_tooltip?r.unit.text:"",d=o.metrics.reduce((u,{unit:p,name:f})=>(p.show_in_tooltip&&(u[f]=p.text),u),{});return X.getTooltip({trigger:o.trigger,formatter:function(u){const p=t[0]??t.default,f=Array.isArray(u)?u:[u];if(f.length===0)return"";const v=Bx(f,e),_=Ee(e.scatter.label_overflow.tooltip),w=f.map(({value:I})=>`
323
+ `}})}const U_={tooltip:{trigger:"axis"},grid:{top:50,left:5,right:10,bottom:20,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function K_(e,t,r,a,l){if(!Ts(r)||!Ts(a))return[];const o=j_(e,t,r,a,l),i=N_(e,o),c={xAxis:X.getXAxis({type:"value",name:r.columnKey,nameLocation:"middle",nameGap:25}),yAxis:X.getYAxis({name:a.columnKey,nameLocation:"end",nameTextStyle:{align:"left"},nameGap:5}),series:[...o,...i],tooltip:W_(r,a),legend:{show:!!l.columnKey&&!!l.queryID,type:"scroll",orient:"horizontal",align:"left",right:0,top:0,left:"auto",itemGap:20,padding:[8,8,0,140],data:o.map(d=>d.name)}};return y.defaultsDeep({},c,U_)}const Vr=T.observer(h.forwardRef((e,t)=>{const{value:r,onChange:a,queryID:l,clearable:o=!1,...i}=e,{panel:c}=re(),d=h.useMemo(()=>c.dataFieldOptionGroups(r,o,l),[r,o,l]);if(d.length===0){const u=c.explainDataKey(r);return n.jsxs(s.HoverCard,{shadow:"md",position:"bottom-start",withinPortal:!0,zIndex:320,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Box,{children:n.jsx(s.TextInput,{label:i.label,required:i.required,defaultValue:u.columnKey,readOnly:!0,disabled:!0})})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsxs(s.Group,{justify:"flex-start",gap:0,children:[n.jsx(s.Text,{size:"xs",c:u.queryName?"black":"red",ff:"monospace",children:u.queryName??u.queryID}),n.jsx(s.Text,{size:"xs",c:"black",ff:"monospace",children:"."}),n.jsx(s.Text,{size:"xs",c:"red",ff:"monospace",children:u.columnKey})]})})]})}return n.jsx(s.NativeSelect,{ref:t,...i,data:d,value:r,onChange:u=>a(u.currentTarget.value)})})),Y_=({xDataKey:e,yDataKey:t,groupKey:r})=>{const{t:a}=x.useTranslation();return n.jsxs(s.HoverCard,{shadow:"md",withinPortal:!0,zIndex:320,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Button,{variant:"subtle",size:"compact-xs",leftSection:n.jsx(S.IconAdjustments,{size:14}),children:a("viz.regression_chart.customize")})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsxs(te,{children:[n.jsx(Vr,{variant:"unstyled",size:"xs",onChange:e.set,value:e.value,leftSection:n.jsx(s.Text,{size:"xs",children:a("chart.x_axis.label")}),rightSectionWidth:14,w:"auto",miw:"unset"}),n.jsx(Vr,{variant:"unstyled",size:"xs",onChange:t.set,value:t.value,leftSection:n.jsx(s.Text,{size:"xs",children:a("chart.y_axis.label")}),rightSectionWidth:14,w:"auto",miw:"unset"}),n.jsx(Vr,{variant:"unstyled",size:"xs",onChange:r.set,value:r.value,leftSection:n.jsx(s.Text,{size:"xs",children:a("viz.regression_chart.split_by")}),rightSectionWidth:14,w:"auto",miw:"unset",clearable:!0})]})})]})},Zl={output:"number",mantissa:2,trimMantissa:!0,absolute:!1};function bn(e,t,r){return 1-(1-e)*(t-1)/(t-r-1)}function X_(e,t,r,a,l){const o=ut.regressionLinear()(r),{a:i,b:c,rSquared:d}=o;return{name:e,expression:n.jsxs(s.Group,{justify:"center",wrap:"nowrap",gap:10,children:[n.jsx(s.Text,{size:"sm",children:l.columnKey}),n.jsx(s.Text,{size:"sm",children:"="}),n.jsx(s.Text,{size:"sm",fw:"bold",c:"red",children:Y(c,Zl)}),n.jsx(s.Text,{size:"sm",children:"+"}),n.jsx(s.Text,{size:"sm",fw:"bold",c:"red",children:Y(i,Zl)}),n.jsx(s.Text,{size:"sm",children:"×"}),n.jsx(s.Text,{size:"sm",children:a.columnKey})]}),rSquared:d,adjustedRSquared:bn(d,t.length,1)}}function Z_(e,t,r,a,l){const{a:o,b:i,rSquared:c}=ut.regressionExp()(r);return{name:e,expression:n.jsxs(s.Group,{justify:"center",wrap:"nowrap",gap:10,children:[n.jsx(s.Text,{size:"sm",children:l.columnKey}),n.jsx(s.Text,{size:"sm",children:"="}),n.jsx(s.Text,{size:"sm",fw:"bold",c:"gray",children:o}),n.jsx(s.Text,{size:"sm",children:"×"}),n.jsxs(s.Group,{justify:"flex-start",wrap:"nowrap",gap:2,children:[n.jsx(s.Text,{size:"sm",children:"Math.exp("}),n.jsx(s.Text,{size:"sm",fw:"bold",c:"gray",children:i}),n.jsx(s.Text,{size:"sm",children:"×"}),n.jsx(s.Text,{size:"sm",children:a.columnKey}),n.jsx(s.Text,{size:"sm",children:")"})]})]}),rSquared:c,adjustedRSquared:bn(c,t.length,1)}}function J_(e,t,r,a,l){const{a:o,b:i,rSquared:c}=ut.regressionLog()(r);return{name:e,expression:n.jsxs(s.Group,{justify:"center",wrap:"nowrap",gap:10,children:[n.jsx(s.Text,{size:"sm",children:l.columnKey}),n.jsx(s.Text,{size:"sm",children:"="}),n.jsx(s.Text,{size:"sm",fw:"bold",c:"gray",children:o}),n.jsx(s.Text,{size:"sm",children:"×"}),n.jsxs(s.Group,{justify:"flex-start",wrap:"nowrap",gap:2,children:[n.jsx(s.Text,{size:"sm",children:"Math.log("}),n.jsx(s.Text,{size:"sm",children:a.columnKey}),n.jsx(s.Text,{size:"sm",children:")"}),n.jsx(s.Text,{size:"sm",children:"+"}),n.jsx(s.Text,{size:"sm",fw:"bold",c:"gray",children:i})]})]}),rSquared:c,adjustedRSquared:bn(c,t.length,1)}}function H_(e,t,r,a){const{regression:l}=a,o=ut.regressionPoly().order(l.transform.config.order)(r),{rSquared:i}=o;return console.log(o),{name:e,expression:"",rSquared:i,adjustedRSquared:bn(i,t.length,1)}}function Jl(e,t,r,a,l){const{regression:o}=r,i=t.map(c=>[c[a.columnKey],c[l.columnKey]]);return o.transform.config.method==="linear"?X_(e,t,i,a,l):o.transform.config.method==="exponential"?Z_(e,t,i,a,l):o.transform.config.method==="logistic"?J_(e,t,i,a,l):o.transform.config.method==="polynomial"?H_(e,t,i,r):{name:e,expression:"",rSquared:0,adjustedRSquared:0}}function R_(e,t,r,a,l){if(!l)return[{name:"",expression:"",rSquared:0,adjustedRSquared:0}];if(!a.columnKey||!a.queryID)return[Jl("",e,l,t,r)];const o=y.groupBy(e,a.columnKey);return Object.entries(o).map(([i,c])=>Jl(i,c,l,t,r))}const ex={marginTop:"10px","tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Hl({desc:e}){const{t}=x.useTranslation(),{expression:r,rSquared:a,adjustedRSquared:l}=e;return r?n.jsx(s.Table,{fz:14,sx:ex,children:n.jsxs(s.Table.Tbody,{children:[n.jsx(s.Table.Tr,{children:n.jsx(s.Table.Td,{colSpan:2,children:n.jsx(s.Text,{size:"sm",ta:"center",children:r})})}),n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:t("viz.regression_chart.r_sq")}),n.jsx(s.Table.Td,{style:{textAlign:"right"},children:Y(a,{output:"percent",mantissa:1,absolute:!1})})]}),n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:t("viz.regression_chart.r_sq_adjusted")}),n.jsx(s.Table.Td,{style:{textAlign:"right"},children:Y(l,{output:"percent",mantissa:1,absolute:!1})})]})]})}):n.jsx(s.Text,{size:"sm",children:"Unavailable for this regression method"})}function tx({conf:e,queryData:t,x:r,y:a,g:l}){var i;const o=h.useMemo(()=>R_(t,r,a,l,e),[e,t,r,a,l]);return!l.columnKey||!l.queryID?n.jsx(Hl,{desc:o[0]}):n.jsxs(s.Tabs,{defaultValue:(i=o[0])==null?void 0:i.name,color:"gray",children:[n.jsx(s.Tabs.List,{grow:!0,children:o.map(c=>n.jsx(s.Tabs.Tab,{value:c.name,children:c.name},c.name))}),o.map(c=>n.jsx(s.Tabs.Panel,{value:c.name,children:n.jsx(Hl,{desc:c})},c.name))]})}function nx({conf:e,queryData:t,x:r,y:a,g:l}){const{t:o}=x.useTranslation();return n.jsxs(s.HoverCard,{shadow:"md",withinPortal:!0,zIndex:320,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Button,{variant:"subtle",size:"compact-xs",leftSection:n.jsx(S.IconInfoCircle,{size:14}),children:o("viz.regression_chart.regression_info")})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(te,{children:n.jsx(tx,{conf:e,queryData:t,x:r,y:a,g:l})})})]})}function rx({conf:e,context:t,xDataKey:r,yDataKey:a,groupKey:l,x:o,y:i,g:c}){const d=h.useMemo(()=>{var w,m;const u=t.data,p=e==null?void 0:e.x_axis.data_key,f=(w=e==null?void 0:e.regression)==null?void 0:w.y_axis_data_key;if(!p||!f)return[];const v=P(p),_=P(f);return(m=u[v.queryID])==null?void 0:m.map(k=>typeof k[_.columnKey]=="number"?k:{...k,[_.columnKey]:Number(k[_.columnKey])})},[r.value,a.value,t.data]);return n.jsxs(s.Group,{justify:"flex-start",sx:{position:"absolute",top:0,left:ve.left,right:ve.right,height:"22px",zIndex:1},children:[n.jsx(nx,{conf:e,queryData:d,x:o,y:i,g:c}),n.jsx(Y_,{xDataKey:r,yDataKey:a,groupKey:l})]})}const Pr=e=>{const[t,r]=h.useState(e);return{value:t,set:r}},ax=({context:e,instance:t,conf:r,width:a,height:l})=>{const o=Pr(r.x_axis.data_key),i=Pr(r.regression.y_axis_data_key),c=Pr(r.regression.group_by_key),d=P(o.value),u=P(i.value),p=P(c.value),f=h.useMemo(()=>K_(y.defaultsDeep({},r,Yl()),e.data,d,u,p),[r,e.data,d,u,p]),v=h.useRef(null),_=k=>{v.current=k},w=h.useCallback(()=>{const k=v.current;k&&de(t,k.getOption())},[t]),m=h.useMemo(()=>({finished:w}),[w]);return n.jsxs(n.Fragment,{children:[n.jsx(rx,{conf:r,context:e,xDataKey:o,yDataKey:i,groupKey:c,x:d,y:u,g:p}),n.jsx(he,{echarts:ie,onChartReady:_,option:f,onEvents:m,style:Ot(a,l),notMerge:!0,theme:"merico-light"})]})};function sx({context:e,instance:t}){const{value:r}=B(e.instanceData,"config"),{width:a,height:l}=e.viewport;return!a||!l||!r?null:n.jsx(_e,{width:a,height:l,children:n.jsx(ax,{context:e,instance:t,conf:r,width:a,height:l})})}const lx=[{lang:"en",resources:{regression_chart:{viz_name:"Regression Chart",regression_info:"Regression Info",r_sq:"R-Sq",r_sq_adjusted:"R-Sq(Adjusted)",customize:"Customize",split_by:"Split by"}}},{lang:"zh",resources:{regression_chart:{viz_name:"回归分析图",regression_info:"回归信息",r_sq:"R方",r_sq_adjusted:"R方(调整)",customize:"自定义",split_by:"拆分"}}}];function ox({control:e,watch:t}){const{t:r,i18n:a}=x.useTranslation();t("regression");const l=t("regression.transform.config.method"),o=t("regression.group_by_key"),i=h.useMemo(()=>[{label:r("chart.regression_line.method.linear"),value:"linear"},{label:r("chart.regression_line.method.exponential"),value:"exponential"},{label:r("chart.regression_line.method.logistic"),value:"logistic"},{label:r("chart.regression_line.method.polynomial"),value:"polynomial"}],[a.language]);return n.jsxs(n.Fragment,{children:[n.jsx(b.Controller,{name:"regression.group_by_key",control:e,render:({field:c})=>n.jsx(q,{label:"默认拆分字段",description:"按此字段拆分为多个系列",clearable:!0,sx:{flex:1},...c})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"regression.transform.config.method",control:e,render:({field:c})=>n.jsx(s.Select,{label:r("chart.regression_line.method.label"),data:i,sx:{flex:1},...c})}),l==="polynomial"&&n.jsx(b.Controller,{name:"regression.transform.config.order",control:e,render:({field:c})=>n.jsx(s.NumberInput,{label:r("chart.regression_line.method.polynomial_order"),sx:{flex:1},...c})})]}),!o&&n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:"regression.plot.color",control:e,render:({field:c})=>n.jsx(be,{label:r("chart.color.label"),...c})})})]})}function ix({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaults({},t),[t]),{control:l,handleSubmit:o,watch:i,formState:c,reset:d}=b.useForm({defaultValues:a});return h.useEffect(()=>{d(a)},[a]),i(["x_axis","regression"]),t?n.jsxs("form",{onSubmit:o(r),children:[n.jsx(ae,{canSubmit:c.isDirty}),n.jsxs(s.Stack,{gap:"xs",children:[n.jsx(b.Controller,{name:"x_axis.data_key",control:l,render:({field:u})=>n.jsx(q,{label:"默认X轴数据字段",required:!0,sx:{flex:1},...u})}),n.jsx(b.Controller,{name:"regression.y_axis_data_key",control:l,render:({field:u})=>n.jsx(q,{label:"默认Y轴数据字段",required:!0,sx:{flex:1},...u})}),n.jsx(s.Divider,{variant:"dashed"}),n.jsx(ox,{control:l,watch:i})]})]}):null}class cx extends ee{constructor(){super(...arguments);V(this,"VERSION",4)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>({...r,version:2,config:L_(r.config)})),this.version(3,(r,a)=>{const{config:l}=r;return{...r,version:3,config:q_(l,a)}}),this.version(4,(r,a)=>{const{config:l}=r;return{...r,version:4,config:O_(l)}})}}const dx={displayName:"viz.regression_chart.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new cx,name:"regressionChart",viewRender:sx,configRender:ix,createConfig(){return{version:3,config:Yl()}},translation:lx},yn={content:""},ux=T.observer(({context:e})=>{const t=J(),{panel:r}=fe(),{value:a}=B(e.instanceData,"config"),{variables:l,data:o}=e,i=h.useMemo(()=>{const c=y.defaults({},a,yn);return c.content?ht(c.content,l,t.payloadForViz,o):""},[o,a,l,t.payloadForViz]);return i?n.jsx(Dt,{value:i,styles:{root:{border:"none",height:"100%"},content:{padding:0}},dashboardStateValues:t.dashboardStateValues,variableAggValueMap:r.variableAggValueMap}):null}),px=T.observer(({context:e})=>{const{panel:t}=re(),{t:r}=x.useTranslation(),{value:a,set:l}=B(e.instanceData,"config"),o=h.useMemo(()=>y.defaults({},a,yn),[a]),{control:i,handleSubmit:c,watch:d,reset:u}=b.useForm({defaultValues:o});d("content"),h.useEffect(()=>{u(o)},[o]);const p=h.useRef(null),f=()=>{var v;return(v=p.current)==null?void 0:v.click()};return n.jsx("form",{onSubmit:c(l),style:{flexGrow:1,display:"flex",flexDirection:"column"},children:n.jsxs(s.Stack,{gap:"xs",sx:{flexGrow:1},children:[n.jsxs(s.Group,{justify:"flex-start",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",display:"none"},children:[n.jsx(s.Text,{size:"sm",children:r("rich_text.content.label")}),n.jsx(s.ActionIcon,{ref:p,type:"submit",mr:5,variant:"filled",color:"blue",children:n.jsx(S.IconDeviceFloppy,{size:20})})]}),n.jsx(b.Controller,{name:"content",control:i,render:({field:v})=>h.createElement(pt,{...v,key:t.id,styles:{root:{flexGrow:1}},label:r("rich_text.content.label"),onSubmit:f})})]})})}),hx=[{lang:"en",resources:{rich_text:{viz_name:"Rich Text"}}},{lang:"zh",resources:{rich_text:{viz_name:"富文本"}}}];class gx extends ee{constructor(){super(...arguments);V(this,"VERSION",1)}fixMalformedConfig(r){return y.defaults({},r,yn)}configVersions(){this.version(1,r=>({version:1,config:this.fixMalformedConfig(r)}))}}const fx={displayName:"viz.rich_text.viz_name",displayGroup:"chart.groups.others",migrator:new gx,name:"richText",viewRender:ux,configRender:px,createConfig(){return{version:1,config:y.cloneDeep(yn)}},translation:hx},Wt={static:{type:"static",color:Be.random().css()},dynamic:{type:"dynamic",func_content:["function getColor({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here",' // return "blue"',"}"].join(`
324
+ `)}};function Rl(){const{on_axis:e,in_tooltip:t}=De();return{label:e,tooltip:t}}const eo={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},unit:U(),color:Wt.static,label_position:"right",label_overflow:Rl()},stats:{top:"",bottom:""},x_axis:{name:"",data_key:"",unit:U(),axisLabel:{rotate:0,formatter:ye(),overflow:De()}},y_axes:[{name:"Y Axis",position:"left",nameAlignment:"center",label_formatter:ce,min:"",max:"",show:!0,mirror:!1}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:wt};function bx(e){const{dataZoom:t=wt,...r}=e;return{...r,dataZoom:t}}function yx(e){const t={scatter:{label_overflow:Rl()}};return y.defaultsDeep(t,e)}function vx(e){const{color:t}=e.scatter;return typeof t=="string"?{...e,scatter:{...e.scatter,color:{...Wt.static,color:t}}}:e}function _x(e){const t=e.reference_lines.map(r=>{const{lineStyle:a={type:"dashed",width:1,color:Be.random().css()},show_in_legend:l=!1,yAxisIndex:o=0}=r;return{...r,lineStyle:a,show_in_legend:l,yAxisIndex:o}});return{...e,reference_lines:t}}function xx(e){const t={tooltip:{trigger:"item"}};return y.defaultsDeep({},e,t)}function wx(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{x_axis:l,scatter:o,tooltip:i,...c}=e;return{...c,x_axis:{...l,data_key:a(l.data_key)},scatter:{...o,y_data_key:a(o.y_data_key),name_data_key:a(o.name_data_key)},tooltip:{...i,metrics:i.metrics.map(d=>({...d,data_key:a(d.data_key)}))}}}catch(r){throw console.error("[Migration failed]",r),r}}function mx(e){const t={x_axis:{axisLabel:{overflow:De()}}};return y.defaultsDeep(t,e)}function Cx(e,t){const{stats:r,...a}=e,l=It(r.templates.top,t),o=It(r.templates.bottom,t);return{stats:{top:l??"",bottom:o??""},...a}}function Sx(e){const{tooltip:t,...r}=e,a=t.metrics;return{...r,tooltip:{...t,metrics:a.map(l=>({...l,unit:l.unit??U()}))}}}function Tx(e){const{scatter:t,x_axis:r}=e;return{...e,x_axis:{...r,unit:r.unit??U()},scatter:{...t,unit:t.unit??U()}}}class kx extends ee{constructor(){super(...arguments);V(this,"VERSION",13)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>{const{tooltip:a={metrics:[]},...l}=r.config;return{...r,version:2,config:{...l,tooltip:a}}}),this.version(3,r=>({...r,version:3,config:bx(r.config)})),this.version(4,r=>{const{config:a}=r;return{...r,version:5,config:yx(a)}}),this.version(6,r=>{const{config:a}=r;return{...r,version:6,config:vx(a)}}),this.version(7,r=>{const{config:a}=r;return{...r,version:7,config:_x(a)}}),this.version(8,r=>{const{config:a}=r;return{...r,version:8,config:xx(a)}}),this.version(9,(r,a)=>{const{config:l}=r;return{...r,version:9,config:wx(l,a)}}),this.version(10,(r,a)=>{const{config:l}=r;return{...r,version:10,config:mx(l)}}),this.version(11,(r,a)=>{const{config:l}=r;return{...r,version:11,config:Cx(l,a.panelModel)}}),this.version(12,r=>{const{config:a}=r;return{...r,version:12,config:Sx(a)}}),this.version(13,r=>{const{config:a}=r;return{...r,version:13,config:Tx(a)}})}}const zx=[{lang:"en",resources:{scatter_chart:{viz_name:"Scatter Chart",color:{type:{static:"Static",dynamic:"Dynamic"},dynamic:{setup:"Setup",setup_title:"Setup dynamic color"}},click_scatter:{trigger:"Click Scatter"}}}},{lang:"zh",resources:{scatter_chart:{viz_name:"散点图",color:{type:{static:"具体颜色",dynamic:"动态计算颜色"},dynamic:{setup:"设置",setup_title:"设置动态计算颜色的逻辑"}},click_scatter:{trigger:"点击散点"}}}}],to={id:"builtin:echarts:click-scatter-chart:series",displayName:"viz.scatter_chart.click_scatter.trigger",nameRender:Ix,configRender:Dx,payload:[{name:"seriesType",description:'"scatter"',valueType:"string"},{name:"componentType",description:'"series"',valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Dx(e){return n.jsx(n.Fragment,{})}function Ix(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.scatter_chart.click_scatter.trigger")})}function Mx(e,t){if(!e.x_axis.data_key)return[];const r=P(e.x_axis.data_key);return[{source:t[r.queryID]}]}function Vx(e){const t=e.y_axes.some(l=>!!l.name);let r=15;t&&(r+=20),e.dataZoom.x_axis_slider&&(r+=20);let a=5;return e.x_axis.name&&(a+=15),{top:r,bottom:a}}function Px(){return{show:!1,bottom:0,left:"center",type:"scroll"}}function vn(e,t){if(e)return t[e]??void 0}function Ax({reference_areas:e,variableValueMap:t}){const r=e.map(a=>[{name:a.content.text,value:a.content.text,itemStyle:a.itemStyle,label:a.label,xAxis:vn(a.leftBottomPoint.x_data_key,t),yAxis:vn(a.leftBottomPoint.y_data_key,t)},{xAxis:vn(a.rightTopPoint.x_data_key,t),yAxis:vn(a.rightTopPoint.y_data_key,t)}]);return{type:"scatter",name:"ref_areas",silent:!0,data:[],markArea:{data:r}}}function $x({type:e,...t},r){if(!e)return 10;if(e==="static"){const{size:l}=t;return l}const{func_content:a}=t;return(l,o)=>{const i=o.data;try{return new Function(`return ${a}`)()({rowData:i,params:o,variables:r},{lodash:y,interpolate:ot.interpolate})}catch(c){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${c.message}`),10}}}function Ex({type:e,...t},r){if(!e)return Wt.static.color;if(e==="static"){const{color:l}=t;return l}const{func_content:a}=t;return({value:l})=>{try{return new Function(`return ${a}`)()({rowData:l,variables:r},{lodash:y,interpolate:ot.interpolate})}catch(o){return console.error(`[getSeriesColor] failed parsing custom function, error: ${o.message}`),10}}}function Bx(e,t,r,a){return e.map(l=>{const o=l.orientation==="horizontal",i=o?"yAxis":"xAxis",c=o?"insideEndTop":"end";return{name:l.name,type:"line",hide_in_legend:!l.show_in_legend,yAxisIndex:l.yAxisIndex,data:[],lineStyle:l.lineStyle,markLine:{data:[{name:l.name,[i]:Number(r[l.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:l.lineStyle,label:{formatter:function(){return l.template?jt(l.template,t,a):""},position:c}}}})}function Lx({x_axis:e,scatter:t},r){const a=P(e.data_key),l=P(t.y_data_key),o=P(t.name_data_key);return{label:{show:!!t.label_position,position:t.label_position,...Fe(t.label_overflow.label),formatter:({value:i})=>i[o.columnKey]},type:"scatter",name:"",xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{color:Ex(t.color,r)},symbolSize:$x(t.symbolSize,r),encode:{x:a.columnKey,y:l.columnKey}}}function qx(e,t,r,a){return[Lx(e,a)].concat(Bx(e.reference_lines,r,a,t)).concat(Ax({reference_areas:e.reference_areas,variableValueMap:a}))}function no(e,t,r){const{x_axis:a}=r;return a.axisLabel.formatter.enabled?ze(a.axisLabel.formatter)(e,t):e}function Ox(e,t){const{x_axis:r,tooltip:a}=t;if(a.trigger==="item"){const c=en(e[0].data,r.data_key);return no(c,0,t)}const l=e.find(c=>c.axisDim==="x"&&c.axisId==="main-x-axis");if(!l)return"";const{axisValue:o,axisIndex:i}=l;return no(o,i,t)}const Nx=e=>Y(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function Gx(e,t){const{scatter:r,x_axis:a,y_axes:l,tooltip:o}=e,i=a.unit.show_in_tooltip?a.unit.text:"",c=r.unit.show_in_tooltip?r.unit.text:"",d=o.metrics.reduce((u,{unit:p,name:f})=>(p.show_in_tooltip&&(u[f]=p.text),u),{});return X.getTooltip({trigger:o.trigger,formatter:function(u){const p=t[0]??t.default,f=Array.isArray(u)?u:[u];if(f.length===0)return"";const v=Ox(f,e),_=Ee(e.scatter.label_overflow.tooltip),w=f.map(({value:I})=>`
325
325
  <th style="text-align: right; padding-right: 1em">
326
326
  <div style="${_}">${en(I,r.name_data_key)}</div>
327
327
  </th>
@@ -346,7 +346,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
346
346
  <th style="text-align: right; padding: 0 1em;">${I.name}</th>
347
347
  ${f.map(({value:L})=>`
348
348
  <td style="text-align: left; padding: 0 2px 0 1em;">
349
- ${Lx(en(L,I.data_key))}
349
+ ${Nx(en(L,I.data_key))}
350
350
  <strong>${d[I.name]??""}</strong>
351
351
  </td>`).join("")}
352
352
  </tr>`);return k.push(...z),`
@@ -354,7 +354,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
354
354
  <thead><tr>${w.join("")}</tr></thead>
355
355
  <tbody>${k.join("")}</tbody>
356
356
  </table>
357
- `}})}function Ox(e,t){const r=t.every(c=>!Number.isNaN(Number(c))),{overflow:a,...l}=e.x_axis.axisLabel,o=Be(a.on_axis),i=t.length===0;return[X.getXAxis({data:t,name:e.x_axis.name??"",nameGap:i?5:void 0,id:"main-x-axis",type:r?"value":"category",axisLabel:{...l,...o,formatter:xe(l.formatter)}})]}function Nx(e,t){return e.y_axes.map(({nameAlignment:r,min:a,max:l,...o},i)=>{let c=o.position;return c||(c=i>0?"right":"left"),X.getYAxis({...o,minInterval:1,min:a||void 0,max:l||void 0,position:c,axisLine:{show:!0},axisLabel:{show:!0,formatter:t[i]??t.default},nameTextStyle:{align:r},nameLocation:"end",nameGap:15,splitLine:{show:!1}})})}const Gx={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}],grid:{top:10,left:20,right:15,bottom:25,containLabel:!0}};function Fx(e,t,r){const a=r.reduce((d,u)=>{const p=Re(u,t);return d[u.name]=$e(u,p),d},{}),l=e.y_axes.reduce((d,{label_formatter:u},p)=>(d[p]=function(v){let _=v;if(typeof v=="object"&&(Array.isArray(v.value)&&v.value.length===2?_=v.value[1]:_=v.value),!u)return _;try{return Y(_,u)}catch(w){return console.error(w),_}},d),{default:({value:d})=>d}),o=y.uniq(Ve(t,e.x_axis.data_key)),i=Ex(e,t,r,a),c={xAxis:Ox(e,o),yAxis:Nx(e,l),series:i,dataset:zx(e,t),tooltip:qx(e,l),grid:Dx(e),legend:Ix(),dataZoom:on(e.dataZoom)};return y.defaultsDeep({},c,Gx)}function jx({conf:e,data:t,width:r,height:a,interactionManager:l,variables:o,instance:i}){const c=mt(t,e.x_axis.data_key),d=Ie(l.triggerManager,Hl.id),u=h.useCallback(m=>{const k=m.data;d.forEach(z=>{l.runInteraction(z.id,{...m,rowData:k})})},[c,d,l]),p=h.useRef(null),f=J(),v=h.useCallback(()=>{var D;const m=(D=p.current)==null?void 0:D.getEchartsInstance();if(!m)return;const k=ht(e.stats.top,o,f.payloadForViz,t),z=ht(e.stats.bottom,o,f.payloadForViz,t);de(i,{...m.getOption(),statsAboveViz:k,statsBelowViz:z})},[i]),_=h.useMemo(()=>({click:u,finished:v}),[u,v]),w=h.useMemo(()=>Fx(e,t,o),[e,t]);return n.jsx(he,{echarts:ce,option:w,ref:p,style:{width:r,height:a},onEvents:_,notMerge:!0,theme:"merico-light"})}function Qx({context:e,instance:t}){const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},a,Jl),[a]),i=e.data,{width:c,height:d}=e.viewport,[u,p]=h.useState(0),[f,v]=h.useState(0),_=Math.max(0,Fe(d)-u-f),w=Ge(c);return!c||!d?null:n.jsxs(_e,{width:c,height:d,children:[n.jsx(un,{onHeightChange:p,value:o.stats.top,context:e}),n.jsx(jx,{instance:t,variables:l,width:w,height:_,data:i,conf:o,interactionManager:r}),n.jsx(un,{onHeightChange:v,value:o.stats.bottom,context:e})]})}const Wx=h.forwardRef(({value:e,onChange:t,xAxisOptions:r,yAxisOptions:a,variableOptions:l},o)=>{const{t:i,i18n:c}=x.useTranslation(),d=(u,p)=>{const f=y.cloneDeep(e);y.set(f,u,p),t(f)};return n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:i("chart.reference_area.content.label"),labelPosition:"right"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(s.TextInput,{label:i("chart.reference_area.content.content_text"),value:e.content.text,onChange:u=>d("content.text",u.currentTarget.value)}),n.jsx(Vt,{label:i("chart.reference_area.content.text_position"),value:e.label.position,onChange:u=>d("label.position",u)})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:i("chart.reference_area.endpoint.labels"),labelPosition:"right"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[r&&n.jsx(s.Select,{label:i("chart.x_axis.label"),data:r,value:e.xAxisIndex,onChange:u=>d("xAxisIndex",u)}),a&&n.jsx(s.Select,{label:i("chart.y_axis.label"),data:a,value:e.yAxisIndex,onChange:u=>d("xAxisIndex",u)})]}),n.jsxs(s.Stack,{gap:0,children:[n.jsx(s.Text,{size:"14px",c:"#212529",fw:500,children:i("chart.reference_area.endpoint.left_bottom_point")}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(s.Select,{leftSection:n.jsx(s.Text,{size:"sm",children:"x"}),data:l,value:e.leftBottomPoint.x_data_key,onChange:u=>d("leftBottomPoint.x_data_key",u??""),clearable:!0}),n.jsx(s.Select,{leftSection:n.jsx(s.Text,{size:"sm",children:"y"}),data:l,value:e.leftBottomPoint.y_data_key,onChange:u=>d("leftBottomPoint.y_data_key",u??""),clearable:!0})]})]}),n.jsxs(s.Stack,{gap:0,children:[n.jsx(s.Text,{size:"14px",c:"#212529",fw:500,children:i("chart.reference_area.endpoint.right_top_point")}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(s.Select,{leftSection:n.jsx(s.Text,{size:"sm",children:"x"}),data:l,value:e.rightTopPoint.x_data_key,onChange:u=>d("rightTopPoint.x_data_key",u??""),clearable:!0}),n.jsx(s.Select,{leftSection:n.jsx(s.Text,{size:"sm",children:"y"}),data:l,value:e.rightTopPoint.y_data_key,onChange:u=>d("rightTopPoint.y_data_key",u??""),clearable:!0})]})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:i("chart.style.label"),labelPosition:"right"}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(ye,{label:i("chart.color.background_color"),value:e.itemStyle.color,onChange:u=>d("itemStyle.color",u)}),n.jsx(ye,{label:i("chart.color.text_color"),value:e.label.color,onChange:u=>d("label.color",u)})]})]})});function Ux(){const e=new Date().getTime().toString();return{id:e,content:{text:e},itemStyle:{color:"rgba(0,0,0,0.05)"},label:{position:"inside",color:"rgba(0,0,0,0.5)"},leftBottomPoint:{x_data_key:"",y_data_key:""},rightTopPoint:{x_data_key:"",y_data_key:""},xAxisIndex:"0",yAxisIndex:"0"}}function Yx({control:e,watch:t,variables:r}){const{t:a}=x.useTranslation(),l=()=>Ux(),o=h.useMemo(()=>r.map(u=>({label:u.name,value:u.name})),[r]),i=t("y_axes"),c=h.useMemo(()=>i.map(({name:u},p)=>({label:u,value:p.toString()})),[i]),d=(u,p)=>p+1;return n.jsx(H,{control:e,watch:t,name:"reference_areas",getItem:l,addButtonText:a("chart.reference_area.add"),deleteButtonText:a("chart.reference_area.delete"),renderTabName:d,children:({field:u,index:p})=>n.jsx(b.Controller,{name:`reference_areas.${p}`,control:e,render:({field:f})=>n.jsx(s.Stack,{children:n.jsx(Wx,{variableOptions:o,yAxisOptions:c,...f})})})})}function Kx({control:e,index:t,watch:r,variableOptions:a,yAxisOptions:l}){const{t:o}=x.useTranslation(),i=r(`reference_lines.${t}.orientation`);return n.jsxs(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:o("common.name"),placeholder:o("chart.reference_line.name_placeholder"),required:!0,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:c})=>n.jsx(s.Select,{label:o("common.data_field"),required:!0,data:a,sx:{flex:1},...c})})]}),n.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:o("chart.content_template.label"),placeholder:o("chart.content_template.hint"),sx:{flex:1},...c})}),n.jsxs(s.Group,{grow:!0,children:[n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:c})=>n.jsx(gt,{sx:{flex:1},...c})}),i==="vertical"&&n.jsx(s.Text,{mt:-10,c:"dimmed",size:"12px",children:o("chart.reference_line.orientation.vertical_hint")})]}),i==="horizontal"&&n.jsx(b.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:c,onChange:d,...u}})=>n.jsx(s.Select,{label:"Y Axis",data:l,disabled:l.length===0,...u,value:(c==null?void 0:c.toString())??"",onChange:p=>{if(!p){d(0);return}d(Number(p))},sx:{flex:1}})})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:o("chart.style.label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:c})=>n.jsx(Pt,{sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:c})=>n.jsx(s.NumberInput,{label:o("chart.series.line.line_width"),min:1,max:10,sx:{flexGrow:1},...c})})]}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:c})=>n.jsx(ye,{label:o("chart.color.label"),...c})})})]})}function Xx({control:e,watch:t,variables:r}){const{t:a}=x.useTranslation(),l=()=>({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:qe.random().css()},show_in_legend:!1,yAxisIndex:0}),o=h.useMemo(()=>r.map(u=>({label:u.name,value:u.name})),[r]),i=t("y_axes"),c=h.useMemo(()=>i.map(({name:u},p)=>({label:u,value:p.toString()})),[i]),d=(u,p)=>{const f=u.name.trim();return f||p+1};return n.jsx(H,{control:e,watch:t,name:"reference_lines",getItem:l,addButtonText:a("chart.reference_line.add"),deleteButtonText:a("chart.reference_line.delete"),renderTabName:d,children:({field:u,index:p})=>n.jsx(Kx,{control:e,index:p,watch:t,variableOptions:o,yAxisOptions:c})})}const Zx=({value:e,onChange:t})=>{const r=a=>{a&&t(a)};return n.jsx(s.Box,{children:n.jsx(Te,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Jx=({value:e,onChange:t})=>{const{t:r}=x.useTranslation(),[a,{setTrue:l,setFalse:o}]=O.useBoolean(),[i,c]=h.useState(e),d=()=>{o();const{type:v,func_content:_}=i,w={type:v,func_content:_};c(w),t(w)},u=()=>{o(),c(e)},p=v=>{c(_=>({..._,func_content:v}))},f=()=>{p(Wt.dynamic.func_content)};return n.jsxs(n.Fragment,{children:[n.jsx(s.Box,{sx:{width:"50%"},children:n.jsx(s.Button,{color:"grape",variant:"filled",leftSection:n.jsx(S.IconMathFunction,{size:16}),mt:24,onClick:l,sx:{flexGrow:0},children:r("viz.scatter_chart.color.dynamic.setup")})}),n.jsx(s.Modal,{size:800,title:r("viz.scatter_chart.color.dynamic.setup_title"),opened:a,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:a&&n.jsxs(s.Stack,{children:[n.jsx(Zx,{value:i.func_content,onChange:p}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:f,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:r("common.actions.reset_to_default")}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:u,variant:"subtle",children:r("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:d,children:r("common.actions.save")})]})]})]})})]})},Hx=({value:e,onChange:t})=>e.type!=="dynamic"?null:n.jsx(Jx,{value:e,onChange:t}),Rx=({value:e,onChange:t})=>{if(e.type!=="static")return null;const r=a=>{t({...e,color:a})};return n.jsx(s.ColorInput,{label:" ",format:"rgb",value:e.color,onChange:r})},ew=h.forwardRef(({label:e="Color",value:t,onChange:r},a)=>{const{t:l,i18n:o}=x.useTranslation(),i=h.useMemo(()=>[{label:l("viz.scatter_chart.color.type.static"),value:"static"},{label:l("viz.scatter_chart.color.type.dynamic"),value:"dynamic"}],[o.language]),c=d=>{d!=="static"&&d!=="dynamic"||r({...Wt[d]})};return n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(s.Select,{ref:a,label:e,data:i,value:t.type,onChange:c,sx:{flexGrow:1}}),n.jsx(Rx,{value:t,onChange:r}),n.jsx(Hx,{value:t,onChange:r})]})}),tw=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a}=x.useTranslation(),l=i=>{t({...e,label:i})},o=i=>{t({...e,tooltip:i})};return n.jsxs(s.Stack,{ref:r,gap:0,children:[n.jsx(sn,{sectionTitle:a("chart.axis.overflow.section_title.on_axis"),value:e.label,onChange:l}),n.jsx(sn,{sectionTitle:a("chart.axis.overflow.section_title.in_tooltip"),value:e.tooltip,onChange:o})]})});function nw({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["scatter"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"scatter.name_data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.name_data_field"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"scatter.y_data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.value_data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:"scatter.unit",control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})}),n.jsx(s.Divider,{mb:-15,label:r("chart.style.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"scatter.symbolSize",control:e,render:({field:a})=>n.jsx(Tr,{...a})}),n.jsx(b.Controller,{name:"scatter.color",control:e,render:({field:a})=>n.jsx(ew,{...a})}),n.jsx(s.Divider,{mb:-15,label:r("chart.label.label"),labelPosition:"center"}),n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:"scatter.label_position",control:e,render:({field:a})=>n.jsx(Vt,{label:r("chart.label_position.label"),withOffOption:!0,...a,onChange:l=>{a.onChange(l??"")}})})}),n.jsx(b.Controller,{name:"scatter.label_overflow",control:e,render:({field:a})=>n.jsx(tw,{...a})})]})}const rw=T.observer(({control:e,watch:t})=>{const{panel:r}=re(),{t:a}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:"stats.top",control:e,render:({field:l})=>n.jsx(pt,{label:a("chart.stats.template.above_chart"),styles:{root:{flexGrow:1,minHeight:"240px"}},autoSubmit:!0,...l},`${r.id}.stats.top`)}),n.jsx(b.Controller,{name:"stats.bottom",control:e,render:({field:l})=>n.jsx(pt,{label:a("chart.stats.template.under_chart"),styles:{root:{flexGrow:1,minHeight:"240px"}},autoSubmit:!0,...l},`${r.id}.stats.bottom`)})]})}),aw=({control:e,index:t})=>{const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.unit`,control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})})]})},sw=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>({id:Date.now().toString(),data_key:"",name:"",unit:U()}),l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:r("chart.tooltip.additional_metrics.description")})]}),n.jsx(H,{control:e,watch:t,name:"tooltip.metrics",getItem:a,addButtonText:r("chart.tooltip.additional_metrics.add"),deleteButtonText:r("chart.tooltip.additional_metrics.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(aw,{control:e,index:i})})]})};function lw({control:e,watch:t}){const{t:r,i18n:a}=x.useTranslation();t("tooltip.trigger");const l=h.useMemo(()=>[{label:r("chart.tooltip.trigger.scatter_point"),value:"item"},{label:r("chart.tooltip.trigger.x_axis"),value:"axis"}],[a.language]);return n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:"tooltip.trigger",control:e,render:({field:o})=>n.jsx(s.Select,{label:r("chart.tooltip.trigger.label"),data:l,sx:{flexGrow:1},...o})}),n.jsx(s.Divider,{variant:"dashed"}),n.jsx(sw,{control:e,watch:t})]})}function ow({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["x_axis"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:"x_axis.unit",control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})}),n.jsx(s.Divider,{mb:-15,label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:a})=>n.jsx(nt,{sx:{width:"48%"},...a})}),n.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(Qe,{...a})})]}),n.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(We,{...a})})]})}function iw({control:e,index:t}){const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[n.jsx(s.Divider,{mb:-15,mt:15,variant:"dashed",label:r("chart.y_axis.y_axis_name"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:a})=>n.jsx(ft,{sx:{flex:1},...a})})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.y_axis.layout"),labelPosition:"center"}),n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:a})=>n.jsx(Il,{sx:{flex:1},...a})})}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.y_axis.label_format"),labelPosition:"center"}),n.jsx(b.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:a})=>n.jsx(Le,{...a})})]}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.y_axis.value_range"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.y_axis.value_min"),...a})}),n.jsx(b.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.y_axis.value_max"),...a})})]})]})]})}function cw({control:e,watch:t}){const{t:r}=x.useTranslation(),a=()=>({name:"",label_formatter:le,min:"",max:"",show:!0,position:"right",nameAlignment:"right",mirror:!1}),l=(i,c)=>{const d=i.name.trim();return d||c+1},o=({field:i,index:c,fields:d})=>d.length<=1;return n.jsx(H,{control:e,watch:t,name:"y_axes",getItem:a,addButtonText:r("chart.y_axis.add"),deleteButtonText:r("chart.y_axis.delete"),renderTabName:l,deleteDisalbed:o,children:({field:i,index:c})=>n.jsx(iw,{control:e,index:c})})}function dw({conf:e,setConf:t,context:r}){const{t:a}=x.useTranslation(),{variables:l}=r,o=h.useMemo(()=>y.defaults({},e),[e]),{control:i,handleSubmit:c,watch:d,reset:u,formState:p}=b.useForm({defaultValues:o});return h.useEffect(()=>{u(o)},[o]),d(["dataZoom"]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:c(t),children:[n.jsx(ae,{canSubmit:p.isDirty}),n.jsxs(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axis",children:a("chart.x_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Y Axes",children:a("chart.y_axis.labels")}),n.jsx(s.Tabs.Tab,{value:"Scatter",children:a("chart.series.scatter.label")}),n.jsx(s.Tabs.Tab,{value:"Tooltip",children:a("chart.tooltip.label")}),n.jsx(s.Tabs.Tab,{value:"Stats",children:a("chart.stats.label")}),n.jsx(s.Tabs.Tab,{value:"Reference Lines",children:a("chart.reference_line.labels")}),n.jsx(s.Tabs.Tab,{value:"Reference Areas",children:a("chart.reference_area.labels")}),n.jsx(s.Tabs.Tab,{value:"Zooming",children:a("chart.zooming.label")})]}),n.jsx(s.Tabs.Panel,{value:"X Axis",children:n.jsx(ow,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Y Axes",children:n.jsx(cw,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Scatter",children:n.jsx(nw,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Tooltip",children:n.jsx(lw,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Stats",children:n.jsx(rw,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Reference Lines",children:n.jsx(Xx,{variables:l,control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Reference Areas",children:n.jsx(Yx,{variables:l,control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Zooming",children:n.jsx(b.Controller,{name:"dataZoom",control:i,render:({field:f})=>n.jsx(cn,{...f})})})]})]})})}function uw(e){const{value:t,set:r}=B(e.context.instanceData,"config");return t?n.jsx(dw,{conf:t,setConf:r,...e}):null}const pw={displayName:"viz.scatter_chart.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new Cx,name:"scatterChart",viewRender:Qx,configRender:uw,createConfig(){return{version:13,config:y.cloneDeep(Jl)}},triggers:[Hl],translation:Sx},hw={content:"Use double curly brackets to wrap js code: {{ new Date().getTime() }}",vertical_align:"center"};function gw(e){if("variables"in e)return e;const{align:t,size:r,weight:a,color:l,content:{prefix:o="",data_field:i="value",formatter:c={output:"number",mantissa:0},postfix:d=""}={}}=e;return{align:t,template:`${o} \${value} ${d}`,variables:[{name:"value",data_field:i,aggregation:{type:"none",config:{}},formatter:c,color:l,weight:a,size:r}]}}function fw(e){return y.omit(e,["variables"])}function bw(e){const{align:t,...r}=e;return{horizontal_align:t,vertical_align:"center",...r}}function yw(e){const t=y.cloneDeep(e),r=y.get(t,"color.valueRange");return r!==void 0&&y.set(t,"color.valueRange",r.map(a=>Number(a))),t}function vw(e,t){return!t||t==="left"?e:`<p style="text-align: ${t}">${e}</p>`}function _w(e,t){const{horizontal_align:r,template:a,...l}=e;let o=It(a,t);return o=vw(o,r),{content:o,...l}}function xw(e,t){const{content:r,...a}=e;return{content:It(r,t),...a}}class ww extends ee{constructor(){super(...arguments);P(this,"VERSION",5)}configVersions(){this.version(1,r=>({version:1,config:gw(r)})),this.version(2,(r,{panelModel:a})=>{const{config:l}=r;return(l.variables||[]).forEach(i=>{a.variables.find(c=>c.name===i.name)||a.addVariable(yw(i))}),{...r,version:2,config:fw(l)}}),this.version(3,r=>{const{config:a}=r;return{...r,version:3,config:bw(a)}}),this.version(4,(r,{panelModel:a})=>{const{config:l}=r;return{...r,version:4,config:_w(l,a)}}),this.version(5,(r,{panelModel:a})=>{const{config:l}=r;return{...r,version:5,config:xw(l,a)}})}}const eo={id:"builtin:stats:click-stats",displayName:"viz.stats.click_stats.trigger",nameRender:Cw,configRender:mw,payload:[{name:"variables",description:"Panel variables",valueType:"object"}]};function mw(e){return n.jsx(n.Fragment,{})}function Cw(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.stats.click_stats.trigger")})}const Sw={top:"flex-start",center:"center",bottom:"flex-end"};function Tw(e){const t={flexGrow:1};return e>0&&(t.cursor="pointer",t["&:hover"]={textDecoration:"underline"}),t}const kw=T.observer(({context:e,instance:t})=>{const r=h.useRef(null),a=Me({vizManager:e.vizManager,instance:t}),l=Ie(a.triggerManager,eo.id),o=J(),{panel:i}=be(),c=i.viz.conf.config,{data:d,variables:u}=e,{width:p,height:f}=e.viewport,v=h.useMemo(()=>{const w=i.viz.conf.config;return w.content?ht(w.content,u,o.payloadForViz,d):""},[d,i,u,o.payloadForViz]);h.useEffect(()=>{de(t,{content:v})},[v]);const _=h.useCallback(()=>{l.forEach(w=>{a.runInteraction(w.id,{variables:i.variableValueMap})})},[i.variableValueMap,l,a]);return h.useEffect(()=>{if(!r.current)return;const w=r.current.querySelector(".ProseMirror");if(!w)return;const{offsetWidth:m,offsetHeight:k}=w,z=p/m,D=f/k,I=Math.min(z,D);w.style.transform=`scale(${I})`},[r.current,p,f,v]),n.jsx(s.Flex,{className:"viz-stats",sx:{width:p,height:f},align:Sw[c.vertical_align],direction:"row",children:n.jsx(s.Box,{className:"viz-stats--clickable-wrapper",sx:Tw(l.length),onClick:_,children:n.jsx(Dt,{ref:r,value:v,styles:{root:{border:"none",maxWidth:p,maxHeight:f,"&.mantine-RichTextEditor-root":{overflow:"hidden !important"}},content:{height:f,"&.mantine-RichTextEditor-content .ProseMirror":{margin:"0 auto",padding:0,display:"table",width:"auto",height:"auto",maxWidth:"100%",maxHeight:"100%",transformOrigin:"top center"},"&.mantine-RichTextEditor-content .ProseMirror > p":{fontSize:"initial",lineHeight:"initial"}}},dashboardStateValues:o.dashboardStateValues,variableAggValueMap:i.variableAggValueMap})})})}),zw=e=>{const{context:t}=e,{value:r}=B(t.instanceData,"config");return r?n.jsx(kw,{...e}):null},Dw=T.observer(({conf:e,setConf:t})=>{const{panel:r}=re(),{t:a}=x.useTranslation(),l=h.useMemo(()=>y.defaults({},e),[e]),{control:o,handleSubmit:i,watch:c,formState:d,reset:u}=b.useForm({defaultValues:l});return h.useEffect(()=>{u(l)},[l]),c(["content","vertical_align"]),n.jsx("form",{onSubmit:i(t),children:n.jsxs(s.Stack,{gap:"xs",children:[n.jsx(ae,{canSubmit:d.isDirty}),n.jsx(b.Controller,{control:o,name:"vertical_align",render:({field:p})=>n.jsx(_l,{...p})}),n.jsx(b.Controller,{name:"content",control:o,render:({field:p})=>h.createElement(pt,{...p,key:r.id,styles:{root:{flexGrow:1,minHeight:"240px"}},label:a("rich_text.content.label"),autoSubmit:!0})})]})})});function Iw(e){const{value:t,set:r}=B(e.context.instanceData,"config");return t?n.jsx(Dw,{conf:t,setConf:r}):null}const Mw=[{lang:"en",resources:{stats:{viz_name:"Stats",click_stats:{trigger:"Click stats text"}}}},{lang:"zh",resources:{stats:{viz_name:"数据指标",click_stats:{trigger:"点击文字"}}}}],Aw={createConfig(){return{version:5,config:hw}},displayName:"viz.stats.viz_name",displayGroup:"chart.groups.others",migrator:new ww,name:"stats",viewRender:zw,configRender:Iw,triggers:[eo],translation:Mw},Pr={label_key:"",value_key:"",group_key:"",unit:U(),levels:[]};function Pw(e){const t=new Set(e.map(a=>a.parent_id)),r=new Set(e.map(a=>a.id));return t.forEach(a=>{a===null||r.has(a)||e.push({id:a,name:a,parent_id:null})}),e}function Vw(e){const t=Pw(e).map(l=>({...l,children:[]})),r=y.keyBy(t,l=>l.id),a=[];return t.forEach(l=>{if(!l.parent_id||!r[l.parent_id]){a.push(l);return}r[l.parent_id].children.push(l)}),a}function $w(e,t){const{label_key:r,value_key:a,group_key:l}=e;if(!r||!a)return[];const o=A(r),i=A(a),c=A(l),d=t[o.queryID].map(u=>({...u,id:u[o.columnKey],parent_id:u[c.columnKey],name:u[o.columnKey],value:u[i.columnKey]?Number(u[i.columnKey]):u[i.columnKey]}));return l?Vw(d):d}const Ew=e=>({treePathInfo:t,name:r,value:a})=>{if(t.length===1||!e)return r;try{const l=t[t.length-2].value;if(a/l<e)return" "}catch{return r}};function Bw(e){const{levels:t}=e;return t.map(r=>{const{show_label_tolerance:a,...l}=r.label;return{...r,label:{...l,formatter:Ew(a)}}})}function Lw(e){return({treePathInfo:t,name:r,value:a,color:l,marker:o,...i})=>{const c=t.slice(0,t.length-1),d=[`<tr>
357
+ `}})}function Fx(e,t){const r=t.every(c=>!Number.isNaN(Number(c))),{overflow:a,...l}=e.x_axis.axisLabel,o=Fe(a.on_axis),i=t.length===0;return[X.getXAxis({data:t,name:e.x_axis.name??"",nameGap:i?5:void 0,id:"main-x-axis",type:r?"value":"category",axisLabel:{...l,...o,formatter:ze(l.formatter)}})]}function jx(e,t){return e.y_axes.map(({nameAlignment:r,min:a,max:l,...o},i)=>{let c=o.position;return c||(c=i>0?"right":"left"),X.getYAxis({...o,minInterval:1,min:a||void 0,max:l||void 0,position:c,axisLine:{show:!0},axisLabel:{show:!0,formatter:t[i]??t.default},nameTextStyle:{align:r},nameLocation:"end",nameGap:15,splitLine:{show:!1}})})}const Qx={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}],grid:{top:10,left:20,right:15,bottom:25,containLabel:!0}};function Wx(e,t,r){const a=r.reduce((d,u)=>{const p=Je(u,t);return d[u.name]=$e(u,p),d},{}),l=e.y_axes.reduce((d,{label_formatter:u},p)=>(d[p]=function(v){let _=v;if(typeof v=="object"&&(Array.isArray(v.value)&&v.value.length===2?_=v.value[1]:_=v.value),!u)return _;try{return Y(_,u)}catch(w){return console.error(w),_}},d),{default:({value:d})=>d}),o=y.uniq(Ae(t,e.x_axis.data_key)),i=qx(e,t,r,a),c={xAxis:Fx(e,o),yAxis:jx(e,l),series:i,dataset:Mx(e,t),tooltip:Gx(e,l),grid:Vx(e),legend:Px(),dataZoom:on(e.dataZoom)};return y.defaultsDeep({},c,Qx)}function Ux({conf:e,data:t,width:r,height:a,interactionManager:l,variables:o,instance:i}){const c=mt(t,e.x_axis.data_key),d=Ie(l.triggerManager,to.id),u=h.useCallback(m=>{const k=m.data;d.forEach(z=>{l.runInteraction(z.id,{...m,rowData:k})})},[c,d,l]),p=h.useRef(null),f=J(),v=h.useCallback(()=>{var D;const m=(D=p.current)==null?void 0:D.getEchartsInstance();if(!m)return;const k=ht(e.stats.top,o,f.payloadForViz,t),z=ht(e.stats.bottom,o,f.payloadForViz,t);de(i,{...m.getOption(),statsAboveViz:k,statsBelowViz:z})},[i]),_=h.useMemo(()=>({click:u,finished:v}),[u,v]),w=h.useMemo(()=>Wx(e,t,o),[e,t]);return n.jsx(he,{echarts:ie,option:w,ref:p,style:{width:r,height:a},onEvents:_,notMerge:!0,theme:"merico-light"})}function Kx({context:e,instance:t}){const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},a,eo),[a]),i=e.data,{width:c,height:d}=e.viewport,[u,p]=h.useState(0),[f,v]=h.useState(0),_=Math.max(0,Ne(d)-u-f),w=Oe(c);return!c||!d?null:n.jsxs(_e,{width:c,height:d,children:[n.jsx(un,{onHeightChange:p,value:o.stats.top,context:e}),n.jsx(Ux,{instance:t,variables:l,width:w,height:_,data:i,conf:o,interactionManager:r}),n.jsx(un,{onHeightChange:v,value:o.stats.bottom,context:e})]})}const Yx=h.forwardRef(({value:e,onChange:t,xAxisOptions:r,yAxisOptions:a,variableOptions:l},o)=>{const{t:i,i18n:c}=x.useTranslation(),d=(u,p)=>{const f=y.cloneDeep(e);y.set(f,u,p),t(f)};return n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:i("chart.reference_area.content.label"),labelPosition:"right"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(s.TextInput,{label:i("chart.reference_area.content.content_text"),value:e.content.text,onChange:u=>d("content.text",u.currentTarget.value)}),n.jsx(At,{label:i("chart.reference_area.content.text_position"),value:e.label.position,onChange:u=>d("label.position",u)})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:i("chart.reference_area.endpoint.labels"),labelPosition:"right"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[r&&n.jsx(s.Select,{label:i("chart.x_axis.label"),data:r,value:e.xAxisIndex,onChange:u=>d("xAxisIndex",u)}),a&&n.jsx(s.Select,{label:i("chart.y_axis.label"),data:a,value:e.yAxisIndex,onChange:u=>d("xAxisIndex",u)})]}),n.jsxs(s.Stack,{gap:0,children:[n.jsx(s.Text,{size:"14px",c:"#212529",fw:500,children:i("chart.reference_area.endpoint.left_bottom_point")}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(s.Select,{leftSection:n.jsx(s.Text,{size:"sm",children:"x"}),data:l,value:e.leftBottomPoint.x_data_key,onChange:u=>d("leftBottomPoint.x_data_key",u??""),clearable:!0}),n.jsx(s.Select,{leftSection:n.jsx(s.Text,{size:"sm",children:"y"}),data:l,value:e.leftBottomPoint.y_data_key,onChange:u=>d("leftBottomPoint.y_data_key",u??""),clearable:!0})]})]}),n.jsxs(s.Stack,{gap:0,children:[n.jsx(s.Text,{size:"14px",c:"#212529",fw:500,children:i("chart.reference_area.endpoint.right_top_point")}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(s.Select,{leftSection:n.jsx(s.Text,{size:"sm",children:"x"}),data:l,value:e.rightTopPoint.x_data_key,onChange:u=>d("rightTopPoint.x_data_key",u??""),clearable:!0}),n.jsx(s.Select,{leftSection:n.jsx(s.Text,{size:"sm",children:"y"}),data:l,value:e.rightTopPoint.y_data_key,onChange:u=>d("rightTopPoint.y_data_key",u??""),clearable:!0})]})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:i("chart.style.label"),labelPosition:"right"}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(be,{label:i("chart.color.background_color"),value:e.itemStyle.color,onChange:u=>d("itemStyle.color",u)}),n.jsx(be,{label:i("chart.color.text_color"),value:e.label.color,onChange:u=>d("label.color",u)})]})]})});function Xx(){const e=new Date().getTime().toString();return{id:e,content:{text:e},itemStyle:{color:"rgba(0,0,0,0.05)"},label:{position:"inside",color:"rgba(0,0,0,0.5)"},leftBottomPoint:{x_data_key:"",y_data_key:""},rightTopPoint:{x_data_key:"",y_data_key:""},xAxisIndex:"0",yAxisIndex:"0"}}function Zx({control:e,watch:t,variables:r}){const{t:a}=x.useTranslation(),l=()=>Xx(),o=h.useMemo(()=>r.map(u=>({label:u.name,value:u.name})),[r]),i=t("y_axes"),c=h.useMemo(()=>i.map(({name:u},p)=>({label:u,value:p.toString()})),[i]),d=(u,p)=>p+1;return n.jsx(H,{control:e,watch:t,name:"reference_areas",getItem:l,addButtonText:a("chart.reference_area.add"),deleteButtonText:a("chart.reference_area.delete"),renderTabName:d,children:({field:u,index:p})=>n.jsx(b.Controller,{name:`reference_areas.${p}`,control:e,render:({field:f})=>n.jsx(s.Stack,{children:n.jsx(Yx,{variableOptions:o,yAxisOptions:c,...f})})})})}function Jx({control:e,index:t,watch:r,variableOptions:a,yAxisOptions:l}){const{t:o}=x.useTranslation(),i=r(`reference_lines.${t}.orientation`);return n.jsxs(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:o("common.name"),placeholder:o("chart.reference_line.name_placeholder"),required:!0,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:c})=>n.jsx(s.Select,{label:o("common.data_field"),required:!0,data:a,sx:{flex:1},...c})})]}),n.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:o("chart.content_template.label"),placeholder:o("chart.content_template.hint"),sx:{flex:1},...c})}),n.jsxs(s.Group,{grow:!0,children:[n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:c})=>n.jsx(gt,{sx:{flex:1},...c})}),i==="vertical"&&n.jsx(s.Text,{mt:-10,c:"dimmed",size:"12px",children:o("chart.reference_line.orientation.vertical_hint")})]}),i==="horizontal"&&n.jsx(b.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:c,onChange:d,...u}})=>n.jsx(s.Select,{label:"Y Axis",data:l,disabled:l.length===0,...u,value:(c==null?void 0:c.toString())??"",onChange:p=>{if(!p){d(0);return}d(Number(p))},sx:{flex:1}})})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:o("chart.style.label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:c})=>n.jsx(Pt,{sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:c})=>n.jsx(s.NumberInput,{label:o("chart.series.line.line_width"),min:1,max:10,sx:{flexGrow:1},...c})})]}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:c})=>n.jsx(be,{label:o("chart.color.label"),...c})})})]})}function Hx({control:e,watch:t,variables:r}){const{t:a}=x.useTranslation(),l=()=>({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:Be.random().css()},show_in_legend:!1,yAxisIndex:0}),o=h.useMemo(()=>r.map(u=>({label:u.name,value:u.name})),[r]),i=t("y_axes"),c=h.useMemo(()=>i.map(({name:u},p)=>({label:u,value:p.toString()})),[i]),d=(u,p)=>{const f=u.name.trim();return f||p+1};return n.jsx(H,{control:e,watch:t,name:"reference_lines",getItem:l,addButtonText:a("chart.reference_line.add"),deleteButtonText:a("chart.reference_line.delete"),renderTabName:d,children:({field:u,index:p})=>n.jsx(Jx,{control:e,index:p,watch:t,variableOptions:o,yAxisOptions:c})})}const Rx=({value:e,onChange:t})=>{const r=a=>{a&&t(a)};return n.jsx(s.Box,{children:n.jsx(Ce,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},ew=({value:e,onChange:t})=>{const{t:r}=x.useTranslation(),[a,{setTrue:l,setFalse:o}]=O.useBoolean(),[i,c]=h.useState(e),d=()=>{o();const{type:v,func_content:_}=i,w={type:v,func_content:_};c(w),t(w)},u=()=>{o(),c(e)},p=v=>{c(_=>({..._,func_content:v}))},f=()=>{p(Wt.dynamic.func_content)};return n.jsxs(n.Fragment,{children:[n.jsx(s.Box,{sx:{width:"50%"},children:n.jsx(s.Button,{color:"grape",variant:"filled",leftSection:n.jsx(S.IconMathFunction,{size:16}),mt:24,onClick:l,sx:{flexGrow:0},children:r("viz.scatter_chart.color.dynamic.setup")})}),n.jsx(s.Modal,{size:800,title:r("viz.scatter_chart.color.dynamic.setup_title"),opened:a,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:a&&n.jsxs(s.Stack,{children:[n.jsx(Rx,{value:i.func_content,onChange:p}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:f,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:r("common.actions.reset_to_default")}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:u,variant:"subtle",children:r("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:d,children:r("common.actions.save")})]})]})]})})]})},tw=({value:e,onChange:t})=>e.type!=="dynamic"?null:n.jsx(ew,{value:e,onChange:t}),nw=({value:e,onChange:t})=>{if(e.type!=="static")return null;const r=a=>{t({...e,color:a})};return n.jsx(s.ColorInput,{label:" ",format:"rgb",value:e.color,onChange:r})},rw=h.forwardRef(({label:e="Color",value:t,onChange:r},a)=>{const{t:l,i18n:o}=x.useTranslation(),i=h.useMemo(()=>[{label:l("viz.scatter_chart.color.type.static"),value:"static"},{label:l("viz.scatter_chart.color.type.dynamic"),value:"dynamic"}],[o.language]),c=d=>{d!=="static"&&d!=="dynamic"||r({...Wt[d]})};return n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(s.Select,{ref:a,label:e,data:i,value:t.type,onChange:c,sx:{flexGrow:1}}),n.jsx(nw,{value:t,onChange:r}),n.jsx(tw,{value:t,onChange:r})]})}),aw=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a}=x.useTranslation(),l=i=>{t({...e,label:i})},o=i=>{t({...e,tooltip:i})};return n.jsxs(s.Stack,{ref:r,gap:0,children:[n.jsx(sn,{sectionTitle:a("chart.axis.overflow.section_title.on_axis"),value:e.label,onChange:l}),n.jsx(sn,{sectionTitle:a("chart.axis.overflow.section_title.in_tooltip"),value:e.tooltip,onChange:o})]})});function sw({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["scatter"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"scatter.name_data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.name_data_field"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"scatter.y_data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.value_data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:"scatter.unit",control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})}),n.jsx(s.Divider,{mb:-15,label:r("chart.style.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"scatter.symbolSize",control:e,render:({field:a})=>n.jsx(Tr,{...a})}),n.jsx(b.Controller,{name:"scatter.color",control:e,render:({field:a})=>n.jsx(rw,{...a})}),n.jsx(s.Divider,{mb:-15,label:r("chart.label.label"),labelPosition:"center"}),n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:"scatter.label_position",control:e,render:({field:a})=>n.jsx(At,{label:r("chart.label_position.label"),withOffOption:!0,...a,onChange:l=>{a.onChange(l??"")}})})}),n.jsx(b.Controller,{name:"scatter.label_overflow",control:e,render:({field:a})=>n.jsx(aw,{...a})})]})}const lw=T.observer(({control:e,watch:t})=>{const{panel:r}=re(),{t:a}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:"stats.top",control:e,render:({field:l})=>n.jsx(pt,{label:a("chart.stats.template.above_chart"),styles:{root:{flexGrow:1,minHeight:"240px"}},autoSubmit:!0,...l},`${r.id}.stats.top`)}),n.jsx(b.Controller,{name:"stats.bottom",control:e,render:({field:l})=>n.jsx(pt,{label:a("chart.stats.template.under_chart"),styles:{root:{flexGrow:1,minHeight:"240px"}},autoSubmit:!0,...l},`${r.id}.stats.bottom`)})]})}),ow=({control:e,index:t})=>{const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.unit`,control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})})]})},iw=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>({id:Date.now().toString(),data_key:"",name:"",unit:U()}),l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:r("chart.tooltip.additional_metrics.description")})]}),n.jsx(H,{control:e,watch:t,name:"tooltip.metrics",getItem:a,addButtonText:r("chart.tooltip.additional_metrics.add"),deleteButtonText:r("chart.tooltip.additional_metrics.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(ow,{control:e,index:i})})]})};function cw({control:e,watch:t}){const{t:r,i18n:a}=x.useTranslation();t("tooltip.trigger");const l=h.useMemo(()=>[{label:r("chart.tooltip.trigger.scatter_point"),value:"item"},{label:r("chart.tooltip.trigger.x_axis"),value:"axis"}],[a.language]);return n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:"tooltip.trigger",control:e,render:({field:o})=>n.jsx(s.Select,{label:r("chart.tooltip.trigger.label"),data:l,sx:{flexGrow:1},...o})}),n.jsx(s.Divider,{variant:"dashed"}),n.jsx(iw,{control:e,watch:t})]})}function dw({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["x_axis"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:"x_axis.unit",control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})}),n.jsx(s.Divider,{mb:-15,label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:a})=>n.jsx(nt,{sx:{width:"48%"},...a})}),n.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(He,{...a})})]}),n.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(Re,{...a})})]})}function uw({control:e,index:t}){const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[n.jsx(s.Divider,{mb:-15,mt:15,variant:"dashed",label:r("chart.y_axis.y_axis_name"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:a})=>n.jsx(ft,{sx:{flex:1},...a})})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.y_axis.layout"),labelPosition:"center"}),n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:a})=>n.jsx(Vl,{sx:{flex:1},...a})})}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.y_axis.label_format"),labelPosition:"center"}),n.jsx(b.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:a})=>n.jsx(je,{...a})})]}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.y_axis.value_range"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.y_axis.value_min"),...a})}),n.jsx(b.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.y_axis.value_max"),...a})})]})]})]})}function pw({control:e,watch:t}){const{t:r}=x.useTranslation(),a=()=>({name:"",label_formatter:ce,min:"",max:"",show:!0,position:"right",nameAlignment:"right",mirror:!1}),l=(i,c)=>{const d=i.name.trim();return d||c+1},o=({field:i,index:c,fields:d})=>d.length<=1;return n.jsx(H,{control:e,watch:t,name:"y_axes",getItem:a,addButtonText:r("chart.y_axis.add"),deleteButtonText:r("chart.y_axis.delete"),renderTabName:l,deleteDisalbed:o,children:({field:i,index:c})=>n.jsx(uw,{control:e,index:c})})}function hw({conf:e,setConf:t,context:r}){const{t:a}=x.useTranslation(),{variables:l}=r,o=h.useMemo(()=>y.defaults({},e),[e]),{control:i,handleSubmit:c,watch:d,reset:u,formState:p}=b.useForm({defaultValues:o});return h.useEffect(()=>{u(o)},[o]),d(["dataZoom"]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:c(t),children:[n.jsx(ae,{canSubmit:p.isDirty}),n.jsxs(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axis",children:a("chart.x_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Y Axes",children:a("chart.y_axis.labels")}),n.jsx(s.Tabs.Tab,{value:"Scatter",children:a("chart.series.scatter.label")}),n.jsx(s.Tabs.Tab,{value:"Tooltip",children:a("chart.tooltip.label")}),n.jsx(s.Tabs.Tab,{value:"Stats",children:a("chart.stats.label")}),n.jsx(s.Tabs.Tab,{value:"Reference Lines",children:a("chart.reference_line.labels")}),n.jsx(s.Tabs.Tab,{value:"Reference Areas",children:a("chart.reference_area.labels")}),n.jsx(s.Tabs.Tab,{value:"Zooming",children:a("chart.zooming.label")})]}),n.jsx(s.Tabs.Panel,{value:"X Axis",children:n.jsx(dw,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Y Axes",children:n.jsx(pw,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Scatter",children:n.jsx(sw,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Tooltip",children:n.jsx(cw,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Stats",children:n.jsx(lw,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Reference Lines",children:n.jsx(Hx,{variables:l,control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Reference Areas",children:n.jsx(Zx,{variables:l,control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Zooming",children:n.jsx(b.Controller,{name:"dataZoom",control:i,render:({field:f})=>n.jsx(cn,{...f})})})]})]})})}function gw(e){const{value:t,set:r}=B(e.context.instanceData,"config");return t?n.jsx(hw,{conf:t,setConf:r,...e}):null}const fw={displayName:"viz.scatter_chart.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new kx,name:"scatterChart",viewRender:Kx,configRender:gw,createConfig(){return{version:13,config:y.cloneDeep(eo)}},triggers:[to],translation:zx},bw={content:"Use double curly brackets to wrap js code: {{ new Date().getTime() }}",vertical_align:"center"};function yw(e){if("variables"in e)return e;const{align:t,size:r,weight:a,color:l,content:{prefix:o="",data_field:i="value",formatter:c={output:"number",mantissa:0},postfix:d=""}={}}=e;return{align:t,template:`${o} \${value} ${d}`,variables:[{name:"value",data_field:i,aggregation:{type:"none",config:{}},formatter:c,color:l,weight:a,size:r}]}}function vw(e){return y.omit(e,["variables"])}function _w(e){const{align:t,...r}=e;return{horizontal_align:t,vertical_align:"center",...r}}function xw(e){const t=y.cloneDeep(e),r=y.get(t,"color.valueRange");return r!==void 0&&y.set(t,"color.valueRange",r.map(a=>Number(a))),t}function ww(e,t){return!t||t==="left"?e:`<p style="text-align: ${t}">${e}</p>`}function mw(e,t){const{horizontal_align:r,template:a,...l}=e;let o=It(a,t);return o=ww(o,r),{content:o,...l}}function Cw(e,t){const{content:r,...a}=e;return{content:It(r,t),...a}}class Sw extends ee{constructor(){super(...arguments);V(this,"VERSION",5)}configVersions(){this.version(1,r=>({version:1,config:yw(r)})),this.version(2,(r,{panelModel:a})=>{const{config:l}=r;return(l.variables||[]).forEach(i=>{a.variables.find(c=>c.name===i.name)||a.addVariable(xw(i))}),{...r,version:2,config:vw(l)}}),this.version(3,r=>{const{config:a}=r;return{...r,version:3,config:_w(a)}}),this.version(4,(r,{panelModel:a})=>{const{config:l}=r;return{...r,version:4,config:mw(l,a)}}),this.version(5,(r,{panelModel:a})=>{const{config:l}=r;return{...r,version:5,config:Cw(l,a)}})}}const ro={id:"builtin:stats:click-stats",displayName:"viz.stats.click_stats.trigger",nameRender:kw,configRender:Tw,payload:[{name:"variables",description:"Panel variables",valueType:"object"}]};function Tw(e){return n.jsx(n.Fragment,{})}function kw(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.stats.click_stats.trigger")})}const zw={top:"flex-start",center:"center",bottom:"flex-end"};function Dw(e){const t={flexGrow:1};return e>0&&(t.cursor="pointer",t["&:hover"]={textDecoration:"underline"}),t}const Iw=T.observer(({context:e,instance:t})=>{const r=h.useRef(null),a=Me({vizManager:e.vizManager,instance:t}),l=Ie(a.triggerManager,ro.id),o=J(),{panel:i}=fe(),c=i.viz.conf.config,{data:d,variables:u}=e,{width:p,height:f}=e.viewport,v=h.useMemo(()=>{const w=i.viz.conf.config;return w.content?ht(w.content,u,o.payloadForViz,d):""},[d,i,u,o.payloadForViz]);h.useEffect(()=>{de(t,{content:v})},[v]);const _=h.useCallback(()=>{l.forEach(w=>{a.runInteraction(w.id,{variables:i.variableValueMap})})},[i.variableValueMap,l,a]);return h.useEffect(()=>{if(!r.current)return;const w=r.current.querySelector(".ProseMirror");if(!w)return;const{offsetWidth:m,offsetHeight:k}=w,z=p/m,D=f/k,I=Math.min(z,D);w.style.transform=`scale(${I})`},[r.current,p,f,v]),n.jsx(s.Flex,{className:"viz-stats",sx:{width:p,height:f},align:zw[c.vertical_align],direction:"row",children:n.jsx(s.Box,{className:"viz-stats--clickable-wrapper",sx:Dw(l.length),onClick:_,children:n.jsx(Dt,{ref:r,value:v,styles:{root:{border:"none",maxWidth:p,maxHeight:f,"&.mantine-RichTextEditor-root":{overflow:"hidden !important"}},content:{height:f,"&.mantine-RichTextEditor-content .ProseMirror":{margin:"0 auto",padding:0,display:"table",width:"auto",height:"auto",maxWidth:"100%",maxHeight:"100%",transformOrigin:"top center"},"&.mantine-RichTextEditor-content .ProseMirror > p":{fontSize:"initial",lineHeight:"initial"}}},dashboardStateValues:o.dashboardStateValues,variableAggValueMap:i.variableAggValueMap})})})}),Mw=e=>{const{context:t}=e,{value:r}=B(t.instanceData,"config");return r?n.jsx(Iw,{...e}):null},Vw=T.observer(({conf:e,setConf:t})=>{const{panel:r}=re(),{t:a}=x.useTranslation(),l=h.useMemo(()=>y.defaults({},e),[e]),{control:o,handleSubmit:i,watch:c,formState:d,reset:u}=b.useForm({defaultValues:l});return h.useEffect(()=>{u(l)},[l]),c(["content","vertical_align"]),n.jsx("form",{onSubmit:i(t),children:n.jsxs(s.Stack,{gap:"xs",children:[n.jsx(ae,{canSubmit:d.isDirty}),n.jsx(b.Controller,{control:o,name:"vertical_align",render:({field:p})=>n.jsx(wl,{...p})}),n.jsx(b.Controller,{name:"content",control:o,render:({field:p})=>h.createElement(pt,{...p,key:r.id,styles:{root:{flexGrow:1,minHeight:"240px"}},label:a("rich_text.content.label"),autoSubmit:!0})})]})})});function Pw(e){const{value:t,set:r}=B(e.context.instanceData,"config");return t?n.jsx(Vw,{conf:t,setConf:r}):null}const Aw=[{lang:"en",resources:{stats:{viz_name:"Stats",click_stats:{trigger:"Click stats text"}}}},{lang:"zh",resources:{stats:{viz_name:"数据指标",click_stats:{trigger:"点击文字"}}}}],$w={createConfig(){return{version:5,config:bw}},displayName:"viz.stats.viz_name",displayGroup:"chart.groups.others",migrator:new Sw,name:"stats",viewRender:Mw,configRender:Pw,triggers:[ro],translation:Aw},Ar={label_key:"",value_key:"",group_key:"",unit:U(),levels:[]};function Ew(e){const t=new Set(e.map(a=>a.parent_id)),r=new Set(e.map(a=>a.id));return t.forEach(a=>{a===null||r.has(a)||e.push({id:a,name:a,parent_id:null})}),e}function Bw(e){const t=Ew(e).map(l=>({...l,children:[]})),r=y.keyBy(t,l=>l.id),a=[];return t.forEach(l=>{if(!l.parent_id||!r[l.parent_id]){a.push(l);return}r[l.parent_id].children.push(l)}),a}function Lw(e,t){const{label_key:r,value_key:a,group_key:l}=e;if(!r||!a)return[];const o=P(r),i=P(a),c=P(l),d=t[o.queryID].map(u=>({...u,id:u[o.columnKey],parent_id:u[c.columnKey],name:u[o.columnKey],value:u[i.columnKey]?Number(u[i.columnKey]):u[i.columnKey]}));return l?Bw(d):d}const qw=e=>({treePathInfo:t,name:r,value:a})=>{if(t.length===1||!e)return r;try{const l=t[t.length-2].value;if(a/l<e)return" "}catch{return r}};function Ow(e){const{levels:t}=e;return t.map(r=>{const{show_label_tolerance:a,...l}=r.label;return{...r,label:{...l,formatter:qw(a)}}})}function Nw(e){return({treePathInfo:t,name:r,value:a,color:l,marker:o,...i})=>{const c=t.slice(0,t.length-1),d=[`<tr>
358
358
  <th style="text-align: right; padding: 0 1em;">Value</th>
359
359
  <td style="text-align: left; padding: 0 2px 0 1em;">${a}</td>
360
360
  <th style="text-align: left; padding: 0;">
@@ -375,9 +375,9 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
375
375
  <table style="width: auto">
376
376
  <tbody>${d.join("")}</tbody>
377
377
  </table>
378
- `}}function qw(e){const t=e.unit.show_in_tooltip?e.unit.text:"";return X.getTooltip({trigger:"item",formatter:Lw(t)})}const Ow={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function Nw(e,t,r){r.reduce((o,i)=>{const c=Re(i,t);return o[i.name]=$e(i,c),o},{});const l={series:{data:$w(e,t),levels:Bw(e)},tooltip:qw(e)};return y.defaultsDeep({},l,Ow)}function Gw({context:e,instance:t}){const{variables:r}=e,{value:a}=B(e.instanceData,"config"),l=h.useMemo(()=>y.defaults({},a,Pr),[a]),o=e.data,{width:i,height:c}=e.viewport,d=h.useRef(null),u=h.useCallback(()=>{var _;const v=(_=d.current)==null?void 0:_.getEchartsInstance();v&&de(t,v.getOption())},[t]),p=h.useMemo(()=>({finished:u}),[u]),f=h.useMemo(()=>Nw(l,o,r),[l,o,r]);return!i||!c?null:n.jsx(_e,{width:i,height:c,children:n.jsx(he,{echarts:ce,option:f,ref:d,onEvents:p,style:Ot(i,c),notMerge:!0,theme:"merico-light"})})}function Fw({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["label_key","value_key","group_key"]),n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:"label_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.name_data_field"),required:!0,...a})}),n.jsx(b.Controller,{name:"value_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.value_data_field"),required:!0,...a})}),n.jsx(b.Controller,{name:"group_key",control:e,render:({field:a})=>n.jsx(q,{label:r("viz.sunburst_chart.group_key"),clearable:!0,...a})}),n.jsx(b.Controller,{name:"unit",control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})})]})}const jw=({control:e,index:t})=>{const{t:r,i18n:a}=x.useTranslation(),l=h.useMemo(()=>[{label:r("viz.sunburst_chart.label.rotate.radial"),value:"radial"},{label:r("viz.sunburst_chart.label.rotate.tangential"),value:"tangential"},{label:r("viz.sunburst_chart.label.rotate.none"),value:"0"}],[a.language]);return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`levels.${t}.r0`,control:e,render:({field:o})=>n.jsx(s.TextInput,{label:r("viz.sunburst_chart.level.inside_radius"),placeholder:"0%",...o})}),n.jsx(b.Controller,{name:`levels.${t}.r`,control:e,render:({field:o})=>n.jsx(s.TextInput,{label:r("viz.sunburst_chart.level.outside_radius"),placeholder:"50%",...o})})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:r("chart.label.label_full"),labelPosition:"center"}),n.jsx(b.Controller,{name:`levels.${t}.label.show_label_tolerance`,control:e,render:({field:o})=>n.jsx(s.NumberInput,{label:r("viz.sunburst_chart.label.show_label_tolerance"),decimalScale:4,step:5e-4,min:0,max:1,...o})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`levels.${t}.label.rotate`,control:e,render:({field:o})=>n.jsx(s.Select,{label:r("viz.sunburst_chart.label.rotate.label"),data:l,...o})}),n.jsx(b.Controller,{name:`levels.${t}.label.align`,control:e,render:({field:o})=>n.jsx(ft,{...o})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`levels.${t}.label.position`,control:e,render:({field:o})=>n.jsx(Vt,{label:r("chart.label_position.label"),...o,onChange:i=>{i&&o.onChange(i)}})}),n.jsx(b.Controller,{name:`levels.${t}.label.padding`,control:e,render:({field:o})=>n.jsx(s.NumberInput,{label:r("chart.padding"),min:0,hideControls:!0,...o})})]})]})},Qw=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>({id:Date.now().toString(),r0:"",r:"",label:{show_label_tolerance:.001,rotate:"0",align:"center",position:"inside",padding:0}}),l=(o,i)=>i+1;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:r("viz.sunburst_chart.level.hint")})]}),n.jsx(s.Divider,{variant:"dashed",my:10}),n.jsx(H,{control:e,watch:t,name:"levels",getItem:a,addButtonText:r("viz.sunburst_chart.level.add"),deleteButtonText:r("viz.sunburst_chart.level.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(jw,{control:e,index:i})})]})};function Ww({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),l=h.useMemo(()=>y.defaultsDeep({},r,Pr),[r]),o=h.useMemo(()=>y.clone(l),[l]),{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=b.useForm({defaultValues:o});h.useEffect(()=>{p(o)},[o]),d(["label_key","value_key","group_key","levels"]);const[f,v]=h.useState("Data");return n.jsx("form",{onSubmit:c(a),children:n.jsxs(s.Stack,{gap:"xs",children:[n.jsx(ae,{canSubmit:u.isDirty}),n.jsxs(s.Tabs,{value:f,onChange:v,orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"Data",children:t("data.label")}),n.jsx(s.Tabs.Tab,{value:"Levels",children:t("viz.sunburst_chart.level.labels")})]}),n.jsx(s.Tabs.Panel,{value:"Data",children:n.jsx(Fw,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Levels",children:n.jsx(Qw,{control:i,watch:d})})]})]})})}const Uw=[{lang:"en",resources:{sunburst_chart:{viz_name:"Sunburst Chart",level:{labels:"Levels",hint:"Configure ring style on each level",inside_radius:"Inside Radius",outside_radius:"Outside Radius",add:"Add a level",delete:"Delete this level"},label:{show_label_tolerance:"Hide label when its percentage is less than...",rotate:{label:"Rotate",radial:"Radial",tangential:"Tangential",none:"None"}},group_key:"Group Key"}}},{lang:"zh",resources:{sunburst_chart:{viz_name:"旭日图",level:{labels:"层级",hint:"为每层配置圆环样式",inside_radius:"内径",outside_radius:"外径",add:"增加一层",delete:"删除这一层"},label:{show_label_tolerance:"当百分比低于此值时,隐藏文案",rotate:{label:"旋转",radial:"径向旋转",tangential:"切向旋转",none:"不旋转"}},group_key:"分组字段"}}}];function Yw(e){const{label_field:t,value_field:r,...a}=e;return{...a,label_key:t,value_key:r}}function Kw(e){const{group_key:t="",...r}=e;return{...r,group_key:t}}function Xw(e){const{levels:t=[],...r}=e;return{...r,levels:t}}function Zw(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{label_key:l,value_key:o,group_key:i,...c}=e;return{...c,label_key:a(l),value_key:a(o),group_key:a(i)}}catch(r){throw console.error("[Migration failed]",r),r}}function Jw(e){const{unit:t}=e;return{...e,unit:t??U()}}class Hw extends ee{constructor(){super(...arguments);P(this,"VERSION",6)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>({...r,version:2,config:Yw(r.config)})),this.version(3,r=>({...r,version:3,config:Kw(r.config)})),this.version(4,r=>({...r,version:4,config:Xw(r.config)})),this.version(5,(r,a)=>({...r,version:5,config:Zw(r.config,a)})),this.version(6,r=>({...r,version:6,config:Jw(r.config)}))}}const Rw={displayName:"viz.sunburst_chart.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new Hw,name:"sunburst",viewRender:Gw,configRender:Ww,createConfig(){return{version:6,config:y.cloneDeep(Pr)}},translation:Uw};var Ue=(e=>(e.string="string",e.number="number",e.eloc="eloc",e.percentage="percentage",e.url="url",e.custom="custom",e))(Ue||{});function to(){return{page_size:0}}const no=["function text({ value, row_data }, utils) {"," return value","}"].join(`
379
- `),ro={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",query_id:"",striped:!0,use_raw_columns:!0,ignored_column_keys:"",verticalSpacing:"14px",pagination:to()};function em(e){const{columns:t,...r}=e;return{...e,columns:t.map(a=>({...a,align:a.align??"left"}))}}function tm(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=c=>c&&`${r}.${c}`,{id_field:l,columns:o,...i}=e;return{...i,id_field:a(l),columns:o.map(c=>({...c,value_field:a(c.value_field)}))}}catch(r){throw console.error("[Migration failed]",r),r}}function nm(e){const{columns:t,...r}=e;return{...r,columns:t.map(a=>({...a,align:a.align??"left",cellBackgroundColor:a.cellBackgroundColor??"",width:a.width??""}))}}function rm(e){const{id_field:t,...r}=e,{queryID:a}=A(t);return{...r,query_id:a??""}}function am(e){const{ignored_column_keys:t,...r}=e;return{...r,ignored_column_keys:t??""}}function sm(e){const{pagination:t=to(),...r}=e;return{...r,pagination:t}}class lm extends ee{constructor(){super(...arguments);P(this,"VERSION",8)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>{const{columns:a,...l}=r.config;return{...r,version:2,config:{...l,columns:a.map(({id:o,...i})=>({id:o??te.randomId(),...i}))}}}),this.version(3,r=>({...r,version:3,config:em(r.config)})),this.version(4,(r,a)=>({...r,version:4,config:tm(r.config,a)})),this.version(5,r=>({...r,version:5,config:nm(r.config)})),this.version(6,r=>({...r,version:6,config:rm(r.config)})),this.version(7,r=>({...r,version:7,config:am(r.config)})),this.version(8,r=>({...r,version:8,config:sm(r.config)}))}}const ao={left:"flex-start",center:"center",right:"flex-end"},om=({header:e,cx:t})=>{const r=y.get(e.column.columnDef.meta,"align","left");return n.jsxs(s.Text,{className:t("table-head-cell",{"table-head-cell--sortable":e.column.getCanSort()}),onClick:e.column.getToggleSortingHandler(),ta:r,sx:{justifyContent:ao[r]},size:"sm",children:[e.isPlaceholder?null:ge.flexRender(e.column.columnDef.header,e.getContext()),n.jsx(im,{direction:e.column.getIsSorted()})]})},im=({direction:e})=>{switch(e){case"asc":return n.jsx(S.IconArrowUp,{size:16});case"desc":return n.jsx(S.IconArrowDown,{size:"1em"});default:return null}},cm=dt.createStyles(e=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:e.colors.gray[0]}}},thead:{background:e.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),dm={tableLayout:"fixed",width:"fit-content",minWidth:"100%","thead, tbody":{tr:{width:"fit-content",th:{position:"relative"},"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1",transform:"translateY(-50%)",backgroundColor:"rgb(248, 249, 250)"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}},so=dt.createStyles((e,t)=>({content:{display:"flex",alignItems:"center",justifyContent:ao[t.align],".table-cell-text":{whiteSpace:"nowrap",cursor:t.clickable?"pointer":"default",textDecoration:t.clickable?"underline":"none"}}}));function um(e){return e?qe(e).oklch()[0]>.7?"black":"white":"inherit"}function lo(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:um(t)}}function $t(e){const t=e.tableCellContext.isClickable(),r=so({clickable:t,align:e.align});return n.jsx("div",{className:r.classes.content,style:{...lo(e)},children:n.jsx(s.Text,{size:"sm",className:"table-cell-text",onClick:e.tableCellContext.getClickHandler(),children:n.jsx("span",{title:e.children,children:e.children})})})}function pm(e){return n.jsx($t,{...e,children:e.value})}function hm(e){const t=so({clickable:!0,align:e.align}),r=e.value;return n.jsx("div",{className:t.classes.content,style:{...lo(e)},children:n.jsx(s.Anchor,{className:"table-cell-text",href:r,target:"_blank",color:"black",children:r})})}function gm(e){const t=Y(e.value,{output:"number",average:!0,mantissa:2,trimMantissa:!0,absolute:!1});return n.jsx($t,{...e,children:t})}function fm(e){const t=Y(e.value,{output:"number",mantissa:0,thousandSeparated:!0,absolute:!1});return n.jsx($t,{...e,children:t})}function bm(e){const t=Y(e.value,{output:"percent",mantissa:3,trimMantissa:!0,absolute:!1});return n.jsx($t,{...e,children:t})}function ym(e){const{value:t,row_data:r,func_content:a}=e;if(!a)return n.jsx($t,{...e,children:t});const l=new Function(`return ${a}`)()({value:t,row_data:r},je);return n.jsx($t,{...e,children:l})}function vm(e){switch(e.type){case Ue.string:return n.jsx(pm,{...e});case Ue.eloc:return n.jsx(gm,{...e});case Ue.number:return n.jsx(fm,{...e});case Ue.percentage:return n.jsx(bm,{...e});case Ue.url:return n.jsx(hm,{...e});case Ue.custom:return n.jsx(ym,{...e})}}function _m({tableContainerRef:e,rows:t}){var c,d;const r=id.useVirtualizer({getScrollElement:()=>e.current,count:t.length,estimateSize:h.useCallback(()=>28,[]),overscan:20}),a=r.getVirtualItems(),l=r.getTotalSize(),o=a.length>0&&((c=a==null?void 0:a[0])==null?void 0:c.start)||0,i=a.length>0?l-(((d=a==null?void 0:a[a.length-1])==null?void 0:d.end)||0):0;return n.jsxs(s.Table.Tbody,{children:[o>0&&n.jsx(s.Table.Tr,{children:n.jsx(s.Table.Td,{style:{height:`${o}px`}})}),a.map(u=>{const p=t[u.index];return n.jsx(s.Table.Tr,{children:p.getVisibleCells().map(f=>n.jsx(s.Table.Td,{children:ge.flexRender(f.column.columnDef.cell,f.getContext())},f.id))},p.id)}),i>0&&n.jsx(s.Table.Tr,{children:n.jsx(s.Table.Td,{style:{height:`${i}px`}})})]})}const Vr={id:"builtin:table:click-cell-content",displayName:"viz.table.click_cell.click_cell_content",nameRender:Cm,configRender:wm,payload:[{name:"row_index",description:"Index of the row that the cell belongs to",valueType:"number"},{name:"col_index",description:"Index of the column that the cell belongs to",valueType:"number"},{name:"row_data",description:"Data of the row that the cell belongs to",valueType:"object"}]},xm={column:""};function oo(e,t){const{value:r}=B(e.instanceData,"config"),a={columnsFromConfig:[],columnsFromData:[]};if(r&&(a.columnsFromConfig=r.columns.map((l,o)=>({label:l.label,value:o.toString()}))),!t)return a;if(r!=null&&r.query_id){const l=t[r.query_id];(l==null?void 0:l.length)>0&&(a.columnsFromData=Object.keys(l[0]).map(o=>({label:o,value:o})))}return a}function io(e){const{value:t}=B(e.instanceData,"config");return(t==null?void 0:t.use_raw_columns)??!1}function wm(e){const{t}=x.useTranslation(),{columnsFromConfig:r,columnsFromData:a}=oo(e.instance,e.sampleData),l=io(e.instance),o=r.length>0?r:a,{value:i,set:c}=B(e.trigger.triggerData,"config"),{column:d}=y.defaults({},i,xm),u=p=>{p&&(isNaN(+p)?c({column:p}):c({column:+p}))};return l?n.jsxs(s.Stack,{children:[n.jsx(s.Alert,{icon:n.jsx(S.IconAlertCircle,{size:"1rem"}),color:"gray",children:n.jsxs(x.Trans,{i18nKey:"viz.table.click_cell.why_column_data_field",children:["Option ",n.jsx(s.Mark,{children:"Use original data columns"})," is enabled, you have to address trigger column by its data field"]})}),n.jsx(s.TextInput,{label:t("viz.table.click_cell.column_data_field"),value:d.toString(),onChange:p=>u(p.currentTarget.value)})]}):n.jsx(s.Select,{clearable:!1,data:o,label:t("viz.table.click_cell.choose_a_column"),value:d.toString(),onChange:u,comboboxProps:{zIndex:340},maxDropdownHeight:500})}function mm(e,t,r){const{t:a}=x.useTranslation();if(!e)return a("viz.table.click_cell.click_cell_content");if(y.isNumber(e.column)){if(r)return a("viz.table.click_cell.click_cell_of_x_th",{x:e.column+1});const l=t[e.column];return l?a("viz.table.click_cell.click_cell_of_x",{x:l.label}):a("viz.table.click_cell.click_cell_invalid_config")}return a("viz.table.click_cell.click_cell_of_x",{x:e.column})}function Cm(e){const{columnsFromConfig:t}=oo(e.instance),{value:r}=B(e.trigger.triggerData,"config"),a=io(e.instance);return n.jsx(s.Text,{size:"sm",children:mm(r,t,a)})}function co(e,t,r){return Math.min(Math.max(e,t),r)}class Sm{constructor(t){this.steps=t;const r=[],a=new Set;for(const l of t)a.has(l.to)||(r.push(l),a.add(l.to));if(r.sort((l,o)=>l.from-o.from),r.length<2)throw new Error("MultiStepValueMapper requires at least 2 steps");this.steps=r}getLinearFunction(t,r){const a=(r.to-t.to)/(r.from-t.from),l=t.to-a*t.from;return o=>a*o+l}getStepFunctionForValue(t){let r=y.findLastIndex(this.steps,a=>a.from<=t);return r=co(r,0,this.steps.length-2),this.getLinearFunction(this.steps[r],this.steps[r+1])}mapValue(t){return co(this.getStepFunctionForValue(t)(t),0,100)}}class Tm{constructor(t,r,a,l,o){this.getColIndex=t,this.cell=r,this.triggers=a,this.interactionManager=l,this.colorManager=o}getClickHandler(){const t=this.getRelatedTrigger();if(t.length!==0)return()=>{const r={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const a of t)this.interactionManager.runInteraction(a.id,r)}}getRelatedTrigger(){return this.triggers.filter(r=>r.schemaRef===Vr.id).filter(r=>{const a=this.getColIndex(this.cell),l=y.get(this.cell.column.columnDef.meta,"value_field"),o=y.get(r.config,"column");return o==a||o==l})}isClickable(){return this.getRelatedTrigger().length>0}get columnConf(){return this.cell.column.columnDef.meta}get bgColor(){const t=this.columnConf.cellBackgroundColor;if(!t||t==="none")return;if(y.isString(t))return t;const r=+this.cell.getValue();if(isFinite(r)){const a=this.colorManager.decodeInterpolation(t.interpolation),o=new Sm(t.steps).mapValue(r);return a==null?void 0:a.getColor(o)}}}const km=e=>{const t=Me(e),r=Ie(t.triggerManager,Vr.id),{colorManager:a}=h.useContext(rt);return h.useCallback(l=>new Tm(e.getColIndex,l,r,t,a),[r,t,e.getColIndex])},zm=({classes:e,pagination:t,setPagination:r,pageCount:a,totalRows:l})=>{const{t:o}=x.useTranslation(),{pageSize:i,pageIndex:c}=t;if(l===0)return null;if(i===0)return n.jsx(s.Box,{className:e.info_bar,sx:{height:22},children:n.jsx(s.Text,{ta:"right",pr:6,size:"14px",c:"dimmed",fw:"normal",children:o("common.pagination.total_rows",{total:l})})});const d=()=>{r({...t,pageIndex:c-1})},u=()=>{r({...t,pageIndex:c+1})};return n.jsxs(s.Group,{wrap:"nowrap",justify:"flex-end",gap:4,className:e.info_bar,sx:{height:22},children:[n.jsx(s.Text,{ta:"right",pr:6,size:"14px",c:"dimmed",fw:"normal",children:o("common.pagination.showing_rows",{start_row:c*i+1,end_row:(c+1)*i,total:l})}),n.jsx(s.ActionIcon,{variant:"default","aria-label":"to previous page",onClick:d,size:"xs",disabled:c===0,children:n.jsx(S.IconChevronLeft,{})}),n.jsx(s.ActionIcon,{variant:"default","aria-label":"to next page",onClick:u,size:"xs",disabled:c===a-1,children:n.jsx(S.IconChevronRight,{})})]})};function uo({queryData:e,width:t,height:r,conf:a,context:l,instance:o}){x.useTranslation();const{use_raw_columns:i,ignored_column_keys:c,columns:d,...u}=a,{classes:p,cx:f}=cm(),v=h.useMemo(()=>{if(!i)return d;if(!Array.isArray(e)||e.length===0)return[];let Pe=Object.keys(e[0]);const Ce=new Set(c==null?void 0:c.split(/\r?\n|\r|\n/g).filter(pe=>!!pe));return Ce.size>0&&(Pe=Pe.filter(pe=>!Ce.has(pe))),Pe.map(pe=>({id:pe,label:pe,value_field:pe,value_type:Ue.string,align:"left",width:"",cellBackgroundColor:""}))},[i,c,d,e]),_=km({getColIndex:h.useCallback(Pe=>v.indexOf(Pe.column.columnDef.meta),[v]),vizManager:l.vizManager,instance:o}),w=h.useMemo(()=>{const Pe=ge.createColumnHelper();return v.map(pe=>{const $D=yu(pe.value_field);return Pe.accessor($D.columnKey,{cell:Ka=>n.jsx(vm,{tableCellContext:_(Ka.cell),value:Ka.getValue(),type:pe.value_type,row_data:Ka.row.original,...pe}),header:pe.label,enableSorting:!0,meta:pe,size:typeof pe.width=="number"?pe.width:void 0,minSize:typeof pe.width=="number"?pe.width:void 0})})},[v,_]),[m,k]=h.useState([]),[z,D]=h.useState({pageIndex:0,pageSize:a.pagination.page_size}),I=h.useMemo(()=>{const{pageIndex:Pe,pageSize:Ce}=z;return Ce===0?e:e.slice(Pe*Ce,(Pe+1)*Ce)},[e,z]),L=Math.ceil(e.length/z.pageSize),E=ge.useReactTable({data:I,state:{sorting:m},onSortingChange:k,columns:w,columnResizeMode:"onChange",getCoreRowModel:ge.getCoreRowModel(),getSortedRowModel:ge.getSortedRowModel()}),{rows:K}=E.getRowModel(),N=h.useRef(null),oe=e.length,me=oe>0,lt=me?r-22:r,yt=me?22:0;return n.jsxs("div",{ref:N,style:{height:r,width:t,padding:"0 5px"},"data-enable-scrollbar":!0,className:f(p.root,{"table-highlight-on-hover":a.highlightOnHover}),children:[n.jsx(zm,{classes:p,pagination:z,totalRows:oe,setPagination:D,pageCount:L}),n.jsxs(s.Table,{sx:{...dm,maxHeight:lt},...u,striped:a.striped,children:[n.jsx(s.Table.Thead,{className:p.thead,style:{top:yt},children:E.getHeaderGroups().map(Pe=>n.jsx(s.Table.Tr,{children:Pe.headers.map(Ce=>n.jsxs(s.Table.Th,{style:{width:Ce.getSize()},children:[n.jsx(om,{header:Ce,cx:f}),n.jsx(s.ActionIcon,{variant:"subtle",onMouseDown:Ce.getResizeHandler(),onTouchStart:Ce.getResizeHandler(),className:`resizer ${Ce.column.getIsResizing()?"isResizing":""}`,children:n.jsx(S.IconArrowBarToRight,{})})]},Ce.id))},Pe.id))}),n.jsx(_m,{tableContainerRef:N,rows:K})]})]})}function po(){const{t:e}=x.useTranslation();return n.jsx(s.Text,{size:"sm",c:"gray",ta:"center",children:e("data.empty_data")})}function Dm({data:e,width:t,height:r,conf:a,context:l,instance:o}){const{t:i}=x.useTranslation(),{panel:c}=be(),d=c.firstQueryData??[];if(c.queryIDs.length===0)return n.jsx(s.Text,{size:"sm",c:"gray",ta:"center",children:i("panel.settings.need_to_choose_queries")});const{query_id:u}=a;if(!u)return d.length===0?n.jsx(po,{}):n.jsx(uo,{queryData:d,width:t,height:r,conf:{...a,use_raw_columns:!0,columns:[]},context:l,instance:o});const p=e[u];return!Array.isArray(p)||p.length===0?n.jsx(po,{}):n.jsx(uo,{queryData:p,width:t,height:r,conf:a,context:l,instance:o})}function Im({context:e,instance:t}){const r=e.data,{height:a,width:l}=e.viewport,{value:o}=B(e.instanceData,"config");return o?n.jsx(Dm,{data:r,width:l,height:a,conf:o,context:e,instance:t}):null}const Mm=[{lang:"en",resources:{table:{viz_name:"Table",column:{labels:"Columns",add:"Add a column",delete:"Delete this column",query_id:"Query",query_id_hint:"Load table data from this query",use_original_data_columns:"Use original data columns",ignore_columns_by_these_key:"Ignore columns by these keys",separate_by_line_break:"Separate by line break",width:"Width",min_width:"Min Width",max_width:"Max Width",cell_background:"Cell background",custom_cell_content:"Custom cell content",value_type:{label:"Value Type",string:"String",number:"Number",percentage:"Percentage",eloc:"ELOC",url:"URL",custom:"Custom"}},style:{horizontal_spacing:"Horizontal Spacing",vertical_spacing:"Vertical Spacing",striped:"Striped",highlight_on_hover:"Hightlight on hover"},click_cell:{label:"Click cell content",click_cell_content:"Click cell content (click to config)",click_cell_of_x:"Click cell of {{ x }}",click_cell_of_x_th:"Click cell by column order {{ x }}",click_cell_invalid_config:"Invalid config",choose_a_column:"Choose a column",why_column_data_field:"Option <1>Use original data columns</1> is enabled, you have to address trigger column by its data field",column_data_field:"Column data field"}}}},{lang:"zh",resources:{table:{viz_name:"表格",column:{labels:"列设置",add:"加一列",delete:"删除这个列",query_id:"表格数据来源",query_id_hint:"通过所选的查询获取表格数据",use_original_data_columns:"使用数据本身的列",ignore_columns_by_these_key:"按下述列名忽略列",separate_by_line_break:"以换行符分隔",width:"宽度",min_width:"最小宽度",max_width:"最大宽度",cell_background:"单元格背景",custom_cell_content:"自定义单元格内容",value_type:{label:"数据类型",string:"文本",number:"数字",percentage:"百分比",eloc:"ELOC",url:"URL",custom:"自定义"}},style:{horizontal_spacing:"水平间距",vertical_spacing:"垂直间距",striped:"隔行变色",highlight_on_hover:"鼠标悬停时高亮整行"},click_cell:{label:"点击单元格",click_cell_content:"点击单元格内容",click_cell_of_x:"点击 {{ x }} 列单元格",click_cell_of_x_th:"点击第 {{ x }} 列单元格",click_cell_invalid_config:"配置信息已失效",choose_a_column:"选择列",why_column_data_field:"选项 <1>使用数据本身的列</1> 已开启,只能通过填写数据字段来指定触发动作的列",column_data_field:"列的数据字段"}}}}],Am=T.observer(h.forwardRef(({label:e,required:t,description:r,value:a,onChange:l,clearable:o=!1,sx:i,...c},d)=>{const{panel:u}=re(),p=h.useMemo(()=>u.queryOptions(a,o),[a,o]);return p.length===0?n.jsx(s.Box,{children:n.jsx(s.TextInput,{label:e,required:t,defaultValue:a,readOnly:!0,disabled:!0})}):n.jsx(s.Select,{ref:d,label:e,description:r,data:p,value:a,onChange:Z(l),required:t,sx:i,maxDropdownHeight:500,...c})})),Pm=[{from:0,to:0},{from:100,to:100}];function ho(e){return e?y.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function Vm(e,t){var r;return ho(t)==="static"?t:(r=e.getStaticColors()[0])==null?void 0:r.value}function $m(e,t){return y.isObject(t)?t:{steps:Pm,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const Em=h.forwardRef((e,t)=>{const{t:r}=x.useTranslation(),{colorManager:a}=h.useContext(rt),[l,o]=h.useState(ho(e.value)),[i,c]=h.useState(Vm(a,e.value)),d=O.useLatest(i),[u,p]=h.useState($m(a,e.value)),f=O.useLatest(u),v=m=>{var k,z,D;o(m||"none"),m==="static"?(k=e.onChange)==null||k.call(e,d.current):m==="none"||!m?(z=e.onChange)==null||z.call(e,"none"):(D=e.onChange)==null||D.call(e,f.current)},_=m=>{var k;c(m),(k=e.onChange)==null||k.call(e,m)},w=m=>{var k;p(m),(k=e.onChange)==null||k.call(e,m)};return n.jsxs(s.Stack,{align:"stretch",children:[n.jsx(hg,{label:r("viz.table.column.cell_background"),value:l||"none",onChange:v}),l==="static"&&n.jsx(ye,{label:r("chart.color.label"),value:i,onChange:_}),l==="interpolation"&&n.jsx(pg,{colorManager:a,value:u,onChange:w})]})}),Bm=h.forwardRef(({value:e,onChange:t,sx:r},a)=>{const{t:l,i18n:o}=x.useTranslation(),i=h.useMemo(()=>Object.values(Ue).map(c=>({label:l(`viz.table.column.value_type.${c}`),value:c})),[o.language]);return n.jsx(s.Select,{ref:a,label:l("viz.table.column.value_type.label"),data:i,value:e,onChange:Z(t),maxDropdownHeight:500,sx:r})}),Lm=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a}=x.useTranslation(),[l,{setTrue:o,setFalse:i}]=O.useBoolean(),[c,d]=h.useState(e),u=()=>{i(),t(c)},p=()=>{i(),d(e)},f=()=>{d(no)};return h.useEffect(()=>{d(e)},[e]),n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{color:"grape",variant:"filled",leftSection:n.jsx(S.IconMathFunction,{size:16}),mt:24,onClick:o,sx:{flexGrow:0},children:a("viz.table.column.custom_cell_content")}),n.jsx(s.Modal,{size:800,title:a("viz.table.column.custom_cell_content"),opened:l,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:l&&n.jsxs(s.Stack,{children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(Rs,{})}),n.jsx(s.Box,{sx:{position:"relative"},children:n.jsx(Te,{height:"500px",defaultLanguage:"javascript",value:c,onChange:v=>d(v??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:f,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:a("common.actions.reset_to_default")}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:p,variant:"subtle",children:a("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:u,children:a("common.actions.save")})]})]})]})})]})}),$r=()=>n.jsx(s.Text,{c:"dimmed",size:"12px",children:"px"}),qm=({control:e,index:t,watch:r})=>{const{t:a}=x.useTranslation(),l=r(`columns.${t}.value_type`),o=r("query_id");return n.jsxs(s.Stack,{my:0,sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`columns.${t}.label`,control:e,render:({field:i})=>n.jsx(s.TextInput,{label:a("chart.label.label"),required:!0,id:`col-label-${t}`,sx:{flex:1},...i})}),n.jsx(b.Controller,{name:`columns.${t}.value_field`,control:e,render:({field:i})=>n.jsx(q,{label:a("common.data_field"),required:!0,queryID:o,...i})})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`columns.${t}.value_type`,control:e,render:({field:i})=>n.jsx(Bm,{sx:{flex:1},...i})}),l===Ue.custom&&n.jsx(b.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:i})=>n.jsx(Lm,{value:i.value??no,onChange:c=>i.onChange(c??"")})})]}),n.jsx(s.Divider,{mb:-10,variant:"dashed",label:a("style.label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.NumberInput,{hideControls:!0,label:a("viz.table.column.min_width"),rightSection:n.jsx($r,{}),disabled:!0}),n.jsx(b.Controller,{name:`columns.${t}.width`,control:e,render:({field:i})=>n.jsx(s.NumberInput,{hideControls:!0,label:a("viz.table.column.width"),rightSection:n.jsx($r,{}),...i})}),n.jsx(s.NumberInput,{hideControls:!0,label:a("viz.table.column.max_width"),rightSection:n.jsx($r,{}),disabled:!0})]}),n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:`columns.${t}.align`,control:e,render:({field:i})=>n.jsx(yr,{...i})})}),n.jsx(b.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:i})=>n.jsx(Em,{...i})})]})},Om=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>{const i=te.randomId();return{id:i,label:i,align:"center",value_field:"",value_type:Ue.string,width:""}},l=(i,c)=>{const d=i.label.trim();return d||c+1};t(["columns","ignored_column_keys"]);const o=t("use_raw_columns");return n.jsxs(n.Fragment,{children:[n.jsx(b.Controller,{name:"use_raw_columns",control:e,render:({field:i})=>n.jsx(s.Switch,{mt:20,mb:20,label:r("viz.table.column.use_original_data_columns"),checked:i.value,onChange:c=>i.onChange(c.currentTarget.checked)})}),o&&n.jsx(b.Controller,{name:"ignored_column_keys",control:e,render:({field:i})=>n.jsx(s.Textarea,{label:r("viz.table.column.ignore_columns_by_these_key"),placeholder:r("viz.table.column.separate_by_line_break"),autosize:!0,minRows:2,maxRows:10,...i})}),!o&&n.jsx(H,{control:e,watch:t,name:"columns",getItem:a,addButtonText:r("viz.table.column.add"),deleteButtonText:r("viz.table.column.delete"),renderTabName:l,children:({field:i,index:c})=>n.jsx(qm,{control:e,watch:t,index:c})})]})};function Nm({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),n.jsxs(s.Stack,{gap:"xs",children:[n.jsxs(s.Group,{justify:"space-between",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[n.jsx(b.Controller,{name:"horizontalSpacing",control:e,render:({field:a})=>n.jsx(xr,{disabled:!0,label:r("viz.table.style.horizontal_spacing"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"verticalSpacing",control:e,render:({field:a})=>n.jsx(xr,{disabled:!0,label:r("viz.table.style.vertical_spacing"),sx:{flex:1},...a})})]}),n.jsx(s.Group,{justify:"space-between",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:n.jsx(b.Controller,{name:"fontSize",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("style.font_size.label"),placeholder:r("style.font_size.placeholder"),required:!0,sx:{flex:1},...a})})}),n.jsxs(s.Group,{justify:"space-between",grow:!0,children:[n.jsx(b.Controller,{name:"striped",control:e,render:({field:a})=>n.jsx(s.Switch,{label:r("viz.table.style.striped"),checked:a.value,onChange:l=>a.onChange(l.currentTarget.checked)})}),n.jsx(b.Controller,{name:"highlightOnHover",control:e,render:({field:a})=>n.jsx(s.Switch,{label:r("viz.table.style.highlight_on_hover"),checked:a.value,onChange:l=>a.onChange(l.currentTarget.checked)})})]})]})}function Gm({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["pagination"]),n.jsx(s.Stack,{children:n.jsx(b.Controller,{name:"pagination.page_size",control:e,render:({field:a})=>n.jsx(s.NumberInput,{label:r("common.pagination.page_size"),description:r("viz.heatmap.pagination.page_size_hint"),size:"xs",sx:{flex:1},...a,onChange:l=>{typeof l!="string"&&a.onChange(l)}})})})}function Fm({columns:e,...t}){return{...t,columns:e.map(({id:r,...a})=>({id:r??te.randomId(),...a}))}}function jm({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),l=h.useMemo(()=>y.defaultsDeep({},r,ro),[r]),o=h.useMemo(()=>Fm(l),[l]);h.useEffect(()=>{!y.isEqual(l,o)&&(console.log("config malformed, resetting to defaults",l,o),a(o))},[l,o]);const{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=b.useForm({defaultValues:o});return h.useEffect(()=>{p(o)},[o]),d(["query_id"]),n.jsxs("form",{onSubmit:c(a),children:[n.jsx(ae,{canSubmit:u.isDirty}),n.jsxs(s.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"Columns",children:t("viz.table.column.labels")}),n.jsx(s.Tabs.Tab,{value:"Style",children:t("style.label")}),n.jsx(s.Tabs.Tab,{value:"Pagination",children:t("common.pagination.label")})]}),n.jsxs(s.Tabs.Panel,{value:"Columns",children:[n.jsx(b.Controller,{name:"query_id",control:i,render:({field:f})=>n.jsx(Am,{label:t("viz.table.column.query_id"),description:t("viz.table.column.query_id_hint"),required:!0,...f})}),n.jsx(s.Divider,{mt:20,mb:10,variant:"dashed"}),n.jsx(Om,{control:i,watch:d})]}),n.jsx(s.Tabs.Panel,{value:"Style",children:n.jsx(Nm,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Pagination",children:n.jsx(Gm,{control:i,watch:d})})]})]})}const go=new lm,Er={createConfig(){return{version:go.VERSION,config:y.cloneDeep(ro)}},displayName:"viz.table.viz_name",displayGroup:"chart.groups.others",migrator:go,name:"table",viewRender:Im,configRender:jm,triggers:[Vr],translation:Mm},fo=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
380
- `),Br={func_content:fo,horizontal_align:"left",font_size:"14px",font_weight:"normal"},Qm=T.observer(({context:e})=>{const t=J(),{value:r=Br}=B(e.instanceData,"config"),{variables:a}=e,l=e.data,{func_content:o,horizontal_align:i,font_size:c,font_weight:d}=r,u=h.useMemo(()=>a.reduce((f,v)=>{const _=Re(v,l);return f[v.name]=$e(v,_),f},{}),[a,l]),p=h.useMemo(()=>new Function(`return ${o}`)()({data:l,variables:u,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}),[o,l,u,t.payloadForSQL]);return n.jsx(s.Text,{ta:i,fw:d,sx:{fontSize:c},children:p})}),_n=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function Wm({label:e,value:t,onChange:r},a){var i;const[l,o]=h.useState(((i=_n.find(c=>c.label===t))==null?void 0:i.value)??_n[0].value);return h.useEffect(()=>{const c=_n.find(d=>d.value===l);c&&r(c.label)},[l]),n.jsxs(s.Stack,{gap:0,mt:"sm",mb:"lg",children:[n.jsx(s.Text,{size:"sm",children:e}),n.jsx(s.Box,{px:"1.5em",children:n.jsx(s.Slider,{label:null,marks:_n,value:l,onChange:o,step:25,ref:a})})]})}const Um=h.forwardRef(Wm),Ym=({value:e,onChange:t})=>{const r=a=>{a&&t(a)};return n.jsx(s.Box,{sx:{position:"relative"},children:n.jsx(Te,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Km=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a}=x.useTranslation(),[l,{setTrue:o,setFalse:i}]=O.useBoolean(),[c,d]=h.useState(e),u=()=>{i(),t(c)},p=()=>{i(),d(e)},f=()=>{d(fo)};return h.useEffect(()=>{d(e)},[e]),n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{color:"grape",variant:"filled",leftSection:n.jsx(S.IconMathFunction,{size:16}),mt:24,onClick:o,sx:{flexGrow:0},children:a("viz.text.content.edit")}),n.jsx(s.Modal,{size:800,title:a("viz.text.content.label"),opened:l,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:l&&n.jsxs(s.Stack,{children:[n.jsx(Ym,{value:c,onChange:d}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:f,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:a("common.actions.reset_to_default")}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:p,variant:"subtle",children:a("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:u,children:a("common.actions.save_changes")})]})]})]})})]})});function Xm({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),l=h.useMemo(()=>y.defaultsDeep({},r,Br),[r]),o=h.useMemo(()=>{const{func_content:f,horizontal_align:v,font_size:_,font_weight:w}=l;return{func_content:f,horizontal_align:v,font_size:_,font_weight:w}},[l]);h.useEffect(()=>{!y.isEqual(l,o)&&(console.log("config malformed, resetting to defaults",l,o),a(o))},[l,o]);const{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=b.useForm({defaultValues:o});return h.useEffect(()=>{p(o)},[o]),d(["func_content","horizontal_align","font_size","font_weight"]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:c(a),children:[n.jsx(ae,{canSubmit:u.isDirty}),n.jsxs(s.Stack,{gap:10,children:[n.jsx(b.Controller,{name:"func_content",control:i,render:({field:f})=>n.jsx(Km,{...f})}),n.jsx(s.Divider,{mt:10,mb:-10,variant:"dashed",label:t("chart.style.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"horizontal_align",control:i,render:({field:f})=>n.jsx(yr,{...f})}),n.jsx(b.Controller,{name:"font_size",control:i,render:({field:f})=>n.jsx(s.TextInput,{label:t("style.font_size.label"),placeholder:t("style.font_size.placeholder"),sx:{flex:1},...f})}),n.jsx(s.Group,{justify:"space-between",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:n.jsx(b.Controller,{name:"font_weight",control:i,render:({field:f})=>n.jsx(Um,{label:t("style.font_weight.label"),...f})})})]})]})})}const Zm=[{lang:"en",resources:{text:{viz_name:"Text",content:{label:"Text content",edit:"Edit Content"}}}},{lang:"zh",resources:{text:{viz_name:"文本",content:{label:"文本内容",edit:"编辑文本内容"}}}}];class Jm extends ee{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const Hm={displayName:"viz.text.viz_name",displayGroup:"chart.groups.others",migrator:new Jm,name:"text",viewRender:Qm,configRender:Xm,createConfig(){return{version:1,config:y.cloneDeep(Br)}},translation:Zm},Rm=()=>n.jsxs("svg",{width:"64",height:"64",viewBox:"0 0 64 64",fill:"none",children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M22.49 27.79H14.47C13.55 27.79 12.81 28.53 12.81 29.45C12.81 30.37 13.55 31.11 14.47 31.11H22.49C23.41 31.11 24.15 30.37 24.15 29.45C24.15 28.54 23.41 27.79 22.49 27.79ZM34.32 31.28C35.22 31.32 35.7 31.82 35.74 32.76C35.78 33.54 35.37 34.3 34.51 35.04C33.52 35.9 33.03 36.95 33.03 38.19V38.81H34.82V38.25C34.78 37.59 35.07 37.02 35.68 36.52C37.12 35.41 37.82 34.15 37.78 32.75C37.66 30.53 36.5 29.35 34.32 29.23C32.3 29.23 31.05 30.46 30.55 32.93L32.53 33.55C32.82 32.04 33.42 31.28 34.32 31.28ZM35 39.93H32.84V42.21H35V39.93ZM14.83 36.42H18.54C19.46 36.42 20.2 37.17 20.2 38.08C20.2 39 19.46 39.74 18.54 39.74H10.52C9.6 39.74 8.86 39 8.86 38.08C8.86 37.61 9.06 37.19 9.37 36.89H5.66C4.74 36.89 4 36.15 4 35.23C4 34.31 4.74 33.57 5.66 33.57H13.68C14.6 33.57 15.34 34.31 15.34 35.23C15.34 35.7 15.14 36.12 14.83 36.42ZM50.94 36.85H58.74C59.66 36.85 60.4 37.59 60.41 38.51C60.41 39.43 59.67 40.17 58.75 40.17H54.26C54.56 40.47 54.74 40.88 54.74 41.34C54.74 42.26 54 43 53.08 43H50.94V36.85Z",fill:"#B8C0CC"}),n.jsx("path",{d:"M18.39 32.28H16.51V35.02H18.39V32.28Z",fill:"#9399A5"}),n.jsx("path",{d:"M46.87 15H20.69C18.38 15 16.5 16.88 16.5 19.19V26.22H18.38V23.45H49.18V47.68H18.38V41.07H16.5V49.55H51.05V19.19C51.06 16.88 49.18 15 46.87 15ZM39.46 20.73C38.81 20.73 38.29 20.2 38.29 19.56C38.29 18.92 38.82 18.39 39.46 18.39C40.11 18.39 40.63 18.92 40.63 19.56C40.63 20.2 40.11 20.73 39.46 20.73ZM43.22 20.73C42.57 20.73 42.05 20.2 42.05 19.56C42.05 18.92 42.58 18.39 43.22 18.39C43.87 18.39 44.39 18.92 44.39 19.56C44.39 20.2 43.87 20.73 43.22 20.73ZM46.97 20.73C46.32 20.73 45.8 20.2 45.8 19.56C45.8 18.92 46.33 18.39 46.97 18.39C47.62 18.39 48.14 18.92 48.14 19.56C48.14 20.2 47.62 20.73 46.97 20.73Z",fill:"#9399A5"})]});function bo(e,t){const r=y.get(e,t,"");if(r)throw new Error(r)}async function e0(e,t,r,a={}){const l={"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json",...a.headers},o={baseURL:e,method:"POST",url:t,params:a.params,headers:l};return o.data=a.string?JSON.stringify(r):r,ke(o).then(i=>i.data).catch(i=>Promise.reject(i))}const t0=({conf:e,panelData:t})=>async()=>{const{expertSystemURL:r,path:a,goal:l,question:o}=e;if(!a||!l||!o)return;const i=vu(t);if(!i)return;const c={dashboard:l,panel:o,data:i};try{const d=r.startsWith("http")?r:window.location.origin;return await e0(d,`/expert/v3/devtable/${a}`,c,{})}catch(d){throw bo(d,"response.data.detail"),bo(d,"response.data.error"),console.error(d),d}},Lr={expertSystemURL:"",path:"",goal:"",question:""},qr={height:"100%",overflowY:"auto",...Jn},yo=({message:e})=>n.jsx(s.Box,{sx:qr,children:n.jsx("div",{dangerouslySetInnerHTML:{__html:e},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),n0=({error:e,width:t,height:r})=>{const a=e.message;if(a.startsWith("<"))return n.jsx(yo,{message:a});const o=r-25-20-30;return n.jsx(s.Center,{sx:{width:"100%",height:o},children:n.jsxs(s.Stack,{align:"center",gap:20,children:[n.jsx(Rm,{}),n.jsx(yo,{message:a})]})})};function r0({context:e}){const{value:t}=B(e.instanceData,"config"),r=h.useMemo(()=>y.defaultsDeep({},t,Lr),[t]),{width:a,height:l}=e.viewport,o=e.data,{data:i,error:c,loading:d}=O.useRequest(t0({conf:r,panelData:o}),{refreshDeps:[o,r]});return!a||!l||!r?null:d?n.jsx(s.Box,{sx:{position:"relative",height:l},children:n.jsx(s.LoadingOverlay,{visible:!0})}):c?n.jsx(s.Box,{sx:qr,"data-enable-scrollbar":!0,children:n.jsx(n0,{error:c,width:a,height:l})}):!i||!Array.isArray(i.replies)||i.replies.length===0?null:n.jsx(s.Box,{sx:qr,"data-enable-scrollbar":!0,children:i.replies.map((u,p)=>n.jsx("div",{dangerouslySetInnerHTML:{__html:u.interpretation.html}},p))})}function a0({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaultsDeep({},t,Lr),[t]),{control:l,handleSubmit:o,watch:i,formState:c,reset:d}=b.useForm({defaultValues:a});return h.useEffect(()=>{d(a)},[a]),i(["expertSystemURL","goal","path","question"]),n.jsx("form",{onSubmit:o(r),children:n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:"expertSystemURL",control:l,render:({field:u})=>n.jsx(s.TextInput,{label:"Expert System URL",...u})}),n.jsx(b.Controller,{name:"path",control:l,render:({field:u})=>n.jsx(s.TextInput,{label:"Path",required:!0,...u})})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:"goal",control:l,render:({field:u})=>n.jsx(s.TextInput,{label:"Goal",required:!0,...u})}),n.jsx(b.Controller,{name:"question",control:l,render:({field:u})=>n.jsx(s.TextInput,{label:"Question",required:!0,...u})})]}),n.jsx(s.Divider,{variant:"dashed",mt:16,mb:8}),n.jsx(s.Button,{type:"submit",variant:"filled",color:"blue",leftSection:n.jsx(S.IconDeviceFloppy,{size:20}),disabled:!c.isDirty,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}const s0=[{lang:"en",resources:{merico_gqm:{viz_name:"Merico GQM"}}},{lang:"zh",resources:{merico_gqm:{viz_name:"思码逸GQM组件"}}}];class l0 extends ee{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const o0={displayName:"viz.merico_gqm.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new l0,name:"mericoGQM",viewRender:r0,configRender:a0,createConfig(){return{version:1,config:y.cloneDeep(Lr)}},translation:s0};function i0(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{calendar:l,heat_block:o,tooltip:i,...c}=e;return{...c,calendar:{...l,data_key:a(l.data_key)},heat_block:{...o,data_key:a(o.data_key)},tooltip:{...i,metrics:i.metrics.map(d=>({...d,data_key:a(d.data_key)}))}}}catch(r){throw console.error("[Migration failed]",r),r}}function c0(e){const{heat_block:t}=e;let{min:r,max:a}=t;return typeof r!="number"&&(r=0),typeof a!="number"&&(a=100),{...e,heat_block:{...t,min:{type:"static",value:r},max:{type:"static",value:a}}}}function d0(e){const{visualMap:t=et(),heat_block:{min:r,max:a,...l},...o}=e;return{...o,heat_block:l,visualMap:{...et(),min:r,max:a}}}function u0(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??U()}))}}}function p0(e){const{heat_block:t}=e;return{...e,heat_block:{...t,unit:t.unit??U()}}}const h0=[{lang:"en",resources:{calendar_heatmap:{viz_name:"Heatmap(Calendar)",calendar:{label:"Calendar",locale:"Langauge"},click_heatmap:{heatblock:{label:"Click heat block"}}}}},{lang:"zh",resources:{calendar_heatmap:{viz_name:"日历热力图",calendar:{label:"日历",locale:"语言"},click_heatmap:{heatblock:{label:"点击热力块"}}}}}];function g0(e){return n.jsx(n.Fragment,{})}function f0(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.calendar_heatmap.click_heatmap.heatblock.label")})}const vo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"viz.calendar_heatmap.click_heatmap.heatblock.label",nameRender:f0,configRender:g0,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]},Or={calendar:{data_key:"",locale:"EN"},heat_block:{name:"Value",data_key:"",unit:U(),value_formatter:le},tooltip:{metrics:[]},visualMap:et()};function b0(e,t,r){if(!e)return r[0];try{return[t,M(t).add(1,"year").subtract(1,"day").valueOf()]}catch(a){return console.error(a),r[0]}}function y0(e,t,r){const a=b0(e,t,r);return{top:50,left:25,right:5,cellSize:["auto",13],range:a,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function v0(e){return{heat_block:function(a){if(!e.heat_block.value_formatter)return a;try{return Y(a,e.heat_block.value_formatter)}catch(l){return console.error(l),a}}}}function _0(e,t){return{show:!e,selectedMode:"single",top:5,right:5,data:t.map(r=>({name:r,icon:"circle"}))}}function x0(e,t,r){return e?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:r}:Object.entries(t).map(([a,l])=>({type:"heatmap",name:a,coordinateSystem:"calendar",calendarIndex:0,data:l}))}const w0=e=>Y(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function m0({conf:e,valueFormatters:t,dataDict:r,params:a,metricUnitMap:l}){const{value:o}=a,[i,c]=o,u=[{label:e.heat_block.name,value:t.heat_block(c),unit:e.heat_block.unit.show_in_tooltip?e.heat_block.unit.text:""}],p=r[i];return p&&e.tooltip.metrics.forEach(f=>{const v=A(f.data_key),_=l[f.name]??"";u.push({label:f.name,value:w0(y.get(p,v.columnKey,"")),unit:_})}),u}function C0(e,t,r){const a=A(e.calendar.data_key),l=y.keyBy(t[a.queryID],a.columnKey),o=e.tooltip.metrics.reduce((i,{unit:c,name:d})=>(c.show_in_tooltip&&(i[d]=c.text),i),{});return X.getTooltip({formatter:function(i){const d=m0({conf:e,valueFormatters:r,dataDict:l,params:i,metricUnitMap:o}).map(f=>`
378
+ `}}function Gw(e){const t=e.unit.show_in_tooltip?e.unit.text:"";return X.getTooltip({trigger:"item",formatter:Nw(t)})}const Fw={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function jw(e,t,r){r.reduce((o,i)=>{const c=Je(i,t);return o[i.name]=$e(i,c),o},{});const l={series:{data:Lw(e,t),levels:Ow(e)},tooltip:Gw(e)};return y.defaultsDeep({},l,Fw)}function Qw({context:e,instance:t}){const{variables:r}=e,{value:a}=B(e.instanceData,"config"),l=h.useMemo(()=>y.defaults({},a,Ar),[a]),o=e.data,{width:i,height:c}=e.viewport,d=h.useRef(null),u=h.useCallback(()=>{var _;const v=(_=d.current)==null?void 0:_.getEchartsInstance();v&&de(t,v.getOption())},[t]),p=h.useMemo(()=>({finished:u}),[u]),f=h.useMemo(()=>jw(l,o,r),[l,o,r]);return!i||!c?null:n.jsx(_e,{width:i,height:c,children:n.jsx(he,{echarts:ie,option:f,ref:d,onEvents:p,style:Ot(i,c),notMerge:!0,theme:"merico-light"})})}function Ww({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["label_key","value_key","group_key"]),n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:"label_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.name_data_field"),required:!0,...a})}),n.jsx(b.Controller,{name:"value_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.value_data_field"),required:!0,...a})}),n.jsx(b.Controller,{name:"group_key",control:e,render:({field:a})=>n.jsx(q,{label:r("viz.sunburst_chart.group_key"),clearable:!0,...a})}),n.jsx(b.Controller,{name:"unit",control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})})]})}const Uw=({control:e,index:t})=>{const{t:r,i18n:a}=x.useTranslation(),l=h.useMemo(()=>[{label:r("viz.sunburst_chart.label.rotate.radial"),value:"radial"},{label:r("viz.sunburst_chart.label.rotate.tangential"),value:"tangential"},{label:r("viz.sunburst_chart.label.rotate.none"),value:"0"}],[a.language]);return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`levels.${t}.r0`,control:e,render:({field:o})=>n.jsx(s.TextInput,{label:r("viz.sunburst_chart.level.inside_radius"),placeholder:"0%",...o})}),n.jsx(b.Controller,{name:`levels.${t}.r`,control:e,render:({field:o})=>n.jsx(s.TextInput,{label:r("viz.sunburst_chart.level.outside_radius"),placeholder:"50%",...o})})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:r("chart.label.label_full"),labelPosition:"center"}),n.jsx(b.Controller,{name:`levels.${t}.label.show_label_tolerance`,control:e,render:({field:o})=>n.jsx(s.NumberInput,{label:r("viz.sunburst_chart.label.show_label_tolerance"),decimalScale:4,step:5e-4,min:0,max:1,...o})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`levels.${t}.label.rotate`,control:e,render:({field:o})=>n.jsx(s.Select,{label:r("viz.sunburst_chart.label.rotate.label"),data:l,...o})}),n.jsx(b.Controller,{name:`levels.${t}.label.align`,control:e,render:({field:o})=>n.jsx(ft,{...o})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`levels.${t}.label.position`,control:e,render:({field:o})=>n.jsx(At,{label:r("chart.label_position.label"),...o,onChange:i=>{i&&o.onChange(i)}})}),n.jsx(b.Controller,{name:`levels.${t}.label.padding`,control:e,render:({field:o})=>n.jsx(s.NumberInput,{label:r("chart.padding"),min:0,hideControls:!0,...o})})]})]})},Kw=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>({id:Date.now().toString(),r0:"",r:"",label:{show_label_tolerance:.001,rotate:"0",align:"center",position:"inside",padding:0}}),l=(o,i)=>i+1;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:r("viz.sunburst_chart.level.hint")})]}),n.jsx(s.Divider,{variant:"dashed",my:10}),n.jsx(H,{control:e,watch:t,name:"levels",getItem:a,addButtonText:r("viz.sunburst_chart.level.add"),deleteButtonText:r("viz.sunburst_chart.level.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(Uw,{control:e,index:i})})]})};function Yw({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),l=h.useMemo(()=>y.defaultsDeep({},r,Ar),[r]),o=h.useMemo(()=>y.clone(l),[l]),{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=b.useForm({defaultValues:o});h.useEffect(()=>{p(o)},[o]),d(["label_key","value_key","group_key","levels"]);const[f,v]=h.useState("Data");return n.jsx("form",{onSubmit:c(a),children:n.jsxs(s.Stack,{gap:"xs",children:[n.jsx(ae,{canSubmit:u.isDirty}),n.jsxs(s.Tabs,{value:f,onChange:v,orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"Data",children:t("data.label")}),n.jsx(s.Tabs.Tab,{value:"Levels",children:t("viz.sunburst_chart.level.labels")})]}),n.jsx(s.Tabs.Panel,{value:"Data",children:n.jsx(Ww,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Levels",children:n.jsx(Kw,{control:i,watch:d})})]})]})})}const Xw=[{lang:"en",resources:{sunburst_chart:{viz_name:"Sunburst Chart",level:{labels:"Levels",hint:"Configure ring style on each level",inside_radius:"Inside Radius",outside_radius:"Outside Radius",add:"Add a level",delete:"Delete this level"},label:{show_label_tolerance:"Hide label when its percentage is less than...",rotate:{label:"Rotate",radial:"Radial",tangential:"Tangential",none:"None"}},group_key:"Group Key"}}},{lang:"zh",resources:{sunburst_chart:{viz_name:"旭日图",level:{labels:"层级",hint:"为每层配置圆环样式",inside_radius:"内径",outside_radius:"外径",add:"增加一层",delete:"删除这一层"},label:{show_label_tolerance:"当百分比低于此值时,隐藏文案",rotate:{label:"旋转",radial:"径向旋转",tangential:"切向旋转",none:"不旋转"}},group_key:"分组字段"}}}];function Zw(e){const{label_field:t,value_field:r,...a}=e;return{...a,label_key:t,value_key:r}}function Jw(e){const{group_key:t="",...r}=e;return{...r,group_key:t}}function Hw(e){const{levels:t=[],...r}=e;return{...r,levels:t}}function Rw(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{label_key:l,value_key:o,group_key:i,...c}=e;return{...c,label_key:a(l),value_key:a(o),group_key:a(i)}}catch(r){throw console.error("[Migration failed]",r),r}}function em(e){const{unit:t}=e;return{...e,unit:t??U()}}class tm extends ee{constructor(){super(...arguments);V(this,"VERSION",6)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>({...r,version:2,config:Zw(r.config)})),this.version(3,r=>({...r,version:3,config:Jw(r.config)})),this.version(4,r=>({...r,version:4,config:Hw(r.config)})),this.version(5,(r,a)=>({...r,version:5,config:Rw(r.config,a)})),this.version(6,r=>({...r,version:6,config:em(r.config)}))}}const nm={displayName:"viz.sunburst_chart.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new tm,name:"sunburst",viewRender:Qw,configRender:Yw,createConfig(){return{version:6,config:y.cloneDeep(Ar)}},translation:Xw};var Qe=(e=>(e.string="string",e.number="number",e.eloc="eloc",e.percentage="percentage",e.url="url",e.custom="custom",e))(Qe||{});function ao(){return{page_size:0}}const so=["function text({ value, row_data }, utils) {"," return value","}"].join(`
379
+ `),lo={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",query_id:"",striped:!0,use_raw_columns:!0,ignored_column_keys:"",verticalSpacing:"14px",pagination:ao()};function rm(e){const{columns:t,...r}=e;return{...e,columns:t.map(a=>({...a,align:a.align??"left"}))}}function am(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=c=>c&&`${r}.${c}`,{id_field:l,columns:o,...i}=e;return{...i,id_field:a(l),columns:o.map(c=>({...c,value_field:a(c.value_field)}))}}catch(r){throw console.error("[Migration failed]",r),r}}function sm(e){const{columns:t,...r}=e;return{...r,columns:t.map(a=>({...a,align:a.align??"left",cellBackgroundColor:a.cellBackgroundColor??"",width:a.width??""}))}}function lm(e){const{id_field:t,...r}=e,{queryID:a}=P(t);return{...r,query_id:a??""}}function om(e){const{ignored_column_keys:t,...r}=e;return{...r,ignored_column_keys:t??""}}function im(e){const{pagination:t=ao(),...r}=e;return{...r,pagination:t}}class cm extends ee{constructor(){super(...arguments);V(this,"VERSION",8)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>{const{columns:a,...l}=r.config;return{...r,version:2,config:{...l,columns:a.map(({id:o,...i})=>({id:o??ne.randomId(),...i}))}}}),this.version(3,r=>({...r,version:3,config:rm(r.config)})),this.version(4,(r,a)=>({...r,version:4,config:am(r.config,a)})),this.version(5,r=>({...r,version:5,config:sm(r.config)})),this.version(6,r=>({...r,version:6,config:lm(r.config)})),this.version(7,r=>({...r,version:7,config:om(r.config)})),this.version(8,r=>({...r,version:8,config:im(r.config)}))}}const oo={left:"flex-start",center:"center",right:"flex-end"},dm=({header:e,cx:t})=>{const r=y.get(e.column.columnDef.meta,"align","left");return n.jsxs(s.Text,{className:t("table-head-cell",{"table-head-cell--sortable":e.column.getCanSort()}),onClick:e.column.getToggleSortingHandler(),ta:r,sx:{justifyContent:oo[r]},size:"sm",children:[e.isPlaceholder?null:ge.flexRender(e.column.columnDef.header,e.getContext()),n.jsx(um,{direction:e.column.getIsSorted()})]})},um=({direction:e})=>{switch(e){case"asc":return n.jsx(S.IconArrowUp,{size:16});case"desc":return n.jsx(S.IconArrowDown,{size:"1em"});default:return null}},pm=dt.createStyles(e=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:e.colors.gray[0]}}},thead:{background:e.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),hm={tableLayout:"fixed",width:"fit-content",minWidth:"100%","thead, tbody":{tr:{width:"fit-content",th:{position:"relative"},"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1",transform:"translateY(-50%)",backgroundColor:"rgb(248, 249, 250)"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}},io=dt.createStyles((e,t)=>({content:{display:"flex",alignItems:"center",justifyContent:oo[t.align],".table-cell-text":{whiteSpace:"nowrap",cursor:t.clickable?"pointer":"default",textDecoration:t.clickable?"underline":"none"}}}));function gm(e){return e?Be(e).oklch()[0]>.7?"black":"white":"inherit"}function co(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:gm(t)}}function $t(e){const t=e.tableCellContext.isClickable(),r=io({clickable:t,align:e.align});return n.jsx("div",{className:r.classes.content,style:{...co(e)},children:n.jsx(s.Text,{size:"sm",className:"table-cell-text",onClick:e.tableCellContext.getClickHandler(),children:n.jsx("span",{title:e.children,children:e.children})})})}function fm(e){return n.jsx($t,{...e,children:e.value})}function bm(e){const t=io({clickable:!0,align:e.align}),r=e.value;return n.jsx("div",{className:t.classes.content,style:{...co(e)},children:n.jsx(s.Anchor,{className:"table-cell-text",href:r,target:"_blank",color:"black",children:r})})}function ym(e){const t=Y(e.value,{output:"number",average:!0,mantissa:2,trimMantissa:!0,absolute:!1});return n.jsx($t,{...e,children:t})}function vm(e){const t=Y(e.value,{output:"number",mantissa:0,thousandSeparated:!0,absolute:!1});return n.jsx($t,{...e,children:t})}function _m(e){const t=Y(e.value,{output:"percent",mantissa:3,trimMantissa:!0,absolute:!1});return n.jsx($t,{...e,children:t})}function xm(e){const{value:t,row_data:r,func_content:a}=e;if(!a)return n.jsx($t,{...e,children:t});const l=new Function(`return ${a}`)()({value:t,row_data:r},Ge);return n.jsx($t,{...e,children:l})}function wm(e){switch(e.type){case Qe.string:return n.jsx(fm,{...e});case Qe.eloc:return n.jsx(ym,{...e});case Qe.number:return n.jsx(vm,{...e});case Qe.percentage:return n.jsx(_m,{...e});case Qe.url:return n.jsx(bm,{...e});case Qe.custom:return n.jsx(xm,{...e})}}function mm({tableContainerRef:e,rows:t}){var c,d;const r=ud.useVirtualizer({getScrollElement:()=>e.current,count:t.length,estimateSize:h.useCallback(()=>28,[]),overscan:20}),a=r.getVirtualItems(),l=r.getTotalSize(),o=a.length>0&&((c=a==null?void 0:a[0])==null?void 0:c.start)||0,i=a.length>0?l-(((d=a==null?void 0:a[a.length-1])==null?void 0:d.end)||0):0;return n.jsxs(s.Table.Tbody,{children:[o>0&&n.jsx(s.Table.Tr,{children:n.jsx(s.Table.Td,{style:{height:`${o}px`}})}),a.map(u=>{const p=t[u.index];return n.jsx(s.Table.Tr,{children:p.getVisibleCells().map(f=>n.jsx(s.Table.Td,{children:ge.flexRender(f.column.columnDef.cell,f.getContext())},f.id))},p.id)}),i>0&&n.jsx(s.Table.Tr,{children:n.jsx(s.Table.Td,{style:{height:`${i}px`}})})]})}const $r={id:"builtin:table:click-cell-content",displayName:"viz.table.click_cell.click_cell_content",nameRender:km,configRender:Sm,payload:[{name:"row_index",description:"Index of the row that the cell belongs to",valueType:"number"},{name:"col_index",description:"Index of the column that the cell belongs to",valueType:"number"},{name:"row_data",description:"Data of the row that the cell belongs to",valueType:"object"}]},Cm={column:""};function uo(e,t){const{value:r}=B(e.instanceData,"config"),a={columnsFromConfig:[],columnsFromData:[]};if(r&&(a.columnsFromConfig=r.columns.map((l,o)=>({label:l.label,value:o.toString()}))),!t)return a;if(r!=null&&r.query_id){const l=t[r.query_id];(l==null?void 0:l.length)>0&&(a.columnsFromData=Object.keys(l[0]).map(o=>({label:o,value:o})))}return a}function po(e){const{value:t}=B(e.instanceData,"config");return(t==null?void 0:t.use_raw_columns)??!1}function Sm(e){const{t}=x.useTranslation(),{columnsFromConfig:r,columnsFromData:a}=uo(e.instance,e.sampleData),l=po(e.instance),o=r.length>0?r:a,{value:i,set:c}=B(e.trigger.triggerData,"config"),{column:d}=y.defaults({},i,Cm),u=p=>{p&&(isNaN(+p)?c({column:p}):c({column:+p}))};return l?n.jsxs(s.Stack,{children:[n.jsx(s.Alert,{icon:n.jsx(S.IconAlertCircle,{size:"1rem"}),color:"gray",children:n.jsxs(x.Trans,{i18nKey:"viz.table.click_cell.why_column_data_field",children:["Option ",n.jsx(s.Mark,{children:"Use original data columns"})," is enabled, you have to address trigger column by its data field"]})}),n.jsx(s.TextInput,{label:t("viz.table.click_cell.column_data_field"),value:d.toString(),onChange:p=>u(p.currentTarget.value)})]}):n.jsx(s.Select,{clearable:!1,data:o,label:t("viz.table.click_cell.choose_a_column"),value:d.toString(),onChange:u,comboboxProps:{zIndex:340},maxDropdownHeight:500})}function Tm(e,t,r){const{t:a}=x.useTranslation();if(!e)return a("viz.table.click_cell.click_cell_content");if(y.isNumber(e.column)){if(r)return a("viz.table.click_cell.click_cell_of_x_th",{x:e.column+1});const l=t[e.column];return l?a("viz.table.click_cell.click_cell_of_x",{x:l.label}):a("viz.table.click_cell.click_cell_invalid_config")}return a("viz.table.click_cell.click_cell_of_x",{x:e.column})}function km(e){const{columnsFromConfig:t}=uo(e.instance),{value:r}=B(e.trigger.triggerData,"config"),a=po(e.instance);return n.jsx(s.Text,{size:"sm",children:Tm(r,t,a)})}function ho(e,t,r){return Math.min(Math.max(e,t),r)}class zm{constructor(t){this.steps=t;const r=[],a=new Set;for(const l of t)a.has(l.to)||(r.push(l),a.add(l.to));if(r.sort((l,o)=>l.from-o.from),r.length<2)throw new Error("MultiStepValueMapper requires at least 2 steps");this.steps=r}getLinearFunction(t,r){const a=(r.to-t.to)/(r.from-t.from),l=t.to-a*t.from;return o=>a*o+l}getStepFunctionForValue(t){let r=y.findLastIndex(this.steps,a=>a.from<=t);return r=ho(r,0,this.steps.length-2),this.getLinearFunction(this.steps[r],this.steps[r+1])}mapValue(t){return ho(this.getStepFunctionForValue(t)(t),0,100)}}class Dm{constructor(t,r,a,l,o){this.getColIndex=t,this.cell=r,this.triggers=a,this.interactionManager=l,this.colorManager=o}getClickHandler(){const t=this.getRelatedTrigger();if(t.length!==0)return()=>{const r={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const a of t)this.interactionManager.runInteraction(a.id,r)}}getRelatedTrigger(){return this.triggers.filter(r=>r.schemaRef===$r.id).filter(r=>{const a=this.getColIndex(this.cell),l=y.get(this.cell.column.columnDef.meta,"value_field"),o=y.get(r.config,"column");return o==a||o==l})}isClickable(){return this.getRelatedTrigger().length>0}get columnConf(){return this.cell.column.columnDef.meta}get bgColor(){const t=this.columnConf.cellBackgroundColor;if(!t||t==="none")return;if(y.isString(t))return t;const r=+this.cell.getValue();if(isFinite(r)){const a=this.colorManager.decodeInterpolation(t.interpolation),o=new zm(t.steps).mapValue(r);return a==null?void 0:a.getColor(o)}}}const Im=e=>{const t=Me(e),r=Ie(t.triggerManager,$r.id),{colorManager:a}=h.useContext(rt);return h.useCallback(l=>new Dm(e.getColIndex,l,r,t,a),[r,t,e.getColIndex])},Mm=({classes:e,pagination:t,setPagination:r,pageCount:a,totalRows:l})=>{const{t:o}=x.useTranslation(),{pageSize:i,pageIndex:c}=t;if(l===0)return null;if(i===0)return n.jsx(s.Box,{className:e.info_bar,sx:{height:22},children:n.jsx(s.Text,{ta:"right",pr:6,size:"14px",c:"dimmed",fw:"normal",children:o("common.pagination.total_rows",{total:l})})});const d=()=>{r({...t,pageIndex:c-1})},u=()=>{r({...t,pageIndex:c+1})};return n.jsxs(s.Group,{wrap:"nowrap",justify:"flex-end",gap:4,className:e.info_bar,sx:{height:22},children:[n.jsx(s.Text,{ta:"right",pr:6,size:"14px",c:"dimmed",fw:"normal",children:o("common.pagination.showing_rows",{start_row:c*i+1,end_row:(c+1)*i,total:l})}),n.jsx(s.ActionIcon,{variant:"default","aria-label":"to previous page",onClick:d,size:"xs",disabled:c===0,children:n.jsx(S.IconChevronLeft,{})}),n.jsx(s.ActionIcon,{variant:"default","aria-label":"to next page",onClick:u,size:"xs",disabled:c===a-1,children:n.jsx(S.IconChevronRight,{})})]})};function go({queryData:e,width:t,height:r,conf:a,context:l,instance:o}){x.useTranslation();const{use_raw_columns:i,ignored_column_keys:c,columns:d,...u}=a,{classes:p,cx:f}=pm(),v=h.useMemo(()=>{if(!i)return d;if(!Array.isArray(e)||e.length===0)return[];let Pe=Object.keys(e[0]);const we=new Set(c==null?void 0:c.split(/\r?\n|\r|\n/g).filter(pe=>!!pe));return we.size>0&&(Pe=Pe.filter(pe=>!we.has(pe))),Pe.map(pe=>({id:pe,label:pe,value_field:pe,value_type:Qe.string,align:"left",width:"",cellBackgroundColor:""}))},[i,c,d,e]),_=Im({getColIndex:h.useCallback(Pe=>v.indexOf(Pe.column.columnDef.meta),[v]),vizManager:l.vizManager,instance:o}),w=h.useMemo(()=>{const Pe=ge.createColumnHelper();return v.map(pe=>{const L3=xu(pe.value_field);return Pe.accessor(L3.columnKey,{cell:Xa=>n.jsx(wm,{tableCellContext:_(Xa.cell),value:Xa.getValue(),type:pe.value_type,row_data:Xa.row.original,...pe}),header:pe.label,enableSorting:!0,meta:pe,size:typeof pe.width=="number"?pe.width:void 0,minSize:typeof pe.width=="number"?pe.width:void 0})})},[v,_]),[m,k]=h.useState([]),[z,D]=h.useState({pageIndex:0,pageSize:a.pagination.page_size}),I=h.useMemo(()=>{const{pageIndex:Pe,pageSize:we}=z;return we===0?e:e.slice(Pe*we,(Pe+1)*we)},[e,z]),L=Math.ceil(e.length/z.pageSize),E=ge.useReactTable({data:I,state:{sorting:m},onSortingChange:k,columns:w,columnResizeMode:"onChange",getCoreRowModel:ge.getCoreRowModel(),getSortedRowModel:ge.getSortedRowModel()}),{rows:K}=E.getRowModel(),N=h.useRef(null),le=e.length,xe=le>0,lt=xe?r-22:r,yt=xe?22:0;return n.jsxs("div",{ref:N,style:{height:r,width:t,padding:"0 5px"},"data-enable-scrollbar":!0,className:f(p.root,{"table-highlight-on-hover":a.highlightOnHover}),children:[n.jsx(Mm,{classes:p,pagination:z,totalRows:le,setPagination:D,pageCount:L}),n.jsxs(s.Table,{sx:{...hm,maxHeight:lt},...u,striped:a.striped,children:[n.jsx(s.Table.Thead,{className:p.thead,style:{top:yt},children:E.getHeaderGroups().map(Pe=>n.jsx(s.Table.Tr,{children:Pe.headers.map(we=>n.jsxs(s.Table.Th,{style:{width:we.getSize()},children:[n.jsx(dm,{header:we,cx:f}),n.jsx(s.ActionIcon,{variant:"subtle",onMouseDown:we.getResizeHandler(),onTouchStart:we.getResizeHandler(),className:`resizer ${we.column.getIsResizing()?"isResizing":""}`,children:n.jsx(S.IconArrowBarToRight,{})})]},we.id))},Pe.id))}),n.jsx(mm,{tableContainerRef:N,rows:K})]})]})}function fo(){const{t:e}=x.useTranslation();return n.jsx(s.Text,{size:"sm",c:"gray",ta:"center",children:e("data.empty_data")})}function Vm({data:e,width:t,height:r,conf:a,context:l,instance:o}){const{t:i}=x.useTranslation(),{panel:c}=fe(),d=c.firstQueryData??[];if(c.queryIDs.length===0)return n.jsx(s.Text,{size:"sm",c:"gray",ta:"center",children:i("panel.settings.need_to_choose_queries")});const{query_id:u}=a;if(!u)return d.length===0?n.jsx(fo,{}):n.jsx(go,{queryData:d,width:t,height:r,conf:{...a,use_raw_columns:!0,columns:[]},context:l,instance:o});const p=e[u];return!Array.isArray(p)||p.length===0?n.jsx(fo,{}):n.jsx(go,{queryData:p,width:t,height:r,conf:a,context:l,instance:o})}function Pm({context:e,instance:t}){const r=e.data,{height:a,width:l}=e.viewport,{value:o}=B(e.instanceData,"config");return o?n.jsx(Vm,{data:r,width:l,height:a,conf:o,context:e,instance:t}):null}const Am=[{lang:"en",resources:{table:{viz_name:"Table",column:{labels:"Columns",add:"Add a column",delete:"Delete this column",query_id:"Query",query_id_hint:"Load table data from this query",use_original_data_columns:"Use original data columns",ignore_columns_by_these_key:"Ignore columns by these keys",separate_by_line_break:"Separate by line break",width:"Width",min_width:"Min Width",max_width:"Max Width",cell_background:"Cell background",custom_cell_content:"Custom cell content",value_type:{label:"Value Type",string:"String",number:"Number",percentage:"Percentage",eloc:"ELOC",url:"URL",custom:"Custom"}},style:{horizontal_spacing:"Horizontal Spacing",vertical_spacing:"Vertical Spacing",striped:"Striped",highlight_on_hover:"Hightlight on hover"},click_cell:{label:"Click cell content",click_cell_content:"Click cell content (click to config)",click_cell_of_x:"Click cell of {{ x }}",click_cell_of_x_th:"Click cell by column order {{ x }}",click_cell_invalid_config:"Invalid config",choose_a_column:"Choose a column",why_column_data_field:"Option <1>Use original data columns</1> is enabled, you have to address trigger column by its data field",column_data_field:"Column data field"}}}},{lang:"zh",resources:{table:{viz_name:"表格",column:{labels:"列设置",add:"加一列",delete:"删除这个列",query_id:"表格数据来源",query_id_hint:"通过所选的查询获取表格数据",use_original_data_columns:"使用数据本身的列",ignore_columns_by_these_key:"按下述列名忽略列",separate_by_line_break:"以换行符分隔",width:"宽度",min_width:"最小宽度",max_width:"最大宽度",cell_background:"单元格背景",custom_cell_content:"自定义单元格内容",value_type:{label:"数据类型",string:"文本",number:"数字",percentage:"百分比",eloc:"ELOC",url:"URL",custom:"自定义"}},style:{horizontal_spacing:"水平间距",vertical_spacing:"垂直间距",striped:"隔行变色",highlight_on_hover:"鼠标悬停时高亮整行"},click_cell:{label:"点击单元格",click_cell_content:"点击单元格内容",click_cell_of_x:"点击 {{ x }} 列单元格",click_cell_of_x_th:"点击第 {{ x }} 列单元格",click_cell_invalid_config:"配置信息已失效",choose_a_column:"选择列",why_column_data_field:"选项 <1>使用数据本身的列</1> 已开启,只能通过填写数据字段来指定触发动作的列",column_data_field:"列的数据字段"}}}}],$m=T.observer(h.forwardRef(({label:e,required:t,description:r,value:a,onChange:l,clearable:o=!1,sx:i,...c},d)=>{const{panel:u}=re(),p=h.useMemo(()=>u.queryOptions(a,o),[a,o]);return p.length===0?n.jsx(s.Box,{children:n.jsx(s.TextInput,{label:e,required:t,defaultValue:a,readOnly:!0,disabled:!0})}):n.jsx(s.Select,{ref:d,label:e,description:r,data:p,value:a,onChange:Z(l),required:t,sx:i,maxDropdownHeight:500,...c})})),Em=[{from:0,to:0},{from:100,to:100}];function bo(e){return e?y.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function Bm(e,t){var r;return bo(t)==="static"?t:(r=e.getStaticColors()[0])==null?void 0:r.value}function Lm(e,t){return y.isObject(t)?t:{steps:Em,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const qm=h.forwardRef((e,t)=>{const{t:r}=x.useTranslation(),{colorManager:a}=h.useContext(rt),[l,o]=h.useState(bo(e.value)),[i,c]=h.useState(Bm(a,e.value)),d=O.useLatest(i),[u,p]=h.useState(Lm(a,e.value)),f=O.useLatest(u),v=m=>{var k,z,D;o(m||"none"),m==="static"?(k=e.onChange)==null||k.call(e,d.current):m==="none"||!m?(z=e.onChange)==null||z.call(e,"none"):(D=e.onChange)==null||D.call(e,f.current)},_=m=>{var k;c(m),(k=e.onChange)==null||k.call(e,m)},w=m=>{var k;p(m),(k=e.onChange)==null||k.call(e,m)};return n.jsxs(s.Stack,{align:"stretch",children:[n.jsx(bg,{label:r("viz.table.column.cell_background"),value:l||"none",onChange:v}),l==="static"&&n.jsx(be,{label:r("chart.color.label"),value:i,onChange:_}),l==="interpolation"&&n.jsx(fg,{colorManager:a,value:u,onChange:w})]})}),Om=h.forwardRef(({value:e,onChange:t,sx:r},a)=>{const{t:l,i18n:o}=x.useTranslation(),i=h.useMemo(()=>Object.values(Qe).map(c=>({label:l(`viz.table.column.value_type.${c}`),value:c})),[o.language]);return n.jsx(s.Select,{ref:a,label:l("viz.table.column.value_type.label"),data:i,value:e,onChange:Z(t),maxDropdownHeight:500,sx:r})}),Nm=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a}=x.useTranslation(),[l,{setTrue:o,setFalse:i}]=O.useBoolean(),[c,d]=h.useState(e),u=()=>{i(),t(c)},p=()=>{i(),d(e)},f=()=>{d(so)};return h.useEffect(()=>{d(e)},[e]),n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{color:"grape",variant:"filled",leftSection:n.jsx(S.IconMathFunction,{size:16}),mt:24,onClick:o,sx:{flexGrow:0},children:a("viz.table.column.custom_cell_content")}),n.jsx(s.Modal,{size:800,title:a("viz.table.column.custom_cell_content"),opened:l,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:l&&n.jsxs(s.Stack,{children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(tl,{})}),n.jsx(s.Box,{sx:{position:"relative"},children:n.jsx(Ce,{height:"500px",defaultLanguage:"javascript",value:c,onChange:v=>d(v??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:f,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:a("common.actions.reset_to_default")}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:p,variant:"subtle",children:a("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:u,children:a("common.actions.save")})]})]})]})})]})}),Er=()=>n.jsx(s.Text,{c:"dimmed",size:"12px",children:"px"}),Gm=({control:e,index:t,watch:r})=>{const{t:a}=x.useTranslation(),l=r(`columns.${t}.value_type`),o=r("query_id");return n.jsxs(s.Stack,{my:0,sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`columns.${t}.label`,control:e,render:({field:i})=>n.jsx(s.TextInput,{label:a("chart.label.label"),required:!0,id:`col-label-${t}`,sx:{flex:1},...i})}),n.jsx(b.Controller,{name:`columns.${t}.value_field`,control:e,render:({field:i})=>n.jsx(q,{label:a("common.data_field"),required:!0,queryID:o,...i})})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`columns.${t}.value_type`,control:e,render:({field:i})=>n.jsx(Om,{sx:{flex:1},...i})}),l===Qe.custom&&n.jsx(b.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:i})=>n.jsx(Nm,{value:i.value??so,onChange:c=>i.onChange(c??"")})})]}),n.jsx(s.Divider,{mb:-10,variant:"dashed",label:a("style.label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.NumberInput,{hideControls:!0,label:a("viz.table.column.min_width"),rightSection:n.jsx(Er,{}),disabled:!0}),n.jsx(b.Controller,{name:`columns.${t}.width`,control:e,render:({field:i})=>n.jsx(s.NumberInput,{hideControls:!0,label:a("viz.table.column.width"),rightSection:n.jsx(Er,{}),...i})}),n.jsx(s.NumberInput,{hideControls:!0,label:a("viz.table.column.max_width"),rightSection:n.jsx(Er,{}),disabled:!0})]}),n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:`columns.${t}.align`,control:e,render:({field:i})=>n.jsx(yr,{...i})})}),n.jsx(b.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:i})=>n.jsx(qm,{...i})})]})},Fm=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>{const i=ne.randomId();return{id:i,label:i,align:"center",value_field:"",value_type:Qe.string,width:""}},l=(i,c)=>{const d=i.label.trim();return d||c+1};t(["columns","ignored_column_keys"]);const o=t("use_raw_columns");return n.jsxs(n.Fragment,{children:[n.jsx(b.Controller,{name:"use_raw_columns",control:e,render:({field:i})=>n.jsx(s.Switch,{mt:20,mb:20,label:r("viz.table.column.use_original_data_columns"),checked:i.value,onChange:c=>i.onChange(c.currentTarget.checked)})}),o&&n.jsx(b.Controller,{name:"ignored_column_keys",control:e,render:({field:i})=>n.jsx(s.Textarea,{label:r("viz.table.column.ignore_columns_by_these_key"),placeholder:r("viz.table.column.separate_by_line_break"),autosize:!0,minRows:2,maxRows:10,...i})}),!o&&n.jsx(H,{control:e,watch:t,name:"columns",getItem:a,addButtonText:r("viz.table.column.add"),deleteButtonText:r("viz.table.column.delete"),renderTabName:l,children:({field:i,index:c})=>n.jsx(Gm,{control:e,watch:t,index:c})})]})};function jm({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),n.jsxs(s.Stack,{gap:"xs",children:[n.jsxs(s.Group,{justify:"space-between",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[n.jsx(b.Controller,{name:"horizontalSpacing",control:e,render:({field:a})=>n.jsx(xr,{disabled:!0,label:r("viz.table.style.horizontal_spacing"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"verticalSpacing",control:e,render:({field:a})=>n.jsx(xr,{disabled:!0,label:r("viz.table.style.vertical_spacing"),sx:{flex:1},...a})})]}),n.jsx(s.Group,{justify:"space-between",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:n.jsx(b.Controller,{name:"fontSize",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("style.font_size.label"),placeholder:r("style.font_size.placeholder"),required:!0,sx:{flex:1},...a})})}),n.jsxs(s.Group,{justify:"space-between",grow:!0,children:[n.jsx(b.Controller,{name:"striped",control:e,render:({field:a})=>n.jsx(s.Switch,{label:r("viz.table.style.striped"),checked:a.value,onChange:l=>a.onChange(l.currentTarget.checked)})}),n.jsx(b.Controller,{name:"highlightOnHover",control:e,render:({field:a})=>n.jsx(s.Switch,{label:r("viz.table.style.highlight_on_hover"),checked:a.value,onChange:l=>a.onChange(l.currentTarget.checked)})})]})]})}function Qm({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["pagination"]),n.jsx(s.Stack,{children:n.jsx(b.Controller,{name:"pagination.page_size",control:e,render:({field:a})=>n.jsx(s.NumberInput,{label:r("common.pagination.page_size"),description:r("viz.heatmap.pagination.page_size_hint"),size:"xs",sx:{flex:1},...a,onChange:l=>{typeof l!="string"&&a.onChange(l)}})})})}function Wm({columns:e,...t}){return{...t,columns:e.map(({id:r,...a})=>({id:r??ne.randomId(),...a}))}}function Um({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),l=h.useMemo(()=>y.defaultsDeep({},r,lo),[r]),o=h.useMemo(()=>Wm(l),[l]);h.useEffect(()=>{!y.isEqual(l,o)&&(console.log("config malformed, resetting to defaults",l,o),a(o))},[l,o]);const{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=b.useForm({defaultValues:o});return h.useEffect(()=>{p(o)},[o]),d(["query_id"]),n.jsxs("form",{onSubmit:c(a),children:[n.jsx(ae,{canSubmit:u.isDirty}),n.jsxs(s.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"Columns",children:t("viz.table.column.labels")}),n.jsx(s.Tabs.Tab,{value:"Style",children:t("style.label")}),n.jsx(s.Tabs.Tab,{value:"Pagination",children:t("common.pagination.label")})]}),n.jsxs(s.Tabs.Panel,{value:"Columns",children:[n.jsx(b.Controller,{name:"query_id",control:i,render:({field:f})=>n.jsx($m,{label:t("viz.table.column.query_id"),description:t("viz.table.column.query_id_hint"),required:!0,...f})}),n.jsx(s.Divider,{mt:20,mb:10,variant:"dashed"}),n.jsx(Fm,{control:i,watch:d})]}),n.jsx(s.Tabs.Panel,{value:"Style",children:n.jsx(jm,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Pagination",children:n.jsx(Qm,{control:i,watch:d})})]})]})}const yo=new cm,Br={createConfig(){return{version:yo.VERSION,config:y.cloneDeep(lo)}},displayName:"viz.table.viz_name",displayGroup:"chart.groups.others",migrator:yo,name:"table",viewRender:Pm,configRender:Um,triggers:[$r],translation:Am},vo=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
380
+ `),Lr={func_content:vo,horizontal_align:"left",font_size:"14px",font_weight:"normal"},Km=T.observer(({context:e})=>{const t=J(),{value:r=Lr}=B(e.instanceData,"config"),{variables:a}=e,l=e.data,{func_content:o,horizontal_align:i,font_size:c,font_weight:d}=r,u=h.useMemo(()=>a.reduce((f,v)=>{const _=Je(v,l);return f[v.name]=$e(v,_),f},{}),[a,l]),p=h.useMemo(()=>new Function(`return ${o}`)()({data:l,variables:u,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}),[o,l,u,t.payloadForSQL]);return n.jsx(s.Text,{ta:i,fw:d,sx:{fontSize:c},children:p})}),_n=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function Ym({label:e,value:t,onChange:r},a){var i;const[l,o]=h.useState(((i=_n.find(c=>c.label===t))==null?void 0:i.value)??_n[0].value);return h.useEffect(()=>{const c=_n.find(d=>d.value===l);c&&r(c.label)},[l]),n.jsxs(s.Stack,{gap:0,mt:"sm",mb:"lg",children:[n.jsx(s.Text,{size:"sm",children:e}),n.jsx(s.Box,{px:"1.5em",children:n.jsx(s.Slider,{label:null,marks:_n,value:l,onChange:o,step:25,ref:a})})]})}const Xm=h.forwardRef(Ym),Zm=({value:e,onChange:t})=>{const r=a=>{a&&t(a)};return n.jsx(s.Box,{sx:{position:"relative"},children:n.jsx(Ce,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Jm=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a}=x.useTranslation(),[l,{setTrue:o,setFalse:i}]=O.useBoolean(),[c,d]=h.useState(e),u=()=>{i(),t(c)},p=()=>{i(),d(e)},f=()=>{d(vo)};return h.useEffect(()=>{d(e)},[e]),n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{color:"grape",variant:"filled",leftSection:n.jsx(S.IconMathFunction,{size:16}),mt:24,onClick:o,sx:{flexGrow:0},children:a("viz.text.content.edit")}),n.jsx(s.Modal,{size:800,title:a("viz.text.content.label"),opened:l,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:l&&n.jsxs(s.Stack,{children:[n.jsx(Zm,{value:c,onChange:d}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:f,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:a("common.actions.reset_to_default")}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:p,variant:"subtle",children:a("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:u,children:a("common.actions.save_changes")})]})]})]})})]})});function Hm({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),l=h.useMemo(()=>y.defaultsDeep({},r,Lr),[r]),o=h.useMemo(()=>{const{func_content:f,horizontal_align:v,font_size:_,font_weight:w}=l;return{func_content:f,horizontal_align:v,font_size:_,font_weight:w}},[l]);h.useEffect(()=>{!y.isEqual(l,o)&&(console.log("config malformed, resetting to defaults",l,o),a(o))},[l,o]);const{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=b.useForm({defaultValues:o});return h.useEffect(()=>{p(o)},[o]),d(["func_content","horizontal_align","font_size","font_weight"]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:c(a),children:[n.jsx(ae,{canSubmit:u.isDirty}),n.jsxs(s.Stack,{gap:10,children:[n.jsx(b.Controller,{name:"func_content",control:i,render:({field:f})=>n.jsx(Jm,{...f})}),n.jsx(s.Divider,{mt:10,mb:-10,variant:"dashed",label:t("chart.style.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"horizontal_align",control:i,render:({field:f})=>n.jsx(yr,{...f})}),n.jsx(b.Controller,{name:"font_size",control:i,render:({field:f})=>n.jsx(s.TextInput,{label:t("style.font_size.label"),placeholder:t("style.font_size.placeholder"),sx:{flex:1},...f})}),n.jsx(s.Group,{justify:"space-between",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:n.jsx(b.Controller,{name:"font_weight",control:i,render:({field:f})=>n.jsx(Xm,{label:t("style.font_weight.label"),...f})})})]})]})})}const Rm=[{lang:"en",resources:{text:{viz_name:"Text",content:{label:"Text content",edit:"Edit Content"}}}},{lang:"zh",resources:{text:{viz_name:"文本",content:{label:"文本内容",edit:"编辑文本内容"}}}}];class e0 extends ee{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const t0={displayName:"viz.text.viz_name",displayGroup:"chart.groups.others",migrator:new e0,name:"text",viewRender:Km,configRender:Hm,createConfig(){return{version:1,config:y.cloneDeep(Lr)}},translation:Rm},n0=()=>n.jsxs("svg",{width:"64",height:"64",viewBox:"0 0 64 64",fill:"none",children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M22.49 27.79H14.47C13.55 27.79 12.81 28.53 12.81 29.45C12.81 30.37 13.55 31.11 14.47 31.11H22.49C23.41 31.11 24.15 30.37 24.15 29.45C24.15 28.54 23.41 27.79 22.49 27.79ZM34.32 31.28C35.22 31.32 35.7 31.82 35.74 32.76C35.78 33.54 35.37 34.3 34.51 35.04C33.52 35.9 33.03 36.95 33.03 38.19V38.81H34.82V38.25C34.78 37.59 35.07 37.02 35.68 36.52C37.12 35.41 37.82 34.15 37.78 32.75C37.66 30.53 36.5 29.35 34.32 29.23C32.3 29.23 31.05 30.46 30.55 32.93L32.53 33.55C32.82 32.04 33.42 31.28 34.32 31.28ZM35 39.93H32.84V42.21H35V39.93ZM14.83 36.42H18.54C19.46 36.42 20.2 37.17 20.2 38.08C20.2 39 19.46 39.74 18.54 39.74H10.52C9.6 39.74 8.86 39 8.86 38.08C8.86 37.61 9.06 37.19 9.37 36.89H5.66C4.74 36.89 4 36.15 4 35.23C4 34.31 4.74 33.57 5.66 33.57H13.68C14.6 33.57 15.34 34.31 15.34 35.23C15.34 35.7 15.14 36.12 14.83 36.42ZM50.94 36.85H58.74C59.66 36.85 60.4 37.59 60.41 38.51C60.41 39.43 59.67 40.17 58.75 40.17H54.26C54.56 40.47 54.74 40.88 54.74 41.34C54.74 42.26 54 43 53.08 43H50.94V36.85Z",fill:"#B8C0CC"}),n.jsx("path",{d:"M18.39 32.28H16.51V35.02H18.39V32.28Z",fill:"#9399A5"}),n.jsx("path",{d:"M46.87 15H20.69C18.38 15 16.5 16.88 16.5 19.19V26.22H18.38V23.45H49.18V47.68H18.38V41.07H16.5V49.55H51.05V19.19C51.06 16.88 49.18 15 46.87 15ZM39.46 20.73C38.81 20.73 38.29 20.2 38.29 19.56C38.29 18.92 38.82 18.39 39.46 18.39C40.11 18.39 40.63 18.92 40.63 19.56C40.63 20.2 40.11 20.73 39.46 20.73ZM43.22 20.73C42.57 20.73 42.05 20.2 42.05 19.56C42.05 18.92 42.58 18.39 43.22 18.39C43.87 18.39 44.39 18.92 44.39 19.56C44.39 20.2 43.87 20.73 43.22 20.73ZM46.97 20.73C46.32 20.73 45.8 20.2 45.8 19.56C45.8 18.92 46.33 18.39 46.97 18.39C47.62 18.39 48.14 18.92 48.14 19.56C48.14 20.2 47.62 20.73 46.97 20.73Z",fill:"#9399A5"})]});function _o(e,t){const r=y.get(e,t,"");if(r)throw new Error(r)}async function r0(e,t,r,a={}){const l={"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json",...a.headers},o={baseURL:e,method:"POST",url:t,params:a.params,headers:l};return o.data=a.string?JSON.stringify(r):r,Se(o).then(i=>i.data).catch(i=>Promise.reject(i))}const a0=({conf:e,panelData:t})=>async()=>{const{expertSystemURL:r,path:a,goal:l,question:o}=e;if(!a||!l||!o)return;const i=wu(t);if(!i)return;const c={dashboard:l,panel:o,data:i};try{const d=r.startsWith("http")?r:window.location.origin;return await r0(d,`/expert/v3/devtable/${a}`,c,{})}catch(d){throw _o(d,"response.data.detail"),_o(d,"response.data.error"),console.error(d),d}},qr={expertSystemURL:"",path:"",goal:"",question:""},Or={height:"100%",overflowY:"auto",...Jn},xo=({message:e})=>n.jsx(s.Box,{sx:Or,children:n.jsx("div",{dangerouslySetInnerHTML:{__html:e},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),s0=({error:e,width:t,height:r})=>{const a=e.message;if(a.startsWith("<"))return n.jsx(xo,{message:a});const o=r-25-20-30;return n.jsx(s.Center,{sx:{width:"100%",height:o},children:n.jsxs(s.Stack,{align:"center",gap:20,children:[n.jsx(n0,{}),n.jsx(xo,{message:a})]})})};function l0({context:e}){const{value:t}=B(e.instanceData,"config"),r=h.useMemo(()=>y.defaultsDeep({},t,qr),[t]),{width:a,height:l}=e.viewport,o=e.data,{data:i,error:c,loading:d}=O.useRequest(a0({conf:r,panelData:o}),{refreshDeps:[o,r]});return!a||!l||!r?null:d?n.jsx(s.Box,{sx:{position:"relative",height:l},children:n.jsx(s.LoadingOverlay,{visible:!0})}):c?n.jsx(s.Box,{sx:Or,"data-enable-scrollbar":!0,children:n.jsx(s0,{error:c,width:a,height:l})}):!i||!Array.isArray(i.replies)||i.replies.length===0?null:n.jsx(s.Box,{sx:Or,"data-enable-scrollbar":!0,children:i.replies.map((u,p)=>n.jsx("div",{dangerouslySetInnerHTML:{__html:u.interpretation.html}},p))})}function o0({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaultsDeep({},t,qr),[t]),{control:l,handleSubmit:o,watch:i,formState:c,reset:d}=b.useForm({defaultValues:a});return h.useEffect(()=>{d(a)},[a]),i(["expertSystemURL","goal","path","question"]),n.jsx("form",{onSubmit:o(r),children:n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:"expertSystemURL",control:l,render:({field:u})=>n.jsx(s.TextInput,{label:"Expert System URL",...u})}),n.jsx(b.Controller,{name:"path",control:l,render:({field:u})=>n.jsx(s.TextInput,{label:"Path",required:!0,...u})})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:"goal",control:l,render:({field:u})=>n.jsx(s.TextInput,{label:"Goal",required:!0,...u})}),n.jsx(b.Controller,{name:"question",control:l,render:({field:u})=>n.jsx(s.TextInput,{label:"Question",required:!0,...u})})]}),n.jsx(s.Divider,{variant:"dashed",mt:16,mb:8}),n.jsx(s.Button,{type:"submit",variant:"filled",color:"blue",leftSection:n.jsx(S.IconDeviceFloppy,{size:20}),disabled:!c.isDirty,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}const i0=[{lang:"en",resources:{merico_gqm:{viz_name:"Merico GQM"}}},{lang:"zh",resources:{merico_gqm:{viz_name:"思码逸GQM组件"}}}];class c0 extends ee{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const d0={displayName:"viz.merico_gqm.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new c0,name:"mericoGQM",viewRender:l0,configRender:o0,createConfig(){return{version:1,config:y.cloneDeep(qr)}},translation:i0};function u0(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{calendar:l,heat_block:o,tooltip:i,...c}=e;return{...c,calendar:{...l,data_key:a(l.data_key)},heat_block:{...o,data_key:a(o.data_key)},tooltip:{...i,metrics:i.metrics.map(d=>({...d,data_key:a(d.data_key)}))}}}catch(r){throw console.error("[Migration failed]",r),r}}function p0(e){const{heat_block:t}=e;let{min:r,max:a}=t;return typeof r!="number"&&(r=0),typeof a!="number"&&(a=100),{...e,heat_block:{...t,min:{type:"static",value:r},max:{type:"static",value:a}}}}function h0(e){const{visualMap:t=et(),heat_block:{min:r,max:a,...l},...o}=e;return{...o,heat_block:l,visualMap:{...et(),min:r,max:a}}}function g0(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??U()}))}}}function f0(e){const{heat_block:t}=e;return{...e,heat_block:{...t,unit:t.unit??U()}}}const b0=[{lang:"en",resources:{calendar_heatmap:{viz_name:"Heatmap(Calendar)",calendar:{label:"Calendar",locale:"Langauge"},click_heatmap:{heatblock:{label:"Click heat block"}}}}},{lang:"zh",resources:{calendar_heatmap:{viz_name:"日历热力图",calendar:{label:"日历",locale:"语言"},click_heatmap:{heatblock:{label:"点击热力块"}}}}}];function y0(e){return n.jsx(n.Fragment,{})}function v0(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.calendar_heatmap.click_heatmap.heatblock.label")})}const wo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"viz.calendar_heatmap.click_heatmap.heatblock.label",nameRender:v0,configRender:y0,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]},Nr={calendar:{data_key:"",locale:"EN"},heat_block:{name:"Value",data_key:"",unit:U(),value_formatter:ce},tooltip:{metrics:[]},visualMap:et()};function _0(e,t,r){if(!e)return r[0];try{return[t,M(t).add(1,"year").subtract(1,"day").valueOf()]}catch(a){return console.error(a),r[0]}}function x0(e,t,r){const a=_0(e,t,r);return{top:50,left:25,right:5,cellSize:["auto",13],range:a,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function w0(e){return{heat_block:function(a){if(!e.heat_block.value_formatter)return a;try{return Y(a,e.heat_block.value_formatter)}catch(l){return console.error(l),a}}}}function m0(e,t){return{show:!e,selectedMode:"single",top:5,right:5,data:t.map(r=>({name:r,icon:"circle"}))}}function C0(e,t,r){return e?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:r}:Object.entries(t).map(([a,l])=>({type:"heatmap",name:a,coordinateSystem:"calendar",calendarIndex:0,data:l}))}const S0=e=>Y(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function T0({conf:e,valueFormatters:t,dataDict:r,params:a,metricUnitMap:l}){const{value:o}=a,[i,c]=o,u=[{label:e.heat_block.name,value:t.heat_block(c),unit:e.heat_block.unit.show_in_tooltip?e.heat_block.unit.text:""}],p=r[i];return p&&e.tooltip.metrics.forEach(f=>{const v=P(f.data_key),_=l[f.name]??"";u.push({label:f.name,value:S0(y.get(p,v.columnKey,"")),unit:_})}),u}function k0(e,t,r){const a=P(e.calendar.data_key),l=y.keyBy(t[a.queryID],a.columnKey),o=e.tooltip.metrics.reduce((i,{unit:c,name:d})=>(c.show_in_tooltip&&(i[d]=c.text),i),{});return X.getTooltip({formatter:function(i){const d=T0({conf:e,valueFormatters:r,dataDict:l,params:i,metricUnitMap:o}).map(f=>`
381
381
  <tr>
382
382
  <th style="text-align: right; padding: 0 1em;">
383
383
  ${f.label}
@@ -406,7 +406,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
406
406
  </thead>
407
407
  <tbody>${d.join("")}</tbody>
408
408
  </table>
409
- `}})}const S0=e=>M(e).get("year");function T0(e){const t=y.groupBy(e,i=>i.value[2]),r=Object.keys(t),a=e.map(i=>M(i.value[0]).valueOf()),l=y.min(a),o=y.max(a);return{minDate:l??0,maxDate:o??0,dateSpan:M(o).diff(l,"day"),dataByYear:t,years:r}}function k0(e,t,r){const a=r.reduce((z,D)=>{const I=Re(D,t);return z[D.name]=$e(D,I),z},{}),l=tn(e.visualMap,a),{min:o,max:i}=l,c=v0(e),d=A(e.calendar.data_key),u=A(e.heat_block.data_key),p=t[d.queryID].map(z=>{const D=y.get(z,d.columnKey),I=y.get(z,u.columnKey),L=S0(z[d.columnKey]),E={value:[D,I,L]},{followVisualMap:K,color:N}=er(I,o,i,e.visualMap);return K||(E.visualMap=!1,E.itemStyle={color:N}),E}),{dateSpan:f,minDate:v,dataByYear:_,years:w}=T0(p),m=f<=366;return{calendar:y0(m,v,w),series:x0(m,_,p),tooltip:C0(e,t,c),visualMap:{...l,orient:"horizontal",left:m?"center":5,dimension:1},legend:_0(m,w),grid:{containLabel:!0}}}function z0({name:e},t){const r=t.getOption();r.calendar.forEach(a=>{a.range=e}),t.setOption(r)}function D0({conf:e,data:t,width:r,height:a,interactionManager:l,variables:o,instance:i}){const c=mt(t,e.calendar.data_key),d=Ie(l.triggerManager,vo.id),u=h.useCallback(w=>{const[m,k]=w.value,z=y.get(c,m,{error:"rowData is not found"});d.forEach(D=>{l.runInteraction(D.id,{...w,rowData:z})})},[c,d,l]),p=h.useRef(null),f=h.useCallback(()=>{var m;const w=(m=p.current)==null?void 0:m.getEchartsInstance();w&&de(i,w.getOption())},[i]),v=h.useMemo(()=>({click:u,legendselectchanged:z0,finished:f}),[u,f]),_=h.useMemo(()=>k0(e,t,o),[e,t]);return n.jsx(he,{echarts:ce,option:_,ref:p,style:{width:r,height:a},onEvents:v,notMerge:!0,opts:{locale:e.calendar.locale},theme:"merico-light"})}function I0({context:e,instance:t}){const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},a,Or),[a]),i=e.data,{width:c,height:d}=e.viewport;return!o.calendar.data_key||!o.heat_block.data_key||!c||!d?null:n.jsx(_e,{width:c,height:d,children:n.jsx(D0,{instance:t,variables:l,width:Ge(c),height:Fe(d),data:i,conf:o,interactionManager:r})})}const M0=[{label:"中文",value:"ZH"},{label:"English",value:"EN"}];function A0({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["calendar"]),n.jsxs(s.Stack,{children:[n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:"calendar.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),sx:{flex:1},...a})})}),n.jsx(b.Controller,{name:"calendar.locale",control:e,render:({field:a})=>n.jsx(s.Select,{label:r("viz.calendar_heatmap.calendar.locale"),data:M0,sx:{flex:1},...a})})]})}function P0({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["heat_block"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"heat_block.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"heat_block.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:"heat_block.unit",control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("numbro.format.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"heat_block.value_formatter",control:e,render:({field:a})=>n.jsx(Le,{...a})})]})}const V0=({control:e,index:t})=>{const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.unit`,control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})})]})},$0=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>({id:Date.now().toString(),data_key:"",name:"",unit:U()}),l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:r("chart.tooltip.additional_metrics.description")})]}),n.jsx(s.Divider,{variant:"dashed",my:10}),n.jsx(H,{control:e,watch:t,name:"tooltip.metrics",getItem:a,addButtonText:r("chart.tooltip.additional_metrics.add"),deleteButtonText:r("chart.tooltip.additional_metrics.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(V0,{control:e,index:i})})]})};function E0({control:e,watch:t}){return n.jsx($0,{control:e,watch:t})}function B0({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),l=h.useMemo(()=>r?y.defaults({},r):Or,[r]),o=h.useMemo(()=>y.cloneDeep(l),[l]);h.useEffect(()=>{!y.isEqual(l,o)&&(console.log("config malformed, resetting to defaults",l,o),a(o))},[l,o]);const i=b.useForm({defaultValues:o}),{control:c,handleSubmit:d,watch:u,formState:p,reset:f}=i;return h.useEffect(()=>{f(o)},[o]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:d(a),children:[n.jsx(ae,{canSubmit:p.isDirty}),n.jsxs(s.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"Calendar",children:t("viz.calendar_heatmap.calendar.label")}),n.jsx(s.Tabs.Tab,{value:"Heat Block",children:t("chart.heatmap.heatblock.label")}),n.jsx(s.Tabs.Tab,{value:"Visual Map",children:t("chart.visual_map.label")}),n.jsx(s.Tabs.Tab,{value:"Tooltip",children:t("chart.tooltip.label")})]}),n.jsx(s.Tabs.Panel,{value:"Calendar",children:n.jsx(A0,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Heat Block",children:n.jsx(P0,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Visual Map",children:n.jsx(Dr,{form:i})}),n.jsx(s.Tabs.Panel,{value:"Tooltip",children:n.jsx(E0,{control:c,watch:u})})]})]})})}class L0 extends ee{constructor(){super(...arguments);P(this,"VERSION",6)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,(r,a)=>({...r,version:2,config:i0(r.config,a)})),this.version(3,r=>({...r,version:3,config:c0(r.config)})),this.version(4,r=>({...r,version:4,config:d0(r.config)})),this.version(5,r=>({...r,version:5,config:u0(r.config)})),this.version(6,r=>({...r,version:6,config:p0(r.config)}))}}const q0={displayName:"viz.calendar_heatmap.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new L0,name:"calendarHeatmap",viewRender:I0,configRender:B0,createConfig:()=>({version:6,config:Or}),triggers:[vo],translation:h0},Nr={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:le,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:fe(),overflow:we()},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function O0(){const e=new Date().getTime().toString();return{id:e,min:"",max:"",name:e,data_key:"",position:"bottom",label_formatter:le,show:!0}}function N0(){const e=new Date().getTime().toString();return{id:e,type:"bar",name:e,unit:U(),stack:"",color:"",barGap:"0%",data_key:"",barWidth:"",barMinWidth:"1",barMaxWidth:"10",group_by_key:"",hide_in_legend:!1,invisible:!1,label_position:"right",aggregation_on_value:kt,xAxisIndex:"0"}}function G0(){const e=new Date().getTime().toString();return{id:e,name:e,template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,xAxisIndex:"0"}}function F0(e){const t=e.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let r=0;t&&(r+=15);const a=e.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let l=0;return a&&(l+=15),e.series.some(o=>!o.hide_in_legend)&&(l+=20),{top:r,right:5,bottom:l,left:5,containLabel:!0}}function j0(e){switch(e){case"bar":return"roundRect";case"scatter":return"circle"}}function Q0(e,t){const r=e.series.reduce((l,{unit:o,name:i})=>(o.show_in_legend&&(l[i]=o.text),l),{}),a={show:!0,bottom:0,left:"center",type:"scroll",formatter:l=>{const o=r[l];return o?`${l}(${o})`:l}};return a.data=t.filter(l=>!l.hide_in_legend).map(({name:l,type:o})=>({name:l,icon:j0(o)})),a}function W0(e,t,r,a){return e.map(l=>{const o=l.orientation==="horizontal",i=o?"yAxis":"xAxis",c=o?"insideEndTop":"end";return{name:l.name,type:"line",hide_in_legend:!l.show_in_legend,xAxisIndex:l.xAxisIndex,data:[],lineStyle:l.lineStyle,markLine:{data:[{name:l.name,[i]:Number(r[l.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:l.lineStyle,label:{formatter:function(){return l.template?jt(l.template,t,a):""},position:c}}}})}function xn(e,t,r){const a=Ve(e,t),l=Ve(e,r);return y.zip(l,a)}function U0(e,t,r,a){const l=xn(t,r,a);return y.unionBy(l,e,0)}function Y0({dataTemplate:e,data:t,name_data_key:r,value_data_key:a,valueTypedXAxis:l}){return l?U0(e,t,r,a):xn(t,r,a)}function K0({dataTemplate:e,data:t,aggregation_on_value:r,name_data_key:a,value_data_key:l,valueTypedXAxis:o}){if(!r||r.type==="none")return Y0({dataTemplate:e,data:t,name_data_key:a,value_data_key:l,valueTypedXAxis:o});const i=xn(t,a,l),c=y.groupBy(i,"0");return e.map(([u])=>{const f=c[u].map(_=>_[1]),v=Nn(f,r);return[u,v]})}function X0({group_by_key:e,data:t,value_data_key:r,name_data_key:a}){const{queryID:l,columnKey:o}=A(e),i=y.groupBy(t[l],o);return Object.entries(i).forEach(([c,d])=>{i[c]=xn({[l]:d},a,r)}),i}function Z0({y_axis:e},{data_key:t,xAxisIndex:r,label_position:a,name:l,group_by_key:o,aggregation_on_value:i,stack:c,color:d,hide_in_legend:u,invisible:p,id:f,...v},_,w,m,k,z){const D={label:{show:!!a,position:a,formatter:z[r??"default"]},name:l,yAxisId:"main-y-axis",xAxisIndex:r,stack:c,color:p?"transparent":d,hide_in_legend:u,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...v};if(!o||o===e.data_key)return D.data=K0({dataTemplate:_,data:m,aggregation_on_value:i,name_data_key:e.data_key,value_data_key:t,valueTypedXAxis:w}),D;const I=X0({group_by_key:o,data:m,name_data_key:e.data_key,value_data_key:t});return Object.entries(I).map(([L,E])=>{const K=y.cloneDeep(D);return K.name=L,K.color=void 0,K.data=E,K})}function J0(e,t,r,a,l,o,i){const c=t.map(u=>[u,0]);return e.series.map(u=>Z0(e,u,c,r,a,i,l)).flat().concat(W0(e.reference_lines,o,i,a))}function H0(e,t){const r=e.find(c=>c.axisDim==="y"&&c.axisId==="main-y-axis");if(!r)return"";const{name:a,axisType:l,axisValue:o,axisIndex:i}=r;return l==="yAxis.category"?a:xe(t.y_axis.axisLabel.formatter)(o,i)}function R0(e,t,r){const a=t.reduce((o,{xAxisIndex:i,name:c})=>(o[c]=i,o),{}),l=e.series.reduce((o,{unit:i,name:c})=>(i.show_in_tooltip&&(o[c]=i.text),o),{});return X.getTooltip({trigger:"axis",axisPointer:{type:"shadow"},formatter:function(o){const i=Array.isArray(o)?o:[o];if(i.length===0)return"";const c=i.map(({seriesName:p,marker:f,value:v})=>{if(Array.isArray(v)&&v.length===2&&(v=v[0]),!p)return v;const _=a[p],w=r[_]??r.default;return`
409
+ `}})}const z0=e=>M(e).get("year");function D0(e){const t=y.groupBy(e,i=>i.value[2]),r=Object.keys(t),a=e.map(i=>M(i.value[0]).valueOf()),l=y.min(a),o=y.max(a);return{minDate:l??0,maxDate:o??0,dateSpan:M(o).diff(l,"day"),dataByYear:t,years:r}}function I0(e,t,r){const a=r.reduce((z,D)=>{const I=Je(D,t);return z[D.name]=$e(D,I),z},{}),l=tn(e.visualMap,a),{min:o,max:i}=l,c=w0(e),d=P(e.calendar.data_key),u=P(e.heat_block.data_key),p=t[d.queryID].map(z=>{const D=y.get(z,d.columnKey),I=y.get(z,u.columnKey),L=z0(z[d.columnKey]),E={value:[D,I,L]},{followVisualMap:K,color:N}=er(I,o,i,e.visualMap);return K||(E.visualMap=!1,E.itemStyle={color:N}),E}),{dateSpan:f,minDate:v,dataByYear:_,years:w}=D0(p),m=f<=366;return{calendar:x0(m,v,w),series:C0(m,_,p),tooltip:k0(e,t,c),visualMap:{...l,orient:"horizontal",left:m?"center":5,dimension:1},legend:m0(m,w),grid:{containLabel:!0}}}function M0({name:e},t){const r=t.getOption();r.calendar.forEach(a=>{a.range=e}),t.setOption(r)}function V0({conf:e,data:t,width:r,height:a,interactionManager:l,variables:o,instance:i}){const c=mt(t,e.calendar.data_key),d=Ie(l.triggerManager,wo.id),u=h.useCallback(w=>{const[m,k]=w.value,z=y.get(c,m,{error:"rowData is not found"});d.forEach(D=>{l.runInteraction(D.id,{...w,rowData:z})})},[c,d,l]),p=h.useRef(null),f=h.useCallback(()=>{var m;const w=(m=p.current)==null?void 0:m.getEchartsInstance();w&&de(i,w.getOption())},[i]),v=h.useMemo(()=>({click:u,legendselectchanged:M0,finished:f}),[u,f]),_=h.useMemo(()=>I0(e,t,o),[e,t]);return n.jsx(he,{echarts:ie,option:_,ref:p,style:{width:r,height:a},onEvents:v,notMerge:!0,opts:{locale:e.calendar.locale},theme:"merico-light"})}function P0({context:e,instance:t}){const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},a,Nr),[a]),i=e.data,{width:c,height:d}=e.viewport;return!o.calendar.data_key||!o.heat_block.data_key||!c||!d?null:n.jsx(_e,{width:c,height:d,children:n.jsx(V0,{instance:t,variables:l,width:Oe(c),height:Ne(d),data:i,conf:o,interactionManager:r})})}const A0=[{label:"中文",value:"ZH"},{label:"English",value:"EN"}];function $0({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["calendar"]),n.jsxs(s.Stack,{children:[n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:"calendar.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),sx:{flex:1},...a})})}),n.jsx(b.Controller,{name:"calendar.locale",control:e,render:({field:a})=>n.jsx(s.Select,{label:r("viz.calendar_heatmap.calendar.locale"),data:A0,sx:{flex:1},...a})})]})}function E0({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["heat_block"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"heat_block.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"heat_block.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:"heat_block.unit",control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("numbro.format.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"heat_block.value_formatter",control:e,render:({field:a})=>n.jsx(je,{...a})})]})}const B0=({control:e,index:t})=>{const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.unit`,control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})})]})},L0=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>({id:Date.now().toString(),data_key:"",name:"",unit:U()}),l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:r("chart.tooltip.additional_metrics.description")})]}),n.jsx(s.Divider,{variant:"dashed",my:10}),n.jsx(H,{control:e,watch:t,name:"tooltip.metrics",getItem:a,addButtonText:r("chart.tooltip.additional_metrics.add"),deleteButtonText:r("chart.tooltip.additional_metrics.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(B0,{control:e,index:i})})]})};function q0({control:e,watch:t}){return n.jsx(L0,{control:e,watch:t})}function O0({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),l=h.useMemo(()=>r?y.defaults({},r):Nr,[r]),o=h.useMemo(()=>y.cloneDeep(l),[l]);h.useEffect(()=>{!y.isEqual(l,o)&&(console.log("config malformed, resetting to defaults",l,o),a(o))},[l,o]);const i=b.useForm({defaultValues:o}),{control:c,handleSubmit:d,watch:u,formState:p,reset:f}=i;return h.useEffect(()=>{f(o)},[o]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:d(a),children:[n.jsx(ae,{canSubmit:p.isDirty}),n.jsxs(s.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"Calendar",children:t("viz.calendar_heatmap.calendar.label")}),n.jsx(s.Tabs.Tab,{value:"Heat Block",children:t("chart.heatmap.heatblock.label")}),n.jsx(s.Tabs.Tab,{value:"Visual Map",children:t("chart.visual_map.label")}),n.jsx(s.Tabs.Tab,{value:"Tooltip",children:t("chart.tooltip.label")})]}),n.jsx(s.Tabs.Panel,{value:"Calendar",children:n.jsx($0,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Heat Block",children:n.jsx(E0,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Visual Map",children:n.jsx(Dr,{form:i})}),n.jsx(s.Tabs.Panel,{value:"Tooltip",children:n.jsx(q0,{control:c,watch:u})})]})]})})}class N0 extends ee{constructor(){super(...arguments);V(this,"VERSION",6)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,(r,a)=>({...r,version:2,config:u0(r.config,a)})),this.version(3,r=>({...r,version:3,config:p0(r.config)})),this.version(4,r=>({...r,version:4,config:h0(r.config)})),this.version(5,r=>({...r,version:5,config:g0(r.config)})),this.version(6,r=>({...r,version:6,config:f0(r.config)}))}}const G0={displayName:"viz.calendar_heatmap.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new N0,name:"calendarHeatmap",viewRender:P0,configRender:O0,createConfig:()=>({version:6,config:Nr}),triggers:[wo],translation:b0},Gr={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:ce,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:ye(),overflow:De()},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function F0(){const e=new Date().getTime().toString();return{id:e,min:"",max:"",name:e,data_key:"",position:"bottom",label_formatter:ce,show:!0}}function j0(){const e=new Date().getTime().toString();return{id:e,type:"bar",name:e,unit:U(),stack:"",color:"",barGap:"0%",data_key:"",barWidth:"",barMinWidth:"1",barMaxWidth:"10",group_by_key:"",hide_in_legend:!1,invisible:!1,label_position:"right",aggregation_on_value:kt,xAxisIndex:"0"}}function Q0(){const e=new Date().getTime().toString();return{id:e,name:e,template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,xAxisIndex:"0"}}function W0(e){const t=e.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let r=0;t&&(r+=15);const a=e.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let l=0;return a&&(l+=15),e.series.some(o=>!o.hide_in_legend)&&(l+=20),{top:r,right:5,bottom:l,left:5,containLabel:!0}}function U0(e){switch(e){case"bar":return"roundRect";case"scatter":return"circle"}}function K0(e,t){const r=e.series.reduce((l,{unit:o,name:i})=>(o.show_in_legend&&(l[i]=o.text),l),{}),a={show:!0,bottom:0,left:"center",type:"scroll",formatter:l=>{const o=r[l];return o?`${l}(${o})`:l}};return a.data=t.filter(l=>!l.hide_in_legend).map(({name:l,type:o})=>({name:l,icon:U0(o)})),a}function Y0(e,t,r,a){return e.map(l=>{const o=l.orientation==="horizontal",i=o?"yAxis":"xAxis",c=o?"insideEndTop":"end";return{name:l.name,type:"line",hide_in_legend:!l.show_in_legend,xAxisIndex:l.xAxisIndex,data:[],lineStyle:l.lineStyle,markLine:{data:[{name:l.name,[i]:Number(r[l.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:l.lineStyle,label:{formatter:function(){return l.template?jt(l.template,t,a):""},position:c}}}})}function xn(e,t,r){const a=Ae(e,t),l=Ae(e,r);return y.zip(l,a)}function X0(e,t,r,a){const l=xn(t,r,a);return y.unionBy(l,e,0)}function Z0({dataTemplate:e,data:t,name_data_key:r,value_data_key:a,valueTypedXAxis:l}){return l?X0(e,t,r,a):xn(t,r,a)}function J0({dataTemplate:e,data:t,aggregation_on_value:r,name_data_key:a,value_data_key:l,valueTypedXAxis:o}){if(!r||r.type==="none")return Z0({dataTemplate:e,data:t,name_data_key:a,value_data_key:l,valueTypedXAxis:o});const i=xn(t,a,l),c=y.groupBy(i,"0");return e.map(([u])=>{const f=c[u].map(_=>_[1]),v=Nn(f,r);return[u,v]})}function H0({group_by_key:e,data:t,value_data_key:r,name_data_key:a}){const{queryID:l,columnKey:o}=P(e),i=y.groupBy(t[l],o);return Object.entries(i).forEach(([c,d])=>{i[c]=xn({[l]:d},a,r)}),i}function R0({y_axis:e},{data_key:t,xAxisIndex:r,label_position:a,name:l,group_by_key:o,aggregation_on_value:i,stack:c,color:d,hide_in_legend:u,invisible:p,id:f,...v},_,w,m,k,z){const D={label:{show:!!a,position:a,formatter:z[r??"default"]},name:l,yAxisId:"main-y-axis",xAxisIndex:r,stack:c,color:p?"transparent":d,hide_in_legend:u,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...v};if(!o||o===e.data_key)return D.data=J0({dataTemplate:_,data:m,aggregation_on_value:i,name_data_key:e.data_key,value_data_key:t,valueTypedXAxis:w}),D;const I=H0({group_by_key:o,data:m,name_data_key:e.data_key,value_data_key:t});return Object.entries(I).map(([L,E])=>{const K=y.cloneDeep(D);return K.name=L,K.color=void 0,K.data=E,K})}function e1(e,t,r,a,l,o,i){const c=t.map(u=>[u,0]);return e.series.map(u=>R0(e,u,c,r,a,i,l)).flat().concat(Y0(e.reference_lines,o,i,a))}function t1(e,t){const r=e.find(c=>c.axisDim==="y"&&c.axisId==="main-y-axis");if(!r)return"";const{name:a,axisType:l,axisValue:o,axisIndex:i}=r;return l==="yAxis.category"?a:ze(t.y_axis.axisLabel.formatter)(o,i)}function n1(e,t,r){const a=t.reduce((o,{xAxisIndex:i,name:c})=>(o[c]=i,o),{}),l=e.series.reduce((o,{unit:i,name:c})=>(i.show_in_tooltip&&(o[c]=i.text),o),{});return X.getTooltip({trigger:"axis",axisPointer:{type:"shadow"},formatter:function(o){const i=Array.isArray(o)?o:[o];if(i.length===0)return"";const c=i.map(({seriesName:p,marker:f,value:v})=>{if(Array.isArray(v)&&v.length===2&&(v=v[0]),!p)return v;const _=a[p],w=r[_]??r.default;return`
410
410
  <tr>
411
411
  <td>${f}</td>
412
412
  <th style="text-align: right; padding: 0 1em;">${p}</th>
@@ -415,7 +415,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
415
415
  ${l[p]??""}
416
416
  </th>
417
417
  </tr>
418
- `}),d=Ee(e.y_axis.axisLabel.overflow.in_tooltip),u=H0(i,e);return`
418
+ `}),d=Ee(e.y_axis.axisLabel.overflow.in_tooltip),u=t1(i,e);return`
419
419
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
420
420
  <div style="${d}">${u}</div>
421
421
  </div>
@@ -424,7 +424,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
424
424
  ${c.join("")}
425
425
  </tbody>
426
426
  </table>
427
- `}})}function e1(e){return e.x_axes.reduce((r,{label_formatter:a},l)=>(r[l]=function(i){let c=i;if(typeof i=="object"&&(Array.isArray(i.value)&&i.value.length===2?c=i.value[0]:c=i.value),!a)return c;try{return Y(c,a)}catch(d){return console.error(d),c}},r),{default:({value:r})=>r})}function t1(e,t){const r={};return t.map(a=>{const l=Re(a,e);r[a.name]=$e(a,l)}),r}function n1(e,t){return e.x_axes.map(({min:r,max:a,...l},o)=>{let i=l.position;return i||(i=o>0?"bottom":"top"),X.getYAxis({...l,type:"value",min:r||void 0,max:a||void 0,position:i,axisLabel:{show:!0,margin:2,formatter:t[o]??t.default},nameLocation:"center",nameGap:15})})}function r1(e,t){const r=t.every(i=>!Number.isNaN(Number(i))),{overflow:a,...l}=e.y_axis.axisLabel,o=Be(a.on_axis);return[X.getXAxis({data:t,name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center"},id:"main-y-axis",type:r?"value":"category",axisLabel:{...l,...o,formatter:xe(l.formatter)},z:5})]}function a1(e,t,r){if(!e.y_axis.data_key)return{};const a=t1(t,r),l=e1(e),o=A(e.y_axis.data_key),i=y.uniq(t[o.queryID].map(p=>p[o.columnKey])),c=i.every(p=>!Number.isNaN(Number(p))),d=J0(e,i,c,t,l,r,a);return{xAxis:n1(e,l),yAxis:r1(e,i),series:d,tooltip:R0(e,d,l),grid:F0(e),legend:Q0(e,d)}}function s1({conf:e,data:t,width:r,height:a,interactionManager:l,variables:o,instance:i}){const c=mt(t,e.y_axis.data_key),d=Ie(l.triggerManager,wr.id),u=h.useCallback(w=>{const m=y.get(c,w.name,{error:"rowData is not found"});d.forEach(k=>{l.runInteraction(k.id,{...w,rowData:m})})},[c,d,l]),p=h.useRef(null),f=h.useCallback(()=>{var m;const w=(m=p.current)==null?void 0:m.getEchartsInstance();w&&de(i,w.getOption())},[i]),v=h.useMemo(()=>({click:u,finished:f}),[u]),_=h.useMemo(()=>a1(e,t,o),[e,t]);return n.jsx(he,{echarts:ce,option:_,ref:p,style:{width:r,height:a},onEvents:v,notMerge:!0,theme:"merico-light"})}function l1({context:e,instance:t}){const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},a,Nr),[a]),i=e.data,{width:c,height:d}=e.viewport;return!c||!d?null:n.jsx(_e,{width:c,height:d,children:n.jsx(s1,{instance:t,variables:l,width:Ge(c),height:Fe(d),data:i,conf:o,interactionManager:r})})}function o1({control:e,index:t,watch:r,variableOptions:a,xAxisOptions:l}){const{t:o}=x.useTranslation(),i=r(`reference_lines.${t}.orientation`);return n.jsxs(s.Stack,{my:0,p:0,pt:10,sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:o("common.name"),placeholder:o("chart.reference_line.name_placeholder"),required:!0,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:c})=>n.jsx(s.Select,{label:o("common.data_field"),required:!0,data:a,sx:{flex:1},...c})})]}),n.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:o("chart.content_template.label"),placeholder:o("chart.content_template.hint"),sx:{flex:1},...c})}),n.jsxs(s.Group,{grow:!0,children:[n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:c})=>n.jsx(gt,{sx:{flex:1},...c})}),i==="vertical"&&n.jsx(s.Text,{mt:-10,c:"dimmed",size:"12px",children:o("chart.reference_line.orientation.vertical_hint")})]}),i==="horizontal"&&n.jsx(b.Controller,{name:`reference_lines.${t}.xAxisIndex`,control:e,render:({field:c})=>n.jsx(s.Select,{label:o("chart.x_axis.label"),data:l,disabled:l.length===0,sx:{flex:1},...c})})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:o("chart.style.label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:c})=>n.jsx(Pt,{sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:c})=>n.jsx(s.NumberInput,{label:o("chart.series.line.line_width"),min:1,max:10,sx:{flexGrow:1},...c})})]}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:c})=>n.jsx(ye,{label:o("chart.color.label"),...c})})}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:o("chart.behavior.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:c})=>n.jsx(s.Checkbox,{label:o("chart.legend.show_in_legend"),checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})]})}function i1({control:e,watch:t,variables:r}){const{t:a}=x.useTranslation(),l=()=>G0(),o=h.useMemo(()=>r.map(u=>({label:u.name,value:u.name})),[r]),i=t("x_axes"),c=h.useMemo(()=>i.map(({name:u},p)=>({label:u,value:p.toString()})),[i]),d=(u,p)=>{const f=u.name.trim();return f||p+1};return n.jsx(H,{control:e,watch:t,name:"reference_lines",getItem:l,addButtonText:a("chart.reference_line.add"),deleteButtonText:a("chart.reference_line.delete"),renderTabName:d,children:({field:u,index:p})=>n.jsx(o1,{control:e,index:p,watch:t,variableOptions:o,xAxisOptions:c})})}function c1({control:e,index:t,seriesItem:r}){const{t:a,i18n:l}=x.useTranslation(),o=!!r.barWidth.trim(),i=h.useMemo(()=>[{label:a("chart.series.bar.bar_gap.no_gap"),value:"0%"},{label:a("chart.series.bar.bar_gap.overlap"),value:"-100%"}],[l.language]);return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${t}.stack`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.stack"),placeholder:a("chart.series.bar.stack_hint"),sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.barGap`,control:e,render:({field:c})=>n.jsx(s.Select,{label:a("chart.series.bar.bar_gap.label"),data:i,sx:{flexGrow:1},...c})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.bar_width.min"),disabled:o,sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.bar_width.exact"),sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.bar_width.max"),disabled:o,sx:{flexGrow:1},...c})})]})]})}function d1({control:e,index:t,seriesItem:r,xAxisOptions:a}){const{t:l}=x.useTranslation();return n.jsxs(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${t}.name`,control:e,render:({field:o})=>n.jsx(s.TextInput,{label:l("common.name"),required:!0,sx:{flex:1},...o})}),n.jsx(b.Controller,{name:`series.${t}.xAxisIndex`,control:e,render:({field:o})=>n.jsx(s.Select,{label:l("chart.x_axis.label"),data:a,disabled:a.length===0,sx:{flex:1},...o})})]}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(b.Controller,{name:`series.${t}.data_key`,control:e,render:({field:o})=>n.jsx(q,{label:l("common.data_field"),required:!0,sx:{flex:1},...o})}),n.jsx(b.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:o})=>n.jsx(kr,{label:l("viz.horizontal_bar_chart.series.aggregation.label"),value:o.value??kt,onChange:o.onChange,pt:0,withFallback:!1})})]}),n.jsx(s.Group,{grow:!0,children:n.jsx(b.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:o})=>n.jsx(q,{label:l("chart.series.group_by.label"),clearable:!0,sx:{flex:1},...o})})}),n.jsx(b.Controller,{name:`series.${t}.unit`,control:e,render:({field:o})=>n.jsx(ue,{...o})}),n.jsx(c1,{index:t,control:e,seriesItem:r}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:l("chart.style.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:`series.${t}.label_position`,control:e,render:({field:o})=>n.jsx(Vt,{label:l("chart.label_position.label"),...o,withOffOption:!0,onChange:i=>{o.onChange(i??"")}})}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:`series.${t}.color`,control:e,render:({field:o})=>n.jsx(ye,{label:l("chart.color.label"),...o})})}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:l("chart.behavior.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:o})=>n.jsx(s.Checkbox,{label:l("chart.legend.hide_in_legend"),checked:o.value,onChange:i=>o.onChange(i.currentTarget.checked)})}),n.jsx(b.Controller,{name:`series.${t}.invisible`,control:e,render:({field:o})=>n.jsx(s.Checkbox,{label:l("chart.behavior.invisible"),checked:o.value,onChange:i=>o.onChange(i.currentTarget.checked)})})]})}function u1({control:e,watch:t}){const{t:r}=x.useTranslation(),a=()=>N0(),l=(c,d)=>{const u=c.name.trim();return u||d+1},o=t("x_axes"),i=h.useMemo(()=>o.map(({name:c},d)=>({label:c,value:d.toString()})),[o]);return n.jsx(H,{control:e,watch:t,name:"series",getItem:a,addButtonText:r("chart.series.add"),deleteButtonText:r("chart.series.delete"),renderTabName:l,children:({field:c,index:d})=>n.jsx(d1,{control:e,index:d,seriesItem:c,xAxisOptions:i})})}const p1=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>[{label:o("chart.x_axis.position.top"),value:"top"},{label:o("chart.x_axis.position.bottom"),value:"bottom"}],[i.language]);return n.jsx(s.Select,{ref:l,label:e??o("chart.x_axis.position.label"),data:c,value:t,onChange:Z(r),sx:a})});function h1({control:e,index:t}){const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{my:10,p:"0",sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`x_axes.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`x_axes.${t}.position`,control:e,render:({field:a})=>n.jsx(p1,{sx:{flex:1},...a})})]}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.x_axis.label_format"),labelPosition:"center"}),n.jsx(b.Controller,{name:`x_axes.${t}.label_formatter`,control:e,render:({field:a})=>n.jsx(Le,{...a})})]}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.x_axis.value_range"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`x_axes.${t}.min`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.x_axis.value_min"),...a})}),n.jsx(b.Controller,{name:`x_axes.${t}.max`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.x_axis.value_max"),...a})})]})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:r("chart.x_axis.behavior"),labelPosition:"center"}),n.jsx(b.Controller,{name:`x_axes.${t}.show`,control:e,render:({field:a})=>n.jsx(s.Checkbox,{label:r("chart.x_axis.visible"),checked:a.value,onChange:l=>a.onChange(l.currentTarget.checked)})})]})}function g1({control:e,watch:t}){const{t:r}=x.useTranslation(),a=()=>O0(),l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsx(H,{control:e,watch:t,name:"x_axes",getItem:a,addButtonText:r("chart.x_axis.add"),deleteButtonText:r("chart.x_axis.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(h1,{control:e,index:i})})}function f1({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["y_axis"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(s.Divider,{mb:-15,label:r("chart.axis.tick_label"),variant:"dashed",labelPosition:"center"}),n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(Qe,{...a})})}),n.jsx(b.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(We,{...a})})]})}function b1({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaultsDeep({},r,Nr),[r]),{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=b.useForm({defaultValues:o});return h.useEffect(()=>{p(o)},[o]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:c(a),children:[n.jsx(ae,{canSubmit:u.isDirty}),n.jsxs(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axes",children:t("chart.x_axis.labels")}),n.jsx(s.Tabs.Tab,{value:"Y Axis",children:t("chart.y_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Series",children:t("chart.series.label")}),n.jsx(s.Tabs.Tab,{value:"Reference Lines",children:t("chart.reference_line.labels")})]}),n.jsx(s.Tabs.Panel,{value:"X Axes",children:n.jsx(g1,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Y Axis",children:n.jsx(f1,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Series",children:n.jsx(u1,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Reference Lines",children:n.jsx(i1,{variables:l,control:i,watch:d})})]})]})})}const y1=[{lang:"en",resources:{horizontal_bar_chart:{viz_name:"Horizontal Bar Chart",series:{aggregation:{label:"Aggregation on Value"}}}}},{lang:"zh",resources:{horizontal_bar_chart:{viz_name:"水平方向柱图",series:{aggregation:{label:"聚合数据"}}}}}],v1={id:"builtin:echarts:click-echart:series",displayName:"viz.cartesian_chart.click_series.label",nameRender:x1,configRender:_1,payload:[{name:"seriesType",description:"'line' | 'scatter' | 'bar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function _1(e){return n.jsx(n.Fragment,{})}function x1(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.cartesian_chart.click_series.label")})}function w1(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&!d.includes(`${r}.`)?`${r}.${d}`:d,{x_axes:l,y_axis:o,series:i,...c}=e;return{...c,x_axes:l.map(d=>({...d,data_key:a(d.data_key)})),y_axis:{...o,data_key:a(o.data_key)},series:i.map(d=>({...d,data_key:a(d.data_key),group_by_key:a(d.group_by_key)}))}}catch(r){throw console.error("[Migration failed]",r),r}}function m1(e){const t=e.series.map(r=>({...r,unit:r.unit??U()}));return{...e,series:t}}class C1 extends ee{constructor(){super(...arguments);P(this,"VERSION",3)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,(r,a)=>{const{config:l}=r;return{...r,version:2,config:w1(l,a)}}),this.version(3,r=>{const{config:a}=r;return{...r,version:3,config:m1(a)}})}}const S1={displayName:"viz.horizontal_bar_chart.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new C1,name:"horizontalBarChart",viewRender:l1,configRender:b1,createConfig:()=>({version:3,config:y.cloneDeep(Nr)}),triggers:[v1],translation:y1},Gr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:fe()}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function T1(){return[{top:20,left:30,right:60,height:40,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:70,left:30,right:60,height:100,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:180,left:30,right:60,bottom:130,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{left:30,right:60,bottom:20,height:100,containLabel:!1,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0}]}const _o=({value:e})=>{try{return Y(e[2],{output:"percent",mantissa:0,absolute:!1})}catch(t){return console.error(t),e}};function k1(e,t,r){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:t.map(l=>{const o=r[l].length,d=(y.countBy(r[l],u=>u.level.diff===0).true??0)/o;return[l,"_y",d]}),label:{show:!0,formatter:_o},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:l,value:o})=>`
427
+ `}})}function r1(e){return e.x_axes.reduce((r,{label_formatter:a},l)=>(r[l]=function(i){let c=i;if(typeof i=="object"&&(Array.isArray(i.value)&&i.value.length===2?c=i.value[0]:c=i.value),!a)return c;try{return Y(c,a)}catch(d){return console.error(d),c}},r),{default:({value:r})=>r})}function a1(e,t){const r={};return t.map(a=>{const l=Je(a,e);r[a.name]=$e(a,l)}),r}function s1(e,t){return e.x_axes.map(({min:r,max:a,...l},o)=>{let i=l.position;return i||(i=o>0?"bottom":"top"),X.getYAxis({...l,type:"value",min:r||void 0,max:a||void 0,position:i,axisLabel:{show:!0,margin:2,formatter:t[o]??t.default},nameLocation:"center",nameGap:15})})}function l1(e,t){const r=t.every(i=>!Number.isNaN(Number(i))),{overflow:a,...l}=e.y_axis.axisLabel,o=Fe(a.on_axis);return[X.getXAxis({data:t,name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center"},id:"main-y-axis",type:r?"value":"category",axisLabel:{...l,...o,formatter:ze(l.formatter)},z:5})]}function o1(e,t,r){if(!e.y_axis.data_key)return{};const a=a1(t,r),l=r1(e),o=P(e.y_axis.data_key),i=y.uniq(t[o.queryID].map(p=>p[o.columnKey])),c=i.every(p=>!Number.isNaN(Number(p))),d=e1(e,i,c,t,l,r,a);return{xAxis:s1(e,l),yAxis:l1(e,i),series:d,tooltip:n1(e,d,l),grid:W0(e),legend:K0(e,d)}}function i1({conf:e,data:t,width:r,height:a,interactionManager:l,variables:o,instance:i}){const c=mt(t,e.y_axis.data_key),d=Ie(l.triggerManager,wr.id),u=h.useCallback(w=>{const m=y.get(c,w.name,{error:"rowData is not found"});d.forEach(k=>{l.runInteraction(k.id,{...w,rowData:m})})},[c,d,l]),p=h.useRef(null),f=h.useCallback(()=>{var m;const w=(m=p.current)==null?void 0:m.getEchartsInstance();w&&de(i,w.getOption())},[i]),v=h.useMemo(()=>({click:u,finished:f}),[u]),_=h.useMemo(()=>o1(e,t,o),[e,t]);return n.jsx(he,{echarts:ie,option:_,ref:p,style:{width:r,height:a},onEvents:v,notMerge:!0,theme:"merico-light"})}function c1({context:e,instance:t}){const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},a,Gr),[a]),i=e.data,{width:c,height:d}=e.viewport;return!c||!d?null:n.jsx(_e,{width:c,height:d,children:n.jsx(i1,{instance:t,variables:l,width:Oe(c),height:Ne(d),data:i,conf:o,interactionManager:r})})}function d1({control:e,index:t,watch:r,variableOptions:a,xAxisOptions:l}){const{t:o}=x.useTranslation(),i=r(`reference_lines.${t}.orientation`);return n.jsxs(s.Stack,{my:0,p:0,pt:10,sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:o("common.name"),placeholder:o("chart.reference_line.name_placeholder"),required:!0,sx:{flex:1},...c})}),n.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:c})=>n.jsx(s.Select,{label:o("common.data_field"),required:!0,data:a,sx:{flex:1},...c})})]}),n.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:o("chart.content_template.label"),placeholder:o("chart.content_template.hint"),sx:{flex:1},...c})}),n.jsxs(s.Group,{grow:!0,children:[n.jsxs(s.Stack,{children:[n.jsx(b.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:c})=>n.jsx(gt,{sx:{flex:1},...c})}),i==="vertical"&&n.jsx(s.Text,{mt:-10,c:"dimmed",size:"12px",children:o("chart.reference_line.orientation.vertical_hint")})]}),i==="horizontal"&&n.jsx(b.Controller,{name:`reference_lines.${t}.xAxisIndex`,control:e,render:({field:c})=>n.jsx(s.Select,{label:o("chart.x_axis.label"),data:l,disabled:l.length===0,sx:{flex:1},...c})})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:o("chart.style.label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:c})=>n.jsx(Pt,{sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:c})=>n.jsx(s.NumberInput,{label:o("chart.series.line.line_width"),min:1,max:10,sx:{flexGrow:1},...c})})]}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:c})=>n.jsx(be,{label:o("chart.color.label"),...c})})}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:o("chart.behavior.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:c})=>n.jsx(s.Checkbox,{label:o("chart.legend.show_in_legend"),checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})]})}function u1({control:e,watch:t,variables:r}){const{t:a}=x.useTranslation(),l=()=>Q0(),o=h.useMemo(()=>r.map(u=>({label:u.name,value:u.name})),[r]),i=t("x_axes"),c=h.useMemo(()=>i.map(({name:u},p)=>({label:u,value:p.toString()})),[i]),d=(u,p)=>{const f=u.name.trim();return f||p+1};return n.jsx(H,{control:e,watch:t,name:"reference_lines",getItem:l,addButtonText:a("chart.reference_line.add"),deleteButtonText:a("chart.reference_line.delete"),renderTabName:d,children:({field:u,index:p})=>n.jsx(d1,{control:e,index:p,watch:t,variableOptions:o,xAxisOptions:c})})}function p1({control:e,index:t,seriesItem:r}){const{t:a,i18n:l}=x.useTranslation(),o=!!r.barWidth.trim(),i=h.useMemo(()=>[{label:a("chart.series.bar.bar_gap.no_gap"),value:"0%"},{label:a("chart.series.bar.bar_gap.overlap"),value:"-100%"}],[l.language]);return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${t}.stack`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.stack"),placeholder:a("chart.series.bar.stack_hint"),sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.barGap`,control:e,render:({field:c})=>n.jsx(s.Select,{label:a("chart.series.bar.bar_gap.label"),data:i,sx:{flexGrow:1},...c})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.bar_width.min"),disabled:o,sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.bar_width.exact"),sx:{flexGrow:1},...c})}),n.jsx(b.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:c})=>n.jsx(s.TextInput,{label:a("chart.series.bar.bar_width.max"),disabled:o,sx:{flexGrow:1},...c})})]})]})}function h1({control:e,index:t,seriesItem:r,xAxisOptions:a}){const{t:l}=x.useTranslation();return n.jsxs(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`series.${t}.name`,control:e,render:({field:o})=>n.jsx(s.TextInput,{label:l("common.name"),required:!0,sx:{flex:1},...o})}),n.jsx(b.Controller,{name:`series.${t}.xAxisIndex`,control:e,render:({field:o})=>n.jsx(s.Select,{label:l("chart.x_axis.label"),data:a,disabled:a.length===0,sx:{flex:1},...o})})]}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(b.Controller,{name:`series.${t}.data_key`,control:e,render:({field:o})=>n.jsx(q,{label:l("common.data_field"),required:!0,sx:{flex:1},...o})}),n.jsx(b.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:o})=>n.jsx(kr,{label:l("viz.horizontal_bar_chart.series.aggregation.label"),value:o.value??kt,onChange:o.onChange,pt:0,withFallback:!1})})]}),n.jsx(s.Group,{grow:!0,children:n.jsx(b.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:o})=>n.jsx(q,{label:l("chart.series.group_by.label"),clearable:!0,sx:{flex:1},...o})})}),n.jsx(b.Controller,{name:`series.${t}.unit`,control:e,render:({field:o})=>n.jsx(ue,{...o})}),n.jsx(p1,{index:t,control:e,seriesItem:r}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:l("chart.style.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:`series.${t}.label_position`,control:e,render:({field:o})=>n.jsx(At,{label:l("chart.label_position.label"),...o,withOffOption:!0,onChange:i=>{o.onChange(i??"")}})}),n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(b.Controller,{name:`series.${t}.color`,control:e,render:({field:o})=>n.jsx(be,{label:l("chart.color.label"),...o})})}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:l("chart.behavior.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:o})=>n.jsx(s.Checkbox,{label:l("chart.legend.hide_in_legend"),checked:o.value,onChange:i=>o.onChange(i.currentTarget.checked)})}),n.jsx(b.Controller,{name:`series.${t}.invisible`,control:e,render:({field:o})=>n.jsx(s.Checkbox,{label:l("chart.behavior.invisible"),checked:o.value,onChange:i=>o.onChange(i.currentTarget.checked)})})]})}function g1({control:e,watch:t}){const{t:r}=x.useTranslation(),a=()=>j0(),l=(c,d)=>{const u=c.name.trim();return u||d+1},o=t("x_axes"),i=h.useMemo(()=>o.map(({name:c},d)=>({label:c,value:d.toString()})),[o]);return n.jsx(H,{control:e,watch:t,name:"series",getItem:a,addButtonText:r("chart.series.add"),deleteButtonText:r("chart.series.delete"),renderTabName:l,children:({field:c,index:d})=>n.jsx(h1,{control:e,index:d,seriesItem:c,xAxisOptions:i})})}const f1=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},l)=>{const{t:o,i18n:i}=x.useTranslation(),c=h.useMemo(()=>[{label:o("chart.x_axis.position.top"),value:"top"},{label:o("chart.x_axis.position.bottom"),value:"bottom"}],[i.language]);return n.jsx(s.Select,{ref:l,label:e??o("chart.x_axis.position.label"),data:c,value:t,onChange:Z(r),sx:a})});function b1({control:e,index:t}){const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{my:10,p:"0",sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`x_axes.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`x_axes.${t}.position`,control:e,render:({field:a})=>n.jsx(f1,{sx:{flex:1},...a})})]}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.x_axis.label_format"),labelPosition:"center"}),n.jsx(b.Controller,{name:`x_axes.${t}.label_formatter`,control:e,render:({field:a})=>n.jsx(je,{...a})})]}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.x_axis.value_range"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(b.Controller,{name:`x_axes.${t}.min`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.x_axis.value_min"),...a})}),n.jsx(b.Controller,{name:`x_axes.${t}.max`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.x_axis.value_max"),...a})})]})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:r("chart.x_axis.behavior"),labelPosition:"center"}),n.jsx(b.Controller,{name:`x_axes.${t}.show`,control:e,render:({field:a})=>n.jsx(s.Checkbox,{label:r("chart.x_axis.visible"),checked:a.value,onChange:l=>a.onChange(l.currentTarget.checked)})})]})}function y1({control:e,watch:t}){const{t:r}=x.useTranslation(),a=()=>F0(),l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsx(H,{control:e,watch:t,name:"x_axes",getItem:a,addButtonText:r("chart.x_axis.add"),deleteButtonText:r("chart.x_axis.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(b1,{control:e,index:i})})}function v1({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["y_axis"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(s.Divider,{mb:-15,label:r("chart.axis.tick_label"),variant:"dashed",labelPosition:"center"}),n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(He,{...a})})}),n.jsx(b.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(Re,{...a})})]})}function _1({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaultsDeep({},r,Gr),[r]),{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=b.useForm({defaultValues:o});return h.useEffect(()=>{p(o)},[o]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:c(a),children:[n.jsx(ae,{canSubmit:u.isDirty}),n.jsxs(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axes",children:t("chart.x_axis.labels")}),n.jsx(s.Tabs.Tab,{value:"Y Axis",children:t("chart.y_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Series",children:t("chart.series.label")}),n.jsx(s.Tabs.Tab,{value:"Reference Lines",children:t("chart.reference_line.labels")})]}),n.jsx(s.Tabs.Panel,{value:"X Axes",children:n.jsx(y1,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Y Axis",children:n.jsx(v1,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Series",children:n.jsx(g1,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Reference Lines",children:n.jsx(u1,{variables:l,control:i,watch:d})})]})]})})}const x1=[{lang:"en",resources:{horizontal_bar_chart:{viz_name:"Horizontal Bar Chart",series:{aggregation:{label:"Aggregation on Value"}}}}},{lang:"zh",resources:{horizontal_bar_chart:{viz_name:"水平方向柱图",series:{aggregation:{label:"聚合数据"}}}}}],w1={id:"builtin:echarts:click-echart:series",displayName:"viz.cartesian_chart.click_series.label",nameRender:C1,configRender:m1,payload:[{name:"seriesType",description:"'line' | 'scatter' | 'bar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function m1(e){return n.jsx(n.Fragment,{})}function C1(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.cartesian_chart.click_series.label")})}function S1(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&!d.includes(`${r}.`)?`${r}.${d}`:d,{x_axes:l,y_axis:o,series:i,...c}=e;return{...c,x_axes:l.map(d=>({...d,data_key:a(d.data_key)})),y_axis:{...o,data_key:a(o.data_key)},series:i.map(d=>({...d,data_key:a(d.data_key),group_by_key:a(d.group_by_key)}))}}catch(r){throw console.error("[Migration failed]",r),r}}function T1(e){const t=e.series.map(r=>({...r,unit:r.unit??U()}));return{...e,series:t}}class k1 extends ee{constructor(){super(...arguments);V(this,"VERSION",3)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,(r,a)=>{const{config:l}=r;return{...r,version:2,config:S1(l,a)}}),this.version(3,r=>{const{config:a}=r;return{...r,version:3,config:T1(a)}})}}const z1={displayName:"viz.horizontal_bar_chart.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new k1,name:"horizontalBarChart",viewRender:c1,configRender:_1,createConfig:()=>({version:3,config:y.cloneDeep(Gr)}),triggers:[w1],translation:x1},Fr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:ye()}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function D1(){return[{top:20,left:30,right:60,height:40,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:70,left:30,right:60,height:100,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:180,left:30,right:60,bottom:130,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{left:30,right:60,bottom:20,height:100,containLabel:!1,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0}]}const mo=({value:e})=>{try{return Y(e[2],{output:"percent",mantissa:0,absolute:!1})}catch(t){return console.error(t),e}};function I1(e,t,r){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:t.map(l=>{const o=r[l].length,d=(y.countBy(r[l],u=>u.level.diff===0).true??0)/o;return[l,"_y",d]}),label:{show:!0,formatter:mo},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:l,value:o})=>`
428
428
  <table style="width: auto">
429
429
  <thead>
430
430
  <tr colspan="2">
@@ -442,17 +442,17 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
442
442
  <tbody>
443
443
  <tr>
444
444
  <th style="text-align: right;">准确估算比例</th>
445
- <td style="text-align: left; padding: 0 1em;">${_o({value:o})}</td>
445
+ <td style="text-align: left; padding: 0 1em;">${mo({value:o})}</td>
446
446
  </tr>
447
447
  </tbody>
448
448
  </table>
449
- `},show_in_legend:!1}}function xo(e){const t=[`background-color: ${e}`];return e==="rgba(255, 255, 255, 1)"&&t.push("box-shadow: 0px 0px 1px 0px rgba(0,0,0,.5)"),t.join(";")}function z1([e,t]){const r={x:e,v:`${t}`};try{r.v=Y(t,{output:"number",mantissa:2,trimMantissa:!0,absolute:!1})}catch{}return r}function D1(e,t,r,a){var d,u;const l=t.map(p=>{const f=r[p],v=y.sumBy(f,_=>_.level.diff);return[p,v/f.length]}),o=Number(((d=y.maxBy(l,p=>p[1]))==null?void 0:d[1])??0),i=Number(((u=y.minBy(l,p=>p[1]))==null?void 0:u[1])??0),c=ot.interpolate([o,0,i],["#D15A40","#FFF","#418AAF"]);return{type:"bar",name:"平均偏差",xAxisIndex:1,yAxisIndex:1,...a,data:l,itemStyle:{color:({value:p})=>{try{return c(p[1])}catch{return"#FFF"}}},label:{position:"outside",show:!0,formatter:({value:p})=>{try{return Y(p[1],{output:"number",mantissa:1,trimMantissa:!0,absolute:!1})}catch{return p[1]}}},tooltip:{trigger:"item",formatter:({color:p,value:f})=>{const{x:v,v:_}=z1(f);return`
449
+ `},show_in_legend:!1}}function Co(e){const t=[`background-color: ${e}`];return e==="rgba(255, 255, 255, 1)"&&t.push("box-shadow: 0px 0px 1px 0px rgba(0,0,0,.5)"),t.join(";")}function M1([e,t]){const r={x:e,v:`${t}`};try{r.v=Y(t,{output:"number",mantissa:2,trimMantissa:!0,absolute:!1})}catch{}return r}function V1(e,t,r,a){var d,u;const l=t.map(p=>{const f=r[p],v=y.sumBy(f,_=>_.level.diff);return[p,v/f.length]}),o=Number(((d=y.maxBy(l,p=>p[1]))==null?void 0:d[1])??0),i=Number(((u=y.minBy(l,p=>p[1]))==null?void 0:u[1])??0),c=ot.interpolate([o,0,i],["#D15A40","#FFF","#418AAF"]);return{type:"bar",name:"平均偏差",xAxisIndex:1,yAxisIndex:1,...a,data:l,itemStyle:{color:({value:p})=>{try{return c(p[1])}catch{return"#FFF"}}},label:{position:"outside",show:!0,formatter:({value:p})=>{try{return Y(p[1],{output:"number",mantissa:1,trimMantissa:!0,absolute:!1})}catch{return p[1]}}},tooltip:{trigger:"item",formatter:({color:p,value:f})=>{const{x:v,v:_}=M1(f);return`
450
450
  <table style="width: auto">
451
451
  <thead>
452
452
  <tr colspan="2">
453
453
  <div style="
454
454
  width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
455
- ${xo(p)}
455
+ ${Co(p)}
456
456
  "/>
457
457
  </tr>
458
458
  <tr>
@@ -468,13 +468,13 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
468
468
  </tr>
469
469
  </tbody>
470
470
  </table>
471
- `}},show_in_legend:!1}}function I1([e,t,r,a]){const l={x:e,percentage:`${t}`,count:r,sum:a};try{l.percentage=Y(t,{output:"percent",mantissa:2,trimMantissa:!0,absolute:!1})}catch{}return l}function M1(e,t,r,a){const l={};t.forEach(p=>{const f=y.countBy(r[p],_=>_.level.diff),v=y.sum(Object.values(f));Object.entries(f).forEach(([_,w])=>{l[_]||(l[_]=[]);const m=w/v;l[_].push([p,m,w,v])})});const o=Object.entries(l).map(([p])=>Number(p)).sort((p,f)=>p-f),i=Math.max(...o),c=Math.min(...o),d=ot.interpolate([i,0,c],["#D15A40","#FFF","#418AAF"]);return o.map(p=>({type:"bar",name:p,xAxisIndex:2,yAxisIndex:2,stack:1,...a,color:d(p),data:l[p],tooltip:{trigger:"item",formatter:({color:f,value:v})=>{const{x:_,percentage:w,count:m,sum:k}=I1(v);return`
471
+ `}},show_in_legend:!1}}function P1([e,t,r,a]){const l={x:e,percentage:`${t}`,count:r,sum:a};try{l.percentage=Y(t,{output:"percent",mantissa:2,trimMantissa:!0,absolute:!1})}catch{}return l}function A1(e,t,r,a){const l={};t.forEach(p=>{const f=y.countBy(r[p],_=>_.level.diff),v=y.sum(Object.values(f));Object.entries(f).forEach(([_,w])=>{l[_]||(l[_]=[]);const m=w/v;l[_].push([p,m,w,v])})});const o=Object.entries(l).map(([p])=>Number(p)).sort((p,f)=>p-f),i=Math.max(...o),c=Math.min(...o),d=ot.interpolate([i,0,c],["#D15A40","#FFF","#418AAF"]);return o.map(p=>({type:"bar",name:p,xAxisIndex:2,yAxisIndex:2,stack:1,...a,color:d(p),data:l[p],tooltip:{trigger:"item",formatter:({color:f,value:v})=>{const{x:_,percentage:w,count:m,sum:k}=P1(v);return`
472
472
  <table style="width: auto">
473
473
  <thead>
474
474
  <tr colspan="2">
475
475
  <div style="
476
476
  width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
477
- ${xo(f)}
477
+ ${Co(f)}
478
478
  "
479
479
  />
480
480
  </tr>
@@ -503,7 +503,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
503
503
  </tr>
504
504
  </tbody>
505
505
  </table>
506
- `}},show_in_legend:!0}))}function A1(e,t,r,a){const l=A(t.data_key),o=t.name,i=r.map(c=>{const d=y.sumBy(a[c],l.columnKey);return[c,d]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:i,show_in_legend:!1}}function P1(e,t,r,a){const i={barMinWidth:5,barMaxWidth:20};return[k1(e,r,a),D1(e,r,a,i),...M1(e,r,a,i),A1(e,t,r,a)]}function V1(e,t){const{axisLabel:r}=e.x_axis;return[{data:t,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:t,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...r,formatter:xe(r.formatter)},axisLine:{show:!1}}]}function $1(e){return[{type:"category",name:"准确估算比例",nameRotate:0,nameGap:5,nameLocation:"end",nameTextStyle:{align:"left"},gridIndex:0,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"平均偏差",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:1,boundaryGap:[1,1],axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"数量占比",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:2,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1},min:0,max:1},{type:"value",gridIndex:3,position:"right",splitNumber:3,axisLabel:{show:!0,verticalAlign:"top",showMinLabel:!1,lineHeight:14},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:e.name,nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:3,position:"left",axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}}]}function Fr(e){return e==1||e==2?1:Fr(e-2)+Fr(e-1)}const E1=Array.from(new Array(20),(e,t)=>Fr(t+1));function wo(e){return e<=1?e:E1.findIndex(t=>e<=t)-1}function B1(e,t){const{x_axis:r,deviation:a}=e,l=A(r.data_key),o=A(a.data_keys.estimated_value),i=A(a.data_keys.actual_value);return t[l.queryID].map(c=>{const d=wo(c[o.columnKey]),u=wo(c[i.columnKey]),p=d-u;return{...c,level:{estimated:d,actual:u,diff:p}}})}function L1(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function q1(e){return{show:!0,orient:"vertical",top:"middle",right:0,data:e.filter(r=>r.show_in_legend).reverse().map(r=>({name:`${r.name}`,color:r.color,itemStyle:L1(r.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const O1={tooltip:{trigger:"axis"}};function N1(e,t){const{deviation:r,metrics:a}=e,l=a.find(i=>i.data_key===t);if(l)return l;const o=r.data_keys.actual_value;return{id:o,name:r.name,data_key:o,unit:U()}}function G1(e,t,r){const a=B1(e,r),l=A(e.x_axis.data_key),o=y.uniqBy(r[l.queryID],l.columnKey).map(p=>p[l.columnKey]),i=y.groupBy(a,l.columnKey),c=N1(e,t),d=P1(e,c,o,i),u={xAxis:V1(e,o),yAxis:$1(c),series:d,grid:T1(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:q1(d)};return y.defaultsDeep({},u,O1)}const F1={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},j1=({conf:e,metricKey:t,setMetricKey:r})=>{const{deviation:a,metrics:l}=e,o=h.useMemo(()=>{const i=l.map(c=>({label:c.name,value:c.data_key}));return i.push({label:a.name?a.name:a.data_keys.actual_value,value:a.data_keys.actual_value}),i},[a,l]);return n.jsxs(s.Group,{gap:1,children:[n.jsx(s.Text,{size:"12px",c:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),n.jsx(s.NativeSelect,{size:"xs",data:o,value:t,onChange:i=>r(i.currentTarget.value),styles:F1})]})},Q1={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function W1(){return n.jsxs(s.HoverCard,{width:400,shadow:"md",children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Button,{variant:"subtle",size:"compact-xs",leftSection:n.jsx(S.IconInfoCircle,{size:14}),children:"指标说明"})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(s.Table,{fz:14,sx:Q1,children:n.jsxs(s.Table.Tbody,{children:[n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"估算偏差"}),n.jsx(s.Table.Td,{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"准确估算比例"}),n.jsx(s.Table.Td,{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function U1(e){return n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(W1,{}),n.jsx(j1,{...e})]})}function Y1({conf:e,data:t,width:r,height:a,metricKey:l,instance:o}){const i=h.useMemo(()=>G1(e,l,t),[e,t,l]),c=h.useRef(null),d=h.useCallback(()=>{var f;const p=(f=c.current)==null?void 0:f.getEchartsInstance();p&&de(o,p.getOption())},[o]),u=h.useMemo(()=>({finished:d}),[d]);return n.jsx(he,{ref:c,onEvents:u,echarts:ce,option:i,style:{width:r,height:a},notMerge:!0,theme:"merico-light"})}function K1({context:e,instance:t}){const{value:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaults({},r,Gr),[r]),l=e.data,{width:o,height:i}=e.viewport,{x_axis:c,deviation:d}=a,{estimated_value:u,actual_value:p}=d.data_keys,[f,v]=h.useState(p);if(h.useEffect(()=>{v(m=>m||p)},[p]),!c.data_key||!u||!p||!o||!i)return null;const _=Math.max(Ge(o),300),w=Math.max(Fe(i),370);return n.jsxs(s.Box,{pt:ve.top,pr:ve.right,pb:ve.bottom,pl:ve.left,sx:{overflow:"hidden",height:i,width:o},children:[n.jsx(U1,{conf:a,metricKey:f,setMetricKey:v}),n.jsx(Y1,{instance:t,width:_,height:w-30,data:l,conf:a,metricKey:f})]})}function X1({control:e,watch:t}){return t(["deviation"]),n.jsxs(s.Stack,{children:[n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:"deviation.name",control:e,render:({field:r})=>n.jsx(s.TextInput,{label:"指标名称",sx:{flex:1},...r})})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"deviation.data_keys.estimated_value",control:e,render:({field:r})=>n.jsx(q,{label:"估算值字段",required:!0,sx:{flex:1},...r})}),n.jsx(b.Controller,{name:"deviation.data_keys.actual_value",control:e,render:({field:r})=>n.jsx(q,{label:"实际值字段",required:!0,sx:{flex:1},...r})})]})]})}const Z1=({control:e,index:t})=>{const{t:r}=x.useTranslation();return n.jsx(s.Stack,{children:n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`metrics.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`metrics.${t}.data_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})})]})})},J1=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>({id:Date.now().toString(),data_key:"",name:"",unit:U()}),l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),n.jsx(s.Divider,{variant:"dashed",my:10}),n.jsx(H,{control:e,watch:t,name:"metrics",getItem:a,addButtonText:r("chart.tooltip.additional_metrics.add"),deleteButtonText:r("chart.tooltip.additional_metrics.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(Z1,{control:e,index:i})})]})};function H1({control:e,watch:t}){return t(["x_axis"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:r})=>n.jsx(q,{label:"数据字段",required:!0,sx:{flex:1},...r})}),n.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:r})=>n.jsx(s.TextInput,{label:"X轴名称",sx:{flex:1},...r})})]}),n.jsx(s.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:r})=>n.jsx(nt,{sx:{width:"48%"},...r})}),n.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:r})=>n.jsx(Qe,{...r})})]})]})}function R1({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaultsDeep({},t,Gr),[t]),{control:l,handleSubmit:o,watch:i,formState:c,reset:d}=b.useForm({defaultValues:a});return h.useEffect(()=>{d(a)},[a]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:o(r),children:[n.jsx(ae,{canSubmit:c.isDirty}),n.jsxs(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axis",children:"X轴"}),n.jsx(s.Tabs.Tab,{value:"Deviation",children:"偏差"}),n.jsx(s.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),n.jsx(s.Tabs.Panel,{value:"X Axis",children:n.jsx(H1,{control:l,watch:i})}),n.jsx(s.Tabs.Panel,{value:"Deviation",children:n.jsx(X1,{control:l,watch:i})}),n.jsx(s.Tabs.Panel,{value:"Additional Metrics",children:n.jsx(J1,{control:l,watch:i})})]})]})})}const eC=[{lang:"en",resources:{merico_estimation_chart:{viz_name:"Merico Estimation Chart"}}},{lang:"zh",resources:{merico_estimation_chart:{viz_name:"思码逸估算分析图"}}}];function tC(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{x_axis:l,deviation:o,metrics:i,...c}=e;return{...c,x_axis:{...l,data_key:a(l.data_key)},deviation:{...o,data_keys:{estimated_value:a(o.data_keys.estimated_value),actual_value:a(o.data_keys.actual_value)}},metrics:i.map(d=>({...d,data_key:a(d.data_key)}))}}catch(r){throw console.error("[Migration failed]",r),r}}function nC(e){const t=e.metrics;return{...e,metrics:t.map(r=>({...r,unit:r.unit??U()}))}}class rC extends ee{constructor(){super(...arguments);P(this,"VERSION",3)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,(r,a)=>{const{config:l}=r;return{...r,version:2,config:tC(l,a)}}),this.version(3,r=>{const{config:a}=r;return{...r,version:3,config:nC(a)}})}}const aC={displayName:"viz.merico_estimation_chart.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new rC,name:"mericoEstimationChart",viewRender:K1,configRender:R1,createConfig:()=>({version:3,config:Gr}),translation:eC},jr={styles:{justify:"space-around",align:"start"},metrics:[]};function sC(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:le,postfix:{type:"text",value:""}}}const mo=({postfix:e})=>e?n.jsxs(n.Fragment,{children:[n.jsx(s.Text,{size:"12px",c:"#818388",sx:{lineHeight:1},children:"/"}),n.jsx(s.Text,{size:"12px",c:"#818388",sx:{lineHeight:1},children:e})]}):null,lC=T.observer(({metric:e,variableValueMap:t})=>{const{names:r,data_keys:a,formatter:l,postfix:o}=e,i=J(),c=h.useMemo(()=>{if(o.type==="text"&&o.value)return o.value;if(o.type==="filter-option-label"&&o.value){const d=i.filters.getSelectOption(o.value);return d?d.label:null}return null},[o,i]);return n.jsxs(s.Stack,{gap:18,children:[n.jsxs(s.Stack,{gap:12,children:[n.jsx(s.Text,{size:"14px",c:"#818388",children:r.value}),n.jsxs(s.Group,{gap:"2px",align:"baseline",children:[n.jsx(s.Text,{size:"24px",fw:"bold",c:"#3D3E45",sx:{lineHeight:1},children:Y(t[a.value],l)}),n.jsx(mo,{postfix:c})]})]}),n.jsxs(s.Stack,{gap:12,children:[n.jsx(s.Text,{size:"14px",c:"#818388",children:r.basis}),n.jsxs(s.Group,{gap:"2px",align:"baseline",children:[n.jsx(s.Text,{size:"12px",c:"#3D3E45",sx:{lineHeight:1},children:Y(t[a.basis],l)}),n.jsx(mo,{postfix:c})]})]})]})}),oC=T.observer(({context:e,instance:t})=>{const{value:r}=B(e.instanceData,"config"),{variables:a}=e,l=h.useMemo(()=>y.defaults({},r,jr),[r]),o=e.data,i=h.useMemo(()=>Cr(o,a),[a,o]),{width:c,height:d}=e.viewport;return!c||!d||!l?null:n.jsx(s.Flex,{w:`${c}px`,h:`${d}px`,justify:l.styles.justify,align:l.styles.align,direction:"row",wrap:"nowrap",sx:{overflow:"hidden"},children:l.metrics.map(u=>n.jsx(lC,{metric:u,variableValueMap:i},u.id))})}),iC=T.observer(h.forwardRef(({value:e,onChange:t},r)=>{const{t:a,i18n:l}=x.useTranslation(),i=F().filters.selects,c=p=>{if(!p)return;t({type:p,value:e.value})},d=p=>{if(p===null)return p;t({type:e.type,value:p})},u=h.useMemo(()=>[{label:a("viz.merico_stats.metric.postfix_type.text"),value:"text"},{label:a("viz.merico_stats.metric.postfix_type.filter"),value:"filter-option-label"}],[l.language]);return n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(s.Select,{label:a("viz.merico_stats.metric.postfix_type.label"),data:u,value:e.type,onChange:c}),e.type==="text"&&n.jsx(s.TextInput,{label:a("viz.merico_stats.metric.postfix_content"),value:e.value,onChange:p=>{d(p.currentTarget.value)}}),e.type==="filter-option-label"&&n.jsx(s.Select,{label:a("viz.merico_stats.metric.postfix_filter"),value:e.value,onChange:d,data:i})]})}));function cC({control:e,index:t,watch:r,variableOptions:a}){const{t:l}=x.useTranslation();return r(`metrics.${t}.postfix`),n.jsxs(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`metrics.${t}.names.value`,control:e,render:({field:o})=>n.jsx(s.TextInput,{label:l("viz.merico_stats.metric.metric_name"),required:!0,sx:{flex:1},...o})}),n.jsx(b.Controller,{name:`metrics.${t}.data_keys.value`,control:e,render:({field:o})=>n.jsx(s.Select,{label:l("viz.merico_stats.metric.metric_data_field"),required:!0,data:a,sx:{flex:1},...o})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`metrics.${t}.names.basis`,control:e,render:({field:o})=>n.jsx(s.TextInput,{label:l("viz.merico_stats.metric.basis_name"),required:!0,sx:{flex:1},...o})}),n.jsx(b.Controller,{name:`metrics.${t}.data_keys.basis`,control:e,render:({field:o})=>n.jsx(s.Select,{label:l("viz.merico_stats.metric.basis_data_field"),required:!0,data:a,sx:{flex:1},...o})})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:l("numbro.format.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:`metrics.${t}.formatter`,control:e,render:({field:o})=>n.jsx(Le,{...o})}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:l("viz.merico_stats.metric.others"),labelPosition:"center"}),n.jsx(b.Controller,{name:`metrics.${t}.postfix`,control:e,render:({field:o})=>n.jsx(iC,{...o})})]})}const dC=({control:e,watch:t,variables:r})=>{const{t:a}=x.useTranslation(),l=()=>sC(),o=(d,u)=>{const p=d.names.value.trim();return p||u+1},i=({field:d,index:u,fields:p})=>p.length<=1,c=h.useMemo(()=>r.map(d=>({label:d.name,value:d.name})),[r]);return n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{mt:15,variant:"dashed",label:a("viz.merico_stats.metric.labels"),labelPosition:"center"}),n.jsx(H,{control:e,watch:t,name:"metrics",getItem:l,addButtonText:a("chart.tooltip.additional_metrics.add"),deleteButtonText:a("chart.tooltip.additional_metrics.delete"),renderTabName:o,deleteDisalbed:i,children:({field:d,index:u})=>n.jsx(cC,{control:e,index:u,variableOptions:c,watch:t})})]})};function uC({control:e,watch:t}){const{t:r}=x.useTranslation();return t("styles"),n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{mt:15,variant:"dashed",label:r("style.label"),labelPosition:"center"}),n.jsxs(s.Group,{children:[n.jsx(b.Controller,{name:"styles.justify",control:e,render:({field:a})=>n.jsx(gg,{sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"styles.align",control:e,render:({field:a})=>n.jsx(fg,{label:r("viz.merico_stats.align_items.label"),sx:{flex:1},...a})})]})]})}function pC({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),{variables:a}=e,l=h.useMemo(()=>y.defaultsDeep({},t,jr),[t]),{control:o,handleSubmit:i,watch:c,formState:d,reset:u}=b.useForm({defaultValues:l});return h.useEffect(()=>{u(l)},[l]),n.jsx("form",{onSubmit:i(r),children:n.jsxs(s.Stack,{gap:"xs",children:[n.jsx(ae,{canSubmit:d.isDirty}),n.jsx(uC,{control:o,watch:c}),n.jsx(dC,{control:o,watch:c,variables:a})]})})}function hC(e){const{metrics:t,...r}=e;return{...r,metrics:t.map(a=>({...a,postfix:a.postfix??{type:"text",value:""}}))}}const gC=[{lang:"en",resources:{merico_stats:{viz_name:"Merico Stats",align_items:{label:"Vertical Align"},metric:{labels:"Metrics",metric_name:"Metric Name",metric_data_field:"Metric Data Field",basis_name:"Basis Name",basis_data_field:"Basis Data Field",others:"Others",postfix_type:{label:"Postfix Type",text:"Text",filter:"Filter Option Label"},postfix_content:"Postfix Content",postfix_filter:"Postfix Filter"}}}},{lang:"zh",resources:{merico_stats:{viz_name:"思码逸数据指标",align_items:{label:"垂直对齐方式"},metric:{labels:"指标",metric_name:"指标名称",metric_data_field:"指标数据字段",basis_name:"基准名",basis_data_field:"基准数据字段",others:"其他",postfix_type:{label:"后缀类型",text:"文本",filter:"筛选器选项文案"},postfix_content:"后缀文案",postfix_filter:"筛选器"}}}}];class fC extends ee{constructor(){super(...arguments);P(this,"VERSION",2)}configVersions(){this.version(1,r=>({...r,version:1,config:r.config})),this.version(2,r=>({...r,version:2,config:hC(r.config)}))}}const bC={displayName:"viz.merico_stats.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new fC,name:"merico-stats",viewRender:oC,configRender:pC,createConfig:()=>({version:2,config:jr}),translation:gC},Qr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:we(),formatter:fe()}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:we(),formatter:fe()}},heat_block:{name:"Value",data_key:"",unit:U(),value_formatter:le,label:{show:!1,fontSize:10}},tooltip:{metrics:[]},visualMap:et()};function yC({control:e,watch:t}){const{t:r}=x.useTranslation();t(["heat_block"]);const a=t("heat_block.label.show");return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"heat_block.data_key",control:e,render:({field:l})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...l})}),n.jsx(b.Controller,{name:"heat_block.name",control:e,render:({field:l})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...l})})]}),n.jsx(b.Controller,{name:"heat_block.unit",control:e,render:({field:l})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...l})}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("numbro.format.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"heat_block.value_formatter",control:e,render:({field:l})=>n.jsx(Le,{...l})}),n.jsx(s.Divider,{mb:-5,variant:"dashed",label:r("chart.label.label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"heat_block.label.show",control:e,render:({field:l})=>n.jsx(s.Switch,{label:r("chart.heatmap.heatblock.show_label"),checked:l.value,onChange:o=>l.onChange(o.currentTarget.checked),sx:{flexGrow:1}})}),n.jsx(b.Controller,{name:"heat_block.label.fontSize",control:e,render:({field:l})=>n.jsx(s.NumberInput,{size:"xs",leftSection:n.jsx(S.IconTextSize,{size:16}),disabled:!a,...l})})]})]})}const vC=({control:e,index:t})=>{const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.unit`,control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})})]})},_C=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>({id:Date.now().toString(),data_key:"",name:"",unit:U()}),l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:r("chart.tooltip.additional_metrics.description")})]}),n.jsx(s.Divider,{variant:"dashed",my:10}),n.jsx(H,{control:e,watch:t,name:"tooltip.metrics",getItem:a,addButtonText:r("chart.tooltip.additional_metrics.add"),deleteButtonText:r("chart.tooltip.additional_metrics.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(vC,{control:e,index:i})})]})};function xC({control:e,watch:t}){return n.jsx(_C,{control:e,watch:t})}function wC({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["x_axis"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(We,{...a})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:a})=>n.jsx(nt,{sx:{width:"48%"},...a})}),n.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(Qe,{...a})})]})]})}function mC({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["y_axis"]),n.jsxs(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})})]}),n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:"y_axis.nameAlignment",control:e,render:({field:a})=>n.jsx(ft,{sx:{flex:1},...a})})}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(We,{...a})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"y_axis.axisLabel.rotate",control:e,render:({field:a})=>n.jsx(nt,{sx:{width:"48%"},...a})}),n.jsx(b.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(Qe,{...a})})]})]})}function CC({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),l=h.useMemo(()=>r?y.defaults({},r):Qr,[r]),o=h.useMemo(()=>y.cloneDeep(l),[l]);h.useEffect(()=>{!y.isEqual(l,o)&&(console.log("config malformed, resetting to defaults",l,o),a(o))},[l,o]);const i=b.useForm({defaultValues:o}),{control:c,handleSubmit:d,watch:u,formState:p,reset:f}=i;return h.useEffect(()=>{f(o)},[o]),n.jsx("form",{onSubmit:d(a),style:{flexGrow:1},children:n.jsxs(s.Stack,{gap:"xs",sx:{height:"100%"},children:[n.jsx(ae,{canSubmit:p.isDirty}),n.jsxs(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{root:{flexGrow:1},tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axis",children:t("chart.x_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Y Axis",children:t("chart.y_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Heat Block",children:t("chart.heatmap.heatblock.label")}),n.jsx(s.Tabs.Tab,{value:"Visual Map",children:t("chart.visual_map.label")}),n.jsx(s.Tabs.Tab,{value:"Tooltip",children:t("chart.tooltip.label")})]}),n.jsx(s.Tabs.Panel,{value:"X Axis",children:n.jsx(wC,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Y Axis",children:n.jsx(mC,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Heat Block",children:n.jsx(yC,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Visual Map",children:n.jsx(Dr,{form:i})}),n.jsx(s.Tabs.Panel,{value:"Tooltip",children:n.jsx(xC,{control:c,watch:u})})]})]})})}function SC(e){return n.jsx(n.Fragment,{})}function TC(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.merico_heatmap.click_heatmap.heatblock.label")})}const Co={id:"builtin:echarts:click-heatmap:heat-block",displayName:"viz.merico_heatmap.click_heatmap.heatblock.label",nameRender:TC,configRender:SC,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function kC(e){const t=xe(e.x_axis.axisLabel.formatter),r=xe(e.y_axis.axisLabel.formatter);return{x_axis:t,y_axis:r}}function zC(e){return{heat_block:function(a){if(!e.heat_block.value_formatter)return a;try{return Y(a,e.heat_block.value_formatter)}catch(l){return console.error(l),a}}}}function DC(e){let t=0;return e.x_axis.name&&(t+=20),{top:45,left:5,right:5,bottom:t,containLabel:!0,borderColor:"none",backgroundColor:"#E7E7E9",z:1}}function IC(e,t){const{heat_block:r}=e;return{type:"heatmap",name:r.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderWidth:0},data:t,label:r.label,labelLayout:{hideOverlap:!0},z:2}}const MC=e=>Y(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function AC({conf:e,labelFormatters:t,valueFormatters:r,dataDict:a,params:l,metricUnitMap:o}){const{value:i,dataIndex:c}=l,[d,u,p]=i,f={label:e.x_axis.name?e.x_axis.name:"X Axis",value:t.x_axis(d,c),style:{label:"",value:Ee(e.x_axis.axisLabel.overflow.in_tooltip)},unit:""},v={label:e.y_axis.name?e.y_axis.name:"Y Axis",value:t.y_axis(u,c),style:{label:"",value:Ee(e.y_axis.axisLabel.overflow.in_tooltip)},unit:""},_={label:e.heat_block.name,value:r.heat_block(p),style:{label:"",value:""},unit:e.heat_block.unit.show_in_tooltip?e.heat_block.unit.text:""},w=[f,v,_],m=a[`${d}---${u}`];return m&&e.tooltip.metrics.forEach(k=>{const z=A(k.data_key),D=o[k.name];w.push({label:k.name,value:MC(y.get(m,z.columnKey,"")),style:{label:"",value:""},unit:D})}),w}function PC(e,t,r,a){const{x_axis:l,y_axis:o,heat_block:i}=e,c=A(l.data_key),d=A(o.data_key);A(i.data_key);const u=y.keyBy(t[c.queryID],f=>`${f[c.columnKey]}---${f[d.columnKey]}`),p=e.tooltip.metrics.reduce((f,{unit:v,name:_})=>(v.show_in_tooltip&&(f[_]=v.text),f),{});return X.getTooltip({formatter:function(f){const _=AC({conf:e,labelFormatters:r,valueFormatters:a,dataDict:u,params:f,metricUnitMap:p}).map(m=>`
506
+ `}},show_in_legend:!0}))}function $1(e,t,r,a){const l=P(t.data_key),o=t.name,i=r.map(c=>{const d=y.sumBy(a[c],l.columnKey);return[c,d]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:i,show_in_legend:!1}}function E1(e,t,r,a){const i={barMinWidth:5,barMaxWidth:20};return[I1(e,r,a),V1(e,r,a,i),...A1(e,r,a,i),$1(e,t,r,a)]}function B1(e,t){const{axisLabel:r}=e.x_axis;return[{data:t,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:t,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...r,formatter:ze(r.formatter)},axisLine:{show:!1}}]}function L1(e){return[{type:"category",name:"准确估算比例",nameRotate:0,nameGap:5,nameLocation:"end",nameTextStyle:{align:"left"},gridIndex:0,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"平均偏差",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:1,boundaryGap:[1,1],axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"数量占比",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:2,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1},min:0,max:1},{type:"value",gridIndex:3,position:"right",splitNumber:3,axisLabel:{show:!0,verticalAlign:"top",showMinLabel:!1,lineHeight:14},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:e.name,nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:3,position:"left",axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}}]}function jr(e){return e==1||e==2?1:jr(e-2)+jr(e-1)}const q1=Array.from(new Array(20),(e,t)=>jr(t+1));function So(e){return e<=1?e:q1.findIndex(t=>e<=t)-1}function O1(e,t){const{x_axis:r,deviation:a}=e,l=P(r.data_key),o=P(a.data_keys.estimated_value),i=P(a.data_keys.actual_value);return t[l.queryID].map(c=>{const d=So(c[o.columnKey]),u=So(c[i.columnKey]),p=d-u;return{...c,level:{estimated:d,actual:u,diff:p}}})}function N1(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function G1(e){return{show:!0,orient:"vertical",top:"middle",right:0,data:e.filter(r=>r.show_in_legend).reverse().map(r=>({name:`${r.name}`,color:r.color,itemStyle:N1(r.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const F1={tooltip:{trigger:"axis"}};function j1(e,t){const{deviation:r,metrics:a}=e,l=a.find(i=>i.data_key===t);if(l)return l;const o=r.data_keys.actual_value;return{id:o,name:r.name,data_key:o,unit:U()}}function Q1(e,t,r){const a=O1(e,r),l=P(e.x_axis.data_key),o=y.uniqBy(r[l.queryID],l.columnKey).map(p=>p[l.columnKey]),i=y.groupBy(a,l.columnKey),c=j1(e,t),d=E1(e,c,o,i),u={xAxis:B1(e,o),yAxis:L1(c),series:d,grid:D1(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:G1(d)};return y.defaultsDeep({},u,F1)}const W1={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},U1=({conf:e,metricKey:t,setMetricKey:r})=>{const{deviation:a,metrics:l}=e,o=h.useMemo(()=>{const i=l.map(c=>({label:c.name,value:c.data_key}));return i.push({label:a.name?a.name:a.data_keys.actual_value,value:a.data_keys.actual_value}),i},[a,l]);return n.jsxs(s.Group,{gap:1,children:[n.jsx(s.Text,{size:"12px",c:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),n.jsx(s.NativeSelect,{size:"xs",data:o,value:t,onChange:i=>r(i.currentTarget.value),styles:W1})]})},K1={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Y1(){return n.jsxs(s.HoverCard,{width:400,shadow:"md",children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Button,{variant:"subtle",size:"compact-xs",leftSection:n.jsx(S.IconInfoCircle,{size:14}),children:"指标说明"})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(s.Table,{fz:14,sx:K1,children:n.jsxs(s.Table.Tbody,{children:[n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"估算偏差"}),n.jsx(s.Table.Td,{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"准确估算比例"}),n.jsx(s.Table.Td,{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function X1(e){return n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(Y1,{}),n.jsx(U1,{...e})]})}function Z1({conf:e,data:t,width:r,height:a,metricKey:l,instance:o}){const i=h.useMemo(()=>Q1(e,l,t),[e,t,l]),c=h.useRef(null),d=h.useCallback(()=>{var f;const p=(f=c.current)==null?void 0:f.getEchartsInstance();p&&de(o,p.getOption())},[o]),u=h.useMemo(()=>({finished:d}),[d]);return n.jsx(he,{ref:c,onEvents:u,echarts:ie,option:i,style:{width:r,height:a},notMerge:!0,theme:"merico-light"})}function J1({context:e,instance:t}){const{value:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaults({},r,Fr),[r]),l=e.data,{width:o,height:i}=e.viewport,{x_axis:c,deviation:d}=a,{estimated_value:u,actual_value:p}=d.data_keys,[f,v]=h.useState(p);if(h.useEffect(()=>{v(m=>m||p)},[p]),!c.data_key||!u||!p||!o||!i)return null;const _=Math.max(Oe(o),300),w=Math.max(Ne(i),370);return n.jsxs(s.Box,{pt:ve.top,pr:ve.right,pb:ve.bottom,pl:ve.left,sx:{overflow:"hidden",height:i,width:o},children:[n.jsx(X1,{conf:a,metricKey:f,setMetricKey:v}),n.jsx(Z1,{instance:t,width:_,height:w-30,data:l,conf:a,metricKey:f})]})}function H1({control:e,watch:t}){return t(["deviation"]),n.jsxs(s.Stack,{children:[n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:"deviation.name",control:e,render:({field:r})=>n.jsx(s.TextInput,{label:"指标名称",sx:{flex:1},...r})})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"deviation.data_keys.estimated_value",control:e,render:({field:r})=>n.jsx(q,{label:"估算值字段",required:!0,sx:{flex:1},...r})}),n.jsx(b.Controller,{name:"deviation.data_keys.actual_value",control:e,render:({field:r})=>n.jsx(q,{label:"实际值字段",required:!0,sx:{flex:1},...r})})]})]})}const R1=({control:e,index:t})=>{const{t:r}=x.useTranslation();return n.jsx(s.Stack,{children:n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`metrics.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`metrics.${t}.data_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})})]})})},eC=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>({id:Date.now().toString(),data_key:"",name:"",unit:U()}),l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),n.jsx(s.Divider,{variant:"dashed",my:10}),n.jsx(H,{control:e,watch:t,name:"metrics",getItem:a,addButtonText:r("chart.tooltip.additional_metrics.add"),deleteButtonText:r("chart.tooltip.additional_metrics.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(R1,{control:e,index:i})})]})};function tC({control:e,watch:t}){return t(["x_axis"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:r})=>n.jsx(q,{label:"数据字段",required:!0,sx:{flex:1},...r})}),n.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:r})=>n.jsx(s.TextInput,{label:"X轴名称",sx:{flex:1},...r})})]}),n.jsx(s.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:r})=>n.jsx(nt,{sx:{width:"48%"},...r})}),n.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:r})=>n.jsx(He,{...r})})]})]})}function nC({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaultsDeep({},t,Fr),[t]),{control:l,handleSubmit:o,watch:i,formState:c,reset:d}=b.useForm({defaultValues:a});return h.useEffect(()=>{d(a)},[a]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:o(r),children:[n.jsx(ae,{canSubmit:c.isDirty}),n.jsxs(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axis",children:"X轴"}),n.jsx(s.Tabs.Tab,{value:"Deviation",children:"偏差"}),n.jsx(s.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),n.jsx(s.Tabs.Panel,{value:"X Axis",children:n.jsx(tC,{control:l,watch:i})}),n.jsx(s.Tabs.Panel,{value:"Deviation",children:n.jsx(H1,{control:l,watch:i})}),n.jsx(s.Tabs.Panel,{value:"Additional Metrics",children:n.jsx(eC,{control:l,watch:i})})]})]})})}const rC=[{lang:"en",resources:{merico_estimation_chart:{viz_name:"Merico Estimation Chart"}}},{lang:"zh",resources:{merico_estimation_chart:{viz_name:"思码逸估算分析图"}}}];function aC(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{x_axis:l,deviation:o,metrics:i,...c}=e;return{...c,x_axis:{...l,data_key:a(l.data_key)},deviation:{...o,data_keys:{estimated_value:a(o.data_keys.estimated_value),actual_value:a(o.data_keys.actual_value)}},metrics:i.map(d=>({...d,data_key:a(d.data_key)}))}}catch(r){throw console.error("[Migration failed]",r),r}}function sC(e){const t=e.metrics;return{...e,metrics:t.map(r=>({...r,unit:r.unit??U()}))}}class lC extends ee{constructor(){super(...arguments);V(this,"VERSION",3)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,(r,a)=>{const{config:l}=r;return{...r,version:2,config:aC(l,a)}}),this.version(3,r=>{const{config:a}=r;return{...r,version:3,config:sC(a)}})}}const oC={displayName:"viz.merico_estimation_chart.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new lC,name:"mericoEstimationChart",viewRender:J1,configRender:nC,createConfig:()=>({version:3,config:Fr}),translation:rC},Qr={styles:{justify:"space-around",align:"start"},metrics:[]};function iC(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:ce,postfix:{type:"text",value:""}}}const To=({postfix:e})=>e?n.jsxs(n.Fragment,{children:[n.jsx(s.Text,{size:"12px",c:"#818388",sx:{lineHeight:1},children:"/"}),n.jsx(s.Text,{size:"12px",c:"#818388",sx:{lineHeight:1},children:e})]}):null,cC=T.observer(({metric:e,variableValueMap:t})=>{const{names:r,data_keys:a,formatter:l,postfix:o}=e,i=J(),c=h.useMemo(()=>{if(o.type==="text"&&o.value)return o.value;if(o.type==="filter-option-label"&&o.value){const d=i.filters.getSelectOption(o.value);return d?d.label:null}return null},[o,i]);return n.jsxs(s.Stack,{gap:18,children:[n.jsxs(s.Stack,{gap:12,children:[n.jsx(s.Text,{size:"14px",c:"#818388",children:r.value}),n.jsxs(s.Group,{gap:"2px",align:"baseline",children:[n.jsx(s.Text,{size:"24px",fw:"bold",c:"#3D3E45",sx:{lineHeight:1},children:Y(t[a.value],l)}),n.jsx(To,{postfix:c})]})]}),n.jsxs(s.Stack,{gap:12,children:[n.jsx(s.Text,{size:"14px",c:"#818388",children:r.basis}),n.jsxs(s.Group,{gap:"2px",align:"baseline",children:[n.jsx(s.Text,{size:"12px",c:"#3D3E45",sx:{lineHeight:1},children:Y(t[a.basis],l)}),n.jsx(To,{postfix:c})]})]})]})}),dC=T.observer(({context:e,instance:t})=>{const{value:r}=B(e.instanceData,"config"),{variables:a}=e,l=h.useMemo(()=>y.defaults({},r,Qr),[r]),o=e.data,i=h.useMemo(()=>Cr(o,a),[a,o]),{width:c,height:d}=e.viewport;return!c||!d||!l?null:n.jsx(s.Flex,{w:`${c}px`,h:`${d}px`,justify:l.styles.justify,align:l.styles.align,direction:"row",wrap:"nowrap",sx:{overflow:"hidden"},children:l.metrics.map(u=>n.jsx(cC,{metric:u,variableValueMap:i},u.id))})}),uC=T.observer(h.forwardRef(({value:e,onChange:t},r)=>{const{t:a,i18n:l}=x.useTranslation(),i=F().filters.selects,c=p=>{if(!p)return;t({type:p,value:e.value})},d=p=>{if(p===null)return p;t({type:e.type,value:p})},u=h.useMemo(()=>[{label:a("viz.merico_stats.metric.postfix_type.text"),value:"text"},{label:a("viz.merico_stats.metric.postfix_type.filter"),value:"filter-option-label"}],[l.language]);return n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(s.Select,{label:a("viz.merico_stats.metric.postfix_type.label"),data:u,value:e.type,onChange:c}),e.type==="text"&&n.jsx(s.TextInput,{label:a("viz.merico_stats.metric.postfix_content"),value:e.value,onChange:p=>{d(p.currentTarget.value)}}),e.type==="filter-option-label"&&n.jsx(s.Select,{label:a("viz.merico_stats.metric.postfix_filter"),value:e.value,onChange:d,data:i})]})}));function pC({control:e,index:t,watch:r,variableOptions:a}){const{t:l}=x.useTranslation();return r(`metrics.${t}.postfix`),n.jsxs(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`metrics.${t}.names.value`,control:e,render:({field:o})=>n.jsx(s.TextInput,{label:l("viz.merico_stats.metric.metric_name"),required:!0,sx:{flex:1},...o})}),n.jsx(b.Controller,{name:`metrics.${t}.data_keys.value`,control:e,render:({field:o})=>n.jsx(s.Select,{label:l("viz.merico_stats.metric.metric_data_field"),required:!0,data:a,sx:{flex:1},...o})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`metrics.${t}.names.basis`,control:e,render:({field:o})=>n.jsx(s.TextInput,{label:l("viz.merico_stats.metric.basis_name"),required:!0,sx:{flex:1},...o})}),n.jsx(b.Controller,{name:`metrics.${t}.data_keys.basis`,control:e,render:({field:o})=>n.jsx(s.Select,{label:l("viz.merico_stats.metric.basis_data_field"),required:!0,data:a,sx:{flex:1},...o})})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:l("numbro.format.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:`metrics.${t}.formatter`,control:e,render:({field:o})=>n.jsx(je,{...o})}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:l("viz.merico_stats.metric.others"),labelPosition:"center"}),n.jsx(b.Controller,{name:`metrics.${t}.postfix`,control:e,render:({field:o})=>n.jsx(uC,{...o})})]})}const hC=({control:e,watch:t,variables:r})=>{const{t:a}=x.useTranslation(),l=()=>iC(),o=(d,u)=>{const p=d.names.value.trim();return p||u+1},i=({field:d,index:u,fields:p})=>p.length<=1,c=h.useMemo(()=>r.map(d=>({label:d.name,value:d.name})),[r]);return n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{mt:15,variant:"dashed",label:a("viz.merico_stats.metric.labels"),labelPosition:"center"}),n.jsx(H,{control:e,watch:t,name:"metrics",getItem:l,addButtonText:a("chart.tooltip.additional_metrics.add"),deleteButtonText:a("chart.tooltip.additional_metrics.delete"),renderTabName:o,deleteDisalbed:i,children:({field:d,index:u})=>n.jsx(pC,{control:e,index:u,variableOptions:c,watch:t})})]})};function gC({control:e,watch:t}){const{t:r}=x.useTranslation();return t("styles"),n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{mt:15,variant:"dashed",label:r("style.label"),labelPosition:"center"}),n.jsxs(s.Group,{children:[n.jsx(b.Controller,{name:"styles.justify",control:e,render:({field:a})=>n.jsx(yg,{sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"styles.align",control:e,render:({field:a})=>n.jsx(vg,{label:r("viz.merico_stats.align_items.label"),sx:{flex:1},...a})})]})]})}function fC({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),{variables:a}=e,l=h.useMemo(()=>y.defaultsDeep({},t,Qr),[t]),{control:o,handleSubmit:i,watch:c,formState:d,reset:u}=b.useForm({defaultValues:l});return h.useEffect(()=>{u(l)},[l]),n.jsx("form",{onSubmit:i(r),children:n.jsxs(s.Stack,{gap:"xs",children:[n.jsx(ae,{canSubmit:d.isDirty}),n.jsx(gC,{control:o,watch:c}),n.jsx(hC,{control:o,watch:c,variables:a})]})})}function bC(e){const{metrics:t,...r}=e;return{...r,metrics:t.map(a=>({...a,postfix:a.postfix??{type:"text",value:""}}))}}const yC=[{lang:"en",resources:{merico_stats:{viz_name:"Merico Stats",align_items:{label:"Vertical Align"},metric:{labels:"Metrics",metric_name:"Metric Name",metric_data_field:"Metric Data Field",basis_name:"Basis Name",basis_data_field:"Basis Data Field",others:"Others",postfix_type:{label:"Postfix Type",text:"Text",filter:"Filter Option Label"},postfix_content:"Postfix Content",postfix_filter:"Postfix Filter"}}}},{lang:"zh",resources:{merico_stats:{viz_name:"思码逸数据指标",align_items:{label:"垂直对齐方式"},metric:{labels:"指标",metric_name:"指标名称",metric_data_field:"指标数据字段",basis_name:"基准名",basis_data_field:"基准数据字段",others:"其他",postfix_type:{label:"后缀类型",text:"文本",filter:"筛选器选项文案"},postfix_content:"后缀文案",postfix_filter:"筛选器"}}}}];class vC extends ee{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,r=>({...r,version:1,config:r.config})),this.version(2,r=>({...r,version:2,config:bC(r.config)}))}}const _C={displayName:"viz.merico_stats.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new vC,name:"merico-stats",viewRender:dC,configRender:fC,createConfig:()=>({version:2,config:Qr}),translation:yC},Wr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:De(),formatter:ye()}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:De(),formatter:ye()}},heat_block:{name:"Value",data_key:"",unit:U(),value_formatter:ce,label:{show:!1,fontSize:10}},tooltip:{metrics:[]},visualMap:et()};function xC({control:e,watch:t}){const{t:r}=x.useTranslation();t(["heat_block"]);const a=t("heat_block.label.show");return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"heat_block.data_key",control:e,render:({field:l})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...l})}),n.jsx(b.Controller,{name:"heat_block.name",control:e,render:({field:l})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...l})})]}),n.jsx(b.Controller,{name:"heat_block.unit",control:e,render:({field:l})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...l})}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("numbro.format.label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"heat_block.value_formatter",control:e,render:({field:l})=>n.jsx(je,{...l})}),n.jsx(s.Divider,{mb:-5,variant:"dashed",label:r("chart.label.label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"heat_block.label.show",control:e,render:({field:l})=>n.jsx(s.Switch,{label:r("chart.heatmap.heatblock.show_label"),checked:l.value,onChange:o=>l.onChange(o.currentTarget.checked),sx:{flexGrow:1}})}),n.jsx(b.Controller,{name:"heat_block.label.fontSize",control:e,render:({field:l})=>n.jsx(s.NumberInput,{size:"xs",leftSection:n.jsx(S.IconTextSize,{size:16}),disabled:!a,...l})})]})]})}const wC=({control:e,index:t})=>{const{t:r}=x.useTranslation();return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(b.Controller,{name:`tooltip.metrics.${t}.unit`,control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})})]})},mC=({control:e,watch:t})=>{const{t:r}=x.useTranslation(),a=()=>({id:Date.now().toString(),data_key:"",name:"",unit:U()}),l=(o,i)=>{const c=o.name.trim();return c||i+1};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:r("chart.tooltip.additional_metrics.description")})]}),n.jsx(s.Divider,{variant:"dashed",my:10}),n.jsx(H,{control:e,watch:t,name:"tooltip.metrics",getItem:a,addButtonText:r("chart.tooltip.additional_metrics.add"),deleteButtonText:r("chart.tooltip.additional_metrics.delete"),renderTabName:l,children:({field:o,index:i})=>n.jsx(wC,{control:e,index:i})})]})};function CC({control:e,watch:t}){return n.jsx(mC,{control:e,watch:t})}function SC({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["x_axis"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),sx:{flex:1},...a})})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(Re,{...a})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:a})=>n.jsx(nt,{sx:{width:"48%"},...a})}),n.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(He,{...a})})]})]})}function TC({control:e,watch:t}){const{t:r}=x.useTranslation();return t(["y_axis"]),n.jsxs(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:a})=>n.jsx(q,{label:r("common.data_field"),required:!0,sx:{flex:1},...a})}),n.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})})]}),n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(b.Controller,{name:"y_axis.nameAlignment",control:e,render:({field:a})=>n.jsx(ft,{sx:{flex:1},...a})})}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsx(b.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(Re,{...a})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(b.Controller,{name:"y_axis.axisLabel.rotate",control:e,render:({field:a})=>n.jsx(nt,{sx:{width:"48%"},...a})}),n.jsx(b.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(He,{...a})})]})]})}function kC({context:e}){const{t}=x.useTranslation(),{value:r,set:a}=B(e.instanceData,"config"),l=h.useMemo(()=>r?y.defaults({},r):Wr,[r]),o=h.useMemo(()=>y.cloneDeep(l),[l]);h.useEffect(()=>{!y.isEqual(l,o)&&(console.log("config malformed, resetting to defaults",l,o),a(o))},[l,o]);const i=b.useForm({defaultValues:o}),{control:c,handleSubmit:d,watch:u,formState:p,reset:f}=i;return h.useEffect(()=>{f(o)},[o]),n.jsx("form",{onSubmit:d(a),style:{flexGrow:1},children:n.jsxs(s.Stack,{gap:"xs",sx:{height:"100%"},children:[n.jsx(ae,{canSubmit:p.isDirty}),n.jsxs(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{root:{flexGrow:1},tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axis",children:t("chart.x_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Y Axis",children:t("chart.y_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Heat Block",children:t("chart.heatmap.heatblock.label")}),n.jsx(s.Tabs.Tab,{value:"Visual Map",children:t("chart.visual_map.label")}),n.jsx(s.Tabs.Tab,{value:"Tooltip",children:t("chart.tooltip.label")})]}),n.jsx(s.Tabs.Panel,{value:"X Axis",children:n.jsx(SC,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Y Axis",children:n.jsx(TC,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Heat Block",children:n.jsx(xC,{control:c,watch:u})}),n.jsx(s.Tabs.Panel,{value:"Visual Map",children:n.jsx(Dr,{form:i})}),n.jsx(s.Tabs.Panel,{value:"Tooltip",children:n.jsx(CC,{control:c,watch:u})})]})]})})}function zC(e){return n.jsx(n.Fragment,{})}function DC(e){const{t}=x.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.merico_heatmap.click_heatmap.heatblock.label")})}const ko={id:"builtin:echarts:click-heatmap:heat-block",displayName:"viz.merico_heatmap.click_heatmap.heatblock.label",nameRender:DC,configRender:zC,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function IC(e){const t=ze(e.x_axis.axisLabel.formatter),r=ze(e.y_axis.axisLabel.formatter);return{x_axis:t,y_axis:r}}function MC(e){return{heat_block:function(a){if(!e.heat_block.value_formatter)return a;try{return Y(a,e.heat_block.value_formatter)}catch(l){return console.error(l),a}}}}function VC(e){let t=0;return e.x_axis.name&&(t+=20),{top:45,left:5,right:5,bottom:t,containLabel:!0,borderColor:"none",backgroundColor:"#E7E7E9",z:1}}function PC(e,t){const{heat_block:r}=e;return{type:"heatmap",name:r.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderWidth:0},data:t,label:r.label,labelLayout:{hideOverlap:!0},z:2}}const AC=e=>Y(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function $C({conf:e,labelFormatters:t,valueFormatters:r,dataDict:a,params:l,metricUnitMap:o}){const{value:i,dataIndex:c}=l,[d,u,p]=i,f={label:e.x_axis.name?e.x_axis.name:"X Axis",value:t.x_axis(d,c),style:{label:"",value:Ee(e.x_axis.axisLabel.overflow.in_tooltip)},unit:""},v={label:e.y_axis.name?e.y_axis.name:"Y Axis",value:t.y_axis(u,c),style:{label:"",value:Ee(e.y_axis.axisLabel.overflow.in_tooltip)},unit:""},_={label:e.heat_block.name,value:r.heat_block(p),style:{label:"",value:""},unit:e.heat_block.unit.show_in_tooltip?e.heat_block.unit.text:""},w=[f,v,_],m=a[`${d}---${u}`];return m&&e.tooltip.metrics.forEach(k=>{const z=P(k.data_key),D=o[k.name];w.push({label:k.name,value:AC(y.get(m,z.columnKey,"")),style:{label:"",value:""},unit:D})}),w}function EC(e,t,r,a){const{x_axis:l,y_axis:o,heat_block:i}=e,c=P(l.data_key),d=P(o.data_key);P(i.data_key);const u=y.keyBy(t[c.queryID],f=>`${f[c.columnKey]}---${f[d.columnKey]}`),p=e.tooltip.metrics.reduce((f,{unit:v,name:_})=>(v.show_in_tooltip&&(f[_]=v.text),f),{});return X.getTooltip({formatter:function(f){const _=$C({conf:e,labelFormatters:r,valueFormatters:a,dataDict:u,params:f,metricUnitMap:p}).map(m=>`
507
507
  <tr>
508
508
  <th style="text-align: right; padding: 0 1em;">
509
509
  <div style="${m.style.label}">${m.label}</div>
@@ -527,7 +527,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
527
527
  </thead>
528
528
  <tbody>${_.join("")}</tbody>
529
529
  </table>
530
- `}})}function VC(e,t,r){const{overflow:a,rotate:l}=e.x_axis.axisLabel,o=Be(a.on_axis);return X.getXAxis({id:"main-x-axis",type:"category",data:t,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:l,...o,formatter:r},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:!1},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:3})}function $C(e,t){const{nameAlignment:r,data_key:a,...l}=e.y_axis,{overflow:o,rotate:i}=e.y_axis.axisLabel,c=Be(o.on_axis);return X.getYAxis({...l,type:"category",axisLabel:{rotate:i,...c,formatter:t},axisLine:{show:!0,lineStyle:{width:3}},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:!1},nameTextStyle:{fontWeight:"bold",align:r},nameLocation:"end",nameGap:15,z:3})}function EC(e,t,r){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const a=r.reduce((m,k)=>{const z=Re(k,t);return m[k.name]=$e(k,z),m},{}),l=kC(e),o=zC(e),i=tn(e.visualMap,a),{min:c,max:d}=i,u=A(e.x_axis.data_key),p=A(e.y_axis.data_key),f=A(e.heat_block.data_key),v=y.uniq(t[u.queryID].map(m=>m[u.columnKey])),_=t[u.queryID].map(m=>{const k=y.get(m,u.columnKey),z=y.get(m,p.columnKey),D=y.get(m,f.columnKey),I={value:[k,z,D]},{followVisualMap:L,color:E}=er(D,c,d,e.visualMap);return L||(I.visualMap=!1,I.itemStyle={color:E}),I});return{xAxis:VC(e,v,l.x_axis),yAxis:$C(e,l.y_axis),series:IC(e,_),tooltip:PC(e,t,l,o),grid:DC(e),visualMap:i}}function BC({conf:e,data:t,width:r,height:a,interactionManager:l,variables:o,instance:i}){const c=h.useMemo(()=>{const w=A(e.x_axis.data_key),m=A(e.y_axis.data_key);return y.keyBy(t[w.queryID],k=>`${k[w.columnKey]}---${k[m.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),d=Ie(l.triggerManager,Co.id),u=h.useCallback(w=>{const[m,k]=w.value,z=y.get(c,`${m}---${k}`,{error:"rowData is not found"});d.forEach(D=>{l.runInteraction(D.id,{...w,rowData:z})})},[c,d,l]),p=h.useRef(null),f=h.useCallback(()=>{var m;const w=(m=p.current)==null?void 0:m.getEchartsInstance();w&&de(i,w.getOption())},[i]),v=h.useMemo(()=>({click:u,finished:f}),[u,f]),_=h.useMemo(()=>EC(e,t,o),[e,t]);return n.jsx(he,{echarts:ce,option:_,ref:p,style:{width:r,height:a},onEvents:v,notMerge:!0,theme:"merico-light"})}function LC({context:e,instance:t}){const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},a,Qr),[a]),i=e.data,{width:c,height:d}=e.viewport;return!c||!d?null:n.jsx(_e,{width:c,height:d,children:n.jsx(BC,{instance:t,variables:l,width:Ge(c),height:Fe(d),data:i,conf:o,interactionManager:r})})}const qC=[{lang:"en",resources:{merico_heatmap:{viz_name:"Merico Heatmap",click_heatmap:{heatblock:{label:"Click heat block"}}}}},{lang:"zh",resources:{merico_heatmap:{viz_name:"思码逸热力图",click_heatmap:{heatblock:{label:"点击热力块"}}}}}];function OC(e){const{visualMap:t=et(),heat_block:{min:r,max:a,...l},...o}=e;return{...o,heat_block:l,visualMap:{...et(),min:r,max:a}}}function NC(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??U()}))}}}function GC(e){const{heat_block:t}=e;return{...e,heat_block:{...t,unit:t.unit??U()}}}class FC extends ee{constructor(){super(...arguments);P(this,"VERSION",4)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>({...r,version:2,config:OC(r.config)})),this.version(3,r=>({...r,version:3,config:NC(r.config)})),this.version(4,r=>({...r,version:4,config:GC(r.config)}))}}const jC={displayName:"viz.merico_heatmap.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new FC,name:"merico-heatmap",viewRender:LC,configRender:CC,createConfig:()=>({version:4,config:Qr}),triggers:[Co],translation:qC},Wr={item_badge:"_item_badge_l2t3l_1",label:"_label_l2t3l_8",value:"_value_l2t3l_20"},QC=({children:e})=>["string","number"].includes(typeof e)?n.jsx(s.Text,{size:"xs",ff:"monospace",children:e}):e,bt=h.forwardRef(({label:e,value:t,label_description:r,value_description:a},l)=>n.jsxs("div",{ref:l,className:Wr.item_badge,children:[n.jsx("div",{className:Wr.label,children:e}),n.jsxs(s.HoverCard,{shadow:"md",disabled:!a,children:[n.jsx(s.HoverCard.Target,{children:n.jsx("div",{className:Wr.value,"data-with-tooltip":!!a,children:t})}),n.jsx(s.HoverCard.Dropdown,{p:"xs",children:n.jsx(QC,{children:a})})]})]})),WC=({item:e})=>e.type!=="checkbox"?null:n.jsx(bt,{label:e.label,value:n.jsx(s.ThemeIcon,{variant:"white",radius:"xs",color:e.value?"teal":"red",w:12,h:12,miw:12,mih:12,children:e.value?n.jsx(S.IconCheck,{size:12,strokeWidth:3}):n.jsx(S.IconX,{strokeWidth:3})}),label_description:`filters.${e.key}`}),UC=({item:e})=>e.type!=="context"?null:n.jsx(bt,{label:e.key,value:e.value,label_description:`context.${e.key}`}),YC=T.observer(({item:e})=>{const{t}=x.useTranslation(),a=e.model.value,[l,o]=a.value,i=h.useMemo(()=>!o&&!l?Number.NaN:M(o).diff(M(l),"days")+1,[l,o]);if(Number.isNaN(i))return n.jsx("span",{style:{userSelect:"none",opacity:0,visibility:"hidden"},children:"."});const c=i===1?t("filter.widget.date_range.one_day"):t("filter.widget.date_range.x_days",{count:i});return n.jsx(bt,{label:e.label,value:e.value.join(" ~ "),label_description:`filters.${e.key}`,value_description:c})}),KC=({item:e})=>e.type!=="date-range"?null:n.jsx(YC,{item:e}),So=({selection:e})=>(x.useTranslation(),e.length===0?null:n.jsx(s.Group,{justify:"flex-start",gap:"xs",maw:"80vw",children:e.map(t=>n.jsx(s.Pill,{size:"xs",ff:"monospace",children:t.label},t.value))})),XC=T.observer(({item:e})=>{x.useTranslation();const r=e.model.config,a=h.useMemo(()=>r.optionsByValues(e.value),[e.value,r.options]);return n.jsx(bt,{label:e.label,value:a.length,label_description:`filters.${e.key}`,value_description:n.jsx(So,{selection:a})})}),ZC=({item:e})=>e.type!=="multi-select"?null:n.jsx(XC,{item:e}),JC=T.observer(({item:e})=>{x.useTranslation();const r=e.model.config,a=h.useMemo(()=>{var l;return((l=r.options.find(o=>o.value===e.value))==null?void 0:l.label)??e.value},[e.value,r.options]);return n.jsx(bt,{label:e.label,value:a,label_description:`filters.${e.key}`})}),HC=({item:e})=>e.type!=="select"?null:n.jsx(JC,{item:e}),RC=({item:e})=>e.type!=="text-input"?null:n.jsx(bt,{label:e.label,value:n.jsx(s.Text,{maw:200,size:"xs",truncate:"end",ff:"monospace",children:e.value}),value_description:e.value}),eS=T.observer(({item:e})=>{x.useTranslation();const r=e.model.config,a=h.useMemo(()=>r.optionsByValues(e.value),[e.value,r.options]);return n.jsx(bt,{label:e.label,value:a.length,label_description:`filters.${e.key}`,value_description:n.jsx(So,{selection:a})})}),tS=({item:e})=>e.type!=="tree-select"?null:n.jsx(eS,{item:e}),nS=T.observer(({item:e})=>{x.useTranslation();const r=e.model.config,a=h.useMemo(()=>{var l;return((l=r.options.find(o=>o.value===e.value))==null?void 0:l.label)??e.value},[e.value,r.options]);return n.jsx(bt,{label:e.label,value:a,label_description:`filters.${e.key}`,value_description:e.value})}),rS=({item:e})=>e.type!=="tree-single-select"?null:n.jsx(nS,{item:e}),Ur=({item:e})=>{switch(e.type){case"date-range":return n.jsx(KC,{item:e});case"select":return n.jsx(HC,{item:e});case"tree-single-select":return n.jsx(rS,{item:e});case"multi-select":return n.jsx(ZC,{item:e});case"tree-select":return n.jsx(tS,{item:e});case"text-input":return n.jsx(RC,{item:e});case"checkbox":return n.jsx(WC,{item:e});case"context":return n.jsx(UC,{item:e});default:return null}},aS=T.observer(({conf:e})=>{const r=J().dashboardState,{all:a,keys:l}=e;return a?n.jsxs(n.Fragment,{children:[Object.entries(r.context).map(([o,i])=>n.jsx(Ur,{item:i},o)),Object.entries(r.filters).map(([o,i])=>n.jsx(Ur,{item:i},o))]}):n.jsx(n.Fragment,{children:l.map(o=>{const i=y.get(r,o);return i?n.jsx(Ur,{item:i},o):null})})}),sS=T.observer(({context:e})=>{const{value:t}=B(e.instanceData,"config"),{width:r,height:a}=e.viewport;return t?n.jsx(s.Group,{justify:"flex-start",align:"flex-start",wrap:"wrap",px:0,py:0,gap:"xs",w:r,mah:a,style:{overflow:"auto"},"data-enable-scrollbar":!0,children:n.jsx(aS,{conf:t})}):null}),To={all:!0,keys:[]},lS={select:"filter.widget.names.select","multi-select":"filter.widget.names.multi_select","tree-select":"filter.widget.names.tree_select","tree-single-select":"filter.widget.names.tree_single_select","text-input":"filter.widget.names.text_input",checkbox:"filter.widget.names.checkbox","date-range":"filter.widget.names.date_range"},oS=({option:e,checked:t,...r})=>{const{t:a}=x.useTranslation(),l=e,o=l.type==="filter";return n.jsxs(s.Group,{gap:4,flex:1,children:[n.jsx(S.IconCheck,{size:14,opacity:t?1:0,color:"black"}),n.jsx(s.Stack,{gap:0,py:4,px:8,flex:1,styles:{root:{flexGrow:1,borderRadius:"4px"}},...r,children:n.jsxs(s.Group,{justify:"space-between",wrap:"nowrap",children:[n.jsx(s.Text,{size:"xs",children:e.label}),o&&n.jsx(s.Text,{size:"xs",c:t?"rgba(0,0,0,.8)":"dimmed",style:{flexShrink:0,flexGrow:0},children:a(lS[l.widget])})]})})]})},iS=T.observer(({value:e,onChange:t,disabled:r})=>{const{t:a}=x.useTranslation(),o=F().dashboardStateVariableOptions,i=h.useMemo(()=>{const{optionGroups:c,validValues:d}=o,u=c.map(f=>({group:a(f.group),items:f.items.map(v=>({...v,label:v.label,value:v.value,widget_label:v.label}))})),p=e.filter(f=>!d.has(f)).map(f=>({label:f,value:f,disabled:!0}));return p.length>0&&u.push({group:a("common.invalid"),items:p}),u},[o,a,e]);return n.jsx(s.MultiSelect,{size:"xs",label:a("viz.vizDashboardState.variable_selector.label"),placeholder:e.length===0?a("viz.vizDashboardState.variable_selector.placeholder"):void 0,data:i,renderOption:oS,maxDropdownHeight:600,value:e,onChange:t,disabled:r,clearable:!0})}),cS=({form:e})=>{const{t}=x.useTranslation(),r=e.watch("all");return n.jsxs(s.Stack,{gap:"xs",p:"xs",children:[n.jsx(b.Controller,{name:"all",control:e.control,render:({field:a})=>n.jsx(s.Checkbox,{size:"xs",label:t("viz.vizDashboardState.show_all"),checked:a.value,onChange:l=>a.onChange(l.currentTarget.checked)})}),n.jsx(b.Controller,{name:"keys",control:e.control,render:({field:a})=>n.jsx(iS,{disabled:r,...a})})]})};function dS({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaultsDeep({},t,To),[t]),l=b.useForm({defaultValues:a}),{handleSubmit:o,formState:i,reset:c}=l;return h.useEffect(()=>{c(a)},[a]),n.jsxs("form",{onSubmit:o(r),children:[n.jsx(ae,{canSubmit:i.isDirty}),n.jsx(cS,{form:l})]})}const uS=[{lang:"en",resources:{vizDashboardState:{viz_name:"Dashboard State",show_all:"Show all filters and context entries",variable_selector:{label:"Select filters and context entries to show",placeholder:""}}}},{lang:"zh",resources:{vizDashboardState:{viz_name:"看板状态",show_all:"显示所有筛选器和上下文条目",variable_selector:{label:"选择要展示的筛选器和上下文",placeholder:""}}}}];class pS extends ee{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const hS={displayName:"viz.vizDashboardState.viz_name",displayGroup:"chart.groups.others",migrator:new pS,name:"vizDashboardState",viewRender:sS,configRender:dS,createConfig:()=>({version:1,config:To}),translation:uS},gS=[{value:"#25262B",name:"Dark"},{value:"#868E96",name:"Gray"},{value:"#FA5252",name:"Red"},{value:"#E64980",name:"Pink"},{value:"#BE4BDB",name:"Grape"},{value:"#7950F2",name:"Violet"},{value:"#4C6EF5",name:"Indigo"},{value:"#228BE6",name:"Blue"},{value:"#15AABF",name:"Cyan"},{value:"#12B886",name:"Teal"},{value:"#40C057",name:"Green"},{value:"#82C91E",name:"Lime"},{value:"#FAB005",name:"Yellow"},{value:"#FD7E14",name:"Orange"}].map(e=>({name:e.name,value:e.value,type:"single",category:"basic"})),fS=[tu,nu,su,au,ru,lu],Yr=[Er,Aw,Hm,px,Rw,o_,S1,Ep,jg,Hb,Fy,q0,zv,Vb,pw,V_,ox,o0,aC,jC,bC,tf,hS],ko=Yr.reduce((e,t)=>(e[t.name]={displayName:t.displayName,displayGroup:t.displayGroup},e),{}),zo=()=>({id:"dashboard",version:Cs,manifest:{viz:Yr,color:[...gS,...fS]}}),Ct=new pu,R={pluginManager:Je("pluginManager"),vizManager:Je("vizManager"),colorManager:Je("colorManager"),panelAddonManager:Je("panelAddonManager"),instanceScope:{panelModel:Je("panelModel"),vizInstance:Je("vizInstance"),interactionManager:Je("interactionManager"),migrator:Je("migrator"),operationManager:Je("operationManager"),triggerManager:Je("triggerManager")}},Kr=()=>{try{Ct.install(zo())}catch{}const e=new Hd(Ct),t=new uu(Ct),r=new iu(Ct);return{pluginManager:Ct,vizManager:e,colorManager:t,panelAddonManager:r}},rt=h.createContext(Kr());try{Ct.install(zo())}catch{}const wn=Se.createInstance({debug:!1,fallbackLng:"en",interpolation:{escapeValue:!1},resources:{en:Xd,zh:Zd}}).use(td).use(x.initReactI18next);wn.init(),Yr.forEach(e=>{var t;(t=e.translation)==null||t.forEach(r=>{wn.addResourceBundle(r.lang,"translation",{viz:r.resources},!0,!0)})});function Do({lang:e,children:t}){return h.useEffect(()=>{wn.changeLanguage(e)},[e]),n.jsx(x.I18nextProvider,{i18n:wn,children:t})}M.extend(cd),M.extend(dd),M.extend(ud),M.extend(pd),M.extend(hd),M.extend(gd),M.extend(fd),M.extend(bd),M.extend(yd),M.extend(vd),M.extend(wd),M.extend(md),M.extend(Cd),M.extend(Sd),M.extend(Td),M.extend(_d),M.extend(xd),M.extend(kd),M.extend(zd),M.extend(Dd),M.extend(Id),M.extend(Md),M.extend(Ad),M.extend(Pd),M.extend(Vd),M.extend($d),M.extend(Ed),M.extend(Bd),M.extend(Ld),M.extend(qd),M.extend(Nd),M.extend(Gd),M.extend(Od),M.tz.setDefault("UTC"),M.updateLocale("en",{weekStart:1});function bS(e){e=e||{};const t=Object.keys(e).sort(),r=[];for(let a=0;a<t.length;a++){const l=t[a];if(l!="authentication"&&e[l])r.push(t[a]+"="+(typeof e[l]=="object"?JSON.stringify(e[l]):e[l]));else{const o=Object.keys(e[l]).sort();for(let i=0;i<o.length;i++){const c=o[i];c!="sign"&&e[l][c]&&r.push(o[i]+"="+(typeof e[l][c]=="object"?JSON.stringify(e[l][c]):e[l][c]))}}}return r.sort().join("&")}function yS(e,t){let r=bS(e);return r+="&key="+t,Yd.MD5(r).toString().toUpperCase()}class Io{constructor(){this.type="default_api_client",this.baseURL="http://localhost:31200",this.app_id="",this.app_secret=""}getAuthentication(t){if(!this.app_id||!this.app_secret)return;const r=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:r,sign:yS({app_id:this.app_id,nonce_str:r,...t},this.app_secret)}}getRequest(t,r){return(a,l,o,i)=>{const c=this.buildHeader(o),d=this.buildAxiosConfig(t,a,l,o,c,r);return ke(d).then(u=>i?u:u.data).catch(u=>{if(ke.isCancel(u))return Promise.reject(u);const p=u,f=y.get(p,"response.data.detail.message",p.message);return Promise.reject(new Error(f))})}}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}buildAxiosConfig(t,r,a,l,o,i){const c={baseURL:this.baseURL,method:t,url:r,params:t==="GET"?a:l.params,headers:o,signal:i};return["POST","PUT"].includes(t)&&(c.data=l.string?JSON.stringify(a):a,c.data.authentication=this.getAuthentication(c.data)),c}buildHeader(t){const r=window.localStorage.getItem("token");return{"X-Requested-With":"XMLHttpRequest","Content-Type":t.string?"application/x-www-form-urlencoded":"application/json",authorization:r?`bearer ${r}`:"",...t.headers}}}class vS{constructor(t){this.implementation=t}getRequest(t,r){return this.implementation.getRequest(t,r)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}class Mo extends Io{constructor(){super(...arguments);P(this,"makeQueryENV",null)}query(r){return async(a,l={})=>{var o;return a.env||(a.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.post(r)("/query",a,l)}}httpDataSourceQuery(r){return async(a,l={})=>{var o;return a.env||(a.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",r)("/query",a,l,!0)}}structure(r){return async(a,l={})=>this.post(r)("/query/structure",a,l)}mericoMetricInfo(r){return async(a,l={})=>this.post(r)("/query/merico_metric_info",a,l,!0)}mericoMetricQuery(r){return async(a,l={})=>this.post(r)("/query",a,l,!0)}}class Ao{constructor(t){this.implementation=t}query(t){return this.implementation.query(t)}httpDataSourceQuery(t){return this.implementation.httpDataSourceQuery(t)}structure(t){return this.implementation.structure(t)}mericoMetricInfo(t){return this.implementation.mericoMetricInfo(t)}mericoMetricQuery(t){return this.implementation.mericoMetricQuery(t)}getRequest(t,r){return this.implementation.getRequest(t,r)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}const Et=new Mo;function Xr(e){Et.baseURL!==e.apiBaseURL&&(Et.baseURL=e.apiBaseURL),e.app_id&&(Et.app_id=e.app_id),e.app_secret&&(Et.app_secret=e.app_secret),e.makeQueryENV&&(Et.makeQueryENV=e.makeQueryENV)}const Po=new Ao(Et),Ae=Po,Zr=g.types.model("MockContextMeta",{current:g.types.optional(g.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get keySet(){return new Set(this.keys)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},defaults(t){e.current={...t,...e.current}},get(t){return e.current[t]},set(t,r){e.current[t]=r}}));function Jr(e){return{current:e}}const _S=g.types.model("PanelStyleBorderMeta",{enabled:g.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),Vo=g.types.model("PanelStyleMeta",{border:_S}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),$o=g.types.model("PanelTitleMeta",{show:g.types.optional(g.types.boolean,!0)}).views(e=>({get json(){const{show:t}=e;return{show:t}}})).actions(e=>({setShow(t){e.show=t}})),Eo=g.types.model("VariableMeta",{name:g.types.string,size:g.types.string,weight:g.types.string,color:g.types.union(g.types.model({type:g.types.literal("static"),staticColor:g.types.string}),g.types.model({type:g.types.literal("continuous"),valueRange:g.types.array(g.types.number),colorRange:g.types.array(g.types.string)}),g.types.model({type:g.types.literal("piecewise")})),formatter:g.types.model({output:g.types.enumeration("Output",["number","percent"]),average:g.types.optional(g.types.boolean,!1),mantissa:g.types.number,trimMantissa:g.types.optional(g.types.boolean,!1),absolute:g.types.optional(g.types.boolean,!1)}),data_field:g.types.string,aggregation:g.types.union(g.types.model({type:g.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:g.types.frozen(),fallback:g.types.optional(g.types.string,"0")}),g.types.model({type:g.types.literal("quantile"),config:g.types.model({p:g.types.number}),fallback:g.types.optional(g.types.string,"0")}),g.types.model({type:g.types.literal("pick_record"),config:g.types.model({method:g.types.enumeration("Pick Record Method",["first","last"])}),fallback:g.types.optional(g.types.string,"0")}),g.types.model({type:g.types.literal("custom"),config:g.types.model({func:g.types.string}),fallback:g.types.optional(g.types.string,"0")}))}).views(e=>({get json(){const{name:t,size:r,weight:a,color:l,formatter:o,data_field:i,aggregation:c}=e;return y.cloneDeep({name:t,size:r,color:l,weight:a,formatter:o,data_field:i,aggregation:c})}})),Bo=g.types.model("PanelVizMeta",{type:g.types.string,conf:g.types.frozen()}).views(e=>({get json(){return{conf:e.conf,type:e.type}}})).actions(e=>({setType(t){e.type=t},setConf(t){y.isEqual(e.conf,t)||(e.conf=t)}})),Lo=g.types.model({id:g.types.string,name:g.types.optional(g.types.string,""),title:$o,description:g.types.string,queryIDs:g.types.array(g.types.string),viz:Bo,style:Vo,variables:g.types.optional(g.types.array(Eo),[])}).views(e=>({get json(){const{id:t,name:r,title:a,description:l,queryIDs:o}=e;return{id:t,viz:e.viz.json,name:r,style:e.style.json,title:a.json,queryIDs:[...o],variables:e.variables.map(i=>i.json),description:l}},get queryIDSet(){return new Set(e.queryIDs)}})).actions(e=>({setID(t){e.id=t},setName(t){e.name=t},setDescription(t){e.description=t},addQueryID(t){e.queryIDSet.has(t)||e.queryIDs.push(t)},removeQueryID(t){if(!e.queryIDSet.has(t))return;const r=new Set(e.queryIDSet);r.delete(t),e.queryIDs=g.cast(Array.from(r))},setQueryIDs(t){e.queryIDs=g.cast(t)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)}}));var j=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e.Transform="transform",e.MericoMetricSystem="merico_metric_system",e))(j||{});const qo=g.types.model("DBQueryMeta",{_type:g.types.enumeration([j.MySQL,j.Postgresql]),sql:g.types.string}).views(e=>({get base(){return g.getParent(e)},get valid(){return!!e.sql},get json(){const{sql:t,_type:r}=e;return{sql:t,_type:r}}})).actions(e=>({setSQL(t){e.sql=t}})),xS=e=>qo.create({_type:e,sql:""}),Oo=g.types.model("HTTPQueryMeta",{_type:g.types.literal(j.HTTP),react_to:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get valid(){return!0},get json(){const{react_to:t,_type:r}=e;return tt({react_to:t,_type:r})}})).actions(e=>({setReactTo(t){e.react_to.length=0,e.react_to.push(...t)}})),wS=()=>Oo.create({_type:j.HTTP,react_to:[]}),No=g.types.model("TransformQueryMeta",{_type:g.types.literal(j.Transform),dep_query_ids:g.types.optional(g.types.array(g.types.string),[]),react_to:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get valid(){return e.dep_query_ids.length>0},get json(){const{dep_query_ids:t,_type:r,react_to:a}=e;return tt({dep_query_ids:t,_type:r,react_to:a})}})).actions(e=>({setDependantQueryIDs(t){e.dep_query_ids.length=0,e.dep_query_ids.push(...t)},setReactTo(t){e.react_to.length=0,e.react_to.push(...t)}})),mS=()=>No.create({_type:j.Transform,dep_query_ids:[]}),Go=g.types.model("MetricFilterColMeta",{dimension:g.types.optional(g.types.string,""),variable:g.types.optional(g.types.string,"")}).views(e=>({get allEmpty(){return!e.dimension&&!e.variable},get json(){const{dimension:t,variable:r}=e;return{dimension:t,variable:r}}})).actions(e=>({removeSelf(){g.getParent(e,2).removeFilter(e)},setDimension(t){e.dimension=t??"",e.allEmpty&&this.removeSelf()},setVariable(t){e.variable=t??"",e.allEmpty&&this.removeSelf()}})),Hr=g.types.model("MericoMetricQueryMeta",{_type:g.types.literal(j.MericoMetricSystem),id:g.types.optional(g.types.string,""),type:g.types.optional(g.types.enumeration("MetricType",["derived","combined"]),"derived"),filters:g.types.optional(g.types.array(Go),[]),groupBys:g.types.optional(g.types.array(g.types.string),[]),timeQuery:g.types.model({enabled:g.types.optional(g.types.boolean,!1),range_variable:g.types.optional(g.types.string,""),unit_variable:g.types.optional(g.types.string,""),timezone:g.types.optional(g.types.string,"PRC"),stepKeyFormat:g.types.optional(g.types.string,"YYYY-MM-DD")}),useDefaultValues:g.types.optional(g.types.boolean,!1)}).views(e=>({get query(){return g.getParent(e)},get valid(){return!!e.id},get json(){const{id:t,type:r,filters:a,groupBys:l,timeQuery:o,useDefaultValues:i,_type:c}=e;return tt({id:t,type:r,filters:a.map(d=>d.json),groupBys:l,timeQuery:o,useDefaultValues:i,_type:c})},get usedFilterDimensionKeys(){const t=e.filters.map(r=>r.dimension).filter(r=>!!r);return new Set(t)},get usedFilterVariableSet(){const t=[...e.filters.map(r=>r.variable)].filter(r=>!!r);return new Set(t)},get usedTimeQueryVariableSet(){const t=[e.timeQuery.range_variable,e.timeQuery.unit_variable].filter(r=>!!r);return new Set(t)},get groupByValues(){const t=e.groupBys.map(r=>r.replace(/^(.+)\s->\s(.*)/,"$1"));return Array.from(new Set(t))}})).actions(e=>({reset(){e.filters.length=0,e.groupBys.length=0,e.timeQuery.enabled=!1,e.timeQuery.range_variable="",e.timeQuery.unit_variable="",e.useDefaultValues=!1,"data"in e.query&&(e.query.setData([]),e.query.setError(null))},setID(t){t!==e.id&&this.reset(),e.id=t},setType(t){t!=="derived"&&t!=="combined"||(e.type=t)},addFilter(t,r){t&&e.usedFilterDimensionKeys.has(t)||e.filters.push(Go.create({dimension:t,variable:r}))},removeFilter(t){g.destroy(t)},setGroupBys(t){e.groupBys.length=0,e.groupBys.push(...t)},setRangeVariable(t){e.timeQuery.range_variable=t??""},setUnitVariable(t){e.timeQuery.unit_variable=t??""},setTimeQueryEnabled(t){e.timeQuery.enabled=t,t?e.groupBys.length>1&&(e.groupBys.length=0):(e.timeQuery.range_variable="",e.timeQuery.unit_variable="")},setUseDefaultValues(t){e.useDefaultValues=t}})),Fo=()=>Hr.create({_type:j.MericoMetricSystem,id:"",type:"derived",filters:[],groupBys:[],timeQuery:{range_variable:"",unit_variable:"",timezone:"PRC",stepKeyFormat:"YYYY-MM-DD"},useDefaultValues:!1}),jo=g.types.model("QueryMeta",{id:g.types.string,name:g.types.string,key:g.types.string,type:g.types.enumeration("DataSourceType",[j.Postgresql,j.MySQL,j.HTTP,j.Transform,j.MericoMetricSystem]),config:g.types.union(qo,Oo,No,Hr),pre_process:g.types.optional(g.types.string,""),post_process:g.types.optional(g.types.string,""),run_by:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get valid(){const{id:t,name:r,key:a,type:l,config:o}=e;return o.valid&&!!t&&!!r&&!!a&&!!l},get json(){const{id:t,name:r,key:a,type:l,config:o,pre_process:i,post_process:c,run_by:d}=e;return tt({id:t,name:r,key:a,type:l,config:o.json,pre_process:i,post_process:c,run_by:d})}})).actions(e=>({setName(t){e.name=t},setKey(t){e.key=t},setType(t){switch(e.type=t,t){case j.HTTP:e.config=wS();break;case j.MySQL:case j.Postgresql:e.config=xS(t);break;case j.Transform:e.config=mS();break;case j.MericoMetricSystem:e.config=Fo();break;default:throw new Error(`Unexpected query type[${t}]`)}},setRunBy(t){e.run_by.length=0,e.run_by.push(...t)},setPreProcess(t){e.pre_process=t},setPostProcess(t){e.post_process=t}})),Qo=g.types.model("LayoutItemMeta",{id:g.types.identifier,panelID:g.types.string,x:g.types.number,y:g.types.maybeNull(g.types.number),w:g.types.number,h:g.types.number,moved:g.types.optional(g.types.boolean,!1),static:g.types.optional(g.types.boolean,!1)}).views(e=>({get json(){const{id:t,panelID:r,x:a,y:l,w:o,h:i,moved:c}=e;return{h:i,w:o,x:a,y:l===null?0:l,id:t,moved:c,static:e.static,panelID:r}},get contentModel(){return g.getRoot(e).content},get panel(){const{panelID:t}=e;return this.contentModel.panels.findByID(t)},get layoutProperies(){const{id:t,x:r,y:a,w:l,h:o,moved:i}=e;return{id:t,i:t,x:r,y:a===null?1/0:a,w:l,h:o,moved:i,static:e.static}}})).actions(e=>({set(t){const{isDraggable:r,x:a,y:l,w:o,h:i,moved:c}=t;e.x=a,e.y=l,e.w=o,e.h=i,e.moved=!!c,e.static=!!t.static},setWidth(t){e.w=t},setHeight(t){e.h=t}})),Wo=g.types.model("LayoutSetMeta",{id:g.types.identifier,name:g.types.string,breakpoint:g.types.number,list:g.types.optional(g.types.array(Qo),[])}).views(e=>({get contentModel(){return g.getRoot(e).content},get json(){const{id:t,name:r,breakpoint:a,list:l}=e;return{id:t,name:r,breakpoint:a,list:l.map(o=>tt(o.json))}},jsonByPanelIDSet(t){const{id:r,name:a,breakpoint:l,list:o}=e;return{id:r,name:a,breakpoint:l,list:o.filter(i=>t.has(i.panelID)).map(i=>tt(i.json))}},findByID(t){return e.list.find(r=>r.id===t)},findByPanelID(t){return e.list.find(r=>r.panelID===t)}})).actions(e=>({setName(t){e.name=t},setBreakpoint(t){e.breakpoint=t},addLayout(t){e.list.push(t)},addNewLayout(t){e.list.push({id:Ke.v4(),panelID:t,x:0,y:1/0,w:18,h:300,static:!1,moved:!1})},removeByPanelID(t){const r=e.list.findIndex(a=>a.panelID===t);r>=0&&e.list.splice(r,1)},removeByPanelIDs(t){for(;t.length>0;){const r=t.pop();r&&this.removeByPanelID(r)}},updateLayoutItem(t){const r=e.list.find(a=>a.id===t.i);if(!r){console.error("Trying to update a layout that doesn't exist"),console.log({strangeLayoutItem:t});return}r.set(t)}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>{const t=e.list.length,r=e.contentModel.panels.list.length;return{match:t===r,layoutCount:t,panelCount:r}},({match:t,panelCount:r,layoutCount:a})=>{if(t)return;const l={id:"layout panel count mismatch",title:"Error detected, please don't save changes.",message:`${a} layout items against and ${r} panels.`,color:"red",autoClose:!1};Ze.showNotification(l),Ze.updateNotification(l)},{fireImmediately:!0,delay:0}))}})),Uo=g.types.model("SQLSnippetMeta",{key:g.types.string,value:g.types.string}).views(e=>({get json(){const{key:t,value:r}=e;return{key:t,value:r}}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.value=t}}));var V=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TreeSingleSelect="tree-single-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(V||{});const Rr=g.types.optional(g.types.enumeration(["intersect","reset"]),"intersect"),ea=g.types.model("FilterCheckboxConfigMeta",{_name:g.types.literal("checkbox"),description:g.types.optional(g.types.string,""),default_value:g.types.boolean}).views(e=>({get json(){const{_name:t,description:r,default_value:a}=e;return{_name:t,description:r,default_value:a}},get isDescriptionEmpty(){const{description:t}=e;return t===""||t==="<p></p>"}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDescription(t){e.description=t}})),Yo=()=>ea.create({_name:"checkbox",description:"",default_value:!1}),Ko=()=>[{key:"d",value:"yesterday",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(1,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"yesterday"}}},{key:"w",value:"last week",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(1,"week").startOf("week").toDate(),M(e).subtract(1,"week").endOf("week").toDate()],shortcut:"last week"}}},{key:"m",value:"last month",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(1,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()],shortcut:"last month"}}},{key:"m2",value:"last 2 months",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(2,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()],shortcut:"last 2 months"}}},{key:"m3",value:"last 3 months",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(3,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()],shortcut:"last 3 months"}}},{key:"y",value:"last year",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(1,"year").startOf("year").toDate(),M(e).subtract(1,"year").endOf("year").toDate()],shortcut:"last year"}}},{key:"d7",value:"recent 7 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(7,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 7 days"}}},{key:"d30",value:"recent 30 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(30,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 30 days"}}},{key:"d60",value:"recent 60 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(60,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 60 days"}}},{key:"d90",value:"recent 90 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(90,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 90 days"}}},{key:"d180",value:"recent 180 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(180,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 180 days"}}},{key:"d365",value:"recent 365 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(365,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 365 days"}}},{key:"d",value:"today",group:"this",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("day").toDate(),M(e).endOf("day").toDate()],shortcut:"today"}}},{key:"w",value:"this week",group:"this",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("week").toDate(),M(e).endOf("week").toDate()],shortcut:"this week"}}},{key:"m",value:"this month",group:"this",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("month").toDate(),M(e).endOf("month").toDate()],shortcut:"this month"}}},{key:"y",value:"this year",group:"this",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("year").toDate(),M(e).endOf("year").toDate()],shortcut:"this year"}}},{key:"w",value:"this week so far",group:"this_so_far",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("week").toDate(),M(e).toDate()],shortcut:"this week so far"}}},{key:"m",value:"this month so far",group:"this_so_far",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("month").toDate(),M(e).toDate()],shortcut:"this month so far"}}},{key:"y",value:"this year so far",group:"this_so_far",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("year").toDate(),M(e).toDate()],shortcut:"this year so far"}}}];function mn(e){if(!e)return null;const r=Ko().find(a=>a.value===e);return r?r.getRange():null}function Xo(){return y.groupBy(Ko(),"group")}function Zo(e){try{if(e.default_shortcut){const r=mn(e.default_shortcut);if(r)return{value:r.value.map(a=>M(a).toDate()),shortcut:e.default_shortcut}}return{value:e.default_value.map(r=>r===null?r:M.tz(r,"UTC").toDate()??r),shortcut:null}}catch(t){return console.error(t),{value:[null,null],shortcut:null}}}function Jo(e,t){return e.map(r=>{try{return r?M.tz(r,"UTC").toISOString():null}catch{return console.log(`[date-range] failed parsing ${r}`),null}})}const CS=g.types.model("FilterDateRangeConfigMeta",{_name:g.types.literal("date-range"),required:g.types.boolean,inputFormat:g.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:g.types.optional(g.types.array(g.types.union(g.types.Date,g.types.null)),[null,null]),default_shortcut:g.types.optional(g.types.string,""),clearable:g.types.boolean,max_days:g.types.optional(g.types.number,0),allowSingleDateInRange:g.types.optional(g.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:r,required:a,clearable:l,inputFormat:o,default_value:i,default_shortcut:c,allowSingleDateInRange:d}=e;return{_name:t,max_days:r,required:a,clearable:l,inputFormat:o,default_value:Jo(i),default_shortcut:c,allowSingleDateInRange:d}},truthy(t){try{const{value:r}=t;return Array.isArray(r)&&r.length===2&&r.every(a=>!!a)}catch(r){return console.error(r),!1}},get filter(){return g.getParent(e)},get dateStringsValue(){try{const t=this.filter.value,[r,a]=t.value,l=r?M(r).format(e.inputFormat):"",o=a?M(a).format(e.inputFormat):"";return[l,o]}catch(t){return console.error(t),["",""]}}})).actions(e=>({setFilterValue(t){try{e.filter.setValue(t)}catch(r){console.error(r)}}})).actions(e=>({setRequired(t){e.required=t},setClearable(t){e.clearable=t},setInputFormat(t){t&&(e.inputFormat=t)},setDefaultValue(t){e.default_value.length=0,e.default_value.push(...t.value),e.setFilterValue(t)},setDefaultShortcut(t){if(e.default_shortcut=t??"",!t)return;const r=mn(e.default_shortcut);r&&e.setFilterValue(r)},setMaxDays(t){const r=Number(t);Number.isFinite(r)&&(e.max_days=r,r>0&&(e.clearable=!0))},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),ta=g.types.snapshotProcessor(CS,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(r=>r===null?null:M.tz(r,"UTC").toDate())}},postProcessor(e){const{default_value:t,...r}=e;return{...r,default_value:Jo(t,r.inputFormat)}}}),Ho=()=>ta.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),Ro=g.types.model({label:g.types.string,value:g.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),na=g.types.model("FilterConfigModel_BaseSelect",{static_options:g.types.optional(g.types.array(Ro),[]),options_query_id:g.types.optional(g.types.string,""),default_selection_count:g.types.optional(g.types.number,0),required:g.types.optional(g.types.boolean,!1)}).views(e=>({get contentModel(){return g.getRoot(e).content},get filter(){return g.getParent(e)},get usingQuery(){return!!e.options_query_id}})).views(e=>({get optionsLoading(){if(!e.usingQuery)return!1;const{state:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t==="loading"},get options(){if(!e.usingQuery)return e.static_options;const{data:t,state:r}=e.contentModel.getDataStuffByID(e.options_query_id);return r==="error"?[]:Array.isArray(t)?t.filter(a=>"label"in a&&"value"in a):[]},get optionValuesSet(){return new Set(this.options.map(t=>t.value))}})).actions(e=>({setRequired(t){e.required=t},addStaticOption(t){e.static_options.push(t)},removeStaticOption(t){e.static_options.splice(t,1)},replaceStaticOptions(t){e.static_options.forEach(a=>g.detach(a));const r=t.map(a=>Ro.create(a));e.static_options.replace(r)},setDefaultSelectionCount(t){const r=Number(t);Number.isFinite(r)&&(e.default_selection_count=r)},setOptionsQueryID(t){e.options_query_id=t??""}})),ra=g.types.compose("FilterMultiSelectConfigMeta",g.types.model({_name:g.types.literal("multi-select"),min_width:g.types.optional(g.types.string,""),default_value:g.types.optional(g.types.array(g.types.string),[]),default_value_mode:Rr}),na).views(e=>({get json(){const{_name:t,default_value:r,default_value_mode:a,required:l,min_width:o,static_options:i,options_query_id:c,default_selection_count:d}=e;return tt({_name:t,required:!!l,min_width:o,default_value:r,static_options:i,options_query_id:c,default_value_mode:a,default_selection_count:d})},get defaultSelection(){const t=e.filter.formattedDefaultValue;return Array.isArray(t)&&t.length>0||!e.usingQuery?t:e.options.slice(0,e.default_selection_count).map(r=>r.value)},optionsByValues(t){if(!Array.isArray(t)||t.length===0)return[];const r=new Set(t);return e.options.filter(a=>r.has(a.value))},initialSelection(t){return t||this.defaultSelection},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=g.cast(t)},setDefaultValueMode(t){t!=="intersect"&&t!=="reset"||(e.default_value_mode=t)},setMinWidth(t){e.min_width=t},applyDefaultSelection(){if(e.optionsLoading)return;if(e.default_value_mode==="reset"){e.filter.setValue(e.defaultSelection);return}const t=new Set(e.options.map(l=>l.value)),a=(e.filter.value??[]).filter(l=>t.has(l));a.length>0?e.filter.setValue(a):e.filter.setValue(e.defaultSelection)}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>Q.toJS(e.defaultSelection),e.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),ei=()=>ra.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),aa=g.types.compose("FilterConfigModel_Select",g.types.model({_name:g.types.literal("select"),default_value:g.types.string,width:g.types.optional(g.types.string,""),clearable:g.types.optional(g.types.boolean,!1)}),na).views(e=>({get json(){const{_name:t,clearable:r,default_value:a,required:l,width:o,static_options:i,options_query_id:c,default_selection_count:d}=e;return tt({_name:t,width:o,required:l,clearable:r,default_value:a,static_options:i,options_query_id:c,default_selection_count:d})},truthy(t){return!!t},getSelectOption(t){return e.options.find(r=>r.value===t)},get default_selection(){return e.usingQuery?e.default_selection_count>0&&e.options.length>0?e.options[0].value:"":e.filter.formattedDefaultValue}})).actions(e=>({setDefaultValue(t){t!==null&&(e.default_value=t)},setWidth(t){e.width=t},setClearable(t){e.clearable=t},setDefaultSelection(){var a;const t=e.filter.value,r=(a=e.options.find(l=>l.value===t))==null?void 0:a.value;r?e.filter.setValue(r):e.filter.setValue(e.default_selection)}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>Q.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!1,delay:0}))}})),ti=()=>aa.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),sa=g.types.model("FilterTextInputConfigMeta",{_name:g.types.literal("text-input"),required:g.types.boolean,default_value:g.types.string}).views(e=>({get json(){const{_name:t,required:r,default_value:a}=e;return{_name:t,required:r,default_value:a}},truthy(t){return typeof t!="string"?!1:!!t.trim()}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),la=()=>sa.create({_name:"text-input",required:!1,default_value:""}),SS=`
530
+ `}})}function BC(e,t,r){const{overflow:a,rotate:l}=e.x_axis.axisLabel,o=Fe(a.on_axis);return X.getXAxis({id:"main-x-axis",type:"category",data:t,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:l,...o,formatter:r},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:!1},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:3})}function LC(e,t){const{nameAlignment:r,data_key:a,...l}=e.y_axis,{overflow:o,rotate:i}=e.y_axis.axisLabel,c=Fe(o.on_axis);return X.getYAxis({...l,type:"category",axisLabel:{rotate:i,...c,formatter:t},axisLine:{show:!0,lineStyle:{width:3}},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:!1},nameTextStyle:{fontWeight:"bold",align:r},nameLocation:"end",nameGap:15,z:3})}function qC(e,t,r){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const a=r.reduce((m,k)=>{const z=Je(k,t);return m[k.name]=$e(k,z),m},{}),l=IC(e),o=MC(e),i=tn(e.visualMap,a),{min:c,max:d}=i,u=P(e.x_axis.data_key),p=P(e.y_axis.data_key),f=P(e.heat_block.data_key),v=y.uniq(t[u.queryID].map(m=>m[u.columnKey])),_=t[u.queryID].map(m=>{const k=y.get(m,u.columnKey),z=y.get(m,p.columnKey),D=y.get(m,f.columnKey),I={value:[k,z,D]},{followVisualMap:L,color:E}=er(D,c,d,e.visualMap);return L||(I.visualMap=!1,I.itemStyle={color:E}),I});return{xAxis:BC(e,v,l.x_axis),yAxis:LC(e,l.y_axis),series:PC(e,_),tooltip:EC(e,t,l,o),grid:VC(e),visualMap:i}}function OC({conf:e,data:t,width:r,height:a,interactionManager:l,variables:o,instance:i}){const c=h.useMemo(()=>{const w=P(e.x_axis.data_key),m=P(e.y_axis.data_key);return y.keyBy(t[w.queryID],k=>`${k[w.columnKey]}---${k[m.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),d=Ie(l.triggerManager,ko.id),u=h.useCallback(w=>{const[m,k]=w.value,z=y.get(c,`${m}---${k}`,{error:"rowData is not found"});d.forEach(D=>{l.runInteraction(D.id,{...w,rowData:z})})},[c,d,l]),p=h.useRef(null),f=h.useCallback(()=>{var m;const w=(m=p.current)==null?void 0:m.getEchartsInstance();w&&de(i,w.getOption())},[i]),v=h.useMemo(()=>({click:u,finished:f}),[u,f]),_=h.useMemo(()=>qC(e,t,o),[e,t]);return n.jsx(he,{echarts:ie,option:_,ref:p,style:{width:r,height:a},onEvents:v,notMerge:!0,theme:"merico-light"})}function NC({context:e,instance:t}){const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},a,Wr),[a]),i=e.data,{width:c,height:d}=e.viewport;return!c||!d?null:n.jsx(_e,{width:c,height:d,children:n.jsx(OC,{instance:t,variables:l,width:Oe(c),height:Ne(d),data:i,conf:o,interactionManager:r})})}const GC=[{lang:"en",resources:{merico_heatmap:{viz_name:"Merico Heatmap",click_heatmap:{heatblock:{label:"Click heat block"}}}}},{lang:"zh",resources:{merico_heatmap:{viz_name:"思码逸热力图",click_heatmap:{heatblock:{label:"点击热力块"}}}}}];function FC(e){const{visualMap:t=et(),heat_block:{min:r,max:a,...l},...o}=e;return{...o,heat_block:l,visualMap:{...et(),min:r,max:a}}}function jC(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??U()}))}}}function QC(e){const{heat_block:t}=e;return{...e,heat_block:{...t,unit:t.unit??U()}}}class WC extends ee{constructor(){super(...arguments);V(this,"VERSION",4)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>({...r,version:2,config:FC(r.config)})),this.version(3,r=>({...r,version:3,config:jC(r.config)})),this.version(4,r=>({...r,version:4,config:QC(r.config)}))}}const UC={displayName:"viz.merico_heatmap.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new WC,name:"merico-heatmap",viewRender:NC,configRender:kC,createConfig:()=>({version:4,config:Wr}),triggers:[ko],translation:GC},Ur={item_badge:"_item_badge_l2t3l_1",label:"_label_l2t3l_8",value:"_value_l2t3l_20"},KC=({children:e})=>["string","number"].includes(typeof e)?n.jsx(s.Text,{size:"xs",ff:"monospace",children:e}):e,bt=h.forwardRef(({label:e,value:t,label_description:r,value_description:a},l)=>n.jsxs("div",{ref:l,className:Ur.item_badge,children:[n.jsx("div",{className:Ur.label,children:e}),n.jsxs(s.HoverCard,{shadow:"md",disabled:!a,children:[n.jsx(s.HoverCard.Target,{children:n.jsx("div",{className:Ur.value,"data-with-tooltip":!!a,children:t})}),n.jsx(s.HoverCard.Dropdown,{p:"xs",children:n.jsx(KC,{children:a})})]})]})),YC=({item:e})=>e.type!=="checkbox"?null:n.jsx(bt,{label:e.label,value:n.jsx(s.ThemeIcon,{variant:"white",radius:"xs",color:e.value?"teal":"red",w:12,h:12,miw:12,mih:12,children:e.value?n.jsx(S.IconCheck,{size:12,strokeWidth:3}):n.jsx(S.IconX,{strokeWidth:3})}),label_description:`filters.${e.key}`}),XC=({item:e})=>e.type!=="context"?null:n.jsx(bt,{label:e.key,value:e.value,label_description:`context.${e.key}`}),ZC=T.observer(({item:e})=>{const{t}=x.useTranslation(),a=e.model.value,[l,o]=a.value,i=h.useMemo(()=>!o&&!l?Number.NaN:M(o).diff(M(l),"days")+1,[l,o]);if(Number.isNaN(i))return n.jsx("span",{style:{userSelect:"none",opacity:0,visibility:"hidden"},children:"."});const c=i===1?t("filter.widget.date_range.one_day"):t("filter.widget.date_range.x_days",{count:i});return n.jsx(bt,{label:e.label,value:e.value.join(" ~ "),label_description:`filters.${e.key}`,value_description:c})}),JC=({item:e})=>e.type!=="date-range"?null:n.jsx(ZC,{item:e}),zo=({selection:e})=>(x.useTranslation(),e.length===0?null:n.jsx(s.Group,{justify:"flex-start",gap:"xs",maw:"80vw",children:e.map(t=>n.jsx(s.Pill,{size:"xs",ff:"monospace",children:t.label},t.value))})),HC=T.observer(({item:e})=>{x.useTranslation();const r=e.model.config,a=h.useMemo(()=>r.optionsByValues(e.value),[e.value,r.options]);return n.jsx(bt,{label:e.label,value:a.length,label_description:`filters.${e.key}`,value_description:n.jsx(zo,{selection:a})})}),RC=({item:e})=>e.type!=="multi-select"?null:n.jsx(HC,{item:e}),eS=T.observer(({item:e})=>{x.useTranslation();const r=e.model.config,a=h.useMemo(()=>{var l;return((l=r.options.find(o=>o.value===e.value))==null?void 0:l.label)??e.value},[e.value,r.options]);return n.jsx(bt,{label:e.label,value:a,label_description:`filters.${e.key}`})}),tS=({item:e})=>e.type!=="select"?null:n.jsx(eS,{item:e}),nS=({item:e})=>e.type!=="text-input"?null:n.jsx(bt,{label:e.label,value:n.jsx(s.Text,{maw:200,size:"xs",truncate:"end",ff:"monospace",children:e.value}),value_description:e.value}),rS=T.observer(({item:e})=>{x.useTranslation();const r=e.model.config,a=h.useMemo(()=>r.optionsByValues(e.value),[e.value,r.options]);return n.jsx(bt,{label:e.label,value:a.length,label_description:`filters.${e.key}`,value_description:n.jsx(zo,{selection:a})})}),aS=({item:e})=>e.type!=="tree-select"?null:n.jsx(rS,{item:e}),sS=T.observer(({item:e})=>{x.useTranslation();const r=e.model.config,a=h.useMemo(()=>{var l;return((l=r.options.find(o=>o.value===e.value))==null?void 0:l.label)??e.value},[e.value,r.options]);return n.jsx(bt,{label:e.label,value:a,label_description:`filters.${e.key}`,value_description:e.value})}),lS=({item:e})=>e.type!=="tree-single-select"?null:n.jsx(sS,{item:e}),Kr=({item:e})=>{switch(e.type){case"date-range":return n.jsx(JC,{item:e});case"select":return n.jsx(tS,{item:e});case"tree-single-select":return n.jsx(lS,{item:e});case"multi-select":return n.jsx(RC,{item:e});case"tree-select":return n.jsx(aS,{item:e});case"text-input":return n.jsx(nS,{item:e});case"checkbox":return n.jsx(YC,{item:e});case"context":return n.jsx(XC,{item:e});default:return null}},oS=T.observer(({conf:e})=>{const r=J().dashboardState,{all:a,keys:l}=e;return a?n.jsxs(n.Fragment,{children:[Object.entries(r.context).map(([o,i])=>n.jsx(Kr,{item:i},o)),Object.entries(r.filters).map(([o,i])=>n.jsx(Kr,{item:i},o))]}):n.jsx(n.Fragment,{children:l.map(o=>{const i=y.get(r,o);return i?n.jsx(Kr,{item:i},o):null})})}),iS=T.observer(({context:e})=>{const{value:t}=B(e.instanceData,"config"),{width:r,height:a}=e.viewport;return t?n.jsx(s.Group,{justify:"flex-start",align:"flex-start",wrap:"wrap",px:0,py:0,gap:"xs",w:r,mah:a,style:{overflow:"auto"},"data-enable-scrollbar":!0,children:n.jsx(oS,{conf:t})}):null}),Do={all:!0,keys:[]},cS={select:"filter.widget.names.select","multi-select":"filter.widget.names.multi_select","tree-select":"filter.widget.names.tree_select","tree-single-select":"filter.widget.names.tree_single_select","text-input":"filter.widget.names.text_input",checkbox:"filter.widget.names.checkbox","date-range":"filter.widget.names.date_range"},dS=({option:e,checked:t,...r})=>{const{t:a}=x.useTranslation(),l=e,o=l.type==="filter";return n.jsxs(s.Group,{gap:4,flex:1,children:[n.jsx(S.IconCheck,{size:14,opacity:t?1:0,color:"black"}),n.jsx(s.Stack,{gap:0,py:4,px:8,flex:1,styles:{root:{flexGrow:1,borderRadius:"4px"}},...r,children:n.jsxs(s.Group,{justify:"space-between",wrap:"nowrap",children:[n.jsx(s.Text,{size:"xs",children:e.label}),o&&n.jsx(s.Text,{size:"xs",c:t?"rgba(0,0,0,.8)":"dimmed",style:{flexShrink:0,flexGrow:0},children:a(cS[l.widget])})]})})]})},uS=T.observer(({value:e,onChange:t,disabled:r})=>{const{t:a}=x.useTranslation(),o=F().dashboardStateVariableOptions,i=h.useMemo(()=>{const{optionGroups:c,validValues:d}=o,u=c.map(f=>({group:a(f.group),items:f.items.map(v=>({...v,label:v.label,value:v.value,widget_label:v.label}))})),p=e.filter(f=>!d.has(f)).map(f=>({label:f,value:f,disabled:!0}));return p.length>0&&u.push({group:a("common.invalid"),items:p}),u},[o,a,e]);return n.jsx(s.MultiSelect,{size:"xs",label:a("viz.vizDashboardState.variable_selector.label"),placeholder:e.length===0?a("viz.vizDashboardState.variable_selector.placeholder"):void 0,data:i,renderOption:dS,maxDropdownHeight:600,value:e,onChange:t,disabled:r,clearable:!0})}),pS=({form:e})=>{const{t}=x.useTranslation(),r=e.watch("all");return n.jsxs(s.Stack,{gap:"xs",p:"xs",children:[n.jsx(b.Controller,{name:"all",control:e.control,render:({field:a})=>n.jsx(s.Checkbox,{size:"xs",label:t("viz.vizDashboardState.show_all"),checked:a.value,onChange:l=>a.onChange(l.currentTarget.checked)})}),n.jsx(b.Controller,{name:"keys",control:e.control,render:({field:a})=>n.jsx(uS,{disabled:r,...a})})]})};function hS({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaultsDeep({},t,Do),[t]),l=b.useForm({defaultValues:a}),{handleSubmit:o,formState:i,reset:c}=l;return h.useEffect(()=>{c(a)},[a]),n.jsxs("form",{onSubmit:o(r),children:[n.jsx(ae,{canSubmit:i.isDirty}),n.jsx(pS,{form:l})]})}const gS=[{lang:"en",resources:{vizDashboardState:{viz_name:"Dashboard State",show_all:"Show all filters and context entries",variable_selector:{label:"Select filters and context entries to show",placeholder:""}}}},{lang:"zh",resources:{vizDashboardState:{viz_name:"看板状态",show_all:"显示所有筛选器和上下文条目",variable_selector:{label:"选择要展示的筛选器和上下文",placeholder:""}}}}];class fS extends ee{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const bS={displayName:"viz.vizDashboardState.viz_name",displayGroup:"chart.groups.others",migrator:new fS,name:"vizDashboardState",viewRender:iS,configRender:hS,createConfig:()=>({version:1,config:Do}),translation:gS},yS=[{value:"#25262B",name:"Dark"},{value:"#868E96",name:"Gray"},{value:"#FA5252",name:"Red"},{value:"#E64980",name:"Pink"},{value:"#BE4BDB",name:"Grape"},{value:"#7950F2",name:"Violet"},{value:"#4C6EF5",name:"Indigo"},{value:"#228BE6",name:"Blue"},{value:"#15AABF",name:"Cyan"},{value:"#12B886",name:"Teal"},{value:"#40C057",name:"Green"},{value:"#82C91E",name:"Lime"},{value:"#FAB005",name:"Yellow"},{value:"#FD7E14",name:"Orange"}].map(e=>({name:e.name,value:e.value,type:"single",category:"basic"})),vS=[au,su,iu,ou,lu,cu],Yr=[Br,$w,t0,fx,nm,d_,z1,qp,Ug,ty,Wy,G0,Mv,Bb,fw,B_,dx,d0,oC,UC,_C,af,bS],Io=Yr.reduce((e,t)=>(e[t.name]={displayName:t.displayName,displayGroup:t.displayGroup},e),{}),Mo=()=>({id:"dashboard",version:Ss,manifest:{viz:Yr,color:[...yS,...vS]}}),Ct=new fu,R={pluginManager:Xe("pluginManager"),vizManager:Xe("vizManager"),colorManager:Xe("colorManager"),panelAddonManager:Xe("panelAddonManager"),instanceScope:{panelModel:Xe("panelModel"),vizInstance:Xe("vizInstance"),interactionManager:Xe("interactionManager"),migrator:Xe("migrator"),operationManager:Xe("operationManager"),triggerManager:Xe("triggerManager")}},Xr=()=>{try{Ct.install(Mo())}catch{}const e=new tu(Ct),t=new gu(Ct),r=new uu(Ct);return{pluginManager:Ct,vizManager:e,colorManager:t,panelAddonManager:r}},rt=h.createContext(Xr());try{Ct.install(Mo())}catch{}const wn=me.createInstance({debug:!1,fallbackLng:"en",interpolation:{escapeValue:!1},resources:{en:Hd,zh:Rd}}).use(ad).use(x.initReactI18next);wn.init(),Yr.forEach(e=>{var t;(t=e.translation)==null||t.forEach(r=>{wn.addResourceBundle(r.lang,"translation",{viz:r.resources},!0,!0)})});function Vo({lang:e,children:t}){return h.useEffect(()=>{wn.changeLanguage(e)},[e]),n.jsx(x.I18nextProvider,{i18n:wn,children:t})}M.extend(pd),M.extend(hd),M.extend(gd),M.extend(fd),M.extend(bd),M.extend(yd),M.extend(vd),M.extend(_d),M.extend(xd),M.extend(wd),M.extend(Sd),M.extend(Td),M.extend(kd),M.extend(zd),M.extend(Dd),M.extend(md),M.extend(Cd),M.extend(Id),M.extend(Md),M.extend(Vd),M.extend(Pd),M.extend(Ad),M.extend($d),M.extend(Ed),M.extend(Bd),M.extend(Ld),M.extend(qd),M.extend(Od),M.extend(Nd),M.extend(Gd),M.extend(jd),M.extend(Qd),M.extend(Fd),M.tz.setDefault("UTC"),M.updateLocale("en",{weekStart:1});function _S(e){e=e||{};const t=Object.keys(e).sort(),r=[];for(let a=0;a<t.length;a++){const l=t[a];if(l!="authentication"&&e[l])r.push(t[a]+"="+(typeof e[l]=="object"?JSON.stringify(e[l]):e[l]));else{const o=Object.keys(e[l]).sort();for(let i=0;i<o.length;i++){const c=o[i];c!="sign"&&e[l][c]&&r.push(o[i]+"="+(typeof e[l][c]=="object"?JSON.stringify(e[l][c]):e[l][c]))}}}return r.sort().join("&")}function xS(e,t){let r=_S(e);return r+="&key="+t,Zd.MD5(r).toString().toUpperCase()}class Po{constructor(){this.type="default_api_client",this.baseURL="http://localhost:31200",this.app_id="",this.app_secret=""}getAuthentication(t){if(!this.app_id||!this.app_secret)return;const r=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:r,sign:xS({app_id:this.app_id,nonce_str:r,...t},this.app_secret)}}getRequest(t,r){return(a,l,o,i)=>{const c=this.buildHeader(o),d=this.buildAxiosConfig(t,a,l,o,c,r);return Se(d).then(u=>i?u:u.data).catch(u=>{if(Se.isCancel(u))return Promise.reject(u);const p=u,f=y.get(p,"response.data.detail.message",p.message);return Promise.reject(new Error(f))})}}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}buildAxiosConfig(t,r,a,l,o,i){const c={baseURL:this.baseURL,method:t,url:r,params:t==="GET"?a:l.params,headers:o,signal:i};return["POST","PUT"].includes(t)&&(c.data=l.string?JSON.stringify(a):a,c.data.authentication=this.getAuthentication(c.data)),c}buildHeader(t){const r=window.localStorage.getItem("token");return{"X-Requested-With":"XMLHttpRequest","Content-Type":t.string?"application/x-www-form-urlencoded":"application/json",authorization:r?`bearer ${r}`:"",...t.headers}}}class wS{constructor(t){this.implementation=t}getRequest(t,r){return this.implementation.getRequest(t,r)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}class Ao extends Po{constructor(){super(...arguments);V(this,"makeQueryENV",null)}query(r){return async(a,l={})=>{var o;return a.env||(a.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.post(r)("/query",a,l)}}httpDataSourceQuery(r){return async(a,l={})=>{var o;return a.env||(a.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",r)("/query",a,l,!0)}}structure(r){return async(a,l={})=>this.post(r)("/query/structure",a,l)}mericoMetricInfo(r){return async(a,l={})=>this.post(r)("/query/merico_metric_info",a,l,!0)}mericoMetricQuery(r){return async(a,l={})=>this.post(r)("/query",a,l,!0)}}class $o{constructor(t){this.implementation=t}query(t){return this.implementation.query(t)}httpDataSourceQuery(t){return this.implementation.httpDataSourceQuery(t)}structure(t){return this.implementation.structure(t)}mericoMetricInfo(t){return this.implementation.mericoMetricInfo(t)}mericoMetricQuery(t){return this.implementation.mericoMetricQuery(t)}getRequest(t,r){return this.implementation.getRequest(t,r)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}const Et=new Ao;function Zr(e){Et.baseURL!==e.apiBaseURL&&(Et.baseURL=e.apiBaseURL),e.app_id&&(Et.app_id=e.app_id),e.app_secret&&(Et.app_secret=e.app_secret),e.makeQueryENV&&(Et.makeQueryENV=e.makeQueryENV)}const Eo=new $o(Et),Ve=Eo,Jr=g.types.model("MockContextMeta",{current:g.types.optional(g.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get keySet(){return new Set(this.keys)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},defaults(t){e.current={...t,...e.current}},get(t){return e.current[t]},set(t,r){e.current[t]=r}}));function Hr(e){return{current:e}}const mS=g.types.model("PanelStyleBorderMeta",{enabled:g.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),Bo=g.types.model("PanelStyleMeta",{border:mS}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),Lo=g.types.model("PanelTitleMeta",{show:g.types.optional(g.types.boolean,!0)}).views(e=>({get json(){const{show:t}=e;return{show:t}}})).actions(e=>({setShow(t){e.show=t}})),qo=g.types.model("VariableMeta",{name:g.types.string,size:g.types.string,weight:g.types.string,color:g.types.union(g.types.model({type:g.types.literal("static"),staticColor:g.types.string}),g.types.model({type:g.types.literal("continuous"),valueRange:g.types.array(g.types.number),colorRange:g.types.array(g.types.string)}),g.types.model({type:g.types.literal("piecewise")})),formatter:g.types.model({output:g.types.enumeration("Output",["number","percent"]),average:g.types.optional(g.types.boolean,!1),mantissa:g.types.number,trimMantissa:g.types.optional(g.types.boolean,!1),absolute:g.types.optional(g.types.boolean,!1)}),data_field:g.types.string,aggregation:g.types.union(g.types.model({type:g.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:g.types.frozen(),fallback:g.types.optional(g.types.string,"0")}),g.types.model({type:g.types.literal("quantile"),config:g.types.model({p:g.types.number}),fallback:g.types.optional(g.types.string,"0")}),g.types.model({type:g.types.literal("pick_record"),config:g.types.model({method:g.types.enumeration("Pick Record Method",["first","last"])}),fallback:g.types.optional(g.types.string,"0")}),g.types.model({type:g.types.literal("custom"),config:g.types.model({func:g.types.string}),fallback:g.types.optional(g.types.string,"0")}))}).views(e=>({get json(){const{name:t,size:r,weight:a,color:l,formatter:o,data_field:i,aggregation:c}=e;return y.cloneDeep({name:t,size:r,color:l,weight:a,formatter:o,data_field:i,aggregation:c})}})),Oo=g.types.model("PanelVizMeta",{type:g.types.string,conf:g.types.frozen()}).views(e=>({get json(){return{conf:e.conf,type:e.type}}})).actions(e=>({setType(t){e.type=t},setConf(t){y.isEqual(e.conf,t)||(e.conf=t)}})),No=g.types.model({id:g.types.string,name:g.types.optional(g.types.string,""),title:Lo,description:g.types.string,queryIDs:g.types.array(g.types.string),viz:Oo,style:Bo,variables:g.types.optional(g.types.array(qo),[])}).views(e=>({get json(){const{id:t,name:r,title:a,description:l,queryIDs:o}=e;return{id:t,viz:e.viz.json,name:r,style:e.style.json,title:a.json,queryIDs:[...o],variables:e.variables.map(i=>i.json),description:l}},get queryIDSet(){return new Set(e.queryIDs)}})).actions(e=>({setID(t){e.id=t},setName(t){e.name=t},setDescription(t){e.description=t},addQueryID(t){e.queryIDSet.has(t)||e.queryIDs.push(t)},removeQueryID(t){if(!e.queryIDSet.has(t))return;const r=new Set(e.queryIDSet);r.delete(t),e.queryIDs=g.cast(Array.from(r))},setQueryIDs(t){e.queryIDs=g.cast(t)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)}}));var j=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e.Transform="transform",e.MericoMetricSystem="merico_metric_system",e))(j||{});const Go=g.types.model("DBQueryMeta",{_type:g.types.enumeration([j.MySQL,j.Postgresql]),sql:g.types.string}).views(e=>({get base(){return g.getParent(e)},get valid(){return!!e.sql},get json(){const{sql:t,_type:r}=e;return{sql:t,_type:r}}})).actions(e=>({setSQL(t){e.sql=t}})),CS=e=>Go.create({_type:e,sql:""}),Fo=g.types.model("HTTPQueryMeta",{_type:g.types.literal(j.HTTP),react_to:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get valid(){return!0},get json(){const{react_to:t,_type:r}=e;return tt({react_to:t,_type:r})}})).actions(e=>({setReactTo(t){e.react_to.length=0,e.react_to.push(...t)}})),SS=()=>Fo.create({_type:j.HTTP,react_to:[]}),jo=g.types.model("TransformQueryMeta",{_type:g.types.literal(j.Transform),dep_query_ids:g.types.optional(g.types.array(g.types.string),[]),react_to:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get valid(){return e.dep_query_ids.length>0},get json(){const{dep_query_ids:t,_type:r,react_to:a}=e;return tt({dep_query_ids:t,_type:r,react_to:a})}})).actions(e=>({setDependantQueryIDs(t){e.dep_query_ids.length=0,e.dep_query_ids.push(...t)},setReactTo(t){e.react_to.length=0,e.react_to.push(...t)}})),TS=()=>jo.create({_type:j.Transform,dep_query_ids:[]}),Qo=g.types.model("MetricFilterColMeta",{dimension:g.types.optional(g.types.string,""),variable:g.types.optional(g.types.string,"")}).views(e=>({get allEmpty(){return!e.dimension&&!e.variable},get json(){const{dimension:t,variable:r}=e;return{dimension:t,variable:r}}})).actions(e=>({removeSelf(){g.getParent(e,2).removeFilter(e)},setDimension(t){e.dimension=t??"",e.allEmpty&&this.removeSelf()},setVariable(t){e.variable=t??"",e.allEmpty&&this.removeSelf()}})),Rr=g.types.model("MericoMetricQueryMeta",{_type:g.types.literal(j.MericoMetricSystem),id:g.types.optional(g.types.string,""),type:g.types.optional(g.types.enumeration("MetricType",["derived","combined"]),"derived"),filters:g.types.optional(g.types.array(Qo),[]),groupBys:g.types.optional(g.types.array(g.types.string),[]),timeQuery:g.types.model({enabled:g.types.optional(g.types.boolean,!1),range_variable:g.types.optional(g.types.string,""),unit_variable:g.types.optional(g.types.string,""),timezone:g.types.optional(g.types.string,"PRC"),stepKeyFormat:g.types.optional(g.types.string,"YYYY-MM-DD")}),useDefaultValues:g.types.optional(g.types.boolean,!1)}).views(e=>({get query(){return g.getParent(e)},get valid(){return!!e.id},get json(){const{id:t,type:r,filters:a,groupBys:l,timeQuery:o,useDefaultValues:i,_type:c}=e;return tt({id:t,type:r,filters:a.map(d=>d.json),groupBys:l,timeQuery:o,useDefaultValues:i,_type:c})},get usedFilterDimensionKeys(){const t=e.filters.map(r=>r.dimension).filter(r=>!!r);return new Set(t)},get usedFilterVariableSet(){const t=[...e.filters.map(r=>r.variable)].filter(r=>!!r);return new Set(t)},get usedTimeQueryVariableSet(){const t=[e.timeQuery.range_variable,e.timeQuery.unit_variable].filter(r=>!!r);return new Set(t)},get groupByValues(){const t=e.groupBys.map(r=>r.replace(/^(.+)\s->\s(.*)/,"$1"));return Array.from(new Set(t))}})).actions(e=>({reset(){e.filters.length=0,e.groupBys.length=0,e.timeQuery.enabled=!1,e.timeQuery.range_variable="",e.timeQuery.unit_variable="",e.useDefaultValues=!1,"data"in e.query&&(e.query.setData([]),e.query.setError(null))},setID(t){t!==e.id&&this.reset(),e.id=t},setType(t){t!=="derived"&&t!=="combined"||(e.type=t)},addFilter(t,r){t&&e.usedFilterDimensionKeys.has(t)||e.filters.push(Qo.create({dimension:t,variable:r}))},removeFilter(t){g.destroy(t)},setGroupBys(t){e.groupBys.length=0,e.groupBys.push(...t)},setRangeVariable(t){e.timeQuery.range_variable=t??""},setUnitVariable(t){e.timeQuery.unit_variable=t??""},setTimeQueryEnabled(t){e.timeQuery.enabled=t,t?e.groupBys.length>1&&(e.groupBys.length=0):(e.timeQuery.range_variable="",e.timeQuery.unit_variable="")},setUseDefaultValues(t){e.useDefaultValues=t}})),Wo=()=>Rr.create({_type:j.MericoMetricSystem,id:"",type:"derived",filters:[],groupBys:[],timeQuery:{range_variable:"",unit_variable:"",timezone:"PRC",stepKeyFormat:"YYYY-MM-DD"},useDefaultValues:!1}),Uo=g.types.model("QueryMeta",{id:g.types.string,name:g.types.string,key:g.types.string,type:g.types.enumeration("DataSourceType",[j.Postgresql,j.MySQL,j.HTTP,j.Transform,j.MericoMetricSystem]),config:g.types.union(Go,Fo,jo,Rr),pre_process:g.types.optional(g.types.string,""),post_process:g.types.optional(g.types.string,""),run_by:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get valid(){const{id:t,name:r,key:a,type:l,config:o}=e;return o.valid&&!!t&&!!r&&!!a&&!!l},get json(){const{id:t,name:r,key:a,type:l,config:o,pre_process:i,post_process:c,run_by:d}=e;return tt({id:t,name:r,key:a,type:l,config:o.json,pre_process:i,post_process:c,run_by:d})}})).actions(e=>({setName(t){e.name=t},setKey(t){e.key=t},setType(t){switch(e.type=t,t){case j.HTTP:e.config=SS();break;case j.MySQL:case j.Postgresql:e.config=CS(t);break;case j.Transform:e.config=TS();break;case j.MericoMetricSystem:e.config=Wo();break;default:throw new Error(`Unexpected query type[${t}]`)}},setRunBy(t){e.run_by.length=0,e.run_by.push(...t)},setPreProcess(t){e.pre_process=t},setPostProcess(t){e.post_process=t}})),Ko=g.types.model("LayoutItemMeta",{id:g.types.identifier,panelID:g.types.string,x:g.types.number,y:g.types.maybeNull(g.types.number),w:g.types.number,h:g.types.number,moved:g.types.optional(g.types.boolean,!1),static:g.types.optional(g.types.boolean,!1)}).views(e=>({get json(){const{id:t,panelID:r,x:a,y:l,w:o,h:i,moved:c}=e;return{h:i,w:o,x:a,y:l===null?0:l,id:t,moved:c,static:e.static,panelID:r}},get contentModel(){return g.getRoot(e).content},get panel(){const{panelID:t}=e;return this.contentModel.panels.findByID(t)},get layoutProperies(){const{id:t,x:r,y:a,w:l,h:o,moved:i}=e;return{id:t,i:t,x:r,y:a===null?1/0:a,w:l,h:o,moved:i,static:e.static}}})).actions(e=>({set(t){const{isDraggable:r,x:a,y:l,w:o,h:i,moved:c}=t;e.x=a,e.y=l,e.w=o,e.h=i,e.moved=!!c,e.static=!!t.static},setWidth(t){e.w=t},setHeight(t){e.h=t}})),Yo=g.types.model("LayoutSetMeta",{id:g.types.identifier,name:g.types.string,breakpoint:g.types.number,list:g.types.optional(g.types.array(Ko),[])}).views(e=>({get contentModel(){return g.getRoot(e).content},get json(){const{id:t,name:r,breakpoint:a,list:l}=e;return{id:t,name:r,breakpoint:a,list:l.map(o=>tt(o.json))}},jsonByPanelIDSet(t){const{id:r,name:a,breakpoint:l,list:o}=e;return{id:r,name:a,breakpoint:l,list:o.filter(i=>t.has(i.panelID)).map(i=>tt(i.json))}},findByID(t){return e.list.find(r=>r.id===t)},findByPanelID(t){return e.list.find(r=>r.panelID===t)}})).actions(e=>({setName(t){e.name=t},setBreakpoint(t){e.breakpoint=t},addLayout(t){e.list.push(t)},addNewLayout(t){e.list.push({id:Ue.v4(),panelID:t,x:0,y:1/0,w:18,h:300,static:!1,moved:!1})},removeByPanelID(t){const r=e.list.findIndex(a=>a.panelID===t);r>=0&&e.list.splice(r,1)},removeByPanelIDs(t){for(;t.length>0;){const r=t.pop();r&&this.removeByPanelID(r)}},updateLayoutItem(t){const r=e.list.find(a=>a.id===t.i);if(!r){console.error("Trying to update a layout that doesn't exist"),console.log({strangeLayoutItem:t});return}r.set(t)}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>{const t=e.list.length,r=e.contentModel.panels.list.length;return{match:t===r,layoutCount:t,panelCount:r}},({match:t,panelCount:r,layoutCount:a})=>{if(t)return;const l={id:"layout panel count mismatch",title:"Error detected, please don't save changes.",message:`${a} layout items against and ${r} panels.`,color:"red",autoClose:!1};Ye.showNotification(l),Ye.updateNotification(l)},{fireImmediately:!0,delay:0}))}})),Xo=g.types.model("SQLSnippetMeta",{key:g.types.string,value:g.types.string}).views(e=>({get json(){const{key:t,value:r}=e;return{key:t,value:r}}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.value=t}}));var A=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TreeSingleSelect="tree-single-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(A||{});const ea=g.types.optional(g.types.enumeration(["intersect","reset"]),"intersect"),ta=g.types.model("FilterCheckboxConfigMeta",{_name:g.types.literal("checkbox"),description:g.types.optional(g.types.string,""),default_value:g.types.boolean}).views(e=>({get json(){const{_name:t,description:r,default_value:a}=e;return{_name:t,description:r,default_value:a}},get isDescriptionEmpty(){const{description:t}=e;return t===""||t==="<p></p>"}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDescription(t){e.description=t}})),Zo=()=>ta.create({_name:"checkbox",description:"",default_value:!1}),Jo=()=>[{key:"d",value:"yesterday",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(1,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"yesterday"}}},{key:"w",value:"last week",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(1,"week").startOf("week").toDate(),M(e).subtract(1,"week").endOf("week").toDate()],shortcut:"last week"}}},{key:"m",value:"last month",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(1,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()],shortcut:"last month"}}},{key:"m2",value:"last 2 months",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(2,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()],shortcut:"last 2 months"}}},{key:"m3",value:"last 3 months",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(3,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()],shortcut:"last 3 months"}}},{key:"y",value:"last year",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(1,"year").startOf("year").toDate(),M(e).subtract(1,"year").endOf("year").toDate()],shortcut:"last year"}}},{key:"d7",value:"recent 7 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(7,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 7 days"}}},{key:"d30",value:"recent 30 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(30,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 30 days"}}},{key:"d60",value:"recent 60 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(60,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 60 days"}}},{key:"d90",value:"recent 90 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(90,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 90 days"}}},{key:"d180",value:"recent 180 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(180,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 180 days"}}},{key:"d365",value:"recent 365 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(365,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 365 days"}}},{key:"d",value:"today",group:"this",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("day").toDate(),M(e).endOf("day").toDate()],shortcut:"today"}}},{key:"w",value:"this week",group:"this",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("week").toDate(),M(e).endOf("week").toDate()],shortcut:"this week"}}},{key:"m",value:"this month",group:"this",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("month").toDate(),M(e).endOf("month").toDate()],shortcut:"this month"}}},{key:"y",value:"this year",group:"this",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("year").toDate(),M(e).endOf("year").toDate()],shortcut:"this year"}}},{key:"w",value:"this week so far",group:"this_so_far",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("week").toDate(),M(e).toDate()],shortcut:"this week so far"}}},{key:"m",value:"this month so far",group:"this_so_far",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("month").toDate(),M(e).toDate()],shortcut:"this month so far"}}},{key:"y",value:"this year so far",group:"this_so_far",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("year").toDate(),M(e).toDate()],shortcut:"this year so far"}}}];function mn(e){if(!e)return null;const r=Jo().find(a=>a.value===e);return r?r.getRange():null}function Ho(){return y.groupBy(Jo(),"group")}function Ro(e){try{if(e.default_shortcut){const r=mn(e.default_shortcut);if(r)return{value:r.value.map(a=>M(a).toDate()),shortcut:e.default_shortcut}}return{value:e.default_value.map(r=>r===null?r:M.tz(r,"UTC").toDate()??r),shortcut:null}}catch(t){return console.error(t),{value:[null,null],shortcut:null}}}function ei(e,t){return e.map(r=>{try{return r?M.tz(r,"UTC").toISOString():null}catch{return console.log(`[date-range] failed parsing ${r}`),null}})}const kS=g.types.model("FilterDateRangeConfigMeta",{_name:g.types.literal("date-range"),required:g.types.boolean,inputFormat:g.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:g.types.optional(g.types.array(g.types.union(g.types.Date,g.types.null)),[null,null]),default_shortcut:g.types.optional(g.types.string,""),clearable:g.types.boolean,max_days:g.types.optional(g.types.number,0),allowSingleDateInRange:g.types.optional(g.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:r,required:a,clearable:l,inputFormat:o,default_value:i,default_shortcut:c,allowSingleDateInRange:d}=e;return{_name:t,max_days:r,required:a,clearable:l,inputFormat:o,default_value:ei(i),default_shortcut:c,allowSingleDateInRange:d}},truthy(t){try{const{value:r}=t;return Array.isArray(r)&&r.length===2&&r.every(a=>!!a)}catch(r){return console.error(r),!1}},get filter(){return g.getParent(e)},get dateStringsValue(){try{const t=this.filter.value,[r,a]=t.value,l=r?M(r).format(e.inputFormat):"",o=a?M(a).format(e.inputFormat):"";return[l,o]}catch(t){return console.error(t),["",""]}}})).actions(e=>({setFilterValue(t){try{e.filter.setValue(t)}catch(r){console.error(r)}}})).actions(e=>({setRequired(t){e.required=t},setClearable(t){e.clearable=t},setInputFormat(t){t&&(e.inputFormat=t)},setDefaultValue(t){e.default_value.length=0,e.default_value.push(...t.value),e.setFilterValue(t)},setDefaultShortcut(t){if(e.default_shortcut=t??"",!t)return;const r=mn(e.default_shortcut);r&&e.setFilterValue(r)},setMaxDays(t){const r=Number(t);Number.isFinite(r)&&(e.max_days=r,r>0&&(e.clearable=!0))},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),na=g.types.snapshotProcessor(kS,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(r=>r===null?null:M.tz(r,"UTC").toDate())}},postProcessor(e){const{default_value:t,...r}=e;return{...r,default_value:ei(t,r.inputFormat)}}}),ti=()=>na.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),ni=g.types.model({label:g.types.string,value:g.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),ra=g.types.model("FilterConfigModel_BaseSelect",{static_options:g.types.optional(g.types.array(ni),[]),options_query_id:g.types.optional(g.types.string,""),default_selection_count:g.types.optional(g.types.number,0),required:g.types.optional(g.types.boolean,!1)}).views(e=>({get contentModel(){return g.getRoot(e).content},get filter(){return g.getParent(e)},get usingQuery(){return!!e.options_query_id}})).views(e=>({get optionsLoading(){if(!e.usingQuery)return!1;const{state:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t==="loading"},get options(){if(!e.usingQuery)return e.static_options;const{data:t,state:r}=e.contentModel.getDataStuffByID(e.options_query_id);return r==="error"?[]:Array.isArray(t)?t.filter(a=>"label"in a&&"value"in a):[]},get optionValuesSet(){return new Set(this.options.map(t=>t.value))}})).actions(e=>({setRequired(t){e.required=t},addStaticOption(t){e.static_options.push(t)},removeStaticOption(t){e.static_options.splice(t,1)},replaceStaticOptions(t){e.static_options.forEach(a=>g.detach(a));const r=t.map(a=>ni.create(a));e.static_options.replace(r)},setDefaultSelectionCount(t){const r=Number(t);Number.isFinite(r)&&(e.default_selection_count=r)},setOptionsQueryID(t){e.options_query_id=t??""}})),aa=g.types.compose("FilterMultiSelectConfigMeta",g.types.model({_name:g.types.literal("multi-select"),min_width:g.types.optional(g.types.string,""),default_value:g.types.optional(g.types.array(g.types.string),[]),default_value_mode:ea}),ra).views(e=>({get json(){const{_name:t,default_value:r,default_value_mode:a,required:l,min_width:o,static_options:i,options_query_id:c,default_selection_count:d}=e;return tt({_name:t,required:!!l,min_width:o,default_value:r,static_options:i,options_query_id:c,default_value_mode:a,default_selection_count:d})},get defaultSelection(){const t=e.filter.formattedDefaultValue;return Array.isArray(t)&&t.length>0||!e.usingQuery?t:e.options.slice(0,e.default_selection_count).map(r=>r.value)},optionsByValues(t){if(!Array.isArray(t)||t.length===0)return[];const r=new Set(t);return e.options.filter(a=>r.has(a.value))},initialSelection(t){return t||this.defaultSelection},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=g.cast(t)},setDefaultValueMode(t){t!=="intersect"&&t!=="reset"||(e.default_value_mode=t)},setMinWidth(t){e.min_width=t},applyDefaultSelection(){if(e.optionsLoading)return;if(e.default_value_mode==="reset"){e.filter.setValue(e.defaultSelection);return}const t=new Set(e.options.map(l=>l.value)),a=(e.filter.value??[]).filter(l=>t.has(l));a.length>0?e.filter.setValue(a):e.filter.setValue(e.defaultSelection)}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>Q.toJS(e.defaultSelection),e.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),ri=()=>aa.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),sa=g.types.compose("FilterConfigModel_Select",g.types.model({_name:g.types.literal("select"),default_value:g.types.string,width:g.types.optional(g.types.string,""),clearable:g.types.optional(g.types.boolean,!1)}),ra).views(e=>({get json(){const{_name:t,clearable:r,default_value:a,required:l,width:o,static_options:i,options_query_id:c,default_selection_count:d}=e;return tt({_name:t,width:o,required:l,clearable:r,default_value:a,static_options:i,options_query_id:c,default_selection_count:d})},truthy(t){return!!t},getSelectOption(t){return e.options.find(r=>r.value===t)},get default_selection(){return e.usingQuery?e.default_selection_count>0&&e.options.length>0?e.options[0].value:"":e.filter.formattedDefaultValue}})).actions(e=>({setDefaultValue(t){t!==null&&(e.default_value=t)},setWidth(t){e.width=t},setClearable(t){e.clearable=t},setDefaultSelection(){var a;const t=e.filter.value,r=(a=e.options.find(l=>l.value===t))==null?void 0:a.value;r?e.filter.setValue(r):e.filter.setValue(e.default_selection)}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>Q.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!1,delay:0}))}})),ai=()=>sa.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),la=g.types.model("FilterTextInputConfigMeta",{_name:g.types.literal("text-input"),required:g.types.boolean,default_value:g.types.string}).views(e=>({get json(){const{_name:t,required:r,default_value:a}=e;return{_name:t,required:r,default_value:a}},truthy(t){return typeof t!="string"?!1:!!t.trim()}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),oa=()=>la.create({_name:"text-input",required:!1,default_value:""}),zS=`
531
531
  // row
532
532
  {
533
533
  label: string;
@@ -536,21 +536,21 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
536
536
  description?: string;
537
537
  disabled?: boolean;
538
538
  }
539
- `,ni=()=>{const{t:e}=x.useTranslation(),[t,r]=h.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{variant:"subtle",size:"compact-sm",onClick:()=>r(a=>!a),children:e(t?"common.actions.close":"filter.widget.common.see_data_structure")}),n.jsx(s.Collapse,{in:t,children:n.jsx(Oe.CodeHighlight,{language:"typescript",withCopyButton:!1,code:SS})})]})},TS={[V.Checkbox]:"true",[V.DateRange]:"[new Date('2023-01-01 00:00:00'), new Date('2024-01-01 00:00:00')]",[V.MultiSelect]:"[]",[V.Select]:'""',[V.TreeSelect]:"[]",[V.TreeSingleSelect]:'""',[V.TextInput]:'""'},kS=e=>["function getDefaultValue(filter, utils, context) {",` return ${TS[e]};`,"}"].join(`
540
- `),St=T.observer(({filter:e})=>{const{t}=x.useTranslation();return n.jsx(nr,{label:"",title:t("filter.field.custom_default_value.title"),triggerLabel:t("filter.field.custom_default_value.trigger"),value:e.default_value_func,onChange:e.setDefaultValueFunc,defaultValue:kS(e.type),triggerButtonProps:{size:"xs",color:"grape",sx:{flexGrow:0,alignSelf:"flex-start"},leftSection:n.jsx(S.IconMathFunction,{size:16})},description:n.jsx(s.Alert,{title:t("filter.field.custom_default_value.tips"),color:"gray",mb:16,children:n.jsxs(s.List,{size:"xs",type:"ordered",children:[n.jsx(s.List.Item,{children:t("filter.field.custom_default_value.tip_1")}),n.jsx(s.List.Item,{children:t("filter.field.custom_default_value.tip_2")})]})})})}),Cn=T.observer(({value:e,onChange:t})=>{const{t:r}=x.useTranslation(),a=W(),l=F(),o=h.useMemo(()=>l.queries.options,[l.queries.current]),i=o.length===0,c=d=>{a.editor.setPath(["_QUERIES_",d])};return n.jsx(s.Select,{label:n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Text,{fw:500,size:"sm",children:r("filter.widget.common.use_query_data_as_options")}),e&&n.jsx(s.Button,{size:"xs",leftSection:n.jsx(S.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>c(e),children:r("query.open")})]}),data:o,value:e,onChange:Z(t),allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:i,error:i?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),ri={stroke:1.5,color:"currentColor",opacity:1,size:18},ai={intersect:n.jsx(S.IconLayersIntersect,{...ri}),reset:n.jsx(S.IconLayersSubtract,{...ri})},zS=({option:e,checked:t})=>n.jsxs(s.Group,{flex:"1",gap:"xs",children:[ai[e.value],e.label]}),oa=T.observer(({config:e})=>{const{t,i18n:r}=x.useTranslation(),a=h.useMemo(()=>[{label:t("filter.widget.common.default_value_mode.intersect"),value:"intersect"},{label:t("filter.widget.common.default_value_mode.reset"),value:"reset"}],[r.language]),{default_value_mode:l}=e;return n.jsx(s.Select,{leftSection:ai[l]??null,label:t("filter.widget.common.default_value_mode.label"),data:a,value:l,onChange:e.setDefaultValueMode,renderOption:zS})}),DS=T.observer(function({filter:t}){const{t:r}=x.useTranslation(),a=t.config;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Checkbox,{checked:a.required,onChange:l=>a.setRequired(l.currentTarget.checked),label:r("filter.widget.select.required")}),n.jsx(St,{filter:t})]}),n.jsx(s.TextInput,{label:r("filter.widget.common.min_width"),value:a.min_width,onChange:l=>a.setMinWidth(l.currentTarget.value),placeholder:"200px"}),n.jsx(s.Divider,{label:r("filter.widget.common.fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(s.Checkbox,{checked:a.treeCheckStrictly,onChange:l=>a.setTreeCheckStrictly(l.currentTarget.checked),label:r("filter.widget.tree_select.strictly")}),n.jsx(Cn,{value:a.options_query_id,onChange:a.setOptionsQueryID}),n.jsx(s.NumberInput,{value:a.default_selection_count,onChange:a.setDefaultSelectionCount,label:r("filter.widget.common.default_selection_count")}),n.jsx(oa,{config:a}),n.jsx(ni,{})]})}),ia=({errorMessage:e})=>{const{t}=x.useTranslation();return e?n.jsx(s.Text,{c:"red",size:"12px",children:e}):n.jsx(s.Text,{c:"dimmed",size:"12px",children:t("filter.widget.common.selector_option_empty")})},IS=({rotate:e,onClick:t})=>n.jsx("svg",{onClick:t,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${e})`,children:n.jsx("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),si=({expanded:e,isLeaf:t,value:r,onClick:a,...l})=>t?n.jsx("span",{style:{width:"14px",display:"inline-block"}}):n.jsx(IS,{rotate:e?"0":"-90",onClick:a,...l}),MS=({onClick:e})=>n.jsxs("svg",{onClick:e,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),n.jsx("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),n.jsx("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),n.jsx("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),li=({onClick:e,...t})=>n.jsx(MS,{onClick:e,...t}),AS=dt.createStyles((e,{radius:t=4,width:r,name:a})=>({root:{borderRadius:s.getRadius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,position:"absolute",width:`${r} !important`,backgroundColor:"#fff",border:"1px solid #e9ecef",boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{padding:0},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"0px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},"&.rc-tree-select-tree-treenode-disabled":{color:"#aaa",".rc-tree-select-tree-title, .rc-tree-select-tree-iconEle":{cursor:"not-allowed"},".rc-tree-select-tree-iconEle":{"svg .border":{fill:"#ced4da"}}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",width:"100%",padding:"8px 0",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),PS=(e,t,r,a)=>{const l=h.useMemo(()=>{if(!a)return y.cloneDeep(e.filter(f=>!f.disabled));const u=[],p=f=>{f.disabled||u.push(f),f.children.forEach(p)};return e.forEach(p),u},[e,a]),o=h.useMemo(()=>new Set(l.map(u=>u.value)),[l]),i=h.useMemo(()=>new Set(t.map(u=>u.value)),[t]),c=h.useMemo(()=>i.size!==o.size?!1:Array.from(o).every(u=>i.has(u)),[i,o]);return{allValueSet:o,selectedValueSet:i,toggleSelectAll:()=>{if(c){r([]);return}const u=Array.from(l);r(u)},allSelected:c}},VS={root:{cursor:"pointer",backgroundColor:"#FFF","&:hover":{backgroundColor:"var(--mantine-color-default-hover)"},"input, .mantine-Checkbox-labelWrapper":{cursor:"pointer",pointerEvents:"none"}}},$S=({disabled:e,radius:t,style:r,label:a,value:l,onChange:o,treeData:i,errorMessage:c,required:d,treeCheckStrictly:u})=>{const{t:p}=x.useTranslation(),{classes:f,cx:v}=AS({radius:t,width:r.width,name:"FilterTreeSelectWidget"}),[_,w]=h.useState(!1),m=L=>{w(L)},k=_&&(l==null?void 0:l.length)>0,z=PS(i,l,o,u),[D,I]=h.useState("");return n.jsxs(s.Stack,{gap:3,children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsxs(s.Text,{className:f.label,size:"sm",children:[a,d&&n.jsx("span",{className:f.required,"aria-hidden":"true",children:"*"})]}),k&&n.jsx(s.Tooltip,{label:p("filter.widget.common.x_selected",{count:l.length}),children:n.jsx(s.Badge,{variant:"light",children:l.length})})]}),n.jsx(qn,{disabled:e,allowClear:{clearIcon:n.jsx(s.CloseButton,{size:"sm"})},treeCheckStrictly:u,labelInValue:!0,className:v(f.root,"check-select"),dropdownClassName:v(f.dropdown,""),onDropdownVisibleChange:m,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:r,listHeight:510,treeLine:!0,switcherIcon:si,treeIcon:li,maxTagTextLength:10,value:l,treeData:i,notFoundContent:n.jsx(ia,{errorMessage:c}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:qn.SHOW_PARENT,onChange:o,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:()=>p("filter.widget.common.x_selected",{count:l.length}),searchValue:D,onSearch:I,dropdownRender:L=>n.jsxs(n.Fragment,{children:[z.allValueSet.size>0&&!D&&n.jsx(s.Group,{px:"xs",pt:8,pb:8,onClick:z.toggleSelectAll,styles:VS,children:n.jsx(s.Checkbox,{size:"xs",checked:z.allSelected,onChange:y.noop,label:p("common.actions.select_all")})}),n.jsx(s.Divider,{}),L]})})]})},ES=T.observer(({label:e,config:t,value:r,onChange:a})=>{const{treeData:l,treeDataLoading:o,errorMessage:i}=t,c=v=>{const _=v.map(w=>w.value);a(_,!1)},d=h.useMemo(()=>t.initialSelection(r),[r,t.initialSelection,o]),u=t.min_width?t.min_width:"200px",f=!!t.options_query_id?o:!1;return n.jsx($S,{disabled:f,style:{minWidth:"160px",width:u,maxWidth:f?u:"unset",borderColor:"#e9ecef"},value:[...d],onChange:c,treeData:l,errorMessage:i,label:e,required:t.required,treeCheckStrictly:t.treeCheckStrictly})}),BS=T.observer(({filter:e})=>{const{t}=x.useTranslation(),r=e.config;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Checkbox,{checked:r.required,onChange:a=>r.setRequired(a.currentTarget.checked),label:t("filter.widget.select.required")}),n.jsx(St,{filter:e})]}),n.jsx(s.TextInput,{label:t("filter.widget.common.min_width"),value:r.min_width,onChange:a=>r.setMinWidth(a.currentTarget.value),placeholder:"200px"}),n.jsx(s.Divider,{label:t("filter.widget.common.fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(Cn,{value:r.options_query_id,onChange:r.setOptionsQueryID}),n.jsx(s.Checkbox,{checked:r.default_selection_count===1,onChange:a=>r.setDefaultSelectionCount(a.currentTarget.checked?1:0),label:t("filter.widget.tree_single_select.select_first_option_by_default")}),n.jsx(oa,{config:r}),n.jsx(ni,{})]})}),LS=dt.createStyles((e,{radius:t=4,width:r,name:a})=>({root:{borderRadius:s.getRadius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},"&.rc-tree-select-focused":{".rc-tree-select-selection-item":{color:"#aaa"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"calc(2.25rem / 3)",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",position:"relative"},".rc-tree-select-selection-search":{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:1,".rc-tree-select-selection-search-input":{height:"36px",paddingLeft:"calc(2.25rem / 3)",textOverflow:"ellipsis"}},".rc-tree-select-selection-item":{position:"absolute",top:0,bottom:0,left:0,paddingLeft:"calc(2.25rem / 3)",color:"#000",lineHeight:"36px",fontSize:"0.875rem",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",transition:"color 200ms ease"},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,paddingTop:"6px",position:"absolute",width:`${r} !important`,"&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"0px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden",transition:"background-color 200ms ease","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-selected":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-disabled":{color:"#aaa",".rc-tree-select-tree-title, .rc-tree-select-tree-iconEle":{cursor:"not-allowed"},".rc-tree-select-tree-iconEle":{"svg .border":{fill:"#ced4da"}}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease",width:"100%",padding:"8px 0","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),qS=({disabled:e,radius:t,style:r,label:a,value:l,onChange:o,treeData:i,errorMessage:c,required:d})=>{x.useTranslation();const{classes:u,cx:p}=LS({radius:t,width:r.width,name:"FilterTreeSelectWidget"});return n.jsxs(s.Stack,{gap:3,children:[n.jsx(s.Group,{justify:"space-between",children:n.jsxs(s.Text,{className:u.label,size:"sm",children:[a,d&&n.jsx("span",{className:u.required,"aria-hidden":"true",children:"*"})]})}),n.jsx(qn,{disabled:e,allowClear:{clearIcon:n.jsx(s.CloseButton,{size:"sm"})},multiple:!1,labelInValue:!0,className:p(u.root,"check-select"),dropdownClassName:p(u.dropdown,""),transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:r,listHeight:510,treeLine:!0,switcherIcon:si,treeIcon:li,value:l,treeData:i,notFoundContent:n.jsx(ia,{errorMessage:c}),treeNodeFilterProp:"filterBasis",treeCheckable:!1,onChange:o,onSelect:console.log,showSearch:!0})]})},OS=T.observer(({label:e,config:t,value:r,onChange:a})=>{const{treeData:l,treeDataLoading:o,errorMessage:i}=t,c=v=>{a(v?v.value:null,!1)},d=h.useMemo(()=>t.initialSelection(r),[r,t.initialSelection,t.treeDataLoading]),u=t.min_width?t.min_width:"200px",f=!!t.options_query_id?o:!1;return n.jsx(qS,{disabled:f,style:{width:u,maxWidth:f?u:"unset",borderColor:"#e9ecef"},value:d,onChange:c,treeData:l,errorMessage:i,label:e,required:t.required})});function NS(e){return jd.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function GS(e){return e.map(t=>{const{label:r,description:a,...l}=t,o={...l,filterBasis:`${r}___${a??""}`,description:a,label:r};return a&&(o.label=h.createElement("div",{},[h.createElement(s.Text,{key:0,title:t.label},t.label),h.createElement(s.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description},t.description)])),o})}const oi=g.types.compose("FilterConfigModel_BaseTreeSelect",g.types.model({min_width:g.types.optional(g.types.string,""),default_value_mode:Rr}),na).views(e=>({get plainData(){const{data:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t},get treeData(){const t=this.plainData,r=GS(t);return NS(r)},get errorMessage(){const{error:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t},get treeDataLoading(){const{state:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t==="loading"}})).actions(e=>({setMinWidth(t){e.min_width=t}})),ca=g.types.compose("FilterTreeSelectConfigMeta",g.types.model({_name:g.types.literal("tree-select"),default_value:g.types.optional(g.types.array(g.types.string),[]),treeCheckStrictly:g.types.optional(g.types.boolean,!1)}),oi).views(e=>({get json(){const{_name:t,default_value:r,default_value_mode:a,required:l,min_width:o,static_options:i,options_query_id:c,default_selection_count:d,treeCheckStrictly:u}=e;return{_name:t,required:!!l,min_width:o,default_value:r,static_options:i,options_query_id:c,treeCheckStrictly:u,default_value_mode:a,default_selection_count:d}},get defaultSelection(){const t=e.filter.formattedDefaultValue;if(Array.isArray(t)&&t.length>0)return t;const{default_selection_count:r}=e;return r?e.treeData.slice(0,r).map(l=>l.value):[]},optionsByValues(t){if(!Array.isArray(t)||t.length===0)return[];const r=new Set(t);return e.options.filter(a=>r.has(a.value))},valueObjects(t){const r=new Set(t);return e.plainData.filter(a=>r.has(a.value))},initialSelection(t){return t?this.valueObjects(t):this.valueObjects(this.defaultSelection)},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=g.cast(t)},setDefaultValueMode(t){t!=="intersect"&&t!=="reset"||(e.default_value_mode=t)},setTreeCheckStrictly(t){e.treeCheckStrictly=t},applyDefaultSelection(){if(e.optionsLoading)return;if(e.default_value_mode==="reset"){e.filter.setValue(e.defaultSelection);return}const t=e.filter.value,r=new Set(e.plainData.map(l=>l.value)),a=(t??[]).filter(l=>r.has(l));a.length>0?e.filter.setValue(a):e.filter.setValue(e.defaultSelection)},afterCreate(){g.addDisposer(e,Q.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),ii=()=>ca.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),da=g.types.compose("FilterTreeSingleSelectConfigMeta",g.types.model({_name:g.types.literal("tree-single-select"),default_value:g.types.optional(g.types.string,"")}),oi).views(e=>({get json(){const{_name:t,default_value:r,default_value_mode:a,required:l,min_width:o,static_options:i,options_query_id:c,default_selection_count:d}=e;return{_name:t,required:!!l,min_width:o,default_value:r,static_options:i,options_query_id:c,default_value_mode:a,default_selection_count:d}},get selectFirstByDefault(){return e.default_selection_count===1},get defaultSelection(){if(e.treeDataLoading)return"";const t=e.filter.formattedDefaultValue;return t||(this.selectFirstByDefault&&e.treeData.length>0?e.treeData[0].value:"")},valueObject(t){if(t)return e.plainData.find(r=>r.value===t)},initialSelection(t){if(t)return this.valueObject(t)},truthy(t){return typeof t=="string"&&t!==""}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDefaultValueMode(t){t!=="intersect"&&t!=="reset"||(e.default_value_mode=t)},applyDefaultSelection(){if(e.treeDataLoading)return;if(e.default_value_mode==="reset"){e.filter.setValue(e.defaultSelection);return}const t=e.filter.value;e.optionValuesSet.has(t)?e.filter.setValue(t):e.filter.setValue(e.defaultSelection)},afterCreate(){g.addDisposer(e,Q.reaction(()=>Q.toJS(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),ci=()=>da.create({_name:"tree-single-select",default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),Sn=g.types.model("FilterMeta",{id:g.types.identifier,key:g.types.string,label:g.types.string,order:g.types.number,visibleInViewsIDs:g.types.array(g.types.string),auto_submit:g.types.optional(g.types.boolean,!1),default_value_func:g.types.optional(g.types.string,""),type:g.types.enumeration("DashboardFilterType",[V.Select,V.MultiSelect,V.TreeSelect,V.TreeSingleSelect,V.TextInput,V.Checkbox,V.DateRange]),config:g.types.union(aa,ra,ca,da,sa,ea,ta)}).views(e=>({get contentModel(){return g.getRoot(e).content},get filters(){return this.contentModel.filters},get value(){return this.filters.values[e.key]},get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==V.TreeSelect&&e.type!==V.TreeSingleSelect},get usingDefaultValueFunc(){return!!e.default_value_func},get formattedDefaultValue(){return this.filters.formattedDefaultValues[e.key]},get auto_submit_supported(){return[V.Select,V.Checkbox,V.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:r,label:a,order:l,visibleInViewsIDs:o,default_value_func:i,auto_submit:c,type:d,config:u}=e;return{id:t,key:r,type:d,label:a,order:l,config:u.json,auto_submit:c,visibleInViewsIDs:Q.toJS(o),default_value_func:i}},get visibleInViewsIDSet(){return new Set(e.visibleInViewsIDs)},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return y.get(e.config,"required",!1)?y.get(e.config,"truthy",()=>!0)(t):!1}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.filters.setValueByKey(e.key,t)},setLabel(t){e.label=t},setOrder(t){const r=Number(t);Number.isFinite(r)&&(e.order=r)},setType(t){switch(t){case V.Select:e.config=ti();break;case V.MultiSelect:e.config=ei();break;case V.TreeSelect:e.config=ii();break;case V.TreeSingleSelect:e.config=ci();break;case V.TextInput:e.config=la();break;case V.Checkbox:e.config=Yo();break;case V.DateRange:e.config=Ho();break;default:return}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t},setDefaultValueFunc(t){e.default_value_func=t}}));var $=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))($||{});const ua=g.types.model("ViewDivisionConfig",{_name:g.types.literal($.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),di=()=>ua.create({_name:$.Division}),FS=g.types.model("CustomModalTitleModel",{enabled:g.types.optional(g.types.boolean,!1),func_content:g.types.optional(g.types.string,"")}).views(e=>({get json(){const{enabled:t,func_content:r}=e;return{enabled:t,func_content:r}},get value(){const{enabled:t,func_content:r}=e,a=g.getParent(e,2),l=g.getRoot(e);if(!t)return a.name;try{const o={filters:l.content.filters.valuesForPayload,context:l.context.current};return new Function(`return ${r}`)()(o)}catch(o){return console.error(o),a.name}}})).actions(e=>({setEnabled(t){e.enabled=t},setFuncContent(t){e.func_content=t},replace({enabled:t,func_content:r}){e.enabled=t,e.func_content=r}})),Tn={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
541
- `)},pa=g.types.model("ViewModalConfig",{_name:g.types.literal($.Modal),width:g.types.string,height:g.types.string,custom_modal_title:g.types.optional(FS,Tn)}).views(e=>({get json(){const{_name:t,width:r,height:a,custom_modal_title:l}=e;return{_name:t,width:r,height:a,custom_modal_title:l.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),ui=()=>pa.create({_name:$.Modal,width:"90vw",height:"90vh"}),jS=g.types.model("ViewTabsTabModel",{id:g.types.identifier,name:g.types.string,view_id:g.types.string,color:g.types.optional(g.types.string,""),order:g.types.optional(g.types.number,0)}).views(e=>({get json(){const{id:t,name:r,view_id:a,color:l,order:o}=e;return{id:t,name:r,color:l,order:o,view_id:a}}})).actions(e=>({setName(t){e.name=t},setViewID(t){t&&(e.view_id=t)},setColor(t){e.color=t},setOrder(t){typeof t!="string"&&(e.order=t)}})),ha=g.types.model("ViewTabsConfig",{_name:g.types.literal($.Modal),tabs:g.types.optional(g.types.array(jS),[]),variant:g.types.optional(g.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:g.types.optional(g.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:g.types.optional(g.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:r,orientation:a,tabs:l,grow:o}=e;return{grow:o,tabs:l.map(i=>i.json),_name:t,variant:r,orientation:a}},get tabsInOrder(){return y.sortBy(e.tabs,"order")}})).actions(e=>({setVariant(t){t&&(e.variant=t)},setOrientation(t){t&&(e.orientation=t)},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=g.cast(t)},addTab(){const t=te.randomId(),r={id:t,name:t,view_id:""};e.tabs.push(r)},removeTab(t){e.tabs.splice(t,1)}})),pi=()=>ha.create({_name:$.Modal,tabs:[]}),hi=g.types.model({id:g.types.identifier,name:g.types.string,type:g.types.enumeration("EViewComponentType",[$.Division,$.Modal,$.Tabs]),config:g.types.union(ua,pa,ha),panelIDs:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get json(){const{id:t,name:r,type:a,config:l}=e;return{id:t,name:r,type:a,config:l.json,panelIDs:e.panelIDs.map(o=>o)}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case $.Division:e.config=di();break;case $.Modal:e.config=ui();break;case $.Tabs:e.config=pi();break;default:return}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},appendPanelIDs(t){e.panelIDs.push(...t)},removePanelID(t){const r=e.panelIDs.filter(a=>a!==t);e.panelIDs.length=0,e.panelIDs.push(...r)}})),at="14.32.0",QS={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:$.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:at,layouts:[{id:"basis",name:"basis",list:[],breakpoint:0}]},ga=g.types.model("DataSourceMetaModel",{id:g.types.string,type:g.types.enumeration("DataSourceType",[j.HTTP,j.MySQL,j.Postgresql,j.MericoMetricSystem]),key:g.types.string,config:g.types.frozen()}),gi=g.types.model("DataSourcesMetaModel",{list:g.types.optional(g.types.array(ga),[])}).views(e=>({find({type:t,key:r}){return e.list.find(a=>a.key===r&&a.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),fi=g.types.model({id:g.types.string,content:g.types.string,create_time:g.types.string,update_time:g.types.string,is_preset:g.types.boolean}),fa=g.types.model("GlobalSQLSnippetsMeta",{list:g.types.optional(g.types.array(fi),[])}).views(e=>({find(t){return e.list.find(r=>r.id===t)},get options(){return e.list.map(t=>({value:t.id,label:t.id}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),kn=g.types.model("ContextMeta",{current:g.types.optional(g.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,r){e.current[t]=r}}));function ba(e){return kn.create({current:e})}const ya=g.types.compose("ViewRenderModel",hi,g.types.model({tab:g.types.optional(g.types.string,"")})).views(e=>({get tabs(){return e.config.tabs},get tabInfo(){const t=this.tabs.find(r=>r.id===e.tab);return t?{id:t.id,name:t.name}:null},get tabView(){return e.type!==$.Tabs?null:this.tabs.find(t=>t.id===e.tab)},get tabViewID(){return this.tabView?this.tabView.view_id??"":""},get contentModel(){return g.getParent(e,3)},get panels(){if(e.type!==$.Tabs)return this.contentModel.panels.panelsByIDs(e.panelIDs);const t=this.tabViewID,r=this.contentModel.views.findByID(t);return(r==null?void 0:r.panels)??[]},get renderViewIDs(){const t=[e.id];return e.type===$.Tabs&&t.push(this.tabViewID),t},async downloadScreenshot(t){const r=t.offsetWidth*2+10,a=t.offsetHeight*2+10,l=new fs,o=new Date().getTime(),i=await gs.toBlob(t,{bgcolor:"white",width:r,height:a,style:{transformOrigin:"0 0",transform:"scale(2)"}});l.file(`${e.name}_${o}.png`,i),l.file(`dashboard_state_${o}.json`,JSON.stringify(this.contentModel.dashboardStateValues,null,4)),l.generateAsync({type:"blob"}).then(c=>{Xt.saveAs(c,`${e.name}_${o}.zip`)}).catch(c=>{console.error(c),Ze.notifications.show({color:"red",title:"Failed to download screenshot with dashboard state",message:c.message})})}})).actions(e=>({setTab(t){e.tab=t??""},setTabByTabInfo(t){e.tab=t.id??""}})),va=g.types.model("ViewsRenderModel",{current:g.types.optional(g.types.array(ya),[]),visibleViewIDs:g.types.array(g.types.string)}).views(e=>({get json(){return e.current.map(t=>tt(t.json))},get idMap(){const t=new Map;return e.current.forEach(r=>{t.set(r.id,r)}),t},findByID(t){return e.current.find(r=>r.id===t)},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:r})=>r===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:r})=>t.has(r))},get firstVisibleTabsView(){return this.visibleViews.find(t=>t.type===$.Tabs)},get firstVisibleTabsViewActiveTab(){const t=this.firstVisibleTabsView;return t?t.tabInfo:null},get firstVisibleTabsViewActiveTabStr(){return JSON.stringify(this.firstVisibleTabsViewActiveTab)}})).actions(e=>({appendToVisibles(t){new Set(e.visibleViewIDs.map(a=>a)).has(t)||e.visibleViewIDs.push(t)},rmVisibleViewID(t){const r=e.visibleViewIDs.findIndex(a=>a===t);r!==-1&&e.visibleViewIDs.splice(r,1)},setFirstVisibleTabsViewActiveTab(t){if(!t)return;const r=e.firstVisibleTabsView;r==null||r.setTabByTabInfo(t)}}));function bi(e,t){const r=e.length>0?[e[0].id]:[],a=e.map(l=>{const{_name:o=l.type}=l.config,i={...l,tab:"",config:{...l.config,_name:o},panelIDs:l.panelIDs};if(l.type===$.Tabs){let c=y.minBy(l.config.tabs,d=>d.order);!c&&l.config.tabs.length>0&&(c=l.config.tabs[0]),i.tab=(c==null?void 0:c.id)??""}return i});return t&&(a[0].tab=t.id),{current:a,visibleViewIDs:r}}const WS=new Fd.AsyncParser({withBOM:!0});async function yi(e){return!Array.isArray(e)||e.length===0?"":await WS.parse(e).promise()}async function vi(e,t){const r=await yi(t),a=new Blob([r],{type:"text/csv"});Xt.saveAs(a,`${e}.csv`)}function _i(e,t){const r=new fs,a=t.map(async({id:l,data:o})=>{const i=await yi(o);r.file(`${l}.csv`,i)});Promise.all(a).then(()=>{r.generateAsync({type:"blob"}).then(l=>{Xt.saveAs(l,`${e}.zip`)})}).catch(l=>{console.error(l),Ze.notifications.show({color:"red",title:"Failed to download data",message:l.message})})}function Bt(e,t){const r=new Blob([t],{type:"application/json"});Xt.saveAs(r,`${e}.json`)}const _a=Lo.views(e=>({get contentModel(){return g.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},get firstQuery(){return this.queries.length>0?this.queries[0]:null},get firstQueryData(){return this.firstQuery?this.firstQuery.data:[]},queryByID(t){return this.queries.find(r=>r.id===t)},get data(){return this.queries.reduce((t,r)=>(t[r.id]=r.data,t),{})},get variableStrings(){return sl(e.variables,this.data)},get variableAggValueMap(){const t={},r=this.data;return e.variables.reduce((a,l)=>(a[l.name]=Re(l,r),a),t),t},get variableValueMap(){const t={},r=this.variableAggValueMap;return e.variables.reduce((a,l)=>(a[l.name]=$e(l,r[l.name]),a),t),t},get variableStyleMap(){const t=this.variableValueMap,r={};return e.variables.reduce((a,l)=>{const o=bu(l.color,t[l.name]);return a[l.name]={color:o,"font-size":l.size,"font-weight":l.weight,variable:l},a},r),r},get dataLoading(){return this.queries.some(t=>t.isTransform?t.depQueryModelStates.some(r=>r==="loading"):t.state==="loading")},get queryStateMessages(){const t=this.queries.filter(o=>!o.runByConditionsMet);if(t.length===0)return"";const r=new Set,a=new Set;t.forEach(o=>{const i=o.conditionNames;i.context.forEach(c=>r.add(c)),i.filters.forEach(c=>a.add(c))});const l=[];return r.size>0&&l.push(`context: ${Array.from(r).join(", ")}`),a.size>0&&l.push(`filter${a.size>1?"s":""}: ${Array.from(a).join(", ")}`),l.length===2&&l.splice(1,0,"and"),l.unshift("Waiting for"),l.join(" ")},get queryErrors(){return this.queries.map(t=>t.error??t.metricQueryPayloadErrorString).filter(t=>!!t)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages===""&&!this.dataLoading}})).actions(e=>({refreshData(){e.queries.forEach(t=>t.fetchData(!0))},downloadData(){e.contentModel.queries.downloadDataByQueryIDs(e.name,e.queryIDs)},getSchema(){const t=e.json;return t.viz.conf={...t.viz.conf,__INTERACTIONS:{},__OPERATIONS:{},__TRIGGERS:{}},{panel:t,queries:e.queries.map(r=>r.json),layouts:e.contentModel.layouts.jsonByPanelIDSet(new Set([e.id]))}},downloadSchema(){const{panel:t,queries:r,layouts:a}=this.getSchema(),o=JSON.stringify({panels:[t],definition:{queries:r},layouts:a,version:at},null,2),i=e.name;Bt(i,o)}}));function xi(e){return{id:e,name:"Panel",title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:Er.name,conf:Er.createConfig()},style:{border:{enabled:!0}}}}const xa=g.types.model("PanelsRenderModel",{list:g.types.optional(g.types.array(_a),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(r=>r.id===t)},get idMap(){const t=new Map;return e.list.forEach(r=>{t.set(r.id,r)}),t}})).views(e=>({panelsByIDs(t){const r=[];return t.forEach(a=>{const l=e.idMap.get(a);l?r.push(l):console.warn(`Panel is not found, id:${a}`)}),r}}));function wi(e){const t=e.config,r=t==null?void 0:t.default_value;return r===void 0?r:t._name==="date-range"?Zo(t):r}function US(e,t){const r=e.default_value_func;try{const a=new Function(`return ${r}`)()(e,je,t);return e.config._name==="date-range"&&Array.isArray(a)?{value:a,shortcut:null}:a}catch(a){return console.error(a),wi(e)}}function mi(e,t){var r;return(r=e.default_value_func)!=null&&r.trim()?US(e,t):wi(e)}function Ci(e,t){return e.reduce((r,a)=>(r[a.key]=mi(a,t),r),{})}function Si(e,t){const r={};return Object.entries(t).forEach(([a,l])=>{const o=e[a];if(typeof l!="object"||!("shortcut"in l)||!o)return r[a]=o??l,r;if(Array.isArray(o))return console.log("⚪️ adapting legacy date-range value: ",o),r[a]={value:o,shortcut:null},r;const i=o;return i.shortcut?(r[a]=mn(i.shortcut),r):(console.log("⚪️ skipping input date range when it has no shortcut",i),r[a]=l,r)}),r}const wa=g.types.model("FiltersRenderModel",{current:g.types.optional(g.types.array(Sn),[]),values:g.types.optional(g.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get valuesString(){return JSON.stringify(e.values)},get filter(){return g.getParent(e)},get keysToTypes(){return e.current.reduce((t,r)=>(t[r.key]=r.type,t),{})},keyStateItemMap(t){return e.current.reduce((r,a)=>{const l=t[a.key];return r[a.key]={type:a.type,key:a.key,model:a,label:a.label??a.id,value:l},r},{})},get valuesForPayload(){const t={};return Object.entries(e.values).forEach(([r,a])=>{t[r]=a;const l=this.findByKey(r);l&&l.config._name==="date-range"&&(t[r]=l.config.dateStringsValue)}),t},get contentModel(){return g.getRoot(e).content},get context(){return this.contentModel.payloadForSQL.context},get initialValuesDep(){return JSON.stringify({filters:e.current.map(({default_value_func:t,config:r})=>({default_value_func:t,config:r})),context:this.contentModel.payloadForSQL.context})},get formattedDefaultValues(){return Ci(this.json,this.contentModel.context)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(r=>r.id===t)},findByKey(t){return e.current.find(r=>r.key===t)},findByIDSet(t){return e.current.filter(r=>t.has(r.id))},get inOrder(){return y.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return y.sortBy(e.current.filter(r=>r.visibleInViewsIDSet.has(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keySet(){return new Set(e.current.map(t=>t.key))},get keyLabelMap(){return e.current.reduce((t,r)=>(t[r.key]=r.label,t),{})},get keyIDMap(){return e.current.reduce((t,r)=>(t[r.key]=r.id,t),{})},getSelectOption(t){const r=this.findByID(t);if(!r||!("getSelectOption"in r.config))return null;const a=e.values[r.key];return r.config.getSelectOption(a)}})).actions(e=>({setValues(t){console.debug("⚪️ setting filter values: ",JSON.stringify(t)),e.values=t},patchValues(t){console.debug("⚪️ patching filter values: ",JSON.stringify(t)),e.values=Si(t,e.values)},setValueByKey(t,r){console.debug(`⚪️ setting filter[${t}] to value: `,JSON.stringify(r)),e.values={...e.values,[t]:r}},applyValuesPatch(t){e.values={...e.values,...t}},getValueByKey(t){return e.values[t]},getSchema(t,r){return{filters:e.findByIDSet(new Set(t)).map(o=>({...o.json,visibleInViewsIDs:r?o.json.visibleInViewsIDs:[]})),version:at}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t,!1),null,2);Bt("Filters",r)}}));function ma(e,t,r,a){const l={...r,...t},o=Ci(e,l),i=Si(a,o);return console.groupCollapsed("⚪️ initialValues"),console.log("filters",e),console.log("defaultValues",o.date_range),console.log("filterValues.date_range: ",a.date_range),console.log("initialValues.date_range: ",i.date_range),console.groupEnd(),{current:e,values:i}}function YS(e,t){const r=bs.decode(t);r!==e&&(console.error("Inconsistent sql"),console.groupCollapsed("Inconsistent sql"),console.table({before:e,after:t,v:r}),console.groupEnd())}async function KS({query:e,name:t,payload:r,additionals:a},l){if(!e.sql)return[];const{type:o,key:i,sql:c,pre_process:d,post_process:u}=e,p=or(c,r),f=Sp({sql:p,pre_process:d}),v=bs.encode(f);YS(f,v);let _=await Ae.query(l)({type:o,key:i,query:v,...a},{params:{name:t}});return _=Tp(u,_,lr(r)),_}async function XS({type:e,key:t,configString:r,name:a,additionals:l},o){try{return await Ae.httpDataSourceQuery(o)({type:e,key:t,query:r,...l},{params:{name:a}})}catch(i){if(ke.isCancel(i))throw i;return console.error(i),i}}async function ZS({key:e,configString:t,name:r,additionals:a},l){try{return await Ae.mericoMetricQuery(l)({type:"merico_metric_system",key:e,query:t,...a},{params:{name:r}})}catch(o){throw o}}async function Ca(){try{return(await Ae.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function Ti(){try{return(await Ae.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}const ki=jo.views(e=>({get rootModel(){return g.getRoot(e)},get contentModel(){return this.rootModel.content},get conditionOptions(){return this.contentModel.dashboardStateVariableOptions},getConditionOptionsWithInvalidValue(t){const{optionGroups:r,validValues:a}=this.conditionOptions;if(!t||a.has(t))return this.conditionOptions;const l={group:"common.invalid",items:[{label:t,value:t}]};return{optionGroups:[...r,l],validValues:a}},get conditionOptionsWithInvalidRunbys(){const{optionGroups:t,validValues:r}=this.conditionOptions,a={group:"common.invalid",items:[]};return e.run_by.forEach(l=>{r.has(l)||a.items.push({label:l,value:l})}),{optionGroups:[...t,a],validValues:r}},get unmetRunByConditions(){if(!g.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const r=this.contentModel.payloadForSQL;return t.filter(a=>{const l=y.get(r,a);return Array.isArray(l)?l.length===0:typeof l=="number"?Number.isNaN(l):!l})}})).views(e=>({get payload(){return e.contentModel.payloadForSQL},get formattedSQL(){const t=y.get(e,"config.sql","");return ir(t,this.payload)},get httpConfigString(){const{context:t,filters:r}=this.payload,{name:a,pre_process:l}=e.json,o=Cp(l,t,r);return console.groupCollapsed(`Request config for: ${a}`),console.log(o),console.groupEnd(),JSON.stringify(o)},get typedAsSQL(){return[j.Postgresql,j.MySQL].includes(e.type)},get typedAsHTTP(){return[j.HTTP].includes(e.type)},get isMericoMetricQuery(){return e.type===j.MericoMetricSystem},get isTransform(){return e.type===j.Transform},get reQueryKey(){const t=y.get(e,"config.react_to",[]);if(t.length===0)return"";const r=e.contentModel.payloadForSQL,a=[...t].reduce((l,o)=>(l[o]=y.get(r,o),l),{});return JSON.stringify(a)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=e.contentModel.filters,r=e.unmetRunByConditions.filter(l=>l.startsWith("context.")).map(l=>l.replace("context.","")),a=e.unmetRunByConditions.filter(l=>l.startsWith("filters.")).map(l=>y.get({filters:t},l,l.replace("filters.",""))).filter(l=>!!l);return{context:r,filters:a}},get queries(){return g.getParent(e,2)},get inUse(){return this.queries.isQueryInUse(e.id)},get dependencies(){if(!this.typedAsSQL)return[];const t=y.get(e,"config.sql","");if(!t)return[];const r=y.uniq(t.match(Mt.sqlSnippet)),a=y.uniq(t.match(Mt.filter)),l=y.uniq(t.match(Mt.context)),o=[];return r.forEach(i=>{o.push({type:"sql_snippet",key:i,valid:e.contentModel.sqlSnippets.keySet.has(i)})}),a.forEach(i=>{o.push({type:"filter",key:i,valid:e.contentModel.filters.keySet.has(i)})}),l.forEach(i=>{o.push({type:"context",key:i,valid:e.contentModel.mock_context.keySet.has(i)})}),o},get usedFilterKeySet(){const t=new Set,r=i=>{t.add(i.replace(/^filters\./,""))};if(e.run_by.forEach(i=>r(i)),y.get(e.config,"react_to",[]).forEach(i=>r(i)),!this.typedAsSQL)return t;const l=y.get(e,"config.sql","");return l&&y.uniq(l.match(Mt.filter)).forEach(i=>r(i)),t},get metricQueryPayload(){if(e.type!==j.MericoMetricSystem)return null;const t=this.payload,r={filters:e.contentModel.filters.keysToTypes},a=e.config,l=a.filters.reduce((f,v)=>{const _=y.get(t,v.variable),w=y.get(r,v.variable),m=v.dimension;if(w===V.DateRange){const z=_.every(D=>Number.isFinite(Number(D)))?_.map(D=>Number(D)):_;f[m]={between:z}}else Array.isArray(_)?f[m]={in:_}:f[m]={eq:_};return f},{}),o={id:a.id,type:a.type,filters:l,groupBys:a.groupBys};if(a.useDefaultValues&&(o.useDefaultValues=!0),!a.timeQuery.enabled)return o;const{range_variable:i,unit_variable:c}=a.timeQuery,d="YYYY-MM-DD",u="PRC",p={start:"",end:"",unitOfTime:y.get(t,c,""),unitNumber:1,timezone:"PRC",stepKeyFormat:d};if(i){const f=y.get(t,i);Array.isArray(f)&&f.length===2&&(p.start=M(f[0]).tz(u).format(d),p.end=M(f[1]).tz(u).format(d))}return o.timeQuery=p,o},get metricQueryPayloadString(){return this.metricQueryPayload?JSON.stringify(this.metricQueryPayload,null,2):""},get metricQueryPayloadError(){const t=[];if(!this.metricQueryPayload)return t;const r=e.config,{timeQuery:a}=this.metricQueryPayload;if(!a)return r.groupByValues.length>2&&t.push("分组聚合维度:最多支持两个维度的聚合计算"),t;r.groupByValues.length>1&&t.push("分组聚合维度:按时间序列展示时,仅可选择一个聚合维度");const{start:l,end:o,unitOfTime:i}=a;return(!l||!o)&&t.push("时间维度:时间范围不完整"),i||t.push("步长:必选"),t},get metricQueryPayloadErrorString(){return this.metricQueryPayloadError.join(`
542
- `)},get metricQueryPayloadValid(){return this.metricQueryPayload?this.metricQueryPayloadError.length===0:!1}})),Sa=g.types.compose("QueryRenderModel",ki,g.types.model({state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),data:g.types.optional(g.types.frozen([]),[]),error:g.types.optional(g.types.frozen(),null)})).views(e=>({get datasource(){const{key:t,type:r}=e;return e.rootModel.datasources.find({type:r,key:t})},get additionalQueryInfo(){return e.contentModel.getAdditionalQueryInfo(e.id)},get depQueryModels(){const t=y.get(e,"config.dep_query_ids",[]);return e.contentModel.queries.findByIDSet(new Set(t))},get depQueryModelStates(){return this.depQueryModels.map(t=>t.state)},get depQueryModelStatesString(){return this.depQueryModelStates.toString()}})).views(e=>({get stateMessage(){if(e.state!=="idle")return"";if(!e.runByConditionsMet){const{context:t,filters:r}=e.conditionNames;if(t.length===0&&r.length===0)return"Waiting";const a=[];return t.length>0&&a.push(`context: ${t.join(", ")}`),r.length>0&&a.push(`filter${r.length>1?"s":""}: ${r.join(", ")}`),a.length===2&&a.splice(1,0,"and"),a.unshift("Waiting for"),a.join(" ")}return e.data.length>0?"":"data.empty_data"}})).volatile(()=>({controller:new AbortController})).actions(e=>({setData(t){e.data=t},setError(t){e.error=t}})).actions(e=>({runSQL:g.flow(function*(){var t;if(e.valid&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const r=e.payload,a=e.config;e.data=yield*g.toGenerator(KS({payload:r,name:e.name,query:{type:e.type,key:e.key,sql:a.sql,pre_process:e.pre_process,post_process:e.post_process},additionals:e.additionalQueryInfo},e.controller.signal)),e.state="idle",e.error=null}catch(r){if(ke.isCancel(r))console.debug(`🟡 Query[${e.name}] is cancelled`),e.data=[],e.state="idle";else{e.data=[];const a=y.get(r,"message","unkown error");e.error=y.get(r,"response.data.detail.message",a),e.state="error"}}}}),runHTTP:g.flow(function*(){var t;if(!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{type:r,key:a,post_process:l}=e.json;let o=JSON.parse(e.httpConfigString);o=rn(e.datasource,o);const i=yield*g.toGenerator(XS({type:r,key:a,configString:JSON.stringify(o),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),c=an(e.datasource,i),d=ol(l,c,e.contentModel.dashboardStateValues);e.data=d,e.state="idle",e.error=null}catch(r){if(console.error(r),ke.isCancel(r))console.debug(`🟡 Query[${e.name}] is cancelled`),e.data=[],e.state="idle";else{e.data=[];const a=y.get(r,"message","unkown error");e.error=y.get(r,"response.data.detail.message",a),e.state="error"}}}}),runMericoMetricQuery:g.flow(function*(){var t;if(!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet&&e.metricQueryPayloadValid)){e.controller=new AbortController,e.state="loading";try{const{type:r,key:a,post_process:l}=e.json;let o={url:"/api/metric_management/query",method:"POST",data:e.metricQueryPayload};o=rn(e.datasource,o);const i=yield*g.toGenerator(ZS({key:a,configString:JSON.stringify(o),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),c=an(e.datasource,i),d=ol(l,c,e.contentModel.dashboardStateValues);e.data=d.data,e.state="idle",e.error=null}catch(r){if(console.error(r),ke.isCancel(r))console.debug(`🟡 Query[${e.name}] is cancelled`),e.data=[],e.state="idle";else{e.data=[];const a=y.get(r,"message","unkown error");e.error=y.get(r,"response.data.detail.message",a),e.state="error"}}}}),runTransformation(){e.state="loading";try{const t=e.depQueryModels.map(o=>({id:o.id,name:o.name,data:y.cloneDeep(o.data)})),r=e.contentModel.dashboardStateValues,a=e.pre_process,l=new Function(`return ${a}`)()(t,r,je);e.data=l,e.state="idle",e.error=null}catch(t){e.data=[],e.error=t.message,e.state="error"}}})).actions(e=>({fetchData:t=>{if(!e.inUse&&!t){console.debug(`🟡 Skipping query[${e.name}]`);return}return console.debug(`🔵 Running query[${e.name}]`),e.isTransform?e.runTransformation():e.typedAsHTTP?e.runHTTP():e.isMericoMetricQuery?e.runMericoMetricQuery():e.runSQL()},beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>{var r,a;if(e.isTransform){const l=e.config;return[e.inUse,e.id,e.key,e.reQueryKey,l.dep_query_ids.toString(),e.pre_process,e.depQueryModelStatesString].join("--")}return e.typedAsHTTP?`${e.inUse}--${e.id}--${e.key}--${e.reQueryKey}--${(r=e.datasource)==null?void 0:r.id}`:e.isMericoMetricQuery?`${e.inUse}--${e.id}--${e.key}--${e.reQueryKey}--${e.metricQueryPayloadString}--${(a=e.datasource)==null?void 0:a.id}`:[e.inUse,e.id,e.key,e.formattedSQL,e.pre_process,e.post_process].join("--")},()=>e.fetchData(!1),{fireImmediately:!0,delay:0}))}})),Ta=g.types.model("QueriesRenderModel",{current:g.types.optional(g.types.array(Sa),[])}).views(e=>({get idSet(){return new Set(e.current.map(t=>t.id))},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(r=>r.id===t)},findByIDSet(t){return e.current.filter(r=>t.has(r.id))},get json(){return e.current.filter(t=>t.id&&t.key).map(t=>t.json)},get root(){return g.getRoot(e)},get dashboardName(){return this.root.name},get contentModel(){return g.getParent(e,1)},get visibleQueryIDSet(){const{views:t,filters:r}=this.contentModel,a=[];t.visibleViews.forEach(i=>{i.panels.forEach(c=>{a.push(...c.queryIDs)})});const l=y.uniq(t.visibleViews.map(i=>i.renderViewIDs).flat());r.current.forEach(i=>{const c=y.get(i,"config.options_query_id");if(!c)return;l.some(u=>i.visibleInViewsIDSet.has(u))&&a.push(c)}),this.findByIDSet(new Set(a)).forEach(i=>{const c=i.config;!i.isTransform||c.dep_query_ids.length===0||a.push(...c.dep_query_ids)});const o=new Set(a);return console.debug("QueryIDs:",o),o},isQueryInUse(t){return this.visibleQueryIDSet.has(t)},addTransformDepQueryIDs(t,r){this.findByIDSet(t).forEach(a=>{const l=a.config;!a.isTransform||l.dep_query_ids.length===0||l.dep_query_ids.forEach(o=>{r!=null&&r.has(o)||t.add(o)})})},get querisToForceReload(){const t=new Set,r=new Set,{views:a,filters:l}=this.contentModel,o=y.uniq(a.visibleViews.map(i=>i.renderViewIDs).flat());return l.current.forEach(i=>{const c=y.get(i,"config.options_query_id");if(!c)return;o.some(u=>i.visibleInViewsIDSet.has(u))&&t.add(c)}),this.addTransformDepQueryIDs(t),a.visibleViews.forEach(i=>{i.panels.forEach(c=>{c.queryIDs.forEach(d=>{t.has(d)||r.add(d)})})}),this.addTransformDepQueryIDs(r,t),{filterQueries:this.findByIDSet(t),panelQueries:this.findByIDSet(r)}}})).actions(e=>({downloadAllData(){const t=e.current.map(({name:r,data:a})=>({id:r,data:a}));_i(e.dashboardName,t)},downloadDataByQueryIDs(t,r){if(r.length===1)return this.downloadDataByQueryID(t,r[0]);const a=new Set(r),l=e.current.filter(o=>a.has(o.id)).map(({name:o,data:i})=>({id:o,data:i}));_i(t,l)},downloadDataByQueryID(t,r){const a=e.findByID(r);if(!a){console.log("[downloadDataByQueryID] query not found");return}const{data:l}=a,o=t??a.name;vi(o,l)},refetchDataByQueryID(t){const r=e.findByID(t);if(!r){console.error(new Error(`[downloadDataByQueryID] query by ID[${t}] not found`));return}return r.fetchData(!0)},getSchema(t){return{definition:{queries:e.findByIDSet(new Set(t)).map(l=>l.json)},version:at}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t),null,2);Bt("Queries",r)},forceReloadVisibleQueries:g.flow(function*(){const{filterQueries:t,panelQueries:r}=e.querisToForceReload;if(console.log("🟡 Force reloading queries"),t.length>0){const a=yield Promise.allSettled(t.map(l=>l.fetchData(!0)));console.log("🟡 Queries from filters reloaded",a)}else console.log("🟡 Found no query from visible filters, skipping");if(r.length>0){const a=yield Promise.allSettled(r.map(l=>l.fetchData(!0)));console.log("🟡 Queries from filters reloaded",a)}else console.log("🟡 Found no query from visible panels, skipping")})}));function zi(e){return{current:e}}function Di({min:e,max:t}){const r=`${e}px`,a=Number.isFinite(t)?`${t}px`:"∞";return`[${r}, ${a})`}const ka=g.types.model("LayoutsRenderModel",{list:g.types.array(Wo),currentBreakpoint:g.types.string}).views(e=>({get json(){return e.list.map(t=>t.json)},jsonByPanelIDSet(t){return e.list.map(r=>r.jsonByPanelIDSet(t))},get root(){return g.getRoot(e)},get contentModel(){return this.root.content},get basisLayoutSet(){return e.list.find(t=>t.id==="basis")},get currentLayoutSet(){return e.list.find(t=>t.id===e.currentBreakpoint)},get currentLayoutRange(){return this.breakpointRanges.find(t=>t.id===e.currentBreakpoint)},get currentRangeText(){const t=this.currentLayoutRange;return Di(t)},get cols(){const t={};return e.list.forEach(r=>{t[r.id]=36}),t},get breakpoints(){const t={};return e.list.forEach(r=>{t[r.id]=r.breakpoint}),t},get breakpointNameRecord(){const t={};return e.list.forEach(r=>{t[r.name]=r.breakpoint}),t},get breakpointRanges(){const t=e.list.map(r=>({id:r.id,name:r.name,min:r.breakpoint,max:1/0,text:""}));return t.sort((r,a)=>r.min-a.min).forEach((r,a)=>{a!==t.length-1&&(r.max=t[a+1].min)}),t.forEach(r=>{r.text=Di(r)}),t},get breakpointsInfo(){return e.list.map(t=>({id:t.id,name:t.name,breakpoint:t.breakpoint})).sort((t,r)=>t.breakpoint-r.breakpoint)},get currentBreakpointRange(){return this.breakpointRanges.find(t=>t.id===e.currentBreakpoint)},get currentLayoutPreviewWidth(){const t=this.currentBreakpointRange;if(t)return t.max===1/0?t.min===0?void 0:t.min+1:t.max},items(t){const r=new Set(t);return this.currentLayoutSet.list.filter(l=>r.has(l.panelID))},gridLayouts(t){const r=new Set(t),a={};return e.list.forEach(l=>{a[l.id]=l.list.filter(o=>r.has(o.panelID)).map(o=>o.layoutProperies)}),a},findItemByPanelID(t){return this.currentLayoutSet.findByPanelID(t)}})).actions(e=>({setCurrentBreakpoint(t){console.log("🔴 onBreakpointChange:",t),e.currentBreakpoint=t},afterCreate(){g.addDisposer(e,Q.reaction(()=>e.currentBreakpoint,()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},{fireImmediately:!1,delay:0}))}})),Ii=Uo.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!g.getParent(e,2).findByKey(t)}})),za=g.types.model("SQLSnippetsRenderModel",{current:g.types.optional(g.types.array(Ii),[])}).views(e=>({get json(){return e.current.map(t=>t.json)},get record(){return e.current.reduce((t,r)=>(t[r.key]=r.value,t),{})},get keySet(){return new Set(e.current.map(t=>t.key))},get firstKey(){if(e.current.length!==0)return e.current[0].key},findByKey(t){return e.current.find(r=>r.key===t)},findByKeySet(t){return e.current.filter(r=>t.has(r.key))}})).actions(e=>({getSchema(t){return{definition:{sqlSnippets:e.findByKeySet(new Set(t)).map(l=>l.json)},version:at}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t),null,2);Bt("SQL Snippets",r)}}));function Mi(e){return{current:e}}function Ut(e,t,r,a){return e.reduce((l,o)=>{try{l[o[t]]=or(o[r],a)}catch(i){l[o[t]]=i.message}return l},{})}class Ai{constructor(t){P(this,"origin");P(this,"copy");this.origin=t,this.copy=g.clone(t),Q.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!y.isEqual(g.getSnapshot(this.origin),g.getSnapshot(this.copy))}commit(){g.applySnapshot(this.origin,g.getSnapshot(this.copy))}reset(){g.applySnapshot(this.copy,g.getSnapshot(this.origin))}update(t){g.applySnapshot(this.copy,t)}}const Pi=e=>new Ai(e),JS=({description:e,isDescriptionEmpty:t})=>t?null:n.jsx(s.Tooltip,{color:"white",label:n.jsx(Dt,{value:e,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:n.jsx(s.Box,{sx:{height:"16px",alignSelf:"center"},children:n.jsx(S.IconInfoCircle,{size:16,color:"gray"})})}),HS=T.observer(({label:e,config:{default_value:t,description:r,isDescriptionEmpty:a,...l},value:o,onChange:i})=>n.jsxs(s.Box,{children:[n.jsx(s.Text,{size:"sm",children:" "}),n.jsx(s.Checkbox,{label:n.jsxs(s.Group,{wrap:"nowrap",justify:"space-between",align:"middle",gap:6,children:[n.jsx(s.Box,{sx:{flexGrow:1},children:e}),n.jsx(JS,{description:r,isDescriptionEmpty:a})]}),checked:o||!1,onChange:c=>i(c.currentTarget.checked),...l,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),RS=({value:e,onChange:t,close:r,max_days:a,allowSingleDateInRange:l})=>{const o=e.value,[i,c]=o,d=h.useMemo(()=>i||new Date,[i]),u=h.useMemo(()=>{if(i&&!c)return i},[i,c]),p=h.useMemo(()=>{if(i&&!c&&a>0)return M(i).add(a-1,"days").toDate()},[i,c,a]),f=v=>{const[_,w]=v;t({value:v,shortcut:null}),_&&w&&r()};return n.jsx(ps.DatePicker,{defaultDate:d,numberOfColumns:2,type:"range",value:o,onChange:f,onNextMonth:console.log,minDate:u,maxDate:p,allowSingleDateInRange:l})},eT=({begin:e,end:t})=>{const{t:r}=x.useTranslation(),a=h.useMemo(()=>!t&&!e?Number.NaN:M(t).diff(M(e),"days")+1,[e,t]);if(Number.isNaN(a))return n.jsx("span",{style:{userSelect:"none",opacity:0,visibility:"hidden"},children:"."});const l=a===1?r("filter.widget.date_range.one_day"):r("filter.widget.date_range.x_days",{count:a});return n.jsx(s.Tooltip,{label:l,children:n.jsx(s.Badge,{size:"sm",variant:"light",children:a})})},tT=({max_days:e})=>{const{t}=x.useTranslation();return e?n.jsxs(n.Fragment,{children:[n.jsx(s.Group,{justify:"flex-end",children:n.jsx(s.Badge,{size:"xs",variant:"light",children:t("filter.widget.date_range.x_max_days",{max_days:e})})}),n.jsx(s.Divider,{variant:"dashed",my:10})]}):null},nT=({onChange:e})=>{const{t,i18n:r}=x.useTranslation(),a=i=>()=>{const c=i();e(c)},l=h.useMemo(()=>Xo(),[]),o=r.language==="zh";return n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{variant:"dashed",my:10}),n.jsx(s.Table,{withTableBorder:!1,sx:{"tbody > tr":{border:"none"},"tbody > tr > th, tbody > tr > td":{borderTop:"none",padding:"2px 6px"},"tbody > tr > th":{cursor:"default",userSelect:"none"},td:{paddingLeft:"1px"}},children:n.jsx(s.Table.Tbody,{children:Object.entries(l).map(([i,c])=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:n.jsx(s.Text,{size:"xs",c:"#555",fw:500,sx:{textAlignLast:"justify"},children:t(`filter.widget.date_range.shortcut.${i}.label`)})}),c.map(({key:d,value:u,getRange:p})=>n.jsx(s.Table.Td,{children:n.jsx(s.Button,{size:"compact-xs",variant:"subtle",onClick:a(p),children:t(`filter.widget.date_range.shortcut.${i}.${o?"full.":""}${d}`)})},d))]},i))})})]})},Vi=e=>({label:{display:"block",height:"21.7px"},input:{borderColor:e?"#228be6":"#e9ecef"}}),rT=({label:e,required:t,value:r,onChange:a,max_days:l,allowSingleDateInRange:o,inputFormat:i,disabled:c})=>{const{t:d}=x.useTranslation(),[u,{open:p,close:f}]=te.useDisclosure(!1),[v,_]=r.value,w=v?M(v).format(i):"",m=_?M(_).format(i):"";return n.jsxs(s.Popover,{opened:u,onClose:f,position:"bottom-start",shadow:"md",children:[n.jsxs(s.Group,{justify:"flex-start",grow:!0,wrap:"nowrap",gap:0,w:"288px",sx:{marginTop:"3px"},children:[n.jsx(s.Popover.Target,{children:n.jsx(s.TextInput,{label:e,labelProps:{title:e},required:t,leftSection:n.jsx(S.IconCalendar,{size:16}),placeholder:d("filter.widget.date_range.start_date"),readOnly:!0,disabled:c,value:w,onFocus:p,styles:Vi(u),sx:{".mantine-TextInput-label":{textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",width:"calc(240px)",position:"relative",zIndex:1},".mantine-Input-input":{borderRight:"none",borderTopRightRadius:0,borderBottomRightRadius:0},".mantine-Input-input[data-disabled]":{backgroundColor:"transparent",backgroundImage:"linear-gradient(to left, #fff 0%, #f1f3f5 30%)",opacity:1},".mantine-Input-input[data-disabled]::placeholder":{opacity:.6}}})}),n.jsx(s.TextInput,{label:n.jsx(s.Group,{justify:"flex-end",children:n.jsx(eT,{begin:v,end:_})}),leftSection:n.jsx(S.IconMinus,{size:16}),placeholder:d("filter.widget.date_range.end_date"),readOnly:!0,disabled:!v||c,value:m,onFocus:p,styles:Vi(u),sx:{".mantine-Input-section":{transform:"translateX(-18px)"},".mantine-Input-input":{borderLeft:"none",borderTopLeftRadius:0,borderBottomLeftRadius:0},".mantine-Input-input[data-disabled]":{backgroundColor:"transparent",backgroundImage:"linear-gradient(to right, #fff 0%, #f1f3f5 30%)",opacity:1},".mantine-Input-input[data-disabled]::placeholder":{opacity:.6}}})]}),n.jsxs(s.Popover.Dropdown,{p:"sm",children:[n.jsx(tT,{max_days:l}),n.jsx(RS,{value:r,onChange:a,close:f,allowSingleDateInRange:o,max_days:l}),n.jsx(nT,{onChange:a})]})]})},$i={value:[null,null],shortcut:null},Ei=e=>{const t=mn(e.shortcut);return t||(Array.isArray(e.value)?e:$i)},aT=e=>h.useMemo(()=>Ei(e),[e]),Bi=T.observer(({label:e,config:t,value:r=$i,onChange:a,disabled:l})=>{const{inputFormat:o,required:i,max_days:c,allowSingleDateInRange:d}=t,u=aT(r);return n.jsx(rT,{label:e,value:u,onChange:a,inputFormat:o,allowSingleDateInRange:d,max_days:c,required:i,disabled:l})}),sT=dt.createStyles((e,{radius:t=4,name:r,...a})=>({root:{borderRadius:s.getRadius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef",...a,"&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{width:"calc(100% - 30px)",overflow:"hidden",'div[data-role="label"]':{overflowWrap:"break-word"}},".rc-select-item-option-state-icon":{lineHeight:"20px"}},".rc-virtual-list-holder-inner":{alignItems:"flex-start"}}})),lT={root:{cursor:"pointer","&:hover":{backgroundColor:"var(--mantine-color-default-hover)"},"input, .mantine-Checkbox-labelWrapper":{cursor:"pointer",pointerEvents:"none"}}},oT=({disabled:e,radius:t,style:r,label:a,value:l,onChange:o,options:i,errorMessage:c,required:d})=>{const{t:u}=x.useTranslation(),{classes:p,cx:f}=sT({radius:t,name:"MultiSelectWidget"}),[v,_]=h.useState(!1),w=N=>{_(N)},m=v&&(l==null?void 0:l.length)>0,[k,z]=h.useState(""),D=h.useMemo(()=>{if(!k)return i;const N=k.toLowerCase(),oe=me=>{var lt;return((lt=me.description)==null?void 0:lt.toLowerCase().includes(N))||me.label.toLowerCase().includes(N)};return i.filter(oe)},[k,i]),I=h.useMemo(()=>new Set(i.map(N=>N.value)),[i]),L=h.useMemo(()=>new Set(l),[l]),E=h.useMemo(()=>L.size!==I.size?!1:Array.from(I).every(N=>L.has(N)),[L,I]),K=()=>{if(E){o([]);return}const N=Array.from(I);o(N)};return n.jsxs(s.Stack,{gap:3,children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsxs(s.Text,{className:p.label,size:"sm",children:[a,d&&n.jsx("span",{className:p.required,"aria-hidden":"true",children:"*"})]}),m&&n.jsx(s.Tooltip,{label:u("filter.widget.common.x_selected",{count:l.length}),children:n.jsx(s.Badge,{variant:"light",children:l.length})})]}),n.jsx(ys,{disabled:e,allowClear:!0,className:f(p.root,"check-select"),dropdownClassName:f(p.dropdown,""),onDropdownVisibleChange:w,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:r,clearIcon:()=>n.jsx(s.CloseButton,{size:"sm"}),value:l,onChange:o,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:n.jsx(ia,{errorMessage:c}),maxTagTextLength:10,maxTagPlaceholder:N=>u("filter.widget.common.x_selected",{count:N.length}),searchValue:k,onSearch:z,filterOption:!1,dropdownRender:N=>n.jsxs(n.Fragment,{children:[I.size>0&&!k&&n.jsx(s.Group,{px:"xs",py:"xs",onClick:K,styles:lT,children:n.jsx(s.Checkbox,{size:"xs",checked:E,onChange:y.noop,label:u("common.actions.select_all")})}),n.jsx(s.Divider,{}),N]}),children:D.map(N=>n.jsxs(ys.Option,{title:N.label,children:[n.jsx(s.Text,{size:"sm","data-role":"label",children:N.label}),N.description&&n.jsx(s.Text,{size:"xs",c:"dimmed","data-role":"description",children:N.description})]},N.value))})]})},iT=T.observer(({label:e,config:t,value:r,onChange:a})=>{const l=J(),o=!!t.options_query_id,{state:i,error:c}=l.getDataStuffByID(t.options_query_id),d=i==="loading",u=t.min_width?t.min_width:"200px",p=o?d:!1,f=h.useMemo(()=>t.initialSelection(r),[r,t.initialSelection]),v=_=>a(_,!1);return n.jsx(oT,{label:e,options:t.options,style:{minWidth:"160px",width:u,maxWidth:p?u:"unset",borderColor:"#e9ecef"},disabled:p,value:[...f],onChange:v,errorMessage:c,required:t.required})}),cT=({option:e,...t})=>{const{label:r,description:a}=e;return n.jsx("div",{...t,children:n.jsx(s.Group,{wrap:"nowrap",children:n.jsxs("div",{children:[n.jsx(s.Text,{size:"sm","data-role":"label",children:r}),n.jsx(s.Text,{size:"xs",c:"dimmed","data-role":"description",children:a})]})})})},dT=T.observer(({label:e,config:t,value:r,onChange:a})=>{const{t:l}=x.useTranslation(),o=J(),i=!!t.options_query_id,{state:c,error:d}=o.getDataStuffByID(t.options_query_id),u=c==="loading",p=h.useCallback((f,v)=>{f&&a(f,!1)},[a]);return n.jsx(s.Select,{label:e,data:t.options,disabled:i?u:!1,value:r,onChange:p,maxDropdownHeight:500,styles:{root:{width:t.width?t.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"},".mantine-Select-nothingFound":{fontSize:"0.75rem",textAlign:"left",padding:"4px 10px"}},renderOption:cT,searchable:!d,nothingFoundMessage:d||l("filter.widget.common.selector_option_empty"),clearable:t.clearable})});function uT({label:e,config:t,value:r,onChange:a}){return n.jsx(s.TextInput,{label:e,value:r||"",onChange:l=>a(l.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}const pT=T.observer(({filter:{type:e,config:t,key:r,...a},formFieldProps:l})=>{switch(e){case V.Select:return n.jsx(dT,{...a,...l,config:t});case V.MultiSelect:return n.jsx(iT,{...a,...l,config:t});case V.TreeSelect:return n.jsx(ES,{...a,...l,config:t});case V.TreeSingleSelect:return n.jsx(OS,{...a,...l,config:t});case V.TextInput:return n.jsx(uT,{...a,...l,config:t});case V.DateRange:return n.jsx(Bi,{...a,...l,config:t});case V.Checkbox:return n.jsx(HS,{...a,...l,config:t});default:return null}}),hT=T.observer(h.forwardRef(({filter:e,...t},r)=>n.jsx("div",{className:"filter-root",ref:r,children:n.jsx(ne,{children:n.jsx(pT,{filter:e,formFieldProps:t})})}))),gT=({disabled:e,onSubmit:t})=>{const{t:r}=x.useTranslation(),{renderSearchButton:a}=Ds();return a?a({disabled:e,onSubmit:t}):n.jsxs(s.Button.Group,{children:[n.jsx(s.Button,{color:"blue",size:"sm",onClick:()=>t(),disabled:e,children:r("common.actions.search")}),n.jsxs(s.Menu,{trigger:"hover",disabled:e,position:"bottom-end",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Button,{disabled:e,color:"blue",px:"xs",style:{borderLeft:`1px solid ${e?"white":"var(--mantine-color-gray-4)"}`},children:n.jsx(S.IconChevronDown,{size:16})})}),n.jsx(s.Menu.Dropdown,{children:n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconRefresh,{size:14}),disabled:e,onClick:()=>t({force:!0}),children:r("common.actions.reload")})})]})]})};function fT(e){const t=F();h.useEffect(()=>{var r,a;(a=(r=t.filters).updatePreviewValues)==null||a.call(r,e)},[e])}const Li="N/A";function bT(){const e=Nt(),t=e.content.views.visibleViews;return h.useMemo(()=>t.map(l=>{var o;return l.type===$.Tabs?(o=l.tabView)==null?void 0:o.view_id:l.id}).filter(Boolean).flatMap(l=>e.content.filters.visibleInView(l)).filter(Boolean).map(l=>yT(l)),[t])}function yT(e){switch(e.type){case V.Select:case V.MultiSelect:case V.TreeSelect:case V.TreeSingleSelect:return{label:e.label,value:vT(e.config,e.value)};case V.TextInput:return{label:e.label,value:e.value};case V.DateRange:return{label:e.label,value:_T(e.config,e.value)};case V.Checkbox:return{label:e.label,value:xT(e.value)};default:return{label:e.label,value:e.value}}}function vT(e,t){const r=new Set;return Array.isArray(t)?t.forEach(a=>r.add(a)):r.add(t),r.size===0?Li:e.options.filter(a=>r.has(a.value)).map(a=>a.label).join(", ")}function q5(e){return e}function _T(e,t){const a=Ei(t).value.filter(l=>!!l).map(l=>M(l).format(e.inputFormat));return a.length===0?Li:a.join(" - ")}function xT(e){return e?"✔️":"❌"}const wT=({opened:e,toggle:t})=>{const{t:r}=x.useTranslation();return n.jsx(s.Group,{justify:"flex-end",ml:-4,mt:-4,mb:e?4:0,children:n.jsx(s.Button,{size:"compact-xs",variant:"subtle",color:e?"gray":"blue",leftSection:e?n.jsx(S.IconChevronsUp,{size:14}):n.jsx(S.IconChevronsDown,{size:14}),onClick:t,children:r(e?"filter.hide_filters":"filter.show_filters")})})},qi=T.observer(function({view:t}){const[r,{toggle:a}]=te.useDisclosure(!0),l=J(),{control:o,handleSubmit:i,reset:c}=b.useForm({defaultValues:l.filters.values,reValidateMode:"onBlur"}),d=b.useWatch({control:o});h.useEffect(()=>{c(l.filters.values)},[l.filters.values,c]),fT(d);const u=l.filters.visibleInView(t.id),p=h.useMemo(()=>u.every(m=>m.should_auto_submit),[u]),f=h.useMemo(()=>u.filter(m=>y.get(m,"config.required",!1)),[u]),v=h.useMemo(()=>f.length===0?!1:f.some(m=>!m.requiredAndPass(d[m.key])),[d,f]),_=(m,k)=>(z,D)=>{k(z),(m.should_auto_submit||D)&&l.filters.setValueByKey(m.key,z)},w=h.useCallback(m=>{const k=y.get(m,"force",!1);i(l.filters.setValues)(),k&&l.queries.forceReloadVisibleQueries()},[i,l.filters.setValues]);return u.length===0?null:n.jsxs("form",{children:[n.jsx(wT,{opened:r,toggle:a}),n.jsx(s.Collapse,{in:r,children:n.jsxs(s.Group,{className:"dashboard-filters",justify:"space-between",wrap:"nowrap",sx:p?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[n.jsx(s.Group,{align:"flex-start",children:u.map(m=>n.jsx(b.Controller,{name:m.key,control:o,render:({field:k})=>n.jsx(hT,{filter:m,value:k.value,onChange:_(m,k.onChange)})},m.id))}),!p&&n.jsx(s.Group,{sx:{alignSelf:"flex-end"},children:n.jsx(gT,{disabled:v,onSubmit:w})})]})})]})}),mT={viewPanelInFullScreen:y.noop,inFullScreen:!1},zn=h.createContext(mT),CT=T.observer(({view:e})=>{const{t}=x.useTranslation(),r=W(),{panel:a}=re(),l=a.realQueryOptions,o=c=>{r.editor.open(["_QUERIES_",c])},i=()=>{r.editor.open(["_VIEWS_",e.id,"_PANELS_",a.id,"_TABS_","Data"])};return l.length===0?null:n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{label:t(l.length>1?"query.labels":"query.label"),labelPosition:"center"}),n.jsx(s.Menu.Item,{onClick:i,leftSection:n.jsx(S.IconDatabase,{size:14}),children:t("data.label")}),l.map(c=>n.jsx(s.Menu.Item,{onClick:()=>o(c.value),leftSection:n.jsx(S.IconDatabase,{size:14}),children:c.label},c.value))]})}),ST=T.observer(({view:e,title:t})=>{const{t:r}=x.useTranslation(),a=W(),l=F(),o=ze.useModals(),{panel:i,downloadPanelScreenshot:c}=re(),{id:d}=i,{viewPanelInFullScreen:u,inFullScreen:p}=h.useContext(zn),f=()=>{l.duplicatePanelByID(d,e.id)},v=()=>{a.editor.open(["_VIEWS_",e.id,"_PANELS_",d,"_TABS_","Panel"])},_=()=>{a.editor.open(["_VIEWS_",e.id,"_PANELS_",d,"_TABS_","Variables"])},w=()=>{a.editor.open(["_VIEWS_",e.id,"_PANELS_",d,"_TABS_","Visualization"])},m=()=>{a.editor.open(["_VIEWS_",e.id,"_PANELS_",d,"_TABS_","Interactions"])},k=()=>o.openConfirmModal({title:`${r("panel.delete")}?`,labels:{confirm:r("common.actions.confirm"),cancel:r("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>l.removePanelByID(d,e.id),confirmProps:{color:"red"},zIndex:320}),z=h.useCallback(()=>{u(d)},[d,u]),D=!p&&e.type!==$.Modal;return n.jsx(n.Fragment,{children:n.jsx(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},title:t,children:n.jsxs(s.Menu,{withinPortal:!0,children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Box,{className:"panel-dropdown-target",sx:{width:"100%"}})}),n.jsxs(s.Menu.Dropdown,{children:[n.jsx(s.Menu.Item,{onClick:i.refreshData,leftSection:n.jsx(S.IconRefresh,{size:14}),children:r("common.actions.refresh")}),n.jsx(s.Menu.Item,{onClick:i.downloadData,leftSection:n.jsx(S.IconDownload,{size:14}),children:r("common.actions.download_data")}),n.jsx(s.Menu.Item,{onClick:i.downloadSchema,leftSection:n.jsx(S.IconCode,{size:14}),children:r("common.actions.download_schema")}),n.jsx(s.Menu.Item,{onClick:c,leftSection:n.jsx(S.IconCamera,{size:14}),children:r("common.actions.download_screenshot")}),D&&n.jsx(s.Menu.Item,{onClick:z,leftSection:n.jsx(S.IconArrowsMaximize,{size:14}),disabled:!0,children:r("common.actions.enter_fullscreen")}),n.jsx(CT,{view:e}),n.jsx(s.Divider,{label:r("common.actions.edit"),labelPosition:"center"}),n.jsx(s.Menu.Item,{onClick:v,leftSection:n.jsx(S.IconAppWindow,{size:14}),children:r("panel.label")}),n.jsx(s.Menu.Item,{onClick:_,leftSection:n.jsx(S.IconVariable,{size:14}),children:r("panel.variable.labels")}),n.jsx(s.Menu.Item,{onClick:w,leftSection:n.jsx(S.IconChartHistogram,{size:14}),children:r("visualization.label")}),n.jsx(s.Menu.Item,{onClick:m,leftSection:n.jsx(S.IconRoute,{size:14}),children:r("interactions.label")}),n.jsx(s.Divider,{label:r("common.actions.actions"),labelPosition:"center"}),n.jsx(s.Menu.Item,{onClick:f,leftSection:n.jsx(S.IconCopy,{size:14}),children:r("common.actions.duplicate")}),n.jsx(s.Menu.Item,{color:"red",onClick:k,leftSection:n.jsx(S.IconTrash,{size:14}),children:r("common.actions.delete")})]})]})})})});function TT(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const kT=T.observer(()=>{const e=J(),{panel:t}=be(),r=h.useMemo(()=>ht(t.description,t.json.variables,e.payloadForViz,t.data),[t.data,t.description,t.json.variables,e.payloadForViz]);return n.jsx(Dt,{value:r,styles:{root:{border:"none"},content:{padding:0}},sx:{".mantine-RichTextEditor-content .ProseMirror":{padding:"0 !important"}},dashboardStateValues:e.dashboardStateValues,variableAggValueMap:t.variableAggValueMap})}),Da=T.observer(()=>{const{t:e}=x.useTranslation(),[t,r]=h.useState(!1),{panel:a}=be();return TT(a.description)?null:n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:t,onClose:()=>r(!1),title:a.title.show?a.name:"",withCloseButton:!1,withinPortal:!0,zIndex:310,children:n.jsx(kT,{})}),n.jsx(s.Tooltip,{label:e("panel.panel_description_click"),position:"top-start",withinPortal:!0,children:n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>r(l=>!l),sx:{verticalAlign:"baseline",cursor:"pointer"},children:n.jsx(S.IconInfoCircle,{size:20})})})]})}),O5="",zT=T.observer(function(){const{panel:t}=be(),{name:r,title:a}=t;return a.show?n.jsx(s.Group,{grow:!0,justify:"center",className:"panel-title-wrapper",sx:{flexGrow:1},children:n.jsx(s.Text,{size:"sm",ta:"center",lineClamp:1,className:"panel-title-text",children:r})}):null});function DT(e){const t=h.useRef(null);return{ref:t,downloadPanelScreenshot:()=>{const a=t.current;if(!a)return;const l=a.offsetWidth*2,o=a.offsetHeight*2;gs.toBlob(t.current,{bgcolor:"white",width:l,height:o,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(i=>{window.saveAs(i,`${e.name?e.name:e.viz.type}.png`)})}}}var Oi=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(Oi||{}),Dn=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(Dn||{});class IT{constructor(t){P(this,"vizInstance");P(this,"operationManager");P(this,"triggerManager");P(this,"vizManager");P(this,"runningMigration");P(this,"panelModel");P(this,"status","notStarted");this.panelModel=t.getRequired(R.instanceScope.panelModel),this.vizInstance=t.getRequired(R.instanceScope.vizInstance),this.operationManager=t.getRequired(R.instanceScope.operationManager),this.triggerManager=t.getRequired(R.instanceScope.triggerManager),this.vizManager=t.getRequired(R.vizManager)}async createMigrationTask(){const t=[];try{await this.instanceNeedMigration()&&t.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&t.push(()=>this.runInteractionMigration())}catch(r){return console.warn("check migration failed",r),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(r=>r())),"migrated"}catch(r){return console.warn("migration failed",r),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(t=>(this.status="done",t))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),r={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(r)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),r={configData:this.vizInstance.instanceData};return t.migrator.needMigration(r)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}class MT{getTriggerSchemaList(){return[]}getTriggerList(){return Promise.resolve([])}removeTrigger(){return Promise.resolve()}createOrGetTrigger(){return Promise.resolve(Ni)}retrieveTrigger(){return Promise.resolve(Ni)}watchTriggerSnapshotList(){return()=>{}}needMigration(){return Promise.resolve(!1)}runMigration(){return Promise.resolve()}}class AT{constructor(){P(this,"id","");P(this,"schemaRef","");P(this,"triggerData",new Jt({}))}}const Ni=new AT;class PT{getOperationSchemaList(){return[]}getOperationList(){return Promise.resolve([])}removeOperation(){return Promise.resolve()}createOrGetOperation(){return Promise.resolve(Gi)}runOperation(){return Promise.resolve()}retrieveTrigger(){return Promise.resolve(Gi)}runMigration(){return Promise.resolve()}needMigration(){return Promise.resolve(!1)}}class VT{constructor(){P(this,"id","");P(this,"schemaRef","");P(this,"operationData",new Jt({}))}}const Gi=new VT,$n=class $n{constructor(){P(this,"triggerManager",new MT);P(this,"operationManager",new PT)}getInteractionList(){return Promise.resolve([])}addInteraction(){return Promise.resolve()}removeInteraction(){return Promise.resolve()}runInteraction(){return Promise.resolve()}};P($n,"instance",new $n);let Ia=$n;function Fi(e,t=!0){const{panel:r}=be();return h.useCallback(a=>{const l=a.getRequired(R.vizManager),o=l.resolveComponent(e.viz.type);return a.createScoped().provideFactory(R.instanceScope.vizInstance,()=>l.getOrCreateInstance(e)).provideFactory(R.instanceScope.interactionManager,i=>{const c=i.getRequired(R.instanceScope.vizInstance);return t?new gl(c,o,hr):new Ia}).provideFactory(R.instanceScope.operationManager,i=>i.getRequired(R.instanceScope.interactionManager).operationManager).provideFactory(R.instanceScope.triggerManager,i=>i.getRequired(R.instanceScope.interactionManager).triggerManager).provideValue(R.instanceScope.panelModel,r).provideFactory(R.instanceScope.migrator,i=>new IT(i))},[e.viz.type,e.viz.conf,t])}const ji={withInteraction:!0,withAddon:!0,withPanelTitle:!0},Qi=h.createContext(ji);function $T({children:e,...t}){const r=y.defaults({},t,ji);return n.jsx(Qi.Provider,{value:r,children:e})}function Ma(){return h.useContext(Qi)}function Wi(e){const[t,r]=h.useState(!1),a=Qt().getRequired(R.instanceScope.migrator);return O.useAsyncEffect(async()=>{const l=a.status===Dn.notStarted;r(a.status===Dn.done),a.status===Dn.notStarted&&a.runMigration().then(o=>{o===Oi.migrated&&l&&(e==null||e())}).finally(()=>{r(!0)})},[a]),t}function Ui(e,t){const r=Qt().getRequired(R.instanceScope.vizInstance);return O.useAsyncEffect(async()=>{y.isEqual(await r.instanceData.getItem(null),t.viz.conf)||await r.instanceData.setItem(null,t.viz.conf)},[r,t.viz.conf]),h.useEffect(()=>r.instanceData.watchItem(null,a=>{e(a)}),[e,t.viz.type]),r}function ET({setVizConf:e,...t}){const{panel:r}=t,a=Ui(e,r),l=Wi(()=>{Ze.showNotification({title:`${r.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return O.useAsyncEffect(async()=>{await a.instanceData.setItem(null,r.viz.conf)},[a,r.viz.type]),l?n.jsx(eu,{...t}):n.jsx(s.Text,{size:"sm",children:"Checking update..."})}function BT(e){const{panel:t,setVizConf:r}=e;Ui(r,t);const{inEditMode:a}=h.useContext(Gt);return Wi(()=>{a&&Ze.showNotification({title:`${t.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?n.jsx(Rd,{...e}):n.jsx(s.Text,{size:"sm",children:"Checking update"})}const N5="";function LT(e,t){const{vizManager:r}=h.useContext(rt),{panel:{viz:a,title:l,id:o,name:i,description:c,queryIDs:d,variables:u}}=be(),p={id:o,name:i,title:l,description:c,queryIDs:d,viz:a},{withInteraction:f}=Ma(),v=Fi(p,f);try{return r.resolveComponent(a.type),n.jsxs(ln,{configure:v,children:[n.jsx(BT,{setVizConf:a.setConf,panel:p,measure:t,data:e,variables:u,vizManager:r}),n.jsx(Ki,{})]})}catch(_){return console.info(y.get(_,"message")),null}}const Yi=T.observer(function({data:t}){const{ref:r,width:a,height:l}=te.useElementSize(),o=LT(t,{w:a,h:l}),i=a>0&&l>0;return n.jsx("div",{className:"viz-root",ref:r,children:n.jsx(s.Box,{sx:{width:a,height:l,overflow:"hidden"},children:i&&n.jsx(ne,{children:o})})})}),Ki=()=>{const e=Qt(),t=e.getRequired(R.instanceScope.vizInstance),{inEditMode:r}=h.useContext(Gt),a=e.getRequired(R.panelAddonManager),{withAddon:l}=Ma(),o=cu();return!o||!l?null:Qd.createPortal(n.jsx(n.Fragment,{children:a.createPanelAddonNode({viz:t,isInEditMode:r})}),o,"addon")},Xi=T.observer(({panel:e})=>n.jsxs(s.Stack,{children:[e.queryErrors.map((t,r)=>n.jsx(s.Text,{c:"red",size:"sm",ta:"center",ff:"monospace",children:t},`${r}-${t}`)),n.jsx(s.Text,{c:"gray",ta:"center",size:"sm",children:e.queryStateMessages})]})),Aa=T.observer(({panel:e})=>n.jsxs(s.Flex,{className:"panel-viz-section",direction:"column",sx:{position:"relative",width:"100%"},children:[n.jsx(s.LoadingOverlay,{visible:e.dataLoading,transitionProps:{exitDuration:0}}),!e.canRenderViz&&n.jsx(Xi,{panel:e}),e.canRenderViz&&n.jsx(Yi,{data:e.data})]})),qT={border:"1px solid #e9ecef"},Pa=T.observer(({panel:e,panelStyle:t,dropdownContent:r})=>{const{ref:a,downloadPanelScreenshot:l}=DT(e),{withAddon:o,withPanelTitle:i}=Ma(),c=o?ms:h.Fragment;return n.jsx(Yn,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors,downloadPanelScreenshot:l},children:n.jsx(s.Box,{id:e.id,className:`panel-root ${e.title.show?"panel-root--show-title":""}`,ref:a,p:0,sx:{...qT,...t},children:n.jsxs(c,{children:[i&&n.jsxs(n.Fragment,{children:[n.jsx(s.Box,{className:"panel-description-popover-wrapper",children:n.jsx(Da,{})}),r,n.jsx(zT,{})]}),n.jsx(Aa,{panel:e})]})})})}),OT={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function NT(e){return e.style.border.enabled?{}:OT}const Zi=T.observer(function({panel:t,view:r}){const a=NT(t);return n.jsx(Pa,{panel:t,panelStyle:a,dropdownContent:n.jsx(ST,{view:r,title:t.name})})});function GT(e){return!["richText","button","vizDashboardState"].includes(e)}const FT=T.observer(({view:e,title:t})=>{const{t:r}=x.useTranslation(),{panel:a,downloadPanelScreenshot:l}=be(),{id:o}=a,{viewPanelInFullScreen:i,inFullScreen:c}=h.useContext(zn),d=h.useCallback(()=>{i(o)},[o,i]),u=!c&&e.type!==$.Modal;return GT(a.viz.type)?n.jsx(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},title:t,children:n.jsxs(s.Menu,{withinPortal:!0,children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Box,{className:"panel-dropdown-target"})}),n.jsxs(s.Menu.Dropdown,{children:[n.jsx(s.Menu.Item,{onClick:a.refreshData,leftSection:n.jsx(S.IconRefresh,{size:14}),children:r("common.actions.refresh")}),n.jsx(s.Menu.Item,{onClick:a.downloadData,leftSection:n.jsx(S.IconDownload,{size:14}),children:r("common.actions.download_data")}),n.jsx(s.Menu.Item,{onClick:l,leftSection:n.jsx(S.IconCamera,{size:14}),children:r("common.actions.download_screenshot")}),u&&n.jsx(s.Menu.Item,{onClick:d,leftSection:n.jsx(S.IconArrowsMaximize,{size:14}),children:r("common.actions.enter_fullscreen")})]})]})}):null});function jT(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const Va=T.observer(({panel:e,view:t})=>{const r=jT(e);return n.jsx(Pa,{panel:e,panelStyle:r,dropdownContent:n.jsx(FT,{title:e.name,view:t})})}),QT={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},Ji=T.observer(function({view:t,panel:r,exitFullScreen:a}){return n.jsx(s.Modal,{opened:!0,fullScreen:!0,onClose:a,title:n.jsx(s.Button,{color:"blue",size:"xs",onClick:a,leftSection:n.jsx(S.IconArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:QT,children:n.jsx(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:n.jsx(Va,{view:t,panel:r})})})});function Hi(e,t,r){const{panels:a}=J(),l=e.id==="Main",[o,i]=h.useState(()=>l&&a.findByID(t)?t:null),c=h.useCallback(f=>{i(f),l&&r(f)},[l,r]),d=h.useCallback(()=>{i(null),l&&r("")},[l,r]),u=o?a.findByID(o):null;return{viewPanelInFullScreen:c,exitFullScreen:d,inFullScreen:!!u,fullScreenPanel:u}}function WT(e){const t=Nt(),r=h.useMemo(()=>t.content.panels.findByID(e.panelId),[e.panelId]);return r?n.jsx($T,{withAddon:!1,withPanelTitle:!1,withInteraction:!1,children:n.jsx(Pa,{panel:r,panelStyle:{}})}):null}const G5="",UT=h.forwardRef(({h:e},t)=>n.jsx(s.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:n.jsx(S.IconArrowsMove,{size:16})})),YT=h.forwardRef(({handleAxis:e,...t},r)=>n.jsx(s.ActionIcon,{ref:r,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...t,children:n.jsx(S.IconChevronDownRight,{size:16})})),KT=Zt.WidthProvider(Zt.Responsive),XT=T.observer(({view:e,className:t="layout"})=>{const a=F().layouts,l=a.items(e.panelIDs),o=a.gridLayouts(e.panelIDs),i=(u,p,f,v)=>{f.h<30&&(f.h=30,v.h=30),f.w<4&&(f.w=4,v.w=4)},c=(u,p,f)=>{console.log("🔴 onResizeStop",{layouts:u,oldItem:p,newItem:f}),a.updateCurrentLayoutItem(f)},d=(u,p,f)=>{console.log("🔴 onDragStop",{layouts:u,oldItem:p,newItem:f}),a.updateCurrentLayoutItems(u)};return n.jsx(KT,{className:`dashboard-layout ${t}`,rowHeight:1,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,cols:a.cols,layouts:o,draggableHandle:".react-grid-customDragHandle",resizeHandle:n.jsx(YT,{}),onResize:i,breakpoints:a.breakpoints,onBreakpointChange:a.setCurrentBreakpoint,onResizeStop:c,onDragStop:d,width:a.currentLayoutPreviewWidth,children:l.map(u=>n.jsxs("div",{"data-grid":u.layoutProperies,className:"panel-grid-item",children:[n.jsx(UT,{h:u.h}),n.jsx(Zi,{view:e,panel:u.panel})]},u.id))})}),ZT=Zt.WidthProvider(Zt.Responsive),JT=T.observer(({view:e,className:t="layout"})=>{const r=J(),a=r.layouts.items(e.panelIDs),l=r.layouts.gridLayouts(e.panelIDs);return n.jsx(ZT,{className:`dashboard-layout ${t}`,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,cols:r.layouts.cols,layouts:l,breakpoints:r.layouts.breakpoints,onBreakpointChange:r.layouts.setCurrentBreakpoint,children:a.map(o=>n.jsx("div",{"data-grid":o.layoutProperies,className:"panel-grid-item",children:n.jsx(Va,{view:e,panel:o.panel})},o.id))})});function $a(e){const t=h.useRef(null);return{ref:t,downloadScreenshot:()=>{var l;const a=(l=t.current)==null?void 0:l.querySelector(".react-grid-layout");a&&e.downloadScreenshot(a)}}}const HT=T.observer(({downloadScreenshot:e})=>{const{t}=x.useTranslation(),[r,{setTrue:a,setFalse:l}]=O.useBoolean(!1),o=ks(),i=J(),c=()=>{const d=JSON.stringify(i.contentJSON,null,2),u=`${o.name}__${i.name}`;Bt(u,d)};return n.jsxs(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:200,closeDelay:400,withinPortal:!0,position:"bottom-end",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Affix,{position:{bottom:"20px",right:"10px"},zIndex:1,children:n.jsx(s.ActionIcon,{size:"md",variant:"gradient",gradient:{from:"indigo",to:"cyan"},onMouseEnter:a,onMouseLeave:l,sx:{opacity:r?1:.6,transform:`translateX(${r?0:"2px"})`,transition:"all ease 300ms",borderRadius:"50%"},children:n.jsx(S.IconShare3,{size:"1rem"})})})}),n.jsxs(s.Menu.Dropdown,{children:[n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconCamera,{size:14}),onClick:e,children:t("common.actions.download_screenshot")}),n.jsx(s.Menu.Divider,{}),n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconDownload,{size:14}),onClick:i.queries.downloadAllData,children:t("common.actions.download_data")}),n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconCode,{size:14}),onClick:c,children:t("common.actions.download_schema")})]})]})}),Ri=T.observer(({children:e,view:t,sx:r={}})=>{const{ref:a,downloadScreenshot:l}=$a(t);return n.jsxs(n.Fragment,{children:[n.jsx(s.Box,{ref:a,pt:10,pb:10,sx:r,children:e}),n.jsx(HT,{downloadScreenshot:l})]})}),ec=T.observer(({downloadScreenshot:e})=>n.jsx(s.ActionIcon,{className:"download-screenshot-button",color:"blue",variant:"subtle",onClick:e,children:n.jsx(S.IconCamera,{size:14})})),RT=T.observer(({children:e,view:t})=>{const r=J(),a=t.config,l=r.views.visibleViewIDs.includes(t.id),o=()=>r.views.rmVisibleViewID(t.id),{ref:i,downloadScreenshot:c}=$a(t);return n.jsx(s.Modal,{size:a.width,centered:!0,opened:l,onClose:o,withCloseButton:!1,title:n.jsxs(s.Group,{justify:"space-between",px:"1rem",h:"48px",children:[n.jsx(s.Box,{children:a.custom_modal_title.value}),n.jsx(ec,{downloadScreenshot:c})]}),trapFocus:!0,onDragStart:d=>{d.stopPropagation()},styles:{root:{position:"fixed",zIndex:200,inset:0},overlay:{zIndex:"unset"},inner:{zIndex:"unset",padding:"0 !important"},content:{border:"1px solid #efefef",maxHeight:"unset !important",overflow:"hidden"},body:{maxHeight:a.height,overflow:"auto",position:"relative",paddingBottom:10},header:{padding:0},title:{flexGrow:1}},transitionProps:{duration:0},children:n.jsx(s.Box,{ref:i,children:e})})}),e2=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},t2=T.observer(({view:e})=>{const t=J(),r=e.config;return n.jsxs(s.Tabs,{className:"render-view-tabs",variant:r.variant,orientation:r.orientation,value:e.tab,onChange:e.setTab,styles:{root:{height:"100%",overflow:r.orientation==="horizontal"?"hidden":"auto"},panel:{padding:r.orientation==="horizontal"?"0px 0px 36px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[n.jsx(s.Tabs.List,{grow:r.grow,children:r.tabsInOrder.map(a=>n.jsx(s.Tabs.Tab,{value:a.id,sx:e2(a),disabled:!a.view_id,children:a.name??a.id},a.id))}),r.tabsInOrder.map(a=>{const l=t.views.findByID(a.view_id);return l?n.jsx(s.Tabs.Panel,{value:a.id,children:n.jsx(In,{view:l})},a.id):null})]})}),n2=T.observer(({view:e,children:t})=>{switch(e.type){case $.Modal:return n.jsx(RT,{view:e,children:t});case $.Tabs:return n.jsx(t2,{view:e});case $.Division:default:return n.jsx(Ri,{view:e,children:t})}}),r2=T.observer(({children:e,view:t})=>{const a=F().layouts,[l,o]=te.useResizeObserver();return h.useEffect(()=>{a.setCurrentLayoutWrapperWidth(o.width)},[o.width]),n.jsx(s.Box,{sx:{height:"100%"},ref:l,children:n.jsx(s.Box,{sx:{paddingBottom:"100px",background:"white",margin:"0 auto",width:a.currentLayoutPreviewWidth??"100%",transform:`scale(${a.divisionPreviewScale})`,transformOrigin:"0 0"},children:n.jsx(Ri,{view:t,sx:{paddingTop:"0px !important",".dashboard-sticky-area > form":{paddingBottom:"5px"},".dashboard-layout":{marginTop:0,marginBottom:0}},children:e})})})});function tc(e){return e.replace(/(vw|vh)/,"%")}const a2=T.observer(({children:e,view:t})=>{const r=t.config,{width:a,height:l}=h.useMemo(()=>({width:tc(r.width),height:tc(r.height)}),[r.width,r.height]),{ref:o,downloadScreenshot:i}=$a(t);return n.jsx(s.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:n.jsx(s.Modal,{size:r.width,opened:!0,onClose:y.noop,withCloseButton:!1,title:n.jsxs(s.Group,{justify:"space-between",px:"1rem",h:"48px",children:[n.jsx(s.Box,{children:r.custom_modal_title.value}),n.jsx(ec,{downloadScreenshot:i})]}),trapFocus:!0,onDragStart:c=>{c.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},inner:{position:"relative",top:"50%",left:"50%",right:"unset",bottom:"unset",transform:"translate(-50%, -50%)",padding:"0 !important",width:a,height:l,maxHeight:l},content:{border:"1px solid #efefef",height:"100%"},body:{maxHeight:"calc(100% - 48px)",overflow:"auto"},header:{padding:0},title:{flexGrow:1}},withinPortal:!1,transitionProps:{duration:0},children:n.jsx(s.Box,{ref:o,children:e})})})}),s2=({variant:e,orientation:t})=>{const r={root:{height:"100%",overflow:"hidden"},list:{backgroundColor:"white"},tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(r.tab.paddingTop="6px",r.tab.paddingBottom="6px"),t==="vertical"&&(r.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},r.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),r},l2=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},o2=T.observer(({view:e})=>{const{t}=x.useTranslation(),r=ze.useModals(),a=F(),l=h.useMemo(()=>a.views.options.filter(u=>u.type===$.Division),[e.id,a.views.options]),o=e.config,i=u=>r.openConfirmModal({title:`${t("view.component.tabs.tab.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.removeTab(u)},confirmProps:{color:"red"},zIndex:320}),c=o.tabs.length===0,d=o.tabsInOrder.length===0?void 0:o.tabsInOrder[0].id;return n.jsxs(s.Tabs,{className:"preview-view-tabs",variant:o.variant,orientation:o.orientation,value:e.tab||d,onChange:e.setTab,styles:s2(o),children:[n.jsxs(s.Tabs.List,{grow:o.grow,children:[o.tabsInOrder.map(u=>n.jsx(s.Tabs.Tab,{value:u.id,sx:l2(u),children:u.name??u.id},u.id)),n.jsx(s.Tabs.Tab,{onClick:o.addTab,value:"add",className:"add-a-tab",children:n.jsx(S.IconPlus,{size:18,color:"#228be6"})})]}),o.tabsInOrder.map((u,p)=>{const f=a.views.findByID(u.view_id);return n.jsxs(s.Tabs.Panel,{value:u.id,sx:{position:"relative"},children:[n.jsxs(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[n.jsx(s.Overlay,{backgroundOpacity:.8,color:"#FFF",blur:10,zIndex:100}),n.jsxs(s.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[n.jsx(s.TextInput,{label:t("view.component.tabs.tab.name"),required:!0,value:u.name,onChange:v=>u.setName(v.currentTarget.value)}),n.jsx(s.Select,{label:t("view.label"),value:u.view_id,onChange:u.setViewID,data:l}),n.jsx(s.NumberInput,{label:t("view.component.tabs.tab.order"),required:!0,value:u.order,onChange:v=>u.setOrder(v||0),min:0,max:1e3,step:1}),n.jsx(s.ColorInput,{label:t("view.component.tabs.tab.color"),value:u.color,onChange:u.setColor,disabled:o.variant!=="default"}),f&&n.jsx(s.Button,{mt:20,variant:"gradient",leftSection:n.jsx(S.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>a.views.setIDOfVIE(f.id),children:t("view.component.tabs.tab.switch_to_view",{name:f.name})}),n.jsx(s.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>i(p),disabled:c,leftSection:n.jsx(S.IconTrash,{size:14}),children:t("view.component.tabs.tab.delete")})]})]}),f&&n.jsx(In,{view:f})]},u.id)})]})}),i2=T.observer(({view:e,children:t})=>{switch(e.type){case $.Modal:return n.jsx(a2,{view:e,children:t});case $.Tabs:return n.jsx(o2,{view:e});case $.Division:default:return n.jsx(r2,{view:e,children:t})}}),nc=T.observer(function({view:t}){const a=F().layouts.divisionPreviewScale!==1;return n.jsx(zn.Provider,{value:{viewPanelInFullScreen:y.noop,inFullScreen:!1},children:n.jsx(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{background:a?"transparent":"#efefef"},children:n.jsx(i2,{view:t,children:n.jsxs(s.Box,{sx:{position:"relative"},children:[n.jsx(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:n.jsx(qi,{view:t})}),n.jsx(XT,{view:t})]})})})})}),In=T.observer(function({view:t}){const{fullScreenPanelID:r,setFullScreenPanelID:a}=Vs(),{viewPanelInFullScreen:l,exitFullScreen:o,inFullScreen:i,fullScreenPanel:c}=Hi(t,r,a);return n.jsx(zn.Provider,{value:{viewPanelInFullScreen:l,inFullScreen:i},children:n.jsxs(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:t.type===$.Modal?"0 !important":"100%"},children:[i&&n.jsx(Ji,{view:t,panel:c,exitFullScreen:o}),n.jsx(n2,{view:t,children:n.jsxs(s.Box,{sx:{position:"relative"},children:[!i&&n.jsx(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:n.jsx(qi,{view:t})}),!i&&n.jsx(JT,{view:t})]})})]})})});var rc=(e=>(e.Use="use",e.Edit="edit",e))(rc||{});const c2={[$.Division]:"Division",[$.Tabs]:"Tabs",[$.Modal]:"Modal"},ac={[$.Division]:"rgba(255, 0, 0, 0.2)",[$.Modal]:"rgba(0, 0, 0, 0.2)",[$.Tabs]:"rgba(255, 200, 100, 0.4)"},d2={[$.Division]:"#ff4000",[$.Modal]:"#000",[$.Tabs]:"#ffad18"},sc=Sn.views(e=>({get usages(){return e.contentModel.findFilterUsage(e.id)}})).actions(e=>({}));function u2(e,t,r){g.addDisposer(e,g.addMiddleware(e,(a,l)=>{l(a,()=>{g.getType(a.context)===t&&a.type==="action"&&r(a.name,a.context)})}))}const lc=g.types.compose("FiltersModel",wa,g.types.model({current:g.types.optional(g.types.array(sc),[]),previewValues:g.types.optional(g.types.frozen(),{})})).views(e=>({get idSet(){return new Set(e.current.map(t=>t.id))},get keySet(){return new Set(e.current.map(t=>t.key))},get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get selects(){return e.current.filter(t=>t.type===V.Select).map(t=>({label:t.label??t.id,value:t.id}))},get keyLabelOptions(){return e.current.map(t=>({label:t.label??t.key,value:t.key,widget:t.type}))},get sortedList(){return y.sortBy(e.current,t=>t.label.toLowerCase())}})).actions(e=>({replace(t){e.current=g.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const r=t.filter(a=>!e.idSet.has(a.id));e.current.push(...r)},remove(t){e.current.splice(t,1)},removeByID(t){const r=e.current.findIndex(a=>a.id===t);r>=0&&e.current.splice(r,1)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){u2(e.current,Sn,(r,a)=>{if(r==="setType"){const l=mi(a.config.default_value,a.config);e.setValueByKey(a.key,l),e.updatePreviewValues({...e.previewValues,[a.key]:l})}})}return{afterCreate(){t()}}}),oc=Sa.views(e=>({get canPreviewData(){return e.isTransform?e.config.dep_query_ids.length>0&&!!e.pre_process:!!e.datasource},get guideToPreviewData(){return e.isTransform?"Need to complete settings in Transform tab":"Need to pick a Data Source first"},get usage(){return e.contentModel.findQueryUsage(e.id)},get runBySet(){return new Set(e.run_by)},keyInRunBy(t){return this.runBySet.has(t)}})).actions(e=>({changeRunByRecord(t,r){const a=new Set(e.run_by);r?a.add(t):a.delete(t),e.run_by.length=0,e.run_by.push(...a)}})),ic=g.types.compose("QueriesModel",Ta,g.types.model({current:g.types.optional(g.types.array(oc),[])})).views(e=>({get options(){const t=e.current.map(r=>({value:r.id,label:r.name,_type:"query"}));return y.sortBy(t,r=>r.label.toLowerCase())},get optionsWithoutTransform(){const t=e.current.filter(r=>r.type!==j.Transform).map(r=>({value:r.id,label:r.name,_type:"query"}));return y.sortBy(t,r=>r.label.toLowerCase())},get sortedList(){return y.sortBy(e.current,t=>t.name.toLowerCase())}})).actions(e=>({replace(t){e.current=g.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const r=t.filter(a=>!e.idSet.has(a.id));e.current.push(...r)},remove(t){e.current.splice(t,1)},replaceByIndex(t,r){e.current.splice(t,1,r)},removeQuery(t){const r=e.current.find(a=>a.id===t);r&&(g.detach(r),e.current.remove(r))},removeQueries(t){const r=new Set(t);e.current.forEach(l=>{r.has(l.id)&&g.detach(l)});const a=[...e.current];y.remove(a,l=>r.has(l.id)),e.current=g.cast(a)}})),cc=za.views(e=>({get sortedList(){return y.sortBy(e.current,t=>t.key.toLowerCase())},get options(){const t=e.current.map(r=>({label:r.key,value:r.key,_type:"sql_snippet"}));return y.sortBy(t,r=>r.label.toLowerCase())},get usedFilterKeyMap(){const t=new Map;return e.current.forEach(r=>{const a=y.get(r,"value","");if(!a)return;const l=y.uniq(a.match(Mt.filter)),o=new Set;l.forEach(i=>o.add(i)),t.set(r.key,o)}),t}})).actions(e=>({replace(t){e.current=g.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const r=t.filter(a=>!e.keySet.has(a.key));e.current.push(...r)},remove(t){e.current.splice(t,1)},removeByKey(t){const r=e.current.findIndex(a=>a.key===t);r>=0&&e.current.splice(r,1)},removeByKeys(t){const r=new Set(t);e.current.forEach(l=>{r.has(l.key)&&g.detach(l)});const a=[...e.current];y.remove(a,l=>r.has(l.key)),e.current=g.cast(a)},replaceByIndex(t,r){e.current.splice(t,1,r)}})),p2=g.types.model({data:g.types.optional(g.types.frozen(),[]),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),h2=g.types.model({data:g.types.optional(g.types.frozen(),[]),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),g2=g.types.model({page:g.types.optional(g.types.number,1),limit:g.types.optional(g.types.number,20),data:g.types.optional(g.types.frozen(),[]),total:g.types.optional(g.types.number,0),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get keywords(){return g.getParent(e,1)},get keywordString(){const{table_name:t,table_schema:r}=g.getParent(e,1);return`${r}||${t}`}})).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get maxPage(){return Math.ceil(e.total/e.limit)},get offset(){return(e.page-1)*e.limit},get countSql(){const{table_name:t,table_schema:r}=e.keywords;return`
539
+ `,si=()=>{const{t:e}=x.useTranslation(),[t,r]=h.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{variant:"subtle",size:"compact-sm",onClick:()=>r(a=>!a),children:e(t?"common.actions.close":"filter.widget.common.see_data_structure")}),n.jsx(s.Collapse,{in:t,children:n.jsx(Le.CodeHighlight,{language:"typescript",withCopyButton:!1,code:zS})})]})},DS={[A.Checkbox]:"true",[A.DateRange]:"[new Date('2023-01-01 00:00:00'), new Date('2024-01-01 00:00:00')]",[A.MultiSelect]:"[]",[A.Select]:'""',[A.TreeSelect]:"[]",[A.TreeSingleSelect]:'""',[A.TextInput]:'""'},IS=e=>["function getDefaultValue(filter, utils, context) {",` return ${DS[e]};`,"}"].join(`
540
+ `),St=T.observer(({filter:e})=>{const{t}=x.useTranslation();return n.jsx(nr,{label:"",title:t("filter.field.custom_default_value.title"),triggerLabel:t("filter.field.custom_default_value.trigger"),value:e.default_value_func,onChange:e.setDefaultValueFunc,defaultValue:IS(e.type),triggerButtonProps:{size:"xs",color:"grape",sx:{flexGrow:0,alignSelf:"flex-start"},leftSection:n.jsx(S.IconMathFunction,{size:16})},description:n.jsx(s.Alert,{title:t("filter.field.custom_default_value.tips"),color:"gray",mb:16,children:n.jsxs(s.List,{size:"xs",type:"ordered",children:[n.jsx(s.List.Item,{children:t("filter.field.custom_default_value.tip_1")}),n.jsx(s.List.Item,{children:t("filter.field.custom_default_value.tip_2")})]})})})}),Cn=T.observer(({value:e,onChange:t})=>{const{t:r}=x.useTranslation(),a=W(),l=F(),o=h.useMemo(()=>l.queries.options,[l.queries.current]),i=o.length===0,c=d=>{a.editor.setPath(["_QUERIES_",d])};return n.jsx(s.Select,{label:n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Text,{fw:500,size:"sm",children:r("filter.widget.common.use_query_data_as_options")}),e&&n.jsx(s.Button,{size:"xs",leftSection:n.jsx(S.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>c(e),children:r("query.open")})]}),data:o,value:e,onChange:Z(t),allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:i,error:i?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),li={stroke:1.5,color:"currentColor",opacity:1,size:18},oi={intersect:n.jsx(S.IconLayersIntersect,{...li}),reset:n.jsx(S.IconLayersSubtract,{...li})},MS=({option:e,checked:t})=>n.jsxs(s.Group,{flex:"1",gap:"xs",children:[oi[e.value],e.label]}),ia=T.observer(({config:e})=>{const{t,i18n:r}=x.useTranslation(),a=h.useMemo(()=>[{label:t("filter.widget.common.default_value_mode.intersect"),value:"intersect"},{label:t("filter.widget.common.default_value_mode.reset"),value:"reset"}],[r.language]),{default_value_mode:l}=e;return n.jsx(s.Select,{leftSection:oi[l]??null,label:t("filter.widget.common.default_value_mode.label"),data:a,value:l,onChange:e.setDefaultValueMode,renderOption:MS})}),VS=T.observer(function({filter:t}){const{t:r}=x.useTranslation(),a=t.config;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Checkbox,{checked:a.required,onChange:l=>a.setRequired(l.currentTarget.checked),label:r("filter.widget.select.required")}),n.jsx(St,{filter:t})]}),n.jsx(s.TextInput,{label:r("filter.widget.common.min_width"),value:a.min_width,onChange:l=>a.setMinWidth(l.currentTarget.value),placeholder:"200px"}),n.jsx(s.Divider,{label:r("filter.widget.common.fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(s.Checkbox,{checked:a.treeCheckStrictly,onChange:l=>a.setTreeCheckStrictly(l.currentTarget.checked),label:r("filter.widget.tree_select.strictly")}),n.jsx(Cn,{value:a.options_query_id,onChange:a.setOptionsQueryID}),n.jsx(s.NumberInput,{value:a.default_selection_count,onChange:a.setDefaultSelectionCount,label:r("filter.widget.common.default_selection_count")}),n.jsx(ia,{config:a}),n.jsx(si,{})]})}),ca=({errorMessage:e})=>{const{t}=x.useTranslation();return e?n.jsx(s.Text,{c:"red",size:"12px",children:e}):n.jsx(s.Text,{c:"dimmed",size:"12px",children:t("filter.widget.common.selector_option_empty")})},PS=({rotate:e,onClick:t})=>n.jsx("svg",{onClick:t,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${e})`,children:n.jsx("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),ii=({expanded:e,isLeaf:t,value:r,onClick:a,...l})=>t?n.jsx("span",{style:{width:"14px",display:"inline-block"}}):n.jsx(PS,{rotate:e?"0":"-90",onClick:a,...l}),AS=({onClick:e})=>n.jsxs("svg",{onClick:e,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),n.jsx("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),n.jsx("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),n.jsx("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),ci=({onClick:e,...t})=>n.jsx(AS,{onClick:e,...t}),$S=dt.createStyles((e,{radius:t=4,width:r,name:a})=>({root:{borderRadius:s.getRadius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,position:"absolute",width:`${r} !important`,backgroundColor:"#fff",border:"1px solid #e9ecef",boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{padding:0},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"0px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},"&.rc-tree-select-tree-treenode-disabled":{color:"#aaa",".rc-tree-select-tree-title, .rc-tree-select-tree-iconEle":{cursor:"not-allowed"},".rc-tree-select-tree-iconEle":{"svg .border":{fill:"#ced4da"}}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",width:"100%",padding:"8px 0",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),ES=(e,t,r,a)=>{const l=h.useMemo(()=>{if(!a)return y.cloneDeep(e.filter(f=>!f.disabled));const u=[],p=f=>{f.disabled||u.push(f),f.children.forEach(p)};return e.forEach(p),u},[e,a]),o=h.useMemo(()=>new Set(l.map(u=>u.value)),[l]),i=h.useMemo(()=>new Set(t.map(u=>u.value)),[t]),c=h.useMemo(()=>i.size!==o.size?!1:Array.from(o).every(u=>i.has(u)),[i,o]);return{allValueSet:o,selectedValueSet:i,toggleSelectAll:()=>{if(c){r([]);return}const u=Array.from(l);r(u)},allSelected:c}},BS={root:{cursor:"pointer",backgroundColor:"#FFF","&:hover":{backgroundColor:"var(--mantine-color-default-hover)"},"input, .mantine-Checkbox-labelWrapper":{cursor:"pointer",pointerEvents:"none"}}},LS=({disabled:e,radius:t,style:r,label:a,value:l,onChange:o,treeData:i,errorMessage:c,required:d,treeCheckStrictly:u})=>{const{t:p}=x.useTranslation(),{classes:f,cx:v}=$S({radius:t,width:r.width,name:"FilterTreeSelectWidget"}),[_,w]=h.useState(!1),m=L=>{w(L)},k=_&&(l==null?void 0:l.length)>0,z=ES(i,l,o,u),[D,I]=h.useState("");return n.jsxs(s.Stack,{gap:3,children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsxs(s.Text,{className:f.label,size:"sm",children:[a,d&&n.jsx("span",{className:f.required,"aria-hidden":"true",children:"*"})]}),k&&n.jsx(s.Tooltip,{label:p("filter.widget.common.x_selected",{count:l.length}),children:n.jsx(s.Badge,{variant:"light",children:l.length})})]}),n.jsx(qn,{disabled:e,allowClear:{clearIcon:n.jsx(s.CloseButton,{size:"sm"})},treeCheckStrictly:u,labelInValue:!0,className:v(f.root,"check-select"),dropdownClassName:v(f.dropdown,""),onDropdownVisibleChange:m,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:r,listHeight:510,treeLine:!0,switcherIcon:ii,treeIcon:ci,maxTagTextLength:10,value:l,treeData:i,notFoundContent:n.jsx(ca,{errorMessage:c}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:qn.SHOW_PARENT,onChange:o,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:()=>p("filter.widget.common.x_selected",{count:l.length}),searchValue:D,onSearch:I,dropdownRender:L=>n.jsxs(n.Fragment,{children:[z.allValueSet.size>0&&!D&&n.jsx(s.Group,{px:"xs",pt:8,pb:8,onClick:z.toggleSelectAll,styles:BS,children:n.jsx(s.Checkbox,{size:"xs",checked:z.allSelected,onChange:y.noop,label:p("common.actions.select_all")})}),n.jsx(s.Divider,{}),L]})})]})},qS=T.observer(({label:e,config:t,value:r,onChange:a})=>{const{treeData:l,treeDataLoading:o,errorMessage:i}=t,c=v=>{const _=v.map(w=>w.value);a(_,!1)},d=h.useMemo(()=>t.initialSelection(r),[r,t.initialSelection,o]),u=t.min_width?t.min_width:"200px",f=!!t.options_query_id?o:!1;return n.jsx(LS,{disabled:f,style:{minWidth:"160px",width:u,maxWidth:f?u:"unset",borderColor:"#e9ecef"},value:[...d],onChange:c,treeData:l,errorMessage:i,label:e,required:t.required,treeCheckStrictly:t.treeCheckStrictly})}),OS=T.observer(({filter:e})=>{const{t}=x.useTranslation(),r=e.config;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Checkbox,{checked:r.required,onChange:a=>r.setRequired(a.currentTarget.checked),label:t("filter.widget.select.required")}),n.jsx(St,{filter:e})]}),n.jsx(s.TextInput,{label:t("filter.widget.common.min_width"),value:r.min_width,onChange:a=>r.setMinWidth(a.currentTarget.value),placeholder:"200px"}),n.jsx(s.Divider,{label:t("filter.widget.common.fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(Cn,{value:r.options_query_id,onChange:r.setOptionsQueryID}),n.jsx(s.Checkbox,{checked:r.default_selection_count===1,onChange:a=>r.setDefaultSelectionCount(a.currentTarget.checked?1:0),label:t("filter.widget.tree_single_select.select_first_option_by_default")}),n.jsx(ia,{config:r}),n.jsx(si,{})]})}),NS=dt.createStyles((e,{radius:t=4,width:r,name:a})=>({root:{borderRadius:s.getRadius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},"&.rc-tree-select-focused":{".rc-tree-select-selection-item":{color:"#aaa"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"calc(2.25rem / 3)",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",position:"relative"},".rc-tree-select-selection-search":{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:1,".rc-tree-select-selection-search-input":{height:"36px",paddingLeft:"calc(2.25rem / 3)",textOverflow:"ellipsis"}},".rc-tree-select-selection-item":{position:"absolute",top:0,bottom:0,left:0,paddingLeft:"calc(2.25rem / 3)",color:"#000",lineHeight:"36px",fontSize:"0.875rem",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",transition:"color 200ms ease"},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,paddingTop:"6px",position:"absolute",width:`${r} !important`,"&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"0px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden",transition:"background-color 200ms ease","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-selected":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-disabled":{color:"#aaa",".rc-tree-select-tree-title, .rc-tree-select-tree-iconEle":{cursor:"not-allowed"},".rc-tree-select-tree-iconEle":{"svg .border":{fill:"#ced4da"}}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease",width:"100%",padding:"8px 0","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),GS=({disabled:e,radius:t,style:r,label:a,value:l,onChange:o,treeData:i,errorMessage:c,required:d})=>{x.useTranslation();const{classes:u,cx:p}=NS({radius:t,width:r.width,name:"FilterTreeSelectWidget"});return n.jsxs(s.Stack,{gap:3,children:[n.jsx(s.Group,{justify:"space-between",children:n.jsxs(s.Text,{className:u.label,size:"sm",children:[a,d&&n.jsx("span",{className:u.required,"aria-hidden":"true",children:"*"})]})}),n.jsx(qn,{disabled:e,allowClear:{clearIcon:n.jsx(s.CloseButton,{size:"sm"})},multiple:!1,labelInValue:!0,className:p(u.root,"check-select"),dropdownClassName:p(u.dropdown,""),transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:r,listHeight:510,treeLine:!0,switcherIcon:ii,treeIcon:ci,value:l,treeData:i,notFoundContent:n.jsx(ca,{errorMessage:c}),treeNodeFilterProp:"filterBasis",treeCheckable:!1,onChange:o,onSelect:console.log,showSearch:!0})]})},FS=T.observer(({label:e,config:t,value:r,onChange:a})=>{const{treeData:l,treeDataLoading:o,errorMessage:i}=t,c=v=>{a(v?v.value:null,!1)},d=h.useMemo(()=>t.initialSelection(r),[r,t.initialSelection,t.treeDataLoading]),u=t.min_width?t.min_width:"200px",f=!!t.options_query_id?o:!1;return n.jsx(GS,{disabled:f,style:{width:u,maxWidth:f?u:"unset",borderColor:"#e9ecef"},value:d,onChange:c,treeData:l,errorMessage:i,label:e,required:t.required})});function jS(e){return Ud.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function QS(e){return e.map(t=>{const{label:r,description:a,...l}=t,o={...l,filterBasis:`${r}___${a??""}`,description:a,label:r};return a&&(o.label=h.createElement("div",{},[h.createElement(s.Text,{key:0,title:t.label},t.label),h.createElement(s.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description},t.description)])),o})}const di=g.types.compose("FilterConfigModel_BaseTreeSelect",g.types.model({min_width:g.types.optional(g.types.string,""),default_value_mode:ea}),ra).views(e=>({get plainData(){const{data:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t},get treeData(){const t=this.plainData,r=QS(t);return jS(r)},get errorMessage(){const{error:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t},get treeDataLoading(){const{state:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t==="loading"}})).actions(e=>({setMinWidth(t){e.min_width=t}})),da=g.types.compose("FilterTreeSelectConfigMeta",g.types.model({_name:g.types.literal("tree-select"),default_value:g.types.optional(g.types.array(g.types.string),[]),treeCheckStrictly:g.types.optional(g.types.boolean,!1)}),di).views(e=>({get json(){const{_name:t,default_value:r,default_value_mode:a,required:l,min_width:o,static_options:i,options_query_id:c,default_selection_count:d,treeCheckStrictly:u}=e;return{_name:t,required:!!l,min_width:o,default_value:r,static_options:i,options_query_id:c,treeCheckStrictly:u,default_value_mode:a,default_selection_count:d}},get defaultSelection(){const t=e.filter.formattedDefaultValue;if(Array.isArray(t)&&t.length>0)return t;const{default_selection_count:r}=e;return r?e.treeData.slice(0,r).map(l=>l.value):[]},optionsByValues(t){if(!Array.isArray(t)||t.length===0)return[];const r=new Set(t);return e.options.filter(a=>r.has(a.value))},valueObjects(t){const r=new Set(t);return e.plainData.filter(a=>r.has(a.value))},initialSelection(t){return t?this.valueObjects(t):this.valueObjects(this.defaultSelection)},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=g.cast(t)},setDefaultValueMode(t){t!=="intersect"&&t!=="reset"||(e.default_value_mode=t)},setTreeCheckStrictly(t){e.treeCheckStrictly=t},applyDefaultSelection(){if(e.optionsLoading)return;if(e.default_value_mode==="reset"){e.filter.setValue(e.defaultSelection);return}const t=e.filter.value,r=new Set(e.plainData.map(l=>l.value)),a=(t??[]).filter(l=>r.has(l));a.length>0?e.filter.setValue(a):e.filter.setValue(e.defaultSelection)},afterCreate(){g.addDisposer(e,Q.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),ui=()=>da.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),ua=g.types.compose("FilterTreeSingleSelectConfigMeta",g.types.model({_name:g.types.literal("tree-single-select"),default_value:g.types.optional(g.types.string,"")}),di).views(e=>({get json(){const{_name:t,default_value:r,default_value_mode:a,required:l,min_width:o,static_options:i,options_query_id:c,default_selection_count:d}=e;return{_name:t,required:!!l,min_width:o,default_value:r,static_options:i,options_query_id:c,default_value_mode:a,default_selection_count:d}},get selectFirstByDefault(){return e.default_selection_count===1},get defaultSelection(){if(e.treeDataLoading)return"";const t=e.filter.formattedDefaultValue;return t||(this.selectFirstByDefault&&e.treeData.length>0?e.treeData[0].value:"")},valueObject(t){if(t)return e.plainData.find(r=>r.value===t)},initialSelection(t){if(t)return this.valueObject(t)},truthy(t){return typeof t=="string"&&t!==""}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDefaultValueMode(t){t!=="intersect"&&t!=="reset"||(e.default_value_mode=t)},applyDefaultSelection(){if(e.treeDataLoading)return;if(e.default_value_mode==="reset"){e.filter.setValue(e.defaultSelection);return}const t=e.filter.value;e.optionValuesSet.has(t)?e.filter.setValue(t):e.filter.setValue(e.defaultSelection)},afterCreate(){g.addDisposer(e,Q.reaction(()=>Q.toJS(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),pi=()=>ua.create({_name:"tree-single-select",default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),Sn=g.types.model("FilterMeta",{id:g.types.identifier,key:g.types.string,label:g.types.string,order:g.types.number,visibleInViewsIDs:g.types.array(g.types.string),auto_submit:g.types.optional(g.types.boolean,!1),default_value_func:g.types.optional(g.types.string,""),type:g.types.enumeration("DashboardFilterType",[A.Select,A.MultiSelect,A.TreeSelect,A.TreeSingleSelect,A.TextInput,A.Checkbox,A.DateRange]),config:g.types.union(sa,aa,da,ua,la,ta,na)}).views(e=>({get contentModel(){return g.getRoot(e).content},get filters(){return this.contentModel.filters},get value(){return this.filters.values[e.key]},get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==A.TreeSelect&&e.type!==A.TreeSingleSelect},get usingDefaultValueFunc(){return!!e.default_value_func},get formattedDefaultValue(){return this.filters.formattedDefaultValues[e.key]},get auto_submit_supported(){return[A.Select,A.Checkbox,A.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:r,label:a,order:l,visibleInViewsIDs:o,default_value_func:i,auto_submit:c,type:d,config:u}=e;return{id:t,key:r,type:d,label:a,order:l,config:u.json,auto_submit:c,visibleInViewsIDs:Q.toJS(o),default_value_func:i}},get visibleInViewsIDSet(){return new Set(e.visibleInViewsIDs)},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return y.get(e.config,"required",!1)?y.get(e.config,"truthy",()=>!0)(t):!1}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.filters.setValueByKey(e.key,t)},setLabel(t){e.label=t},setOrder(t){const r=Number(t);Number.isFinite(r)&&(e.order=r)},setType(t){switch(t){case A.Select:e.config=ai();break;case A.MultiSelect:e.config=ri();break;case A.TreeSelect:e.config=ui();break;case A.TreeSingleSelect:e.config=pi();break;case A.TextInput:e.config=oa();break;case A.Checkbox:e.config=Zo();break;case A.DateRange:e.config=ti();break;default:return}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t},setDefaultValueFunc(t){e.default_value_func=t}}));var $=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))($||{});const pa=g.types.model("ViewDivisionConfig",{_name:g.types.literal($.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),hi=()=>pa.create({_name:$.Division}),WS=g.types.model("CustomModalTitleModel",{enabled:g.types.optional(g.types.boolean,!1),func_content:g.types.optional(g.types.string,"")}).views(e=>({get json(){const{enabled:t,func_content:r}=e;return{enabled:t,func_content:r}},get value(){const{enabled:t,func_content:r}=e,a=g.getParent(e,2),l=g.getRoot(e);if(!t)return a.name;try{const o={filters:l.content.filters.valuesForPayload,context:l.context.current};return new Function(`return ${r}`)()(o)}catch(o){return console.error(o),a.name}}})).actions(e=>({setEnabled(t){e.enabled=t},setFuncContent(t){e.func_content=t},replace({enabled:t,func_content:r}){e.enabled=t,e.func_content=r}})),Tn={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
541
+ `)},ha=g.types.model("ViewModalConfig",{_name:g.types.literal($.Modal),width:g.types.string,height:g.types.string,custom_modal_title:g.types.optional(WS,Tn)}).views(e=>({get json(){const{_name:t,width:r,height:a,custom_modal_title:l}=e;return{_name:t,width:r,height:a,custom_modal_title:l.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),gi=()=>ha.create({_name:$.Modal,width:"90vw",height:"90vh"}),US=g.types.model("ViewTabsTabModel",{id:g.types.identifier,name:g.types.string,view_id:g.types.string,color:g.types.optional(g.types.string,""),order:g.types.optional(g.types.number,0)}).views(e=>({get json(){const{id:t,name:r,view_id:a,color:l,order:o}=e;return{id:t,name:r,color:l,order:o,view_id:a}}})).actions(e=>({setName(t){e.name=t},setViewID(t){t&&(e.view_id=t)},setColor(t){e.color=t},setOrder(t){typeof t!="string"&&(e.order=t)}})),ga=g.types.model("ViewTabsConfig",{_name:g.types.literal($.Modal),tabs:g.types.optional(g.types.array(US),[]),variant:g.types.optional(g.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:g.types.optional(g.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:g.types.optional(g.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:r,orientation:a,tabs:l,grow:o}=e;return{grow:o,tabs:l.map(i=>i.json),_name:t,variant:r,orientation:a}},get tabsInOrder(){return y.sortBy(e.tabs,"order")}})).actions(e=>({setVariant(t){t&&(e.variant=t)},setOrientation(t){t&&(e.orientation=t)},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=g.cast(t)},addTab(){const t=ne.randomId(),r={id:t,name:t,view_id:""};e.tabs.push(r)},removeTab(t){e.tabs.splice(t,1)}})),fi=()=>ga.create({_name:$.Modal,tabs:[]}),bi=g.types.model({id:g.types.identifier,name:g.types.string,type:g.types.enumeration("EViewComponentType",[$.Division,$.Modal,$.Tabs]),config:g.types.union(pa,ha,ga),panelIDs:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get json(){const{id:t,name:r,type:a,config:l}=e;return{id:t,name:r,type:a,config:l.json,panelIDs:e.panelIDs.map(o=>o)}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case $.Division:e.config=hi();break;case $.Modal:e.config=gi();break;case $.Tabs:e.config=fi();break;default:return}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},appendPanelIDs(t){e.panelIDs.push(...t)},removePanelID(t){const r=e.panelIDs.filter(a=>a!==t);e.panelIDs.length=0,e.panelIDs.push(...r)}})),at="14.32.0",KS={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:$.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:at,layouts:[{id:"basis",name:"basis",list:[],breakpoint:0}]},fa=g.types.model("DataSourceMetaModel",{id:g.types.string,type:g.types.enumeration("DataSourceType",[j.HTTP,j.MySQL,j.Postgresql,j.MericoMetricSystem]),key:g.types.string,config:g.types.frozen()}),yi=g.types.model("DataSourcesMetaModel",{list:g.types.optional(g.types.array(fa),[])}).views(e=>({find({type:t,key:r}){return e.list.find(a=>a.key===r&&a.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),vi=g.types.model({id:g.types.string,content:g.types.string,create_time:g.types.string,update_time:g.types.string,is_preset:g.types.boolean}),ba=g.types.model("GlobalSQLSnippetsMeta",{list:g.types.optional(g.types.array(vi),[])}).views(e=>({find(t){return e.list.find(r=>r.id===t)},get options(){return e.list.map(t=>({value:t.id,label:t.id}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),kn=g.types.model("ContextMeta",{current:g.types.optional(g.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,r){e.current[t]=r}}));function ya(e){return kn.create({current:e})}const va=g.types.compose("ViewRenderModel",bi,g.types.model({tab:g.types.optional(g.types.string,"")})).views(e=>({get tabs(){return e.config.tabs},get tabInfo(){const t=this.tabs.find(r=>r.id===e.tab);return t?{id:t.id,name:t.name}:null},get tabView(){return e.type!==$.Tabs?null:this.tabs.find(t=>t.id===e.tab)},get tabViewID(){return this.tabView?this.tabView.view_id??"":""},get contentModel(){return g.getParent(e,3)},get panels(){if(e.type!==$.Tabs)return this.contentModel.panels.panelsByIDs(e.panelIDs);const t=this.tabViewID,r=this.contentModel.views.findByID(t);return(r==null?void 0:r.panels)??[]},get renderViewIDs(){const t=[e.id];return e.type===$.Tabs&&t.push(this.tabViewID),t},async downloadScreenshot(t){const r=t.offsetWidth*2+10,a=t.offsetHeight*2+10,l=new bs,o=new Date().getTime(),i=await fs.toBlob(t,{bgcolor:"white",width:r,height:a,style:{transformOrigin:"0 0",transform:"scale(2)"}});l.file(`${e.name}_${o}.png`,i),l.file(`dashboard_state_${o}.json`,JSON.stringify(this.contentModel.dashboardStateValues,null,4)),l.generateAsync({type:"blob"}).then(c=>{Xt.saveAs(c,`${e.name}_${o}.zip`)}).catch(c=>{console.error(c),Ye.notifications.show({color:"red",title:"Failed to download screenshot with dashboard state",message:c.message})})}})).actions(e=>({setTab(t){e.tab=t??""},setTabByTabInfo(t){e.tab=t.id??""}})),_a=g.types.model("ViewsRenderModel",{current:g.types.optional(g.types.array(va),[]),visibleViewIDs:g.types.array(g.types.string)}).views(e=>({get json(){return e.current.map(t=>tt(t.json))},get idMap(){const t=new Map;return e.current.forEach(r=>{t.set(r.id,r)}),t},findByID(t){return e.current.find(r=>r.id===t)},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:r})=>r===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:r})=>t.has(r))},get firstVisibleTabsView(){return this.visibleViews.find(t=>t.type===$.Tabs)},get firstVisibleTabsViewActiveTab(){const t=this.firstVisibleTabsView;return t?t.tabInfo:null},get firstVisibleTabsViewActiveTabStr(){return JSON.stringify(this.firstVisibleTabsViewActiveTab)}})).actions(e=>({appendToVisibles(t){new Set(e.visibleViewIDs.map(a=>a)).has(t)||e.visibleViewIDs.push(t)},rmVisibleViewID(t){const r=e.visibleViewIDs.findIndex(a=>a===t);r!==-1&&e.visibleViewIDs.splice(r,1)},setFirstVisibleTabsViewActiveTab(t){if(!t)return;const r=e.firstVisibleTabsView;r==null||r.setTabByTabInfo(t)}}));function _i(e,t){const r=e.length>0?[e[0].id]:[],a=e.map(l=>{const{_name:o=l.type}=l.config,i={...l,tab:"",config:{...l.config,_name:o},panelIDs:l.panelIDs};if(l.type===$.Tabs){let c=y.minBy(l.config.tabs,d=>d.order);!c&&l.config.tabs.length>0&&(c=l.config.tabs[0]),i.tab=(c==null?void 0:c.id)??""}return i});return t&&(a[0].tab=t.id),{current:a,visibleViewIDs:r}}const YS=new Wd.AsyncParser({withBOM:!0});async function xi(e){return!Array.isArray(e)||e.length===0?"":await YS.parse(e).promise()}async function wi(e,t){const r=await xi(t),a=new Blob([r],{type:"text/csv"});Xt.saveAs(a,`${e}.csv`)}function mi(e,t){const r=new bs,a=t.map(async({id:l,data:o})=>{const i=await xi(o);r.file(`${l}.csv`,i)});Promise.all(a).then(()=>{r.generateAsync({type:"blob"}).then(l=>{Xt.saveAs(l,`${e}.zip`)})}).catch(l=>{console.error(l),Ye.notifications.show({color:"red",title:"Failed to download data",message:l.message})})}function Bt(e,t){const r=new Blob([t],{type:"application/json"});Xt.saveAs(r,`${e}.json`)}const xa=No.views(e=>({get contentModel(){return g.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},get firstQuery(){return this.queries.length>0?this.queries[0]:null},get firstQueryData(){return this.firstQuery?this.firstQuery.data:[]},queryByID(t){return this.queries.find(r=>r.id===t)},get data(){return this.queries.reduce((t,r)=>(t[r.id]=r.data,t),{})},get variableStrings(){return ol(e.variables,this.data)},get variableAggValueMap(){const t={},r=this.data;return e.variables.reduce((a,l)=>(a[l.name]=Je(l,r),a),t),t},get variableValueMap(){const t={},r=this.variableAggValueMap;return e.variables.reduce((a,l)=>(a[l.name]=$e(l,r[l.name]),a),t),t},get variableStyleMap(){const t=this.variableValueMap,r={};return e.variables.reduce((a,l)=>{const o=_u(l.color,t[l.name]);return a[l.name]={color:o,"font-size":l.size,"font-weight":l.weight,variable:l},a},r),r},get dataLoading(){return this.queries.some(t=>t.isTransform?t.depQueryModelStates.some(r=>r==="loading"):t.state==="loading")},get queryStateMessages(){const t=this.queries.filter(o=>!o.runByConditionsMet);if(t.length===0)return"";const r=new Set,a=new Set;t.forEach(o=>{const i=o.conditionNames;i.context.forEach(c=>r.add(c)),i.filters.forEach(c=>a.add(c))});const l=[];return r.size>0&&l.push(`context: ${Array.from(r).join(", ")}`),a.size>0&&l.push(`filter${a.size>1?"s":""}: ${Array.from(a).join(", ")}`),l.length===2&&l.splice(1,0,"and"),l.unshift("Waiting for"),l.join(" ")},get queryErrors(){return this.queries.map(t=>t.error??t.metricQueryPayloadErrorString).filter(t=>!!t)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages===""&&!this.dataLoading}})).actions(e=>({refreshData(){e.queries.forEach(t=>t.fetchData(!0))},downloadData(){e.contentModel.queries.downloadDataByQueryIDs(e.name,e.queryIDs)},getSchema(){const t=e.json;return t.viz.conf={...t.viz.conf,__INTERACTIONS:{},__OPERATIONS:{},__TRIGGERS:{}},{panel:t,queries:e.queries.map(r=>r.json),layouts:e.contentModel.layouts.jsonByPanelIDSet(new Set([e.id]))}},downloadSchema(){const{panel:t,queries:r,layouts:a}=this.getSchema(),o=JSON.stringify({panels:[t],definition:{queries:r},layouts:a,version:at},null,2),i=e.name;Bt(i,o)}}));function Ci(e){return{id:e,name:"Panel",title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:Br.name,conf:Br.createConfig()},style:{border:{enabled:!0}}}}const wa=g.types.model("PanelsRenderModel",{list:g.types.optional(g.types.array(xa),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(r=>r.id===t)},get idMap(){const t=new Map;return e.list.forEach(r=>{t.set(r.id,r)}),t}})).views(e=>({panelsByIDs(t){const r=[];return t.forEach(a=>{const l=e.idMap.get(a);l?r.push(l):console.warn(`Panel is not found, id:${a}`)}),r}}));function Si(e){const t=e.config,r=t==null?void 0:t.default_value;return r===void 0?r:t._name==="date-range"?Ro(t):r}function XS(e,t){const r=e.default_value_func;try{const a=new Function(`return ${r}`)()(e,Ge,t);return e.config._name==="date-range"&&Array.isArray(a)?{value:a,shortcut:null}:a}catch(a){return console.error(a),Si(e)}}function Ti(e,t){var r;return(r=e.default_value_func)!=null&&r.trim()?XS(e,t):Si(e)}function ki(e,t){return e.reduce((r,a)=>(r[a.key]=Ti(a,t),r),{})}function zi(e,t){const r={};return Object.entries(t).forEach(([a,l])=>{const o=e[a];if(typeof l!="object"||!("shortcut"in l)||!o)return r[a]=o??l,r;if(Array.isArray(o))return console.log("⚪️ adapting legacy date-range value: ",o),r[a]={value:o,shortcut:null},r;const i=o;return i.shortcut?(r[a]=mn(i.shortcut),r):(console.log("⚪️ skipping input date range when it has no shortcut",i),r[a]=l,r)}),r}const ma=g.types.model("FiltersRenderModel",{current:g.types.optional(g.types.array(Sn),[]),values:g.types.optional(g.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get valuesString(){return JSON.stringify(e.values)},get filter(){return g.getParent(e)},get keysToTypes(){return e.current.reduce((t,r)=>(t[r.key]=r.type,t),{})},keyStateItemMap(t){return e.current.reduce((r,a)=>{const l=t[a.key];return r[a.key]={type:a.type,key:a.key,model:a,label:a.label??a.id,value:l},r},{})},get valuesForPayload(){const t={};return Object.entries(e.values).forEach(([r,a])=>{t[r]=a;const l=this.findByKey(r);l&&l.config._name==="date-range"&&(t[r]=l.config.dateStringsValue)}),t},get contentModel(){return g.getRoot(e).content},get context(){return this.contentModel.payloadForSQL.context},get initialValuesDep(){return JSON.stringify({filters:e.current.map(({default_value_func:t,config:r})=>({default_value_func:t,config:r})),context:this.contentModel.payloadForSQL.context})},get formattedDefaultValues(){return ki(this.json,this.contentModel.context)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(r=>r.id===t)},findByKey(t){return e.current.find(r=>r.key===t)},findByIDSet(t){return e.current.filter(r=>t.has(r.id))},get inOrder(){return y.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return y.sortBy(e.current.filter(r=>r.visibleInViewsIDSet.has(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keySet(){return new Set(e.current.map(t=>t.key))},get keyLabelMap(){return e.current.reduce((t,r)=>(t[r.key]=r.label,t),{})},get keyIDMap(){return e.current.reduce((t,r)=>(t[r.key]=r.id,t),{})},getSelectOption(t){const r=this.findByID(t);if(!r||!("getSelectOption"in r.config))return null;const a=e.values[r.key];return r.config.getSelectOption(a)}})).actions(e=>({setValues(t){console.debug("⚪️ setting filter values: ",JSON.stringify(t)),e.values=t},patchValues(t){console.debug("⚪️ patching filter values: ",JSON.stringify(t)),e.values=zi(t,e.values)},setValueByKey(t,r){console.debug(`⚪️ setting filter[${t}] to value: `,JSON.stringify(r)),e.values={...e.values,[t]:r}},applyValuesPatch(t){e.values={...e.values,...t}},getValueByKey(t){return e.values[t]},getSchema(t,r){return{filters:e.findByIDSet(new Set(t)).map(o=>({...o.json,visibleInViewsIDs:r?o.json.visibleInViewsIDs:[]})),version:at}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t,!1),null,2);Bt("Filters",r)}}));function Ca(e,t,r,a){const l={...r,...t},o=ki(e,l),i=zi(a,o);return console.groupCollapsed("⚪️ initialValues"),console.log("filters",e),console.log("defaultValues",o.date_range),console.log("filterValues.date_range: ",a.date_range),console.log("initialValues.date_range: ",i.date_range),console.groupEnd(),{current:e,values:i}}function ZS(e,t){const r=ys.decode(t);r!==e&&(console.error("Inconsistent sql"),console.groupCollapsed("Inconsistent sql"),console.table({before:e,after:t,v:r}),console.groupEnd())}async function JS({query:e,name:t,payload:r,additionals:a},l){if(!e.sql)return[];const{type:o,key:i,sql:c,pre_process:d,post_process:u}=e,p=or(c,r),f=zp({sql:p,pre_process:d}),v=ys.encode(f);ZS(f,v);let _=await Ve.query(l)({type:o,key:i,query:v,...a},{params:{name:t}});return _=Dp(u,_,lr(r)),_}async function HS({type:e,key:t,configString:r,name:a,additionals:l},o){try{return await Ve.httpDataSourceQuery(o)({type:e,key:t,query:r,...l},{params:{name:a}})}catch(i){if(Se.isCancel(i))throw i;return console.error(i),i}}async function RS({key:e,configString:t,name:r,additionals:a},l){try{return await Ve.mericoMetricQuery(l)({type:"merico_metric_system",key:e,query:t,...a},{params:{name:r}})}catch(o){throw o}}async function Sa(){try{return(await Ve.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function Di(){try{return(await Ve.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}const Ii=Uo.views(e=>({get rootModel(){return g.getRoot(e)},get contentModel(){return this.rootModel.content},get conditionOptions(){return this.contentModel.dashboardStateVariableOptions},getConditionOptionsWithInvalidValue(t){const{optionGroups:r,validValues:a}=this.conditionOptions;if(!t||a.has(t))return this.conditionOptions;const l={group:"common.invalid",items:[{label:t,value:t}]};return{optionGroups:[...r,l],validValues:a}},get conditionOptionsWithInvalidRunbys(){const{optionGroups:t,validValues:r}=this.conditionOptions,a={group:"common.invalid",items:[]};return e.run_by.forEach(l=>{r.has(l)||a.items.push({label:l,value:l})}),{optionGroups:[...t,a],validValues:r}},get unmetRunByConditions(){if(!g.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const r=this.contentModel.payloadForSQL;return t.filter(a=>{const l=y.get(r,a);return Array.isArray(l)?l.length===0:typeof l=="number"?Number.isNaN(l):!l})}})).views(e=>({get payload(){return e.contentModel.payloadForSQL},get formattedSQL(){const t=y.get(e,"config.sql","");return ir(t,this.payload)},get httpConfigString(){const{context:t,filters:r}=this.payload,{name:a,pre_process:l}=e.json,o=kp(l,t,r);return console.groupCollapsed(`Request config for: ${a}`),console.log(o),console.groupEnd(),JSON.stringify(o)},get typedAsSQL(){return[j.Postgresql,j.MySQL].includes(e.type)},get typedAsHTTP(){return[j.HTTP].includes(e.type)},get isMericoMetricQuery(){return e.type===j.MericoMetricSystem},get isTransform(){return e.type===j.Transform},get reQueryKey(){const t=y.get(e,"config.react_to",[]);if(t.length===0)return"";const r=e.contentModel.payloadForSQL,a=[...t].reduce((l,o)=>(l[o]=y.get(r,o),l),{});return JSON.stringify(a)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=e.contentModel.filters,r=e.unmetRunByConditions.filter(l=>l.startsWith("context.")).map(l=>l.replace("context.","")),a=e.unmetRunByConditions.filter(l=>l.startsWith("filters.")).map(l=>y.get({filters:t},l,l.replace("filters.",""))).filter(l=>!!l);return{context:r,filters:a}},get queries(){return g.getParent(e,2)},get inUse(){return this.queries.isQueryInUse(e.id)},get dependencies(){if(!this.typedAsSQL)return[];const t=y.get(e,"config.sql","");if(!t)return[];const r=y.uniq(t.match(Mt.sqlSnippet)),a=y.uniq(t.match(Mt.filter)),l=y.uniq(t.match(Mt.context)),o=[];return r.forEach(i=>{o.push({type:"sql_snippet",key:i,valid:e.contentModel.sqlSnippets.keySet.has(i)})}),a.forEach(i=>{o.push({type:"filter",key:i,valid:e.contentModel.filters.keySet.has(i)})}),l.forEach(i=>{o.push({type:"context",key:i,valid:e.contentModel.mock_context.keySet.has(i)})}),o},get usedFilterKeySet(){const t=new Set,r=i=>{t.add(i.replace(/^filters\./,""))};if(e.run_by.forEach(i=>r(i)),y.get(e.config,"react_to",[]).forEach(i=>r(i)),!this.typedAsSQL)return t;const l=y.get(e,"config.sql","");return l&&y.uniq(l.match(Mt.filter)).forEach(i=>r(i)),t},get metricQueryPayload(){if(e.type!==j.MericoMetricSystem)return null;const t=this.payload,r={filters:e.contentModel.filters.keysToTypes},a=e.config,l=a.filters.reduce((f,v)=>{const _=y.get(t,v.variable),w=y.get(r,v.variable),m=v.dimension;if(w===A.DateRange){const z=_.every(D=>Number.isFinite(Number(D)))?_.map(D=>Number(D)):_;f[m]={between:z}}else Array.isArray(_)?f[m]={in:_}:f[m]={eq:_};return f},{}),o={id:a.id,type:a.type,filters:l,groupBys:a.groupBys};if(a.useDefaultValues&&(o.useDefaultValues=!0),!a.timeQuery.enabled)return o;const{range_variable:i,unit_variable:c}=a.timeQuery,d="YYYY-MM-DD",u="PRC",p={start:"",end:"",unitOfTime:y.get(t,c,""),unitNumber:1,timezone:"PRC",stepKeyFormat:d};if(i){const f=y.get(t,i);Array.isArray(f)&&f.length===2&&(p.start=M(f[0]).tz(u).format(d),p.end=M(f[1]).tz(u).format(d))}return o.timeQuery=p,o},get metricQueryPayloadString(){return this.metricQueryPayload?JSON.stringify(this.metricQueryPayload,null,2):""},get metricQueryPayloadError(){const t=[];if(!this.metricQueryPayload)return t;const r=e.config,{timeQuery:a}=this.metricQueryPayload;if(!a)return r.groupByValues.length>2&&t.push("分组聚合维度:最多支持两个维度的聚合计算"),t;r.groupByValues.length>1&&t.push("分组聚合维度:按时间序列展示时,仅可选择一个聚合维度");const{start:l,end:o,unitOfTime:i}=a;return(!l||!o)&&t.push("时间维度:时间范围不完整"),i||t.push("步长:必选"),t},get metricQueryPayloadErrorString(){return this.metricQueryPayloadError.join(`
542
+ `)},get metricQueryPayloadValid(){return this.metricQueryPayload?this.metricQueryPayloadError.length===0:!1}})),Ta=g.types.compose("QueryRenderModel",Ii,g.types.model({state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),data:g.types.optional(g.types.frozen([]),[]),error:g.types.optional(g.types.frozen(),null)})).views(e=>({get datasource(){const{key:t,type:r}=e;return e.rootModel.datasources.find({type:r,key:t})},get additionalQueryInfo(){return e.contentModel.getAdditionalQueryInfo(e.id)},get depQueryModels(){const t=y.get(e,"config.dep_query_ids",[]);return e.contentModel.queries.findByIDSet(new Set(t))},get depQueryModelStates(){return this.depQueryModels.map(t=>t.state)},get depQueryModelStatesString(){return this.depQueryModelStates.toString()}})).views(e=>({get stateMessage(){if(e.state!=="idle")return"";if(!e.runByConditionsMet){const{context:t,filters:r}=e.conditionNames;if(t.length===0&&r.length===0)return"Waiting";const a=[];return t.length>0&&a.push(`context: ${t.join(", ")}`),r.length>0&&a.push(`filter${r.length>1?"s":""}: ${r.join(", ")}`),a.length===2&&a.splice(1,0,"and"),a.unshift("Waiting for"),a.join(" ")}return e.data.length>0?"":"data.empty_data"}})).volatile(()=>({controller:new AbortController})).actions(e=>({setData(t){e.data=t},setError(t){e.error=t}})).actions(e=>({runSQL:g.flow(function*(){var t;if(e.valid&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const r=e.payload,a=e.config;e.data=yield*g.toGenerator(JS({payload:r,name:e.name,query:{type:e.type,key:e.key,sql:a.sql,pre_process:e.pre_process,post_process:e.post_process},additionals:e.additionalQueryInfo},e.controller.signal)),e.state="idle",e.error=null}catch(r){if(Se.isCancel(r))console.debug(`🟡 Query[${e.name}] is cancelled`),e.data=[],e.state="idle";else{e.data=[];const a=y.get(r,"message","unkown error");e.error=y.get(r,"response.data.detail.message",a),e.state="error"}}}}),runHTTP:g.flow(function*(){var t;if(!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{type:r,key:a,post_process:l}=e.json;let o=JSON.parse(e.httpConfigString);o=rn(e.datasource,o);const i=yield*g.toGenerator(HS({type:r,key:a,configString:JSON.stringify(o),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),c=an(e.datasource,i),d=cl(l,c,e.contentModel.dashboardStateValues);e.data=d,e.state="idle",e.error=null}catch(r){if(console.error(r),Se.isCancel(r))console.debug(`🟡 Query[${e.name}] is cancelled`),e.data=[],e.state="idle";else{e.data=[];const a=y.get(r,"message","unkown error");e.error=y.get(r,"response.data.detail.message",a),e.state="error"}}}}),runMericoMetricQuery:g.flow(function*(){var t;if(!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet&&e.metricQueryPayloadValid)){e.controller=new AbortController,e.state="loading";try{const{type:r,key:a,post_process:l}=e.json;let o={url:"/api/metric_management/query",method:"POST",data:e.metricQueryPayload};o=rn(e.datasource,o);const i=yield*g.toGenerator(RS({key:a,configString:JSON.stringify(o),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),c=an(e.datasource,i),d=cl(l,c,e.contentModel.dashboardStateValues);e.data=d.data,e.state="idle",e.error=null}catch(r){if(console.error(r),Se.isCancel(r))console.debug(`🟡 Query[${e.name}] is cancelled`),e.data=[],e.state="idle";else{e.data=[];const a=y.get(r,"message","unkown error");e.error=y.get(r,"response.data.detail.message",a),e.state="error"}}}}),runTransformation(){e.state="loading";try{const t=e.depQueryModels.map(o=>({id:o.id,name:o.name,data:y.cloneDeep(o.data)})),r=e.contentModel.dashboardStateValues,a=e.pre_process,l=new Function(`return ${a}`)()(t,r,Ge);e.data=l,e.state="idle",e.error=null}catch(t){e.data=[],e.error=t.message,e.state="error"}}})).actions(e=>({fetchData:t=>{if(!e.inUse&&!t){console.debug(`🟡 Skipping query[${e.name}]`);return}return console.debug(`🔵 Running query[${e.name}]`),e.isTransform?e.runTransformation():e.typedAsHTTP?e.runHTTP():e.isMericoMetricQuery?e.runMericoMetricQuery():e.runSQL()},beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>{var r,a;if(e.isTransform){const l=e.config;return[e.inUse,e.id,e.key,e.reQueryKey,l.dep_query_ids.toString(),e.pre_process,e.depQueryModelStatesString].join("--")}return e.typedAsHTTP?`${e.inUse}--${e.id}--${e.key}--${e.reQueryKey}--${(r=e.datasource)==null?void 0:r.id}`:e.isMericoMetricQuery?`${e.inUse}--${e.id}--${e.key}--${e.reQueryKey}--${e.metricQueryPayloadString}--${(a=e.datasource)==null?void 0:a.id}`:[e.inUse,e.id,e.key,e.formattedSQL,e.pre_process,e.post_process].join("--")},()=>e.fetchData(!1),{fireImmediately:!0,delay:0}))}})),ka=g.types.model("QueriesRenderModel",{current:g.types.optional(g.types.array(Ta),[])}).views(e=>({get idSet(){return new Set(e.current.map(t=>t.id))},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(r=>r.id===t)},findByIDSet(t){return e.current.filter(r=>t.has(r.id))},get json(){return e.current.filter(t=>t.id&&t.key).map(t=>t.json)},get root(){return g.getRoot(e)},get dashboardName(){return this.root.name},get contentModel(){return g.getParent(e,1)},get visibleQueryIDSet(){const{views:t,filters:r}=this.contentModel,a=[];t.visibleViews.forEach(i=>{i.panels.forEach(c=>{a.push(...c.queryIDs)})});const l=y.uniq(t.visibleViews.map(i=>i.renderViewIDs).flat());r.current.forEach(i=>{const c=y.get(i,"config.options_query_id");if(!c)return;l.some(u=>i.visibleInViewsIDSet.has(u))&&a.push(c)}),this.findByIDSet(new Set(a)).forEach(i=>{const c=i.config;!i.isTransform||c.dep_query_ids.length===0||a.push(...c.dep_query_ids)});const o=new Set(a);return console.debug("QueryIDs:",o),o},isQueryInUse(t){return this.visibleQueryIDSet.has(t)},addTransformDepQueryIDs(t,r){this.findByIDSet(t).forEach(a=>{const l=a.config;!a.isTransform||l.dep_query_ids.length===0||l.dep_query_ids.forEach(o=>{r!=null&&r.has(o)||t.add(o)})})},get querisToForceReload(){const t=new Set,r=new Set,{views:a,filters:l}=this.contentModel,o=y.uniq(a.visibleViews.map(i=>i.renderViewIDs).flat());return l.current.forEach(i=>{const c=y.get(i,"config.options_query_id");if(!c)return;o.some(u=>i.visibleInViewsIDSet.has(u))&&t.add(c)}),this.addTransformDepQueryIDs(t),a.visibleViews.forEach(i=>{i.panels.forEach(c=>{c.queryIDs.forEach(d=>{t.has(d)||r.add(d)})})}),this.addTransformDepQueryIDs(r,t),{filterQueries:this.findByIDSet(t),panelQueries:this.findByIDSet(r)}}})).actions(e=>({downloadAllData(){const t=e.current.map(({name:r,data:a})=>({id:r,data:a}));mi(e.dashboardName,t)},downloadDataByQueryIDs(t,r){if(r.length===1)return this.downloadDataByQueryID(t,r[0]);const a=new Set(r),l=e.current.filter(o=>a.has(o.id)).map(({name:o,data:i})=>({id:o,data:i}));mi(t,l)},downloadDataByQueryID(t,r){const a=e.findByID(r);if(!a){console.log("[downloadDataByQueryID] query not found");return}const{data:l}=a,o=t??a.name;wi(o,l)},refetchDataByQueryID(t){const r=e.findByID(t);if(!r){console.error(new Error(`[downloadDataByQueryID] query by ID[${t}] not found`));return}return r.fetchData(!0)},getSchema(t){return{definition:{queries:e.findByIDSet(new Set(t)).map(l=>l.json)},version:at}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t),null,2);Bt("Queries",r)},forceReloadVisibleQueries:g.flow(function*(){const{filterQueries:t,panelQueries:r}=e.querisToForceReload;if(console.log("🟡 Force reloading queries"),t.length>0){const a=yield Promise.allSettled(t.map(l=>l.fetchData(!0)));console.log("🟡 Queries from filters reloaded",a)}else console.log("🟡 Found no query from visible filters, skipping");if(r.length>0){const a=yield Promise.allSettled(r.map(l=>l.fetchData(!0)));console.log("🟡 Queries from filters reloaded",a)}else console.log("🟡 Found no query from visible panels, skipping")})}));function Mi(e){return{current:e}}function Vi({min:e,max:t}){const r=`${e}px`,a=Number.isFinite(t)?`${t}px`:"∞";return`[${r}, ${a})`}const za=g.types.model("LayoutsRenderModel",{list:g.types.array(Yo),currentBreakpoint:g.types.string}).views(e=>({get json(){return e.list.map(t=>t.json)},jsonByPanelIDSet(t){return e.list.map(r=>r.jsonByPanelIDSet(t))},get root(){return g.getRoot(e)},get contentModel(){return this.root.content},get basisLayoutSet(){return e.list.find(t=>t.id==="basis")},get currentLayoutSet(){return e.list.find(t=>t.id===e.currentBreakpoint)},get currentLayoutRange(){return this.breakpointRanges.find(t=>t.id===e.currentBreakpoint)},get currentRangeText(){const t=this.currentLayoutRange;return Vi(t)},get cols(){const t={};return e.list.forEach(r=>{t[r.id]=36}),t},get breakpoints(){const t={};return e.list.forEach(r=>{t[r.id]=r.breakpoint}),t},get breakpointNameRecord(){const t={};return e.list.forEach(r=>{t[r.name]=r.breakpoint}),t},get breakpointRanges(){const t=e.list.map(r=>({id:r.id,name:r.name,min:r.breakpoint,max:1/0,text:""}));return t.sort((r,a)=>r.min-a.min).forEach((r,a)=>{a!==t.length-1&&(r.max=t[a+1].min)}),t.forEach(r=>{r.text=Vi(r)}),t},get breakpointsInfo(){return e.list.map(t=>({id:t.id,name:t.name,breakpoint:t.breakpoint})).sort((t,r)=>t.breakpoint-r.breakpoint)},get currentBreakpointRange(){return this.breakpointRanges.find(t=>t.id===e.currentBreakpoint)},get currentLayoutPreviewWidth(){const t=this.currentBreakpointRange;if(t)return t.max===1/0?t.min===0?void 0:t.min+1:t.max},items(t){const r=new Set(t);return this.currentLayoutSet.list.filter(l=>r.has(l.panelID))},gridLayouts(t){const r=new Set(t),a={};return e.list.forEach(l=>{a[l.id]=l.list.filter(o=>r.has(o.panelID)).map(o=>o.layoutProperies)}),a},findItemByPanelID(t){return this.currentLayoutSet.findByPanelID(t)}})).actions(e=>({setCurrentBreakpoint(t){console.log("🔴 onBreakpointChange:",t),e.currentBreakpoint=t},afterCreate(){g.addDisposer(e,Q.reaction(()=>e.currentBreakpoint,()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},{fireImmediately:!1,delay:0}))}})),Pi=Xo.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!g.getParent(e,2).findByKey(t)}})),Da=g.types.model("SQLSnippetsRenderModel",{current:g.types.optional(g.types.array(Pi),[])}).views(e=>({get json(){return e.current.map(t=>t.json)},get record(){return e.current.reduce((t,r)=>(t[r.key]=r.value,t),{})},get keySet(){return new Set(e.current.map(t=>t.key))},get firstKey(){if(e.current.length!==0)return e.current[0].key},findByKey(t){return e.current.find(r=>r.key===t)},findByKeySet(t){return e.current.filter(r=>t.has(r.key))}})).actions(e=>({getSchema(t){return{definition:{sqlSnippets:e.findByKeySet(new Set(t)).map(l=>l.json)},version:at}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t),null,2);Bt("SQL Snippets",r)}}));function Ai(e){return{current:e}}function Ut(e,t,r,a){return e.reduce((l,o)=>{try{l[o[t]]=or(o[r],a)}catch(i){l[o[t]]=i.message}return l},{})}class $i{constructor(t){V(this,"origin");V(this,"copy");this.origin=t,this.copy=g.clone(t),Q.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!y.isEqual(g.getSnapshot(this.origin),g.getSnapshot(this.copy))}commit(){g.applySnapshot(this.origin,g.getSnapshot(this.copy))}reset(){g.applySnapshot(this.copy,g.getSnapshot(this.origin))}update(t){g.applySnapshot(this.copy,t)}}const Ei=e=>new $i(e),eT=({description:e,isDescriptionEmpty:t})=>t?null:n.jsx(s.Tooltip,{color:"white",label:n.jsx(Dt,{value:e,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:n.jsx(s.Box,{sx:{height:"16px",alignSelf:"center"},children:n.jsx(S.IconInfoCircle,{size:16,color:"gray"})})}),tT=T.observer(({label:e,config:{default_value:t,description:r,isDescriptionEmpty:a,...l},value:o,onChange:i})=>n.jsxs(s.Box,{children:[n.jsx(s.Text,{size:"sm",children:" "}),n.jsx(s.Checkbox,{label:n.jsxs(s.Group,{wrap:"nowrap",justify:"space-between",align:"middle",gap:6,children:[n.jsx(s.Box,{sx:{flexGrow:1},children:e}),n.jsx(eT,{description:r,isDescriptionEmpty:a})]}),checked:o||!1,onChange:c=>i(c.currentTarget.checked),...l,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),nT=({value:e,onChange:t,close:r,max_days:a,allowSingleDateInRange:l})=>{const o=e.value,[i,c]=o,d=h.useMemo(()=>i||new Date,[i]),u=h.useMemo(()=>{if(i&&!c)return i},[i,c]),p=h.useMemo(()=>{if(i&&!c&&a>0)return M(i).add(a-1,"days").toDate()},[i,c,a]),f=v=>{const[_,w]=v;t({value:v,shortcut:null}),_&&w&&r()};return n.jsx(hs.DatePicker,{defaultDate:d,numberOfColumns:2,type:"range",value:o,onChange:f,onNextMonth:console.log,minDate:u,maxDate:p,allowSingleDateInRange:l})},rT=({begin:e,end:t})=>{const{t:r}=x.useTranslation(),a=h.useMemo(()=>!t&&!e?Number.NaN:M(t).diff(M(e),"days")+1,[e,t]);if(Number.isNaN(a))return n.jsx("span",{style:{userSelect:"none",opacity:0,visibility:"hidden"},children:"."});const l=a===1?r("filter.widget.date_range.one_day"):r("filter.widget.date_range.x_days",{count:a});return n.jsx(s.Tooltip,{label:l,children:n.jsx(s.Badge,{size:"sm",variant:"light",children:a})})},aT=({max_days:e})=>{const{t}=x.useTranslation();return e?n.jsxs(n.Fragment,{children:[n.jsx(s.Group,{justify:"flex-end",children:n.jsx(s.Badge,{size:"xs",variant:"light",children:t("filter.widget.date_range.x_max_days",{max_days:e})})}),n.jsx(s.Divider,{variant:"dashed",my:10})]}):null},sT=({onChange:e})=>{const{t,i18n:r}=x.useTranslation(),a=i=>()=>{const c=i();e(c)},l=h.useMemo(()=>Ho(),[]),o=r.language==="zh";return n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{variant:"dashed",my:10}),n.jsx(s.Table,{withTableBorder:!1,sx:{"tbody > tr":{border:"none"},"tbody > tr > th, tbody > tr > td":{borderTop:"none",padding:"2px 6px"},"tbody > tr > th":{cursor:"default",userSelect:"none"},td:{paddingLeft:"1px"}},children:n.jsx(s.Table.Tbody,{children:Object.entries(l).map(([i,c])=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:n.jsx(s.Text,{size:"xs",c:"#555",fw:500,sx:{textAlignLast:"justify"},children:t(`filter.widget.date_range.shortcut.${i}.label`)})}),c.map(({key:d,value:u,getRange:p})=>n.jsx(s.Table.Td,{children:n.jsx(s.Button,{size:"compact-xs",variant:"subtle",onClick:a(p),children:t(`filter.widget.date_range.shortcut.${i}.${o?"full.":""}${d}`)})},d))]},i))})})]})},Bi=e=>({label:{display:"block",height:"21.7px"},input:{borderColor:e?"#228be6":"#e9ecef"}}),lT=({label:e,required:t,value:r,onChange:a,max_days:l,allowSingleDateInRange:o,inputFormat:i,disabled:c})=>{const{t:d}=x.useTranslation(),[u,{open:p,close:f}]=ne.useDisclosure(!1),[v,_]=r.value,w=v?M(v).format(i):"",m=_?M(_).format(i):"";return n.jsxs(s.Popover,{opened:u,onClose:f,position:"bottom-start",shadow:"md",children:[n.jsxs(s.Group,{justify:"flex-start",grow:!0,wrap:"nowrap",gap:0,w:"288px",sx:{marginTop:"3px"},children:[n.jsx(s.Popover.Target,{children:n.jsx(s.TextInput,{label:e,labelProps:{title:e},required:t,leftSection:n.jsx(S.IconCalendar,{size:16}),placeholder:d("filter.widget.date_range.start_date"),readOnly:!0,disabled:c,value:w,onFocus:p,styles:Bi(u),sx:{".mantine-TextInput-label":{textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",width:"calc(240px)",position:"relative",zIndex:1},".mantine-Input-input":{borderRight:"none",borderTopRightRadius:0,borderBottomRightRadius:0},".mantine-Input-input[data-disabled]":{backgroundColor:"transparent",backgroundImage:"linear-gradient(to left, #fff 0%, #f1f3f5 30%)",opacity:1},".mantine-Input-input[data-disabled]::placeholder":{opacity:.6}}})}),n.jsx(s.TextInput,{label:n.jsx(s.Group,{justify:"flex-end",children:n.jsx(rT,{begin:v,end:_})}),leftSection:n.jsx(S.IconMinus,{size:16}),placeholder:d("filter.widget.date_range.end_date"),readOnly:!0,disabled:!v||c,value:m,onFocus:p,styles:Bi(u),sx:{".mantine-Input-section":{transform:"translateX(-18px)"},".mantine-Input-input":{borderLeft:"none",borderTopLeftRadius:0,borderBottomLeftRadius:0},".mantine-Input-input[data-disabled]":{backgroundColor:"transparent",backgroundImage:"linear-gradient(to right, #fff 0%, #f1f3f5 30%)",opacity:1},".mantine-Input-input[data-disabled]::placeholder":{opacity:.6}}})]}),n.jsxs(s.Popover.Dropdown,{p:"sm",children:[n.jsx(aT,{max_days:l}),n.jsx(nT,{value:r,onChange:a,close:f,allowSingleDateInRange:o,max_days:l}),n.jsx(sT,{onChange:a})]})]})},Li={value:[null,null],shortcut:null},qi=e=>{const t=mn(e.shortcut);return t||(Array.isArray(e.value)?e:Li)},oT=e=>h.useMemo(()=>qi(e),[e]),Oi=T.observer(({label:e,config:t,value:r=Li,onChange:a,disabled:l})=>{const{inputFormat:o,required:i,max_days:c,allowSingleDateInRange:d}=t,u=oT(r);return n.jsx(lT,{label:e,value:u,onChange:a,inputFormat:o,allowSingleDateInRange:d,max_days:c,required:i,disabled:l})}),iT=dt.createStyles((e,{radius:t=4,name:r,...a})=>({root:{borderRadius:s.getRadius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef",...a,"&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{width:"calc(100% - 30px)",overflow:"hidden",'div[data-role="label"]':{overflowWrap:"break-word"}},".rc-select-item-option-state-icon":{lineHeight:"20px"}},".rc-virtual-list-holder-inner":{alignItems:"flex-start"}}})),cT={root:{cursor:"pointer","&:hover":{backgroundColor:"var(--mantine-color-default-hover)"},"input, .mantine-Checkbox-labelWrapper":{cursor:"pointer",pointerEvents:"none"}}},dT=({disabled:e,radius:t,style:r,label:a,value:l,onChange:o,options:i,errorMessage:c,required:d})=>{const{t:u}=x.useTranslation(),{classes:p,cx:f}=iT({radius:t,name:"MultiSelectWidget"}),[v,_]=h.useState(!1),w=N=>{_(N)},m=v&&(l==null?void 0:l.length)>0,[k,z]=h.useState(""),D=h.useMemo(()=>{if(!k)return i;const N=k.toLowerCase(),le=xe=>{var lt;return((lt=xe.description)==null?void 0:lt.toLowerCase().includes(N))||xe.label.toLowerCase().includes(N)};return i.filter(le)},[k,i]),I=h.useMemo(()=>new Set(i.map(N=>N.value)),[i]),L=h.useMemo(()=>new Set(l),[l]),E=h.useMemo(()=>L.size!==I.size?!1:Array.from(I).every(N=>L.has(N)),[L,I]),K=()=>{if(E){o([]);return}const N=Array.from(I);o(N)};return n.jsxs(s.Stack,{gap:3,children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsxs(s.Text,{className:p.label,size:"sm",children:[a,d&&n.jsx("span",{className:p.required,"aria-hidden":"true",children:"*"})]}),m&&n.jsx(s.Tooltip,{label:u("filter.widget.common.x_selected",{count:l.length}),children:n.jsx(s.Badge,{variant:"light",children:l.length})})]}),n.jsx(vs,{disabled:e,allowClear:!0,className:f(p.root,"check-select"),dropdownClassName:f(p.dropdown,""),onDropdownVisibleChange:w,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:r,clearIcon:()=>n.jsx(s.CloseButton,{size:"sm"}),value:l,onChange:o,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:n.jsx(ca,{errorMessage:c}),maxTagTextLength:10,maxTagPlaceholder:N=>u("filter.widget.common.x_selected",{count:N.length}),searchValue:k,onSearch:z,filterOption:!1,dropdownRender:N=>n.jsxs(n.Fragment,{children:[I.size>0&&!k&&n.jsx(s.Group,{px:"xs",py:"xs",onClick:K,styles:cT,children:n.jsx(s.Checkbox,{size:"xs",checked:E,onChange:y.noop,label:u("common.actions.select_all")})}),n.jsx(s.Divider,{}),N]}),children:D.map(N=>n.jsxs(vs.Option,{title:N.label,children:[n.jsx(s.Text,{size:"sm","data-role":"label",children:N.label}),N.description&&n.jsx(s.Text,{size:"xs",c:"dimmed","data-role":"description",children:N.description})]},N.value))})]})},uT=T.observer(({label:e,config:t,value:r,onChange:a})=>{const l=J(),o=!!t.options_query_id,{state:i,error:c}=l.getDataStuffByID(t.options_query_id),d=i==="loading",u=t.min_width?t.min_width:"200px",p=o?d:!1,f=h.useMemo(()=>t.initialSelection(r),[r,t.initialSelection]),v=_=>a(_,!1);return n.jsx(dT,{label:e,options:t.options,style:{minWidth:"160px",width:u,maxWidth:p?u:"unset",borderColor:"#e9ecef"},disabled:p,value:[...f],onChange:v,errorMessage:c,required:t.required})}),pT=({option:e,...t})=>{const{label:r,description:a}=e;return n.jsx("div",{...t,children:n.jsx(s.Group,{wrap:"nowrap",children:n.jsxs("div",{children:[n.jsx(s.Text,{size:"sm","data-role":"label",children:r}),n.jsx(s.Text,{size:"xs",c:"dimmed","data-role":"description",children:a})]})})})},hT=T.observer(({label:e,config:t,value:r,onChange:a})=>{const{t:l}=x.useTranslation(),o=J(),i=!!t.options_query_id,{state:c,error:d}=o.getDataStuffByID(t.options_query_id),u=c==="loading",p=h.useCallback((f,v)=>{f&&a(f,!1)},[a]);return n.jsx(s.Select,{label:e,data:t.options,disabled:i?u:!1,value:r,onChange:p,maxDropdownHeight:500,styles:{root:{width:t.width?t.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"},".mantine-Select-nothingFound":{fontSize:"0.75rem",textAlign:"left",padding:"4px 10px"}},renderOption:pT,searchable:!d,nothingFoundMessage:d||l("filter.widget.common.selector_option_empty"),clearable:t.clearable})});function gT({label:e,config:t,value:r,onChange:a}){return n.jsx(s.TextInput,{label:e,value:r||"",onChange:l=>a(l.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}const fT=T.observer(({filter:{type:e,config:t,key:r,...a},formFieldProps:l})=>{switch(e){case A.Select:return n.jsx(hT,{...a,...l,config:t});case A.MultiSelect:return n.jsx(uT,{...a,...l,config:t});case A.TreeSelect:return n.jsx(qS,{...a,...l,config:t});case A.TreeSingleSelect:return n.jsx(FS,{...a,...l,config:t});case A.TextInput:return n.jsx(gT,{...a,...l,config:t});case A.DateRange:return n.jsx(Oi,{...a,...l,config:t});case A.Checkbox:return n.jsx(tT,{...a,...l,config:t});default:return null}}),bT=T.observer(h.forwardRef(({filter:e,...t},r)=>n.jsx("div",{className:"filter-root",ref:r,children:n.jsx(te,{children:n.jsx(fT,{filter:e,formFieldProps:t})})}))),yT=({disabled:e,onSubmit:t})=>{const{t:r}=x.useTranslation(),{renderSearchButton:a}=Ms();return a?a({disabled:e,onSubmit:t}):n.jsxs(s.Button.Group,{children:[n.jsx(s.Button,{color:"blue",size:"sm",onClick:()=>t(),disabled:e,children:r("common.actions.search")}),n.jsxs(s.Menu,{trigger:"hover",disabled:e,position:"bottom-end",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Button,{disabled:e,color:"blue",px:"xs",style:{borderLeft:`1px solid ${e?"white":"var(--mantine-color-gray-4)"}`},children:n.jsx(S.IconChevronDown,{size:16})})}),n.jsx(s.Menu.Dropdown,{children:n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconRefresh,{size:14}),disabled:e,onClick:()=>t({force:!0}),children:r("common.actions.reload")})})]})]})};function vT(e){const t=F();h.useEffect(()=>{var r,a;(a=(r=t.filters).updatePreviewValues)==null||a.call(r,e)},[e])}const Ni="N/A";function _T(){const e=Nt(),t=e.content.views.visibleViews;return h.useMemo(()=>t.map(l=>{var o;return l.type===$.Tabs?(o=l.tabView)==null?void 0:o.view_id:l.id}).filter(Boolean).flatMap(l=>e.content.filters.visibleInView(l)).filter(Boolean).map(l=>xT(l)),[t])}function xT(e){switch(e.type){case A.Select:case A.MultiSelect:case A.TreeSelect:case A.TreeSingleSelect:return{label:e.label,value:wT(e.config,e.value)};case A.TextInput:return{label:e.label,value:e.value};case A.DateRange:return{label:e.label,value:mT(e.config,e.value)};case A.Checkbox:return{label:e.label,value:CT(e.value)};default:return{label:e.label,value:e.value}}}function wT(e,t){const r=new Set;return Array.isArray(t)?t.forEach(a=>r.add(a)):r.add(t),r.size===0?Ni:e.options.filter(a=>r.has(a.value)).map(a=>a.label).join(", ")}function G5(e){return e}function mT(e,t){const a=qi(t).value.filter(l=>!!l).map(l=>M(l).format(e.inputFormat));return a.length===0?Ni:a.join(" - ")}function CT(e){return e?"✔️":"❌"}const ST=({opened:e,toggle:t})=>{const{t:r}=x.useTranslation();return n.jsx(s.Group,{justify:"flex-end",ml:-4,mt:-4,mb:e?4:0,children:n.jsx(s.Button,{size:"compact-xs",variant:"subtle",color:e?"gray":"blue",leftSection:e?n.jsx(S.IconChevronsUp,{size:14}):n.jsx(S.IconChevronsDown,{size:14}),onClick:t,children:r(e?"filter.hide_filters":"filter.show_filters")})})},Gi=T.observer(function({view:t}){const[r,{toggle:a}]=ne.useDisclosure(!0),l=J(),{control:o,handleSubmit:i,reset:c}=b.useForm({defaultValues:l.filters.values,reValidateMode:"onBlur"}),d=b.useWatch({control:o});h.useEffect(()=>{c(l.filters.values)},[l.filters.values,c]),vT(d);const u=l.filters.visibleInView(t.id),p=h.useMemo(()=>u.every(m=>m.should_auto_submit),[u]),f=h.useMemo(()=>u.filter(m=>y.get(m,"config.required",!1)),[u]),v=h.useMemo(()=>f.length===0?!1:f.some(m=>!m.requiredAndPass(d[m.key])),[d,f]),_=(m,k)=>(z,D)=>{k(z),(m.should_auto_submit||D)&&l.filters.setValueByKey(m.key,z)},w=h.useCallback(m=>{const k=y.get(m,"force",!1);i(l.filters.setValues)(),k&&l.queries.forceReloadVisibleQueries()},[i,l.filters.setValues]);return u.length===0?null:n.jsxs("form",{children:[n.jsx(ST,{opened:r,toggle:a}),n.jsx(s.Collapse,{in:r,children:n.jsxs(s.Group,{className:"dashboard-filters",justify:"space-between",wrap:"nowrap",sx:p?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[n.jsx(s.Group,{align:"flex-start",children:u.map(m=>n.jsx(b.Controller,{name:m.key,control:o,render:({field:k})=>n.jsx(bT,{filter:m,value:k.value,onChange:_(m,k.onChange)})},m.id))}),!p&&n.jsx(s.Group,{sx:{alignSelf:"flex-end"},children:n.jsx(yT,{disabled:v,onSubmit:w})})]})})]})}),TT={viewPanelInFullScreen:y.noop,inFullScreen:!1},zn=h.createContext(TT),kT=T.observer(({view:e})=>{const{t}=x.useTranslation(),r=W(),{panel:a}=re(),l=a.realQueryOptions,o=c=>{r.editor.open(["_QUERIES_",c])},i=()=>{r.editor.open(["_VIEWS_",e.id,"_PANELS_",a.id,"_TABS_","Data"])};return l.length===0?null:n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{label:t(l.length>1?"query.labels":"query.label"),labelPosition:"center"}),n.jsx(s.Menu.Item,{onClick:i,leftSection:n.jsx(S.IconDatabase,{size:14}),children:t("data.label")}),l.map(c=>n.jsx(s.Menu.Item,{onClick:()=>o(c.value),leftSection:n.jsx(S.IconDatabase,{size:14}),children:c.label},c.value))]})}),zT=T.observer(({view:e,title:t})=>{const{t:r}=x.useTranslation(),a=W(),l=F(),o=Te.useModals(),{panel:i,downloadPanelScreenshot:c}=re(),{id:d}=i,{viewPanelInFullScreen:u,inFullScreen:p}=h.useContext(zn),f=()=>{l.duplicatePanelByID(d,e.id)},v=()=>{a.editor.open(["_VIEWS_",e.id,"_PANELS_",d,"_TABS_","Panel"])},_=()=>{a.editor.open(["_VIEWS_",e.id,"_PANELS_",d,"_TABS_","Variables"])},w=()=>{a.editor.open(["_VIEWS_",e.id,"_PANELS_",d,"_TABS_","Visualization"])},m=()=>{a.editor.open(["_VIEWS_",e.id,"_PANELS_",d,"_TABS_","Interactions"])},k=()=>o.openConfirmModal({title:`${r("panel.delete")}?`,labels:{confirm:r("common.actions.confirm"),cancel:r("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>l.removePanelByID(d,e.id),confirmProps:{color:"red"},zIndex:320}),z=h.useCallback(()=>{u(d)},[d,u]),D=!p&&e.type!==$.Modal;return n.jsx(n.Fragment,{children:n.jsx(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},title:t,children:n.jsxs(s.Menu,{withinPortal:!0,children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Box,{className:"panel-dropdown-target",sx:{width:"100%"}})}),n.jsxs(s.Menu.Dropdown,{children:[n.jsx(s.Menu.Item,{onClick:i.refreshData,leftSection:n.jsx(S.IconRefresh,{size:14}),children:r("common.actions.refresh")}),n.jsx(s.Menu.Item,{onClick:i.downloadData,leftSection:n.jsx(S.IconDownload,{size:14}),children:r("common.actions.download_data")}),n.jsx(s.Menu.Item,{onClick:i.downloadSchema,leftSection:n.jsx(S.IconCode,{size:14}),children:r("common.actions.download_schema")}),n.jsx(s.Menu.Item,{onClick:c,leftSection:n.jsx(S.IconCamera,{size:14}),children:r("common.actions.download_screenshot")}),D&&n.jsx(s.Menu.Item,{onClick:z,leftSection:n.jsx(S.IconArrowsMaximize,{size:14}),disabled:!0,children:r("common.actions.enter_fullscreen")}),n.jsx(kT,{view:e}),n.jsx(s.Divider,{label:r("common.actions.edit"),labelPosition:"center"}),n.jsx(s.Menu.Item,{onClick:v,leftSection:n.jsx(S.IconAppWindow,{size:14}),children:r("panel.label")}),n.jsx(s.Menu.Item,{onClick:_,leftSection:n.jsx(S.IconVariable,{size:14}),children:r("panel.variable.labels")}),n.jsx(s.Menu.Item,{onClick:w,leftSection:n.jsx(S.IconChartHistogram,{size:14}),children:r("visualization.label")}),n.jsx(s.Menu.Item,{onClick:m,leftSection:n.jsx(S.IconRoute,{size:14}),children:r("interactions.label")}),n.jsx(s.Divider,{label:r("common.actions.actions"),labelPosition:"center"}),n.jsx(s.Menu.Item,{onClick:f,leftSection:n.jsx(S.IconCopy,{size:14}),children:r("common.actions.duplicate")}),n.jsx(s.Menu.Item,{color:"red",onClick:k,leftSection:n.jsx(S.IconTrash,{size:14}),children:r("common.actions.delete")})]})]})})})});function DT(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const IT=T.observer(()=>{const e=J(),{panel:t}=fe(),r=h.useMemo(()=>ht(t.description,t.json.variables,e.payloadForViz,t.data),[t.data,t.description,t.json.variables,e.payloadForViz]);return n.jsx(Dt,{value:r,styles:{root:{border:"none"},content:{padding:0}},sx:{".mantine-RichTextEditor-content .ProseMirror":{padding:"0 !important"}},dashboardStateValues:e.dashboardStateValues,variableAggValueMap:t.variableAggValueMap})}),Ia=T.observer(()=>{const{t:e}=x.useTranslation(),[t,r]=h.useState(!1),{panel:a}=fe();return DT(a.description)?null:n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:t,onClose:()=>r(!1),title:a.title.show?a.name:"",withCloseButton:!1,withinPortal:!0,zIndex:310,children:n.jsx(IT,{})}),n.jsx(s.Tooltip,{label:e("panel.panel_description_click"),position:"top-start",withinPortal:!0,children:n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>r(l=>!l),sx:{verticalAlign:"baseline",cursor:"pointer"},children:n.jsx(S.IconInfoCircle,{size:20})})})]})}),F5="",MT=T.observer(function(){const{panel:t}=fe(),{name:r,title:a}=t;return a.show?n.jsx(s.Group,{grow:!0,justify:"center",className:"panel-title-wrapper",sx:{flexGrow:1},children:n.jsx(s.Text,{size:"sm",ta:"center",lineClamp:1,className:"panel-title-text",children:r})}):null});function VT(e){const t=h.useRef(null);return{ref:t,downloadPanelScreenshot:()=>{const a=t.current;if(!a)return;const l=a.offsetWidth*2,o=a.offsetHeight*2;fs.toBlob(t.current,{bgcolor:"white",width:l,height:o,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(i=>{window.saveAs(i,`${e.name?e.name:e.viz.type}.png`)})}}}var Fi=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(Fi||{}),Dn=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(Dn||{});class PT{constructor(t){V(this,"vizInstance");V(this,"operationManager");V(this,"triggerManager");V(this,"vizManager");V(this,"runningMigration");V(this,"panelModel");V(this,"status","notStarted");this.panelModel=t.getRequired(R.instanceScope.panelModel),this.vizInstance=t.getRequired(R.instanceScope.vizInstance),this.operationManager=t.getRequired(R.instanceScope.operationManager),this.triggerManager=t.getRequired(R.instanceScope.triggerManager),this.vizManager=t.getRequired(R.vizManager)}async createMigrationTask(){const t=[];try{await this.instanceNeedMigration()&&t.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&t.push(()=>this.runInteractionMigration())}catch(r){return console.warn("check migration failed",r),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(r=>r())),"migrated"}catch(r){return console.warn("migration failed",r),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(t=>(this.status="done",t))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),r={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(r)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),r={configData:this.vizInstance.instanceData};return t.migrator.needMigration(r)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}class AT{getTriggerSchemaList(){return[]}getTriggerList(){return Promise.resolve([])}removeTrigger(){return Promise.resolve()}createOrGetTrigger(){return Promise.resolve(ji)}retrieveTrigger(){return Promise.resolve(ji)}watchTriggerSnapshotList(){return()=>{}}needMigration(){return Promise.resolve(!1)}runMigration(){return Promise.resolve()}}class $T{constructor(){V(this,"id","");V(this,"schemaRef","");V(this,"triggerData",new Jt({}))}}const ji=new $T;class ET{getOperationSchemaList(){return[]}getOperationList(){return Promise.resolve([])}removeOperation(){return Promise.resolve()}createOrGetOperation(){return Promise.resolve(Qi)}runOperation(){return Promise.resolve()}retrieveTrigger(){return Promise.resolve(Qi)}runMigration(){return Promise.resolve()}needMigration(){return Promise.resolve(!1)}}class BT{constructor(){V(this,"id","");V(this,"schemaRef","");V(this,"operationData",new Jt({}))}}const Qi=new BT,$n=class $n{constructor(){V(this,"triggerManager",new AT);V(this,"operationManager",new ET)}getInteractionList(){return Promise.resolve([])}addInteraction(){return Promise.resolve()}removeInteraction(){return Promise.resolve()}runInteraction(){return Promise.resolve()}};V($n,"instance",new $n);let Ma=$n;function Wi(e,t=!0){const{panel:r}=fe();return h.useCallback(a=>{const l=a.getRequired(R.vizManager),o=l.resolveComponent(e.viz.type);return a.createScoped().provideFactory(R.instanceScope.vizInstance,()=>l.getOrCreateInstance(e)).provideFactory(R.instanceScope.interactionManager,i=>{const c=i.getRequired(R.instanceScope.vizInstance);return t?new bl(c,o,hr):new Ma}).provideFactory(R.instanceScope.operationManager,i=>i.getRequired(R.instanceScope.interactionManager).operationManager).provideFactory(R.instanceScope.triggerManager,i=>i.getRequired(R.instanceScope.interactionManager).triggerManager).provideValue(R.instanceScope.panelModel,r).provideFactory(R.instanceScope.migrator,i=>new PT(i))},[e.viz.type,e.viz.conf,t])}const Ui={withInteraction:!0,withAddon:!0,withPanelTitle:!0},Ki=h.createContext(Ui);function LT({children:e,...t}){const r=y.defaults({},t,Ui);return n.jsx(Ki.Provider,{value:r,children:e})}function Va(){return h.useContext(Ki)}function Yi(e){const[t,r]=h.useState(!1),a=Qt().getRequired(R.instanceScope.migrator);return O.useAsyncEffect(async()=>{const l=a.status===Dn.notStarted;r(a.status===Dn.done),a.status===Dn.notStarted&&a.runMigration().then(o=>{o===Fi.migrated&&l&&(e==null||e())}).finally(()=>{r(!0)})},[a]),t}function Xi(e,t){const r=Qt().getRequired(R.instanceScope.vizInstance);return O.useAsyncEffect(async()=>{y.isEqual(await r.instanceData.getItem(null),t.viz.conf)||await r.instanceData.setItem(null,t.viz.conf)},[r,t.viz.conf]),h.useEffect(()=>r.instanceData.watchItem(null,a=>{e(a)}),[e,t.viz.type]),r}function qT({setVizConf:e,...t}){const{panel:r}=t,a=Xi(e,r),l=Yi(()=>{Ye.showNotification({title:`${r.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return O.useAsyncEffect(async()=>{await a.instanceData.setItem(null,r.viz.conf)},[a,r.viz.type]),l?n.jsx(ru,{...t}):n.jsx(s.Text,{size:"sm",children:"Checking update..."})}function OT(e){const{panel:t,setVizConf:r}=e;Xi(r,t);const{inEditMode:a}=h.useContext(Gt);return Yi(()=>{a&&Ye.showNotification({title:`${t.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?n.jsx(nu,{...e}):n.jsx(s.Text,{size:"sm",children:"Checking update"})}const j5="";function NT(e,t){const{vizManager:r}=h.useContext(rt),{panel:{viz:a,title:l,id:o,name:i,description:c,queryIDs:d,variables:u}}=fe(),p={id:o,name:i,title:l,description:c,queryIDs:d,viz:a},{withInteraction:f}=Va(),v=Wi(p,f);try{return r.resolveComponent(a.type),n.jsxs(ln,{configure:v,children:[n.jsx(OT,{setVizConf:a.setConf,panel:p,measure:t,data:e,variables:u,vizManager:r}),n.jsx(Ji,{})]})}catch(_){return console.info(y.get(_,"message")),null}}const Zi=T.observer(function({data:t}){const{ref:r,width:a,height:l}=ne.useElementSize(),o=NT(t,{w:a,h:l}),i=a>0&&l>0;return n.jsx("div",{className:"viz-root",ref:r,children:n.jsx(s.Box,{sx:{width:a,height:l,overflow:"hidden"},children:i&&n.jsx(te,{children:o})})})}),Ji=()=>{const e=Qt(),t=e.getRequired(R.instanceScope.vizInstance),{inEditMode:r}=h.useContext(Gt),a=e.getRequired(R.panelAddonManager),{withAddon:l}=Va(),o=pu();return!o||!l?null:Kd.createPortal(n.jsx(n.Fragment,{children:a.createPanelAddonNode({viz:t,isInEditMode:r})}),o,"addon")},Hi=T.observer(({panel:e})=>n.jsxs(s.Stack,{children:[e.queryErrors.map((t,r)=>n.jsx(s.Text,{c:"red",size:"sm",ta:"center",ff:"monospace",children:t},`${r}-${t}`)),n.jsx(s.Text,{c:"gray",ta:"center",size:"sm",children:e.queryStateMessages})]})),Pa=T.observer(({panel:e})=>n.jsxs(s.Flex,{className:"panel-viz-section",direction:"column",sx:{position:"relative",width:"100%"},children:[n.jsx(s.LoadingOverlay,{visible:e.dataLoading,transitionProps:{exitDuration:0}}),!e.canRenderViz&&n.jsx(Hi,{panel:e}),e.canRenderViz&&n.jsx(Zi,{data:e.data})]})),GT={border:"1px solid #e9ecef"},Aa=T.observer(({panel:e,panelStyle:t,dropdownContent:r})=>{const{ref:a,downloadPanelScreenshot:l}=VT(e),{withAddon:o,withPanelTitle:i}=Va(),c=o?Cs:h.Fragment;return n.jsx(Kn,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors,downloadPanelScreenshot:l},children:n.jsx(s.Box,{id:e.id,className:`panel-root ${e.title.show?"panel-root--show-title":""}`,ref:a,p:0,sx:{...GT,...t},children:n.jsxs(c,{children:[i&&n.jsxs(n.Fragment,{children:[n.jsx(s.Box,{className:"panel-description-popover-wrapper",children:n.jsx(Ia,{})}),r,n.jsx(MT,{})]}),n.jsx(Pa,{panel:e})]})})})}),FT={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function jT(e){return e.style.border.enabled?{}:FT}const Ri=T.observer(function({panel:t,view:r}){const a=jT(t);return n.jsx(Aa,{panel:t,panelStyle:a,dropdownContent:n.jsx(zT,{view:r,title:t.name})})});function QT(e){return!["richText","button","vizDashboardState"].includes(e)}const WT=T.observer(({view:e,title:t})=>{const{t:r}=x.useTranslation(),{panel:a,downloadPanelScreenshot:l}=fe(),{id:o}=a,{viewPanelInFullScreen:i,inFullScreen:c}=h.useContext(zn),d=h.useCallback(()=>{i(o)},[o,i]),u=!c&&e.type!==$.Modal;return QT(a.viz.type)?n.jsx(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},title:t,children:n.jsxs(s.Menu,{withinPortal:!0,children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Box,{className:"panel-dropdown-target"})}),n.jsxs(s.Menu.Dropdown,{children:[n.jsx(s.Menu.Item,{onClick:a.refreshData,leftSection:n.jsx(S.IconRefresh,{size:14}),children:r("common.actions.refresh")}),n.jsx(s.Menu.Item,{onClick:a.downloadData,leftSection:n.jsx(S.IconDownload,{size:14}),children:r("common.actions.download_data")}),n.jsx(s.Menu.Item,{onClick:l,leftSection:n.jsx(S.IconCamera,{size:14}),children:r("common.actions.download_screenshot")}),u&&n.jsx(s.Menu.Item,{onClick:d,leftSection:n.jsx(S.IconArrowsMaximize,{size:14}),children:r("common.actions.enter_fullscreen")})]})]})}):null});function UT(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const $a=T.observer(({panel:e,view:t})=>{const r=UT(e);return n.jsx(Aa,{panel:e,panelStyle:r,dropdownContent:n.jsx(WT,{title:e.name,view:t})})}),KT={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},ec=T.observer(function({view:t,panel:r,exitFullScreen:a}){return n.jsx(s.Modal,{opened:!0,fullScreen:!0,onClose:a,title:n.jsx(s.Button,{color:"blue",size:"xs",onClick:a,leftSection:n.jsx(S.IconArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:KT,children:n.jsx(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:n.jsx($a,{view:t,panel:r})})})});function tc(e,t,r){const{panels:a}=J(),l=e.id==="Main",[o,i]=h.useState(()=>l&&a.findByID(t)?t:null),c=h.useCallback(f=>{i(f),l&&r(f)},[l,r]),d=h.useCallback(()=>{i(null),l&&r("")},[l,r]),u=o?a.findByID(o):null;return{viewPanelInFullScreen:c,exitFullScreen:d,inFullScreen:!!u,fullScreenPanel:u}}function YT(e){const t=Nt(),r=h.useMemo(()=>t.content.panels.findByID(e.panelId),[e.panelId]);return r?n.jsx(LT,{withAddon:!1,withPanelTitle:!1,withInteraction:!1,children:n.jsx(Aa,{panel:r,panelStyle:{}})}):null}const Q5="",XT=h.forwardRef(({h:e},t)=>n.jsx(s.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:n.jsx(S.IconArrowsMove,{size:16})})),ZT=h.forwardRef(({handleAxis:e,...t},r)=>n.jsx(s.ActionIcon,{ref:r,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...t,children:n.jsx(S.IconChevronDownRight,{size:16})})),JT=Zt.WidthProvider(Zt.Responsive),HT=T.observer(({view:e,className:t="layout"})=>{const a=F().layouts,l=a.items(e.panelIDs),o=a.gridLayouts(e.panelIDs),i=(u,p,f,v)=>{f.h<30&&(f.h=30,v.h=30),f.w<4&&(f.w=4,v.w=4)},c=(u,p,f)=>{console.log("🔴 onResizeStop",{layouts:u,oldItem:p,newItem:f}),a.updateCurrentLayoutItem(f)},d=(u,p,f)=>{console.log("🔴 onDragStop",{layouts:u,oldItem:p,newItem:f}),a.updateCurrentLayoutItems(u)};return n.jsx(JT,{className:`dashboard-layout ${t}`,rowHeight:1,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,cols:a.cols,layouts:o,draggableHandle:".react-grid-customDragHandle",resizeHandle:n.jsx(ZT,{}),onResize:i,breakpoints:a.breakpoints,onBreakpointChange:a.setCurrentBreakpoint,onResizeStop:c,onDragStop:d,width:a.currentLayoutPreviewWidth,children:l.map(u=>n.jsxs("div",{"data-grid":u.layoutProperies,className:"panel-grid-item",children:[n.jsx(XT,{h:u.h}),n.jsx(Ri,{view:e,panel:u.panel})]},u.id))})}),RT=Zt.WidthProvider(Zt.Responsive),e2=T.observer(({view:e,className:t="layout"})=>{const r=J(),a=r.layouts.items(e.panelIDs),l=r.layouts.gridLayouts(e.panelIDs);return n.jsx(RT,{className:`dashboard-layout ${t}`,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,cols:r.layouts.cols,layouts:l,breakpoints:r.layouts.breakpoints,onBreakpointChange:r.layouts.setCurrentBreakpoint,children:a.map(o=>n.jsx("div",{"data-grid":o.layoutProperies,className:"panel-grid-item",children:n.jsx($a,{view:e,panel:o.panel})},o.id))})});function Ea(e){const t=h.useRef(null);return{ref:t,downloadScreenshot:()=>{var l;const a=(l=t.current)==null?void 0:l.querySelector(".react-grid-layout");a&&e.downloadScreenshot(a)}}}const t2=T.observer(({downloadScreenshot:e})=>{const{t}=x.useTranslation(),[r,{setTrue:a,setFalse:l}]=O.useBoolean(!1),o=Ds(),i=J(),c=()=>{const d=JSON.stringify(i.contentJSON,null,2),u=`${o.name}__${i.name}`;Bt(u,d)};return n.jsxs(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:200,closeDelay:400,withinPortal:!0,position:"bottom-end",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Affix,{position:{bottom:"20px",right:"10px"},zIndex:1,children:n.jsx(s.ActionIcon,{size:"md",variant:"gradient",gradient:{from:"indigo",to:"cyan"},onMouseEnter:a,onMouseLeave:l,sx:{opacity:r?1:.6,transform:`translateX(${r?0:"2px"})`,transition:"all ease 300ms",borderRadius:"50%"},children:n.jsx(S.IconShare3,{size:"1rem"})})})}),n.jsxs(s.Menu.Dropdown,{children:[n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconCamera,{size:14}),onClick:e,children:t("common.actions.download_screenshot")}),n.jsx(s.Menu.Divider,{}),n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconDownload,{size:14}),onClick:i.queries.downloadAllData,children:t("common.actions.download_data")}),n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconCode,{size:14}),onClick:c,children:t("common.actions.download_schema")})]})]})}),nc=T.observer(({children:e,view:t,sx:r={}})=>{const{ref:a,downloadScreenshot:l}=Ea(t);return n.jsxs(n.Fragment,{children:[n.jsx(s.Box,{ref:a,pt:10,pb:10,sx:r,children:e}),n.jsx(t2,{downloadScreenshot:l})]})}),rc=T.observer(({downloadScreenshot:e})=>n.jsx(s.ActionIcon,{className:"download-screenshot-button",color:"blue",variant:"subtle",onClick:e,children:n.jsx(S.IconCamera,{size:14})})),n2=T.observer(({children:e,view:t})=>{const r=J(),a=t.config,l=r.views.visibleViewIDs.includes(t.id),o=()=>r.views.rmVisibleViewID(t.id),{ref:i,downloadScreenshot:c}=Ea(t);return n.jsx(s.Modal,{size:a.width,centered:!0,opened:l,onClose:o,withCloseButton:!1,title:n.jsxs(s.Group,{justify:"space-between",px:"1rem",h:"48px",children:[n.jsx(s.Box,{children:a.custom_modal_title.value}),n.jsx(rc,{downloadScreenshot:c})]}),trapFocus:!0,onDragStart:d=>{d.stopPropagation()},styles:{root:{position:"fixed",zIndex:200,inset:0},overlay:{zIndex:"unset"},inner:{zIndex:"unset",padding:"0 !important"},content:{border:"1px solid #efefef",maxHeight:"unset !important",overflow:"hidden"},body:{maxHeight:a.height,overflow:"auto",position:"relative",paddingBottom:10},header:{padding:0},title:{flexGrow:1}},transitionProps:{duration:0},children:n.jsx(s.Box,{ref:i,children:e})})}),r2=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},a2=T.observer(({view:e})=>{const t=J(),r=e.config;return n.jsxs(s.Tabs,{className:"render-view-tabs",variant:r.variant,orientation:r.orientation,value:e.tab,onChange:e.setTab,styles:{root:{height:"100%",overflow:r.orientation==="horizontal"?"hidden":"auto"},panel:{padding:r.orientation==="horizontal"?"0px 0px 36px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[n.jsx(s.Tabs.List,{grow:r.grow,children:r.tabsInOrder.map(a=>n.jsx(s.Tabs.Tab,{value:a.id,sx:r2(a),disabled:!a.view_id,children:a.name??a.id},a.id))}),r.tabsInOrder.map(a=>{const l=t.views.findByID(a.view_id);return l?n.jsx(s.Tabs.Panel,{value:a.id,children:n.jsx(In,{view:l})},a.id):null})]})}),s2=T.observer(({view:e,children:t})=>{switch(e.type){case $.Modal:return n.jsx(n2,{view:e,children:t});case $.Tabs:return n.jsx(a2,{view:e});case $.Division:default:return n.jsx(nc,{view:e,children:t})}}),l2=T.observer(({children:e,view:t})=>{const a=F().layouts,[l,o]=ne.useResizeObserver();return h.useEffect(()=>{a.setCurrentLayoutWrapperWidth(o.width)},[o.width]),n.jsx(s.Box,{sx:{height:"100%"},ref:l,children:n.jsx(s.Box,{sx:{paddingBottom:"100px",background:"white",margin:"0 auto",width:a.currentLayoutPreviewWidth??"100%",transform:`scale(${a.divisionPreviewScale})`,transformOrigin:"0 0"},children:n.jsx(nc,{view:t,sx:{paddingTop:"0px !important",".dashboard-sticky-area > form":{paddingBottom:"5px"},".dashboard-layout":{marginTop:0,marginBottom:0}},children:e})})})});function ac(e){return e.replace(/(vw|vh)/,"%")}const o2=T.observer(({children:e,view:t})=>{const r=t.config,{width:a,height:l}=h.useMemo(()=>({width:ac(r.width),height:ac(r.height)}),[r.width,r.height]),{ref:o,downloadScreenshot:i}=Ea(t);return n.jsx(s.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:n.jsx(s.Modal,{size:r.width,opened:!0,onClose:y.noop,withCloseButton:!1,title:n.jsxs(s.Group,{justify:"space-between",px:"1rem",h:"48px",children:[n.jsx(s.Box,{children:r.custom_modal_title.value}),n.jsx(rc,{downloadScreenshot:i})]}),trapFocus:!0,onDragStart:c=>{c.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},inner:{position:"relative",top:"50%",left:"50%",right:"unset",bottom:"unset",transform:"translate(-50%, -50%)",padding:"0 !important",width:a,height:l,maxHeight:l},content:{border:"1px solid #efefef",height:"100%"},body:{maxHeight:"calc(100% - 48px)",overflow:"auto"},header:{padding:0},title:{flexGrow:1}},withinPortal:!1,transitionProps:{duration:0},children:n.jsx(s.Box,{ref:o,children:e})})})}),i2=({variant:e,orientation:t})=>{const r={root:{height:"100%",overflow:"hidden"},list:{backgroundColor:"white"},tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(r.tab.paddingTop="6px",r.tab.paddingBottom="6px"),t==="vertical"&&(r.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},r.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),r},c2=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},d2=T.observer(({view:e})=>{const{t}=x.useTranslation(),r=Te.useModals(),a=F(),l=h.useMemo(()=>a.views.options.filter(u=>u.type===$.Division),[e.id,a.views.options]),o=e.config,i=u=>r.openConfirmModal({title:`${t("view.component.tabs.tab.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.removeTab(u)},confirmProps:{color:"red"},zIndex:320}),c=o.tabs.length===0,d=o.tabsInOrder.length===0?void 0:o.tabsInOrder[0].id;return n.jsxs(s.Tabs,{className:"preview-view-tabs",variant:o.variant,orientation:o.orientation,value:e.tab||d,onChange:e.setTab,styles:i2(o),children:[n.jsxs(s.Tabs.List,{grow:o.grow,children:[o.tabsInOrder.map(u=>n.jsx(s.Tabs.Tab,{value:u.id,sx:c2(u),children:u.name??u.id},u.id)),n.jsx(s.Tabs.Tab,{onClick:o.addTab,value:"add",className:"add-a-tab",children:n.jsx(S.IconPlus,{size:18,color:"#228be6"})})]}),o.tabsInOrder.map((u,p)=>{const f=a.views.findByID(u.view_id);return n.jsxs(s.Tabs.Panel,{value:u.id,sx:{position:"relative"},children:[n.jsxs(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[n.jsx(s.Overlay,{backgroundOpacity:.8,color:"#FFF",blur:10,zIndex:100}),n.jsxs(s.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[n.jsx(s.TextInput,{label:t("view.component.tabs.tab.name"),required:!0,value:u.name,onChange:v=>u.setName(v.currentTarget.value)}),n.jsx(s.Select,{label:t("view.label"),value:u.view_id,onChange:u.setViewID,data:l}),n.jsx(s.NumberInput,{label:t("view.component.tabs.tab.order"),required:!0,value:u.order,onChange:v=>u.setOrder(v||0),min:0,max:1e3,step:1}),n.jsx(s.ColorInput,{label:t("view.component.tabs.tab.color"),value:u.color,onChange:u.setColor,disabled:o.variant!=="default"}),f&&n.jsx(s.Button,{mt:20,variant:"gradient",leftSection:n.jsx(S.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>a.views.setIDOfVIE(f.id),children:t("view.component.tabs.tab.switch_to_view",{name:f.name})}),n.jsx(s.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>i(p),disabled:c,leftSection:n.jsx(S.IconTrash,{size:14}),children:t("view.component.tabs.tab.delete")})]})]}),f&&n.jsx(In,{view:f})]},u.id)})]})}),u2=T.observer(({view:e,children:t})=>{switch(e.type){case $.Modal:return n.jsx(o2,{view:e,children:t});case $.Tabs:return n.jsx(d2,{view:e});case $.Division:default:return n.jsx(l2,{view:e,children:t})}}),sc=T.observer(function({view:t}){const a=F().layouts.divisionPreviewScale!==1;return n.jsx(zn.Provider,{value:{viewPanelInFullScreen:y.noop,inFullScreen:!1},children:n.jsx(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{background:a?"transparent":"#efefef"},children:n.jsx(u2,{view:t,children:n.jsxs(s.Box,{sx:{position:"relative"},children:[n.jsx(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:n.jsx(Gi,{view:t})}),n.jsx(HT,{view:t})]})})})})}),In=T.observer(function({view:t}){const{fullScreenPanelID:r,setFullScreenPanelID:a}=Es(),{viewPanelInFullScreen:l,exitFullScreen:o,inFullScreen:i,fullScreenPanel:c}=tc(t,r,a);return n.jsx(zn.Provider,{value:{viewPanelInFullScreen:l,inFullScreen:i},children:n.jsxs(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:t.type===$.Modal?"0 !important":"100%"},children:[i&&n.jsx(ec,{view:t,panel:c,exitFullScreen:o}),n.jsx(s2,{view:t,children:n.jsxs(s.Box,{sx:{position:"relative"},children:[!i&&n.jsx(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:n.jsx(Gi,{view:t})}),!i&&n.jsx(e2,{view:t})]})})]})})});var lc=(e=>(e.Use="use",e.Edit="edit",e))(lc||{});const p2={[$.Division]:"Division",[$.Tabs]:"Tabs",[$.Modal]:"Modal"},oc={[$.Division]:"rgba(255, 0, 0, 0.2)",[$.Modal]:"rgba(0, 0, 0, 0.2)",[$.Tabs]:"rgba(255, 200, 100, 0.4)"},h2={[$.Division]:"#ff4000",[$.Modal]:"#000",[$.Tabs]:"#ffad18"},ic=Sn.views(e=>({get usages(){return e.contentModel.findFilterUsage(e.id)}})).actions(e=>({}));function g2(e,t,r){g.addDisposer(e,g.addMiddleware(e,(a,l)=>{l(a,()=>{g.getType(a.context)===t&&a.type==="action"&&r(a.name,a.context)})}))}const cc=g.types.compose("FiltersModel",ma,g.types.model({current:g.types.optional(g.types.array(ic),[]),previewValues:g.types.optional(g.types.frozen(),{})})).views(e=>({get idSet(){return new Set(e.current.map(t=>t.id))},get keySet(){return new Set(e.current.map(t=>t.key))},get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get selects(){return e.current.filter(t=>t.type===A.Select).map(t=>({label:t.label??t.id,value:t.id}))},get keyLabelOptions(){return e.current.map(t=>({label:t.label??t.key,value:t.key,widget:t.type}))},get sortedList(){return y.sortBy(e.current,t=>t.label.toLowerCase())}})).actions(e=>({replace(t){e.current=g.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const r=t.filter(a=>!e.idSet.has(a.id));e.current.push(...r)},remove(t){e.current.splice(t,1)},removeByID(t){const r=e.current.findIndex(a=>a.id===t);r>=0&&e.current.splice(r,1)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){g2(e.current,Sn,(r,a)=>{if(r==="setType"){const l=Ti(a.config.default_value,a.config);e.setValueByKey(a.key,l),e.updatePreviewValues({...e.previewValues,[a.key]:l})}})}return{afterCreate(){t()}}}),dc=Ta.views(e=>({get canPreviewData(){return e.isTransform?e.config.dep_query_ids.length>0&&!!e.pre_process:!!e.datasource},get guideToPreviewData(){return e.isTransform?"Need to complete settings in Transform tab":"Need to pick a Data Source first"},get usage(){return e.contentModel.findQueryUsage(e.id)},get runBySet(){return new Set(e.run_by)},keyInRunBy(t){return this.runBySet.has(t)}})).actions(e=>({changeRunByRecord(t,r){const a=new Set(e.run_by);r?a.add(t):a.delete(t),e.run_by.length=0,e.run_by.push(...a)}})),uc=g.types.compose("QueriesModel",ka,g.types.model({current:g.types.optional(g.types.array(dc),[])})).views(e=>({get options(){const t=e.current.map(r=>({value:r.id,label:r.name,_type:"query"}));return y.sortBy(t,r=>r.label.toLowerCase())},get optionsWithoutTransform(){const t=e.current.filter(r=>r.type!==j.Transform).map(r=>({value:r.id,label:r.name,_type:"query"}));return y.sortBy(t,r=>r.label.toLowerCase())},get sortedList(){return y.sortBy(e.current,t=>t.name.toLowerCase())}})).actions(e=>({replace(t){e.current=g.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const r=t.filter(a=>!e.idSet.has(a.id));e.current.push(...r)},remove(t){e.current.splice(t,1)},replaceByIndex(t,r){e.current.splice(t,1,r)},removeQuery(t){const r=e.current.find(a=>a.id===t);r&&(g.detach(r),e.current.remove(r))},removeQueries(t){const r=new Set(t);e.current.forEach(l=>{r.has(l.id)&&g.detach(l)});const a=[...e.current];y.remove(a,l=>r.has(l.id)),e.current=g.cast(a)}})),pc=Da.views(e=>({get sortedList(){return y.sortBy(e.current,t=>t.key.toLowerCase())},get options(){const t=e.current.map(r=>({label:r.key,value:r.key,_type:"sql_snippet"}));return y.sortBy(t,r=>r.label.toLowerCase())},get usedFilterKeyMap(){const t=new Map;return e.current.forEach(r=>{const a=y.get(r,"value","");if(!a)return;const l=y.uniq(a.match(Mt.filter)),o=new Set;l.forEach(i=>o.add(i)),t.set(r.key,o)}),t}})).actions(e=>({replace(t){e.current=g.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const r=t.filter(a=>!e.keySet.has(a.key));e.current.push(...r)},remove(t){e.current.splice(t,1)},removeByKey(t){const r=e.current.findIndex(a=>a.key===t);r>=0&&e.current.splice(r,1)},removeByKeys(t){const r=new Set(t);e.current.forEach(l=>{r.has(l.key)&&g.detach(l)});const a=[...e.current];y.remove(a,l=>r.has(l.key)),e.current=g.cast(a)},replaceByIndex(t,r){e.current.splice(t,1,r)}})),f2=g.types.model({data:g.types.optional(g.types.frozen(),[]),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),b2=g.types.model({data:g.types.optional(g.types.frozen(),[]),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),y2=g.types.model({page:g.types.optional(g.types.number,1),limit:g.types.optional(g.types.number,20),data:g.types.optional(g.types.frozen(),[]),total:g.types.optional(g.types.number,0),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get keywords(){return g.getParent(e,1)},get keywordString(){const{table_name:t,table_schema:r}=g.getParent(e,1);return`${r}||${t}`}})).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get maxPage(){return Math.ceil(e.total/e.limit)},get offset(){return(e.page-1)*e.limit},get countSql(){const{table_name:t,table_schema:r}=e.keywords;return`
543
543
  SELECT count(*) AS total
544
544
  FROM ${r}.${t}
545
- `}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),g.addDisposer(e,Q.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),f2=g.types.model({data:g.types.optional(g.types.frozen(),{}),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0}})),b2=g.types.model({tables:g.types.optional(f2,{}),columns:g.types.optional(p2,{}),tableData:g.types.optional(g2,{}),indexes:g.types.optional(h2,{}),table_schema:g.types.optional(g.types.string,""),table_name:g.types.optional(g.types.string,"")}).views(e=>({get dataSource(){return g.getParent(e)},get key(){return this.dataSource.key},get type(){return this.dataSource.type},get sqlDataSourceType(){return this.type},get reloadConditionString(){const t=this.type,{table_name:r,table_schema:a}=e;return`${t};${r};${a}`}})).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(e=>({setKeywords(t,r){e.table_schema=t,e.table_name=r}})).actions(e=>({initKeywords(){if(e.tables.empty)return;const t=Object.keys(e.tables.data)[0],r=e.tables.data[t][0].table_name;e.setKeywords(t,r)}})).actions(e=>{const t=g.flow(function*(){var r;(r=e.controllers.tables)==null||r.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const a=yield*g.toGenerator(Ae.structure(e.controllers.tables.signal)({query_type:"TABLES",type:e.sqlDataSourceType,key:e.key,table_schema:"",table_name:""},{params:{query_type:"TABLES"}}));e.tables.data=y.groupBy(a,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(a){if(!ke.isCancel(a)){e.tables.data={};const l=y.get(a,"message","unkown error");e.tables.error=y.get(a,"response.data.detail.message",l),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:g.flow(function*(){var r;(r=e.controllers.columns)==null||r.abort(),e.controllers.columns=new AbortController,e.columns.state="loading";try{e.columns.data=yield*g.toGenerator(Ae.structure(e.controllers.columns.signal)({query_type:"COLUMNS",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"COLUMNS"}})),e.columns.state="idle",e.columns.error=null}catch(a){if(ke.isCancel(a))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const l=y.get(a,"message","unkown error");e.columns.error=y.get(a,"response.data.detail.message",l),e.columns.state="error"}}}),loadIndexes:g.flow(function*(){var r;(r=e.controllers.indexes)==null||r.abort(),e.controllers.indexes=new AbortController,e.indexes.state="loading";try{e.indexes.data=yield*g.toGenerator(Ae.structure(e.controllers.indexes.signal)({query_type:"INDEXES",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"INDEXES"}})),e.indexes.state="idle",e.indexes.error=null}catch(a){if(ke.isCancel(a))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const l=y.get(a,"message","unkown error");e.indexes.error=y.get(a,"response.data.detail.message",l),e.indexes.state="error"}}}),loadTableData:g.flow(function*(){var a;(a=e.controllers.tableData)==null||a.abort(),e.controllers.tableData=new AbortController;const r=e.tableData;r.state="loading";try{r.data=yield*g.toGenerator(Ae.structure(e.controllers.tableData.signal)({query_type:"DATA",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name,limit:r.limit,offset:r.offset},{params:{query_type:"DATA"}}));const[{total:l}]=yield*g.toGenerator(Ae.structure(e.controllers.tableData.signal)({query_type:"COUNT",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"COUNT"}}));r.total=Number(l),r.state="idle",r.error=null}catch(l){if(ke.isCancel(l))r.state="idle",r.error=null;else{r.data=[];const o=y.get(l,"message","unkown error");r.error=y.get(l,"response.data.detail.message",o),r.state="error"}}})}}).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>e.reloadConditionString,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>e.reloadConditionString,e.loadIndexes,{fireImmediately:!1,delay:500})),g.addDisposer(e,Q.reaction(()=>`${e.reloadConditionString};limit:${e.tableData.limit};offset:${e.tableData.offset}`,e.loadTableData,{fireImmediately:!1,delay:0}))}})),dc=new Set(["yoy_ratio","step_ratio","span_steps_calculation"]),uc={accumulate:"累计计算",yoy_ratio:"年同比率(yoy)",step_ratio:"环比率",span_steps_calculation:"移动计算",percentage_total:"总占"};function y2(e){var a;if("cols"in e){const{cols:l}=e,o=((a=l.find(c=>c.type==="trending_date_col"))==null?void 0:a.metricSourceCol)??null,i=dc.has(e.calculation)?`当前指标涉及 ${y.get(uc,e.calculation,e.calculation)},缺少时序则无法展示有效结果。
546
- `:"";return{filters:l.filter(c=>c.type==="filter").map(c=>c.metricSourceCol),groupBys:l.filter(c=>c.type==="group_by").map(c=>c.metricSourceCol),trendingDateCol:o,supportTrending:!!o,requireTrendingReason:i}}const t=y.uniq(e.derivedMetrics.map(l=>l.calculation)).filter(l=>dc.has(l)),r=e.supportTrending&&t.length>0?`当前指标涉及 ${t.map(l=>y.get(uc,l,l)).join("、")},缺少时序则无法展示有效结果。`:"";return{filters:e.filters,groupBys:e.groupBys,trendingDateCol:null,supportTrending:e.supportTrending,requireTrendingReason:r}}const pc={string:"维度列",number:"数值列",date:"数值列",boolean:"维度列",dimension:"扩展维度"};function hc(e){return y.groupBy(e,r=>{const{dataType:a}=r;return a?pc[a]:r.dimension!==null?pc.dimension:"ERROR"})}function v2(e){if(e.length===0)return[];const t=hc(e);return Object.entries(t).map(([a,l])=>({group:`${a}(${l.length})`,items:l.map(o=>{const{dataType:i,dimension:c}=o;return c?{group:o.name,description:o.description,items:c.fields.map(d=>typeof d=="string"?{label:d,value:`${o.name} -> ${d}`}:{label:d.field,value:`${o.name} -> ${d.field}`,...d})}:{label:o.name,value:o.name,...o}})}))}function _2(e){if(e.length===0)return[];const t=hc(e);return Object.entries(t).map(([a,l])=>({group:`${a}(${l.length})`,items:l.map(o=>({label:o.name,value:o.name,description:o.description,dataType:o.dataType??"dimension",dimension:o.dimension}))}))}function x2(e,t){if(!t)throw new Error("Shouldnt run query without ID");if(e==="derived")return`/api/metric_management/derived_metric/${t}`;if(e==="combined")return`/api/metric_management/combined_metric/${t}`;throw new Error(`Unexpected metric type[${e}]`)}const w2=g.types.model({data:g.types.optional(g.types.frozen(),null),filters:g.types.optional(g.types.frozen(),[]),groupBys:g.types.optional(g.types.frozen(),[]),trendingDateCol:g.types.optional(g.types.frozen(),null),supportTrending:g.types.optional(g.types.boolean,!1),requireTrendingReason:g.types.optional(g.types.string,""),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).volatile(()=>({controller:new AbortController})).views(e=>({get loading(){return e.state==="loading"},get hasData(){return e.data!==null},get mmInfo(){return g.getParent(e)},get metricID(){return this.mmInfo.metricID},get metric(){return this.mmInfo.metric},get metricType(){var t;return(t=this.metric)==null?void 0:t.type},get filterColOptions(){return v2(e.filters)},get groupByColOptions(){return _2(e.groupBys)},get flatGroupByColOptions(){const t=this.groupByColOptions,r=[];return t.forEach(({group:a,items:l})=>{r.push(...l)}),r},getGroupByOptions(t){const r=new Set(t);return this.flatGroupByColOptions.filter(a=>r.has(a.value))}})).actions(e=>({load:g.flow(function*(){var t;if(e.mmInfo.type===j.MericoMetricSystem&&!(!e.metricID||!e.metricType)){(t=e.controller)==null||t.abort(),e.controller=new AbortController,e.state="loading";try{const r=x2(e.metricType,e.metricID),a=rn(e.mmInfo.dataSource,{url:r,method:"GET",data:{key:e.mmInfo.key}}),l=yield*g.toGenerator(Ae.mericoMetricInfo(e.controller.signal)({key:e.mmInfo.key,query:JSON.stringify(a),...e.mmInfo.additionalQueryInfo},e.controller.signal)),o=an(e.mmInfo.dataSource,l),i=y.cloneDeep(o.data),{filters:c,groupBys:d,trendingDateCol:u,supportTrending:p,requireTrendingReason:f}=y2(o.data);e.data=i,e.filters=c,e.groupBys=d,e.supportTrending=p,e.requireTrendingReason=f,e.trendingDateCol=u,e.state="idle",e.error=null}catch(r){if(!ke.isCancel(r)){e.data=null;const a=y.get(r,"message","unkown error");e.error=y.get(r,"response.data.detail.message",a),e.state="error"}}}})})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>e.metricID+e.metricType,e.load,{fireImmediately:!0,delay:0}))}})),m2=g.types.model({keyword:g.types.optional(g.types.string,""),data:g.types.optional(g.types.frozen(),[]),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).volatile(()=>({controller:new AbortController})).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0},get mmInfo(){return g.getParent(e)}})).actions(e=>({setKeyword(t){e.keyword=t}})).actions(e=>({load:g.flow(function*(){var t;if(e.mmInfo.type===j.MericoMetricSystem){(t=e.controller)==null||t.abort(),e.controller=new AbortController,e.state="loading";try{const r=rn(e.mmInfo.dataSource,{url:"/api/metric_management/search",method:"POST",data:{key:e.mmInfo.key},params:{search:e.keyword}}),a=yield*g.toGenerator(Ae.mericoMetricInfo(e.controller.signal)({key:e.mmInfo.key,query:JSON.stringify(r),...e.mmInfo.additionalQueryInfo},e.controller.signal)),o=an(e.mmInfo.dataSource,a).data;e.data=o,e.state="idle",e.error=null}catch(r){if(!ke.isCancel(r)){e.data=[];const a=y.get(r,"message","unkown error");e.error=y.get(r,"response.data.detail.message",a),e.state="error"}}}})})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>`${e.mmInfo.type}:${e.keyword}`,e.load,{fireImmediately:!0,delay:0}))}})),C2=g.types.model({metrics:g.types.optional(m2,{}),metricDetail:g.types.optional(w2,{}),keyword:g.types.optional(g.types.string,""),metricID:g.types.optional(g.types.string,"")}).views(e=>({get rootModel(){return g.getRoot(e)},get contentModel(){return this.rootModel.content},get additionalQueryInfo(){return this.contentModel.getAdditionalQueryInfo("")},get dataSource(){return g.getParent(e)},get key(){return this.dataSource.key},get type(){return this.dataSource.type},get metric(){return e.metricID?e.metrics.data.find(t=>t.id===e.metricID)??null:null}})).actions(e=>({selectMetric(t){e.metricID=t}})),S2=g.types.compose("DataSourceModel",ga,g.types.model({dbInfo:g.types.optional(b2,{}),mericoMetricInfo:g.types.optional(C2,{})})),T2=g.types.model("DataSourcesModel",{list:g.types.optional(g.types.array(S2),[])}).views(e=>({find({type:t,key:r}){return e.list.find(a=>a.key===r&&a.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}}));function k2(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function z2(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function D2(e){return e.length===1&&e[0]==="_FILTERS_"}function I2(e){return e.length===2&&e[0]==="_FILTERS_"}function M2(e){return e.length===1&&e[0]==="_SQL_SNIPPETS_"}function A2(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function P2(e){return e.length===2&&e[0]==="_QUERIES_"}function V2(e){return e.length===1&&e[0]==="_QUERIES_"}function $2(e){return e.length===2&&e[0]==="_VIEWS_"}function Ea(e){return e.length===6&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}function Tt(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function E2(e){switch(e._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",e.value];case"sql_snippet":return["_SQL_SNIPPETS_",e.value];case"query":return["_QUERIES_",e.value];case"view":return["_VIEWS_",e.value];case"panel":return e.parentID?["_VIEWS_",e.parentID,"_PANELS_",e.value,"_TABS_","Data"]:(console.error("[getPathFromOption] parentID is required"),null)}}const B2=g.types.model("EditorModel",{path:g.types.optional(g.types.frozen(),[]),settings_open:g.types.optional(g.types.boolean,!1)}).views(e=>({get isPanelPath(){return Ea(e.path)},get panelTab(){return this.isPanelPath?y.get(e.path,5,"Data"):null},get navOptions(){const{content:t}=g.getRoot(e),{filters:r,views:a,sqlSnippets:l,queries:o}=t;return[{label:"query_variable.labels",value:"_QUERY_VARS_",_type:"query_variables",Icon:S.IconVariable},{label:"mock_context.label",value:"_MOCK_CONTEXT_",Icon:S.IconCodeDots,_type:"mock_context"},{label:"filter.labels",value:"_FILTERS_",Icon:S.IconFilter,children:[Tt("_FILTERS_SETTINGS_"),...r.options,Tt("_Add_A_Filter_")],_type:"GROUP"},{label:"sql_snippet.labels",value:"_SQL_SNIPPETS_",Icon:S.IconCopy,children:[Tt("_SQL_SNIPPETS_SETTINGS_"),...l.options,Tt("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"query.labels",value:"_QUERIES_",Icon:S.IconDatabase,children:[Tt("_QUERIES_SETTINGS_"),...o.options,Tt("_Add_A_QUERY_")],_type:"GROUP"},{label:"view.labels",value:"_VIEWS_",Icon:S.IconBoxMultiple,children:[...a.editorOptions,Tt("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(t,r){return t.length===0?!1:Ea(t)?t[3]===r.value:t[t.length-1]===r.value},isOptionOpened(t){const{path:r}=e;return r.length===0||!t.children||t.children.length===0?!1:r.includes(t.value)}})).actions(e=>({setPath(t){e.path=t},setSettingsOpen(t){e.settings_open=t},openAndSetPath(t){this.setPath(t),e.settings_open||(e.settings_open=!0)}})).actions(e=>({setPanelTab(t){if(!e.isPanelPath||e.panelTab===t||!t)return;const r=y.clone(e.path);r[5]=t,e.setPath(r)},open(t){e.setPath(t),e.setSettingsOpen(!0)},close(){e.setSettingsOpen(!1)},navigate(t){const r=E2(t);r&&e.setPath(r)}})).views(e=>({get spotlightActionGroups(){const{content:t}=g.getRoot(e),{filters:r,views:a,sqlSnippets:l,queries:o}=t,i={group:"spotlight.main_group",actions:[{id:"query_variable.labels",title:"query_variable.labels",onClick:()=>e.openAndSetPath(["_QUERY_VARS_"]),iconKey:"query_variables"},{id:"mock_context.label",title:"mock_context.label",onClick:()=>e.openAndSetPath(["_MOCK_CONTEXT_"]),iconKey:"mock_context"},{id:"filter.labels",title:"filter.labels",onClick:()=>e.openAndSetPath(["_FILTERS_"]),iconKey:"filter"},{id:"sql_snippet.labels",title:"sql_snippet.labels",onClick:()=>e.openAndSetPath(["_SQL_SNIPPETS_"]),iconKey:"sql_snippet"},{id:"query.labels",title:"query.labels",onClick:()=>e.openAndSetPath(["_QUERIES_"]),iconKey:"query"}]},c={group:"filter.labels",actions:[]};r.options.forEach(f=>{c.actions.push({id:`_FILTERS_.${f.value}`,title:f.label,onClick:()=>e.openAndSetPath(["_FILTERS_",f.value]),iconKey:"filter"})});const d={group:"sql_snippet.labels",actions:[]};l.options.forEach(f=>{d.actions.push({id:`_SQL_SNIPPETS_.${f.value}`,title:f.label,onClick:()=>e.openAndSetPath(["_SQL_SNIPPETS_",f.value]),iconKey:"sql_snippet"})});const u={group:"query.labels",actions:[]};o.options.forEach(f=>{u.actions.push({id:`_QUERIES_.${f.value}`,title:f.label,onClick:()=>e.openAndSetPath(["_QUERIES_",f.value]),iconKey:"query"})});const p=[i,c,d,u];return a.editorOptions.forEach(f=>{const v={group:f.label,actions:[]};v.actions.push({id:`_VIEWS_.${f.value}`,title:f.label,onClick:()=>e.openAndSetPath(["_VIEWS_",f.value]),iconKey:"view",group:f.label}),f.children.forEach(_=>{_._type!=="ACTION"&&v.actions.push({id:`_VIEWS_._PANELS_.${_.value}`,title:_.label,viz:_.viz,onClick:()=>e.openAndSetPath(["_VIEWS_",f.value,"_PANELS_",_.value,"_TABS_","Panel"]),iconKey:"panel",group:f.label})}),p.push(v)}),p}})),L2=g.types.compose("LayoutsModel",ka,g.types.model({currentLayoutWrapperWidth:g.types.optional(g.types.number,0)})).views(e=>({get divisionPreviewScale(){const t=e.currentLayoutPreviewWidth,r=e.currentLayoutWrapperWidth;return!t||!r||t<=r?1:r/t}})).actions(e=>({addALayoutItem(t){e.list.forEach(r=>{r.addNewLayout(t)})},duplicateLayoutItemsByPanelID(t,r){e.list.forEach(a=>{const l=a.findByPanelID(t);if(!l){console.error(`Can't find a layout item by panelID[${t}] in layoutSet[${a.name}]`);return}a.list.push({...l,id:Ke.v4(),panelID:r,y:1/0})})},removeByPanelID(t){e.list.forEach(r=>{r.removeByPanelID(t)})},removeByPanelIDs(t){e.list.forEach(r=>{r.removeByPanelIDs(t)})},setCurrentLayoutWrapperWidth(t){e.currentLayoutWrapperWidth=t},addALayoutSet(t,r,a){const l=e.basisLayoutSet,o={id:t,name:r,breakpoint:a,list:l.json.list.map(i=>({...i,id:Ke.v4()}))};e.list.push(o)},updateLayoutSetsInfo(t){const r=y.keyBy(e.list,"id");t.forEach(o=>{const i=r[o.id];if(i){i.setName(o.name),i.setBreakpoint(o.breakpoint),delete r[o.id];return}this.addALayoutSet(o.id,o.name,o.breakpoint)});const a=new Set(Object.keys(r)),l=a.size>0;a.forEach(o=>{const i=e.list.findIndex(c=>c.id===o);e.list.splice(i,1)}),l&&e.setCurrentBreakpoint("basis")},updateCurrentLayoutItem(t){e.currentLayoutSet.updateLayoutItem(t)},updateCurrentLayoutItems(t){t.forEach(r=>{e.currentLayoutSet.updateLayoutItem(r)})},append(t){e.list.push(t)},appendMultiple(t){t.length!==0&&e.list.push(...t)},remove(t){e.list.splice(t,1)},removeByID(t){const r=e.list.findIndex(a=>a.id===t);r!==-1&&e.list.splice(r,1)},removeByIDs(t){t.forEach(r=>{this.removeByID(r)})}})),gc=_a.views(e=>({get realDataFieldOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>{const r=t.data;return r.length===0?[]:Object.keys(r[0]).map(l=>({label:l,value:`${t.id}.${l}`,group:t.name,group_id:t.id,disabled:!1}))}).flat()},get realQueryOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>({label:t.name,value:t.id,disabled:!1}))},queryOptions(t,r){const a=[...this.realQueryOptions];return t&&!a.find(l=>l.value===t)&&a.unshift({label:t,value:t,disabled:!0}),r&&a.unshift({label:"unset",value:"",disabled:!1}),a},get realVariableOptions(){const t=e.variableValueMap;return Object.entries(e.variableAggValueMap).map(([r,a])=>({label:r,value:r,formattedValue:t[r],aggValue:a,disabled:!1}))},variableOptions(t,r){const a=[...this.realVariableOptions];return t&&!a.find(l=>l.value===t)&&a.unshift({label:t,value:t,formattedValue:"",aggValue:"",disabled:!0}),r&&a.unshift({label:"unset",value:"",formattedValue:"",aggValue:"",disabled:!1}),a},dataFieldOptions(t,r,a){let l=[...this.realDataFieldOptions];if(a&&(l=l.filter(o=>o.group_id===a)),t&&!l.find(o=>o.value===t)){const o=A(t),i=e.queryByID(o.queryID);l.unshift({label:o.columnKey,value:t,group:i?i.name:o.queryID,group_id:i?i.id:"",disabled:!0})}return r&&l.unshift({label:"unset",value:"",group:"",group_id:"",disabled:!1}),l},dataFieldOptionGroups(t,r,a){const l=this.dataFieldOptions(t,r,a);return Object.entries(y.groupBy(l,"group")).map(([i,c])=>({group:i,items:c.map(d=>({label:d.label,value:d.value,group_id:d.group_id,disabled:d.disabled}))}))},explainDataKey(t){const{queryID:r,columnKey:a}=A(t),l=e.queries.find(o=>o.id===r);return l?{queryID:r,queryName:l.name,columnKey:a}:{queryID:r,queryName:null,columnKey:a}}})).actions(e=>({removeSelf(){g.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,r){g.getRoot(e).content.views.findByID(t).removePanelID(e.id),g.getRoot(e).content.views.findByID(r).appendPanelID(e.id),g.getRoot(e).editor.setPath(["_VIEWS_",r,"_PANELS_",e.id])}})),fc=g.types.compose("PanelsModel",xa,g.types.model({list:g.types.optional(g.types.array(gc),[])})).views(e=>({get contentModel(){return g.getRoot(e).content},get options(){return e.list.map(t=>({label:t.name,value:t.id,viz_type:t.viz.type}))},editorOptions(t,r){const a=e.panelsByIDs(r);a.length!==r.length&&console.warn(`Unfulfilled panels for View[${t}]`);const l=a.map(i=>({label:i.name,value:i.id,_type:"panel",parentID:t,viz:ko[i.viz.type]})),o="_Add_A_PANEL_";return l.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:t,Icon:null,children:null}),l}})).actions(e=>({replace(t){e.list=g.castToSnapshot(t)},append(t){e.list.push(t)},appendMultiple(t){t.length!==0&&e.list.push(...t)},remove(t){e.list.splice(t,1)},removeByID(t){const r=e.list.findIndex(a=>a.id===t);r!==-1&&e.list.splice(r,1)},removeByIDs(t){t.forEach(r=>{this.removeByID(r)})},duplicateByID(t){const r=e.list.find(l=>l.id===t);if(!r){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}const a=new Date().getTime().toString();return e.list.push({...r.json,id:a,title:{...r.json.title}}),e.contentModel.layouts.duplicateLayoutItemsByPanelID(r.id,a),a},replaceByIndex(t,r){e.list.splice(t,1,r)}})),q2=ya.actions(e=>({getSchema(){const t=e.json,r=[],a=[];e.panels.forEach(i=>{const c=i.getSchema();r.push(c.panel),c.queries.length>0&&a.push(...c.queries)});const l=e.contentModel.layouts.jsonByPanelIDSet(new Set(e.panelIDs));return{views:[t],panels:r,definition:{queries:y.uniqBy(a,i=>i.id)},layouts:l,version:at}},downloadSchema(){if(e.type===$.Tabs){console.error(new Error("Please choose a tab first"));return}const t=JSON.stringify(this.getSchema(),null,2),r=e.name;Bt(r,t)}})),bc=g.types.compose("ViewsModel",va,g.types.model({current:g.types.optional(g.types.array(q2),[]),idOfVIE:g.types.string})).views(e=>({get isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))},get tabViewOptions(){return this.options.filter(t=>t.type===$.Tabs)},tabOptions(t){const r=e.current.find(a=>a.id===t&&a.type===$.Tabs&&a.tabs.length>0);return r?r.tabs.map(a=>({label:a.name,value:a.id})):[]},get editorOptions(){const t=g.getRoot(e).content.panels;return e.current.map(r=>({label:r.name,value:r.id,_type:"view",children:t.editorOptions(r.id,r.panelIDs)}))},get contentModel(){return g.getRoot(e).content}})).actions(e=>({setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},resetIDOfVIE(){this.setIDOfVIE(e.current[0].id)},replace(t){e.current.replace(t)},addANewView(t,r,a,l){e.current.push({id:t,name:r,type:a,config:l,panelIDs:[]})},append(t){e.current.push(t)},appendMultiple(t){t.length!==0&&e.current.push(...t)},remove(t){e.current.splice(t,1)},removeByID(t){const r=e.current.findIndex(i=>i.id===t);if(r===-1)return;const a=e.current[r],l=e.contentModel.panels,o=e.contentModel.layouts;l.removeByIDs(a.panelIDs),o.removeByPanelIDs(a.panelIDs),e.current.splice(r,1),this.resetIDOfVIE()},replaceByIndex(t,r){e.current.splice(t,1,r)},addARandomNewView(){const t=new Date().getTime().toString();this.addANewView(t,$.Division,$.Division,{_name:$.Division}),this.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(this.removeByID(e.idOfVIE),this.resetIDOfVIE())}}));function Ba(e){const t=e.length>0?[e[0].id]:[],r=e.length>0?e[0].id:"";return{current:e.map(l=>{const{_name:o=l.type}=l.config;return{...l,config:{...l.config,_name:o},panelIDs:l.panelIDs}}),visibleViewIDs:t,idOfVIE:r}}const O2=g.types.model({id:g.types.string,name:g.types.string,dashboard_id:g.types.string,create_time:g.types.string,update_time:g.types.string,version:g.types.string,filters:lc,queries:ic,sqlSnippets:cc,views:bc,panels:fc,layouts:L2,mock_context:Zr,origin:g.types.maybe(g.types.frozen())}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,layouts:e.layouts.json,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get contentJSON(){return this.json.content},get filtersChanged(){const t="filters.current";return!y.isEqual(g.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get queriesChanged(){const t="queries.current",r=g.getSnapshot(y.get(e,t)).map(l=>y.pick(l,["id","name","key","type","run_by","pre_process","post_process","config"])),a=y.get(e.origin,t);return!y.isEqual(r,a)},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!y.isEqual(g.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get viewsChanged(){const t="views.current";return!y.isEqual(e.views.json,y.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!y.isEqual(g.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get layoutsChanged(){const t="layouts.list";return!y.isEqual(g.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!y.isEqual(y.get(e,t),y.get(e.origin,t))},get context(){const t=g.getParent(e).context.current;return{...e.mock_context.current,...t}},get payloadForSQL(){const t=g.getParent(e).globalSQLSnippets,r={context:this.context,filters:e.filters.valuesForPayload};return{...r,sql_snippets:Ut(e.sqlSnippets.current,"key","value",r),global_sql_snippets:Ut(t.list,"id","content",r)}},get payloadForViz(){return{context:this.context,filters:e.filters.valuesForPayload}},get dashboardState(){const{context:t,filters:r}=this.payloadForViz,a={context:{},filters:e.filters.keyStateItemMap(r)};return Object.entries(t).forEach(([l,o])=>{a.context[l]={key:l,type:"context",value:o}}),a},get dashboardStateValues(){return lr(this.payloadForSQL)},get dashboardStateVariableOptions(){if(!g.isAlive(e))return{optionGroups:[],validValues:new Set};const t=new Set,{context:r}=this.payloadForSQL,a={group:"context.label",items:Object.keys(r).map(i=>{const c=`context.${i}`;return t.add(c),{label:i,value:c,description:void 0,type:"context"}})},l={group:"filter.labels",items:e.filters.keyLabelOptions.map(i=>{const c=`filters.${i.value}`;return t.add(c),{label:i.label,value:c,description:i.value,type:"filter",widget:i.widget}})};return{optionGroups:[a,l],validValues:t}},getAdditionalQueryInfo(t){return{content_id:e.id,query_id:t,params:this.dashboardStateValues}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.layoutsChanged||this.mockContextChanged},get data(){return e.queries.current.map(({id:r,data:a})=>({id:r,data:a})).reduce((r,a)=>(r[a.id]=a.data,r),{})},getDataStuffByID(t){const r=e.queries.findByID(t);return r?{data:r.data,len:r.data.length,state:r.state,error:r.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(e=>({get filtersUsage(){const t=[],r=e.views.idMap;e.filters.current.forEach(l=>{l.visibleInViewsIDs.forEach(o=>{var i;t.push({filterID:l.id,type:"view",type_label:"view.label",id:o,label:((i=r.get(o))==null?void 0:i.name)??o})})});const a=e.filters.keyIDMap;return e.queries.current.forEach(l=>{l.usedFilterKeySet.forEach(o=>{t.push({filterID:a[o]??o,type:"query",type_label:"query.label",id:l.id,label:l.name})})}),e.sqlSnippets.usedFilterKeyMap.forEach((l,o)=>{l.forEach(i=>{t.push({filterID:a[i]??i,type:"sql_snippet",type_label:"sql_snippet.label",id:o,label:o})})}),y.groupBy(t,"filterID")},findFilterUsage(t){return this.filtersUsage[t]??[]},get queriesUsage(){const t=e.panels.idMap,r=[];e.views.current.forEach(l=>{l.panelIDs.forEach(o=>{const i=t.get(o);if(!i)return;const c="panel",d=i.name,u=[{id:l.id,label:l.name}];i.queryIDs.forEach(p=>{r.push({id:o,queryID:p,type:c,type_label:"panel.label",label:d,views:u})})})});const a=e.views.idMap;return e.filters.current.filter(l=>!!y.get(l,"config.options_query_id")).forEach(l=>{r.push({type:"filter",type_label:"filter.label",id:l.id,queryID:y.get(l,"config.options_query_id"),label:l.label,views:l.visibleInViewsIDs.map(o=>{var i;return{id:o,label:((i=a.get(o))==null?void 0:i.name)??o}})})}),e.queries.current.forEach(l=>{if(!l.isTransform)return;l.config.dep_query_ids.forEach(i=>{r.push({type:"transform-query",type_label:"query.transform.full_label",id:l.id,queryID:i,label:l.name,views:[]})})}),y.groupBy(r,"queryID")},get hasUnusedQueries(){return e.queries.current.length>Object.keys(this.queriesUsage).length},findQueryUsage(t){return this.queriesUsage[t]??[]},get sqlSnippetsUsage(){const t=[];return e.queries.current.forEach(r=>{if(!r.typedAsSQL)return;const a=r.config;y.uniq(a.sql.match(Mt.sqlSnippet)).forEach(o=>{t.push({queryID:r.id,sqlSnippetKey:o,queryName:r.name})})}),y.groupBy(t,"sqlSnippetKey")},get hasUnusedSQLSnippets(){return e.sqlSnippets.current.length>Object.keys(this.sqlSnippetsUsage).length},findSQLSnippetUsage(t){return this.sqlSnippetsUsage[t]??[]}})).actions(e=>({removeUnusedQueries(){const t=new Set(Object.keys(e.queriesUsage)),r=e.queries.current.filter(a=>!t.has(a.id)).map(a=>a.id);e.queries.removeQueries(r)},removeUnusedSQLSnippets(){const t=new Set(Object.keys(e.sqlSnippetsUsage)),r=e.sqlSnippets.current.filter(a=>!t.has(a.key)).map(a=>a.key);e.sqlSnippets.removeByKeys(r)},duplicatePanelByID(t,r){var l;const a=e.panels.duplicateByID(t);a&&((l=e.views.findByID(r))==null||l.appendPanelID(a))},removePanelByID(t,r){var a;e.panels.removeByID(t),e.layouts.removeByPanelID(t),(a=e.views.findByID(r))==null||a.removePanelID(t)},addANewPanel(t){var a;const r=Ke.v4();e.panels.append(xi(r)),(a=e.views.findByID(t))==null||a.appendPanelID(r),e.layouts.addALayoutItem(r)},applyJSONSchema(t){var f;const{views:r,panels:a,filters:l,definition:o={},layouts:i}=t,{queries:c,sqlSnippets:d,mock_context:u}=o,p=new Map;if(Array.isArray(a)){const v=a.map(_=>{const w=Ke.v4();return p.set(_.id,w),{..._,id:w}});if(e.panels.appendMultiple(v),!Array.isArray(r)||r.length===0){const _=v.map(w=>w.id);(f=e.views.VIE)==null||f.appendPanelIDs(_)}}if(Array.isArray(r)){const v=r.map(_=>{const w=_.panelIDs.map(m=>p.get(m)??m);return{..._,id:Ke.v4(),panelIDs:w}});e.views.appendMultiple(v)}if(Array.isArray(i)){const v=(m,k)=>e.layouts.breakpointNameRecord[m]===k;let _=[];const w=i.filter(m=>v(m.name,m.breakpoint));w.forEach(m=>{m.id==="basis"&&(_=m.list),m.list.forEach(k=>{const z=p.get(k.panelID);k.id=Ke.v4(),k.panelID=z})}),e.layouts.list.forEach(m=>{const k=w.find(z=>z.name===m.name&&z.breakpoint===m.breakpoint);if(!k){_.forEach(z=>{m.addLayout(z)});return}k.list.forEach(z=>{m.addLayout(z)})})}Array.isArray(l)&&e.filters.appendMultiple(l),Array.isArray(c)&&e.queries.appendMultiple(c),Array.isArray(d)&&e.sqlSnippets.appendMultiple(d),u&&Object.keys(u).length>0&&e.mock_context.defaults(u)}})).actions(e=>({reset(){g.applySnapshot(e.filters.current,e.origin.filters.current),g.applySnapshot(e.queries.current,e.origin.queries.current),g.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),g.applySnapshot(e.views.current,e.origin.views.current),g.applySnapshot(e.panels.list,e.origin.panels.list),g.applySnapshot(e.layouts.list,e.origin.layouts.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){g.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:r,name:a,content:l}=t;if(!l)throw new Error("unexpected null content when updating a content model");const{version:o,filters:i,views:c,panels:d,definition:{queries:u,sqlSnippets:p,mock_context:f={}}}=l;e.id=r,e.name=a,e.version=o,g.applySnapshot(e.filters.current,i),g.applySnapshot(e.views.current,Ba(c).current),g.applySnapshot(e.panels.list,d),g.applySnapshot(e.queries.current,u),g.applySnapshot(e.sqlSnippets.current,p),e.mock_context.current=f}})),La=g.types.snapshotProcessor(O2,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=g.castToSnapshot(e.queries.current.map(r=>y.pick(r,["id","key","type","sql"])));return y.defaults({},{queries:{current:t}},e)}});function N2(e,t){t.filters&&g.applySnapshot(e.filters.current,t.filters)}function yc({id:e,name:t,dashboard_id:r,create_time:a,update_time:l,content:o},i,c){if(!o)throw new Error("unexpected null content when creating a content model");const{version:d,filters:u,views:p,panels:f,layouts:v,definition:{queries:_,sqlSnippets:w,mock_context:m={}}}=o;return La.create({id:e,name:t,dashboard_id:r,create_time:a,update_time:l,version:d,filters:ma(u,i,m,c),queries:{current:_},sqlSnippets:{current:w},mock_context:Jr(m),views:Ba(p),panels:{list:f},layouts:{list:v,currentBreakpoint:v[0].id}})}const vc=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:La,content_id:g.types.string,datasources:T2,globalSQLSnippets:fa,context:kn,editor:B2}).views(e=>({get json(){return{id:e.id,name:e.name,group:e.group,content_id:e.content_id}},get queryVariables(){return{context:{...e.content.mock_context.current,...e.context.current},filters:e.content.filters.previewValues}},get queryVariablesString(){return JSON.stringify(this.queryVariables,null,2)}})).actions(e=>({updateCurrentContent(t){e.content.updateCurrent(t)},updateCurrent(t,r){const{id:a,name:l,group:o,content_id:i}=t;e.id=a,e.name=l,e.group=o,e.content_id=i,this.updateCurrentContent(r)}}));function _c({id:e,name:t,group:r,content_id:a},l,o,i,c,d){return vc.create({id:e,name:t,group:r,content_id:a,content:yc(l,c,d),datasources:{list:o},globalSQLSnippets:{list:i},context:ba(c),editor:{}})}function Lt(e){console.groupCollapsed("Running operation ",e.type),console.log(e),console.groupEnd()}function xc(e,t){h.useEffect(()=>{const a=l=>{Lt(l);const{viewID:o}=l.detail;if(!o){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(o),t&&e.views.setIDOfVIE(o)};return window.addEventListener("open-view",a),()=>{window.removeEventListener("open-view",a)}},[e,t]);const r=Wd.useNavigate();h.useEffect(()=>{const a=l=>{Lt(l);const{panelID:o}=l.detail;if(!o){console.error(new Error("[Scroll to Panel] Needs to pick a panel first"));return}r(`#${o}`),setTimeout(()=>{const i=document.getElementById(o);i&&i.scrollIntoView({behavior:"smooth"})},300)};return window.addEventListener("scroll_to_panel",a),()=>{window.removeEventListener("scroll_to_panel",a)}},[r]),h.useEffect(()=>{const a=l=>{Lt(l);const{viewID:o,tab:i}=l.detail;if(!o){console.error(new Error("[Switch Tab] Needs to pick a view and a tab first"));return}const c=e.views.findByID(o);if(!c){console.error(new Error(`[Switch Tab] View by ID[${o}] is not found`));return}c.setTab(i)};return window.addEventListener("switch_tab",a),()=>{window.removeEventListener("switch_tab",a)}},[e,t]),h.useEffect(()=>{const a=l=>{Lt(l);const{dictionary:o,payload:i}=l.detail;if(!i||Object.keys(i).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}const c={};Object.entries(o).forEach(([d,u])=>{const p=y.get(i,u);c[d]=p}),e.filters.applyValuesPatch(c)};return window.addEventListener("set-filter-values",a),()=>{window.removeEventListener("set-filter-values",a)}},[e]),h.useEffect(()=>{function a(o){return Array.isArray(o)?[]:typeof o=="object"?{}:typeof o=="boolean"?!1:typeof o=="string"?"":typeof o=="number"?0:o}const l=o=>{Lt(o);const i={},{filter_keys:c}=o.detail;c.forEach(d=>{const u=y.get(e.filters.values,d),p=a(u);i[d]=p}),e.filters.applyValuesPatch(i)};return window.addEventListener("clear-filter-values",l),()=>{window.removeEventListener("clear-filter-values",l)}},[e]),h.useEffect(()=>{const a=l=>{Lt(l);const{urlTemplate:o,openInNewTab:i,enableEncoding:c=!1,payload:d}=l.detail;if(!o){console.error(new Error("[Open Link] URL is empty"));return}function u(v){return y.cloneDeepWith(v,w=>{if(c&&typeof w=="string")return encodeURIComponent(w)})}const f=y.template(o||"")(u({...d,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}));window.open(f,i?"_blank":"_self","noopener")};return window.addEventListener("open-link",a),()=>{window.removeEventListener("open-link",a)}},[e])}function wc(e){return h.useCallback(t=>t.provideValue(R.pluginManager,e.pluginManager).provideValue(R.vizManager,e.vizManager).provideValue(R.panelAddonManager,e.panelAddonManager).provideValue(R.colorManager,e.colorManager),[e])}const F5="",G2=T.observer(({saveDashboardChanges:e})=>{const{t}=x.useTranslation(),r=ze.useModals(),a=F(),l=()=>{r.openConfirmModal({title:n.jsxs(s.Group,{justify:"flex-start",children:[n.jsx(S.IconAlertTriangle,{size:18,color:"red"}),n.jsx(s.Text,{size:"sm",children:"You are reverting changes"})]}),labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>a.reset(),zIndex:320,withCloseButton:!1})},o=a.changed;return n.jsxs(s.Group,{gap:0,children:[n.jsx(s.Button,{color:"green",variant:"filled",size:"xs",leftSection:n.jsx(S.IconDeviceFloppy,{size:18}),onClick:e,disabled:!o,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:t("common.actions.save_changes")}),n.jsxs(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!o,children:[n.jsx(s.Menu.Target,{children:n.jsx(s.ActionIcon,{variant:"default",disabled:!o,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:n.jsx(S.IconCaretDown,{size:18})})}),n.jsx(s.Menu.Dropdown,{children:n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconRecycle,{size:14,color:"red"}),disabled:!o,onClick:l,children:t("common.actions.revert_changes")})})]})]})}),F2=T.observer(({saveDashboardChanges:e,onExit:t,headerSlot:r=null})=>{x.useTranslation();const a=W(),l=a.content.changed,o=()=>{t({hasChanges:l,dashboardId:a.id})};return n.jsx(s.AppShell.Header,{h:60,py:0,px:"md",sx:{zIndex:299},children:n.jsxs(s.Group,{justify:"space-between",sx:{height:60,minWidth:"1000px",position:"relative"},children:[n.jsxs(s.Group,{children:[n.jsx(s.Button,{size:"xs",color:l?"red":"green",leftSection:n.jsx(S.IconArrowLeft,{size:20}),onClick:o,children:n.jsx(s.Group,{gap:4,children:n.jsx(x.Trans,{i18nKey:"common.actions.end_editing",values:{name:a.name},children:n.jsx(s.Text,{td:"underline",size:"xs",children:a.name})})})}),n.jsx(G2,{saveDashboardChanges:e})]}),n.jsx(s.Group,{justify:"flex-end",sx:{flexGrow:1},children:r})]})})}),mc={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},j2=T.observer(()=>{var l;const{t:e}=x.useTranslation(),t=F(),r=((l=t.views.VIE)==null?void 0:l.type)===$.Tabs,a=()=>t.addANewPanel(t.views.idOfVIE);return r?n.jsx(s.Tooltip,{label:e("common.choose_a_tab_first"),children:n.jsx(s.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),sx:{...mc,transform:"none !important"},children:e("panel.add")})}):n.jsx(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:a,leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),sx:{...mc,background:"rgb(231, 245, 255)"},children:e("panel.add")})}),Q2=T.observer(({done:e})=>{var E,K;const{t}=x.useTranslation(),a=F().layouts,l=h.useMemo(()=>({list:a.breakpointsInfo}),[a.breakpointsInfo]),{control:o,handleSubmit:i,watch:c,getValues:d,reset:u,formState:p}=b.useForm({defaultValues:l}),{fields:f,append:v,remove:_}=b.useFieldArray({control:o,name:"list",rules:{validate:N=>{if(y.uniqBy(N,"breakpoint").length!==N.length)return"Screen sizes should be unique by min width"}}}),w=c("list"),m=f.map((N,oe)=>({...N,...w[oe]})),k=()=>{v({id:Ke.v4(),name:"",breakpoint:""})},z=({list:N})=>{const oe=N.filter(me=>Number.isFinite(me.breakpoint));a.updateLayoutSetsInfo(oe),e()},D=d(),I=h.useMemo(()=>{const N={list:D.list.filter(oe=>!!oe.name&&Number.isFinite(oe.breakpoint))};return!y.isEqual(N,l)},[D,l]),L=(K=(E=p.errors.list)==null?void 0:E.root)==null?void 0:K.message;return n.jsx(n.Fragment,{children:n.jsxs("form",{onSubmit:i(z),children:[n.jsxs(s.Table,{fz:"sm",highlightOnHover:!0,withTableBorder:!0,sx:{tableLayout:"fixed"},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"340px"},children:t("common.name")}),n.jsx(s.Table.Th,{style:{width:"160px"},children:t("breakpoint.breakpoint")}),n.jsx(s.Table.Th,{})]})}),n.jsxs(s.Table.Tbody,{children:[m.map((N,oe)=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:N.id==="basis"?N.name:n.jsx(b.Controller,{name:`list.${oe}.name`,control:o,render:({field:me})=>n.jsx(s.TextInput,{size:"xs",label:"",required:!0,sx:{flex:1},...me})})}),n.jsx(s.Table.Td,{children:N.id==="basis"?n.jsxs(s.Text,{size:"sm",ff:"monospace",children:[N.breakpoint,"px"]}):n.jsx(b.Controller,{name:`list.${oe}.breakpoint`,control:o,render:({field:me})=>n.jsx(s.NumberInput,{size:"xs",label:"",required:!0,max:1e4,hideControls:!0,rightSection:n.jsx(s.Text,{size:"sm",c:"dimmed",children:"px"}),rightSectionProps:{style:{width:"30px"}},sx:{flex:1},ff:"monospace",styles:{input:{paddingRight:"30px"}},...me})})}),n.jsx(s.Table.Td,{children:N.id!=="basis"&&n.jsx(s.ActionIcon,{mx:"auto",size:"xs",variant:"subtle",color:"red",onClick:()=>_(oe),children:n.jsx(S.IconTrash,{})})})]},N.id)),n.jsx(s.Table.Tr,{style:{backgroundColor:"transparent"},children:n.jsx(s.Table.Td,{colSpan:3,style:{padding:"0"},children:n.jsx(s.Tooltip,{label:t("breakpoint.add"),children:n.jsx(s.ActionIcon,{variant:"subtle",size:"md",color:"blue",onClick:k,sx:{width:"100%"},children:n.jsx(S.IconPlus,{size:18})})})})})]})]}),n.jsx(s.Text,{mt:6,ta:"right",size:"xs",c:"red",children:L??" "}),n.jsxs(s.Group,{mt:6,justify:"space-between",children:[n.jsx(s.Button,{color:"orange",size:"xs",onClick:()=>u(),leftSection:n.jsx(S.IconRecycle,{size:18}),disabled:!I,children:t("common.actions.revert")}),n.jsx(s.Button,{color:"green",size:"xs",type:"submit",leftSection:n.jsx(S.IconDeviceFloppy,{size:18}),disabled:!I,children:t("common.actions.save_changes")})]})]})})}),W2=T.observer(()=>{const{t:e}=x.useTranslation(),[t,{open:r,close:a}]=te.useDisclosure(!1),l=F(),o=l.layouts.currentBreakpoint,i=l.layouts.currentLayoutRange,c=()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},d=()=>{a(),c()};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{children:[n.jsxs(s.Menu,{withArrow:!0,withinPortal:!0,zIndex:320,trigger:"hover",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Button,{size:"xs",variant:"subtle",leftSection:n.jsx(S.IconDevices,{size:16}),sx:{borderRadius:0},children:n.jsxs(s.Group,{gap:6,children:[n.jsx(s.Text,{size:"xs",fw:"normal",children:i.name}),n.jsx(s.Text,{size:"xs",c:"#777",children:l.layouts.currentRangeText})]})})}),n.jsxs(s.Menu.Dropdown,{children:[l.layouts.breakpointRanges.map(u=>n.jsx(s.Menu.Item,{onClick:()=>l.layouts.setCurrentBreakpoint(u.id),disabled:o===u.id,children:n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Text,{size:"sm",children:u.name}),n.jsx(s.Text,{size:"xs",c:"dimmed",children:u.text})]})},u.id)),n.jsx(s.Menu.Divider,{}),n.jsx(s.Menu.Item,{color:"blue",leftSection:n.jsx(S.IconSettings,{size:14}),onClick:r,children:n.jsx(s.Text,{size:"sm",children:e("breakpoint.manage")})})]})]}),l.layouts.divisionPreviewScale<1&&n.jsx(s.Text,{size:"xs",c:"dimmed",children:Ye(l.layouts.divisionPreviewScale).format({output:"percent",mantissa:0})})]}),n.jsx(s.Modal,{opened:t,onClose:d,title:e("breakpoint.label",{count:2}),withinPortal:!0,zIndex:320,size:600,closeOnClickOutside:!1,children:n.jsx(Q2,{done:d})})]})}),Cc={height:"30px",borderRight:"none",borderTop:"none",borderLeft:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},U2=T.observer(()=>{var l;const{t:e}=x.useTranslation(),t=F(),r=((l=t.views.VIE)==null?void 0:l.type)===$.Tabs,a=()=>{var o;return(o=t.views.VIE)==null?void 0:o.downloadSchema()};return r?n.jsx(s.Tooltip,{label:e("common.choose_a_tab_first"),children:n.jsx(s.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftSection:n.jsx(S.IconCode,{size:16}),sx:{...Cc,transform:"none !important"},children:e("view.download_schema")})}):n.jsx(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:a,leftSection:n.jsx(S.IconCode,{size:16}),sx:{...Cc},children:e("view.download_schema")})}),Mn=({headers:e,rows:t})=>n.jsxs(s.Table,{fz:"xs",highlightOnHover:!0,sx:{tableLayout:"fixed",fontFamily:"monospace"},children:[n.jsx(s.Table.Thead,{children:e}),n.jsx(s.Table.Tbody,{children:t})]}),Y2=({content:e})=>{const{t}=x.useTranslation(),r=e.views;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("view.labels")}),n.jsx(Mn,{headers:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"160px"},children:t("common.id")}),n.jsx(s.Table.Th,{children:t("common.name")}),n.jsx(s.Table.Th,{children:t("common.type")})]}),rows:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.id}),n.jsx(s.Table.Td,{children:a.name}),n.jsx(s.Table.Td,{children:t(`view.component.${a.type}.label`)})]},a.id))})]})},K2=({content:e})=>{const{t}=x.useTranslation(),r=e.filters;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("filter.labels")}),n.jsx(Mn,{headers:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"160px"},children:t("common.id")}),n.jsx(s.Table.Th,{children:t("common.key")}),n.jsx(s.Table.Th,{children:t("common.label")})]}),rows:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.id}),n.jsx(s.Table.Td,{children:a.key}),n.jsx(s.Table.Td,{children:a.label})]},a.id))})]})},X2=({content:e})=>{const{t}=x.useTranslation(),r=e.panels;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("panel.labels")}),n.jsx(Mn,{headers:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"160px"},children:t("common.id")}),n.jsx(s.Table.Th,{children:t("common.name")}),n.jsx(s.Table.Th,{children:t("visualization.component")})]}),rows:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.id}),n.jsx(s.Table.Td,{children:a.name}),n.jsx(s.Table.Td,{children:a.viz.type})]},a.id))})]})},Z2=({content:e})=>{var a;const{t}=x.useTranslation(),r=(a=e.definition)==null?void 0:a.queries;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("query.labels")}),n.jsx(Mn,{headers:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"160px"},children:t("common.id")}),n.jsx(s.Table.Th,{children:t("common.name")}),n.jsx(s.Table.Th,{style:{width:"140px"},children:t("common.type")}),n.jsx(s.Table.Th,{style:{width:"260px"},children:t("data_source.label")})]}),rows:r.map(l=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:l.id}),n.jsx(s.Table.Td,{children:l.name}),n.jsx(s.Table.Td,{children:l.type}),n.jsx(s.Table.Td,{children:l.key})]},l.id))})]})},J2=({content:e})=>{var a;const{t}=x.useTranslation(),r=(a=e.definition)==null?void 0:a.sqlSnippets;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("sql_snippet.labels")}),n.jsx(s.List,{size:"sm",pl:10,ff:"monospace",icon:n.jsx(S.IconPointFilled,{size:10}),children:r.map(l=>n.jsx(s.List.Item,{children:l.key},l.key))})]})},H2=({content:e})=>{var a;const{t}=x.useTranslation(),r=Object.keys(((a=e.definition)==null?void 0:a.mock_context)??{});return r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("mock_context.label")}),n.jsx(s.List,{size:"sm",pl:10,ff:"monospace",icon:n.jsx(S.IconPointFilled,{size:10}),children:r.map(l=>n.jsx(s.List.Item,{children:l},l))})]})},R2=({content:e})=>e?n.jsxs(s.Box,{children:[n.jsx(s.Divider,{mt:20,mb:10,variant:"dashed"}),n.jsx(s.Text,{ta:"left",c:"dimmed",size:"sm",children:"Preview"}),n.jsxs(s.Stack,{children:[n.jsx(Y2,{content:e}),n.jsx(K2,{content:e}),n.jsx(X2,{content:e}),n.jsx(Z2,{content:e}),n.jsx(J2,{content:e}),n.jsx(H2,{content:e})]})]}):null;function ek(e){if(e.target===null)throw new Error("FileReader failed with null result");if(typeof e.target.result!="string")throw new Error(`Unparsable file content of type: ${typeof e.target.result}`);let t=JSON.parse(e.target.result);if("content"in t&&(t=t.content),t.version!==at)throw new Error("Schema version mismatch");return t}const tk=T.observer(({onSuccess:e,stretchModal:t,shrinkModal:r})=>{var z,D;const{t:a}=x.useTranslation(),l=F(),{handleSubmit:o,formState:{errors:i},setValue:c,watch:d,setError:u,clearErrors:p}=b.useForm({defaultValues:{content:null}}),f=({content:I})=>{try{if(!I)throw new Error("please use a valid json file");l.applyJSONSchema(I),Ze.showNotification({title:"Successful",message:"",color:"green"}),e()}catch(L){console.error(L),Ze.showNotification({title:"Failed",message:L.message,color:"red"})}},[v,_]=h.useState(null);h.useEffect(()=>{if(!v)return;const I=new FileReader;I.readAsText(v,"UTF-8"),I.onload=L=>{try{const E=ek(L);c("content",E),p("content")}catch(E){console.error(E),u("content",{type:"custom",message:E.message})}},I.onabort=()=>console.log("🟨 abort"),I.onerror=()=>{I.error&&(console.error(I.error),u("content",{type:"custom",message:I.error.message}))}},[v]);const[w]=d(["content"]),m=!w,k=(z=i==null?void 0:i.content)==null?void 0:z.message;return h.useEffect(()=>{!w||k?r():t()},[w,k]),n.jsx(s.Box,{mx:"auto",sx:{position:"relative"},children:n.jsxs("form",{onSubmit:o(f),children:[n.jsx(s.FileInput,{label:a("import.json_file"),required:!0,value:v,onChange:_,error:(D=i==null?void 0:i.content)==null?void 0:D.message,sx:{maxWidth:500}}),k?n.jsx(s.Table,{fz:12,mt:10,children:n.jsxs(s.Table.Tbody,{children:[n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:a("import.this_dashboard")}),n.jsx(s.Table.Td,{children:at})]}),n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:a("import.this_file")}),n.jsx(s.Table.Td,{style:{color:"red"},children:w==null?void 0:w.version})]})]})}):n.jsxs(n.Fragment,{children:[n.jsx(R2,{content:w}),n.jsx(s.Group,{justify:"flex-end",my:"md",children:n.jsx(s.Button,{type:"submit",color:"green",disabled:m,children:a("common.actions.confirm")})})]})]})})}),Sc={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},nk=T.observer(()=>{var u;const{t:e}=x.useTranslation(),[t,{open:r,close:a}]=te.useDisclosure(!1),[l,{setTrue:o,setFalse:i}]=O.useBoolean(!1),d=((u=W().content.views.VIE)==null?void 0:u.type)===$.Tabs;return d?n.jsx(s.Tooltip,{label:e("common.choose_a_tab_first"),children:n.jsx(s.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftSection:n.jsx(S.IconFileImport,{size:16}),sx:{...Sc,transform:"none !important"},children:e("import.label")})}):n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{variant:"subtle",color:"blue",radius:0,size:"xs",disabled:d||t,onClick:r,leftSection:n.jsx(S.IconFileImport,{size:16}),sx:{...Sc},children:e("import.label")}),n.jsx(s.Modal,{opened:t,onClose:a,title:e("import.title"),trapFocus:!0,onDragStart:p=>{p.stopPropagation()},withinPortal:!0,zIndex:320,size:l?"90vw":500,children:n.jsx(tk,{onSuccess:a,stretchModal:o,shrinkModal:i})})]})}),rk=({iconKey:e,...t})=>{switch(e){case"query_variables":return n.jsx(S.IconVariable,{...t});case"mock_context":return n.jsx(S.IconCodeDots,{...t});case"filter":return n.jsx(S.IconFilter,{...t});case"sql_snippet":return n.jsx(S.IconCopy,{...t});case"query":return n.jsx(S.IconDatabase,{...t});case"view":return n.jsx(S.IconBoxMultiple,{...t});case"panel":return n.jsx(S.IconAppWindow,{...t});default:return null}},ak=({action:e})=>{const{t}=x.useTranslation();return e.description?n.jsx(s.Text,{c:"dimmed",size:"xs",children:t(e.description)}):e.viz?n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Text,{c:"dimmed",size:"xs",children:t(e.viz.displayName)}),n.jsx(s.Text,{c:"dimmed",size:"xs",className:"spotlight-action-viz-group",children:t(e.viz.displayGroup)})]}):null},sk=T.observer(({action:e,query:t})=>{const{t:r}=x.useTranslation();return n.jsx(s.Box,{className:"spotlight-custom-action-component",children:n.jsxs(s.Group,{wrap:"nowrap",children:[n.jsx(rk,{iconKey:e.iconKey,size:14}),n.jsxs("div",{style:{flex:1},children:[n.jsx(s.Highlight,{highlight:t,size:"sm",children:e.title?r(e.title):""}),n.jsx(ak,{action:e})]})]})})}),lk=({groups:e,query:t})=>{const{t:r}=x.useTranslation();return e.length===0?n.jsx(vt.Spotlight.Empty,{children:r("spotlight.not_found")}):n.jsx(n.Fragment,{children:e.map(a=>n.jsx(vt.Spotlight.ActionsGroup,{label:a.group,children:a.actions.map(l=>n.jsx(vt.Spotlight.Action,{onClick:l.onClick,children:n.jsx(sk,{action:l,query:t})},l.id))},a.group))})},ok=T.observer(()=>{const{t:e,i18n:t}=x.useTranslation(),r=s.useMantineTheme(),a=W(),[l,o]=h.useState(""),i=h.useMemo(()=>a.editor.spotlightActionGroups.map(d=>({group:e(d.group),keywords:[d.group,e(d.group)],actions:d.actions.map(u=>{const p=[];return u.title&&(p.push(u.title.toLowerCase()),p.push(e(u.title).toLowerCase())),u.group&&p.push(u.group.toLowerCase()),u.viz&&(p.push(u.viz.displayGroup.toLowerCase()),p.push(u.viz.displayName.toLowerCase())),u.iconKey&&p.push(u.iconKey),{...u,keywords:p}})})),[a.editor.spotlightActionGroups,t.language]),c=h.useMemo(()=>{const d=l.toLowerCase().trim();return d?i.map(p=>{if(p.keywords.some(_=>_.includes(d)))return p;const v=p.actions.filter(_=>_.keywords.some(w=>w.includes(d)));return v.length===0?null:{...p,actions:v}}).filter(p=>p!==null):[i[0]]},[i,l]);return n.jsxs(vt.Spotlight.Root,{onQueryChange:o,shortcut:["mod + P","mod + K"],radius:"md",styles:{search:{border:"none"},action:{position:"relative",display:"block",width:"100%",padding:`${s.rem(10)} ${s.rem(12)}`,borderRadius:r.radius.sm,".spotlight-action-viz-group":{opacity:0},"&:hover, &[data-selected]":{backgroundColor:r.colors.gray[1],".spotlight-action-viz-group":{opacity:1}}}},children:[n.jsx(vt.Spotlight.Search,{placeholder:e("spotlight.placeholder"),leftSection:n.jsx(S.IconSearch,{size:"1.2rem"})}),n.jsx(vt.Spotlight.ActionsList,{children:n.jsx(lk,{groups:c,query:l})})]})}),Tc=({children:e})=>n.jsx(s.Text,{style:{fontSize:"0.6875rem",lineHeight:1,padding:"0.25rem 0.2375rem",borderRadius:"0.25rem"},children:e}),kc=function(){var t;return(((t=navigator.userAgentData)==null?void 0:t.platform)??navigator.platform).toLowerCase().includes("mac")}(),ik=()=>{const{t:e}=x.useTranslation();return n.jsx(s.Tooltip,{label:n.jsxs(n.Fragment,{children:[kc&&n.jsx(Tc,{children:"⌘ + K"}),!kc&&n.jsx(Tc,{children:"Ctrl + K"})]}),children:n.jsx(s.UnstyledButton,{onClick:()=>vt.spotlight.open(),style:{height:"1.875rem",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef",paddingLeft:"calc(0.875rem / 1.5)",paddingRight:"1rem"},sx:{color:"#228be6",background:"transparent","&:hover":{background:"rgb(231, 245, 255)"}},children:n.jsxs(s.Group,{gap:"0.625rem",children:[n.jsx(S.IconSearch,{size:"1rem",color:"#228be6"}),n.jsx(s.Text,{fw:500,style:{flexGrow:1,fontWeight:500,fontSize:"0.75rem",lineHeight:1},children:e("spotlight.trigger_text")})]})})})},ck={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},dk=T.observer(()=>n.jsx(s.Box,{sx:ck,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:n.jsxs(s.Group,{justify:"space-between",align:"center",sx:{height:"30px"},children:[n.jsxs(s.Group,{justify:"flex-start",gap:0,children:[n.jsx(j2,{}),n.jsx(nk,{}),n.jsx(ik,{})]}),n.jsx(W2,{}),n.jsx(s.Group,{justify:"flex-end",gap:0,children:n.jsx(U2,{})})]})})),uk=T.observer(e=>n.jsxs(n.Fragment,{children:[n.jsx(F2,{...e}),n.jsx(dk,{})]}));function pk(e,t,r){const a=[];return e.filter(l=>"__INTERACTIONS"in l.viz.conf).forEach((l,o)=>{const i=t[l.id];i.data.interactions=y.get(i,"data.interactions",[]);const{__INTERACTIONS:c,__OPERATIONS:d,__TRIGGERS:u}=l.viz.conf;Object.entries(d).forEach(([p,f])=>{const{schemaRef:v,data:_}=f,{config:w}=_;switch(v){case"builtin:op:open-link":let m=w.urlTemplate.substring(0,100);w.urlTemplate.length>=20&&(m+="..."),i.type="interaction",i.data.interactions.push({schemaRef:v,urlTemplate:w.urlTemplate,shortURLTemplate:m});return;case"builtin:op:open_view":a.push({id:`OPERATION--${p}`,source:l.id,target:w.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":i.type="interaction",i.data.interactions.push({schemaRef:v,filters:Object.keys(w.dictionary).map(k=>({key:k,label:r[k]}))});return;case"builtin:op:clear_filter_values":i.type="interaction",i.data.interactions.push({schemaRef:v,filters:w.filter_keys.map(k=>({key:k,label:r[k]}))});return;default:return}})}),a}function hk(e,t){const r=e.filters.keyLabelMap;return{edges:pk(e.panels.list,t,r),edgeNodes:[]}}function zc(e,t,r){return e*t+e*r}function gk(e,t,r){return e*t+(e-1)*r}const An=25,qa=40,Dc=25,Oa=350,fk=150,bk=150,Ic=150,Mc=300,Pn=40,Ac=25,yk=300;function vk(e,t){const r=y.keyBy(t,l=>l.id),a=[];return e.current.forEach((l,o)=>{l.panelIDs.forEach((i,c)=>{const d=zc(c,Pn,Ac)+qa,u=r[i];if(!u){a.push({id:i,_node_type:"panel",parentNode:l.id,data:{label:`!: ${i}`},position:{x:An,y:d},sourcePosition:ie.Position.Right,targetPosition:ie.Position.Left,style:{width:Mc,height:Pn}});return}const p=u.name;a.push({id:u.id,_node_type:"panel",parentNode:l.id,data:{label:p},position:{x:An,y:d},sourcePosition:ie.Position.Right,targetPosition:ie.Position.Left,style:{width:Mc,height:Pn}})})}),a}const _k={[$.Division]:"Div",[$.Modal]:"Modal",[$.Tabs]:"Tabs"},xk=ac;function wk(e){return e.current.map((r,a)=>{const l=gk(r.panelIDs.length,Pn,Ac)+qa+Dc;let o=[];return r.type===$.Tabs&&(o=r.config.tabsInOrder.map(c=>c.view_id)),{id:r.id,_node_type:"view-root",_view_type:r.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${_k[r.type]}:${r.name}`},position:{x:0,y:0},sourcePosition:ie.Position.Right,targetPosition:ie.Position.Left,className:"light",style:{backgroundColor:xk[r.type],width:Oa,height:l}}})}function mk(e){const t=y.keyBy(e,r=>r.id);e.forEach(r=>{r._node_type!=="view-root"||r._view_type!==$.Tabs||r._tab_view_ids.forEach(a=>{t[a].parentNode=r.id})})}function Ck(e){const t=wk(e.views);mk(t);const r=vk(e.views,e.panels.list);return[...t,...r]}function Sk({nodeMap:e,nodes:t,edges:r}){t.forEach(a=>{a._node_type!=="view-root"||a._view_type!==$.Tabs||(a.sourcePosition=ie.Position.Bottom,a.style.width=Oa+An*2,a.style.height=Dc+a._tab_view_ids.reduce((l,o)=>{const i=e[o];i.position.y=l,i.position.x=An;const c=i.style.height;return l+c+20},qa))})}function Tk({nodeMap:e,nodes:t,edges:r}){r.filter(a=>a.label==="Open View").forEach(a=>{const l=e[a.source],o=e[a.target];if(!l||!o||!l.parentNode)return;const i=e[l.parentNode];i._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+i._view_level,i._sub_view_ids.push(o.id))}),t.sort((a,l)=>a._node_type==="view-root"&&l._node_type==="view-root"?a._view_level-l._view_level:a._node_type!=="view-root"&&l._node_type!=="view-root"?0:a._node_type==="view-root"?-1:1)}function kk({nodeMap:e,nodes:t,edges:r}){const a={};r.forEach(l=>{if(l.label!=="Open View")return;const o=e[l.source],i=e[l.target];if(o&&i&&o.parentNode){const c=e[o.parentNode],d=c.position.x,u=Number(y.get(i,"style.height",0)),p=Number(c.style.width);i.position.x=d+p+yk,c._view_level===0&&i._sub_view_ids.length===0&&(o.sourcePosition=ie.Position.Left,i.targetPosition=ie.Position.Right,i.position.x*=-1);const v=i.position.x,_=y.get(a,v,0);i.position.y=_,a[v]=_+u+Ic}})}function zk({nodeMap:e,nodes:t,edges:r}){const a=new Set,l=new Set;r.forEach(i=>{a.add(i.source),l.add(i.target)}),t.filter(i=>i._node_type!=="view-root"||i.id==="Main"||i.parentNode?!1:!a.has(i.id)&&!l.has(i.id)).forEach((i,c)=>{i.position.x=zc(c,Oa,bk),i.position.y=0-fk-Ic})}function Dk({nodeMap:e,nodes:t,edges:r}){const a={nodeMap:e,nodes:t,edges:r};return zk(a),Tk(a),Sk(a),kk(a),{nodes:t,edges:r}}function Ik(e){const t=Ck(e),r=y.keyBy(t,d=>d.id),{edges:a,edgeNodes:l}=hk(e,r),o=[...t,...l],i=y.keyBy(o,d=>d.id),c={edges:y.uniqBy(a,d=>d.id),nodes:o,nodeMap:i};return Dk(c)}const j5="",Na={"builtin:op:open-link":n.jsx(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:n.jsx(S.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":n.jsx(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:n.jsx(S.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":n.jsx(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:n.jsx(S.IconCircleOff,{size:14})})};function Mk(e){const t=[];return e.forEach(r=>{switch(r.schemaRef){case"builtin:op:open-link":t.push({key:r.urlTemplate,icon:Na[r.schemaRef],text:n.jsxs(s.Group,{gap:4,children:[n.jsx(s.Text,{size:"sm",children:"Open: "}),n.jsx(s.Text,{size:"sm",c:"dimmed",children:r.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":r.filters.forEach(({key:a,label:l})=>{t.push({key:r.schemaRef+a,icon:Na[r.schemaRef],text:n.jsx(s.Group,{gap:4,children:n.jsxs(s.Text,{size:"sm",children:["Set Filter: ",l]})})})});return;case"builtin:op:clear_filter_values":r.filters.forEach(({key:a,label:l})=>{t.push({key:r.schemaRef+a,icon:Na[r.schemaRef],text:n.jsx(s.Group,{gap:4,children:n.jsxs(s.Text,{size:"sm",children:["Clear Filter: ",l]})})})});return}}),t}const Ak=h.memo(({data:e,isConnectable:t,sourcePosition:r=ie.Position.Right,targetPosition:a=ie.Position.Left,...l})=>{const o=h.useMemo(()=>Mk(e.interactions),[e.interactions]);return n.jsxs(n.Fragment,{children:[n.jsx(ie.Handle,{type:"target",position:a,isConnectable:t}),n.jsx(s.Box,{sx:{position:"absolute",top:0,right:0},children:n.jsx(S.IconChevronsUpRight,{size:12})}),n.jsxs(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Text,{size:"sm",children:e.label})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(s.List,{spacing:"xs",size:"sm",center:!0,children:o.map(i=>n.jsx(s.List.Item,{icon:i.icon,children:i.text},i.key))})})]}),n.jsx(ie.Handle,{type:"source",position:r,isConnectable:t})]})}),Q5="",Pk={interaction:Ak},Vk=T.observer(()=>{const e=J(),{edges:t,nodes:r}=Ik(e);return n.jsxs(ie,{nodes:r,edges:t,onNodesChange:y.noop,onEdgesChange:y.noop,onConnect:y.noop,className:"interactions-viewer",fitView:!0,nodeTypes:Pk,children:[n.jsx(ie.MiniMap,{}),n.jsx(ie.Controls,{}),n.jsx(ie.Background,{})]})}),$k=T.observer(({opened:e,close:t})=>{const{t:r}=x.useTranslation();return n.jsx(s.Modal,{size:"96vw",opened:e,onClose:t,title:r("interactions.interactions_viewer"),trapFocus:!0,onDragStart:a=>{a.stopPropagation()},styles:{body:{height:"calc(90vh - 54px)"},content:{transform:"none !important"}},zIndex:300,children:n.jsx(Vk,{})})}),Ek={"> button":{"&:first-of-type":{borderTopRightRadius:0,borderBottomRightRadius:0,borderRightWidth:.5},":not(:first-of-type):not(:last-of-type)":{borderTopRightRadius:0,borderBottomRightRadius:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5,borderRightWidth:.5},"&:last-of-type":{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5}}};function Bk({onClick:e,name:t,active:r,openSettings:a}){return n.jsxs(s.Box,{sx:{position:"relative"},children:[n.jsx(s.UnstyledButton,{sx:l=>({display:"block",width:"100%",padding:l.spacing.xs,borderRadius:0,position:"relative",color:l.black,"&:hover":{backgroundColor:l.colors.gray[0]},backgroundColor:r?l.colors.gray[2]:"transparent"}),children:n.jsx(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:n.jsx(s.Text,{size:"sm",children:t})})}),r&&n.jsx(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:n.jsx(s.ActionIcon,{onClick:a,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:n.jsx(S.IconAdjustments,{size:16})})})]})}const Lk=T.observer(()=>{const{t:e}=x.useTranslation(),t=W(),r=F(),a=h.useCallback(o=>()=>r.views.setIDOfVIE(o),[r]),l=o=>{t.editor.open(["_VIEWS_",o])};return n.jsxs(s.Box,{sx:{position:"relative"},children:[r.views.options.map(o=>n.jsx(Bk,{active:r.views.idOfVIE===o.value,name:o.label,onClick:a(o.value),openSettings:()=>l(o.value)},o.value)),n.jsx(s.Divider,{variant:"dashed"}),n.jsx(s.Button,{variant:"subtle",rightSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:r.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:e("view.add")})]})}),qk=T.observer(()=>{const{t:e}=x.useTranslation(),t=W(),r=F(),a=()=>{if(!r.queries.firstID){t.editor.open(["_QUERIES_",""]);return}t.editor.open(["_QUERIES_",r.queries.firstID])},l=()=>{if(!r.filters.firstID){t.editor.open(["_FILTERS_",""]);return}t.editor.open(["_FILTERS_",r.filters.firstID])},[o,i]=h.useState(!1),c=()=>i(!0),d=()=>i(!1);return n.jsxs(s.AppShell.Navbar,{p:0,zIndex:299,children:[n.jsxs(s.AppShell.Section,{children:[n.jsxs(s.Group,{grow:!0,gap:0,sx:{...Ek,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[n.jsx(s.Tooltip,{label:e("filter.labels"),withinPortal:!0,children:n.jsx(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:n.jsx(S.IconFilter,{size:18})})}),n.jsx(s.Tooltip,{label:e("query.labels"),withinPortal:!0,children:n.jsx(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:a,children:n.jsx(S.IconDatabase,{size:18})})}),n.jsx(s.Tooltip,{label:e("interactions.interactions_viewer"),withinPortal:!0,children:n.jsx(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:c,children:n.jsx(S.IconRoute,{size:18})})})]}),n.jsx($k,{opened:o,close:d})]}),n.jsx(s.AppShell.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:n.jsx(s.Text,{size:"sm",ta:"center",sx:{userSelect:"none",cursor:"default"},children:e("view.labels")})}),n.jsx(s.AppShell.Section,{grow:!0,sx:{overflow:"auto"},children:n.jsx(Lk,{})}),n.jsx(s.AppShell.Section,{children:n.jsx(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:n.jsx(s.Button,{size:"xs",leftSection:n.jsx(S.IconSettings,{size:20}),onClick:()=>t.editor.open([]),children:e("common.titles.settings")})})})]})}),Ok=T.observer(({filter:e})=>{const{t}=x.useTranslation(),r=e.config;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Checkbox,{checked:r.default_value,onChange:a=>r.setDefaultValue(a.currentTarget.checked),label:t("filter.widget.checkbox.default_checked")}),n.jsx(St,{filter:e})]}),n.jsx(pt,{label:t("filter.widget.checkbox.description"),value:r.description,onChange:r.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}},e.id)]})}),Nk=[{label:"2022",value:"YYYY"},{label:"202201",value:"YYYYMM"},{label:"20220101",value:"YYYYMMDD"},{label:"2022-01",value:"YYYY-MM"},{label:"2022-01-01",value:"YYYY-MM-DD"}],Gk=T.observer(function({filter:t}){const{t:r}=x.useTranslation(),a=t.config,l=h.useMemo(()=>{const i=Xo();return Object.entries(i).map(([c,d])=>({group:r(`filter.widget.date_range.shortcut.${c}.label`),items:d.map(({key:u,value:p})=>({label:r(`filter.widget.date_range.shortcut.${c}.full.${u}`),value:p}))}))},[]),o=[...a.default_value];return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{children:[n.jsx(s.Checkbox,{checked:a.required,onChange:i=>a.setRequired(i.currentTarget.checked),label:r("filter.widget.date_range.required")}),n.jsx(s.Checkbox,{checked:a.allowSingleDateInRange,onChange:i=>a.setAllowSingleDateInRange(i.currentTarget.checked),label:r("filter.widget.date_range.allow_single_date")})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.Select,{data:Nk,label:r("filter.widget.date_range.display_format"),value:a.inputFormat,onChange:a.setInputFormat}),n.jsx(s.NumberInput,{label:r("filter.widget.date_range.max_days"),min:0,value:a.max_days,onChange:a.setMaxDays,hideControls:!0})]}),n.jsxs(s.Group,{children:[n.jsx(Bi,{label:r("filter.widget.date_range.default_value"),config:a,value:{value:o,shortcut:null},onChange:a.setDefaultValue,disabled:!!a.default_shortcut}),n.jsx(s.Select,{data:l,label:r("filter.widget.date_range.default_by_shortcut"),value:a.default_shortcut,onChange:a.setDefaultShortcut,placeholder:r("filter.widget.date_range.default_by_shortcut_placeholder"),clearable:!0,sx:{flexGrow:1},maxDropdownHeight:500})]}),n.jsx(St,{filter:t})]})}),Fk=`
545
+ `}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),g.addDisposer(e,Q.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),v2=g.types.model({data:g.types.optional(g.types.frozen(),{}),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0}})),_2=g.types.model({tables:g.types.optional(v2,{}),columns:g.types.optional(f2,{}),tableData:g.types.optional(y2,{}),indexes:g.types.optional(b2,{}),table_schema:g.types.optional(g.types.string,""),table_name:g.types.optional(g.types.string,"")}).views(e=>({get dataSource(){return g.getParent(e)},get key(){return this.dataSource.key},get type(){return this.dataSource.type},get sqlDataSourceType(){return this.type},get reloadConditionString(){const t=this.type,{table_name:r,table_schema:a}=e;return`${t};${r};${a}`}})).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(e=>({setKeywords(t,r){e.table_schema=t,e.table_name=r}})).actions(e=>({initKeywords(){if(e.tables.empty)return;const t=Object.keys(e.tables.data)[0],r=e.tables.data[t][0].table_name;e.setKeywords(t,r)}})).actions(e=>{const t=g.flow(function*(){var r;(r=e.controllers.tables)==null||r.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const a=yield*g.toGenerator(Ve.structure(e.controllers.tables.signal)({query_type:"TABLES",type:e.sqlDataSourceType,key:e.key,table_schema:"",table_name:""},{params:{query_type:"TABLES"}}));e.tables.data=y.groupBy(a,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(a){if(!Se.isCancel(a)){e.tables.data={};const l=y.get(a,"message","unkown error");e.tables.error=y.get(a,"response.data.detail.message",l),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:g.flow(function*(){var r;(r=e.controllers.columns)==null||r.abort(),e.controllers.columns=new AbortController,e.columns.state="loading";try{e.columns.data=yield*g.toGenerator(Ve.structure(e.controllers.columns.signal)({query_type:"COLUMNS",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"COLUMNS"}})),e.columns.state="idle",e.columns.error=null}catch(a){if(Se.isCancel(a))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const l=y.get(a,"message","unkown error");e.columns.error=y.get(a,"response.data.detail.message",l),e.columns.state="error"}}}),loadIndexes:g.flow(function*(){var r;(r=e.controllers.indexes)==null||r.abort(),e.controllers.indexes=new AbortController,e.indexes.state="loading";try{e.indexes.data=yield*g.toGenerator(Ve.structure(e.controllers.indexes.signal)({query_type:"INDEXES",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"INDEXES"}})),e.indexes.state="idle",e.indexes.error=null}catch(a){if(Se.isCancel(a))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const l=y.get(a,"message","unkown error");e.indexes.error=y.get(a,"response.data.detail.message",l),e.indexes.state="error"}}}),loadTableData:g.flow(function*(){var a;(a=e.controllers.tableData)==null||a.abort(),e.controllers.tableData=new AbortController;const r=e.tableData;r.state="loading";try{r.data=yield*g.toGenerator(Ve.structure(e.controllers.tableData.signal)({query_type:"DATA",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name,limit:r.limit,offset:r.offset},{params:{query_type:"DATA"}}));const[{total:l}]=yield*g.toGenerator(Ve.structure(e.controllers.tableData.signal)({query_type:"COUNT",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"COUNT"}}));r.total=Number(l),r.state="idle",r.error=null}catch(l){if(Se.isCancel(l))r.state="idle",r.error=null;else{r.data=[];const o=y.get(l,"message","unkown error");r.error=y.get(l,"response.data.detail.message",o),r.state="error"}}})}}).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>e.reloadConditionString,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>e.reloadConditionString,e.loadIndexes,{fireImmediately:!1,delay:500})),g.addDisposer(e,Q.reaction(()=>`${e.reloadConditionString};limit:${e.tableData.limit};offset:${e.tableData.offset}`,e.loadTableData,{fireImmediately:!1,delay:0}))}})),hc=new Set(["yoy_ratio","step_ratio","span_steps_calculation"]),gc={accumulate:"累计计算",yoy_ratio:"年同比率(yoy)",step_ratio:"环比率",span_steps_calculation:"移动计算",percentage_total:"总占"};function x2(e){var a;if("cols"in e){const{cols:l}=e,o=((a=l.find(c=>c.type==="trending_date_col"))==null?void 0:a.metricSourceCol)??null,i=hc.has(e.calculation)?`当前指标涉及 ${y.get(gc,e.calculation,e.calculation)},缺少时序则无法展示有效结果。
546
+ `:"";return{filters:l.filter(c=>c.type==="filter").map(c=>c.metricSourceCol),groupBys:l.filter(c=>c.type==="group_by").map(c=>c.metricSourceCol),trendingDateCol:o,supportTrending:!!o,requireTrendingReason:i}}const t=y.uniq(e.derivedMetrics.map(l=>l.calculation)).filter(l=>hc.has(l)),r=e.supportTrending&&t.length>0?`当前指标涉及 ${t.map(l=>y.get(gc,l,l)).join("、")},缺少时序则无法展示有效结果。`:"";return{filters:e.filters,groupBys:e.groupBys,trendingDateCol:null,supportTrending:e.supportTrending,requireTrendingReason:r}}const fc={string:"维度列",number:"数值列",date:"数值列",boolean:"维度列",dimension:"扩展维度"};function bc(e){return y.groupBy(e,r=>{const{dataType:a}=r;return a?fc[a]:r.dimension!==null?fc.dimension:"ERROR"})}function w2(e){if(e.length===0)return[];const t=bc(e);return Object.entries(t).map(([a,l])=>({group:`${a}(${l.length})`,items:l.map(o=>{const{dataType:i,dimension:c}=o;return c?{group:o.name,description:o.description,items:c.fields.map(d=>typeof d=="string"?{label:d,value:`${o.name} -> ${d}`}:{label:d.field,value:`${o.name} -> ${d.field}`,...d})}:{label:o.name,value:o.name,...o}})}))}function m2(e){if(e.length===0)return[];const t=bc(e);return Object.entries(t).map(([a,l])=>({group:`${a}(${l.length})`,items:l.map(o=>({label:o.name,value:o.name,description:o.description,dataType:o.dataType??"dimension",dimension:o.dimension}))}))}function C2(e,t){if(!t)throw new Error("Shouldnt run query without ID");if(e==="derived")return`/api/metric_management/derived_metric/${t}`;if(e==="combined")return`/api/metric_management/combined_metric/${t}`;throw new Error(`Unexpected metric type[${e}]`)}const S2=g.types.model({data:g.types.optional(g.types.frozen(),null),filters:g.types.optional(g.types.frozen(),[]),groupBys:g.types.optional(g.types.frozen(),[]),trendingDateCol:g.types.optional(g.types.frozen(),null),supportTrending:g.types.optional(g.types.boolean,!1),requireTrendingReason:g.types.optional(g.types.string,""),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).volatile(()=>({controller:new AbortController})).views(e=>({get loading(){return e.state==="loading"},get hasData(){return e.data!==null},get mmInfo(){return g.getParent(e)},get metricID(){return this.mmInfo.metricID},get metric(){return this.mmInfo.metric},get metricType(){var t;return(t=this.metric)==null?void 0:t.type},get filterColOptions(){return w2(e.filters)},get groupByColOptions(){return m2(e.groupBys)},get flatGroupByColOptions(){const t=this.groupByColOptions,r=[];return t.forEach(({group:a,items:l})=>{r.push(...l)}),r},getGroupByOptions(t){const r=new Set(t);return this.flatGroupByColOptions.filter(a=>r.has(a.value))}})).actions(e=>({load:g.flow(function*(){var t;if(e.mmInfo.type===j.MericoMetricSystem&&!(!e.metricID||!e.metricType)){(t=e.controller)==null||t.abort(),e.controller=new AbortController,e.state="loading";try{const r=C2(e.metricType,e.metricID),a=rn(e.mmInfo.dataSource,{url:r,method:"GET",data:{key:e.mmInfo.key}}),l=yield*g.toGenerator(Ve.mericoMetricInfo(e.controller.signal)({key:e.mmInfo.key,query:JSON.stringify(a),...e.mmInfo.additionalQueryInfo},e.controller.signal)),o=an(e.mmInfo.dataSource,l),i=y.cloneDeep(o.data),{filters:c,groupBys:d,trendingDateCol:u,supportTrending:p,requireTrendingReason:f}=x2(o.data);e.data=i,e.filters=c,e.groupBys=d,e.supportTrending=p,e.requireTrendingReason=f,e.trendingDateCol=u,e.state="idle",e.error=null}catch(r){if(!Se.isCancel(r)){e.data=null;const a=y.get(r,"message","unkown error");e.error=y.get(r,"response.data.detail.message",a),e.state="error"}}}})})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>e.metricID+e.metricType,e.load,{fireImmediately:!0,delay:0}))}})),T2=g.types.model({keyword:g.types.optional(g.types.string,""),data:g.types.optional(g.types.frozen(),[]),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).volatile(()=>({controller:new AbortController})).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0},get mmInfo(){return g.getParent(e)}})).actions(e=>({setKeyword(t){e.keyword=t}})).actions(e=>({load:g.flow(function*(){var t;if(e.mmInfo.type===j.MericoMetricSystem){(t=e.controller)==null||t.abort(),e.controller=new AbortController,e.state="loading";try{const r=rn(e.mmInfo.dataSource,{url:"/api/metric_management/search",method:"POST",data:{key:e.mmInfo.key},params:{search:e.keyword}}),a=yield*g.toGenerator(Ve.mericoMetricInfo(e.controller.signal)({key:e.mmInfo.key,query:JSON.stringify(r),...e.mmInfo.additionalQueryInfo},e.controller.signal)),o=an(e.mmInfo.dataSource,a).data;e.data=o,e.state="idle",e.error=null}catch(r){if(!Se.isCancel(r)){e.data=[];const a=y.get(r,"message","unkown error");e.error=y.get(r,"response.data.detail.message",a),e.state="error"}}}})})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>`${e.mmInfo.type}:${e.keyword}`,e.load,{fireImmediately:!0,delay:0}))}})),k2=g.types.model({metrics:g.types.optional(T2,{}),metricDetail:g.types.optional(S2,{}),keyword:g.types.optional(g.types.string,""),metricID:g.types.optional(g.types.string,"")}).views(e=>({get rootModel(){return g.getRoot(e)},get contentModel(){return this.rootModel.content},get additionalQueryInfo(){return this.contentModel.getAdditionalQueryInfo("")},get dataSource(){return g.getParent(e)},get key(){return this.dataSource.key},get type(){return this.dataSource.type},get metric(){return e.metricID?e.metrics.data.find(t=>t.id===e.metricID)??null:null}})).actions(e=>({selectMetric(t){e.metricID=t}})),z2=g.types.compose("DataSourceModel",fa,g.types.model({dbInfo:g.types.optional(_2,{}),mericoMetricInfo:g.types.optional(k2,{})})),D2=g.types.model("DataSourcesModel",{list:g.types.optional(g.types.array(z2),[])}).views(e=>({find({type:t,key:r}){return e.list.find(a=>a.key===r&&a.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}}));function I2(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function M2(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function V2(e){return e.length===1&&e[0]==="_FILTERS_"}function P2(e){return e.length===2&&e[0]==="_FILTERS_"}function A2(e){return e.length===1&&e[0]==="_SQL_SNIPPETS_"}function $2(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function E2(e){return e.length===2&&e[0]==="_QUERIES_"}function B2(e){return e.length===1&&e[0]==="_QUERIES_"}function L2(e){return e.length===2&&e[0]==="_VIEWS_"}function Ba(e){return e.length===6&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}function Tt(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function q2(e){switch(e._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",e.value];case"sql_snippet":return["_SQL_SNIPPETS_",e.value];case"query":return["_QUERIES_",e.value];case"view":return["_VIEWS_",e.value];case"panel":return e.parentID?["_VIEWS_",e.parentID,"_PANELS_",e.value,"_TABS_","Data"]:(console.error("[getPathFromOption] parentID is required"),null)}}const O2=g.types.model("EditorModel",{path:g.types.optional(g.types.frozen(),[]),settings_open:g.types.optional(g.types.boolean,!1)}).views(e=>({get isPanelPath(){return Ba(e.path)},get panelTab(){return this.isPanelPath?y.get(e.path,5,"Data"):null},get navOptions(){const{content:t}=g.getRoot(e),{filters:r,views:a,sqlSnippets:l,queries:o}=t;return[{label:"query_variable.labels",value:"_QUERY_VARS_",_type:"query_variables",Icon:S.IconVariable},{label:"mock_context.label",value:"_MOCK_CONTEXT_",Icon:S.IconCodeDots,_type:"mock_context"},{label:"filter.labels",value:"_FILTERS_",Icon:S.IconFilter,children:[Tt("_FILTERS_SETTINGS_"),...r.options,Tt("_Add_A_Filter_")],_type:"GROUP"},{label:"sql_snippet.labels",value:"_SQL_SNIPPETS_",Icon:S.IconCopy,children:[Tt("_SQL_SNIPPETS_SETTINGS_"),...l.options,Tt("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"query.labels",value:"_QUERIES_",Icon:S.IconDatabase,children:[Tt("_QUERIES_SETTINGS_"),...o.options,Tt("_Add_A_QUERY_")],_type:"GROUP"},{label:"view.labels",value:"_VIEWS_",Icon:S.IconBoxMultiple,children:[...a.editorOptions,Tt("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(t,r){return t.length===0?!1:Ba(t)?t[3]===r.value:t[t.length-1]===r.value},isOptionOpened(t){const{path:r}=e;return r.length===0||!t.children||t.children.length===0?!1:r.includes(t.value)}})).actions(e=>({setPath(t){e.path=t},setSettingsOpen(t){e.settings_open=t},openAndSetPath(t){this.setPath(t),e.settings_open||(e.settings_open=!0)}})).actions(e=>({setPanelTab(t){if(!e.isPanelPath||e.panelTab===t||!t)return;const r=y.clone(e.path);r[5]=t,e.setPath(r)},open(t){e.setPath(t),e.setSettingsOpen(!0)},close(){e.setSettingsOpen(!1)},navigate(t){const r=q2(t);r&&e.setPath(r)}})).views(e=>({get spotlightActionGroups(){const{content:t}=g.getRoot(e),{filters:r,views:a,sqlSnippets:l,queries:o}=t,i={group:"spotlight.main_group",actions:[{id:"query_variable.labels",title:"query_variable.labels",onClick:()=>e.openAndSetPath(["_QUERY_VARS_"]),iconKey:"query_variables"},{id:"mock_context.label",title:"mock_context.label",onClick:()=>e.openAndSetPath(["_MOCK_CONTEXT_"]),iconKey:"mock_context"},{id:"filter.labels",title:"filter.labels",onClick:()=>e.openAndSetPath(["_FILTERS_"]),iconKey:"filter"},{id:"sql_snippet.labels",title:"sql_snippet.labels",onClick:()=>e.openAndSetPath(["_SQL_SNIPPETS_"]),iconKey:"sql_snippet"},{id:"query.labels",title:"query.labels",onClick:()=>e.openAndSetPath(["_QUERIES_"]),iconKey:"query"}]},c={group:"filter.labels",actions:[]};r.options.forEach(f=>{c.actions.push({id:`_FILTERS_.${f.value}`,title:f.label,onClick:()=>e.openAndSetPath(["_FILTERS_",f.value]),iconKey:"filter"})});const d={group:"sql_snippet.labels",actions:[]};l.options.forEach(f=>{d.actions.push({id:`_SQL_SNIPPETS_.${f.value}`,title:f.label,onClick:()=>e.openAndSetPath(["_SQL_SNIPPETS_",f.value]),iconKey:"sql_snippet"})});const u={group:"query.labels",actions:[]};o.options.forEach(f=>{u.actions.push({id:`_QUERIES_.${f.value}`,title:f.label,onClick:()=>e.openAndSetPath(["_QUERIES_",f.value]),iconKey:"query"})});const p=[i,c,d,u];return a.editorOptions.forEach(f=>{const v={group:f.label,actions:[]};v.actions.push({id:`_VIEWS_.${f.value}`,title:f.label,onClick:()=>e.openAndSetPath(["_VIEWS_",f.value]),iconKey:"view",group:f.label}),f.children.forEach(_=>{_._type!=="ACTION"&&v.actions.push({id:`_VIEWS_._PANELS_.${_.value}`,title:_.label,viz:_.viz,onClick:()=>e.openAndSetPath(["_VIEWS_",f.value,"_PANELS_",_.value,"_TABS_","Panel"]),iconKey:"panel",group:f.label})}),p.push(v)}),p}})),N2=g.types.compose("LayoutsModel",za,g.types.model({currentLayoutWrapperWidth:g.types.optional(g.types.number,0)})).views(e=>({get divisionPreviewScale(){const t=e.currentLayoutPreviewWidth,r=e.currentLayoutWrapperWidth;return!t||!r||t<=r?1:r/t}})).actions(e=>({addALayoutItem(t){e.list.forEach(r=>{r.addNewLayout(t)})},duplicateLayoutItemsByPanelID(t,r){e.list.forEach(a=>{const l=a.findByPanelID(t);if(!l){console.error(`Can't find a layout item by panelID[${t}] in layoutSet[${a.name}]`);return}a.list.push({...l,id:Ue.v4(),panelID:r,y:1/0})})},removeByPanelID(t){e.list.forEach(r=>{r.removeByPanelID(t)})},removeByPanelIDs(t){e.list.forEach(r=>{r.removeByPanelIDs(t)})},setCurrentLayoutWrapperWidth(t){e.currentLayoutWrapperWidth=t},addALayoutSet(t,r,a){const l=e.basisLayoutSet,o={id:t,name:r,breakpoint:a,list:l.json.list.map(i=>({...i,id:Ue.v4()}))};e.list.push(o)},updateLayoutSetsInfo(t){const r=y.keyBy(e.list,"id");t.forEach(o=>{const i=r[o.id];if(i){i.setName(o.name),i.setBreakpoint(o.breakpoint),delete r[o.id];return}this.addALayoutSet(o.id,o.name,o.breakpoint)});const a=new Set(Object.keys(r)),l=a.size>0;a.forEach(o=>{const i=e.list.findIndex(c=>c.id===o);e.list.splice(i,1)}),l&&e.setCurrentBreakpoint("basis")},updateCurrentLayoutItem(t){e.currentLayoutSet.updateLayoutItem(t)},updateCurrentLayoutItems(t){t.forEach(r=>{e.currentLayoutSet.updateLayoutItem(r)})},append(t){e.list.push(t)},appendMultiple(t){t.length!==0&&e.list.push(...t)},remove(t){e.list.splice(t,1)},removeByID(t){const r=e.list.findIndex(a=>a.id===t);r!==-1&&e.list.splice(r,1)},removeByIDs(t){t.forEach(r=>{this.removeByID(r)})}})),yc=xa.views(e=>({get realDataFieldOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>{const r=t.data;return r.length===0?[]:Object.keys(r[0]).map(l=>({label:l,value:`${t.id}.${l}`,group:t.name,group_id:t.id,disabled:!1}))}).flat()},get realQueryOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>({label:t.name,value:t.id,disabled:!1}))},queryOptions(t,r){const a=[...this.realQueryOptions];return t&&!a.find(l=>l.value===t)&&a.unshift({label:t,value:t,disabled:!0}),r&&a.unshift({label:"unset",value:"",disabled:!1}),a},get realVariableOptions(){const t=e.variableValueMap;return Object.entries(e.variableAggValueMap).map(([r,a])=>({label:r,value:r,formattedValue:t[r],aggValue:a,disabled:!1}))},variableOptions(t,r){const a=[...this.realVariableOptions];return t&&!a.find(l=>l.value===t)&&a.unshift({label:t,value:t,formattedValue:"",aggValue:"",disabled:!0}),r&&a.unshift({label:"unset",value:"",formattedValue:"",aggValue:"",disabled:!1}),a},dataFieldOptions(t,r,a){let l=[...this.realDataFieldOptions];if(a&&(l=l.filter(o=>o.group_id===a)),t&&!l.find(o=>o.value===t)){const o=P(t),i=e.queryByID(o.queryID);l.unshift({label:o.columnKey,value:t,group:i?i.name:o.queryID,group_id:i?i.id:"",disabled:!0})}return r&&l.unshift({label:"unset",value:"",group:"",group_id:"",disabled:!1}),l},dataFieldOptionGroups(t,r,a){const l=this.dataFieldOptions(t,r,a);return Object.entries(y.groupBy(l,"group")).map(([i,c])=>({group:i,items:c.map(d=>({label:d.label,value:d.value,group_id:d.group_id,disabled:d.disabled}))}))},explainDataKey(t){const{queryID:r,columnKey:a}=P(t),l=e.queries.find(o=>o.id===r);return l?{queryID:r,queryName:l.name,columnKey:a}:{queryID:r,queryName:null,columnKey:a}}})).actions(e=>({removeSelf(){g.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,r){g.getRoot(e).content.views.findByID(t).removePanelID(e.id),g.getRoot(e).content.views.findByID(r).appendPanelID(e.id),g.getRoot(e).editor.setPath(["_VIEWS_",r,"_PANELS_",e.id])}})),vc=g.types.compose("PanelsModel",wa,g.types.model({list:g.types.optional(g.types.array(yc),[])})).views(e=>({get contentModel(){return g.getRoot(e).content},get options(){return e.list.map(t=>({label:t.name,value:t.id,viz_type:t.viz.type}))},editorOptions(t,r){const a=e.panelsByIDs(r);a.length!==r.length&&console.warn(`Unfulfilled panels for View[${t}]`);const l=a.map(i=>({label:i.name,value:i.id,_type:"panel",parentID:t,viz:Io[i.viz.type]})),o="_Add_A_PANEL_";return l.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:t,Icon:null,children:null}),l}})).actions(e=>({replace(t){e.list=g.castToSnapshot(t)},append(t){e.list.push(t)},appendMultiple(t){t.length!==0&&e.list.push(...t)},remove(t){e.list.splice(t,1)},removeByID(t){const r=e.list.findIndex(a=>a.id===t);r!==-1&&e.list.splice(r,1)},removeByIDs(t){t.forEach(r=>{this.removeByID(r)})},duplicateByID(t){const r=e.list.find(l=>l.id===t);if(!r){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}const a=new Date().getTime().toString();return e.list.push({...r.json,id:a,title:{...r.json.title}}),e.contentModel.layouts.duplicateLayoutItemsByPanelID(r.id,a),a},replaceByIndex(t,r){e.list.splice(t,1,r)}})),G2=va.actions(e=>({getSchema(){const t=e.json,r=[],a=[];e.panels.forEach(i=>{const c=i.getSchema();r.push(c.panel),c.queries.length>0&&a.push(...c.queries)});const l=e.contentModel.layouts.jsonByPanelIDSet(new Set(e.panelIDs));return{views:[t],panels:r,definition:{queries:y.uniqBy(a,i=>i.id)},layouts:l,version:at}},downloadSchema(){if(e.type===$.Tabs){console.error(new Error("Please choose a tab first"));return}const t=JSON.stringify(this.getSchema(),null,2),r=e.name;Bt(r,t)}})),_c=g.types.compose("ViewsModel",_a,g.types.model({current:g.types.optional(g.types.array(G2),[]),idOfVIE:g.types.string})).views(e=>({get isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))},get tabViewOptions(){return this.options.filter(t=>t.type===$.Tabs)},tabOptions(t){const r=e.current.find(a=>a.id===t&&a.type===$.Tabs&&a.tabs.length>0);return r?r.tabs.map(a=>({label:a.name,value:a.id})):[]},get editorOptions(){const t=g.getRoot(e).content.panels;return e.current.map(r=>({label:r.name,value:r.id,_type:"view",children:t.editorOptions(r.id,r.panelIDs)}))},get contentModel(){return g.getRoot(e).content}})).actions(e=>({setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},resetIDOfVIE(){this.setIDOfVIE(e.current[0].id)},replace(t){e.current.replace(t)},addANewView(t,r,a,l){e.current.push({id:t,name:r,type:a,config:l,panelIDs:[]})},append(t){e.current.push(t)},appendMultiple(t){t.length!==0&&e.current.push(...t)},remove(t){e.current.splice(t,1)},removeByID(t){const r=e.current.findIndex(i=>i.id===t);if(r===-1)return;const a=e.current[r],l=e.contentModel.panels,o=e.contentModel.layouts;l.removeByIDs(a.panelIDs),o.removeByPanelIDs(a.panelIDs),e.current.splice(r,1),this.resetIDOfVIE()},replaceByIndex(t,r){e.current.splice(t,1,r)},addARandomNewView(){const t=new Date().getTime().toString();this.addANewView(t,$.Division,$.Division,{_name:$.Division}),this.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(this.removeByID(e.idOfVIE),this.resetIDOfVIE())}}));function La(e){const t=e.length>0?[e[0].id]:[],r=e.length>0?e[0].id:"";return{current:e.map(l=>{const{_name:o=l.type}=l.config;return{...l,config:{...l.config,_name:o},panelIDs:l.panelIDs}}),visibleViewIDs:t,idOfVIE:r}}const F2=g.types.model({id:g.types.string,name:g.types.string,dashboard_id:g.types.string,create_time:g.types.string,update_time:g.types.string,version:g.types.string,filters:cc,queries:uc,sqlSnippets:pc,views:_c,panels:vc,layouts:N2,mock_context:Jr,origin:g.types.maybe(g.types.frozen())}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,layouts:e.layouts.json,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get contentJSON(){return this.json.content},get filtersChanged(){const t="filters.current";return!y.isEqual(g.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get queriesChanged(){const t="queries.current",r=g.getSnapshot(y.get(e,t)).map(l=>y.pick(l,["id","name","key","type","run_by","pre_process","post_process","config"])),a=y.get(e.origin,t);return!y.isEqual(r,a)},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!y.isEqual(g.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get viewsChanged(){const t="views.current";return!y.isEqual(e.views.json,y.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!y.isEqual(g.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get layoutsChanged(){const t="layouts.list";return!y.isEqual(g.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!y.isEqual(y.get(e,t),y.get(e.origin,t))},get context(){const t=g.getParent(e).context.current;return{...e.mock_context.current,...t}},get payloadForSQL(){const t=g.getParent(e).globalSQLSnippets,r={context:this.context,filters:e.filters.valuesForPayload};return{...r,sql_snippets:Ut(e.sqlSnippets.current,"key","value",r),global_sql_snippets:Ut(t.list,"id","content",r)}},get payloadForViz(){return{context:this.context,filters:e.filters.valuesForPayload}},get dashboardState(){const{context:t,filters:r}=this.payloadForViz,a={context:{},filters:e.filters.keyStateItemMap(r)};return Object.entries(t).forEach(([l,o])=>{a.context[l]={key:l,type:"context",value:o}}),a},get dashboardStateValues(){return lr(this.payloadForSQL)},get dashboardStateVariableOptions(){if(!g.isAlive(e))return{optionGroups:[],validValues:new Set};const t=new Set,{context:r}=this.payloadForSQL,a={group:"context.label",items:Object.keys(r).map(i=>{const c=`context.${i}`;return t.add(c),{label:i,value:c,description:void 0,type:"context"}})},l={group:"filter.labels",items:e.filters.keyLabelOptions.map(i=>{const c=`filters.${i.value}`;return t.add(c),{label:i.label,value:c,description:i.value,type:"filter",widget:i.widget}})};return{optionGroups:[a,l],validValues:t}},getAdditionalQueryInfo(t){return{content_id:e.id,query_id:t,params:this.dashboardStateValues}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.layoutsChanged||this.mockContextChanged},get data(){return e.queries.current.map(({id:r,data:a})=>({id:r,data:a})).reduce((r,a)=>(r[a.id]=a.data,r),{})},getDataStuffByID(t){const r=e.queries.findByID(t);return r?{data:r.data,len:r.data.length,state:r.state,error:r.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(e=>({get filtersUsage(){const t=[],r=e.views.idMap;e.filters.current.forEach(l=>{l.visibleInViewsIDs.forEach(o=>{var i;t.push({filterID:l.id,type:"view",type_label:"view.label",id:o,label:((i=r.get(o))==null?void 0:i.name)??o})})});const a=e.filters.keyIDMap;return e.queries.current.forEach(l=>{l.usedFilterKeySet.forEach(o=>{t.push({filterID:a[o]??o,type:"query",type_label:"query.label",id:l.id,label:l.name})})}),e.sqlSnippets.usedFilterKeyMap.forEach((l,o)=>{l.forEach(i=>{t.push({filterID:a[i]??i,type:"sql_snippet",type_label:"sql_snippet.label",id:o,label:o})})}),y.groupBy(t,"filterID")},findFilterUsage(t){return this.filtersUsage[t]??[]},get queriesUsage(){const t=e.panels.idMap,r=[];e.views.current.forEach(l=>{l.panelIDs.forEach(o=>{const i=t.get(o);if(!i)return;const c="panel",d=i.name,u=[{id:l.id,label:l.name}];i.queryIDs.forEach(p=>{r.push({id:o,queryID:p,type:c,type_label:"panel.label",label:d,views:u})})})});const a=e.views.idMap;return e.filters.current.filter(l=>!!y.get(l,"config.options_query_id")).forEach(l=>{r.push({type:"filter",type_label:"filter.label",id:l.id,queryID:y.get(l,"config.options_query_id"),label:l.label,views:l.visibleInViewsIDs.map(o=>{var i;return{id:o,label:((i=a.get(o))==null?void 0:i.name)??o}})})}),e.queries.current.forEach(l=>{if(!l.isTransform)return;l.config.dep_query_ids.forEach(i=>{r.push({type:"transform-query",type_label:"query.transform.full_label",id:l.id,queryID:i,label:l.name,views:[]})})}),y.groupBy(r,"queryID")},get hasUnusedQueries(){return e.queries.current.length>Object.keys(this.queriesUsage).length},findQueryUsage(t){return this.queriesUsage[t]??[]},get sqlSnippetsUsage(){const t=[];return e.queries.current.forEach(r=>{if(!r.typedAsSQL)return;const a=r.config;y.uniq(a.sql.match(Mt.sqlSnippet)).forEach(o=>{t.push({queryID:r.id,sqlSnippetKey:o,queryName:r.name})})}),y.groupBy(t,"sqlSnippetKey")},get hasUnusedSQLSnippets(){return e.sqlSnippets.current.length>Object.keys(this.sqlSnippetsUsage).length},findSQLSnippetUsage(t){return this.sqlSnippetsUsage[t]??[]}})).actions(e=>({removeUnusedQueries(){const t=new Set(Object.keys(e.queriesUsage)),r=e.queries.current.filter(a=>!t.has(a.id)).map(a=>a.id);e.queries.removeQueries(r)},removeUnusedSQLSnippets(){const t=new Set(Object.keys(e.sqlSnippetsUsage)),r=e.sqlSnippets.current.filter(a=>!t.has(a.key)).map(a=>a.key);e.sqlSnippets.removeByKeys(r)},duplicatePanelByID(t,r){var l;const a=e.panels.duplicateByID(t);a&&((l=e.views.findByID(r))==null||l.appendPanelID(a))},removePanelByID(t,r){var a;e.panels.removeByID(t),e.layouts.removeByPanelID(t),(a=e.views.findByID(r))==null||a.removePanelID(t)},addANewPanel(t){var a;const r=Ue.v4();e.panels.append(Ci(r)),(a=e.views.findByID(t))==null||a.appendPanelID(r),e.layouts.addALayoutItem(r)},applyJSONSchema(t){var f;const{views:r,panels:a,filters:l,definition:o={},layouts:i}=t,{queries:c,sqlSnippets:d,mock_context:u}=o,p=new Map;if(Array.isArray(a)){const v=a.map(_=>{const w=Ue.v4();return p.set(_.id,w),{..._,id:w}});if(e.panels.appendMultiple(v),!Array.isArray(r)||r.length===0){const _=v.map(w=>w.id);(f=e.views.VIE)==null||f.appendPanelIDs(_)}}if(Array.isArray(r)){const v=r.map(_=>{const w=_.panelIDs.map(m=>p.get(m)??m);return{..._,id:Ue.v4(),panelIDs:w}});e.views.appendMultiple(v)}if(Array.isArray(i)){const v=(m,k)=>e.layouts.breakpointNameRecord[m]===k;let _=[];const w=i.filter(m=>v(m.name,m.breakpoint));w.forEach(m=>{m.id==="basis"&&(_=m.list),m.list.forEach(k=>{const z=p.get(k.panelID);k.id=Ue.v4(),k.panelID=z})}),e.layouts.list.forEach(m=>{const k=w.find(z=>z.name===m.name&&z.breakpoint===m.breakpoint);if(!k){_.forEach(z=>{m.addLayout(z)});return}k.list.forEach(z=>{m.addLayout(z)})})}Array.isArray(l)&&e.filters.appendMultiple(l),Array.isArray(c)&&e.queries.appendMultiple(c),Array.isArray(d)&&e.sqlSnippets.appendMultiple(d),u&&Object.keys(u).length>0&&e.mock_context.defaults(u)}})).actions(e=>({reset(){g.applySnapshot(e.filters.current,e.origin.filters.current),g.applySnapshot(e.queries.current,e.origin.queries.current),g.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),g.applySnapshot(e.views.current,e.origin.views.current),g.applySnapshot(e.panels.list,e.origin.panels.list),g.applySnapshot(e.layouts.list,e.origin.layouts.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){g.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:r,name:a,content:l}=t;if(!l)throw new Error("unexpected null content when updating a content model");const{version:o,filters:i,views:c,panels:d,definition:{queries:u,sqlSnippets:p,mock_context:f={}}}=l;e.id=r,e.name=a,e.version=o,g.applySnapshot(e.filters.current,i),g.applySnapshot(e.views.current,La(c).current),g.applySnapshot(e.panels.list,d),g.applySnapshot(e.queries.current,u),g.applySnapshot(e.sqlSnippets.current,p),e.mock_context.current=f}})),qa=g.types.snapshotProcessor(F2,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=g.castToSnapshot(e.queries.current.map(r=>y.pick(r,["id","key","type","sql"])));return y.defaults({},{queries:{current:t}},e)}});function j2(e,t){t.filters&&g.applySnapshot(e.filters.current,t.filters)}function xc({id:e,name:t,dashboard_id:r,create_time:a,update_time:l,content:o},i,c){if(!o)throw new Error("unexpected null content when creating a content model");const{version:d,filters:u,views:p,panels:f,layouts:v,definition:{queries:_,sqlSnippets:w,mock_context:m={}}}=o;return qa.create({id:e,name:t,dashboard_id:r,create_time:a,update_time:l,version:d,filters:Ca(u,i,m,c),queries:{current:_},sqlSnippets:{current:w},mock_context:Hr(m),views:La(p),panels:{list:f},layouts:{list:v,currentBreakpoint:v[0].id}})}const wc=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:qa,content_id:g.types.string,datasources:D2,globalSQLSnippets:ba,context:kn,editor:O2}).views(e=>({get json(){return{id:e.id,name:e.name,group:e.group,content_id:e.content_id}},get queryVariables(){return{context:{...e.content.mock_context.current,...e.context.current},filters:e.content.filters.previewValues}},get queryVariablesString(){return JSON.stringify(this.queryVariables,null,2)}})).actions(e=>({updateCurrentContent(t){e.content.updateCurrent(t)},updateCurrent(t,r){const{id:a,name:l,group:o,content_id:i}=t;e.id=a,e.name=l,e.group=o,e.content_id=i,this.updateCurrentContent(r)}}));function mc({id:e,name:t,group:r,content_id:a},l,o,i,c,d){return wc.create({id:e,name:t,group:r,content_id:a,content:xc(l,c,d),datasources:{list:o},globalSQLSnippets:{list:i},context:ya(c),editor:{}})}function Lt(e){console.groupCollapsed("Running operation ",e.type),console.log(e),console.groupEnd()}function Cc(e,t){h.useEffect(()=>{const a=l=>{Lt(l);const{viewID:o}=l.detail;if(!o){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(o),t&&e.views.setIDOfVIE(o)};return window.addEventListener("open-view",a),()=>{window.removeEventListener("open-view",a)}},[e,t]);const r=Yd.useNavigate();h.useEffect(()=>{const a=l=>{Lt(l);const{panelID:o}=l.detail;if(!o){console.error(new Error("[Scroll to Panel] Needs to pick a panel first"));return}r(`#${o}`),setTimeout(()=>{const i=document.getElementById(o);i&&i.scrollIntoView({behavior:"smooth"})},300)};return window.addEventListener("scroll_to_panel",a),()=>{window.removeEventListener("scroll_to_panel",a)}},[r]),h.useEffect(()=>{const a=l=>{Lt(l);const{viewID:o,tab:i}=l.detail;if(!o){console.error(new Error("[Switch Tab] Needs to pick a view and a tab first"));return}const c=e.views.findByID(o);if(!c){console.error(new Error(`[Switch Tab] View by ID[${o}] is not found`));return}c.setTab(i)};return window.addEventListener("switch_tab",a),()=>{window.removeEventListener("switch_tab",a)}},[e,t]),h.useEffect(()=>{const a=l=>{Lt(l);const{dictionary:o,payload:i}=l.detail;if(!i||Object.keys(i).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}const c={};Object.entries(o).forEach(([d,u])=>{const p=y.get(i,u);c[d]=p}),e.filters.applyValuesPatch(c)};return window.addEventListener("set-filter-values",a),()=>{window.removeEventListener("set-filter-values",a)}},[e]),h.useEffect(()=>{function a(o){return Array.isArray(o)?[]:typeof o=="object"?{}:typeof o=="boolean"?!1:typeof o=="string"?"":typeof o=="number"?0:o}const l=o=>{Lt(o);const i={},{filter_keys:c}=o.detail;c.forEach(d=>{const u=y.get(e.filters.values,d),p=a(u);i[d]=p}),e.filters.applyValuesPatch(i)};return window.addEventListener("clear-filter-values",l),()=>{window.removeEventListener("clear-filter-values",l)}},[e]),h.useEffect(()=>{const a=l=>{Lt(l);const{urlTemplate:o,openInNewTab:i,enableEncoding:c=!1,payload:d}=l.detail;if(!o){console.error(new Error("[Open Link] URL is empty"));return}function u(v){return y.cloneDeepWith(v,w=>{if(c&&typeof w=="string")return encodeURIComponent(w)})}const f=y.template(o||"")(u({...d,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}));window.open(f,i?"_blank":"_self","noopener")};return window.addEventListener("open-link",a),()=>{window.removeEventListener("open-link",a)}},[e])}function Sc(e){return h.useCallback(t=>t.provideValue(R.pluginManager,e.pluginManager).provideValue(R.vizManager,e.vizManager).provideValue(R.panelAddonManager,e.panelAddonManager).provideValue(R.colorManager,e.colorManager),[e])}const W5="",Q2=T.observer(({saveDashboardChanges:e})=>{const{t}=x.useTranslation(),r=Te.useModals(),a=F(),l=()=>{r.openConfirmModal({title:n.jsxs(s.Group,{justify:"flex-start",children:[n.jsx(S.IconAlertTriangle,{size:18,color:"red"}),n.jsx(s.Text,{size:"sm",children:"You are reverting changes"})]}),labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>a.reset(),zIndex:320,withCloseButton:!1})},o=a.changed;return n.jsxs(s.Group,{gap:0,children:[n.jsx(s.Button,{color:"green",variant:"filled",size:"xs",leftSection:n.jsx(S.IconDeviceFloppy,{size:18}),onClick:e,disabled:!o,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:t("common.actions.save_changes")}),n.jsxs(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!o,children:[n.jsx(s.Menu.Target,{children:n.jsx(s.ActionIcon,{variant:"default",disabled:!o,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:n.jsx(S.IconCaretDown,{size:18})})}),n.jsx(s.Menu.Dropdown,{children:n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconRecycle,{size:14,color:"red"}),disabled:!o,onClick:l,children:t("common.actions.revert_changes")})})]})]})}),W2=T.observer(({saveDashboardChanges:e,onExit:t,headerSlot:r=null})=>{x.useTranslation();const a=W(),l=a.content.changed,o=()=>{t({hasChanges:l,dashboardId:a.id})};return n.jsx(s.AppShell.Header,{h:60,py:0,px:"md",sx:{zIndex:299},children:n.jsxs(s.Group,{justify:"space-between",sx:{height:60,minWidth:"1000px",position:"relative"},children:[n.jsxs(s.Group,{children:[n.jsx(s.Button,{size:"xs",color:l?"red":"green",leftSection:n.jsx(S.IconArrowLeft,{size:20}),onClick:o,children:n.jsx(s.Group,{gap:4,children:n.jsx(x.Trans,{i18nKey:"common.actions.end_editing",values:{name:a.name},children:n.jsx(s.Text,{td:"underline",size:"xs",children:a.name})})})}),n.jsx(Q2,{saveDashboardChanges:e})]}),n.jsx(s.Group,{justify:"flex-end",sx:{flexGrow:1},children:r})]})})}),Tc={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},U2=T.observer(()=>{var l;const{t:e}=x.useTranslation(),t=F(),r=((l=t.views.VIE)==null?void 0:l.type)===$.Tabs,a=()=>t.addANewPanel(t.views.idOfVIE);return r?n.jsx(s.Tooltip,{label:e("common.choose_a_tab_first"),children:n.jsx(s.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),sx:{...Tc,transform:"none !important"},children:e("panel.add")})}):n.jsx(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:a,leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),sx:{...Tc,background:"rgb(231, 245, 255)"},children:e("panel.add")})}),K2=T.observer(({done:e})=>{var E,K;const{t}=x.useTranslation(),a=F().layouts,l=h.useMemo(()=>({list:a.breakpointsInfo}),[a.breakpointsInfo]),{control:o,handleSubmit:i,watch:c,getValues:d,reset:u,formState:p}=b.useForm({defaultValues:l}),{fields:f,append:v,remove:_}=b.useFieldArray({control:o,name:"list",rules:{validate:N=>{if(y.uniqBy(N,"breakpoint").length!==N.length)return"Screen sizes should be unique by min width"}}}),w=c("list"),m=f.map((N,le)=>({...N,...w[le]})),k=()=>{v({id:Ue.v4(),name:"",breakpoint:""})},z=({list:N})=>{const le=N.filter(xe=>Number.isFinite(xe.breakpoint));a.updateLayoutSetsInfo(le),e()},D=d(),I=h.useMemo(()=>{const N={list:D.list.filter(le=>!!le.name&&Number.isFinite(le.breakpoint))};return!y.isEqual(N,l)},[D,l]),L=(K=(E=p.errors.list)==null?void 0:E.root)==null?void 0:K.message;return n.jsx(n.Fragment,{children:n.jsxs("form",{onSubmit:i(z),children:[n.jsxs(s.Table,{fz:"sm",highlightOnHover:!0,withTableBorder:!0,sx:{tableLayout:"fixed"},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"340px"},children:t("common.name")}),n.jsx(s.Table.Th,{style:{width:"160px"},children:t("breakpoint.breakpoint")}),n.jsx(s.Table.Th,{})]})}),n.jsxs(s.Table.Tbody,{children:[m.map((N,le)=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:N.id==="basis"?N.name:n.jsx(b.Controller,{name:`list.${le}.name`,control:o,render:({field:xe})=>n.jsx(s.TextInput,{size:"xs",label:"",required:!0,sx:{flex:1},...xe})})}),n.jsx(s.Table.Td,{children:N.id==="basis"?n.jsxs(s.Text,{size:"sm",ff:"monospace",children:[N.breakpoint,"px"]}):n.jsx(b.Controller,{name:`list.${le}.breakpoint`,control:o,render:({field:xe})=>n.jsx(s.NumberInput,{size:"xs",label:"",required:!0,max:1e4,hideControls:!0,rightSection:n.jsx(s.Text,{size:"sm",c:"dimmed",children:"px"}),rightSectionProps:{style:{width:"30px"}},sx:{flex:1},ff:"monospace",styles:{input:{paddingRight:"30px"}},...xe})})}),n.jsx(s.Table.Td,{children:N.id!=="basis"&&n.jsx(s.ActionIcon,{mx:"auto",size:"xs",variant:"subtle",color:"red",onClick:()=>_(le),children:n.jsx(S.IconTrash,{})})})]},N.id)),n.jsx(s.Table.Tr,{style:{backgroundColor:"transparent"},children:n.jsx(s.Table.Td,{colSpan:3,style:{padding:"0"},children:n.jsx(s.Tooltip,{label:t("breakpoint.add"),children:n.jsx(s.ActionIcon,{variant:"subtle",size:"md",color:"blue",onClick:k,sx:{width:"100%"},children:n.jsx(S.IconPlus,{size:18})})})})})]})]}),n.jsx(s.Text,{mt:6,ta:"right",size:"xs",c:"red",children:L??" "}),n.jsxs(s.Group,{mt:6,justify:"space-between",children:[n.jsx(s.Button,{color:"orange",size:"xs",onClick:()=>u(),leftSection:n.jsx(S.IconRecycle,{size:18}),disabled:!I,children:t("common.actions.revert")}),n.jsx(s.Button,{color:"green",size:"xs",type:"submit",leftSection:n.jsx(S.IconDeviceFloppy,{size:18}),disabled:!I,children:t("common.actions.save_changes")})]})]})})}),Y2=T.observer(()=>{const{t:e}=x.useTranslation(),[t,{open:r,close:a}]=ne.useDisclosure(!1),l=F(),o=l.layouts.currentBreakpoint,i=l.layouts.currentLayoutRange,c=()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},d=()=>{a(),c()};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{children:[n.jsxs(s.Menu,{withArrow:!0,withinPortal:!0,zIndex:320,trigger:"hover",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Button,{size:"xs",variant:"subtle",leftSection:n.jsx(S.IconDevices,{size:16}),sx:{borderRadius:0},children:n.jsxs(s.Group,{gap:6,children:[n.jsx(s.Text,{size:"xs",fw:"normal",children:i.name}),n.jsx(s.Text,{size:"xs",c:"#777",children:l.layouts.currentRangeText})]})})}),n.jsxs(s.Menu.Dropdown,{children:[l.layouts.breakpointRanges.map(u=>n.jsx(s.Menu.Item,{onClick:()=>l.layouts.setCurrentBreakpoint(u.id),disabled:o===u.id,children:n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Text,{size:"sm",children:u.name}),n.jsx(s.Text,{size:"xs",c:"dimmed",children:u.text})]})},u.id)),n.jsx(s.Menu.Divider,{}),n.jsx(s.Menu.Item,{color:"blue",leftSection:n.jsx(S.IconSettings,{size:14}),onClick:r,children:n.jsx(s.Text,{size:"sm",children:e("breakpoint.manage")})})]})]}),l.layouts.divisionPreviewScale<1&&n.jsx(s.Text,{size:"xs",c:"dimmed",children:We(l.layouts.divisionPreviewScale).format({output:"percent",mantissa:0})})]}),n.jsx(s.Modal,{opened:t,onClose:d,title:e("breakpoint.label",{count:2}),withinPortal:!0,zIndex:320,size:600,closeOnClickOutside:!1,children:n.jsx(K2,{done:d})})]})}),kc={height:"30px",borderRight:"none",borderTop:"none",borderLeft:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},X2=T.observer(()=>{var l;const{t:e}=x.useTranslation(),t=F(),r=((l=t.views.VIE)==null?void 0:l.type)===$.Tabs,a=()=>{var o;return(o=t.views.VIE)==null?void 0:o.downloadSchema()};return r?n.jsx(s.Tooltip,{label:e("common.choose_a_tab_first"),children:n.jsx(s.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftSection:n.jsx(S.IconCode,{size:16}),sx:{...kc,transform:"none !important"},children:e("view.download_schema")})}):n.jsx(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:a,leftSection:n.jsx(S.IconCode,{size:16}),sx:{...kc},children:e("view.download_schema")})}),Mn=({headers:e,rows:t})=>n.jsxs(s.Table,{fz:"xs",highlightOnHover:!0,sx:{tableLayout:"fixed",fontFamily:"monospace"},children:[n.jsx(s.Table.Thead,{children:e}),n.jsx(s.Table.Tbody,{children:t})]}),Z2=({content:e})=>{const{t}=x.useTranslation(),r=e.views;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("view.labels")}),n.jsx(Mn,{headers:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"160px"},children:t("common.id")}),n.jsx(s.Table.Th,{children:t("common.name")}),n.jsx(s.Table.Th,{children:t("common.type")})]}),rows:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.id}),n.jsx(s.Table.Td,{children:a.name}),n.jsx(s.Table.Td,{children:t(`view.component.${a.type}.label`)})]},a.id))})]})},J2=({content:e})=>{const{t}=x.useTranslation(),r=e.filters;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("filter.labels")}),n.jsx(Mn,{headers:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"160px"},children:t("common.id")}),n.jsx(s.Table.Th,{children:t("common.key")}),n.jsx(s.Table.Th,{children:t("common.label")})]}),rows:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.id}),n.jsx(s.Table.Td,{children:a.key}),n.jsx(s.Table.Td,{children:a.label})]},a.id))})]})},H2=({content:e})=>{const{t}=x.useTranslation(),r=e.panels;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("panel.labels")}),n.jsx(Mn,{headers:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"160px"},children:t("common.id")}),n.jsx(s.Table.Th,{children:t("common.name")}),n.jsx(s.Table.Th,{children:t("visualization.component")})]}),rows:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.id}),n.jsx(s.Table.Td,{children:a.name}),n.jsx(s.Table.Td,{children:a.viz.type})]},a.id))})]})},R2=({content:e})=>{var a;const{t}=x.useTranslation(),r=(a=e.definition)==null?void 0:a.queries;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("query.labels")}),n.jsx(Mn,{headers:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"160px"},children:t("common.id")}),n.jsx(s.Table.Th,{children:t("common.name")}),n.jsx(s.Table.Th,{style:{width:"140px"},children:t("common.type")}),n.jsx(s.Table.Th,{style:{width:"260px"},children:t("data_source.label")})]}),rows:r.map(l=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:l.id}),n.jsx(s.Table.Td,{children:l.name}),n.jsx(s.Table.Td,{children:l.type}),n.jsx(s.Table.Td,{children:l.key})]},l.id))})]})},ek=({content:e})=>{var a;const{t}=x.useTranslation(),r=(a=e.definition)==null?void 0:a.sqlSnippets;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("sql_snippet.labels")}),n.jsx(s.List,{size:"sm",pl:10,ff:"monospace",icon:n.jsx(S.IconPointFilled,{size:10}),children:r.map(l=>n.jsx(s.List.Item,{children:l.key},l.key))})]})},tk=({content:e})=>{var a;const{t}=x.useTranslation(),r=Object.keys(((a=e.definition)==null?void 0:a.mock_context)??{});return r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("mock_context.label")}),n.jsx(s.List,{size:"sm",pl:10,ff:"monospace",icon:n.jsx(S.IconPointFilled,{size:10}),children:r.map(l=>n.jsx(s.List.Item,{children:l},l))})]})},nk=({content:e})=>e?n.jsxs(s.Box,{children:[n.jsx(s.Divider,{mt:20,mb:10,variant:"dashed"}),n.jsx(s.Text,{ta:"left",c:"dimmed",size:"sm",children:"Preview"}),n.jsxs(s.Stack,{children:[n.jsx(Z2,{content:e}),n.jsx(J2,{content:e}),n.jsx(H2,{content:e}),n.jsx(R2,{content:e}),n.jsx(ek,{content:e}),n.jsx(tk,{content:e})]})]}):null;function rk(e){if(e.target===null)throw new Error("FileReader failed with null result");if(typeof e.target.result!="string")throw new Error(`Unparsable file content of type: ${typeof e.target.result}`);let t=JSON.parse(e.target.result);if("content"in t&&(t=t.content),t.version!==at)throw new Error("Schema version mismatch");return t}const ak=T.observer(({onSuccess:e,stretchModal:t,shrinkModal:r})=>{var z,D;const{t:a}=x.useTranslation(),l=F(),{handleSubmit:o,formState:{errors:i},setValue:c,watch:d,setError:u,clearErrors:p}=b.useForm({defaultValues:{content:null}}),f=({content:I})=>{try{if(!I)throw new Error("please use a valid json file");l.applyJSONSchema(I),Ye.showNotification({title:"Successful",message:"",color:"green"}),e()}catch(L){console.error(L),Ye.showNotification({title:"Failed",message:L.message,color:"red"})}},[v,_]=h.useState(null);h.useEffect(()=>{if(!v)return;const I=new FileReader;I.readAsText(v,"UTF-8"),I.onload=L=>{try{const E=rk(L);c("content",E),p("content")}catch(E){console.error(E),u("content",{type:"custom",message:E.message})}},I.onabort=()=>console.log("🟨 abort"),I.onerror=()=>{I.error&&(console.error(I.error),u("content",{type:"custom",message:I.error.message}))}},[v]);const[w]=d(["content"]),m=!w,k=(z=i==null?void 0:i.content)==null?void 0:z.message;return h.useEffect(()=>{!w||k?r():t()},[w,k]),n.jsx(s.Box,{mx:"auto",sx:{position:"relative"},children:n.jsxs("form",{onSubmit:o(f),children:[n.jsx(s.FileInput,{label:a("import.json_file"),required:!0,value:v,onChange:_,error:(D=i==null?void 0:i.content)==null?void 0:D.message,sx:{maxWidth:500}}),k?n.jsx(s.Table,{fz:12,mt:10,children:n.jsxs(s.Table.Tbody,{children:[n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:a("import.this_dashboard")}),n.jsx(s.Table.Td,{children:at})]}),n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:a("import.this_file")}),n.jsx(s.Table.Td,{style:{color:"red"},children:w==null?void 0:w.version})]})]})}):n.jsxs(n.Fragment,{children:[n.jsx(nk,{content:w}),n.jsx(s.Group,{justify:"flex-end",my:"md",children:n.jsx(s.Button,{type:"submit",color:"green",disabled:m,children:a("common.actions.confirm")})})]})]})})}),zc={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},sk=T.observer(()=>{var u;const{t:e}=x.useTranslation(),[t,{open:r,close:a}]=ne.useDisclosure(!1),[l,{setTrue:o,setFalse:i}]=O.useBoolean(!1),d=((u=W().content.views.VIE)==null?void 0:u.type)===$.Tabs;return d?n.jsx(s.Tooltip,{label:e("common.choose_a_tab_first"),children:n.jsx(s.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftSection:n.jsx(S.IconFileImport,{size:16}),sx:{...zc,transform:"none !important"},children:e("import.label")})}):n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{variant:"subtle",color:"blue",radius:0,size:"xs",disabled:d||t,onClick:r,leftSection:n.jsx(S.IconFileImport,{size:16}),sx:{...zc},children:e("import.label")}),n.jsx(s.Modal,{opened:t,onClose:a,title:e("import.title"),trapFocus:!0,onDragStart:p=>{p.stopPropagation()},withinPortal:!0,zIndex:320,size:l?"90vw":500,children:n.jsx(ak,{onSuccess:a,stretchModal:o,shrinkModal:i})})]})}),lk=({iconKey:e,...t})=>{switch(e){case"query_variables":return n.jsx(S.IconVariable,{...t});case"mock_context":return n.jsx(S.IconCodeDots,{...t});case"filter":return n.jsx(S.IconFilter,{...t});case"sql_snippet":return n.jsx(S.IconCopy,{...t});case"query":return n.jsx(S.IconDatabase,{...t});case"view":return n.jsx(S.IconBoxMultiple,{...t});case"panel":return n.jsx(S.IconAppWindow,{...t});default:return null}},ok=({action:e})=>{const{t}=x.useTranslation();return e.description?n.jsx(s.Text,{c:"dimmed",size:"xs",children:t(e.description)}):e.viz?n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Text,{c:"dimmed",size:"xs",children:t(e.viz.displayName)}),n.jsx(s.Text,{c:"dimmed",size:"xs",className:"spotlight-action-viz-group",children:t(e.viz.displayGroup)})]}):null},ik=T.observer(({action:e,query:t})=>{const{t:r}=x.useTranslation();return n.jsx(s.Box,{className:"spotlight-custom-action-component",children:n.jsxs(s.Group,{wrap:"nowrap",children:[n.jsx(lk,{iconKey:e.iconKey,size:14}),n.jsxs("div",{style:{flex:1},children:[n.jsx(s.Highlight,{highlight:t,size:"sm",children:e.title?r(e.title):""}),n.jsx(ok,{action:e})]})]})})}),ck=({groups:e,query:t})=>{const{t:r}=x.useTranslation();return e.length===0?n.jsx(vt.Spotlight.Empty,{children:r("spotlight.not_found")}):n.jsx(n.Fragment,{children:e.map(a=>n.jsx(vt.Spotlight.ActionsGroup,{label:a.group,children:a.actions.map(l=>n.jsx(vt.Spotlight.Action,{onClick:l.onClick,children:n.jsx(ik,{action:l,query:t})},l.id))},a.group))})},dk=T.observer(()=>{const{t:e,i18n:t}=x.useTranslation(),r=s.useMantineTheme(),a=W(),[l,o]=h.useState(""),i=h.useMemo(()=>a.editor.spotlightActionGroups.map(d=>({group:e(d.group),keywords:[d.group,e(d.group)],actions:d.actions.map(u=>{const p=[];return u.title&&(p.push(u.title.toLowerCase()),p.push(e(u.title).toLowerCase())),u.group&&p.push(u.group.toLowerCase()),u.viz&&(p.push(u.viz.displayGroup.toLowerCase()),p.push(u.viz.displayName.toLowerCase())),u.iconKey&&p.push(u.iconKey),{...u,keywords:p}})})),[a.editor.spotlightActionGroups,t.language]),c=h.useMemo(()=>{const d=l.toLowerCase().trim();return d?i.map(p=>{if(p.keywords.some(_=>_.includes(d)))return p;const v=p.actions.filter(_=>_.keywords.some(w=>w.includes(d)));return v.length===0?null:{...p,actions:v}}).filter(p=>p!==null):[i[0]]},[i,l]);return n.jsxs(vt.Spotlight.Root,{onQueryChange:o,shortcut:["mod + P","mod + K"],radius:"md",styles:{search:{border:"none"},action:{position:"relative",display:"block",width:"100%",padding:`${s.rem(10)} ${s.rem(12)}`,borderRadius:r.radius.sm,".spotlight-action-viz-group":{opacity:0},"&:hover, &[data-selected]":{backgroundColor:r.colors.gray[1],".spotlight-action-viz-group":{opacity:1}}}},children:[n.jsx(vt.Spotlight.Search,{placeholder:e("spotlight.placeholder"),leftSection:n.jsx(S.IconSearch,{size:"1.2rem"})}),n.jsx(vt.Spotlight.ActionsList,{children:n.jsx(ck,{groups:c,query:l})})]})}),Dc=({children:e})=>n.jsx(s.Text,{style:{fontSize:"0.6875rem",lineHeight:1,padding:"0.25rem 0.2375rem",borderRadius:"0.25rem"},children:e}),Ic=function(){var t;return(((t=navigator.userAgentData)==null?void 0:t.platform)??navigator.platform).toLowerCase().includes("mac")}(),uk=()=>{const{t:e}=x.useTranslation();return n.jsx(s.Tooltip,{label:n.jsxs(n.Fragment,{children:[Ic&&n.jsx(Dc,{children:"⌘ + K"}),!Ic&&n.jsx(Dc,{children:"Ctrl + K"})]}),children:n.jsx(s.UnstyledButton,{onClick:()=>vt.spotlight.open(),style:{height:"1.875rem",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef",paddingLeft:"calc(0.875rem / 1.5)",paddingRight:"1rem"},sx:{color:"#228be6",background:"transparent","&:hover":{background:"rgb(231, 245, 255)"}},children:n.jsxs(s.Group,{gap:"0.625rem",children:[n.jsx(S.IconSearch,{size:"1rem",color:"#228be6"}),n.jsx(s.Text,{fw:500,style:{flexGrow:1,fontWeight:500,fontSize:"0.75rem",lineHeight:1},children:e("spotlight.trigger_text")})]})})})},pk={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},hk=T.observer(()=>n.jsx(s.Box,{sx:pk,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:n.jsxs(s.Group,{justify:"space-between",align:"center",sx:{height:"30px"},children:[n.jsxs(s.Group,{justify:"flex-start",gap:0,children:[n.jsx(U2,{}),n.jsx(sk,{}),n.jsx(uk,{})]}),n.jsx(Y2,{}),n.jsx(s.Group,{justify:"flex-end",gap:0,children:n.jsx(X2,{})})]})})),gk=T.observer(e=>n.jsxs(n.Fragment,{children:[n.jsx(W2,{...e}),n.jsx(hk,{})]}));function fk(e,t,r){const a=[];return e.filter(l=>"__INTERACTIONS"in l.viz.conf).forEach((l,o)=>{const i=t[l.id];i.data.interactions=y.get(i,"data.interactions",[]);const{__INTERACTIONS:c,__OPERATIONS:d,__TRIGGERS:u}=l.viz.conf;Object.entries(d).forEach(([p,f])=>{const{schemaRef:v,data:_}=f,{config:w}=_;switch(v){case"builtin:op:open-link":let m=w.urlTemplate.substring(0,100);w.urlTemplate.length>=20&&(m+="..."),i.type="interaction",i.data.interactions.push({schemaRef:v,urlTemplate:w.urlTemplate,shortURLTemplate:m});return;case"builtin:op:open_view":a.push({id:`OPERATION--${p}`,source:l.id,target:w.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":i.type="interaction",i.data.interactions.push({schemaRef:v,filters:Object.keys(w.dictionary).map(k=>({key:k,label:r[k]}))});return;case"builtin:op:clear_filter_values":i.type="interaction",i.data.interactions.push({schemaRef:v,filters:w.filter_keys.map(k=>({key:k,label:r[k]}))});return;default:return}})}),a}function bk(e,t){const r=e.filters.keyLabelMap;return{edges:fk(e.panels.list,t,r),edgeNodes:[]}}function Mc(e,t,r){return e*t+e*r}function yk(e,t,r){return e*t+(e-1)*r}const Vn=25,Oa=40,Vc=25,Na=350,vk=150,_k=150,Pc=150,Ac=300,Pn=40,$c=25,xk=300;function wk(e,t){const r=y.keyBy(t,l=>l.id),a=[];return e.current.forEach((l,o)=>{l.panelIDs.forEach((i,c)=>{const d=Mc(c,Pn,$c)+Oa,u=r[i];if(!u){a.push({id:i,_node_type:"panel",parentNode:l.id,data:{label:`!: ${i}`},position:{x:Vn,y:d},sourcePosition:oe.Position.Right,targetPosition:oe.Position.Left,style:{width:Ac,height:Pn}});return}const p=u.name;a.push({id:u.id,_node_type:"panel",parentNode:l.id,data:{label:p},position:{x:Vn,y:d},sourcePosition:oe.Position.Right,targetPosition:oe.Position.Left,style:{width:Ac,height:Pn}})})}),a}const mk={[$.Division]:"Div",[$.Modal]:"Modal",[$.Tabs]:"Tabs"},Ck=oc;function Sk(e){return e.current.map((r,a)=>{const l=yk(r.panelIDs.length,Pn,$c)+Oa+Vc;let o=[];return r.type===$.Tabs&&(o=r.config.tabsInOrder.map(c=>c.view_id)),{id:r.id,_node_type:"view-root",_view_type:r.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${mk[r.type]}:${r.name}`},position:{x:0,y:0},sourcePosition:oe.Position.Right,targetPosition:oe.Position.Left,className:"light",style:{backgroundColor:Ck[r.type],width:Na,height:l}}})}function Tk(e){const t=y.keyBy(e,r=>r.id);e.forEach(r=>{r._node_type!=="view-root"||r._view_type!==$.Tabs||r._tab_view_ids.forEach(a=>{t[a].parentNode=r.id})})}function kk(e){const t=Sk(e.views);Tk(t);const r=wk(e.views,e.panels.list);return[...t,...r]}function zk({nodeMap:e,nodes:t,edges:r}){t.forEach(a=>{a._node_type!=="view-root"||a._view_type!==$.Tabs||(a.sourcePosition=oe.Position.Bottom,a.style.width=Na+Vn*2,a.style.height=Vc+a._tab_view_ids.reduce((l,o)=>{const i=e[o];i.position.y=l,i.position.x=Vn;const c=i.style.height;return l+c+20},Oa))})}function Dk({nodeMap:e,nodes:t,edges:r}){r.filter(a=>a.label==="Open View").forEach(a=>{const l=e[a.source],o=e[a.target];if(!l||!o||!l.parentNode)return;const i=e[l.parentNode];i._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+i._view_level,i._sub_view_ids.push(o.id))}),t.sort((a,l)=>a._node_type==="view-root"&&l._node_type==="view-root"?a._view_level-l._view_level:a._node_type!=="view-root"&&l._node_type!=="view-root"?0:a._node_type==="view-root"?-1:1)}function Ik({nodeMap:e,nodes:t,edges:r}){const a={};r.forEach(l=>{if(l.label!=="Open View")return;const o=e[l.source],i=e[l.target];if(o&&i&&o.parentNode){const c=e[o.parentNode],d=c.position.x,u=Number(y.get(i,"style.height",0)),p=Number(c.style.width);i.position.x=d+p+xk,c._view_level===0&&i._sub_view_ids.length===0&&(o.sourcePosition=oe.Position.Left,i.targetPosition=oe.Position.Right,i.position.x*=-1);const v=i.position.x,_=y.get(a,v,0);i.position.y=_,a[v]=_+u+Pc}})}function Mk({nodeMap:e,nodes:t,edges:r}){const a=new Set,l=new Set;r.forEach(i=>{a.add(i.source),l.add(i.target)}),t.filter(i=>i._node_type!=="view-root"||i.id==="Main"||i.parentNode?!1:!a.has(i.id)&&!l.has(i.id)).forEach((i,c)=>{i.position.x=Mc(c,Na,_k),i.position.y=0-vk-Pc})}function Vk({nodeMap:e,nodes:t,edges:r}){const a={nodeMap:e,nodes:t,edges:r};return Mk(a),Dk(a),zk(a),Ik(a),{nodes:t,edges:r}}function Pk(e){const t=kk(e),r=y.keyBy(t,d=>d.id),{edges:a,edgeNodes:l}=bk(e,r),o=[...t,...l],i=y.keyBy(o,d=>d.id),c={edges:y.uniqBy(a,d=>d.id),nodes:o,nodeMap:i};return Vk(c)}const U5="",Ga={"builtin:op:open-link":n.jsx(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:n.jsx(S.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":n.jsx(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:n.jsx(S.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":n.jsx(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:n.jsx(S.IconCircleOff,{size:14})})};function Ak(e){const t=[];return e.forEach(r=>{switch(r.schemaRef){case"builtin:op:open-link":t.push({key:r.urlTemplate,icon:Ga[r.schemaRef],text:n.jsxs(s.Group,{gap:4,children:[n.jsx(s.Text,{size:"sm",children:"Open: "}),n.jsx(s.Text,{size:"sm",c:"dimmed",children:r.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":r.filters.forEach(({key:a,label:l})=>{t.push({key:r.schemaRef+a,icon:Ga[r.schemaRef],text:n.jsx(s.Group,{gap:4,children:n.jsxs(s.Text,{size:"sm",children:["Set Filter: ",l]})})})});return;case"builtin:op:clear_filter_values":r.filters.forEach(({key:a,label:l})=>{t.push({key:r.schemaRef+a,icon:Ga[r.schemaRef],text:n.jsx(s.Group,{gap:4,children:n.jsxs(s.Text,{size:"sm",children:["Clear Filter: ",l]})})})});return}}),t}const $k=h.memo(({data:e,isConnectable:t,sourcePosition:r=oe.Position.Right,targetPosition:a=oe.Position.Left,...l})=>{const o=h.useMemo(()=>Ak(e.interactions),[e.interactions]);return n.jsxs(n.Fragment,{children:[n.jsx(oe.Handle,{type:"target",position:a,isConnectable:t}),n.jsx(s.Box,{sx:{position:"absolute",top:0,right:0},children:n.jsx(S.IconChevronsUpRight,{size:12})}),n.jsxs(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Text,{size:"sm",children:e.label})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(s.List,{spacing:"xs",size:"sm",center:!0,children:o.map(i=>n.jsx(s.List.Item,{icon:i.icon,children:i.text},i.key))})})]}),n.jsx(oe.Handle,{type:"source",position:r,isConnectable:t})]})}),K5="",Ek={interaction:$k},Bk=T.observer(()=>{const e=J(),{edges:t,nodes:r}=Pk(e);return n.jsxs(oe,{nodes:r,edges:t,onNodesChange:y.noop,onEdgesChange:y.noop,onConnect:y.noop,className:"interactions-viewer",fitView:!0,nodeTypes:Ek,children:[n.jsx(oe.MiniMap,{}),n.jsx(oe.Controls,{}),n.jsx(oe.Background,{})]})}),Lk=T.observer(({opened:e,close:t})=>{const{t:r}=x.useTranslation();return n.jsx(s.Modal,{size:"96vw",opened:e,onClose:t,title:r("interactions.interactions_viewer"),trapFocus:!0,onDragStart:a=>{a.stopPropagation()},styles:{body:{height:"calc(90vh - 54px)"},content:{transform:"none !important"}},zIndex:300,children:n.jsx(Bk,{})})}),qk={"> button":{"&:first-of-type":{borderTopRightRadius:0,borderBottomRightRadius:0,borderRightWidth:.5},":not(:first-of-type):not(:last-of-type)":{borderTopRightRadius:0,borderBottomRightRadius:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5,borderRightWidth:.5},"&:last-of-type":{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5}}};function Ok({onClick:e,name:t,active:r,openSettings:a}){return n.jsxs(s.Box,{sx:{position:"relative"},children:[n.jsx(s.UnstyledButton,{sx:l=>({display:"block",width:"100%",padding:l.spacing.xs,borderRadius:0,position:"relative",color:l.black,"&:hover":{backgroundColor:l.colors.gray[0]},backgroundColor:r?l.colors.gray[2]:"transparent"}),children:n.jsx(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:n.jsx(s.Text,{size:"sm",children:t})})}),r&&n.jsx(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:n.jsx(s.ActionIcon,{onClick:a,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:n.jsx(S.IconAdjustments,{size:16})})})]})}const Nk=T.observer(()=>{const{t:e}=x.useTranslation(),t=W(),r=F(),a=h.useCallback(o=>()=>r.views.setIDOfVIE(o),[r]),l=o=>{t.editor.open(["_VIEWS_",o])};return n.jsxs(s.Box,{sx:{position:"relative"},children:[r.views.options.map(o=>n.jsx(Ok,{active:r.views.idOfVIE===o.value,name:o.label,onClick:a(o.value),openSettings:()=>l(o.value)},o.value)),n.jsx(s.Divider,{variant:"dashed"}),n.jsx(s.Button,{variant:"subtle",rightSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:r.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:e("view.add")})]})}),Gk=T.observer(()=>{const{t:e}=x.useTranslation(),t=W(),r=F(),a=()=>{if(!r.queries.firstID){t.editor.open(["_QUERIES_",""]);return}t.editor.open(["_QUERIES_",r.queries.firstID])},l=()=>{if(!r.filters.firstID){t.editor.open(["_FILTERS_",""]);return}t.editor.open(["_FILTERS_",r.filters.firstID])},[o,i]=h.useState(!1),c=()=>i(!0),d=()=>i(!1);return n.jsxs(s.AppShell.Navbar,{p:0,zIndex:299,children:[n.jsxs(s.AppShell.Section,{children:[n.jsxs(s.Group,{grow:!0,gap:0,sx:{...qk,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[n.jsx(s.Tooltip,{label:e("filter.labels"),withinPortal:!0,children:n.jsx(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:n.jsx(S.IconFilter,{size:18})})}),n.jsx(s.Tooltip,{label:e("query.labels"),withinPortal:!0,children:n.jsx(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:a,children:n.jsx(S.IconDatabase,{size:18})})}),n.jsx(s.Tooltip,{label:e("interactions.interactions_viewer"),withinPortal:!0,children:n.jsx(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:c,children:n.jsx(S.IconRoute,{size:18})})})]}),n.jsx(Lk,{opened:o,close:d})]}),n.jsx(s.AppShell.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:n.jsx(s.Text,{size:"sm",ta:"center",sx:{userSelect:"none",cursor:"default"},children:e("view.labels")})}),n.jsx(s.AppShell.Section,{grow:!0,sx:{overflow:"auto"},children:n.jsx(Nk,{})}),n.jsx(s.AppShell.Section,{children:n.jsx(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:n.jsx(s.Button,{size:"xs",leftSection:n.jsx(S.IconSettings,{size:20}),onClick:()=>t.editor.open([]),children:e("common.titles.settings")})})})]})}),Fk=T.observer(({filter:e})=>{const{t}=x.useTranslation(),r=e.config;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Checkbox,{checked:r.default_value,onChange:a=>r.setDefaultValue(a.currentTarget.checked),label:t("filter.widget.checkbox.default_checked")}),n.jsx(St,{filter:e})]}),n.jsx(pt,{label:t("filter.widget.checkbox.description"),value:r.description,onChange:r.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}},e.id)]})}),jk=[{label:"2022",value:"YYYY"},{label:"202201",value:"YYYYMM"},{label:"20220101",value:"YYYYMMDD"},{label:"2022-01",value:"YYYY-MM"},{label:"2022-01-01",value:"YYYY-MM-DD"}],Qk=T.observer(function({filter:t}){const{t:r}=x.useTranslation(),a=t.config,l=h.useMemo(()=>{const i=Ho();return Object.entries(i).map(([c,d])=>({group:r(`filter.widget.date_range.shortcut.${c}.label`),items:d.map(({key:u,value:p})=>({label:r(`filter.widget.date_range.shortcut.${c}.full.${u}`),value:p}))}))},[]),o=[...a.default_value];return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{children:[n.jsx(s.Checkbox,{checked:a.required,onChange:i=>a.setRequired(i.currentTarget.checked),label:r("filter.widget.date_range.required")}),n.jsx(s.Checkbox,{checked:a.allowSingleDateInRange,onChange:i=>a.setAllowSingleDateInRange(i.currentTarget.checked),label:r("filter.widget.date_range.allow_single_date")})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.Select,{data:jk,label:r("filter.widget.date_range.display_format"),value:a.inputFormat,onChange:a.setInputFormat}),n.jsx(s.NumberInput,{label:r("filter.widget.date_range.max_days"),min:0,value:a.max_days,onChange:a.setMaxDays,hideControls:!0})]}),n.jsxs(s.Group,{children:[n.jsx(Oi,{label:r("filter.widget.date_range.default_value"),config:a,value:{value:o,shortcut:null},onChange:a.setDefaultValue,disabled:!!a.default_shortcut}),n.jsx(s.Select,{data:l,label:r("filter.widget.date_range.default_by_shortcut"),value:a.default_shortcut,onChange:a.setDefaultShortcut,placeholder:r("filter.widget.date_range.default_by_shortcut_placeholder"),clearable:!0,sx:{flexGrow:1},maxDropdownHeight:500})]}),n.jsx(St,{filter:t})]})}),Wk=`
547
547
  // row
548
548
  {
549
549
  label: string;
550
550
  value: string;
551
551
  description?: string; // optional
552
552
  }
553
- `,Pc=()=>{const{t:e}=x.useTranslation(),[t,r]=h.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{variant:"subtle",size:"compact-sm",onClick:()=>r(a=>!a),children:e(t?"common.actions.close":"filter.widget.common.see_data_structure")}),n.jsx(s.Collapse,{in:t,children:n.jsx(Oe.CodeHighlight,{language:"typescript",withCopyButton:!1,code:Fk})})]})},jk=T.observer(function({filter:t}){const{t:r}=x.useTranslation(),a=t.config,l=()=>{a.addStaticOption({label:"",value:""})},o=a.static_options,i=o.filter(c=>c.value!==""&&c.label!=="");return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Checkbox,{checked:a.required,onChange:c=>a.setRequired(c.currentTarget.checked),label:r("filter.widget.select.required")}),n.jsx(St,{filter:t})]}),n.jsx(s.TextInput,{label:r("filter.widget.select.width"),description:r("filter.widget.multi_select.width_description"),value:a.min_width,onChange:c=>a.setMinWidth(c.currentTarget.value),placeholder:"200px"}),n.jsx(s.Divider,{label:r("filter.widget.select.configure_options"),labelPosition:"center"}),n.jsxs(s.Stack,{gap:10,sx:{position:"relative",minHeight:"50px"},children:[a.usingQuery&&n.jsxs(n.Fragment,{children:[n.jsx(s.Overlay,{backgroundOpacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),n.jsx(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:n.jsx(s.Text,{c:"white",size:"16px",children:r("filter.widget.common.using_query")})})]}),i.length>0&&n.jsx(s.MultiSelect,{label:r("filter.widget.select.default_selection"),placeholder:r("filter.widget.select.no_default_selection"),data:i,value:[...a.default_value],onChange:a.setDefaultValue}),o.map((c,d)=>n.jsxs(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[n.jsx(s.TextInput,{label:r("common.label"),required:!0,value:a.static_options[d].label,onChange:u=>{a.static_options[d].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.TextInput,{label:r("common.value"),required:!0,value:a.static_options[d].value,onChange:u=>{a.static_options[d].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>a.removeStaticOption(d),sx:{position:"absolute",top:28,right:5},children:n.jsx(S.IconTrash,{size:16})})]},d)),n.jsx(s.Button,{mt:10,size:"xs",color:"blue",leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),onClick:l,sx:{width:"50%"},mx:"auto",children:r("common.actions.add_an_option")})]}),n.jsx(s.Divider,{label:r("filter.widget.common.or_fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(Cn,{value:a.options_query_id,onChange:a.setOptionsQueryID}),n.jsx(s.NumberInput,{value:a.default_selection_count,onChange:a.setDefaultSelectionCount,label:r("filter.widget.common.default_selection_count")}),n.jsx(oa,{config:a}),n.jsx(Pc,{})]})}),Vc={date_unit:{zh:[{label:"天",value:"day"},{label:"周",value:"week"},{label:"双周",value:"bi-week"},{label:"月",value:"month"},{label:"季度",value:"quarter"},{label:"年",value:"year"}],en:[{label:"Day",value:"day"},{label:"Week",value:"week"},{label:"Bi-Week",value:"bi-week"},{label:"Month",value:"month"},{label:"Quarter",value:"quarter"},{label:"Year",value:"year"}]}},$c=T.observer(({config:e})=>{const{t,i18n:r}=x.useTranslation(),a=()=>{e.addStaticOption({label:"",value:""})},l=h.useMemo(()=>[{label:t("filter.widget.select.preset_options.date_unit"),value:"date_unit"}],[r.language]),o=i=>{if(!i||!(i in Vc))return;const c=Vc[i][r.language];e.replaceStaticOptions(c),c.length>0&&e.setDefaultValue(c[0].value)};return n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{size:"xs",color:"blue",leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),onClick:a,children:t("common.actions.add_an_option")}),n.jsx(s.Select,{placeholder:t("filter.widget.select.preset_options.apply"),value:null,onChange:o,data:l,size:"xs"})]})}),Qk=T.observer(({config:e})=>{const{t,i18n:r}=x.useTranslation(),a=[...e.static_options],l=h.useMemo(()=>[{label:t("filter.widget.select.no_default_selection"),value:""},...a.filter(o=>o.value!=="")],[r.language,a]);return a.length===0?n.jsx($c,{config:e}):n.jsxs(n.Fragment,{children:[n.jsx(s.Select,{label:t("filter.widget.select.default_selection"),data:l,value:e.default_value,onChange:e.setDefaultValue}),a.map((o,i)=>n.jsxs(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[n.jsx(s.TextInput,{label:t("common.label"),required:!0,value:e.static_options[i].label,onChange:c=>{e.static_options[i].setLabel(c.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.TextInput,{label:t("common.value"),required:!0,value:e.static_options[i].value,onChange:c=>{e.static_options[i].setValue(c.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.removeStaticOption(i),sx:{position:"absolute",top:28,right:5},children:n.jsx(S.IconTrash,{size:16})})]},i)),n.jsx($c,{config:e})]})}),Wk=T.observer(({filter:e})=>{const{t}=x.useTranslation(),r=e.config;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Checkbox,{checked:r.required,onChange:a=>r.setRequired(a.currentTarget.checked),label:t("filter.widget.select.required")}),n.jsx(s.Checkbox,{checked:r.clearable,onChange:a=>r.setClearable(a.currentTarget.checked),label:t("filter.widget.select.clearable")}),n.jsx(St,{filter:e})]}),n.jsx(s.TextInput,{label:t("filter.widget.select.width"),value:r.width,onChange:a=>r.setWidth(a.currentTarget.value),placeholder:"200px"}),n.jsx(s.Divider,{label:t("filter.widget.select.configure_options"),labelPosition:"center"}),n.jsxs(s.Stack,{gap:10,sx:{position:"relative",minHeight:"50px"},children:[r.usingQuery&&n.jsxs(n.Fragment,{children:[n.jsx(s.Overlay,{backgroundOpacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),n.jsx(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:n.jsx(s.Text,{c:"white",size:"16px",children:t("filter.widget.common.using_query")})})]}),n.jsx(Qk,{config:r})]}),n.jsx(s.Divider,{label:t("filter.widget.common.or_fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(s.Checkbox,{checked:r.default_selection_count===1,onChange:a=>r.setDefaultSelectionCount(a.currentTarget.checked?1:0),label:t("filter.widget.select.select_first_option_by_default")}),n.jsx(Cn,{value:r.options_query_id,onChange:r.setOptionsQueryID}),n.jsx(Pc,{})]})}),Uk=T.observer(function({filter:t}){const{t:r}=x.useTranslation(),a=t.config;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{children:[n.jsx(s.TextInput,{label:r("filter.widget.text_input.default_value"),value:a.default_value,onChange:l=>{a.setDefaultValue(l.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.Box,{mt:22,children:n.jsx(St,{filter:t})})]}),n.jsx(s.Checkbox,{checked:a.required,onChange:l=>a.setRequired(l.currentTarget.checked),label:r("filter.widget.text_input.required")})]})}),Yk=T.observer(({filter:e})=>{const{t}=x.useTranslation(),r=W().editor,a=e.usages,l=o=>{switch(o.type){case"query":r.setPath(["_QUERIES_",o.id]);break;case"sql_snippet":r.setPath(["_SQL_SNIPPETS_",o.id]);break;case"view":r.setPath(["_VIEWS_",o.id]);default:return}};return a.length===0?n.jsx(s.Text,{mt:10,ml:10,size:"sm",children:t("filter.usage.unused_description")}):n.jsxs(s.Table,{highlightOnHover:!0,layout:"fixed",styles:{table:{fontSize:"14px"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:80}}),n.jsx("col",{})]}),n.jsx(s.Table.Tbody,{children:a.map(o=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:n.jsx(s.Text,{size:"xs",children:t(o.type_label)})}),n.jsx(s.Table.Td,{children:n.jsx(s.Anchor,{size:"xs",title:o.label,onClick:()=>l(o),children:n.jsx(s.Text,{truncate:"end",children:o.label})})})]},o.id))})]})}),Kk=T.observer(({filter:e})=>{const{t}=x.useTranslation();return n.jsxs(s.Tabs,{defaultValue:"usage",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"config",children:t("common.titles.config")}),n.jsx(s.Tabs.Tab,{value:"usage",children:t("filter.usage.label")})]}),n.jsx(s.Tabs.Panel,{value:"config",children:n.jsx(s.Box,{sx:{minWidth:"480px"},children:n.jsx(Oe.CodeHighlight,{mt:22,language:"json",withCopyButton:!1,code:JSON.stringify(e,null,4)})})}),n.jsx(s.Tabs.Panel,{value:"usage",children:n.jsx(Yk,{filter:e})})]})}),Xk={[V.Select]:Wk,[V.MultiSelect]:jk,[V.TreeSelect]:DS,[V.TreeSingleSelect]:BS,[V.TextInput]:Uk,[V.Checkbox]:Ok,[V.DateRange]:Gk},st={[V.Select]:"filter.widget.names.select",[V.MultiSelect]:"filter.widget.names.multi_select",[V.TreeSelect]:"filter.widget.names.tree_select",[V.TreeSingleSelect]:"filter.widget.names.tree_single_select",[V.TextInput]:"filter.widget.names.text_input",[V.Checkbox]:"filter.widget.names.checkbox",[V.DateRange]:"filter.widget.names.date_range"},Zk=T.observer(({filter:e})=>{const{t,i18n:r}=x.useTranslation(),a=F(),l=h.useMemo(()=>Xk[e.type],[e.type]),o=h.useMemo(()=>[{label:t(st[V.Select]),value:"select"},{label:t(st[V.MultiSelect]),value:"multi-select"},{label:t(st[V.TreeSelect]),value:"tree-select"},{label:t(st[V.TreeSingleSelect]),value:"tree-single-select"},{label:t(st[V.TextInput]),value:"text-input"},{label:t(st[V.Checkbox]),value:"checkbox"},{label:t(st[V.DateRange]),value:"date-range"}],[r.language]);return n.jsxs(s.Group,{grow:!0,gap:20,align:"top",children:[n.jsxs(s.Box,{w:600,children:[n.jsx(s.Text,{pb:"md",c:"gray",size:"sm",children:t("common.titles.edit")}),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{wrap:"nowrap",children:[n.jsx(s.NumberInput,{label:t("filter.field.order"),required:!0,value:e.order,onChange:e.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),e.auto_submit_supported&&n.jsx(s.Checkbox,{label:t("filter.field.auto_submit"),checked:e.auto_submit,onChange:i=>e.setAutoSubmit(i.currentTarget.checked),mt:22})]}),n.jsx(s.MultiSelect,{label:t("filter.field.visible_in"),data:a.views.options,value:[...e.visibleInViewsIDs],onChange:e.setVisibleInViewsIDs}),n.jsx(s.TextInput,{label:t("common.key"),placeholder:t("filter.field.key_placeholder"),required:!0,value:e.key,onChange:i=>{e.setKey(i.currentTarget.value)}}),n.jsx(s.TextInput,{label:t("common.label"),placeholder:t("filter.field.label_placeholder"),required:!0,value:e.label,onChange:i=>{e.setLabel(i.currentTarget.value)}}),n.jsx(s.Select,{label:t("filter.field.widget"),data:o,required:!0,value:e.type,onChange:e.setType,maxDropdownHeight:500}),n.jsx(s.Divider,{mb:0,mt:10,variant:"dashed",labelPosition:"center"}),n.jsx(l,{filter:e})]})]}),n.jsx(Kk,{filter:e})]})}),Jk=T.observer(({id:e})=>{const{t}=x.useTranslation(),r=ze.useModals(),a=W(),l=F();if(e==="")return null;const o=l.filters.findByID(e);if(!o)return n.jsxs(s.Text,{size:"14px",children:["Filter by ID[",e,"] is not found"]});const i=()=>{a.editor.setPath(["_FILTERS_",""])},c=()=>{r.openConfirmModal({title:`${t("filter.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{l.filters.removeByID(e),i()},confirmProps:{color:"red"},zIndex:320})};return n.jsxs(s.Stack,{sx:{minWidth:"1100px",height:"100vh"},gap:"sm",pb:30,children:[n.jsx(s.Group,{justify:"flex-end",pt:10,children:n.jsx(s.Button,{size:"xs",color:"red",leftSection:n.jsx(S.IconTrash,{size:16}),onClick:c,children:t("filter.delete")})}),n.jsx(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:n.jsx(Zk,{filter:o})})]})}),Hk=T.observer(()=>{const{t:e}=x.useTranslation(),[t,r]=h.useState([]),a=W(),l=u=>{a.editor.setPath(["_FILTERS_",u])},o=()=>{a.content.filters.downloadSchema(t)},i=h.useMemo(()=>a.content.filters.sortedList.map(u=>u.id),[a.content.filters.sortedList]),c=()=>{r(i)},d=()=>{r([])};return n.jsxs(s.Stack,{sx:{height:"100%"},gap:"sm",pb:"59px",children:[n.jsx(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:n.jsx(s.Text,{size:"sm",px:"md",ta:"left",sx:{userSelect:"none",cursor:"default"},children:e("filter.manage")})}),n.jsx(s.Flex,{justify:"space-between",align:"center",px:12,children:n.jsxs(s.Group,{justify:"flex-start",children:[n.jsxs(s.Button.Group,{children:[n.jsx(s.Button,{variant:"default",size:"xs",onClick:c,children:e("common.actions.select_all")}),n.jsx(s.Button,{variant:"default",size:"xs",onClick:d,children:e("common.actions.clear_selection")})]}),n.jsx(s.Button,{size:"xs",color:"blue",leftSection:n.jsx(S.IconCode,{size:14}),disabled:t.length===0,onClick:o,children:e("common.actions.download_schema")})]})}),n.jsx(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:n.jsx(s.Checkbox.Group,{size:"xs",value:t,onChange:r,children:n.jsxs(s.Table,{fz:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"40px"}}),n.jsx(s.Table.Th,{style:{width:"300px"},children:e("common.label")}),n.jsx(s.Table.Th,{children:e("common.key")}),n.jsx(s.Table.Th,{style:{width:"100px"},children:e("filter.field.widget")}),n.jsx(s.Table.Th,{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),n.jsx(s.Table.Tbody,{children:a.content.filters.sortedList.map(u=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:n.jsx(s.Checkbox,{value:u.id,styles:{input:{cursor:"pointer"}}})}),n.jsx(s.Table.Td,{children:u.label}),n.jsx(s.Table.Td,{children:u.key}),n.jsx(s.Table.Td,{children:e(st[u.type])}),n.jsx(s.Table.Td,{children:n.jsx(s.Button,{variant:"subtle",size:"xs",onClick:()=>l(u.id),children:e("common.actions.open")})})]},u.id))})]})})})]})}),Rk=T.observer(()=>{const{t:e}=x.useTranslation(),t=F(),[r,a]=h.useState(()=>JSON.stringify(t.mock_context.current,null,4)),l=()=>{try{t.mock_context.replace(JSON.parse(r))}catch(i){Ze.showNotification({title:"Failed",message:i.message,color:"red"})}},o=h.useMemo(()=>{try{return JSON.stringify(JSON.parse(r))!==JSON.stringify(t.mock_context.current)}catch{return!1}},[r,t.mock_context.current]);return n.jsxs(s.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[n.jsx(s.Group,{justify:"flex-start",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:n.jsx(s.Text,{size:"sm",fw:500,children:e("mock_context.label")})}),n.jsx(s.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:n.jsxs(s.Stack,{gap:10,sx:{maxWidth:"unset !important"},children:[n.jsxs(s.Group,{justify:"flex-start",children:[n.jsx(s.Text,{size:"sm",children:e("mock_context.hint")}),n.jsx(s.Button,{color:"green",size:"compact-sm",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:l,disabled:!o,children:e("common.actions.save")})]}),n.jsx(s.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:r,onChange:a,sx:{flexGrow:1}})]})})]})}),ez=T.observer(()=>{const{t:e}=x.useTranslation(),{panel:t}=re();return n.jsx(pt,{label:e("panel.panel_description"),value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1}}},t.id)}),tz=T.observer(()=>{const{t:e}=x.useTranslation(),{panel:t}=re(),r=J().layouts.findItemByPanelID(t.id),{style:a}=t;return n.jsx(n.Fragment,{children:n.jsxs(s.Stack,{gap:20,children:[n.jsxs(s.Group,{grow:!0,align:"top",children:[n.jsx(s.NumberInput,{label:e("panel.style.width"),min:1,max:36,step:1,decimalScale:0,rightSection:n.jsx(s.Text,{size:"12px",children:e("panel.style.width_postfix")}),styles:{section:{width:"auto",maxWidth:"100px",paddingRight:"14px",justifyContent:"flex-end"}},value:r.w,onChange:l=>{typeof l!="string"&&r.setWidth(l)}}),n.jsx(s.NumberInput,{label:e("panel.style.height"),rightSection:n.jsx(s.Text,{size:"12px",children:e("panel.style.height_postfix")}),styles:{section:{width:"40px"}},value:r.h,onChange:l=>{typeof l!="string"&&r.setHeight(l)}})]}),n.jsx(s.Checkbox,{ml:6,label:e("panel.style.border"),checked:a.border.enabled,onChange:l=>a.border.setEnabled(l.currentTarget.checked)})]})})}),nz=()=>n.jsxs("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),rz=T.observer(()=>{const{t:e}=x.useTranslation(),{panel:t}=re(),{name:r}=t,[a,l]=te.useInputState(r),o=r!==a,i=h.useCallback(()=>{o&&t.setName(a)},[o,a]);h.useEffect(()=>{l(r)},[r]);const c=!a.trim();return n.jsxs(s.Stack,{gap:4,children:[n.jsxs(s.Group,{align:"center",children:[n.jsxs(s.Text,{size:"14px",fw:500,children:[e("panel.panel_name"),n.jsx(nz,{})]}),n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",disabled:!o||c,onClick:i,children:n.jsx(S.IconDeviceFloppy,{size:18})})]}),n.jsx(s.TextInput,{value:a,onChange:l,required:!0})]})}),az=T.observer(()=>{const{t:e}=x.useTranslation(),{panel:t}=re();return n.jsx(s.Stack,{gap:6,mb:10,children:n.jsxs(s.Group,{pl:6,justify:"flex-start",gap:20,children:[n.jsx(s.Checkbox,{size:"sm",checked:t.title.show,onChange:r=>t.title.setShow(r.currentTarget.checked),label:e("panel.show_title"),sx:{userSelect:"none"}}),n.jsx(s.Checkbox,{size:"sm",checked:!0,disabled:!0,label:e("panel.use_name_as_title")})]})})});function sz(){const{t:e}=x.useTranslation();return n.jsxs(s.Stack,{sx:{height:"100%"},children:[n.jsx(tz,{}),n.jsx(s.Divider,{label:e("common.info"),labelPosition:"center",variant:"dashed"}),n.jsx(rz,{}),n.jsx(az,{}),n.jsx(ez,{})]})}const lz={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},"th, td":{wordBreak:"break-word"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1",backgroundColor:"rgb(248, 249, 250)"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function Ec({data:e}){const t=h.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const a=ge.createColumnHelper();return Object.keys(e[0]).map(l=>a.accessor(l,{cell:o=>o.getValue()}))},[e]),r=ge.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:ge.getCoreRowModel()});return e.length===0?n.jsx(s.Box,{sx:{height:"5em"}}):n.jsx(ne,{children:n.jsxs(s.Table,{sx:lz,children:[n.jsx(s.Table.Thead,{children:r.getHeaderGroups().map(a=>n.jsx(s.Table.Tr,{children:a.headers.map(l=>n.jsxs(s.Table.Th,{style:{width:l.getSize()},children:[l.isPlaceholder?null:ge.flexRender(l.column.columnDef.header,l.getContext()),n.jsx(s.ActionIcon,{variant:"subtle",onMouseDown:l.getResizeHandler(),onTouchStart:l.getResizeHandler(),className:`resizer ${l.column.getIsResizing()?"isResizing":""}`,children:n.jsx(S.IconArrowBarToRight,{})})]},l.id))},a.id))}),n.jsx(s.Table.Tbody,{children:r.getRowModel().rows.map(a=>n.jsx(s.Table.Tr,{children:a.getVisibleCells().map(l=>n.jsx(s.Table.Td,{children:n.jsx(ne,{children:typeof l.getValue()=="object"?n.jsx("pre",{children:JSON.stringify(l.getValue(),null,2)}):ge.flexRender(l.column.columnDef.cell,l.getContext())})},l.id))},a.id))})]})})}const oz=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],iz={section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px"}},cz=({data:e,page:t,setPage:r,limit:a,setLimit:l})=>{const{t:o}=x.useTranslation(),i=e.length,c=Math.ceil(i/a),d=p=>{p&&(r(1),l(Number(p)))};if(i===0)return null;const u=c===1&&i<=10;return n.jsxs(s.Group,{pt:10,px:10,justify:"space-between",children:[n.jsxs(s.Group,{justify:"flex-start",children:[c>1&&n.jsx(s.Pagination,{size:"sm",value:t,onChange:r,total:c,withEdges:c>7,styles:{control:{height:"30px"}}}),!u&&n.jsx(s.Select,{leftSection:n.jsx(s.Text,{ta:"center",c:"dimmed",size:"14px",children:o("common.pagination.page_size")}),size:"xs",styles:iz,data:oz,value:String(a),onChange:d})]}),n.jsx(s.Group,{justify:"flex-end",children:n.jsx(s.Text,{c:"dimmed",my:0,size:"14px",children:o("common.pagination.total_rows",{total:i})})})]})},dz=ll(({data:e,loading:t})=>{const[r,a]=h.useState(1),[l,o]=h.useState(20),i=h.useMemo(()=>{const c=(r-1)*l,d=c+l;return e.slice(c,d)},[e,r,l]);return n.jsxs(ne,{children:[n.jsx(cz,{data:e,page:r,setPage:a,limit:l,setLimit:o}),n.jsxs(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n.jsx(s.LoadingOverlay,{visible:t,overlayProps:{blur:2}}),n.jsx(Ec,{data:i})]})]})}),uz=T.observer(({queryID:e})=>{const{t}=x.useTranslation(),r=J(),a=h.useMemo(()=>r.queries.findByID(e),[r,e]);if(!a||a.state==="loading")return null;const{error:l,metricQueryPayloadErrorString:o,stateMessage:i}=a;return l||o?n.jsx(s.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:l??o}):i?n.jsx(s.Text,{size:"sm",mt:10,c:"gray",ta:"center",children:t(i)}):null}),Ga=T.observer(({id:e,moreActions:t,refreshOnMount:r})=>{const{t:a}=x.useTranslation(),l=J(),{data:o,state:i}=l.getDataStuffByID(e),c=i==="loading",d=h.useCallback(()=>{l.queries.refetchDataByQueryID(e)},[e,l]),u=()=>{l.queries.downloadDataByQueryID(null,e)};h.useEffect(()=>{r&&d()},[d,r]);const p=!Array.isArray(o)||o.length===0;return n.jsxs(s.Stack,{gap:0,sx:{height:"100%",border:"1px solid #eee"},children:[n.jsxs(s.Group,{justify:"space-between",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(s.Text,{size:"sm",fw:500,children:a("data.preview_data")})}),n.jsxs(s.Group,{pr:15,children:[t,n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",disabled:c,onClick:d,children:n.jsx(S.IconRefresh,{size:16})}),n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",disabled:c||p,onClick:u,children:n.jsx(S.IconDownload,{size:16})})]})]}),n.jsxs(s.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[n.jsx(uz,{queryID:e}),n.jsx(dz,{data:o,loading:c})]})]})}),pz=T.observer(function(){const{t}=x.useTranslation(),r=W(),a=F(),{panel:l}=re(),[o,i]=h.useState(!1),c=u=>{r.editor.setPath(["_QUERIES_",u])},d=l.queryIDs.length;return n.jsxs(n.Fragment,{children:[n.jsx(s.Drawer,{opened:o,onClose:()=>i(!1),title:t("panel.settings.choose_queries"),padding:"xl",size:500,zIndex:320,children:n.jsx(s.Checkbox.Group,{value:[...l.queryIDs],onChange:l.setQueryIDs,children:n.jsx(s.Stack,{gap:"lg",children:a.queries.options.map(u=>n.jsx(s.Checkbox,{label:u.label,value:u.value},u.value))})})}),n.jsxs(s.Stack,{gap:6,children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(s.Button,{variant:"light",size:"sm",leftSection:n.jsx(S.IconLine,{size:16}),onClick:()=>i(!0),children:t(d===0?"panel.settings.need_to_choose_queries":"panel.settings.choose_queries")})}),d===1&&n.jsx(Ga,{id:l.queryIDs[0],moreActions:n.jsx(s.Tooltip,{label:t("query.open"),children:n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(l.queryIDs[0]),children:n.jsx(S.IconArrowCurveRight,{size:16})})})}),d>1&&n.jsxs(s.Tabs,{defaultValue:l.queryIDs[0],children:[n.jsx(s.Tabs.List,{children:l.queries.map(u=>n.jsx(s.Tabs.Tab,{value:u.id,children:u.name},u.id))}),l.queries.map(u=>n.jsx(s.Tabs.Panel,{value:u.id,children:n.jsx(Ga,{id:u.id,moreActions:n.jsx(s.Tooltip,{label:t("query.open"),children:n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(u.id),children:n.jsx(S.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),hz=T.observer(()=>{const{panel:e}=be();return e.title.show?n.jsx(s.Group,{grow:!0,justify:"center",className:"panel-title-wrapper",sx:{flexGrow:1},children:n.jsx(s.Text,{size:"sm",ta:"center",lineClamp:1,className:"panel-title-text",children:e.title.show?e.name:""})}):null}),gz=T.observer(()=>{const{panel:e}=be();return n.jsx(ne,{children:n.jsx(s.Box,{className:`panel-root ${e.title.show?"panel-root--show-title":""}`,p:0,sx:{border:"1px solid",borderColor:e.style.border.enabled?"#e9ecef":"transparent",flexGrow:0,flexShrink:0,width:"600px !important",height:"450px !important"},children:n.jsxs(ms,{children:[n.jsx(s.Box,{className:"panel-description-popover-wrapper",children:n.jsx(Da,{})}),n.jsx(hz,{}),n.jsx(Aa,{panel:e})]})})})});function fz(){const{t:e}=x.useTranslation(),{vizManager:t}=h.useContext(rt);return h.useMemo(()=>y.orderBy(Object.entries(y.groupBy(t.availableVizList,"displayGroup")),[l=>l[0]],["asc"]).map(([l,o])=>{const i=o.map(c=>({value:c.name,label:e(c.displayName??it.name)}));return{group:e(l??"ungrouped"),items:y.orderBy(i,[c=>c.label],["asc"])}}),[t])}const bz=T.observer(({value:e,submit:t})=>{const{t:r}=x.useTranslation(),[a,l]=te.useInputState(e);h.useEffect(()=>{l(e)},[e]);const o=fz(),i=e!==a;return n.jsx(s.Select,{label:r("visualization.component"),value:a,searchable:!0,onChange:l,data:o,rightSection:n.jsx(s.ActionIcon,{variant:"filled",color:"green",disabled:!i,onClick:()=>t(a),styles:{root:{pointerEvents:"all"}},children:n.jsx(S.IconDeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Bc=[];function yz(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function vz(){const{data:e,panel:{variables:t,viz:r,title:a,name:l,queryIDs:o,description:i,id:c}}=re(),{vizManager:d}=h.useContext(rt),u={name:l,title:a,description:i,viz:r,queryIDs:o,id:c},p=Fi(u);try{return d.resolveComponent(u.viz.type),n.jsx(ln,{configure:p,children:n.jsx(ET,{variables:t,setVizConf:r.setConf,panel:u,vizManager:d,data:e})})}catch(f){return console.info(y.get(f,"message")),null}}const _z=T.observer(()=>{const{data:e,panel:{viz:t}}=re(),{vizManager:r}=h.useContext(rt),a=h.useCallback(u=>{if(u===t.type)return;const p=yz(r,u);t.setType(u),t.setConf(p||{})},[t.type]),l=u=>{try{t.setConf(JSON.parse(u))}catch(p){console.error(p)}},o=h.useMemo(()=>{var u;return(u=Bc.find(p=>p.value===t.type))==null?void 0:u.Panel},[t.type,Bc]),i=vz(),c=o?h.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,d=i||c;return n.jsxs(s.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[n.jsx(bz,{submit:a,value:t.type}),n.jsxs(ne,{children:[n.jsx(s.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:d}),!d&&n.jsx(s.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:l})]})]})}),xz=T.observer(({panel:e,sourceViewID:t})=>{const{t:r}=x.useTranslation(),a=F(),[l,o]=h.useState(t);h.useEffect(()=>{o(t)},[t]);const[i,{open:c,close:d}]=te.useDisclosure(!1),u=()=>{e.moveToView(t,l),d()};return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{size:"xs",variant:"subtle",color:"blue",onClick:c,leftSection:n.jsx(S.IconBoxMultiple,{size:14}),children:r("panel.settings.change_view")}),n.jsx(s.Modal,{opened:i,onClose:d,title:r("panel.settings.change_view_title"),zIndex:320,children:n.jsxs(s.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[n.jsx(s.Radio.Group,{value:l,onChange:o,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:n.jsx(s.Stack,{gap:"xs",children:a.views.options.map(p=>n.jsx(s.Radio,{value:p.value,label:p.label},p.value))})}),n.jsxs(s.Group,{wrap:"nowrap",justify:"space-between",sx:{flexGrow:0,flexShrink:0},children:[n.jsx(s.Button,{size:"xs",color:"red",leftSection:n.jsx(S.IconX,{size:14}),onClick:d,children:r("common.actions.cancel")}),n.jsx(s.Button,{size:"xs",color:"blue",leftSection:n.jsx(S.IconDeviceFloppy,{size:14}),onClick:u,disabled:l===t,children:r("common.actions.confirm")})]})]})})]})}),wz=T.observer(({sx:e={}})=>{const{t}=x.useTranslation(),r=J(),{panel:a}=be(),l=r.dashboardStateValues,o=(()=>{const i={...l,...a.variableStrings};return JSON.stringify(i,null,2)})();return n.jsx(s.Stack,{sx:{overflow:"hidden",...e},children:n.jsxs(s.Tabs,{defaultValue:"vars",keepMounted:!1,children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"guide",leftSection:n.jsx(S.IconAlertCircle,{size:14}),children:t("panel.variable.guide.tabs.guide")}),n.jsx(s.Tabs.Tab,{value:"vars",leftSection:n.jsx(S.IconVariable,{size:14}),children:t("panel.variable.guide.tabs.vars")})]}),n.jsx(s.Tabs.Panel,{value:"guide",pt:"xs",children:n.jsx(Oe.CodeHighlight,{language:"sql",sx:{width:"100%"},withCopyButton:!1,code:t("panel.variable.guide.text")})}),n.jsx(s.Tabs.Panel,{value:"vars",pt:"xs",children:n.jsx(Oe.CodeHighlight,{language:"json",sx:{width:"100%"},withCopyButton:!1,code:o})})]})})}),Fa={name:"new_var",size:"1rem",weight:"initial",color:{type:"static",staticColor:"Red"},data_field:"",aggregation:{type:"sum",config:{},fallback:"0"},formatter:{output:"number",mantissa:0,trimMantissa:!1,average:!1}};class mz{constructor(t){P(this,"panel");P(this,"selected");this.panel=t,t.variables.length>0&&(this.selected=t.variables[0]),Q.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}get variableOptions(){return this.panel.variables.map(t=>({label:t.name,value:t.name,description:t.aggregation.type}))}addNew(){const t=this.panel.variables.filter(r=>r.name.startsWith(Fa.name)).length;this.panel.addVariable(y.cloneDeep({...Fa,name:`${Fa.name}${t||""}`})),this.selected=y.last(this.panel.variables)}select(t){this.selected=t}selectByName(t){if(!t){console.warn("Unexpected null name when calling selectByName");return}const r=this.variables.find(a=>a.name===t);if(!r){console.error(`Variable by name[${t}] not found`);return}this.selected=r}remove(t){this.selected===t&&(this.selected=void 0);const r=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!y.isEmpty(this.panel.variables)){const a=Math.min(this.panel.variables.length-1,r);this.selected=this.panel.variables[a]}}}function Cz(){const{panel:e}=re();return O.useCreation(()=>new mz(e),[e])}const Sz=h.forwardRef(function({value:t,onChange:r,remove:a},l){const{t:o}=x.useTranslation(),i=(c,d)=>{const u=y.cloneDeep(t);y.set(u,c,d),r(u)};return n.jsxs(s.Stack,{ref:l,children:[n.jsxs(s.Stack,{gap:"xs",px:"sm",py:"md",sx:{border:"1px solid #e9ecef"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(s.TextInput,{label:o("common.name"),required:!0,value:t.name,onChange:c=>i("name",c.currentTarget.value)}),n.jsx(q,{label:o("common.data_field"),required:!0,value:t.data_field,onChange:c=>i("data_field",c)})]}),n.jsx(kr,{label:o("panel.variable.aggregation.label"),pt:0,value:t.aggregation,onChange:c=>i("aggregation",c),withFallback:!0}),t.aggregation.type!=="custom"&&n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{mt:"xl",mb:0,label:o("numbro.format.label"),labelPosition:"center",variant:"dashed"}),n.jsx(Le,{value:t.formatter,onChange:c=>i("formatter",c)})]})]}),n.jsx(s.Button,{mt:20,leftSection:n.jsx(S.IconTrash,{size:16}),color:"red",variant:"light",onClick:a,children:o("panel.variable.delete")})]})}),Tz=T.observer(e=>{const{t}=x.useTranslation(),r=O.useCreation(()=>Pi(e.variable),[e.variable]),a=()=>e.uiModel.remove(e.variable);return n.jsxs(s.Stack,{"data-testid":"variable-editor",align:"stretch",children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{variant:"subtle",size:"xs",disabled:!r.changed,color:"red",onClick:r.reset,leftSection:n.jsx(S.IconRecycle,{size:18}),children:t("common.actions.revert_changes")}),n.jsx(s.Button,{variant:"filled",size:"xs",disabled:!r.changed,color:"green",onClick:r.commit,leftSection:n.jsx(S.IconDeviceFloppy,{size:18}),children:t("common.actions.save_changes")})]}),n.jsx(Sz,{value:g.getSnapshot(r.copy),onChange:r.update,remove:a})]})});T.observer(e=>{const{uiModel:t}=e;return n.jsx(s.Stack,{className:"var-list",children:t.variables.map(r=>n.jsx(s.Button,{variant:t.selected===r?"filled":"subtle",color:"gray",onClick:()=>t.select(r),children:r.name},r.name))})});const kz=T.observer(({model:e})=>{const{t}=x.useTranslation();return n.jsx(s.Overlay,{color:"#fff",backgroundOpacity:1,sx:{position:"absolute"},children:n.jsx(s.Button,{variant:"light",size:"xs",leftSection:n.jsx(S.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:t("panel.variable.add")})})}),zz=T.observer(()=>{var r;const{t:e}=x.useTranslation(),t=Cz();return t.variableOptions.length===0?n.jsx(kz,{model:t}):n.jsxs(s.Stack,{pb:20,children:[n.jsxs(s.Group,{justify:"flex-start",children:[n.jsx(s.Select,{label:e("panel.variable.labels"),data:t.variableOptions,value:(r=t.selected)==null?void 0:r.name,onChange:t.selectByName,maxDropdownHeight:600,sx:{flexGrow:1}}),n.jsx(s.Button,{variant:"light",size:"xs",leftSection:n.jsx(S.IconPlus,{size:16}),onClick:t.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:e("panel.variable.add")})]}),n.jsx(s.Divider,{variant:"dashed"}),t.selected?n.jsx(Tz,{uiModel:t,variable:t.selected}):n.jsx("span",{children:"Select or create a new variable on right side"})]})}),Dz={root:{flexGrow:1,width:"100%",minWidth:"1200px",overflow:"hidden"},panel:{width:"100%",minWidth:"1200px",height:"calc(100% - 44px)",padding:10,overflow:"auto"}},ja=({children:e})=>n.jsxs(s.Group,{wrap:"nowrap",grow:!0,justify:"flex-start",gap:20,sx:{width:"100%",height:"100%",position:"relative"},children:[n.jsx(s.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),n.jsxs(s.Stack,{justify:"flex-start",sx:{alignSelf:"flex-start",width:"600px",flexGrow:0,flexShrink:0},children:[n.jsx(gz,{}),n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(wz,{})})]})]});function Iz(e){return!["richText","button"].includes(e)}const Mz=T.observer(({panel:e})=>{const{t}=x.useTranslation(),r=ze.useModals(),a=W(),l=F(),[o,i]=h.useState(a.editor.panelTab),c=e.queries,u=Iz(e.viz.type)&&e.dataLoading,p=u||e.queryErrors.length>0||e.queryStateMessages!==""||c.length===0,f=a.editor.path[1];h.useEffect(()=>{i(m=>p&&m==="Visualization"?"Data":m)},[e.id,p]);const v=h.useCallback(m=>{i(m),a.editor.setPanelTab(o)},[]),_=()=>{a.editor.setPath(["_VIEWS_",f])},w=()=>r.openConfirmModal({title:`${t("panel.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{l.removePanelByID(e.id,f),_()},confirmProps:{color:"red"},zIndex:320});return n.jsxs(Yn,{value:{panel:e,data:e.data,loading:u,errors:e.queryErrors,downloadPanelScreenshot:()=>{}},children:[n.jsxs(s.Group,{px:16,justify:"space-between",sx:{borderBottom:"1px solid #eee"},children:[n.jsx(s.Text,{size:"sm",pt:9,pb:8,children:e.name}),n.jsxs(s.Group,{justify:"flex-end",wrap:"nowrap",children:[n.jsx(xz,{panel:e,sourceViewID:f}),n.jsx(s.Button,{size:"xs",variant:"subtle",color:"red",onClick:w,leftSection:n.jsx(S.IconTrash,{size:14}),children:t("panel.delete")})]})]}),n.jsxs(s.Tabs,{value:o,onChange:v,keepMounted:!1,styles:Dz,children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"Data",leftSection:n.jsx(S.IconDatabase,{size:14}),disabled:u,children:t("data.label")}),n.jsx(s.Tabs.Tab,{value:"Panel",leftSection:n.jsx(S.IconAppWindow,{size:14}),children:t("panel.label")}),n.jsx(s.Tabs.Tab,{value:"Variables",leftSection:n.jsx(S.IconVariable,{size:14}),disabled:p,children:n.jsx(s.Tooltip,{label:t("data.requires_data"),disabled:!p,withinPortal:!0,zIndex:310,children:n.jsx(s.Text,{size:"sm",children:t("panel.variable.labels")})})}),n.jsx(s.Tabs.Tab,{value:"Visualization",leftSection:n.jsx(S.IconChartHistogram,{size:14}),disabled:p,children:n.jsx(s.Tooltip,{label:t("data.requires_data"),disabled:!p,withinPortal:!0,zIndex:310,children:n.jsx(s.Text,{size:"sm",children:t("visualization.label")})})}),n.jsx(s.Tabs.Tab,{value:"Interactions",leftSection:n.jsx(S.IconRoute,{size:14}),children:t("interactions.label")})]}),n.jsxs(s.Tabs.Panel,{value:"Data",children:[n.jsx(s.LoadingOverlay,{visible:u,transitionProps:{exitDuration:0}}),n.jsx(pz,{})]}),n.jsx(s.Tabs.Panel,{value:"Panel",children:n.jsx(ja,{children:n.jsx(sz,{})})}),n.jsx(s.Tabs.Panel,{value:"Variables",children:n.jsx(ja,{children:n.jsx(zz,{})})}),n.jsx(s.Tabs.Panel,{value:"Visualization",children:n.jsx(ne,{children:n.jsx(ja,{children:n.jsx(_z,{})})})}),n.jsx(s.Tabs.Panel,{value:"Interactions",children:n.jsx(ne,{children:n.jsx(Vh,{})})})]})]})}),Az=T.observer(({viewID:e,panelID:t})=>{const r=F();if(!r.views.findByID(e))return n.jsxs(s.Text,{size:"14px",children:["View by ID[",e,"] is not found"]});const l=r.panels.findByID(t);return l?n.jsx(Mz,{panel:l}):n.jsxs(s.Text,{size:"14px",children:["Panel by ID[",t,"] is not found"]})}),Pz=T.observer(()=>{const{t:e}=x.useTranslation(),[t,r]=h.useState([]),a=ze.useModals(),l=W(),o=v=>{l.editor.setPath(["_QUERIES_",v])},i=()=>{a.openConfirmModal({title:"Delete ununsed queries?",children:n.jsx(s.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>l.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},c=()=>{l.content.queries.downloadSchema(t)},d=h.useMemo(()=>l.content.queries.sortedList.map(v=>v.id),[l.content.queries.sortedList]),u=()=>{r(d)},p=()=>{r([])},f=l.content.queriesUsage;return n.jsxs(s.Stack,{sx:{height:"100%"},gap:"sm",pb:"59px",children:[n.jsx(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:n.jsx(s.Text,{px:"md",ta:"left",sx:{userSelect:"none",cursor:"default"},children:e("query.manage")})}),n.jsxs(s.Flex,{justify:"space-between",align:"center",px:12,children:[n.jsxs(s.Group,{justify:"flex-start",children:[n.jsxs(s.Button.Group,{children:[n.jsx(s.Button,{variant:"default",size:"xs",onClick:u,children:e("common.actions.select_all")}),n.jsx(s.Button,{variant:"default",size:"xs",onClick:p,children:e("common.actions.clear_selection")})]}),n.jsx(s.Button,{size:"xs",color:"blue",leftSection:n.jsx(S.IconCode,{size:14}),disabled:t.length===0,onClick:c,children:e("common.actions.download_schema")})]}),n.jsx(s.Button,{variant:"subtle",size:"xs",color:"red",leftSection:n.jsx(S.IconTrash,{size:14}),disabled:!l.content.hasUnusedQueries,onClick:i,children:e("query.delete_unused")})]}),n.jsx(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:n.jsx(s.Checkbox.Group,{size:"xs",value:t,onChange:r,children:n.jsxs(s.Table,{fz:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"40px"}}),n.jsx(s.Table.Th,{children:e("common.name")}),n.jsx(s.Table.Th,{style:{width:"200px"},children:e("data_source.label")}),n.jsx(s.Table.Th,{style:{width:"100px",textAlign:"right"},children:e("common.type")}),n.jsx(s.Table.Th,{style:{width:"100px",textAlign:"center"},children:e("query.usage.label")}),n.jsx(s.Table.Th,{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),n.jsx(s.Table.Tbody,{children:l.content.queries.sortedList.map(v=>{var w;const _=((w=f[v.id])==null?void 0:w.length)??0;return n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:n.jsx(s.Checkbox,{value:v.id,styles:{input:{cursor:"pointer"}}})}),n.jsx(s.Table.Td,{children:v.name}),n.jsx(s.Table.Td,{children:v.key}),n.jsx(s.Table.Td,{style:{textAlign:"right"},children:v.type}),n.jsx(s.Table.Td,{style:{color:_===0?"#ff0000":"#000",fontWeight:_===0?"bold":"normal",textAlign:"center"},children:_}),n.jsx(s.Table.Td,{children:n.jsx(s.Button,{variant:"subtle",size:"xs",onClick:()=>o(v.id),children:e("common.actions.open")})})]},v.id)})})]})})})]})}),Vz=e=>{const{t}=x.useTranslation(),{queryModel:r}=e,a=W(),l=F(),i=l.findQueryUsage(r.id).length>0,c=ze.useModals(),d=()=>{c.openConfirmModal({title:`${t("query.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{l.queries.removeQuery(r.id),a.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return i?n.jsx(s.Tooltip,{label:t("query.cant_delete"),withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,zIndex:320,position:"top-end",children:n.jsx(s.Box,{sx:{alignSelf:"flex-end"},children:n.jsx(s.Button,{disabled:!0,size:"xs",leftSection:n.jsx(S.IconTrash,{size:16}),children:t("query.delete")})})}):n.jsx(s.Button,{color:"red",size:"xs",onClick:d,leftSection:n.jsx(S.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:t("query.delete")})},$z=T.observer(Vz),Lc=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:r,count:a,spacing:l=16,pl:o=0})=>n.jsxs(s.Stack,{gap:l,mt:6,pl:o,children:[Array.from(new Array(a-1),(i,c)=>n.jsx(s.Skeleton,{width:e,height:r,radius:"xs"},c)),n.jsx(s.Skeleton,{width:t,height:r,radius:"xs"})]}),Yt=({value:e})=>e===null||e===""?null:n.jsx(s.Tooltip,{label:e,disabled:!e,multiline:!0,zIndex:340,children:n.jsx(s.ActionIcon,{variant:"subtle",children:n.jsx(S.IconInfoCircle,{size:14})})}),Ez=({column:e})=>{const{column_key:t,column_key_text:r}=e;return t?n.jsx(s.Tooltip,{label:r,disabled:!r,children:n.jsx(s.Badge,{variant:"light",children:t})}):null},Bz=T.observer(({dataSource:e})=>{const{columns:t}=e.dbInfo;return t.loading?n.jsx(Lc,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:n.jsxs(s.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:50}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:30}}),n.jsx("col",{style:{width:70}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{minWidth:80,width:80}}),n.jsx("col",{style:{minWidth:120,width:120}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"#"}),n.jsx(s.Table.Th,{children:"Column Name"}),n.jsx(s.Table.Th,{}),n.jsx(s.Table.Th,{}),n.jsx(s.Table.Th,{children:"Type"}),n.jsx(s.Table.Th,{children:"Nullable"}),n.jsx(s.Table.Th,{children:"Default Value"})]})}),n.jsx(s.Table.Tbody,{children:t.data.map(r=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:r.ordinal_position}),n.jsx(s.Table.Td,{children:r.column_name}),n.jsx(s.Table.Td,{children:n.jsx(Yt,{value:r.column_comment})}),n.jsx(s.Table.Td,{children:n.jsx(Ez,{column:r})}),n.jsx(s.Table.Td,{children:r.column_type}),n.jsx(s.Table.Td,{children:r.is_nullable}),n.jsx(s.Table.Td,{children:n.jsx(Yt,{value:r.column_default})})]},r.column_name))})]})}),Lz=T.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo,r=t.data;return n.jsxs(s.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:250}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"Index Length"}),n.jsx(s.Table.Th,{children:"Index Name"}),n.jsx(s.Table.Th,{children:"Index Algorithm"}),n.jsx(s.Table.Th,{children:"Unique"}),n.jsx(s.Table.Th,{children:"Column Name"})]})}),n.jsx(s.Table.Tbody,{children:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.index_length}),n.jsx(s.Table.Td,{children:a.index_name}),n.jsx(s.Table.Td,{children:a.index_algorithm}),n.jsx(s.Table.Td,{children:a.is_unique?"YES":"NO"}),n.jsx(s.Table.Td,{children:a.column_name})]},a.index_name))})]})}),qz=T.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo,r=t.data;return n.jsxs(s.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"Index Name"}),n.jsx(s.Table.Th,{children:"Index Algorithm"}),n.jsx(s.Table.Th,{children:"Unique"}),n.jsx(s.Table.Th,{children:"Definition"}),n.jsx(s.Table.Th,{children:"Condition"}),n.jsx(s.Table.Th,{children:"Comment"})]})}),n.jsx(s.Table.Tbody,{children:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.index_name}),n.jsx(s.Table.Td,{children:a.index_algorithm}),n.jsx(s.Table.Td,{children:a.is_unique?"YES":"NO"}),n.jsx(s.Table.Td,{children:n.jsx(Yt,{value:a.index_definition})}),n.jsx(s.Table.Td,{children:n.jsx(Yt,{value:a.condition})}),n.jsx(s.Table.Td,{children:n.jsx(Yt,{value:a.comment})})]},a.index_name))})]})}),Oz=T.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo;return t.loading||t.empty?null:e.type===j.MySQL?n.jsx(Lz,{dataSource:e}):e.type===j.Postgresql?n.jsx(qz,{dataSource:e}):null}),Nz=T.observer(({dataSource:e})=>n.jsxs(s.Stack,{gap:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[n.jsx(ne,{children:n.jsx(Bz,{dataSource:e})}),n.jsx(ne,{children:n.jsx(Oz,{dataSource:e})})]}));function Gz({table_type:e}){return e==="VIEW"?n.jsx(S.IconEye,{size:14}):e==="BASE TABLE"?n.jsx(S.IconTable,{size:14}):null}const Fz=T.observer(({dataSource:e})=>{const t=e.dbInfo,{tables:r}=t;return r.loading?n.jsx(Lc,{height:"24px",lastWidth:"50%",count:15}):n.jsx(s.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(r.data).map(([a,l])=>n.jsx(s.NavLink,{label:a,title:a,leftSection:n.jsx(S.IconDatabase,{size:14}),defaultOpened:t.table_schema===a,pl:0,childrenOffset:14,children:l.map(o=>n.jsx(s.NavLink,{label:o.table_name,title:o.table_name,leftSection:n.jsx(Gz,{table_type:o.table_type}),onClick:()=>{t.setKeywords(a,o.table_name)},active:t.table_name===o.table_name},o.table_name))},a))})}),jz=({visible:e})=>n.jsx(s.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:n.jsx(s.LoadingOverlay,{visible:e})}),Qz=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],Wz={section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px"}},Uz=T.observer(({dataSource:e})=>{const{t}=x.useTranslation(),{tableData:r}=e.dbInfo;return n.jsxs(s.Group,{pt:10,px:10,justify:"space-between",children:[n.jsxs(s.Group,{justify:"flex-start",children:[r.maxPage>1&&n.jsx(s.Pagination,{size:"sm",value:r.page,onChange:r.setPage,total:r.maxPage,withEdges:r.maxPage>7,styles:{control:{height:"30px"}}}),n.jsx(s.Select,{leftSection:n.jsx(s.Text,{ta:"center",c:"dimmed",size:"14px",children:t("common.pagination.page_size")}),size:"xs",styles:Wz,data:Qz,value:String(r.limit),onChange:a=>r.setLimit(Number(a)),comboboxProps:{zIndex:340}})]}),n.jsx(s.Group,{justify:"flex-end",children:n.jsx(s.Text,{c:"dimmed",my:0,size:"14px",children:t("common.pagination.total_rows",{total:r.total})})})]})}),Yz=T.observer(({dataSource:e})=>{const t=e.dbInfo.tableData;return t.maxPage===0?n.jsx(s.Text,{mt:20,c:"red",size:"md",ta:"center",ff:"monospace",children:"This table is empty"}):t.error?n.jsx(s.Text,{mt:20,c:"red",size:"md",ta:"center",ff:"monospace",children:t.error}):t.page===1&&t.loading?n.jsx(jz,{visible:!0}):n.jsxs(ne,{children:[n.jsx(Uz,{dataSource:e}),n.jsxs(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n.jsx(s.LoadingOverlay,{visible:t.loading,overlayProps:{blur:2}}),n.jsx(Ec,{data:t.data})]})]})}),Kz={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},Xz=T.observer(({dataSource:e})=>{const{t}=x.useTranslation(),r=e.dbInfo;return h.useEffect(()=>{r.loadTablesIfEmpty()},[r]),r.tables.error?n.jsx(s.Text,{c:"red",size:"md",ta:"center",ff:"monospace",children:r.tables.error}):n.jsxs(s.Flex,{sx:{height:"100%"},children:[n.jsx(s.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:n.jsx(ne,{children:n.jsx(Fz,{dataSource:e})})}),n.jsxs(s.Tabs,{defaultValue:"structure",styles:Kz,children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"structure",leftSection:n.jsx(S.IconColumns,{size:14}),children:t("data_source.table_structure_short")}),n.jsx(s.Tabs.Tab,{value:"data",leftSection:n.jsx(S.IconDatabase,{size:14}),children:t("data.label")})]}),n.jsx(s.Tabs.Panel,{value:"structure",children:n.jsx(Nz,{dataSource:e})}),n.jsx(s.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:n.jsx(Yz,{dataSource:e})})]})]})}),Zz={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"20px 20px 10px",borderBottom:"1px solid #efefef",gap:"20px"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},qc=T.observer(({dataSource:e,triggerButtonProps:t={}})=>{const{t:r}=x.useTranslation(),[a,l]=h.useState(!1),{type:o}=e;return o==="http"||o==="merico_metric_system"?null:n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:a,onClose:()=>l(!1),title:n.jsxs(s.Group,{justify:"space-between",sx:{flexGrow:1},children:[n.jsx(s.Text,{size:"sm",fw:500,children:r("data_source.explorer")}),n.jsxs(s.Group,{gap:7,children:[n.jsx(s.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),n.jsx(s.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",styles:Zz,children:n.jsx(s.Box,{sx:{height:"calc(100vh - 220px)"},children:n.jsx(Xz,{dataSource:e})})}),n.jsx(s.Button,{variant:"subtle",onClick:()=>l(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:r("data_source.see_table_structure")})]})}),Oc={http:"HTTP",mysql:"MySQL",postgresql:"PostgreSQL",merico_metric_system:"指标系统"},Jz=({option:e,...t})=>{const{label:r,type:a}=e;return a===j.Transform?n.jsxs(s.Group,{className:"transform-query-option",justify:"flex-start",...t,sx:{flexGrow:1,'&[data-selected="true"]':{".mantine-Text-root":{color:"white"},svg:{stroke:"white"}}},children:[n.jsx(S.IconVectorTriangle,{size:14,color:"#228be6"}),n.jsx(s.Text,{size:"sm",c:"blue",children:r})]}):n.jsxs(s.Group,{justify:"space-between",...t,sx:{flexGrow:1},children:[n.jsx(s.Text,{size:"sm",children:r}),n.jsx(s.Text,{size:"sm",children:Oc[a]})]})},Nc=T.observer(({queryModel:e,size:t="sm"})=>{const{t:r}=x.useTranslation(),a=W(),{data:l=[],loading:o}=O.useRequest(Ca,{refreshDeps:[]},[]),i=h.useMemo(()=>{const p=l.map(f=>({label:f.key,value:f.key,type:f.type}));return p.push({label:r("query.transform.data_source"),value:j.Transform,type:j.Transform}),p},[l]),c=h.useMemo(()=>i.reduce((p,f)=>(p[f.value]=f.type,p),{}),[i]),d=p=>{p!==null&&(e.setKey(p),e.setType(c[p]))},u=h.useMemo(()=>a.datasources.find({type:e.type,key:e.key}),[a,e.type,e.key]);return n.jsx(s.Select,{size:t,data:i,label:n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Box,{children:r("data_source.label")}),u&&n.jsx(qc,{dataSource:u,triggerButtonProps:{size:"compact-xs",px:10}})]}),renderOption:Jz,rightSection:u?n.jsx(s.Text,{size:"xs",c:"dimmed",children:Oc[u.type]??u.type}):void 0,rightSectionWidth:85,maxDropdownHeight:500,styles:{root:{flex:1,minWidth:"300px"},label:{display:"block"},section:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:o,value:e.key,onChange:d})}),Hz=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),[r,a]=h.useState(e.name);h.useEffect(()=>{a(e.name)},[e.name]);const l=h.useMemo(()=>e.conditionOptionsWithInvalidRunbys.optionGroups.map(i=>({group:t(i.group),items:i.items})),[e.conditionOptionsWithInvalidRunbys.optionGroups]);return n.jsx(s.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:n.jsxs(s.Stack,{gap:10,sx:{width:"100%"},children:[n.jsx(s.Divider,{mb:-10,variant:"dashed",label:t("query.basics"),labelPosition:"center"}),n.jsx(s.TextInput,{placeholder:t("query.name_description"),label:t("query.name"),required:!0,sx:{flex:1},value:r,onChange:o=>{a(o.currentTarget.value)},rightSection:n.jsx(s.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(r),disabled:r===e.name,children:n.jsx(S.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(r)}}),n.jsx(Nc,{queryModel:e}),n.jsx(s.Divider,{mt:10,mb:-10,variant:"dashed",label:t("query.conditions"),labelPosition:"center"}),n.jsx(s.MultiSelect,{label:t("query.run_by_condition.label"),description:t("query.run_by_condition.description"),placeholder:t("query.run_by_condition.unset"),data:l,value:[...e.run_by],onChange:e.setRunBy,renderOption:rr,maxDropdownHeight:500}),e.typedAsHTTP&&n.jsx(s.MultiSelect,{label:t("query.re_run_condition.label"),placeholder:t("query.re_run_condition.label"),data:l,value:[...e.config.react_to],onChange:e.config.setReactTo,renderOption:rr,maxDropdownHeight:500}),e.isTransform&&n.jsx(s.MultiSelect,{label:t("query.re_run_condition.label"),placeholder:t("query.re_run_condition.label"),data:l,value:[...e.config.react_to],onChange:e.config.setReactTo,renderOption:rr,maxDropdownHeight:500}),n.jsx(s.Divider,{mt:20,mb:10,variant:"dashed"}),n.jsx($z,{queryModel:e})]})})});function Rz({content:e}){return n.jsxs(s.HoverCard,{width:"60vw",shadow:"md",zIndex:340,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.ActionIcon,{size:16,color:"blue",variant:"subtle",children:n.jsx(S.IconEye,{})})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(Oe.CodeHighlight,{language:"sql",withCopyButton:!1,code:e})})]})}const e3=T.observer(()=>{const t=[...W().globalSQLSnippets.list];return t.length===0?null:n.jsxs(s.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fz:"sm",highlightOnHover:!0,children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"Key"}),n.jsx(s.Table.Th,{children:"Value"})]})}),n.jsx(s.Table.Tbody,{children:t.map(r=>{const{id:a,content:l}=r;return n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a}),n.jsx(s.Table.Td,{width:200,children:n.jsx(Rz,{content:l})})]},a)})})]})}),t3=`
553
+ `,Ec=()=>{const{t:e}=x.useTranslation(),[t,r]=h.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{variant:"subtle",size:"compact-sm",onClick:()=>r(a=>!a),children:e(t?"common.actions.close":"filter.widget.common.see_data_structure")}),n.jsx(s.Collapse,{in:t,children:n.jsx(Le.CodeHighlight,{language:"typescript",withCopyButton:!1,code:Wk})})]})},Uk=T.observer(function({filter:t}){const{t:r}=x.useTranslation(),a=t.config,l=()=>{a.addStaticOption({label:"",value:""})},o=a.static_options,i=o.filter(c=>c.value!==""&&c.label!=="");return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Checkbox,{checked:a.required,onChange:c=>a.setRequired(c.currentTarget.checked),label:r("filter.widget.select.required")}),n.jsx(St,{filter:t})]}),n.jsx(s.TextInput,{label:r("filter.widget.select.width"),description:r("filter.widget.multi_select.width_description"),value:a.min_width,onChange:c=>a.setMinWidth(c.currentTarget.value),placeholder:"200px"}),n.jsx(s.Divider,{label:r("filter.widget.select.configure_options"),labelPosition:"center"}),n.jsxs(s.Stack,{gap:10,sx:{position:"relative",minHeight:"50px"},children:[a.usingQuery&&n.jsxs(n.Fragment,{children:[n.jsx(s.Overlay,{backgroundOpacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),n.jsx(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:n.jsx(s.Text,{c:"white",size:"16px",children:r("filter.widget.common.using_query")})})]}),i.length>0&&n.jsx(s.MultiSelect,{label:r("filter.widget.select.default_selection"),placeholder:r("filter.widget.select.no_default_selection"),data:i,value:[...a.default_value],onChange:a.setDefaultValue}),o.map((c,d)=>n.jsxs(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[n.jsx(s.TextInput,{label:r("common.label"),required:!0,value:a.static_options[d].label,onChange:u=>{a.static_options[d].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.TextInput,{label:r("common.value"),required:!0,value:a.static_options[d].value,onChange:u=>{a.static_options[d].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>a.removeStaticOption(d),sx:{position:"absolute",top:28,right:5},children:n.jsx(S.IconTrash,{size:16})})]},d)),n.jsx(s.Button,{mt:10,size:"xs",color:"blue",leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),onClick:l,sx:{width:"50%"},mx:"auto",children:r("common.actions.add_an_option")})]}),n.jsx(s.Divider,{label:r("filter.widget.common.or_fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(Cn,{value:a.options_query_id,onChange:a.setOptionsQueryID}),n.jsx(s.NumberInput,{value:a.default_selection_count,onChange:a.setDefaultSelectionCount,label:r("filter.widget.common.default_selection_count")}),n.jsx(ia,{config:a}),n.jsx(Ec,{})]})}),Bc={date_unit:{zh:[{label:"天",value:"day"},{label:"周",value:"week"},{label:"双周",value:"bi-week"},{label:"月",value:"month"},{label:"季度",value:"quarter"},{label:"年",value:"year"}],en:[{label:"Day",value:"day"},{label:"Week",value:"week"},{label:"Bi-Week",value:"bi-week"},{label:"Month",value:"month"},{label:"Quarter",value:"quarter"},{label:"Year",value:"year"}]}},Lc=T.observer(({config:e})=>{const{t,i18n:r}=x.useTranslation(),a=()=>{e.addStaticOption({label:"",value:""})},l=h.useMemo(()=>[{label:t("filter.widget.select.preset_options.date_unit"),value:"date_unit"}],[r.language]),o=i=>{if(!i||!(i in Bc))return;const c=Bc[i][r.language];e.replaceStaticOptions(c),c.length>0&&e.setDefaultValue(c[0].value)};return n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{size:"xs",color:"blue",leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),onClick:a,children:t("common.actions.add_an_option")}),n.jsx(s.Select,{placeholder:t("filter.widget.select.preset_options.apply"),value:null,onChange:o,data:l,size:"xs"})]})}),Kk=T.observer(({config:e})=>{const{t,i18n:r}=x.useTranslation(),a=[...e.static_options],l=h.useMemo(()=>[{label:t("filter.widget.select.no_default_selection"),value:""},...a.filter(o=>o.value!=="")],[r.language,a]);return a.length===0?n.jsx(Lc,{config:e}):n.jsxs(n.Fragment,{children:[n.jsx(s.Select,{label:t("filter.widget.select.default_selection"),data:l,value:e.default_value,onChange:e.setDefaultValue}),a.map((o,i)=>n.jsxs(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[n.jsx(s.TextInput,{label:t("common.label"),required:!0,value:e.static_options[i].label,onChange:c=>{e.static_options[i].setLabel(c.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.TextInput,{label:t("common.value"),required:!0,value:e.static_options[i].value,onChange:c=>{e.static_options[i].setValue(c.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.removeStaticOption(i),sx:{position:"absolute",top:28,right:5},children:n.jsx(S.IconTrash,{size:16})})]},i)),n.jsx(Lc,{config:e})]})}),Yk=T.observer(({filter:e})=>{const{t}=x.useTranslation(),r=e.config;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Checkbox,{checked:r.required,onChange:a=>r.setRequired(a.currentTarget.checked),label:t("filter.widget.select.required")}),n.jsx(s.Checkbox,{checked:r.clearable,onChange:a=>r.setClearable(a.currentTarget.checked),label:t("filter.widget.select.clearable")}),n.jsx(St,{filter:e})]}),n.jsx(s.TextInput,{label:t("filter.widget.select.width"),value:r.width,onChange:a=>r.setWidth(a.currentTarget.value),placeholder:"200px"}),n.jsx(s.Divider,{label:t("filter.widget.select.configure_options"),labelPosition:"center"}),n.jsxs(s.Stack,{gap:10,sx:{position:"relative",minHeight:"50px"},children:[r.usingQuery&&n.jsxs(n.Fragment,{children:[n.jsx(s.Overlay,{backgroundOpacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),n.jsx(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:n.jsx(s.Text,{c:"white",size:"16px",children:t("filter.widget.common.using_query")})})]}),n.jsx(Kk,{config:r})]}),n.jsx(s.Divider,{label:t("filter.widget.common.or_fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(s.Checkbox,{checked:r.default_selection_count===1,onChange:a=>r.setDefaultSelectionCount(a.currentTarget.checked?1:0),label:t("filter.widget.select.select_first_option_by_default")}),n.jsx(Cn,{value:r.options_query_id,onChange:r.setOptionsQueryID}),n.jsx(Ec,{})]})}),Xk=T.observer(function({filter:t}){const{t:r}=x.useTranslation(),a=t.config;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{children:[n.jsx(s.TextInput,{label:r("filter.widget.text_input.default_value"),value:a.default_value,onChange:l=>{a.setDefaultValue(l.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.Box,{mt:22,children:n.jsx(St,{filter:t})})]}),n.jsx(s.Checkbox,{checked:a.required,onChange:l=>a.setRequired(l.currentTarget.checked),label:r("filter.widget.text_input.required")})]})}),Zk=T.observer(({filter:e})=>{const{t}=x.useTranslation(),r=W().editor,a=e.usages,l=o=>{switch(o.type){case"query":r.setPath(["_QUERIES_",o.id]);break;case"sql_snippet":r.setPath(["_SQL_SNIPPETS_",o.id]);break;case"view":r.setPath(["_VIEWS_",o.id]);default:return}};return a.length===0?n.jsx(s.Text,{mt:10,ml:10,size:"sm",children:t("filter.usage.unused_description")}):n.jsxs(s.Table,{highlightOnHover:!0,layout:"fixed",styles:{table:{fontSize:"14px"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:80}}),n.jsx("col",{})]}),n.jsx(s.Table.Tbody,{children:a.map(o=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:n.jsx(s.Text,{size:"xs",children:t(o.type_label)})}),n.jsx(s.Table.Td,{children:n.jsx(s.Anchor,{size:"xs",title:o.label,onClick:()=>l(o),children:n.jsx(s.Text,{truncate:"end",children:o.label})})})]},o.id))})]})}),Jk=T.observer(({filter:e})=>{const{t}=x.useTranslation();return n.jsxs(s.Tabs,{defaultValue:"usage",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"config",children:t("common.titles.config")}),n.jsx(s.Tabs.Tab,{value:"usage",children:t("filter.usage.label")})]}),n.jsx(s.Tabs.Panel,{value:"config",children:n.jsx(s.Box,{sx:{minWidth:"480px"},children:n.jsx(Le.CodeHighlight,{mt:22,language:"json",withCopyButton:!1,code:JSON.stringify(e,null,4)})})}),n.jsx(s.Tabs.Panel,{value:"usage",children:n.jsx(Zk,{filter:e})})]})}),Hk={[A.Select]:Yk,[A.MultiSelect]:Uk,[A.TreeSelect]:VS,[A.TreeSingleSelect]:OS,[A.TextInput]:Xk,[A.Checkbox]:Fk,[A.DateRange]:Qk},st={[A.Select]:"filter.widget.names.select",[A.MultiSelect]:"filter.widget.names.multi_select",[A.TreeSelect]:"filter.widget.names.tree_select",[A.TreeSingleSelect]:"filter.widget.names.tree_single_select",[A.TextInput]:"filter.widget.names.text_input",[A.Checkbox]:"filter.widget.names.checkbox",[A.DateRange]:"filter.widget.names.date_range"},Rk=T.observer(({filter:e})=>{const{t,i18n:r}=x.useTranslation(),a=F(),l=h.useMemo(()=>Hk[e.type],[e.type]),o=h.useMemo(()=>[{label:t(st[A.Select]),value:"select"},{label:t(st[A.MultiSelect]),value:"multi-select"},{label:t(st[A.TreeSelect]),value:"tree-select"},{label:t(st[A.TreeSingleSelect]),value:"tree-single-select"},{label:t(st[A.TextInput]),value:"text-input"},{label:t(st[A.Checkbox]),value:"checkbox"},{label:t(st[A.DateRange]),value:"date-range"}],[r.language]);return n.jsxs(s.Group,{grow:!0,gap:20,align:"top",children:[n.jsxs(s.Box,{w:600,children:[n.jsx(s.Text,{pb:"md",c:"gray",size:"sm",children:t("common.titles.edit")}),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{wrap:"nowrap",children:[n.jsx(s.NumberInput,{label:t("filter.field.order"),required:!0,value:e.order,onChange:e.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),e.auto_submit_supported&&n.jsx(s.Checkbox,{label:t("filter.field.auto_submit"),checked:e.auto_submit,onChange:i=>e.setAutoSubmit(i.currentTarget.checked),mt:22})]}),n.jsx(s.MultiSelect,{label:t("filter.field.visible_in"),data:a.views.options,value:[...e.visibleInViewsIDs],onChange:e.setVisibleInViewsIDs}),n.jsx(s.TextInput,{label:t("common.key"),placeholder:t("filter.field.key_placeholder"),required:!0,value:e.key,onChange:i=>{e.setKey(i.currentTarget.value)}}),n.jsx(s.TextInput,{label:t("common.label"),placeholder:t("filter.field.label_placeholder"),required:!0,value:e.label,onChange:i=>{e.setLabel(i.currentTarget.value)}}),n.jsx(s.Select,{label:t("filter.field.widget"),data:o,required:!0,value:e.type,onChange:e.setType,maxDropdownHeight:500}),n.jsx(s.Divider,{mb:0,mt:10,variant:"dashed",labelPosition:"center"}),n.jsx(l,{filter:e})]})]}),n.jsx(Jk,{filter:e})]})}),ez=T.observer(({id:e})=>{const{t}=x.useTranslation(),r=Te.useModals(),a=W(),l=F();if(e==="")return null;const o=l.filters.findByID(e);if(!o)return n.jsxs(s.Text,{size:"14px",children:["Filter by ID[",e,"] is not found"]});const i=()=>{a.editor.setPath(["_FILTERS_",""])},c=()=>{r.openConfirmModal({title:`${t("filter.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{l.filters.removeByID(e),i()},confirmProps:{color:"red"},zIndex:320})};return n.jsxs(s.Stack,{sx:{minWidth:"1100px",height:"100vh"},gap:"sm",pb:30,children:[n.jsx(s.Group,{justify:"flex-end",pt:10,children:n.jsx(s.Button,{size:"xs",color:"red",leftSection:n.jsx(S.IconTrash,{size:16}),onClick:c,children:t("filter.delete")})}),n.jsx(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:n.jsx(Rk,{filter:o})})]})}),tz=T.observer(()=>{const{t:e}=x.useTranslation(),[t,r]=h.useState([]),a=W(),l=u=>{a.editor.setPath(["_FILTERS_",u])},o=()=>{a.content.filters.downloadSchema(t)},i=h.useMemo(()=>a.content.filters.sortedList.map(u=>u.id),[a.content.filters.sortedList]),c=()=>{r(i)},d=()=>{r([])};return n.jsxs(s.Stack,{sx:{height:"100%"},gap:"sm",pb:"59px",children:[n.jsx(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:n.jsx(s.Text,{size:"sm",px:"md",ta:"left",sx:{userSelect:"none",cursor:"default"},children:e("filter.manage")})}),n.jsx(s.Flex,{justify:"space-between",align:"center",px:12,children:n.jsxs(s.Group,{justify:"flex-start",children:[n.jsxs(s.Button.Group,{children:[n.jsx(s.Button,{variant:"default",size:"xs",onClick:c,children:e("common.actions.select_all")}),n.jsx(s.Button,{variant:"default",size:"xs",onClick:d,children:e("common.actions.clear_selection")})]}),n.jsx(s.Button,{size:"xs",color:"blue",leftSection:n.jsx(S.IconCode,{size:14}),disabled:t.length===0,onClick:o,children:e("common.actions.download_schema")})]})}),n.jsx(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:n.jsx(s.Checkbox.Group,{size:"xs",value:t,onChange:r,children:n.jsxs(s.Table,{fz:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"40px"}}),n.jsx(s.Table.Th,{style:{width:"300px"},children:e("common.label")}),n.jsx(s.Table.Th,{children:e("common.key")}),n.jsx(s.Table.Th,{style:{width:"100px"},children:e("filter.field.widget")}),n.jsx(s.Table.Th,{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),n.jsx(s.Table.Tbody,{children:a.content.filters.sortedList.map(u=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:n.jsx(s.Checkbox,{value:u.id,styles:{input:{cursor:"pointer"}}})}),n.jsx(s.Table.Td,{children:u.label}),n.jsx(s.Table.Td,{children:u.key}),n.jsx(s.Table.Td,{children:e(st[u.type])}),n.jsx(s.Table.Td,{children:n.jsx(s.Button,{variant:"subtle",size:"xs",onClick:()=>l(u.id),children:e("common.actions.open")})})]},u.id))})]})})})]})}),nz=T.observer(()=>{const{t:e}=x.useTranslation(),t=F(),[r,a]=h.useState(()=>JSON.stringify(t.mock_context.current,null,4)),l=()=>{try{t.mock_context.replace(JSON.parse(r))}catch(i){Ye.showNotification({title:"Failed",message:i.message,color:"red"})}},o=h.useMemo(()=>{try{return JSON.stringify(JSON.parse(r))!==JSON.stringify(t.mock_context.current)}catch{return!1}},[r,t.mock_context.current]);return n.jsxs(s.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[n.jsx(s.Group,{justify:"flex-start",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:n.jsx(s.Text,{size:"sm",fw:500,children:e("mock_context.label")})}),n.jsx(s.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:n.jsxs(s.Stack,{gap:10,sx:{maxWidth:"unset !important"},children:[n.jsxs(s.Group,{justify:"flex-start",children:[n.jsx(s.Text,{size:"sm",children:e("mock_context.hint")}),n.jsx(s.Button,{color:"green",size:"compact-sm",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:l,disabled:!o,children:e("common.actions.save")})]}),n.jsx(s.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:r,onChange:a,sx:{flexGrow:1}})]})})]})}),rz=T.observer(()=>{const{t:e}=x.useTranslation(),{panel:t}=re();return n.jsx(pt,{label:e("panel.panel_description"),value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1}}},t.id)}),az=T.observer(()=>{const{t:e}=x.useTranslation(),{panel:t}=re(),r=J().layouts.findItemByPanelID(t.id),{style:a}=t;return n.jsx(n.Fragment,{children:n.jsxs(s.Stack,{gap:20,children:[n.jsxs(s.Group,{grow:!0,align:"top",children:[n.jsx(s.NumberInput,{label:e("panel.style.width"),min:1,max:36,step:1,decimalScale:0,rightSection:n.jsx(s.Text,{size:"12px",children:e("panel.style.width_postfix")}),styles:{section:{width:"auto",maxWidth:"100px",paddingRight:"14px",justifyContent:"flex-end"}},value:r.w,onChange:l=>{typeof l!="string"&&r.setWidth(l)}}),n.jsx(s.NumberInput,{label:e("panel.style.height"),rightSection:n.jsx(s.Text,{size:"12px",children:e("panel.style.height_postfix")}),styles:{section:{width:"40px"}},value:r.h,onChange:l=>{typeof l!="string"&&r.setHeight(l)}})]}),n.jsx(s.Checkbox,{ml:6,label:e("panel.style.border"),checked:a.border.enabled,onChange:l=>a.border.setEnabled(l.currentTarget.checked)})]})})}),sz=()=>n.jsxs("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),lz=T.observer(()=>{const{t:e}=x.useTranslation(),{panel:t}=re(),{name:r}=t,[a,l]=ne.useInputState(r),o=r!==a,i=h.useCallback(()=>{o&&t.setName(a)},[o,a]);h.useEffect(()=>{l(r)},[r]);const c=!a.trim();return n.jsxs(s.Stack,{gap:4,children:[n.jsxs(s.Group,{align:"center",children:[n.jsxs(s.Text,{size:"14px",fw:500,children:[e("panel.panel_name"),n.jsx(sz,{})]}),n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",disabled:!o||c,onClick:i,children:n.jsx(S.IconDeviceFloppy,{size:18})})]}),n.jsx(s.TextInput,{value:a,onChange:l,required:!0})]})}),oz=T.observer(()=>{const{t:e}=x.useTranslation(),{panel:t}=re();return n.jsx(s.Stack,{gap:6,mb:10,children:n.jsxs(s.Group,{pl:6,justify:"flex-start",gap:20,children:[n.jsx(s.Checkbox,{size:"sm",checked:t.title.show,onChange:r=>t.title.setShow(r.currentTarget.checked),label:e("panel.show_title"),sx:{userSelect:"none"}}),n.jsx(s.Checkbox,{size:"sm",checked:!0,disabled:!0,label:e("panel.use_name_as_title")})]})})});function iz(){const{t:e}=x.useTranslation();return n.jsxs(s.Stack,{sx:{height:"100%"},children:[n.jsx(az,{}),n.jsx(s.Divider,{label:e("common.info"),labelPosition:"center",variant:"dashed"}),n.jsx(lz,{}),n.jsx(oz,{}),n.jsx(rz,{})]})}const cz={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},"th, td":{wordBreak:"break-word"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1",backgroundColor:"rgb(248, 249, 250)"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function qc({data:e}){const t=h.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const a=ge.createColumnHelper();return Object.keys(e[0]).map(l=>a.accessor(l,{cell:o=>o.getValue()}))},[e]),r=ge.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:ge.getCoreRowModel()});return e.length===0?n.jsx(s.Box,{sx:{height:"5em"}}):n.jsx(te,{children:n.jsxs(s.Table,{sx:cz,children:[n.jsx(s.Table.Thead,{children:r.getHeaderGroups().map(a=>n.jsx(s.Table.Tr,{children:a.headers.map(l=>n.jsxs(s.Table.Th,{style:{width:l.getSize()},children:[l.isPlaceholder?null:ge.flexRender(l.column.columnDef.header,l.getContext()),n.jsx(s.ActionIcon,{variant:"subtle",onMouseDown:l.getResizeHandler(),onTouchStart:l.getResizeHandler(),className:`resizer ${l.column.getIsResizing()?"isResizing":""}`,children:n.jsx(S.IconArrowBarToRight,{})})]},l.id))},a.id))}),n.jsx(s.Table.Tbody,{children:r.getRowModel().rows.map(a=>n.jsx(s.Table.Tr,{children:a.getVisibleCells().map(l=>n.jsx(s.Table.Td,{children:n.jsx(te,{children:typeof l.getValue()=="object"?n.jsx("pre",{children:JSON.stringify(l.getValue(),null,2)}):ge.flexRender(l.column.columnDef.cell,l.getContext())})},l.id))},a.id))})]})})}const dz=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],uz={section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px"}},pz=({data:e,page:t,setPage:r,limit:a,setLimit:l})=>{const{t:o}=x.useTranslation(),i=e.length,c=Math.ceil(i/a),d=p=>{p&&(r(1),l(Number(p)))};if(i===0)return null;const u=c===1&&i<=10;return n.jsxs(s.Group,{pt:10,px:10,justify:"space-between",children:[n.jsxs(s.Group,{justify:"flex-start",children:[c>1&&n.jsx(s.Pagination,{size:"sm",value:t,onChange:r,total:c,withEdges:c>7,styles:{control:{height:"30px"}}}),!u&&n.jsx(s.Select,{leftSection:n.jsx(s.Text,{ta:"center",c:"dimmed",size:"14px",children:o("common.pagination.page_size")}),size:"xs",styles:uz,data:dz,value:String(a),onChange:d})]}),n.jsx(s.Group,{justify:"flex-end",children:n.jsx(s.Text,{c:"dimmed",my:0,size:"14px",children:o("common.pagination.total_rows",{total:i})})})]})},hz=il(({data:e,loading:t})=>{const[r,a]=h.useState(1),[l,o]=h.useState(20),i=h.useMemo(()=>{const c=(r-1)*l,d=c+l;return e.slice(c,d)},[e,r,l]);return n.jsxs(te,{children:[n.jsx(pz,{data:e,page:r,setPage:a,limit:l,setLimit:o}),n.jsxs(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n.jsx(s.LoadingOverlay,{visible:t,overlayProps:{blur:2}}),n.jsx(qc,{data:i})]})]})}),gz=T.observer(({queryID:e})=>{const{t}=x.useTranslation(),r=J(),a=h.useMemo(()=>r.queries.findByID(e),[r,e]);if(!a||a.state==="loading")return null;const{error:l,metricQueryPayloadErrorString:o,stateMessage:i}=a;return l||o?n.jsx(s.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:l??o}):i?n.jsx(s.Text,{size:"sm",mt:10,c:"gray",ta:"center",children:t(i)}):null}),Fa=T.observer(({id:e,moreActions:t,refreshOnMount:r})=>{const{t:a}=x.useTranslation(),l=J(),{data:o,state:i}=l.getDataStuffByID(e),c=i==="loading",d=h.useCallback(()=>{l.queries.refetchDataByQueryID(e)},[e,l]),u=()=>{l.queries.downloadDataByQueryID(null,e)};h.useEffect(()=>{r&&d()},[d,r]);const p=!Array.isArray(o)||o.length===0;return n.jsxs(s.Stack,{gap:0,sx:{height:"100%",border:"1px solid #eee"},children:[n.jsxs(s.Group,{justify:"space-between",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(s.Text,{size:"sm",fw:500,children:a("data.preview_data")})}),n.jsxs(s.Group,{pr:15,children:[t,n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",disabled:c,onClick:d,children:n.jsx(S.IconRefresh,{size:16})}),n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",disabled:c||p,onClick:u,children:n.jsx(S.IconDownload,{size:16})})]})]}),n.jsxs(s.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[n.jsx(gz,{queryID:e}),n.jsx(hz,{data:o,loading:c})]})]})}),fz=T.observer(function(){const{t}=x.useTranslation(),r=W(),a=F(),{panel:l}=re(),[o,i]=h.useState(!1),c=u=>{r.editor.setPath(["_QUERIES_",u])},d=l.queryIDs.length;return n.jsxs(n.Fragment,{children:[n.jsx(s.Drawer,{opened:o,onClose:()=>i(!1),title:t("panel.settings.choose_queries"),padding:"xl",size:500,zIndex:320,children:n.jsx(s.Checkbox.Group,{value:[...l.queryIDs],onChange:l.setQueryIDs,children:n.jsx(s.Stack,{gap:"lg",children:a.queries.options.map(u=>n.jsx(s.Checkbox,{label:u.label,value:u.value},u.value))})})}),n.jsxs(s.Stack,{gap:6,children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(s.Button,{variant:"light",size:"sm",leftSection:n.jsx(S.IconLine,{size:16}),onClick:()=>i(!0),children:t(d===0?"panel.settings.need_to_choose_queries":"panel.settings.choose_queries")})}),d===1&&n.jsx(Fa,{id:l.queryIDs[0],moreActions:n.jsx(s.Tooltip,{label:t("query.open"),children:n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(l.queryIDs[0]),children:n.jsx(S.IconArrowCurveRight,{size:16})})})}),d>1&&n.jsxs(s.Tabs,{defaultValue:l.queryIDs[0],children:[n.jsx(s.Tabs.List,{children:l.queries.map(u=>n.jsx(s.Tabs.Tab,{value:u.id,children:u.name},u.id))}),l.queries.map(u=>n.jsx(s.Tabs.Panel,{value:u.id,children:n.jsx(Fa,{id:u.id,moreActions:n.jsx(s.Tooltip,{label:t("query.open"),children:n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(u.id),children:n.jsx(S.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),bz=T.observer(()=>{const{panel:e}=fe();return e.title.show?n.jsx(s.Group,{grow:!0,justify:"center",className:"panel-title-wrapper",sx:{flexGrow:1},children:n.jsx(s.Text,{size:"sm",ta:"center",lineClamp:1,className:"panel-title-text",children:e.title.show?e.name:""})}):null}),yz=T.observer(()=>{const{panel:e}=fe();return n.jsx(te,{children:n.jsx(s.Box,{className:`panel-root ${e.title.show?"panel-root--show-title":""}`,p:0,sx:{border:"1px solid",borderColor:e.style.border.enabled?"#e9ecef":"transparent",flexGrow:0,flexShrink:0,width:"600px !important",height:"450px !important"},children:n.jsxs(Cs,{children:[n.jsx(s.Box,{className:"panel-description-popover-wrapper",children:n.jsx(Ia,{})}),n.jsx(bz,{}),n.jsx(Pa,{panel:e})]})})})});function vz(){const{t:e}=x.useTranslation(),{vizManager:t}=h.useContext(rt);return h.useMemo(()=>y.orderBy(Object.entries(y.groupBy(t.availableVizList,"displayGroup")),[l=>l[0]],["asc"]).map(([l,o])=>{const i=o.map(c=>({value:c.name,label:e(c.displayName??it.name)}));return{group:e(l??"ungrouped"),items:y.orderBy(i,[c=>c.label],["asc"])}}),[t])}const _z=T.observer(({value:e,submit:t})=>{const{t:r}=x.useTranslation(),[a,l]=ne.useInputState(e);h.useEffect(()=>{l(e)},[e]);const o=vz(),i=e!==a;return n.jsx(s.Select,{label:r("visualization.component"),value:a,searchable:!0,onChange:l,data:o,rightSection:n.jsx(s.ActionIcon,{variant:"filled",color:"green",disabled:!i,onClick:()=>t(a),styles:{root:{pointerEvents:"all"}},children:n.jsx(S.IconDeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Oc=[];function xz(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function wz(){const{data:e,panel:{variables:t,viz:r,title:a,name:l,queryIDs:o,description:i,id:c}}=re(),{vizManager:d}=h.useContext(rt),u={name:l,title:a,description:i,viz:r,queryIDs:o,id:c},p=Wi(u);try{return d.resolveComponent(u.viz.type),n.jsx(ln,{configure:p,children:n.jsx(qT,{variables:t,setVizConf:r.setConf,panel:u,vizManager:d,data:e})})}catch(f){return console.info(y.get(f,"message")),null}}const mz=T.observer(()=>{const{data:e,panel:{viz:t}}=re(),{vizManager:r}=h.useContext(rt),a=h.useCallback(u=>{if(u===t.type)return;const p=xz(r,u);t.setType(u),t.setConf(p||{})},[t.type]),l=u=>{try{t.setConf(JSON.parse(u))}catch(p){console.error(p)}},o=h.useMemo(()=>{var u;return(u=Oc.find(p=>p.value===t.type))==null?void 0:u.Panel},[t.type,Oc]),i=wz(),c=o?h.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,d=i||c;return n.jsxs(s.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[n.jsx(_z,{submit:a,value:t.type}),n.jsxs(te,{children:[n.jsx(s.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:d}),!d&&n.jsx(s.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:l})]})]})}),Cz=T.observer(({panel:e,sourceViewID:t})=>{const{t:r}=x.useTranslation(),a=F(),[l,o]=h.useState(t);h.useEffect(()=>{o(t)},[t]);const[i,{open:c,close:d}]=ne.useDisclosure(!1),u=()=>{e.moveToView(t,l),d()};return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{size:"xs",variant:"subtle",color:"blue",onClick:c,leftSection:n.jsx(S.IconBoxMultiple,{size:14}),children:r("panel.settings.change_view")}),n.jsx(s.Modal,{opened:i,onClose:d,title:r("panel.settings.change_view_title"),zIndex:320,children:n.jsxs(s.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[n.jsx(s.Radio.Group,{value:l,onChange:o,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:n.jsx(s.Stack,{gap:"xs",children:a.views.options.map(p=>n.jsx(s.Radio,{value:p.value,label:p.label},p.value))})}),n.jsxs(s.Group,{wrap:"nowrap",justify:"space-between",sx:{flexGrow:0,flexShrink:0},children:[n.jsx(s.Button,{size:"xs",color:"red",leftSection:n.jsx(S.IconX,{size:14}),onClick:d,children:r("common.actions.cancel")}),n.jsx(s.Button,{size:"xs",color:"blue",leftSection:n.jsx(S.IconDeviceFloppy,{size:14}),onClick:u,disabled:l===t,children:r("common.actions.confirm")})]})]})})]})}),Sz=T.observer(({sx:e={}})=>{const{t}=x.useTranslation(),r=J(),{panel:a}=fe(),l=r.dashboardStateValues,o=(()=>{const i={...l,...a.variableStrings};return JSON.stringify(i,null,2)})();return n.jsx(s.Stack,{sx:{overflow:"hidden",...e},children:n.jsxs(s.Tabs,{defaultValue:"vars",keepMounted:!1,children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"guide",leftSection:n.jsx(S.IconAlertCircle,{size:14}),children:t("panel.variable.guide.tabs.guide")}),n.jsx(s.Tabs.Tab,{value:"vars",leftSection:n.jsx(S.IconVariable,{size:14}),children:t("panel.variable.guide.tabs.vars")})]}),n.jsx(s.Tabs.Panel,{value:"guide",pt:"xs",children:n.jsx(Le.CodeHighlight,{language:"sql",sx:{width:"100%"},withCopyButton:!1,code:t("panel.variable.guide.text")})}),n.jsx(s.Tabs.Panel,{value:"vars",pt:"xs",children:n.jsx(Le.CodeHighlight,{language:"json",sx:{width:"100%"},withCopyButton:!1,code:o})})]})})}),ja={name:"new_var",size:"1rem",weight:"initial",color:{type:"static",staticColor:"Red"},data_field:"",aggregation:{type:"sum",config:{},fallback:"0"},formatter:{output:"number",mantissa:0,trimMantissa:!1,average:!1}};class Tz{constructor(t){V(this,"panel");V(this,"selected");this.panel=t,t.variables.length>0&&(this.selected=t.variables[0]),Q.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}get variableOptions(){return this.panel.variables.map(t=>({label:t.name,value:t.name,description:t.aggregation.type}))}addNew(){const t=this.panel.variables.filter(r=>r.name.startsWith(ja.name)).length;this.panel.addVariable(y.cloneDeep({...ja,name:`${ja.name}${t||""}`})),this.selected=y.last(this.panel.variables)}select(t){this.selected=t}selectByName(t){if(!t){console.warn("Unexpected null name when calling selectByName");return}const r=this.variables.find(a=>a.name===t);if(!r){console.error(`Variable by name[${t}] not found`);return}this.selected=r}remove(t){this.selected===t&&(this.selected=void 0);const r=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!y.isEmpty(this.panel.variables)){const a=Math.min(this.panel.variables.length-1,r);this.selected=this.panel.variables[a]}}}function kz(){const{panel:e}=re();return O.useCreation(()=>new Tz(e),[e])}const zz=h.forwardRef(function({value:t,onChange:r,remove:a},l){const{t:o}=x.useTranslation(),i=(c,d)=>{const u=y.cloneDeep(t);y.set(u,c,d),r(u)};return n.jsxs(s.Stack,{ref:l,children:[n.jsxs(s.Stack,{gap:"xs",px:"sm",py:"md",sx:{border:"1px solid #e9ecef"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(s.TextInput,{label:o("common.name"),required:!0,value:t.name,onChange:c=>i("name",c.currentTarget.value)}),n.jsx(q,{label:o("common.data_field"),required:!0,value:t.data_field,onChange:c=>i("data_field",c)})]}),n.jsx(kr,{label:o("panel.variable.aggregation.label"),pt:0,value:t.aggregation,onChange:c=>i("aggregation",c),withFallback:!0}),t.aggregation.type!=="custom"&&n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{mt:"xl",mb:0,label:o("numbro.format.label"),labelPosition:"center",variant:"dashed"}),n.jsx(je,{value:t.formatter,onChange:c=>i("formatter",c)})]})]}),n.jsx(s.Button,{mt:20,leftSection:n.jsx(S.IconTrash,{size:16}),color:"red",variant:"light",onClick:a,children:o("panel.variable.delete")})]})}),Dz=T.observer(e=>{const{t}=x.useTranslation(),r=O.useCreation(()=>Ei(e.variable),[e.variable]),a=()=>e.uiModel.remove(e.variable);return n.jsxs(s.Stack,{"data-testid":"variable-editor",align:"stretch",children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{variant:"subtle",size:"xs",disabled:!r.changed,color:"red",onClick:r.reset,leftSection:n.jsx(S.IconRecycle,{size:18}),children:t("common.actions.revert_changes")}),n.jsx(s.Button,{variant:"filled",size:"xs",disabled:!r.changed,color:"green",onClick:r.commit,leftSection:n.jsx(S.IconDeviceFloppy,{size:18}),children:t("common.actions.save_changes")})]}),n.jsx(zz,{value:g.getSnapshot(r.copy),onChange:r.update,remove:a})]})});T.observer(e=>{const{uiModel:t}=e;return n.jsx(s.Stack,{className:"var-list",children:t.variables.map(r=>n.jsx(s.Button,{variant:t.selected===r?"filled":"subtle",color:"gray",onClick:()=>t.select(r),children:r.name},r.name))})});const Iz=T.observer(({model:e})=>{const{t}=x.useTranslation();return n.jsx(s.Overlay,{color:"#fff",backgroundOpacity:1,sx:{position:"absolute"},children:n.jsx(s.Button,{variant:"light",size:"xs",leftSection:n.jsx(S.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:t("panel.variable.add")})})}),Mz=T.observer(()=>{var r;const{t:e}=x.useTranslation(),t=kz();return t.variableOptions.length===0?n.jsx(Iz,{model:t}):n.jsxs(s.Stack,{pb:20,children:[n.jsxs(s.Group,{justify:"flex-start",children:[n.jsx(s.Select,{label:e("panel.variable.labels"),data:t.variableOptions,value:(r=t.selected)==null?void 0:r.name,onChange:t.selectByName,maxDropdownHeight:600,sx:{flexGrow:1}}),n.jsx(s.Button,{variant:"light",size:"xs",leftSection:n.jsx(S.IconPlus,{size:16}),onClick:t.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:e("panel.variable.add")})]}),n.jsx(s.Divider,{variant:"dashed"}),t.selected?n.jsx(Dz,{uiModel:t,variable:t.selected}):n.jsx("span",{children:"Select or create a new variable on right side"})]})}),Vz={root:{flexGrow:1,width:"100%",minWidth:"1200px",overflow:"hidden"},panel:{width:"100%",minWidth:"1200px",height:"calc(100% - 44px)",padding:10,overflow:"auto"}},Qa=({children:e})=>n.jsxs(s.Group,{wrap:"nowrap",grow:!0,justify:"flex-start",gap:20,sx:{width:"100%",height:"100%",position:"relative"},children:[n.jsx(s.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),n.jsxs(s.Stack,{justify:"flex-start",sx:{alignSelf:"flex-start",width:"600px",flexGrow:0,flexShrink:0},children:[n.jsx(yz,{}),n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(Sz,{})})]})]});function Pz(e){return!["richText","button"].includes(e)}const Az=T.observer(({panel:e})=>{const{t}=x.useTranslation(),r=Te.useModals(),a=W(),l=F(),[o,i]=h.useState(a.editor.panelTab),c=e.queries,u=Pz(e.viz.type)&&e.dataLoading,p=u||e.queryErrors.length>0||e.queryStateMessages!==""||c.length===0,f=a.editor.path[1];h.useEffect(()=>{i(m=>p&&m==="Visualization"?"Data":m)},[e.id,p]);const v=h.useCallback(m=>{i(m),a.editor.setPanelTab(o)},[]),_=()=>{a.editor.setPath(["_VIEWS_",f])},w=()=>r.openConfirmModal({title:`${t("panel.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{l.removePanelByID(e.id,f),_()},confirmProps:{color:"red"},zIndex:320});return n.jsxs(Kn,{value:{panel:e,data:e.data,loading:u,errors:e.queryErrors,downloadPanelScreenshot:()=>{}},children:[n.jsxs(s.Group,{px:16,justify:"space-between",sx:{borderBottom:"1px solid #eee"},children:[n.jsx(s.Text,{size:"sm",pt:9,pb:8,children:e.name}),n.jsxs(s.Group,{justify:"flex-end",wrap:"nowrap",children:[n.jsx(Cz,{panel:e,sourceViewID:f}),n.jsx(s.Button,{size:"xs",variant:"subtle",color:"red",onClick:w,leftSection:n.jsx(S.IconTrash,{size:14}),children:t("panel.delete")})]})]}),n.jsxs(s.Tabs,{value:o,onChange:v,keepMounted:!1,styles:Vz,children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"Data",leftSection:n.jsx(S.IconDatabase,{size:14}),disabled:u,children:t("data.label")}),n.jsx(s.Tabs.Tab,{value:"Panel",leftSection:n.jsx(S.IconAppWindow,{size:14}),children:t("panel.label")}),n.jsx(s.Tabs.Tab,{value:"Variables",leftSection:n.jsx(S.IconVariable,{size:14}),disabled:p,children:n.jsx(s.Tooltip,{label:t("data.requires_data"),disabled:!p,withinPortal:!0,zIndex:310,children:n.jsx(s.Text,{size:"sm",children:t("panel.variable.labels")})})}),n.jsx(s.Tabs.Tab,{value:"Visualization",leftSection:n.jsx(S.IconChartHistogram,{size:14}),disabled:p,children:n.jsx(s.Tooltip,{label:t("data.requires_data"),disabled:!p,withinPortal:!0,zIndex:310,children:n.jsx(s.Text,{size:"sm",children:t("visualization.label")})})}),n.jsx(s.Tabs.Tab,{value:"Interactions",leftSection:n.jsx(S.IconRoute,{size:14}),children:t("interactions.label")})]}),n.jsxs(s.Tabs.Panel,{value:"Data",children:[n.jsx(s.LoadingOverlay,{visible:u,transitionProps:{exitDuration:0}}),n.jsx(fz,{})]}),n.jsx(s.Tabs.Panel,{value:"Panel",children:n.jsx(Qa,{children:n.jsx(iz,{})})}),n.jsx(s.Tabs.Panel,{value:"Variables",children:n.jsx(Qa,{children:n.jsx(Mz,{})})}),n.jsx(s.Tabs.Panel,{value:"Visualization",children:n.jsx(te,{children:n.jsx(Qa,{children:n.jsx(mz,{})})})}),n.jsx(s.Tabs.Panel,{value:"Interactions",children:n.jsx(te,{children:n.jsx(Bh,{})})})]})]})}),$z=T.observer(({viewID:e,panelID:t})=>{const r=F();if(!r.views.findByID(e))return n.jsxs(s.Text,{size:"14px",children:["View by ID[",e,"] is not found"]});const l=r.panels.findByID(t);return l?n.jsx(Az,{panel:l}):n.jsxs(s.Text,{size:"14px",children:["Panel by ID[",t,"] is not found"]})}),Ez=T.observer(()=>{const{t:e}=x.useTranslation(),[t,r]=h.useState([]),a=Te.useModals(),l=W(),o=v=>{l.editor.setPath(["_QUERIES_",v])},i=()=>{a.openConfirmModal({title:"Delete ununsed queries?",children:n.jsx(s.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>l.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},c=()=>{l.content.queries.downloadSchema(t)},d=h.useMemo(()=>l.content.queries.sortedList.map(v=>v.id),[l.content.queries.sortedList]),u=()=>{r(d)},p=()=>{r([])},f=l.content.queriesUsage;return n.jsxs(s.Stack,{sx:{height:"100%"},gap:"sm",pb:"59px",children:[n.jsx(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:n.jsx(s.Text,{px:"md",ta:"left",sx:{userSelect:"none",cursor:"default"},children:e("query.manage")})}),n.jsxs(s.Flex,{justify:"space-between",align:"center",px:12,children:[n.jsxs(s.Group,{justify:"flex-start",children:[n.jsxs(s.Button.Group,{children:[n.jsx(s.Button,{variant:"default",size:"xs",onClick:u,children:e("common.actions.select_all")}),n.jsx(s.Button,{variant:"default",size:"xs",onClick:p,children:e("common.actions.clear_selection")})]}),n.jsx(s.Button,{size:"xs",color:"blue",leftSection:n.jsx(S.IconCode,{size:14}),disabled:t.length===0,onClick:c,children:e("common.actions.download_schema")})]}),n.jsx(s.Button,{variant:"subtle",size:"xs",color:"red",leftSection:n.jsx(S.IconTrash,{size:14}),disabled:!l.content.hasUnusedQueries,onClick:i,children:e("query.delete_unused")})]}),n.jsx(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:n.jsx(s.Checkbox.Group,{size:"xs",value:t,onChange:r,children:n.jsxs(s.Table,{fz:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"40px"}}),n.jsx(s.Table.Th,{children:e("common.name")}),n.jsx(s.Table.Th,{style:{width:"200px"},children:e("data_source.label")}),n.jsx(s.Table.Th,{style:{width:"100px",textAlign:"right"},children:e("common.type")}),n.jsx(s.Table.Th,{style:{width:"100px",textAlign:"center"},children:e("query.usage.label")}),n.jsx(s.Table.Th,{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),n.jsx(s.Table.Tbody,{children:l.content.queries.sortedList.map(v=>{var w;const _=((w=f[v.id])==null?void 0:w.length)??0;return n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:n.jsx(s.Checkbox,{value:v.id,styles:{input:{cursor:"pointer"}}})}),n.jsx(s.Table.Td,{children:v.name}),n.jsx(s.Table.Td,{children:v.key}),n.jsx(s.Table.Td,{style:{textAlign:"right"},children:v.type}),n.jsx(s.Table.Td,{style:{color:_===0?"#ff0000":"#000",fontWeight:_===0?"bold":"normal",textAlign:"center"},children:_}),n.jsx(s.Table.Td,{children:n.jsx(s.Button,{variant:"subtle",size:"xs",onClick:()=>o(v.id),children:e("common.actions.open")})})]},v.id)})})]})})})]})}),Bz=e=>{const{t}=x.useTranslation(),{queryModel:r}=e,a=W(),l=F(),i=l.findQueryUsage(r.id).length>0,c=Te.useModals(),d=()=>{c.openConfirmModal({title:`${t("query.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{l.queries.removeQuery(r.id),a.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return i?n.jsx(s.Tooltip,{label:t("query.cant_delete"),withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,zIndex:320,position:"top-end",children:n.jsx(s.Box,{sx:{alignSelf:"flex-end"},children:n.jsx(s.Button,{disabled:!0,size:"xs",leftSection:n.jsx(S.IconTrash,{size:16}),children:t("query.delete")})})}):n.jsx(s.Button,{color:"red",size:"xs",onClick:d,leftSection:n.jsx(S.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:t("query.delete")})},Lz=T.observer(Bz),Nc=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:r,count:a,spacing:l=16,pl:o=0})=>n.jsxs(s.Stack,{gap:l,mt:6,pl:o,children:[Array.from(new Array(a-1),(i,c)=>n.jsx(s.Skeleton,{width:e,height:r,radius:"xs"},c)),n.jsx(s.Skeleton,{width:t,height:r,radius:"xs"})]}),Kt=({value:e})=>e===null||e===""?null:n.jsx(s.Tooltip,{label:e,disabled:!e,multiline:!0,zIndex:340,children:n.jsx(s.ActionIcon,{variant:"subtle",children:n.jsx(S.IconInfoCircle,{size:14})})}),qz=({column:e})=>{const{column_key:t,column_key_text:r}=e;return t?n.jsx(s.Tooltip,{label:r,disabled:!r,children:n.jsx(s.Badge,{variant:"light",children:t})}):null},Oz=T.observer(({dataSource:e})=>{const{columns:t}=e.dbInfo;return t.loading?n.jsx(Nc,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:n.jsxs(s.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:50}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:30}}),n.jsx("col",{style:{width:70}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{minWidth:80,width:80}}),n.jsx("col",{style:{minWidth:120,width:120}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"#"}),n.jsx(s.Table.Th,{children:"Column Name"}),n.jsx(s.Table.Th,{}),n.jsx(s.Table.Th,{}),n.jsx(s.Table.Th,{children:"Type"}),n.jsx(s.Table.Th,{children:"Nullable"}),n.jsx(s.Table.Th,{children:"Default Value"})]})}),n.jsx(s.Table.Tbody,{children:t.data.map(r=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:r.ordinal_position}),n.jsx(s.Table.Td,{children:r.column_name}),n.jsx(s.Table.Td,{children:n.jsx(Kt,{value:r.column_comment})}),n.jsx(s.Table.Td,{children:n.jsx(qz,{column:r})}),n.jsx(s.Table.Td,{children:r.column_type}),n.jsx(s.Table.Td,{children:r.is_nullable}),n.jsx(s.Table.Td,{children:n.jsx(Kt,{value:r.column_default})})]},r.column_name))})]})}),Nz=T.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo,r=t.data;return n.jsxs(s.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:250}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"Index Length"}),n.jsx(s.Table.Th,{children:"Index Name"}),n.jsx(s.Table.Th,{children:"Index Algorithm"}),n.jsx(s.Table.Th,{children:"Unique"}),n.jsx(s.Table.Th,{children:"Column Name"})]})}),n.jsx(s.Table.Tbody,{children:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.index_length}),n.jsx(s.Table.Td,{children:a.index_name}),n.jsx(s.Table.Td,{children:a.index_algorithm}),n.jsx(s.Table.Td,{children:a.is_unique?"YES":"NO"}),n.jsx(s.Table.Td,{children:a.column_name})]},a.index_name))})]})}),Gz=T.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo,r=t.data;return n.jsxs(s.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"Index Name"}),n.jsx(s.Table.Th,{children:"Index Algorithm"}),n.jsx(s.Table.Th,{children:"Unique"}),n.jsx(s.Table.Th,{children:"Definition"}),n.jsx(s.Table.Th,{children:"Condition"}),n.jsx(s.Table.Th,{children:"Comment"})]})}),n.jsx(s.Table.Tbody,{children:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.index_name}),n.jsx(s.Table.Td,{children:a.index_algorithm}),n.jsx(s.Table.Td,{children:a.is_unique?"YES":"NO"}),n.jsx(s.Table.Td,{children:n.jsx(Kt,{value:a.index_definition})}),n.jsx(s.Table.Td,{children:n.jsx(Kt,{value:a.condition})}),n.jsx(s.Table.Td,{children:n.jsx(Kt,{value:a.comment})})]},a.index_name))})]})}),Fz=T.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo;return t.loading||t.empty?null:e.type===j.MySQL?n.jsx(Nz,{dataSource:e}):e.type===j.Postgresql?n.jsx(Gz,{dataSource:e}):null}),jz=T.observer(({dataSource:e})=>n.jsxs(s.Stack,{gap:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[n.jsx(te,{children:n.jsx(Oz,{dataSource:e})}),n.jsx(te,{children:n.jsx(Fz,{dataSource:e})})]}));function Qz({table_type:e}){return e==="VIEW"?n.jsx(S.IconEye,{size:14}):e==="BASE TABLE"?n.jsx(S.IconTable,{size:14}):null}const Wz=T.observer(({dataSource:e})=>{const t=e.dbInfo,{tables:r}=t;return r.loading?n.jsx(Nc,{height:"24px",lastWidth:"50%",count:15}):n.jsx(s.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(r.data).map(([a,l])=>n.jsx(s.NavLink,{label:a,title:a,leftSection:n.jsx(S.IconDatabase,{size:14}),defaultOpened:t.table_schema===a,pl:0,childrenOffset:14,children:l.map(o=>n.jsx(s.NavLink,{label:o.table_name,title:o.table_name,leftSection:n.jsx(Qz,{table_type:o.table_type}),onClick:()=>{t.setKeywords(a,o.table_name)},active:t.table_name===o.table_name},o.table_name))},a))})}),Uz=({visible:e})=>n.jsx(s.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:n.jsx(s.LoadingOverlay,{visible:e})}),Kz=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],Yz={section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px"}},Xz=T.observer(({dataSource:e})=>{const{t}=x.useTranslation(),{tableData:r}=e.dbInfo;return n.jsxs(s.Group,{pt:10,px:10,justify:"space-between",children:[n.jsxs(s.Group,{justify:"flex-start",children:[r.maxPage>1&&n.jsx(s.Pagination,{size:"sm",value:r.page,onChange:r.setPage,total:r.maxPage,withEdges:r.maxPage>7,styles:{control:{height:"30px"}}}),n.jsx(s.Select,{leftSection:n.jsx(s.Text,{ta:"center",c:"dimmed",size:"14px",children:t("common.pagination.page_size")}),size:"xs",styles:Yz,data:Kz,value:String(r.limit),onChange:a=>r.setLimit(Number(a)),comboboxProps:{zIndex:340}})]}),n.jsx(s.Group,{justify:"flex-end",children:n.jsx(s.Text,{c:"dimmed",my:0,size:"14px",children:t("common.pagination.total_rows",{total:r.total})})})]})}),Zz=T.observer(({dataSource:e})=>{const t=e.dbInfo.tableData;return t.maxPage===0?n.jsx(s.Text,{mt:20,c:"red",size:"md",ta:"center",ff:"monospace",children:"This table is empty"}):t.error?n.jsx(s.Text,{mt:20,c:"red",size:"md",ta:"center",ff:"monospace",children:t.error}):t.page===1&&t.loading?n.jsx(Uz,{visible:!0}):n.jsxs(te,{children:[n.jsx(Xz,{dataSource:e}),n.jsxs(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n.jsx(s.LoadingOverlay,{visible:t.loading,overlayProps:{blur:2}}),n.jsx(qc,{data:t.data})]})]})}),Jz={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},Hz=T.observer(({dataSource:e})=>{const{t}=x.useTranslation(),r=e.dbInfo;return h.useEffect(()=>{r.loadTablesIfEmpty()},[r]),r.tables.error?n.jsx(s.Text,{c:"red",size:"md",ta:"center",ff:"monospace",children:r.tables.error}):n.jsxs(s.Flex,{sx:{height:"100%"},children:[n.jsx(s.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:n.jsx(te,{children:n.jsx(Wz,{dataSource:e})})}),n.jsxs(s.Tabs,{defaultValue:"structure",styles:Jz,children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"structure",leftSection:n.jsx(S.IconColumns,{size:14}),children:t("data_source.table_structure_short")}),n.jsx(s.Tabs.Tab,{value:"data",leftSection:n.jsx(S.IconDatabase,{size:14}),children:t("data.label")})]}),n.jsx(s.Tabs.Panel,{value:"structure",children:n.jsx(jz,{dataSource:e})}),n.jsx(s.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:n.jsx(Zz,{dataSource:e})})]})]})}),Rz={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"20px 20px 10px",borderBottom:"1px solid #efefef",gap:"20px"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},Gc=T.observer(({dataSource:e,triggerButtonProps:t={}})=>{const{t:r}=x.useTranslation(),[a,l]=h.useState(!1),{type:o}=e;return o==="http"||o==="merico_metric_system"?null:n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:a,onClose:()=>l(!1),title:n.jsxs(s.Group,{justify:"space-between",sx:{flexGrow:1},children:[n.jsx(s.Text,{size:"sm",fw:500,children:r("data_source.explorer")}),n.jsxs(s.Group,{gap:7,children:[n.jsx(s.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),n.jsx(s.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",styles:Rz,children:n.jsx(s.Box,{sx:{height:"calc(100vh - 220px)"},children:n.jsx(Hz,{dataSource:e})})}),n.jsx(s.Button,{variant:"subtle",onClick:()=>l(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:r("data_source.see_table_structure")})]})}),Fc={http:"HTTP",mysql:"MySQL",postgresql:"PostgreSQL",merico_metric_system:"指标系统"},eD=({option:e,...t})=>{const{label:r,type:a}=e;return a===j.Transform?n.jsxs(s.Group,{className:"transform-query-option",justify:"flex-start",...t,sx:{flexGrow:1,'&[data-selected="true"]':{".mantine-Text-root":{color:"white"},svg:{stroke:"white"}}},children:[n.jsx(S.IconVectorTriangle,{size:14,color:"#228be6"}),n.jsx(s.Text,{size:"sm",c:"blue",children:r})]}):n.jsxs(s.Group,{justify:"space-between",...t,sx:{flexGrow:1},children:[n.jsx(s.Text,{size:"sm",children:r}),n.jsx(s.Text,{size:"sm",children:Fc[a]})]})},jc=T.observer(({queryModel:e,size:t="sm"})=>{const{t:r}=x.useTranslation(),a=W(),{data:l=[],loading:o}=O.useRequest(Sa,{refreshDeps:[]},[]),i=h.useMemo(()=>{const p=l.map(f=>({label:f.key,value:f.key,type:f.type}));return p.push({label:r("query.transform.data_source"),value:j.Transform,type:j.Transform}),p},[l]),c=h.useMemo(()=>i.reduce((p,f)=>(p[f.value]=f.type,p),{}),[i]),d=p=>{p!==null&&(e.setKey(p),e.setType(c[p]))},u=h.useMemo(()=>a.datasources.find({type:e.type,key:e.key}),[a,e.type,e.key]);return n.jsx(s.Select,{size:t,data:i,label:n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Box,{children:r("data_source.label")}),u&&n.jsx(Gc,{dataSource:u,triggerButtonProps:{size:"compact-xs",px:10}})]}),renderOption:eD,rightSection:u?n.jsx(s.Text,{size:"xs",c:"dimmed",children:Fc[u.type]??u.type}):void 0,rightSectionWidth:85,maxDropdownHeight:500,styles:{root:{flex:1,minWidth:"300px"},label:{display:"block"},section:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:o,value:e.key,onChange:d})}),tD=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),[r,a]=h.useState(e.name);h.useEffect(()=>{a(e.name)},[e.name]);const l=h.useMemo(()=>e.conditionOptionsWithInvalidRunbys.optionGroups.map(i=>({group:t(i.group),items:i.items})),[e.conditionOptionsWithInvalidRunbys.optionGroups]);return n.jsx(s.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:n.jsxs(s.Stack,{gap:10,sx:{width:"100%"},children:[n.jsx(s.Divider,{mb:-10,variant:"dashed",label:t("query.basics"),labelPosition:"center"}),n.jsx(s.TextInput,{placeholder:t("query.name_description"),label:t("query.name"),required:!0,sx:{flex:1},value:r,onChange:o=>{a(o.currentTarget.value)},rightSection:n.jsx(s.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(r),disabled:r===e.name,children:n.jsx(S.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(r)}}),n.jsx(jc,{queryModel:e}),n.jsx(s.Divider,{mt:10,mb:-10,variant:"dashed",label:t("query.conditions"),labelPosition:"center"}),n.jsx(s.MultiSelect,{label:t("query.run_by_condition.label"),description:t("query.run_by_condition.description"),placeholder:t("query.run_by_condition.unset"),data:l,value:[...e.run_by],onChange:e.setRunBy,renderOption:rr,maxDropdownHeight:500}),e.typedAsHTTP&&n.jsx(s.MultiSelect,{label:t("query.re_run_condition.label"),placeholder:t("query.re_run_condition.label"),data:l,value:[...e.config.react_to],onChange:e.config.setReactTo,renderOption:rr,maxDropdownHeight:500}),e.isTransform&&n.jsx(s.MultiSelect,{label:t("query.re_run_condition.label"),placeholder:t("query.re_run_condition.label"),data:l,value:[...e.config.react_to],onChange:e.config.setReactTo,renderOption:rr,maxDropdownHeight:500}),n.jsx(s.Divider,{mt:20,mb:10,variant:"dashed"}),n.jsx(Lz,{queryModel:e})]})})});function nD({content:e}){return n.jsxs(s.HoverCard,{width:"60vw",shadow:"md",zIndex:340,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.ActionIcon,{size:16,color:"blue",variant:"subtle",children:n.jsx(S.IconEye,{})})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(Le.CodeHighlight,{language:"sql",withCopyButton:!1,code:e})})]})}const rD=T.observer(()=>{const t=[...W().globalSQLSnippets.list];return t.length===0?null:n.jsxs(s.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fz:"sm",highlightOnHover:!0,children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"Key"}),n.jsx(s.Table.Th,{children:"Value"})]})}),n.jsx(s.Table.Tbody,{children:t.map(r=>{const{id:a,content:l}=r;return n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a}),n.jsx(s.Table.Td,{width:200,children:n.jsx(nD,{content:l})})]},a)})})]})}),aD=`
554
554
  -- You may reference query variables in SQL or VizConfig.
555
555
  SELECT *
556
556
  FROM commit
@@ -563,10 +563,10 @@ WHERE
563
563
  AND \${sql_snippets.author_email_condition}
564
564
  -- Global SQL snippets (shared between dashboards)
565
565
  AND \${global_sql_snippets.account_condition}
566
- `,Gc=T.observer(function({showSQLSnippets:t=!0,sx:r={}}){const{t:a}=x.useTranslation(),l=W(),o=F(),i=(()=>{const c=l.queryVariables;return t&&(c.sql_snippets=o.sqlSnippets.record),JSON.stringify(c,null,2)})();return n.jsx(s.Stack,{sx:{overflow:"hidden",...r},children:n.jsxs(s.Tabs,{defaultValue:"guide",keepMounted:!1,children:[n.jsxs(s.Tabs.List,{grow:!0,children:[n.jsx(s.Tabs.Tab,{value:"guide",leftSection:n.jsx(S.IconAlertCircle,{size:14}),children:a("query_variable.guide.tabs.guide")}),n.jsx(s.Tabs.Tab,{value:"local_query_vars",leftSection:n.jsx(S.IconVariable,{size:14}),children:a("query_variable.guide.tabs.variables_in_this_dashboard")}),n.jsx(s.Tabs.Tab,{value:"global_sql_snippets",leftSection:n.jsx(S.IconVariablePlus,{size:14}),children:a("query_variable.guide.tabs.global_sql_snippets")})]}),n.jsx(s.Tabs.Panel,{value:"guide",pt:"xs",children:n.jsx(Oe.CodeHighlight,{language:"sql",sx:{width:"100%"},withCopyButton:!1,code:t3})}),n.jsx(s.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:n.jsx(Oe.CodeHighlight,{language:"json",sx:{width:"100%"},withCopyButton:!1,code:i})}),n.jsx(s.Tabs.Panel,{value:"global_sql_snippets",pt:"xs",children:n.jsxs(s.Stack,{gap:10,children:[n.jsx(s.Alert,{icon:n.jsx(S.IconAlertCircle,{size:16}),title:a("global_sql_snippet.labels"),children:a("global_sql_snippet.description")}),n.jsx(e3,{})]})})]})})}),Qa=T.observer(()=>{const{t:e}=x.useTranslation(),[t,r]=h.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:t,onClose:()=>r(!1),title:e("query_variable.labels"),zIndex:320,size:"800px",children:n.jsx(Gc,{})}),n.jsx(s.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:e("query_variable.open")})]})}),Fc={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method: 'POST', url: '/', params: {}, headers: {}, data: {} }","}"].join(`
566
+ `,Qc=T.observer(function({showSQLSnippets:t=!0,sx:r={}}){const{t:a}=x.useTranslation(),l=W(),o=F(),i=(()=>{const c=l.queryVariables;return t&&(c.sql_snippets=o.sqlSnippets.record),JSON.stringify(c,null,2)})();return n.jsx(s.Stack,{sx:{overflow:"hidden",...r},children:n.jsxs(s.Tabs,{defaultValue:"guide",keepMounted:!1,children:[n.jsxs(s.Tabs.List,{grow:!0,children:[n.jsx(s.Tabs.Tab,{value:"guide",leftSection:n.jsx(S.IconAlertCircle,{size:14}),children:a("query_variable.guide.tabs.guide")}),n.jsx(s.Tabs.Tab,{value:"local_query_vars",leftSection:n.jsx(S.IconVariable,{size:14}),children:a("query_variable.guide.tabs.variables_in_this_dashboard")}),n.jsx(s.Tabs.Tab,{value:"global_sql_snippets",leftSection:n.jsx(S.IconVariablePlus,{size:14}),children:a("query_variable.guide.tabs.global_sql_snippets")})]}),n.jsx(s.Tabs.Panel,{value:"guide",pt:"xs",children:n.jsx(Le.CodeHighlight,{language:"sql",sx:{width:"100%"},withCopyButton:!1,code:aD})}),n.jsx(s.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:n.jsx(Le.CodeHighlight,{language:"json",sx:{width:"100%"},withCopyButton:!1,code:i})}),n.jsx(s.Tabs.Panel,{value:"global_sql_snippets",pt:"xs",children:n.jsxs(s.Stack,{gap:10,children:[n.jsx(s.Alert,{icon:n.jsx(S.IconAlertCircle,{size:16}),title:a("global_sql_snippet.labels"),children:a("global_sql_snippet.description")}),n.jsx(rD,{})]})})]})})}),Wa=T.observer(()=>{const{t:e}=x.useTranslation(),[t,r]=h.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:t,onClose:()=>r(!1),title:e("query_variable.labels"),zIndex:320,size:"800px",children:n.jsx(Qc,{})}),n.jsx(s.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:e("query_variable.open")})]})}),Wc={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method: 'POST', url: '/', params: {}, headers: {}, data: {} }","}"].join(`
567
567
  `),post:["function process_result(resp, utils, state) {"," return resp.data","}"].join(`
568
- `)},n3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation();return e.typedAsHTTP?n.jsxs(s.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"pre_process",children:t("query.build_request")}),n.jsx(s.Tabs.Tab,{value:"post_process",children:t("query.process_result")}),n.jsx(Qa,{})]}),n.jsx(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:n.jsx(xt,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Fc.pre})}),n.jsx(s.Tabs.Panel,{value:"post_process",p:"sm",children:n.jsx(xt,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Fc.post})})]}):null}),jc=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=W().editor,a=i=>{if(i.type==="filter"){r.setPath(["_FILTERS_",i.id]);return}if(i.type==="panel"){const c=i.views[0].id;r.setPath(["_VIEWS_",c,"_PANELS_",i.id,"_TABS_","Data"]);return}},l=i=>{r.setPath(["_VIEWS_",i])},o=e.usage;return n.jsxs(s.Table,{highlightOnHover:!0,layout:"fixed",styles:{table:{fontSize:"14px"}},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:100},children:t("common.type")}),n.jsx(s.Table.Th,{style:{width:"calc(50% - 50px)"},children:t("common.name")}),n.jsx(s.Table.Th,{children:t("query.usage.in_views")})]})}),n.jsx(s.Table.Tbody,{children:o.map(i=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:t(i.type_label)}),n.jsx(s.Table.Td,{children:n.jsx(s.Anchor,{size:"sm",component:"button",type:"button",onClick:()=>a(i),children:i.label})}),n.jsx(s.Table.Td,{children:n.jsxs(s.Stack,{align:"flex-start",justify:"flex-start",gap:2,children:[i.views.map(c=>n.jsx(s.Anchor,{size:"sm",component:"button",type:"button",onClick:()=>l(c.id),children:n.jsx(s.Box,{children:c.label})},c.id)),i.views.length===0&&n.jsx(s.Box,{children:"--"})]})})]},i.id))})]})}),r3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=h.useMemo(()=>y.groupBy(e.dependencies,"type"),[e.dependencies]),a=h.useMemo(()=>e.dependencies.some(o=>!o.valid),[e.dependencies]),l=e.dependencies.length>0;return l?n.jsxs(s.HoverCard,{withinPortal:!0,zIndex:340,shadow:"md",disabled:!l,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Button,{size:"xs",variant:"subtle",color:a?"red":"green",disabled:!l,leftSection:a?n.jsx(S.IconAlertTriangle,{size:16}):n.jsx(S.IconDiscountCheckFilled,{size:16}),children:t("query.dependency.label")})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(s.List,{spacing:"md",size:"sm",listStyleType:"none",children:Object.entries(r).map(([o,i])=>n.jsxs(s.List.Item,{children:[n.jsx(s.Text,{size:"sm",fw:"bold",ff:"monospace",children:t(`${o}.label`)}),n.jsx(s.List,{withPadding:!0,size:"sm",sx:{fontFamily:"monospace",svg:{verticalAlign:"middle"}},children:i.map(c=>n.jsx(s.List.Item,{icon:n.jsx(s.Box,{sx:{path:{fill:c.valid?"rgb(18, 184, 134)":"rgb(250, 82, 82)"}},children:n.jsx(S.IconPointFilled,{size:12})}),children:c.key},c.key))})]},o))})})]}):n.jsx(s.Tooltip,{label:t("query.dependency.has_none"),children:n.jsx(s.Button,{size:"xs",variant:"subtle",color:"gray",leftSection:n.jsx(S.IconHierarchy,{size:16,style:{transform:"rotate(180deg)"}}),sx:{transform:"none !important"},children:t("query.dependency.label")})})}),a3="SELECT 1",s3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=e.config,[a,l]=h.useState(r.sql),o=()=>{r.setSQL(a)},i=()=>{l(r.sql)},c=()=>{l(a3)};h.useEffect(()=>{l(r.sql)},[r.sql]);const d=a!==r.sql;return n.jsxs(s.Stack,{gap:4,sx:{height:"100%"},children:[n.jsxs(s.Group,{mb:6,justify:"space-between",sx:{flexShrink:0,flexGrow:0},children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(r3,{queryModel:e})}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:c,size:"xs",variant:"default",leftSection:n.jsx(S.IconPlayerSkipBack,{size:16}),children:t("common.actions.reset_to_default")}),n.jsx(s.Button,{onClick:i,color:"red",size:"xs",disabled:!d,leftSection:n.jsx(S.IconRecycle,{size:16}),children:t("common.actions.revert_changes")}),n.jsx(s.Button,{color:"green",size:"xs",onClick:o,disabled:!d,leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),children:t("common.actions.save_changes")})]})]}),n.jsx(ar,{height:"100%",value:a,onChange:l,theme:"sql-dark",defaultLanguage:"sql"})]})}),l3=({value:e,height:t="200px",defaultLanguage:r="sql"})=>n.jsx(Te,{className:"preview-sql-in-monaco-editor",height:t,defaultLanguage:r,value:e,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),o3=T.observer(({value:e})=>{const r=J().payloadForSQL,a=h.useMemo(()=>ir(e,r),[e,r]);return n.jsx(l3,{height:"100%",value:a})}),Qc={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
568
+ `)},sD=T.observer(({queryModel:e})=>{const{t}=x.useTranslation();return e.typedAsHTTP?n.jsxs(s.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"pre_process",children:t("query.build_request")}),n.jsx(s.Tabs.Tab,{value:"post_process",children:t("query.process_result")}),n.jsx(Wa,{})]}),n.jsx(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:n.jsx(xt,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Wc.pre})}),n.jsx(s.Tabs.Panel,{value:"post_process",p:"sm",children:n.jsx(xt,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Wc.post})})]}):null}),Uc=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=W().editor,a=i=>{if(i.type==="filter"){r.setPath(["_FILTERS_",i.id]);return}if(i.type==="panel"){const c=i.views[0].id;r.setPath(["_VIEWS_",c,"_PANELS_",i.id,"_TABS_","Data"]);return}},l=i=>{r.setPath(["_VIEWS_",i])},o=e.usage;return n.jsxs(s.Table,{highlightOnHover:!0,layout:"fixed",styles:{table:{fontSize:"14px"}},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:100},children:t("common.type")}),n.jsx(s.Table.Th,{style:{width:"calc(50% - 50px)"},children:t("common.name")}),n.jsx(s.Table.Th,{children:t("query.usage.in_views")})]})}),n.jsx(s.Table.Tbody,{children:o.map(i=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:t(i.type_label)}),n.jsx(s.Table.Td,{children:n.jsx(s.Anchor,{size:"sm",component:"button",type:"button",onClick:()=>a(i),children:i.label})}),n.jsx(s.Table.Td,{children:n.jsxs(s.Stack,{align:"flex-start",justify:"flex-start",gap:2,children:[i.views.map(c=>n.jsx(s.Anchor,{size:"sm",component:"button",type:"button",onClick:()=>l(c.id),children:n.jsx(s.Box,{children:c.label})},c.id)),i.views.length===0&&n.jsx(s.Box,{children:"--"})]})})]},i.id))})]})}),lD=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=h.useMemo(()=>y.groupBy(e.dependencies,"type"),[e.dependencies]),a=h.useMemo(()=>e.dependencies.some(o=>!o.valid),[e.dependencies]),l=e.dependencies.length>0;return l?n.jsxs(s.HoverCard,{withinPortal:!0,zIndex:340,shadow:"md",disabled:!l,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Button,{size:"xs",variant:"subtle",color:a?"red":"green",disabled:!l,leftSection:a?n.jsx(S.IconAlertTriangle,{size:16}):n.jsx(S.IconDiscountCheckFilled,{size:16}),children:t("query.dependency.label")})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(s.List,{spacing:"md",size:"sm",listStyleType:"none",children:Object.entries(r).map(([o,i])=>n.jsxs(s.List.Item,{children:[n.jsx(s.Text,{size:"sm",fw:"bold",ff:"monospace",children:t(`${o}.label`)}),n.jsx(s.List,{withPadding:!0,size:"sm",sx:{fontFamily:"monospace",svg:{verticalAlign:"middle"}},children:i.map(c=>n.jsx(s.List.Item,{icon:n.jsx(s.Box,{sx:{path:{fill:c.valid?"rgb(18, 184, 134)":"rgb(250, 82, 82)"}},children:n.jsx(S.IconPointFilled,{size:12})}),children:c.key},c.key))})]},o))})})]}):n.jsx(s.Tooltip,{label:t("query.dependency.has_none"),children:n.jsx(s.Button,{size:"xs",variant:"subtle",color:"gray",leftSection:n.jsx(S.IconHierarchy,{size:16,style:{transform:"rotate(180deg)"}}),sx:{transform:"none !important"},children:t("query.dependency.label")})})}),oD="SELECT 1",iD=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=e.config,[a,l]=h.useState(r.sql),o=()=>{r.setSQL(a)},i=()=>{l(r.sql)},c=()=>{l(oD)};h.useEffect(()=>{l(r.sql)},[r.sql]);const d=a!==r.sql;return n.jsxs(s.Stack,{gap:4,sx:{height:"100%"},children:[n.jsxs(s.Group,{mb:6,justify:"space-between",sx:{flexShrink:0,flexGrow:0},children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(lD,{queryModel:e})}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:c,size:"xs",variant:"default",leftSection:n.jsx(S.IconPlayerSkipBack,{size:16}),children:t("common.actions.reset_to_default")}),n.jsx(s.Button,{onClick:i,color:"red",size:"xs",disabled:!d,leftSection:n.jsx(S.IconRecycle,{size:16}),children:t("common.actions.revert_changes")}),n.jsx(s.Button,{color:"green",size:"xs",onClick:o,disabled:!d,leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),children:t("common.actions.save_changes")})]})]}),n.jsx(ar,{height:"100%",value:a,onChange:l,theme:"sql-dark",defaultLanguage:"sql"})]})}),cD=({value:e,height:t="200px",defaultLanguage:r="sql"})=>n.jsx(Ce,{className:"preview-sql-in-monaco-editor",height:t,defaultLanguage:r,value:e,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),dD=T.observer(({value:e})=>{const r=J().payloadForSQL,a=h.useMemo(()=>ir(e,r),[e,r]);return n.jsx(cD,{height:"100%",value:a})}),Kc={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
569
569
  `),post:["function process_result(data, utils, state) {"," // process data and return the result"," return data","}"].join(`
570
- `)},i3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation();if(!e.typedAsSQL)return null;const r=e.config;return n.jsxs(s.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"Edit",children:n.jsx(s.Group,{gap:14,justify:"space-between",children:t("query.edit_sql")})}),n.jsx(s.Tabs.Tab,{value:"Preview",children:t("query.preview_sql")}),n.jsx(s.Tabs.Tab,{value:"pre_process",children:t("query.process_request")}),n.jsx(s.Tabs.Tab,{value:"post_process",children:t("query.process_result")}),n.jsx(Qa,{}),e.datasource&&n.jsx(qc,{dataSource:e.datasource})]}),n.jsx(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:n.jsx(s3,{queryModel:e})}),n.jsx(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:n.jsx(o3,{value:r.sql})}),n.jsx(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:n.jsx(xt,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Qc.pre})}),n.jsx(s.Tabs.Panel,{value:"post_process",p:"sm",children:n.jsx(xt,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Qc.post})})]})}),c3={pre:["function transform(queries, state, utils) {"," // use queries & dashboar state to build new data"," const data = []"," return data","}"].join(`
571
- `),post:""},d3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=F();if(!e.isTransform)return null;const a=e.config;return n.jsxs(s.Stack,{py:20,px:20,sx:{height:"100%"},children:[n.jsx(s.Text,{size:"sm",children:t("query.transform.guide.pick_queries")}),n.jsx(s.MultiSelect,{data:r.queries.optionsWithoutTransform,value:[...a.dep_query_ids],onChange:a.setDependantQueryIDs,maxDropdownHeight:800}),n.jsx(s.Text,{size:"sm",children:t("query.transform.guide.write_function")}),n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(xt,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:c3.pre})})]})}),Kt={height:"calc(100% - 44px)",padding:0},u3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=F(),a=h.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[l,o]=h.useState(a);h.useEffect(()=>{o(d=>d!=="Configurations"&&a==="Configurations"?"Configurations":d)},[a]);const c=r.findQueryUsage(e.id).length===0;return n.jsxs(s.Tabs,{value:l,onChange:o,defaultValue:a,orientation:"horizontal",keepMounted:!1,sx:{height:"100vh"},children:[n.jsxs(s.Tabs.List,{grow:!0,children:[n.jsx(s.Tabs.Tab,{value:"Configurations",children:t("query.configurations")}),e.typedAsSQL&&n.jsx(s.Tabs.Tab,{value:"SQL",children:t("query.request")}),e.typedAsHTTP&&n.jsx(s.Tabs.Tab,{value:"HTTP",children:t("query.request")}),e.isTransform&&n.jsx(s.Tabs.Tab,{value:"Transform",children:t("query.transform.label")}),n.jsx(s.Tabs.Tab,{value:"Data",disabled:!e.canPreviewData,children:n.jsx(s.Tooltip,{label:e.guideToPreviewData,disabled:e.canPreviewData,withinPortal:!0,children:n.jsx(s.Text,{size:"sm",children:t("data.preview_data")})})}),n.jsx(s.Tabs.Tab,{value:"Usage",disabled:c,children:n.jsx(s.Tooltip,{label:t("query.usage.unused_description"),disabled:!c,withinPortal:!0,children:n.jsx(s.Text,{size:"sm",children:t("query.usage.label")})})})]}),n.jsx(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:n.jsx(Hz,{queryModel:e})}),e.typedAsSQL&&n.jsx(s.Tabs.Panel,{value:"SQL",sx:Kt,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(i3,{queryModel:e})})}),e.typedAsHTTP&&n.jsx(s.Tabs.Panel,{value:"HTTP",sx:Kt,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(n3,{queryModel:e})})}),e.isTransform&&n.jsx(s.Tabs.Panel,{value:"Transform",sx:Kt,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(d3,{queryModel:e})})}),n.jsx(s.Tabs.Panel,{value:"Data",sx:{...Kt,overflow:"hidden"},children:n.jsx(Ga,{id:e.id,moreActions:null,refreshOnMount:!0})}),n.jsx(s.Tabs.Panel,{value:"Usage",py:"sm",px:"md",sx:{...Kt,overflow:"hidden"},children:n.jsx(jc,{queryModel:e})})]})}),p3=({width:e,height:t})=>n.jsxs("svg",{width:e,height:t,viewBox:"0 0 36 36",fill:"none",children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.5 10.5C7.10217 10.5 6.72064 10.658 6.43934 10.9393C6.15804 11.2206 6 11.6022 6 12V28.5C6 28.8978 6.15804 29.2794 6.43934 29.5607C6.72064 29.842 7.10218 30 7.5 30H24C24.3978 30 24.7794 29.842 25.0607 29.5607C25.342 29.2794 25.5 28.8978 25.5 28.5V19.5C25.5 18.6716 26.1716 18 27 18C27.8284 18 28.5 18.6716 28.5 19.5V28.5C28.5 29.6935 28.0259 30.8381 27.182 31.682C26.3381 32.5259 25.1935 33 24 33H7.5C6.30653 33 5.16193 32.5259 4.31802 31.682C3.47411 30.8381 3 29.6935 3 28.5V12C3 10.8065 3.47411 9.66193 4.31802 8.81802C5.16193 7.97411 6.30653 7.5 7.5 7.5H16.5C17.3284 7.5 18 8.17157 18 9C18 9.82843 17.3284 10.5 16.5 10.5H7.5Z",fill:"#3D3E45"}),n.jsx("path",{d:"M32.8862 3.92582C32.8135 3.75021 32.7061 3.5856 32.5638 3.44253C32.5617 3.4404 32.5596 3.43828 32.5575 3.43616C32.2863 3.16658 31.9126 3 31.5 3H22.5C21.6716 3 21 3.67157 21 4.5C21 5.32843 21.6716 6 22.5 6H27.8787L13.9393 19.9393C13.3536 20.5251 13.3536 21.4749 13.9393 22.0607C14.5251 22.6464 15.4749 22.6464 16.0607 22.0607L30 8.12132V13.5C30 14.3284 30.6716 15 31.5 15C32.3284 15 33 14.3284 33 13.5V4.5C33 4.29662 32.9595 4.10268 32.8862 3.92582Z",fill:"#3D3E45"})]}),Wc=({width:e,height:t,color:r="#FFFFFF"})=>n.jsxs("svg",{viewBox:"0 0 36 36",fill:"none",width:e,height:t,children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M24.6931 20.547C26.1129 19.5516 26.113 17.4483 24.6931 16.4529L16.9351 11.0141C15.2783 9.85255 13 11.0377 13 13.0611L13 23.9389C13 25.9623 15.2783 27.1474 16.9351 25.9859L24.6931 20.547ZM16 14.0223L22.387 18.5L16 22.9777L16 14.0223Z",fill:r}),n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M18 1.5C8.8873 1.5 1.5 8.8873 1.5 18C1.5 27.1127 8.8873 34.5 18 34.5C27.1127 34.5 34.5 27.1127 34.5 18C34.5 8.8873 27.1127 1.5 18 1.5ZM4.5 18C4.5 10.5442 10.5442 4.5 18 4.5C25.4558 4.5 31.5 10.5442 31.5 18C31.5 25.4558 25.4558 31.5 18 31.5C10.5442 31.5 4.5 25.4558 4.5 18Z",fill:r})]}),Uc=({width:e,height:t,color:r="#EB1212"})=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",width:e,height:t,children:[n.jsx("path",{d:"M6.66665 6.66699C7.03484 6.66699 7.33331 6.96547 7.33331 7.33366V11.3337C7.33331 11.7018 7.03484 12.0003 6.66665 12.0003C6.29846 12.0003 5.99998 11.7018 5.99998 11.3337V7.33366C5.99998 6.96547 6.29846 6.66699 6.66665 6.66699Z",fill:r}),n.jsx("path",{d:"M9.99998 11.3337V7.33366C9.99998 6.96547 9.7015 6.66699 9.33331 6.66699C8.96512 6.66699 8.66665 6.96547 8.66665 7.33366V11.3337C8.66665 11.7018 8.96512 12.0003 9.33331 12.0003C9.7015 12.0003 9.99998 11.7018 9.99998 11.3337Z",fill:r}),n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M4.66665 3.33366V2.66699C4.66665 2.13656 4.87736 1.62785 5.25243 1.25278C5.62751 0.877706 6.13621 0.666992 6.66665 0.666992H9.33331C9.86375 0.666992 10.3725 0.877706 10.7475 1.25278C11.1226 1.62785 11.3333 2.13656 11.3333 2.66699V3.33366H14C14.3682 3.33366 14.6666 3.63214 14.6666 4.00033C14.6666 4.36852 14.3682 4.66699 14 4.66699H13.3333V13.3337C13.3333 13.8641 13.1226 14.3728 12.7475 14.7479C12.3725 15.1229 11.8637 15.3337 11.3333 15.3337H4.66665C4.13621 15.3337 3.62751 15.1229 3.25243 14.7479C2.87736 14.3728 2.66665 13.8641 2.66665 13.3337V4.66699H1.99998C1.63179 4.66699 1.33331 4.36852 1.33331 4.00033C1.33331 3.63214 1.63179 3.33366 1.99998 3.33366H4.66665ZM6.19524 2.19559C6.32027 2.07056 6.48984 2.00033 6.66665 2.00033H9.33331C9.51012 2.00033 9.67969 2.07056 9.80472 2.19559C9.92974 2.32061 9.99998 2.49018 9.99998 2.66699V3.33366H5.99998V2.66699C5.99998 2.49018 6.07022 2.32061 6.19524 2.19559ZM3.99998 4.66699V13.3337C3.99998 13.5105 4.07022 13.68 4.19524 13.8051C4.32027 13.9301 4.48984 14.0003 4.66665 14.0003H11.3333C11.5101 14.0003 11.6797 13.9301 11.8047 13.8051C11.9297 13.68 12 13.5105 12 13.3337V4.66699H3.99998Z",fill:r})]}),h3=({width:e,height:t})=>n.jsxs("svg",{viewBox:"0 0 18 18",fill:"none",width:e,height:t,children:[n.jsx("path",{d:"M7.5 3.75C7.5 2.92157 8.17157 2.25 9 2.25C9.82843 2.25 10.5 2.92157 10.5 3.75C10.5 4.57843 9.82843 5.25 9 5.25C8.17157 5.25 7.5 4.57843 7.5 3.75Z",fill:"#3D3E45"}),n.jsx("path",{d:"M7.5 9C7.5 8.17157 8.17157 7.5 9 7.5C9.82843 7.5 10.5 8.17157 10.5 9C10.5 9.82843 9.82843 10.5 9 10.5C8.17157 10.5 7.5 9.82843 7.5 9Z",fill:"#3D3E45"}),n.jsx("path",{d:"M9 12.75C8.17157 12.75 7.5 13.4216 7.5 14.25C7.5 15.0784 8.17157 15.75 9 15.75C9.82843 15.75 10.5 15.0784 10.5 14.25C10.5 13.4216 9.82843 12.75 9 12.75Z",fill:"#3D3E45"})]}),g3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=W(),a=F(),o=a.findQueryUsage(e.id).length>0,i=ze.useModals(),c=()=>{i.openConfirmModal({title:`${t("query.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{a.queries.removeQuery(e.id),r.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?n.jsx(s.Tooltip,{label:"此查询在使用中,不能删除。请查看“使用情况”标签页以了解详情",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,zIndex:320,position:"bottom-end",children:n.jsx(s.Button,{leftSection:n.jsx(Uc,{width:14,height:14,color:"gray"}),variant:"subtle",color:"gray",onClick:d=>{d.stopPropagation()},children:"删除查询"})}):n.jsx(s.Menu.Item,{leftSection:n.jsx(Uc,{width:14,height:14}),color:"red",onClick:c,children:"删除查询"})}),f3=T.observer(({queryModel:e})=>n.jsxs(s.Menu,{shadow:"md",width:120,trigger:"hover",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.ActionIcon,{variant:"subtle","aria-label":"Settings",children:n.jsx(h3,{width:18,height:18})})}),n.jsx(s.Menu.Dropdown,{children:n.jsx(g3,{queryModel:e})})]})),b3={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},"th, td":{wordBreak:"break-word"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1",backgroundColor:"rgb(248, 249, 250)"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function y3({data:e}){const t=h.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const a=ge.createColumnHelper();return Object.keys(e[0]).map(l=>a.accessor(l,{cell:o=>o.getValue()}))},[e]),r=ge.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:ge.getCoreRowModel()});return e.length===0?n.jsx(s.Box,{sx:{height:"5em"}}):n.jsx(ne,{children:n.jsxs(s.Table,{sx:b3,stickyHeader:!0,stickyHeaderOffset:0,children:[n.jsx(s.Table.Thead,{style:{backgroundColor:"#F9F9FA"},children:r.getHeaderGroups().map(a=>n.jsx(s.Table.Tr,{children:a.headers.map(l=>n.jsxs(s.Table.Th,{style:{width:l.getSize()},children:[l.isPlaceholder?null:ge.flexRender(l.column.columnDef.header,l.getContext()),n.jsx(s.ActionIcon,{variant:"subtle",onMouseDown:l.getResizeHandler(),onTouchStart:l.getResizeHandler(),className:`resizer ${l.column.getIsResizing()?"isResizing":""}`,children:n.jsx(S.IconArrowBarToRight,{})})]},l.id))},a.id))}),n.jsx(s.Table.Tbody,{children:r.getRowModel().rows.map(a=>n.jsx(s.Table.Tr,{children:a.getVisibleCells().map(l=>n.jsx(s.Table.Td,{children:n.jsx(ne,{children:typeof l.getValue()=="object"?n.jsx("pre",{children:JSON.stringify(l.getValue(),null,2)}):ge.flexRender(l.column.columnDef.cell,l.getContext())})},l.id))},a.id))})]})})}const v3=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],_3={root:{width:"150px"},section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px",paddingRight:0}},x3=({data:e,page:t,setPage:r,limit:a,setLimit:l})=>{const{t:o}=x.useTranslation(),i=e.length,c=Math.ceil(i/a),d=p=>{p&&(r(1),l(Number(p)))};if(i===0)return null;const u=c===1&&i<=10;return n.jsxs(s.Group,{pt:10,px:10,justify:"space-between",children:[n.jsxs(s.Group,{justify:"flex-start",children:[!u&&n.jsx(s.Select,{leftSection:n.jsx(s.Text,{ta:"center",c:"dimmed",size:"xs",children:o("common.pagination.page_size")}),size:"xs",styles:_3,data:v3,value:String(a),onChange:d}),c>1&&n.jsx(s.Pagination,{size:"sm",value:t,onChange:r,total:c,withEdges:c>7,styles:{control:{height:"30px"}},color:"red"})]}),n.jsx(s.Group,{justify:"flex-end",children:n.jsx(s.Text,{c:"dimmed",my:0,size:"14px",children:o("common.pagination.total_rows",{total:i})})})]})},w3=ll(({data:e,loading:t})=>{const[r,a]=h.useState(1),[l,o]=h.useState(20),i=h.useMemo(()=>{const c=(r-1)*l,d=c+l;return e.slice(c,d)},[e,r,l]);return n.jsx(ne,{children:n.jsxs(s.Stack,{gap:10,styles:{root:{height:"100%",overflow:"hidden"}},children:[n.jsx(x3,{data:e,page:r,setPage:a,limit:l,setLimit:o}),n.jsxs(s.Box,{sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n.jsx(s.LoadingOverlay,{visible:t,overlayProps:{blur:2}}),n.jsx(y3,{data:i})]})]})})}),m3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),{state:r,error:a,metricQueryPayloadErrorString:l,stateMessage:o}=e;return r==="loading"?null:a?n.jsx(s.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:a}):l?n.jsx(s.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:l}):o?n.jsx(s.Text,{size:"sm",mt:10,c:"gray",ta:"center",children:t(o)}):null}),C3=T.observer(({queryModel:e})=>{x.useTranslation();const{data:t,state:r}=e,a=r==="loading",l=h.useCallback(()=>{e.fetchData(!0)},[e.fetchData]),o=()=>{vi(e.name,e.data)};h.useEffect(()=>{l()},[l]);const i=!Array.isArray(t)||t.length===0;return n.jsxs(s.Stack,{gap:0,sx:{maxHeight:"calc(50vh - 48px)",flexGrow:1,flexShrink:0,background:"#F9F9FA"},children:[n.jsxs(s.Group,{justify:"space-between",py:7,px:8,children:[n.jsx(s.Text,{size:"sm",fw:500,children:"查询结果"}),n.jsx(s.Button,{size:"xs",variant:"transparent",color:"gray",leftSection:n.jsx(S.IconDownload,{size:16}),disabled:a||i,onClick:o,children:"下载查询结果"})]}),n.jsxs(s.Box,{sx:{position:"relative",flexGrow:1,overflow:"hidden"},children:[n.jsx(m3,{queryModel:e}),n.jsx(w3,{data:t,loading:a})]})]})}),S3=T.observer(({queryModel:e})=>{const t=W();return n.jsxs(s.Tabs,{defaultValue:"看板变量预览",w:"40%",maw:"600px",styles:{root:{borderRadius:4,backgroundColor:"#F9F9FA",height:"100%",minHeight:"350px",maxHeight:"50vh",overflow:"hidden"},panel:{height:"calc(100% - 36px)"}},color:"red",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"看板变量预览",children:"看板变量预览"}),n.jsx(s.Tabs.Tab,{value:"查询预览",children:"查询预览"})]}),n.jsx(s.Tabs.Panel,{value:"查询预览",children:n.jsx(Oe.CodeHighlight,{language:"json",sx:{width:"100%",height:"100%",minHeight:"400px",overflowY:"auto"},withCopyButton:!1,code:e.metricQueryPayloadString})}),n.jsx(s.Tabs.Panel,{value:"看板变量预览",children:n.jsx(Oe.CodeHighlight,{language:"json",sx:{width:"100%",height:"100%",minHeight:"400px",overflowY:"auto"},withCopyButton:!1,code:t.queryVariablesString})})]})}),T3=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.24335 1.62305C7.50108 1.62305 7.71001 1.83198 7.71001 2.08971L7.71001 11.423C7.71001 11.6808 7.50108 11.8897 7.24335 11.8897C6.98561 11.8897 6.77668 11.6808 6.77668 11.423L6.77668 2.08971C6.77668 1.83198 6.98561 1.62305 7.24335 1.62305Z",fill:"#3D3E45"}),n.jsx("path",{d:"M9.93845 9.4786C9.80779 9.4786 9.70045 9.43893 9.61645 9.3596C9.53712 9.2756 9.49745 9.17293 9.49745 9.0516L9.49745 5.0056C9.49745 4.88427 9.53712 4.78393 9.61645 4.7046C9.70045 4.6206 9.80312 4.5786 9.92445 4.5786L12.1995 4.5786C12.3208 4.5786 12.4211 4.61827 12.5005 4.6976C12.5845 4.77227 12.6265 4.87027 12.6265 4.9916C12.6265 5.09427 12.5845 5.18527 12.5005 5.2646C12.4211 5.34393 12.3208 5.3836 12.1995 5.3836L10.3725 5.3836V6.6156H11.8845C12.0058 6.6156 12.1061 6.65527 12.1855 6.7346C12.2695 6.80927 12.3115 6.90727 12.3115 7.0286C12.3115 7.13127 12.2695 7.22227 12.1855 7.3016C12.1061 7.38093 12.0058 7.4206 11.8845 7.4206H10.3725L10.3725 9.0516C10.3725 9.17293 10.3281 9.2756 10.2395 9.3596C10.1555 9.43893 10.0551 9.4786 9.93845 9.4786Z",fill:"#3D3E45"}),n.jsx("path",{d:"M3.34754 9.4786C3.21687 9.4786 3.10954 9.43893 3.02554 9.3596C2.94154 9.2756 2.89954 9.17293 2.89954 9.0516L2.89954 5.3836H1.80054C1.6792 5.3836 1.57654 5.34627 1.49254 5.2716C1.4132 5.19693 1.37354 5.09893 1.37354 4.9776C1.37354 4.85627 1.4132 4.7606 1.49254 4.6906C1.57654 4.61593 1.6792 4.5786 1.80054 4.5786H4.90854C5.02987 4.5786 5.1302 4.61593 5.20954 4.6906C5.29354 4.76527 5.33554 4.86327 5.33554 4.9846C5.33554 5.10593 5.29354 5.20393 5.20954 5.2786C5.1302 5.3486 5.02987 5.3836 4.90854 5.3836H3.80954L3.80954 9.0516C3.80954 9.17293 3.7652 9.2756 3.67654 9.3596C3.59254 9.43893 3.48287 9.4786 3.34754 9.4786Z",fill:"#3D3E45"})]}),k3=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("g",{clipPath:"url(#clip0_245_10828)",children:n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M9.91663 1.16634C9.91663 0.844175 9.65546 0.583008 9.33329 0.583008C9.01113 0.583008 8.74996 0.844175 8.74996 1.16634V1.74967L5.24996 1.74967V1.16634C5.24996 0.844175 4.98879 0.583008 4.66663 0.583008C4.34446 0.583008 4.08329 0.844175 4.08329 1.16634V1.74967H2.91663C1.95013 1.74967 1.16663 2.53318 1.16663 3.49967L1.16663 11.6663C1.16663 12.6328 1.95013 13.4163 2.91663 13.4163L11.0833 13.4163C12.0498 13.4163 12.8333 12.6328 12.8333 11.6663L12.8333 3.49967C12.8333 2.53318 12.0498 1.74967 11.0833 1.74967H9.91663V1.16634ZM11.6666 5.24967V3.49967C11.6666 3.17751 11.4055 2.91634 11.0833 2.91634H9.91663V3.49967C9.91663 3.82184 9.65546 4.08301 9.33329 4.08301C9.01113 4.08301 8.74996 3.82184 8.74996 3.49967V2.91634L5.24996 2.91634V3.49967C5.24996 3.82184 4.98879 4.08301 4.66663 4.08301C4.34446 4.08301 4.08329 3.82184 4.08329 3.49967V2.91634L2.91663 2.91634C2.59446 2.91634 2.33329 3.17751 2.33329 3.49967L2.33329 5.24967L11.6666 5.24967ZM2.33329 6.41634L11.6666 6.41634L11.6666 11.6663C11.6666 11.9885 11.4055 12.2497 11.0833 12.2497L2.91663 12.2497C2.59446 12.2497 2.33329 11.9885 2.33329 11.6663V6.41634Z",fill:"#3D3E45"})}),n.jsx("defs",{children:n.jsx("clipPath",{id:"clip0_245_10828",children:n.jsx("rect",{width:"14",height:"14",fill:"white"})})})]}),z3=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M3.11108 2.13932C2.78892 2.13932 2.52775 2.40049 2.52775 2.72266V10.8893C2.52775 11.2115 2.78892 11.4727 3.11108 11.4727H11.2778C11.5999 11.4727 11.8611 11.2115 11.8611 10.8893V2.72266C11.8611 2.40049 11.5999 2.13932 11.2778 2.13932H3.11108ZM1.36108 2.72266C1.36108 1.75616 2.14459 0.972656 3.11108 0.972656H11.2778C12.2442 0.972656 13.0278 1.75616 13.0278 2.72266V10.8893C13.0278 11.8558 12.2442 12.6393 11.2778 12.6393H3.11108C2.14459 12.6393 1.36108 11.8558 1.36108 10.8893V2.72266Z",fill:"#3D3E45"}),n.jsx("path",{d:"M9.84418 8.37166C9.94816 8.37166 10.0348 8.40631 10.1041 8.47563C10.1734 8.54494 10.2081 8.63159 10.2081 8.73556C10.2081 8.8352 10.1734 8.91968 10.1041 8.989C10.0348 9.05398 9.94816 9.08647 9.84418 9.08647H7.63475C7.52211 9.08647 7.4333 9.05182 7.36832 8.9825C7.30334 8.91318 7.27084 8.82437 7.27084 8.71607C7.27084 8.60776 7.30983 8.51245 7.38781 8.43014L8.80445 6.91603C8.96474 6.74274 9.09038 6.56512 9.18135 6.38317C9.27666 6.20121 9.32432 6.04309 9.32432 5.90879C9.32432 5.69218 9.2615 5.51889 9.13587 5.38892C9.01023 5.25462 8.84344 5.18747 8.63549 5.18747C8.55318 5.18747 8.4687 5.20697 8.38206 5.24596C8.29541 5.28495 8.21094 5.3391 8.12862 5.40842C8.05064 5.47773 7.977 5.55788 7.90768 5.64885C7.85569 5.71817 7.80371 5.76149 7.75172 5.77882C7.69973 5.79615 7.65208 5.80481 7.60876 5.80481C7.51345 5.80481 7.42464 5.77016 7.34233 5.70084C7.26435 5.62719 7.22536 5.54271 7.22536 5.44741C7.22536 5.37376 7.24918 5.30228 7.29684 5.23296C7.34882 5.16365 7.41164 5.09216 7.48529 5.01852C7.59359 4.91021 7.7149 4.8149 7.8492 4.73259C7.98349 4.65028 8.12213 4.58746 8.26509 4.54414C8.40805 4.49648 8.54668 4.47266 8.68098 4.47266C8.97124 4.47266 9.22251 4.53114 9.43479 4.64811C9.6514 4.76075 9.81819 4.92321 9.93516 5.13549C10.0521 5.34343 10.1106 5.59037 10.1106 5.8763C10.1106 6.11457 10.0391 6.381 9.89617 6.67559C9.75754 6.96585 9.56909 7.23878 9.33081 7.49438L8.50837 8.37166H9.84418Z",fill:"#3D3E45"}),n.jsx("path",{d:"M5.49994 9.08647C5.37864 9.08647 5.279 9.04965 5.20102 8.976C5.12304 8.89802 5.08405 8.80271 5.08405 8.69007V5.62518L4.70065 5.90879C4.64 5.95644 4.56418 5.98027 4.47321 5.98027C4.36923 5.98027 4.27826 5.94128 4.20028 5.8633C4.1223 5.78532 4.08331 5.69218 4.08331 5.58387C4.08331 5.44524 4.15046 5.3326 4.28475 5.24596L5.22051 4.62212C5.26384 4.59179 5.31149 4.57013 5.36348 4.55713C5.4198 4.54414 5.47178 4.53764 5.51944 4.53764C5.64507 4.53764 5.74471 4.57663 5.81836 4.65461C5.89201 4.72826 5.92883 4.8214 5.92883 4.93404V8.69007C5.92883 8.80271 5.88768 8.89802 5.80536 8.976C5.72738 9.04965 5.62558 9.08647 5.49994 9.08647Z",fill:"#3D3E45"})]}),D3=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{d:"M12.0334 5.64833C12.3099 5.64833 12.55 5.67744 12.7537 5.73565C12.9623 5.79386 13.1224 5.87632 13.2339 5.98303C13.3504 6.0849 13.4086 6.20859 13.4086 6.35412C13.4086 6.45113 13.3795 6.5433 13.3213 6.63061C13.263 6.71307 13.1782 6.7543 13.0666 6.7543C12.989 6.7543 12.9235 6.7446 12.8701 6.7252C12.8216 6.70094 12.778 6.67184 12.7392 6.63788C12.7004 6.60393 12.6543 6.5724 12.6009 6.54329C12.5524 6.51419 12.4772 6.49236 12.3754 6.47781C12.2783 6.45841 12.2056 6.44871 12.1571 6.44871C11.9097 6.44871 11.6987 6.50206 11.5241 6.60878C11.3543 6.7155 11.2233 6.86102 11.1311 7.04535C11.039 7.22482 10.9929 7.43341 10.9929 7.67109C10.9929 7.90393 11.039 8.11251 11.1311 8.29684C11.2282 8.47631 11.3591 8.61941 11.5241 8.72613C11.6938 8.83284 11.8879 8.8862 12.1061 8.8862C12.2274 8.8862 12.3317 8.87893 12.419 8.86437C12.5063 8.84982 12.5791 8.82799 12.6373 8.79889C12.7052 8.76008 12.7658 8.71885 12.8192 8.6752C12.8726 8.63154 12.9526 8.60971 13.0593 8.60971C13.1854 8.60971 13.2824 8.65094 13.3504 8.7334C13.4183 8.81102 13.4522 8.90803 13.4522 9.02445C13.4522 9.14572 13.3843 9.25728 13.2485 9.35915C13.1127 9.45616 12.9332 9.5362 12.7101 9.59926C12.4918 9.65747 12.2541 9.68657 11.997 9.68657C11.6138 9.68657 11.2815 9.59926 11.0002 9.42463C10.7188 9.24516 10.5005 9.00262 10.3453 8.69702C10.1949 8.39143 10.1198 8.04945 10.1198 7.67109C10.1198 7.27333 10.1998 6.92408 10.3599 6.62333C10.5248 6.31774 10.7504 6.08005 11.0366 5.91027C11.3276 5.73565 11.6599 5.64833 12.0334 5.64833Z",fill:"#3D3E45"}),n.jsx("path",{d:"M7.74826 5.64833C8.08781 5.64833 8.39099 5.73565 8.65778 5.91027C8.92942 6.08005 9.14285 6.31531 9.29807 6.61606C9.45815 6.9168 9.53819 7.26606 9.53819 7.66382C9.53819 8.06158 9.45815 8.41326 9.29807 8.71885C9.14285 9.0196 8.93184 9.25728 8.66505 9.43191C8.40311 9.60169 8.10722 9.68657 7.77737 9.68657C7.58334 9.68657 7.40143 9.65505 7.23166 9.59199C7.06188 9.52893 6.91151 9.44889 6.78054 9.35187C6.65442 9.25486 6.55498 9.15784 6.48222 9.06083C6.41431 8.95896 6.38035 8.87408 6.38035 8.80617L6.60591 8.71158V9.24273C6.60591 9.36885 6.56468 9.47557 6.48222 9.56288C6.39976 9.64534 6.29547 9.68657 6.16935 9.68657C6.04323 9.68657 5.93894 9.64534 5.85647 9.56288C5.77401 9.48042 5.73278 9.3737 5.73278 9.24273V4.67333C5.73278 4.54722 5.77401 4.44292 5.85647 4.36046C5.93894 4.27315 6.04323 4.22949 6.16935 4.22949C6.29547 4.22949 6.39976 4.27315 6.48222 4.36046C6.56468 4.44292 6.60591 4.54722 6.60591 4.67333V6.52147L6.48222 6.45598C6.48222 6.39292 6.51617 6.31774 6.58408 6.23042C6.652 6.13826 6.74416 6.04852 6.86058 5.96121C6.97699 5.86904 7.11039 5.79386 7.26076 5.73565C7.41599 5.67744 7.57849 5.64833 7.74826 5.64833ZM7.63912 6.44871C7.42569 6.44871 7.23893 6.50206 7.07886 6.60878C6.91879 6.7155 6.79267 6.86102 6.7005 7.04535C6.61319 7.22482 6.56953 7.43098 6.56953 7.66382C6.56953 7.8918 6.61319 8.10038 6.7005 8.28956C6.79267 8.47389 6.91879 8.61941 7.07886 8.72613C7.23893 8.83285 7.42569 8.8862 7.63912 8.8862C7.85255 8.8862 8.03688 8.83285 8.19211 8.72613C8.35218 8.61941 8.47587 8.47389 8.56319 8.28956C8.65535 8.10038 8.70143 7.8918 8.70143 7.66382C8.70143 7.43098 8.65535 7.22482 8.56319 7.04535C8.47587 6.86102 8.35218 6.7155 8.19211 6.60878C8.03688 6.50206 7.85255 6.44871 7.63912 6.44871Z",fill:"#3D3E45"}),n.jsx("path",{d:"M3.02845 5.66289L1.45681 9.35915C1.42286 9.45131 1.3695 9.52408 1.29674 9.57743C1.22883 9.62594 1.15364 9.65019 1.07118 9.65019C0.940211 9.65019 0.843196 9.61381 0.780136 9.54105C0.717077 9.46829 0.685547 9.37855 0.685547 9.27184C0.685547 9.22818 0.692823 9.1821 0.707375 9.13359L2.51913 4.78248C2.55793 4.68546 2.61614 4.61028 2.69375 4.55692C2.77622 4.50356 2.86353 4.48173 2.95569 4.49143C3.04301 4.49143 3.12304 4.51811 3.19581 4.57147C3.27342 4.61998 3.3292 4.69031 3.36316 4.78248L5.15308 9.04628C5.17733 9.10934 5.18946 9.16755 5.18946 9.2209C5.18946 9.35187 5.1458 9.45616 5.05849 9.53378C4.97603 9.61139 4.88386 9.65019 4.782 9.65019C4.69468 9.65019 4.61465 9.62352 4.54189 9.57016C4.47398 9.5168 4.42062 9.44404 4.38181 9.35187L2.81745 5.70654L3.02845 5.66289ZM1.68237 8.47146L2.08256 7.63471H4.04711L4.18536 8.47146H1.68237Z",fill:"#3D3E45"})]}),I3=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("g",{clipPath:"url(#clip0_567_6919)",children:n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.00001 1.02051C7.29533 1.02051 7.53473 1.25991 7.53473 1.55523V2.99492L11.3486 5.17429C11.5152 5.2695 11.6181 5.44667 11.6181 5.63856V9.97475L13.0725 10.702C13.3366 10.834 13.4437 11.1552 13.3116 11.4194C13.1795 11.6835 12.8583 11.7906 12.5942 11.6585L11.1002 10.9115L7.26531 13.1028C7.10091 13.1968 6.8991 13.1968 6.73471 13.1028L2.89985 10.9115L1.40581 11.6585C1.14167 11.7906 0.820476 11.6835 0.688405 11.4194C0.556335 11.1552 0.663399 10.834 0.92754 10.702L2.38195 9.97475V5.63856C2.38195 5.44667 2.48477 5.2695 2.65138 5.17429L6.46529 2.99492V1.55523C6.46529 1.25991 6.70469 1.02051 7.00001 1.02051ZM7.00001 3.9211L3.99444 5.63856L7.00001 7.35603L10.0056 5.63856L7.00001 3.9211ZM10.5486 6.55999L7.53473 8.28221V11.7171L10.5486 9.99492V6.55999ZM6.46529 11.7171V8.28221L3.4514 6.55999V9.99492L6.46529 11.7171Z",fill:"#3D3E45"})}),n.jsx("defs",{children:n.jsx("clipPath",{id:"clip0_567_6919",children:n.jsx("rect",{width:"14",height:"14",fill:"white"})})})]}),Wa=({type:e})=>{switch(e){case"boolean":return n.jsx(T3,{});case"date":return n.jsx(k3,{});case"number":return n.jsx(z3,{});case"string":return n.jsx(D3,{});case"dimension":return n.jsx(I3,{});default:return null}},M3={option:{fontFamily:"monospace","&.sub-option":{position:"relative",marginLeft:"22px"},"&.sub-option::before":{content:'""',width:"1px",height:"100%",position:"absolute",left:"-6px",borderLeft:"1px solid #E7E7E9"}},groupLabel:{cursor:"default",fontWeight:"normal","&::before":{content:'""',flex:1,insetInline:0,height:"calc(0.0625rem* var(--mantine-scale))",marginInlineEnd:"var(--mantine-spacing-xs)",borderBottom:"1px dashed var(--mantine-color-gray-2)"},"&::after":{borderBottom:"1px dashed var(--mantine-color-gray-2)",background:"none"}},group:{"&.dimension-group":{paddingBottom:"4px",".mantine-Combobox-groupLabel":{color:"#000"},".mantine-Combobox-groupLabel::before":{display:"none"},".mantine-Combobox-groupLabel::after":{display:"none"}}}},A3={root:{maxWidth:"unset"},option:{fontFamily:"monospace"},input:{paddingInlineStart:"var(--input-padding-inline-start)",height:"auto",color:"black",fontFamily:"monospace"}},Yc=(e,t,r)=>{const a=[];return t&&a.push("sub-option"),r&&a.push("disabled"),n.jsx(s.Combobox.Option,{value:e.value,className:a.join(" "),disabled:r,children:n.jsxs(s.Stack,{gap:1,children:[n.jsxs(s.Group,{gap:4,children:[!!e.dataType&&n.jsx(Wa,{type:e.dataType}),n.jsx(s.Text,{size:"xs",children:e.label})]}),n.jsx(s.Text,{size:"xs",c:"dimmed",pl:18,children:e.description})]})},e.value)},Kc=T.observer(({mmInfo:e,value:t,onChange:r,usedKeys:a})=>{const l=e.metricDetail,o=e.metrics.loading||l.loading,i=l.error,c=l.filterColOptions,d=s.useCombobox({onDropdownClose:()=>d.resetSelectedOption()}),u=h.useMemo(()=>o?n.jsx(s.Loader,{size:"xs"}):t?n.jsx(s.CloseButton,{size:"xs",onClick:()=>r(null)}):n.jsx(s.Combobox.Chevron,{size:"xs"}),[o,t]),p=n.jsx(s.InputBase,{component:"button",type:"button",variant:"unstyled",size:"xs",pointer:!0,rightSection:u,rightSectionPointerEvents:!o&&t?"all":"none",onClick:()=>d.toggleDropdown(),disabled:o||c.length===0,styles:A3,error:!!i,children:t||n.jsx(s.Input.Placeholder,{children:"选择维度"})});return n.jsxs(s.Combobox,{store:d,onOptionSubmit:f=>{r(f),d.closeDropdown()},styles:M3,children:[n.jsx(s.Combobox.Target,{children:i?n.jsx(s.Tooltip,{label:i,children:p}):p}),n.jsx(s.Combobox.Dropdown,{miw:300,children:n.jsx(s.Combobox.Options,{mah:500,style:{overflowY:"auto"},children:c.map(({group:f,items:v})=>n.jsx(s.Combobox.Group,{label:f,children:v.map(_=>{var w;return"group"in _?n.jsx(s.Combobox.Group,{className:"dimension-group",label:n.jsxs(s.Group,{gap:4,children:[n.jsx(Wa,{type:"dimension"}),n.jsx(s.Text,{size:"sm",children:_.group}),n.jsx(s.Text,{size:"xs",c:"dimmed",children:_.description})]}),children:(w=_.items)==null?void 0:w.map(m=>Yc(m,!0,a.has(m.value)))},_.group):Yc(_,!1,a.has(_.value))})},f))})})]})}),Xc={tbody:{td:{fontFamily:"monospace"}}},P3={root:{maxWidth:"unset"},option:{fontFamily:"monospace","&[data-checked=true][data-combobox-disabled]":{opacity:1}},input:{fontFamily:"monospace"},groupLabel:{"&::before":{content:'""',flex:1,insetInline:0,height:"calc(0.0625rem* var(--mantine-scale))",marginInlineEnd:"var(--mantine-spacing-xs)",backgroundColor:"var(--mantine-color-gray-2)"}}},V3=({option:e,...t})=>{const{t:r}=x.useTranslation(),a=e,l=a.type==="filter";return n.jsxs(s.Stack,{gap:0,py:4,styles:{root:{flexGrow:1,'&[data-selected="true"]':{".mantine-Text-root":{color:"white"},svg:{stroke:"white"}}}},...t,children:[n.jsx(s.Group,{flex:"1",gap:4,children:n.jsx(s.Text,{size:"xs",children:e.value})}),l&&n.jsxs(s.Group,{justify:"space-between",wrap:"nowrap",children:[n.jsx(s.Text,{size:"xs",c:t.checked?"rgba(255,255,255,.8)":"dimmed",style:{flexShrink:1,flexGrow:1},children:a.widget_label}),n.jsx(s.Text,{size:"xs",c:t.checked?"rgba(255,255,255,.8)":"dimmed",style:{flexShrink:0,flexGrow:0},children:r(st[a.widget])})]})]})},Vn=T.observer(({queryModel:e,value:t,onChange:r,usedKeys:a})=>{const{t:l}=x.useTranslation();e.config;const o=h.useMemo(()=>e.getConditionOptionsWithInvalidValue(t).optionGroups.map(d=>{const u=d.items.length;return{group:`${l(d.group)}(${u})`,items:d.items.map(f=>({...f,label:f.value,widget_label:f.label,disabled:a==null?void 0:a.has(f.value)}))}}),[e.getConditionOptionsWithInvalidValue,l,t,a]),i=h.useCallback((c,d)=>{r(c,d)},[r]);return n.jsx(s.Select,{size:"xs",variant:"unstyled",placeholder:"选择变量",styles:P3,data:o,renderOption:V3,maxDropdownHeight:600,value:t,onChange:i,clearable:!0})}),Ua=T.observer(({variable:e})=>{const t=W();if(!e)return null;const r=y.has(t.queryVariables,e);return n.jsx(s.ThemeIcon,{variant:"white",size:"xs",color:r?"#88CE98":"#F15050",styles:{root:{flexGrow:0,flexShrink:0}},children:n.jsx(S.IconPointFilled,{})})}),$3=T.observer(({queryModel:e})=>{const t=e.config,a=e.datasource.mericoMetricInfo;return h.useEffect(()=>{a.selectMetric(t.id)},[t.id,a]),n.jsxs(s.Stack,{gap:7,children:[n.jsxs(s.Group,{justify:"flex-start",gap:8,children:[n.jsx(s.Text,{size:"sm",children:"看板变量与指标维度关联"}),n.jsx(s.Tooltip,{label:"将看板的筛选器参数与指标的查询维度关联上,使指标可以按照看板的筛选条件和背景变量进行关联展示。",children:n.jsx(s.ActionIcon,{size:"xs",variant:"subtle",color:"gray",children:n.jsx(S.IconInfoCircle,{})})})]}),n.jsxs(s.Table,{withTableBorder:!0,withColumnBorders:!0,layout:"fixed",styles:Xc,children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:"49%"}}),n.jsx("col",{}),n.jsx("col",{style:{width:130}}),n.jsx("col",{style:{width:40}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:"指标筛选维度"}),n.jsx(s.Table.Td,{children:"看板变量"}),n.jsx(s.Table.Td,{colSpan:2,children:"变量值为真时运行查询"})]})}),n.jsxs(s.Table.Tbody,{children:[t.filters.map(l=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{pr:0,children:n.jsx(Kc,{mmInfo:a,value:l.dimension,onChange:l.setDimension,usedKeys:t.usedFilterDimensionKeys})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsxs(s.Group,{justify:"flex-start",grow:!0,gap:0,w:"100%",children:[n.jsx(Ua,{variable:l.variable}),n.jsx(Vn,{queryModel:e,value:l.variable,onChange:l.setVariable})]})}),n.jsx(s.Table.Td,{children:n.jsx(s.Checkbox,{size:"xs",checked:e.keyInRunBy(l.variable),onChange:o=>e.changeRunByRecord(l.variable,o.currentTarget.checked),color:"red"})})]},l.dimension)),n.jsxs(s.Table.Tr,{className:"add-a-row",children:[n.jsx(s.Table.Td,{pr:0,children:n.jsx(Kc,{mmInfo:a,value:null,onChange:l=>l&&t.addFilter(l,""),usedKeys:t.usedFilterDimensionKeys})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsx(Vn,{queryModel:e,value:null,onChange:l=>l&&t.addFilter("",l)})}),n.jsx(s.Table.Td,{})]})]})]})]})}),E3=T.observer(({queryModel:e,variable:t})=>{const r=e.keyInRunBy(t),a=l=>{e.changeRunByRecord(t,l.currentTarget.checked)};return n.jsx(s.Checkbox,{size:"xs",checked:r,onChange:a,color:"red"})}),Zc=({queryModel:e,variable:t})=>t?n.jsx(E3,{queryModel:e,variable:t}):null,B3=T.observer(({queryModel:e})=>{const t=e.config,l=e.datasource.mericoMetricInfo.metricDetail,o=l.trendingDateCol,i=t.timeQuery.enabled;return h.useEffect(()=>{if(!i&&l.requireTrendingReason){t.setTimeQueryEnabled(!0);return}},[l.requireTrendingReason,i]),l.supportTrending?l.requireTrendingReason?n.jsx(s.Tooltip,{label:l.requireTrendingReason,children:n.jsx(s.Box,{children:n.jsx(s.Switch,{size:"xs",color:"red",checked:!0,readOnly:!0,styles:{track:{cursor:"not-allowed"}}})})}):n.jsx(s.Switch,{size:"xs",color:"red",checked:i,onChange:c=>t.setTimeQueryEnabled(c.currentTarget.checked),styles:{track:{cursor:"pointer"}}}):n.jsx(s.Tooltip,{label:"由于指标未设定时序维度,所以不具备时间序列展示功能。",children:n.jsx(s.Box,{children:n.jsx(s.Switch,{size:"xs",color:"red",disabled:!o})})})}),L3=T.observer(({queryModel:e})=>{const t=e.config,l=e.datasource.mericoMetricInfo.metricDetail,o=l.trendingDateCol;return!t.timeQuery.enabled||!l.supportTrending?null:n.jsxs(s.Table,{withTableBorder:!0,withColumnBorders:!0,layout:"fixed",styles:Xc,children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:250}}),n.jsx("col",{}),n.jsx("col",{style:{width:130}}),n.jsx("col",{style:{width:40}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{}),n.jsx(s.Table.Td,{children:"看板变量"}),n.jsx(s.Table.Td,{colSpan:2,children:"变量值为真时运行查询"})]})}),n.jsxs(s.Table.Tbody,{children:[n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{pr:0,children:n.jsxs(s.Group,{gap:4,children:[n.jsx(s.Text,{size:"xs",children:"时间维度"}),n.jsx(s.Text,{size:"xs",c:"dimmed",ff:"monospace",children:(o==null?void 0:o.name)??null})]})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsxs(s.Group,{justify:"flex-start",gap:0,grow:!0,children:[n.jsx(Ua,{variable:t.timeQuery.range_variable}),n.jsx(Vn,{queryModel:e,value:t.timeQuery.range_variable,onChange:t.setRangeVariable,usedKeys:t.usedTimeQueryVariableSet})]})}),n.jsx(s.Table.Td,{children:n.jsx(Zc,{queryModel:e,variable:t.timeQuery.range_variable})})]},"dimension.time"),n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:n.jsx(s.Text,{size:"xs",children:"步长"})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsxs(s.Group,{justify:"flex-start",gap:0,grow:!0,children:[n.jsx(Ua,{variable:t.timeQuery.unit_variable}),n.jsx(Vn,{queryModel:e,value:t.timeQuery.unit_variable,onChange:t.setUnitVariable,usedKeys:t.usedTimeQueryVariableSet})]})}),n.jsx(s.Table.Td,{children:n.jsx(Zc,{queryModel:e,variable:t.timeQuery.unit_variable})})]},"dimension.step")]})]})}),q3=T.observer(({queryModel:e})=>n.jsxs(s.Stack,{gap:7,children:[n.jsxs(s.Group,{justify:"flex-start",gap:8,children:[n.jsx(s.Text,{size:"sm",children:"按时间序列展示"}),n.jsx(s.Tooltip,{label:"将看板的时间&步长筛选器与相应的查询维度关联上。",children:n.jsx(s.ActionIcon,{size:"xs",variant:"subtle",color:"gray",children:n.jsx(S.IconInfoCircle,{})})}),n.jsx(B3,{queryModel:e})]}),n.jsx(L3,{queryModel:e})]})),O3={label:{fontWeight:"normal"},input:{fontSize:"12px"},groupLabel:{cursor:"default",fontWeight:"normal","&::before":{content:'""',flex:1,insetInline:0,height:"calc(0.0625rem* var(--mantine-scale))",marginInlineEnd:"var(--mantine-spacing-xs)",borderBottom:"1px dashed var(--mantine-color-gray-2)"},"&::after":{borderBottom:"1px dashed var(--mantine-color-gray-2)",background:"none"}},option:{fontFamily:"monospace"}},N3=e=>{const t=e.option;return n.jsxs(s.Stack,{gap:1,styles:{root:{flexGrow:1}},children:[n.jsxs(s.Group,{gap:4,children:[n.jsx(Wa,{type:t.dataType}),n.jsx(s.Text,{size:"xs",children:t.label})]}),n.jsx(s.Text,{size:"xs",c:"dimmed",pl:18,children:t.description})]})},G3=T.observer(({queryModel:e})=>{const t=e.config,a=e.datasource.mericoMetricInfo,l=a.metricDetail,o=a.metrics.loading||l.loading,i=l.groupByColOptions,c=d=>{const u=l.getGroupByOptions(d),p=[];u.forEach(f=>{f.dimension?f.dimension.fields.forEach(v=>{typeof v=="string"?p.push(`${f.value} -> ${v}`):p.push(`${f.value} -> ${v.field}`)}):p.push(f.value)}),t.setGroupBys(p)};return n.jsxs(n.Fragment,{children:[n.jsx(s.MultiSelect,{size:"sm",label:"分组聚合维度",description:"指标在查询时按照哪些维度进行聚合计算。最多支持两个维度的聚合计算。若选择按时间序列展示,则仅可选择一个聚合维度。",data:i,searchable:!0,styles:O3,renderOption:N3,rightSection:o?n.jsx(s.Loader,{size:"xs"}):null,value:[...t.groupByValues],onChange:c,maxValues:t.timeQuery.enabled?1:2,placeholder:t.timeQuery.enabled?"仅可选一个维度":"最多选两个维度",disabled:o}),n.jsx(s.Switch,{labelPosition:"left",label:"聚合维度为空时,自动补零",size:"sm",color:"red",checked:t.useDefaultValues,onChange:d=>t.setUseDefaultValues(d.currentTarget.checked),disabled:i.length===0})]})}),F3=T.observer(({queryModel:e})=>{const t=e.config,r=t.id;return h.useEffect(()=>{if(e.run_by.length===0)return;const a=[],l=t.usedFilterVariableSet,o=t.usedTimeQueryVariableSet;e.run_by.forEach(i=>{(l.has(i)||o.has(i))&&a.push(i)}),e.setRunBy(a)},[t.usedFilterVariableSet,t.usedTimeQueryVariableSet,e.run_by]),n.jsxs(s.Stack,{gap:16,pos:"relative",children:[!r&&n.jsx(s.Overlay,{color:"#fff",backgroundOpacity:.5,blur:3,children:n.jsx(s.Center,{h:"100%",children:n.jsx(s.Text,{size:"sm",c:"black",children:"请先选择指标"})})}),n.jsx($3,{queryModel:e}),n.jsx(q3,{queryModel:e}),n.jsx(G3,{queryModel:e})]})}),j3=["function process_result(resp, utils, state) {"," return resp.data","}"].join(`
572
- `),Q3={root:{minHeight:"350px",maxHeight:"50vh",height:"100%",overflow:"hidden"},list:{"&::before":{borderColor:"transparent"}},panel:{height:"calc(100% - 36px)",overflowY:"auto"}},W3=T.observer(({queryModel:e})=>{const[t,r]=h.useState("编辑查询");return n.jsxs(s.Tabs,{color:"red",defaultValue:"编辑查询",styles:Q3,value:t,onChange:r,w:"60%",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"编辑查询",size:"xs",children:"编辑查询"}),n.jsx(s.Tabs.Tab,{value:"加工结果",size:"xs",children:"加工结果"}),n.jsx(s.Tabs.Tab,{value:"使用情况",size:"xs",children:"使用情况"})]}),n.jsx(s.Tabs.Panel,{value:"编辑查询",pt:"xs",children:n.jsx(F3,{queryModel:e})}),n.jsx(s.Tabs.Panel,{value:"加工结果",pt:"xs",children:n.jsx(xt,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:j3})}),n.jsx(s.Tabs.Panel,{value:"使用情况",pt:"xs",children:n.jsx(jc,{queryModel:e})})]})}),U3=T.observer(({queryModel:e})=>{const t=e.metricQueryPayloadError;return t.length>0?n.jsxs(s.HoverCard,{shadow:"md",children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Box,{children:n.jsx(s.Button,{size:"xs",leftSection:n.jsx(Wc,{width:14,height:14,color:"rgb(173, 181, 189)"}),variant:"filled",color:"red",disabled:!0,children:"执行查询"})})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(s.List,{size:"xs",children:t.map(r=>n.jsx(s.List.Item,{children:r},r))})})]}):n.jsx(s.Button,{size:"xs",leftSection:n.jsx(Wc,{width:14,height:14}),variant:"filled",color:"red",onClick:()=>e.fetchData(!0),children:"执行查询"})}),Y3=({option:e,...t})=>{const r=e;return n.jsxs(s.Stack,{gap:0,py:4,styles:{root:{flexGrow:1,'&[data-selected="true"]':{".mantine-Text-root":{color:"white"},svg:{stroke:"white"}}}},...t,children:[n.jsxs(s.Group,{flex:"1",gap:4,children:[n.jsx(S.IconHash,{size:12}),n.jsx(s.Text,{size:"xs",children:r.label})]}),n.jsx(s.Text,{ml:16,size:"xs",c:t.checked?"rgba(255,255,255,.8)":"dimmed",children:r.description})]})},K3=T.observer(({queryModel:e})=>{const t=e.config,a=e.datasource.mericoMetricInfo,l=a.metrics;h.useEffect(()=>{l.load()},[l]),h.useEffect(()=>{!a.metricID&&t.id&&a.selectMetric(t.id)},[t.id]);const o=h.useMemo(()=>l.data.map(p=>({label:p.name,value:p.id,description:p.description,type:p.type})),[l.data]),i=h.useCallback((p,f)=>{p&&(a.selectMetric(p),t.setID(p),t.setType(f.type))},[a,t]),c=h.useMemo(()=>{const p=window.localStorage.getItem("ee_site_url")??"";let f=`${p}/dashboard/admin/metrics/list`;return t.id&&t.type&&(f=`${p}/dashboard/admin/metrics/details/${t.type}/${t.id}`),f.replace("//dashboard","/dashboard")},[t.id,t.type]),{loading:d,error:u}=l;return n.jsx(ne,{children:n.jsxs(s.Group,{justify:"flex-end",gap:12,align:"flex-end",children:[u?n.jsx(s.Tooltip,{label:u,children:n.jsx(s.Select,{size:"xs",label:"指标",error:!0,styles:{root:{flexGrow:1}}})}):n.jsx(s.Select,{size:"xs",label:"指标",data:o,renderOption:Y3,styles:{root:{flexGrow:1}},maxDropdownHeight:500,value:t.id,onChange:i,rightSection:d?n.jsx(s.Loader,{size:"xs"}):null}),n.jsx(s.Tooltip,{label:"跳转到指标明细页查看详情。",disabled:d,children:n.jsx(s.Anchor,{size:"md",variant:"subtle",mb:2,href:c,target:"_blank",underline:"never",children:n.jsx(p3,{width:14,height:14})})})]})})}),X3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation();return n.jsxs(s.Stack,{pt:8,pb:16,px:24,gap:8,styles:{root:{height:"100vh",overflow:"hidden"}},children:[n.jsx(s.Group,{styles:{root:{flexGrow:0,flexShrink:0}},children:n.jsx(s.TextInput,{size:"xs",placeholder:t("query.name_description"),label:t("query.name"),value:e.name,onChange:r=>{e.setName(r.currentTarget.value)},styles:{root:{flexGrow:0,width:"calc(50% - 44px)"}}})}),n.jsxs(s.Group,{justify:"space-between",grow:!0,gap:8,align:"flex-end",styles:{root:{flexGrow:0,flexShrink:0}},children:[n.jsxs(s.Group,{justify:"flex-start",grow:!0,gap:24,align:"flex-end",children:[n.jsx(Nc,{queryModel:e,size:"xs"}),n.jsx(K3,{queryModel:e})]}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(U3,{queryModel:e}),n.jsx(f3,{queryModel:e})]})]}),n.jsxs(s.Group,{justify:"space-between",grow:!0,gap:12,align:"flex-start",sx:{flexGrow:0,flexShrink:1,overflowY:"hidden"},children:[n.jsx(W3,{queryModel:e}),n.jsx(S3,{queryModel:e})]}),n.jsx(C3,{queryModel:e})]})}),Z3=T.observer(({id:e})=>{const r=F().queries.findByID(e);return e===""?null:r?r.isMericoMetricQuery?n.jsx(X3,{queryModel:r}):n.jsx(u3,{queryModel:r}):n.jsx(s.Text,{size:"14px",c:"red",children:"Invalid Query ID"})}),J3=T.observer(({value:e})=>{const r=J().payloadForSQL,a=h.useMemo(()=>ir(e,r),[e,r]);return n.jsx(ar,{height:"100%",value:a})}),H3=T.observer(({item:e,remove:t,onKeyChanged:r})=>{const{t:a}=x.useTranslation(),[l,o]=h.useState("SQL"),[i,c]=h.useState(e.key),d=()=>{e.setKey(i),r(i)},u=i!==e.key,p=e.isADuplicatedKey(i),[f,v]=h.useState(e.value),_=()=>{e.setValue(f)};h.useEffect(()=>{c(e.key),v(e.value)},[e]);const w=f!==e.value,m=ze.useModals(),k=()=>{m.openConfirmModal({title:`${a("sql_snippet.delete")}?`,labels:{confirm:a("common.actions.confirm"),cancel:a("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:t,confirmProps:{color:"red"},zIndex:320})};return n.jsxs(s.Stack,{p:20,sx:{minWidth:"1100px",height:"100vh"},gap:"sm",children:[n.jsxs(s.Group,{sx:{alignItems:"end"},gap:40,children:[n.jsx(s.TextInput,{label:a(p?"sql_snippet.key_occupied":"sql_snippet.key"),value:i,onChange:z=>{c(z.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:n.jsx(s.ActionIcon,{color:"blue",variant:"subtle",onClick:d,disabled:!u||p,children:n.jsx(S.IconDeviceFloppy,{size:16})}),error:p}),n.jsx(s.Button,{leftSection:n.jsx(S.IconTrash,{size:16}),color:"red",variant:"light",onClick:k,children:a("sql_snippet.delete")})]}),n.jsxs(s.Tabs,{value:l,onChange:o,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[n.jsxs(s.Tabs.List,{sx:{position:"relative"},children:[n.jsx(s.Tabs.Tab,{value:"SQL",children:a("sql_snippet.edit_snippet")}),n.jsx(s.Tabs.Tab,{value:"Preview",children:a("sql_snippet.preview_snippet")}),n.jsx(Qa,{}),n.jsx(s.ActionIcon,{color:"blue",variant:"filled",onClick:_,disabled:!w,sx:{position:"absolute",top:0,right:10},children:n.jsx(S.IconDeviceFloppy,{size:18})})]}),n.jsx(s.Tabs.Panel,{value:"SQL",pt:"sm",children:n.jsx(ar,{height:"100%",value:f,onChange:v,defaultLanguage:"sql",theme:"sql-dark"})}),n.jsx(s.Tabs.Panel,{value:"Preview",pt:"sm",children:n.jsx(J3,{value:f})})]})]})}),R3=T.observer(({id:e})=>{const t=W(),r=F(),a=h.useMemo(()=>r.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!a)return n.jsxs(s.Text,{size:"14px",children:["SQL Snippet by key[",e,"] is not found"]});const l=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])},o=()=>{r.sqlSnippets.removeByKey(e),l()},i=c=>{t.editor.setPath(["_SQL_SNIPPETS_",c])};return n.jsx(H3,{item:a,remove:o,onKeyChanged:i})}),eD=T.observer(()=>{const{t:e}=x.useTranslation(),[t,r]=h.useState([]),a=ze.useModals(),l=W(),o=v=>{l.editor.setPath(["_SQL_SNIPPETS_",v])},i=()=>{a.openConfirmModal({title:"Delete ununsed SQL snippets?",children:n.jsx(s.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>l.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},c=()=>{l.content.sqlSnippets.downloadSchema(t)},d=h.useMemo(()=>l.content.sqlSnippets.sortedList.map(v=>v.key),[l.content.sqlSnippets.sortedList]),u=()=>{r(d)},p=()=>{r([])},f=l.content.sqlSnippetsUsage;return n.jsxs(s.Stack,{sx:{height:"100%"},gap:"sm",pb:"59px",children:[n.jsx(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:n.jsx(s.Text,{size:"sm",px:"md",ta:"left",sx:{userSelect:"none",cursor:"default"},children:e("sql_snippet.manage")})}),n.jsxs(s.Flex,{justify:"space-between",align:"center",px:12,children:[n.jsxs(s.Group,{justify:"flex-start",children:[n.jsxs(s.Button.Group,{children:[n.jsx(s.Button,{variant:"default",size:"xs",onClick:u,children:e("common.actions.select_all")}),n.jsx(s.Button,{variant:"default",size:"xs",onClick:p,children:e("common.actions.clear_selection")})]}),n.jsx(s.Button,{size:"xs",color:"blue",leftSection:n.jsx(S.IconCode,{size:14}),disabled:t.length===0,onClick:c,children:e("common.actions.download_schema")})]}),n.jsx(s.Button,{variant:"subtle",size:"xs",color:"red",leftSection:n.jsx(S.IconTrash,{size:14}),disabled:!l.content.hasUnusedSQLSnippets,onClick:i,children:e("sql_snippet.delete_unused")})]}),n.jsx(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:n.jsx(s.Checkbox.Group,{size:"xs",value:t,onChange:r,children:n.jsxs(s.Table,{fz:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"40px"}}),n.jsx(s.Table.Th,{children:e("common.key")}),n.jsx(s.Table.Th,{style:{width:"100px",textAlign:"center"},children:e("sql_snippet.usage.label")}),n.jsx(s.Table.Th,{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),n.jsx(s.Table.Tbody,{children:l.content.sqlSnippets.sortedList.map(v=>{var w;const _=((w=f[v.key])==null?void 0:w.length)??0;return n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:n.jsx(s.Checkbox,{value:v.key,styles:{input:{cursor:"pointer"}}})}),n.jsx(s.Table.Td,{children:v.key}),n.jsx(s.Table.Td,{style:{color:_===0?"#ff0000":"#000",fontWeight:_===0?"bold":"normal",textAlign:"center"},children:_}),n.jsx(s.Table.Td,{children:n.jsx(s.Button,{variant:"subtle",size:"xs",onClick:()=>o(v.key),children:e("common.actions.open")})})]},v.key)})})]})})})]})}),tD=T.observer(({view:e})=>!e||e.type!==$.Division?null:n.jsx(s.Stack,{})),nD=T.observer(({view:e})=>{const{t,i18n:r}=x.useTranslation(),a=h.useMemo(()=>[{value:"default",label:t("common.tabs.variant.default")},{value:"outline",label:t("common.tabs.variant.outline")},{value:"pills",label:t("common.tabs.variant.pills")}],[r.language]),l=h.useMemo(()=>[{value:"horizontal",label:t("common.tabs.orientation.horizontal")},{value:"vertical",label:t("common.tabs.orientation.vertical")}],[r.language]);if(!e||e.type!==$.Tabs)return null;const o=e.config;return n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mt:8,mb:0,label:t("view.component.tabs.tabs_settings"),labelPosition:"center"}),n.jsx(s.Select,{label:t("common.tabs.variant.label"),value:o.variant,onChange:o.setVariant,data:a}),n.jsx(s.Select,{label:t("common.tabs.orientation.label"),value:o.orientation,onChange:o.setOrientation,data:l}),n.jsx(s.Switch,{label:t("common.tabs.grow_tabs"),checked:o.grow,onChange:i=>o.setGrow(i.currentTarget.checked)})]})}),rD=({disabled:e,value:t,onChange:r})=>{const a=l=>{l&&r(l)};return n.jsxs(s.Box,{sx:{position:"relative"},children:[e&&n.jsx(s.Overlay,{backgroundOpacity:.6,color:"#fff",zIndex:5,blur:2}),n.jsx(Te,{height:"500px",defaultLanguage:"javascript",value:t,onChange:a,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},aD=({value:e,onChange:t})=>{const{t:r}=x.useTranslation(),[a,{setTrue:l,setFalse:o}]=O.useBoolean(),[i,c]=h.useState(e??Tn),d=_=>{c({...i,enabled:_})},u=()=>{o();const{enabled:_,func_content:w}=i,m={enabled:_,func_content:w};c(m),t(m)},p=()=>{o(),c(e)},f=_=>{c(w=>({...w,func_content:_}))},v=()=>{f(Tn.func_content)};return n.jsxs(n.Fragment,{children:[n.jsx(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:l,sx:{flexGrow:0},children:n.jsx(S.IconSettings,{size:14})}),n.jsx(s.Modal,{size:800,title:r("view.component.modal.custom_title"),opened:a,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:a&&n.jsxs(s.Stack,{children:[n.jsx(s.Checkbox,{mt:10,label:r("common.enabled"),checked:i.enabled,onChange:_=>d(_.currentTarget.checked)}),n.jsx(rD,{value:i.func_content,onChange:f,disabled:!i.enabled}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:v,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:r("common.actions.revert")}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:p,variant:"subtle",children:r("common.actions.cancel")}),n.jsx(s.Button,{onClick:u,children:r("common.actions.save")})]})]})]})})]})},sD=T.observer(({view:e})=>{const{t}=x.useTranslation();if(!e||e.type!==$.Modal)return null;const r=e.config,a=r.custom_modal_title.value;return n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mt:8,label:t("view.component.modal.modal_settings"),labelPosition:"center"}),n.jsxs(s.Flex,{gap:10,children:[n.jsx(s.TextInput,{label:t("view.component.modal.title"),value:a,onChange:y.noop,disabled:!0,sx:{flexGrow:1}}),n.jsx(aD,{value:r.custom_modal_title,onChange:r.custom_modal_title.replace})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.TextInput,{label:t("view.component.modal.width"),value:r.width,onChange:l=>r.setWidth(l.currentTarget.value),placeholder:"600px / 50vw"}),n.jsx(s.TextInput,{label:t("view.component.modal.height"),value:r.height,onChange:l=>r.setHeight(l.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),lD=T.observer(({view:e})=>n.jsxs(n.Fragment,{children:[n.jsx(tD,{view:e}),n.jsx(sD,{view:e}),n.jsx(nD,{view:e})]})),oD=T.observer(({view:e})=>{const{t,i18n:r}=x.useTranslation(),a=h.useMemo(()=>[{label:t("view.component.div.label"),value:$.Division},{label:t("view.component.modal.label"),value:$.Modal},{label:t("view.component.tabs.label"),value:$.Tabs}],[r.language]);return e?n.jsxs(s.Stack,{sx:{position:"relative"},children:[n.jsx(s.TextInput,{label:t("common.name"),value:e.name,onChange:l=>{e.setName(l.currentTarget.value)}}),n.jsx(s.Select,{label:t("common.type"),comboboxProps:{withinPortal:!0,zIndex:320},value:e.type,onChange:e.setType,data:a}),n.jsx(lD,{view:e})]}):null}),iD=T.observer(({id:e})=>{const{t}=x.useTranslation(),r=ze.useModals(),a=W(),l=F();if(e==="")return null;const o=l.views.findByID(e);if(!o)return n.jsxs(s.Text,{size:"14px",children:["View by ID[",e,"] is not found"]});const i=()=>{a.editor.setPath(["_VIEWS_",""])},c=()=>{r.openConfirmModal({title:`${t("view.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{l.views.removeByID(e),i()},confirmProps:{color:"red"},zIndex:320})};return n.jsxs(s.Stack,{sx:{maxWidth:"600px",height:"100%"},gap:"sm",children:[n.jsx(s.Group,{justify:"flex-end",pt:10,children:n.jsx(s.Button,{size:"xs",color:"red",leftSection:n.jsx(S.IconTrash,{size:16}),onClick:c,children:t("view.delete")})}),n.jsx(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:n.jsx(oD,{view:o})})]})}),cD=T.observer(()=>n.jsx(s.Stack,{sx:{height:"100%"},p:"sm",children:n.jsx(Gc,{})})),dD=T.observer(()=>{const e=W().editor,t=e.path;return k2(t)?n.jsx(cD,{}):z2(t)?n.jsx(Rk,{}):D2(t)?n.jsx(Hk,{}):I2(t)?n.jsx(s.Box,{p:"xs",pl:20,children:n.jsx(Jk,{id:t[1]})}):M2(t)?n.jsx(eD,{}):A2(t)?n.jsx(R3,{id:t[1]}):V2(t)?n.jsx(Pz,{}):P2(t)?n.jsx(Z3,{id:t[1]}):$2(t)?n.jsx(s.Box,{p:"xs",pl:20,children:n.jsx(iD,{id:t[1]})}):Ea(t)?n.jsx(Az,{viewID:t[1],panelID:t[3]}):n.jsx(s.Box,{children:e.path})}),uD=T.observer(()=>n.jsx(dD,{})),pD=T.observer(()=>{const{t:e}=x.useTranslation(),t=W(),r=()=>{const a=new Date().getTime().toString(),l={id:a,key:a,label:a,order:t.content.filters.current.length+1,type:V.TextInput,config:la(),visibleInViewsIDs:["Main"],auto_submit:!1};t.content.filters.append(l),t.editor.setPath(["_FILTERS_",a])};return n.jsx(s.Button,{variant:"subtle",leftSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:r,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("filter.add")})}),hD=T.observer(({parentID:e})=>{const{t}=x.useTranslation(),r=F();if(!e)return null;const a=r.views.findByID(e);return!a||a.type===$.Tabs?null:n.jsx(s.Button,{variant:"subtle",leftSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>r.addANewPanel(a.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:t("panel.add")})}),gD=T.observer(()=>{const{t:e}=x.useTranslation(),t=W(),r=()=>{const a=new Date().getTime().toString(),l={id:a,name:a,type:j.Postgresql,key:"",config:{_type:j.Postgresql,sql:""}};t.content.queries.append(l),t.editor.setPath(["_QUERIES_",a])};return n.jsx(s.Button,{variant:"subtle",leftSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:r,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("query.add")})}),fD=T.observer(()=>{const{t:e}=x.useTranslation(),t=W(),r=()=>{const a=new Date().getTime().toString(),l={key:a,value:""};t.content.sqlSnippets.append(l),t.editor.setPath(["_SQL_SNIPPETS_",a])};return n.jsx(s.Button,{variant:"subtle",leftSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:r,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("sql_snippet.add")})}),bD=T.observer(()=>{const{t:e}=x.useTranslation(),t=F();return n.jsx(s.Button,{variant:"subtle",leftSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("view.add")})}),yD=T.observer(()=>{const{t:e}=x.useTranslation(),t=W();return n.jsx(s.Button,{variant:"subtle",rightSection:n.jsx(S.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_QUERIES_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:e("query.manage")})}),vD=T.observer(()=>{const{t:e}=x.useTranslation(),t=W();return n.jsx(s.Button,{variant:"subtle",rightSection:n.jsx(S.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_SQL_SNIPPETS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:e("sql_snippet.manage")})}),_D=T.observer(()=>{const{t:e}=x.useTranslation(),t=W();return n.jsx(s.Button,{variant:"subtle",rightSection:n.jsx(S.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_FILTERS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:e("filter.manage")})}),xD=T.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?n.jsx(pD,{}):e==="_Add_A_SQL_SNIPPET_"?n.jsx(fD,{}):e==="_Add_A_QUERY_"?n.jsx(gD,{}):e==="_Add_A_VIEW_"?n.jsx(bD,{}):e==="_Add_A_PANEL_"?n.jsx(hD,{parentID:t}):e==="_QUERIES_SETTINGS_"?n.jsx(yD,{}):e==="_SQL_SNIPPETS_SETTINGS_"?n.jsx(vD,{}):e==="_FILTERS_SETTINGS_"?n.jsx(_D,{}):null),Jc=T.observer(({option:e})=>{var p;const{t}=x.useTranslation(),r=W().editor,a=r.isOptionActive,l=a(r.path,e),o=r.isOptionOpened,i=r.navigate,c=o(e),[d,u]=h.useState(c);return h.useEffect(()=>{u(c)},[c]),n.jsx(s.NavLink,{active:l,defaultOpened:c,opened:d,onChange:u,label:t(e.label),onClick:()=>i(e),leftSection:e.Icon?n.jsx(e.Icon,{size:18}):null,children:(p=e.children)==null?void 0:p.map(f=>f._type==="ACTION"?n.jsx(xD,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):n.jsx(Jc,{option:f},f.value))},e.label)}),wD=T.observer(()=>{const e=W();return n.jsx(s.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>n.jsx(Jc,{option:t},t.value))})}),mD=T.observer(()=>{const{t:e}=x.useTranslation(),t=W();return n.jsxs(s.AppShell.Navbar,{p:0,sx:{height:"100vh - 60px - 60px",".mantine-NavLink-body":{wordWrap:"break-word"}},children:[n.jsx(s.AppShell.Section,{sx:{borderBottom:"1px solid #eee",padding:"var(--mantine-spacing-xs) var(--mantine-spacing-md)"},children:n.jsx(s.Text,{size:"sm",ta:"center",sx:{userSelect:"none",cursor:"default"},children:e("common.titles.settings")})}),n.jsx(s.AppShell.Section,{grow:!0,sx:{overflow:"auto"},children:n.jsx(wD,{})}),n.jsx(s.AppShell.Section,{children:n.jsx(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:n.jsx(s.Button,{size:"xs",color:"red",leftSection:n.jsx(S.IconX,{size:18}),onClick:()=>t.editor.close(),children:e("common.actions.close")})})})]})}),CD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden",minWidth:"calc(var(--app-shell-navbar-width, 0px) + 1200px)"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},SD=T.observer(()=>{const e=W().editor;return n.jsx(s.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"},content:{overflowY:"hidden !important"}},children:n.jsxs(s.AppShell,{padding:0,navbar:{width:{base:220,xs:220,sm:240,md:260,lg:300,xl:320},breakpoint:"xxs"},styles:CD,children:[n.jsx(mD,{}),n.jsx(s.AppShell.Main,{children:n.jsx(uD,{})})]})})}),TD=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function kD(e){h.useEffect(()=>{if(Te.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const r=TD(e);Te.loader.config({paths:{vs:r}}),Te.loader.init().then(a=>console.log("monaco instance:",a))},[])}const zD=e=>{const t=h.useCallback(r=>{const a=r||window.event;return a.preventDefault(),a&&(a.returnValue=""),""},[]);h.useEffect(()=>{if(e)return window.addEventListener("beforeunload",t),()=>{window.removeEventListener("beforeunload",t)}},[e])};qs(),il();const DD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden","--app-shell-header-offset":"calc(3.75rem * var(--mantine-scale))"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},ID=({context:e,dashboard:t,content:r,update:a,className:l="dashboard",config:o,onChange:i,headerSlot:c,filterValues:d,onFilterValuesChange:u,onExit:p,lang:f},v)=>{kD(o.monacoPath),Xr(o);const{data:_=[]}=O.useRequest(Ca),{data:w=[]}=O.useRequest(Ti),m=h.useMemo(()=>_c(t,r,_,w,e,d??{}),[t,r]);h.useImperativeHandle(v,()=>m,[m]),xc(m.content,!0),h.useEffect(()=>{m.context.replace(e)},[e]),h.useEffect(()=>{m.datasources.replace(_)},[_]),h.useEffect(()=>{m.globalSQLSnippets.replace(w)},[w]),h.useEffect(()=>{u==null||u(m.content.filters.values)},[u,m.content.filters.values]),h.useEffect(()=>{d&&m.content.filters.patchValues(d)},[d,m.content.filters.patchValues]),h.useEffect(()=>Q.reaction(()=>Q.toJS(m.json),I=>{i==null||i(I)}),[m]);const k=async()=>{await a(m.json,m.content.json)},z=O.useCreation(Kr,[]),D=wc(z);return zD(m.content.changed),O.useWhyDidYouUpdate("@devtable/dashboard editor",{context:e,dashboard:t,content:r,update:a,className:l,config:o,onChange:i,headerSlot:c,filterValues:d,onFilterValuesChange:u,onExit:p,lang:f}),n.jsx(dt.MantineEmotionProvider,{children:n.jsx(Do,{lang:f,children:n.jsx(ze.ModalsProvider,{children:n.jsx(Zn,{children:n.jsx(jn,{value:{renderSearchButton:o.renderSearchButton},children:n.jsx(Fn,{value:m,children:n.jsx(Wn,{value:m.content,children:n.jsxs(Gt.Provider,{value:{inEditMode:!0},children:[n.jsx(ok,{}),n.jsx(rt.Provider,{value:z,children:n.jsxs(ln,{configure:D,children:[n.jsxs(s.AppShell,{padding:0,navbar:{width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},breakpoint:"xxs"},styles:DD,children:[n.jsx(uk,{onExit:p,saveDashboardChanges:k,headerSlot:c}),n.jsx(qk,{}),n.jsx(s.AppShell.Main,{children:n.jsx(s.Box,{className:`${l} dashboard-root`,sx:{position:"relative"},children:m.content.views.visibleViews.map(I=>n.jsx(nc,{view:I},I.id))})})]}),n.jsx(SD,{})]})})]})})})})})})})})},MD=T.observer(h.forwardRef(ID)),W5="",Ya=g.types.model({id:g.types.string,name:g.types.string,dashboard_id:g.types.string,create_time:g.types.string,update_time:g.types.string,version:g.types.string,filters:wa,queries:Ta,sqlSnippets:za,views:va,panels:xa,layouts:ka,mock_context:Zr}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,layouts:e.layouts.json,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get contentJSON(){return this.json.content},get payloadForSQL(){const t=g.getParent(e).context.current,r=g.getParent(e).globalSQLSnippets,a={context:{...e.mock_context.current,...t},filters:e.filters.valuesForPayload};return{...a,sql_snippets:Ut(e.sqlSnippets.current,"key","value",a),global_sql_snippets:Ut(r.list,"id","content",a)}},get payloadForViz(){const t=g.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.valuesForPayload}},get dashboardState(){const{context:t,filters:r}=this.payloadForViz,a={context:{},filters:e.filters.keyStateItemMap(r)};return Object.entries(t).forEach(([l,o])=>{a.context[l]={type:"context",key:l,value:o}}),a},get dashboardStateValues(){return lr(this.payloadForSQL)},getAdditionalQueryInfo(t){return{content_id:e.id,query_id:t,params:this.dashboardStateValues}},get data(){return e.queries.current.map(({id:r,data:a})=>({id:r,data:a})).reduce((r,a)=>(r[a.id]=a.data,r),{})},getDataStuffByID(t){const r=e.queries.findByID(t);return r?{data:r.data,len:r.data.length,state:r.state,error:r.error??r.metricQueryPayloadErrorString}:{data:[],len:0,state:"idle",error:void 0}}})).actions(e=>({}));function Hc({id:e,name:t,dashboard_id:r,create_time:a,update_time:l,content:o},i,c,d){if(!o)throw new Error("unexpected null content when creating a content model");const{version:u,filters:p,views:f,panels:v,layouts:_,definition:{queries:w,sqlSnippets:m,mock_context:k={}}}=o;return Ya.create({id:e,name:t,dashboard_id:r,create_time:a,update_time:l,version:u,filters:ma(p,i,k,c),queries:zi(w),sqlSnippets:Mi(m),mock_context:Jr(k),views:bi(f,d),panels:{list:v},layouts:{list:_,currentBreakpoint:_[0].id}})}const Rc=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:Ya,content_id:g.types.string,datasources:gi,globalSQLSnippets:fa,context:kn});function ed({id:e,name:t,group:r,content_id:a},l,o,i,c,d,u){return Rc.create({id:e,name:t,group:r,content_id:a,content:Hc(l,c,d,u),datasources:{list:o},globalSQLSnippets:{list:i},context:ba(c)})}qs(),il();const AD=({context:e,dashboard:t,content:r,className:a="dashboard",config:l,fullScreenPanelID:o,setFullScreenPanelID:i,filterValues:c,onFilterValuesChange:d,activeTab:u,onActiveTabChange:p,lang:f})=>{Xr(l);const{data:v=[]}=O.useRequest(Ca),{data:_=[]}=O.useRequest(Ti),w=h.useMemo(()=>ed(t,r,v,_,e,c??{},u??null),[t,r]);xc(w.content,!1),h.useEffect(()=>{w.context.replace(e)},[e]),h.useEffect(()=>{w.datasources.replace(v)},[v]),h.useEffect(()=>{w.globalSQLSnippets.replace(_)},[_]),h.useEffect(()=>{console.log("⚪️ calling onFilterValuesChange: ",w.content.filters.values),d==null||d(w.content.filters.values)},[d,w.content.filters.valuesString]),h.useEffect(()=>{c&&w.content.filters.patchValues(c)},[c,w.content.filters.patchValues]),h.useEffect(()=>{p==null||p(w.content.views.firstVisibleTabsViewActiveTab)},[p,w.content.views.firstVisibleTabsViewActiveTabStr]),h.useEffect(()=>{u&&w.content.views.setFirstVisibleTabsViewActiveTab(u)},[u,w.content.views.setFirstVisibleTabsViewActiveTab]);const m=O.useCreation(Kr,[w]),k=wc(m);return O.useWhyDidYouUpdate("@devtable/dashboard render",{context:e,dashboard:t,content:r,className:a,config:l,fullScreenPanelID:o,setFullScreenPanelID:i,filterValues:c,onFilterValuesChange:d,activeTab:u,onActiveTabChange:p,lang:f}),n.jsx(dt.MantineEmotionProvider,{children:n.jsx(Do,{lang:f,children:n.jsx(ze.ModalsProvider,{children:n.jsx(Zn,{children:n.jsx(jn,{value:{renderSearchButton:l.renderSearchButton},children:n.jsx(Fn,{value:w,children:n.jsx(Wn,{value:w.content,children:n.jsx(Xn.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:i},children:n.jsx(Gt.Provider,{value:{inEditMode:!1},children:n.jsx(s.Box,{className:`${a} dashboard-root`,children:n.jsx(rt.Provider,{value:m,children:n.jsx(ln,{configure:k,children:w.content.views.visibleViews.map(z=>n.jsx(In,{view:z},z.id))})})})})})})})})})})})})},PD=T.observer(AD),VD=()=>Promise.resolve().then(()=>du).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));C.APIClient=Ae,C.CURRENT_SCHEMA_VERSION=at,C.ClientPanelRender=WT,C.ContentModel=La,C.ContentModelContext=Qn,C.ContentModelContextProvider=Wn,C.ContentRenderModel=Ya,C.ContextMeta=kn,C.DEFAULT_CUSTOM_MODAL_TITLE=Tn,C.DashboardApiClient=Mo,C.DashboardApiFacadeClient=Ao,C.DashboardEditor=MD,C.DashboardFilterType=V,C.DashboardMode=rc,C.DashboardModel=vc,C.DashboardModelContextProvider=Fn,C.DashboardRenderModel=Rc,C.DashboardThemeContextProvider=jn,C.DashboardViewEditor=nc,C.DashboardViewRender=In,C.DataSourceMetaModel=ga,C.DataSourceType=j,C.DataSourcesMetaModel=gi,C.DatesProvider=Zn,C.DefaultApiClient=Io,C.DefaultValueModeModelType=Rr,C.DescriptionPopover=Da,C.DraftModel=Ai,C.EViewComponentType=$,C.FacadeApiClient=vS,C.FilterCheckboxConfigMeta=ea,C.FilterDateRangeConfigMeta=ta,C.FilterMeta=Sn,C.FilterModel=sc,C.FilterMultiSelectConfigMeta=ra,C.FilterSelectConfigMeta=aa,C.FilterTextInputConfigMeta=sa,C.FilterTreeSelectConfigMeta=ca,C.FilterTreeSingleSelectConfigMeta=da,C.FiltersModel=lc,C.FiltersRenderModel=wa,C.FullScreenPanel=Ji,C.FullScreenPanelContext=Xn,C.GlobalSQLSnippetMeta=fi,C.GlobalSQLSnippetsMeta=fa,C.LayoutItemMeta=Qo,C.LayoutSetMeta=Wo,C.LayoutStateContext=Gt,C.LayoutsRenderModel=ka,C.MericoMetricQueryMeta=Hr,C.MockContextMeta=Zr,C.MuteQueryModel=ki,C.Panel=Zi,C.PanelContextProvider=Yn,C.PanelErrorOrStateMessage=Xi,C.PanelMeta=Lo,C.PanelModel=gc,C.PanelRender=Va,C.PanelRenderModel=_a,C.PanelStyleMeta=Vo,C.PanelTitleMeta=$o,C.PanelVizAddons=Ki,C.PanelVizMeta=Bo,C.PanelVizSection=Aa,C.PanelsModel=fc,C.PanelsRenderModel=xa,C.QueriesModel=ic,C.QueriesRenderModel=Ta,C.QueryMeta=jo,C.QueryModel=oc,C.QueryRenderModel=Sa,C.ReadOnlyDashboard=PD,C.SQLSnippetMeta=Uo,C.SQLSnippetRenderModel=Ii,C.SQLSnippetsModel=cc,C.SQLSnippetsRenderModel=za,C.VariableMeta=Eo,C.ViewComponentTypeBackground=ac,C.ViewComponentTypeColor=d2,C.ViewComponentTypeName=c2,C.ViewDivisionConfig=ua,C.ViewMeta=hi,C.ViewModalConfig=pa,C.ViewRenderModel=ya,C.ViewTabsConfig=ha,C.ViewsModel=bc,C.ViewsRenderModel=va,C.Viz=Yi,C.applyPartialDashboard=N2,C.configureAPIClient=Xr,C.createContentModel=yc,C.createContentRenderModel=Hc,C.createContextMeta=ba,C.createDashboardModel=_c,C.createDashboardRenderModel=ed,C.createDraft=Pi,C.createFilterCheckboxConfig=Yo,C.createFilterDateRangeConfig=Ho,C.createFilterMultiSelectConfig=ei,C.createFilterSelectConfig=ti,C.createFilterTextInputConfig=la,C.createFilterTreeSelectConfig=ii,C.createFilterTreeSingleSelectConfig=ci,C.createMericoMetricQueryMetaConfig=Fo,C.createViewDivisionConfig=di,C.createViewModalConfig=ui,C.createViewTabsConfig=pi,C.facadeApiClient=Po,C.formatSQLSnippet=Ut,C.getInitialDashboardViewsModel=Ba,C.getInitialFiltersConfig=ma,C.getInitialMockContextMeta=Jr,C.getInitialQueriesRenderModel=zi,C.getInitialSQLSnippetsRenderModel=Mi,C.getInitialViewsRenderModel=bi,C.getNewPanel=xi,C.getStaticDateRangeDefaultValue=Zo,C.getVersion=VD,C.initialDashboardContent=QS,C.notifyVizRendered=de,C.onVizRendered=Ip,C.pluginManager=Ct,C.pluginServices=R,C.useContentModelContext=Un,C.useDashboardContext=Nt,C.useDashboardThemeContext=Ds,C.useEditContentModelContext=F,C.useEditDashboardContext=W,C.useEditPanelContext=re,C.useFullScreenPanelContext=Vs,C.useIsInEditPanelContext=Ps,C.useIsInRenderPanelContext=As,C.usePanelFullScreen=Hi,C.useRenderContentModelContext=J,C.useRenderDashboardContext=ks,C.useRenderPanelContext=be,C.useServiceLocator=Qt,C.useVisibleFilters=bT,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
570
+ `)},uD=T.observer(({queryModel:e})=>{const{t}=x.useTranslation();if(!e.typedAsSQL)return null;const r=e.config;return n.jsxs(s.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"Edit",children:n.jsx(s.Group,{gap:14,justify:"space-between",children:t("query.edit_sql")})}),n.jsx(s.Tabs.Tab,{value:"Preview",children:t("query.preview_sql")}),n.jsx(s.Tabs.Tab,{value:"pre_process",children:t("query.process_request")}),n.jsx(s.Tabs.Tab,{value:"post_process",children:t("query.process_result")}),n.jsx(Wa,{}),e.datasource&&n.jsx(Gc,{dataSource:e.datasource})]}),n.jsx(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:n.jsx(iD,{queryModel:e})}),n.jsx(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:n.jsx(dD,{value:r.sql})}),n.jsx(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:n.jsx(xt,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Kc.pre})}),n.jsx(s.Tabs.Panel,{value:"post_process",p:"sm",children:n.jsx(xt,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Kc.post})})]})}),pD={pre:["function transform(queries, state, utils) {"," // use queries & dashboar state to build new data"," const data = []"," return data","}"].join(`
571
+ `),post:""},hD=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=F();if(!e.isTransform)return null;const a=e.config;return n.jsxs(s.Stack,{py:20,px:20,sx:{height:"100%"},children:[n.jsx(s.Text,{size:"sm",children:t("query.transform.guide.pick_queries")}),n.jsx(s.MultiSelect,{data:r.queries.optionsWithoutTransform,value:[...a.dep_query_ids],onChange:a.setDependantQueryIDs,maxDropdownHeight:800}),n.jsx(s.Text,{size:"sm",children:t("query.transform.guide.write_function")}),n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(xt,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:pD.pre})})]})}),Yt={height:"calc(100% - 44px)",padding:0},gD=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=F(),a=h.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[l,o]=h.useState(a);h.useEffect(()=>{o(d=>d!=="Configurations"&&a==="Configurations"?"Configurations":d)},[a]);const c=r.findQueryUsage(e.id).length===0;return n.jsxs(s.Tabs,{value:l,onChange:o,defaultValue:a,orientation:"horizontal",keepMounted:!1,sx:{height:"100vh"},children:[n.jsxs(s.Tabs.List,{grow:!0,children:[n.jsx(s.Tabs.Tab,{value:"Configurations",children:t("query.configurations")}),e.typedAsSQL&&n.jsx(s.Tabs.Tab,{value:"SQL",children:t("query.request")}),e.typedAsHTTP&&n.jsx(s.Tabs.Tab,{value:"HTTP",children:t("query.request")}),e.isTransform&&n.jsx(s.Tabs.Tab,{value:"Transform",children:t("query.transform.label")}),n.jsx(s.Tabs.Tab,{value:"Data",disabled:!e.canPreviewData,children:n.jsx(s.Tooltip,{label:e.guideToPreviewData,disabled:e.canPreviewData,withinPortal:!0,children:n.jsx(s.Text,{size:"sm",children:t("data.preview_data")})})}),n.jsx(s.Tabs.Tab,{value:"Usage",disabled:c,children:n.jsx(s.Tooltip,{label:t("query.usage.unused_description"),disabled:!c,withinPortal:!0,children:n.jsx(s.Text,{size:"sm",children:t("query.usage.label")})})})]}),n.jsx(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:n.jsx(tD,{queryModel:e})}),e.typedAsSQL&&n.jsx(s.Tabs.Panel,{value:"SQL",sx:Yt,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(uD,{queryModel:e})})}),e.typedAsHTTP&&n.jsx(s.Tabs.Panel,{value:"HTTP",sx:Yt,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(sD,{queryModel:e})})}),e.isTransform&&n.jsx(s.Tabs.Panel,{value:"Transform",sx:Yt,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(hD,{queryModel:e})})}),n.jsx(s.Tabs.Panel,{value:"Data",sx:{...Yt,overflow:"hidden"},children:n.jsx(Fa,{id:e.id,moreActions:null,refreshOnMount:!0})}),n.jsx(s.Tabs.Panel,{value:"Usage",py:"sm",px:"md",sx:{...Yt,overflow:"hidden"},children:n.jsx(Uc,{queryModel:e})})]})}),fD=({width:e,height:t})=>n.jsxs("svg",{width:e,height:t,viewBox:"0 0 36 36",fill:"none",children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.5 10.5C7.10217 10.5 6.72064 10.658 6.43934 10.9393C6.15804 11.2206 6 11.6022 6 12V28.5C6 28.8978 6.15804 29.2794 6.43934 29.5607C6.72064 29.842 7.10218 30 7.5 30H24C24.3978 30 24.7794 29.842 25.0607 29.5607C25.342 29.2794 25.5 28.8978 25.5 28.5V19.5C25.5 18.6716 26.1716 18 27 18C27.8284 18 28.5 18.6716 28.5 19.5V28.5C28.5 29.6935 28.0259 30.8381 27.182 31.682C26.3381 32.5259 25.1935 33 24 33H7.5C6.30653 33 5.16193 32.5259 4.31802 31.682C3.47411 30.8381 3 29.6935 3 28.5V12C3 10.8065 3.47411 9.66193 4.31802 8.81802C5.16193 7.97411 6.30653 7.5 7.5 7.5H16.5C17.3284 7.5 18 8.17157 18 9C18 9.82843 17.3284 10.5 16.5 10.5H7.5Z",fill:"#3D3E45"}),n.jsx("path",{d:"M32.8862 3.92582C32.8135 3.75021 32.7061 3.5856 32.5638 3.44253C32.5617 3.4404 32.5596 3.43828 32.5575 3.43616C32.2863 3.16658 31.9126 3 31.5 3H22.5C21.6716 3 21 3.67157 21 4.5C21 5.32843 21.6716 6 22.5 6H27.8787L13.9393 19.9393C13.3536 20.5251 13.3536 21.4749 13.9393 22.0607C14.5251 22.6464 15.4749 22.6464 16.0607 22.0607L30 8.12132V13.5C30 14.3284 30.6716 15 31.5 15C32.3284 15 33 14.3284 33 13.5V4.5C33 4.29662 32.9595 4.10268 32.8862 3.92582Z",fill:"#3D3E45"})]}),Yc=({width:e,height:t,color:r="#FFFFFF"})=>n.jsxs("svg",{viewBox:"0 0 36 36",fill:"none",width:e,height:t,children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M24.6931 20.547C26.1129 19.5516 26.113 17.4483 24.6931 16.4529L16.9351 11.0141C15.2783 9.85255 13 11.0377 13 13.0611L13 23.9389C13 25.9623 15.2783 27.1474 16.9351 25.9859L24.6931 20.547ZM16 14.0223L22.387 18.5L16 22.9777L16 14.0223Z",fill:r}),n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M18 1.5C8.8873 1.5 1.5 8.8873 1.5 18C1.5 27.1127 8.8873 34.5 18 34.5C27.1127 34.5 34.5 27.1127 34.5 18C34.5 8.8873 27.1127 1.5 18 1.5ZM4.5 18C4.5 10.5442 10.5442 4.5 18 4.5C25.4558 4.5 31.5 10.5442 31.5 18C31.5 25.4558 25.4558 31.5 18 31.5C10.5442 31.5 4.5 25.4558 4.5 18Z",fill:r})]}),Xc=({width:e,height:t,color:r="#EB1212"})=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",width:e,height:t,children:[n.jsx("path",{d:"M6.66665 6.66699C7.03484 6.66699 7.33331 6.96547 7.33331 7.33366V11.3337C7.33331 11.7018 7.03484 12.0003 6.66665 12.0003C6.29846 12.0003 5.99998 11.7018 5.99998 11.3337V7.33366C5.99998 6.96547 6.29846 6.66699 6.66665 6.66699Z",fill:r}),n.jsx("path",{d:"M9.99998 11.3337V7.33366C9.99998 6.96547 9.7015 6.66699 9.33331 6.66699C8.96512 6.66699 8.66665 6.96547 8.66665 7.33366V11.3337C8.66665 11.7018 8.96512 12.0003 9.33331 12.0003C9.7015 12.0003 9.99998 11.7018 9.99998 11.3337Z",fill:r}),n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M4.66665 3.33366V2.66699C4.66665 2.13656 4.87736 1.62785 5.25243 1.25278C5.62751 0.877706 6.13621 0.666992 6.66665 0.666992H9.33331C9.86375 0.666992 10.3725 0.877706 10.7475 1.25278C11.1226 1.62785 11.3333 2.13656 11.3333 2.66699V3.33366H14C14.3682 3.33366 14.6666 3.63214 14.6666 4.00033C14.6666 4.36852 14.3682 4.66699 14 4.66699H13.3333V13.3337C13.3333 13.8641 13.1226 14.3728 12.7475 14.7479C12.3725 15.1229 11.8637 15.3337 11.3333 15.3337H4.66665C4.13621 15.3337 3.62751 15.1229 3.25243 14.7479C2.87736 14.3728 2.66665 13.8641 2.66665 13.3337V4.66699H1.99998C1.63179 4.66699 1.33331 4.36852 1.33331 4.00033C1.33331 3.63214 1.63179 3.33366 1.99998 3.33366H4.66665ZM6.19524 2.19559C6.32027 2.07056 6.48984 2.00033 6.66665 2.00033H9.33331C9.51012 2.00033 9.67969 2.07056 9.80472 2.19559C9.92974 2.32061 9.99998 2.49018 9.99998 2.66699V3.33366H5.99998V2.66699C5.99998 2.49018 6.07022 2.32061 6.19524 2.19559ZM3.99998 4.66699V13.3337C3.99998 13.5105 4.07022 13.68 4.19524 13.8051C4.32027 13.9301 4.48984 14.0003 4.66665 14.0003H11.3333C11.5101 14.0003 11.6797 13.9301 11.8047 13.8051C11.9297 13.68 12 13.5105 12 13.3337V4.66699H3.99998Z",fill:r})]}),bD=({width:e,height:t})=>n.jsxs("svg",{viewBox:"0 0 18 18",fill:"none",width:e,height:t,children:[n.jsx("path",{d:"M7.5 3.75C7.5 2.92157 8.17157 2.25 9 2.25C9.82843 2.25 10.5 2.92157 10.5 3.75C10.5 4.57843 9.82843 5.25 9 5.25C8.17157 5.25 7.5 4.57843 7.5 3.75Z",fill:"#3D3E45"}),n.jsx("path",{d:"M7.5 9C7.5 8.17157 8.17157 7.5 9 7.5C9.82843 7.5 10.5 8.17157 10.5 9C10.5 9.82843 9.82843 10.5 9 10.5C8.17157 10.5 7.5 9.82843 7.5 9Z",fill:"#3D3E45"}),n.jsx("path",{d:"M9 12.75C8.17157 12.75 7.5 13.4216 7.5 14.25C7.5 15.0784 8.17157 15.75 9 15.75C9.82843 15.75 10.5 15.0784 10.5 14.25C10.5 13.4216 9.82843 12.75 9 12.75Z",fill:"#3D3E45"})]}),yD=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=W(),a=F(),o=a.findQueryUsage(e.id).length>0,i=Te.useModals(),c=()=>{i.openConfirmModal({title:`${t("query.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{a.queries.removeQuery(e.id),r.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?n.jsx(s.Tooltip,{label:"此查询在使用中,不能删除。请查看“使用情况”标签页以了解详情",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,zIndex:320,position:"bottom-end",children:n.jsx(s.Button,{leftSection:n.jsx(Xc,{width:14,height:14,color:"gray"}),variant:"subtle",color:"gray",onClick:d=>{d.stopPropagation()},children:"删除查询"})}):n.jsx(s.Menu.Item,{leftSection:n.jsx(Xc,{width:14,height:14}),color:"red",onClick:c,children:"删除查询"})}),vD=T.observer(({queryModel:e})=>n.jsxs(s.Menu,{shadow:"md",width:120,trigger:"hover",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.ActionIcon,{variant:"subtle","aria-label":"Settings",children:n.jsx(bD,{width:18,height:18})})}),n.jsx(s.Menu.Dropdown,{children:n.jsx(yD,{queryModel:e})})]})),_D={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},"th, td":{wordBreak:"break-word"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1",backgroundColor:"rgb(248, 249, 250)"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function xD({data:e}){const t=h.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const a=ge.createColumnHelper();return Object.keys(e[0]).map(l=>a.accessor(l,{cell:o=>o.getValue()}))},[e]),r=ge.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:ge.getCoreRowModel()});return e.length===0?n.jsx(s.Box,{sx:{height:"5em"}}):n.jsx(te,{children:n.jsxs(s.Table,{sx:_D,stickyHeader:!0,stickyHeaderOffset:0,children:[n.jsx(s.Table.Thead,{style:{backgroundColor:"#F9F9FA"},children:r.getHeaderGroups().map(a=>n.jsx(s.Table.Tr,{children:a.headers.map(l=>n.jsxs(s.Table.Th,{style:{width:l.getSize()},children:[l.isPlaceholder?null:ge.flexRender(l.column.columnDef.header,l.getContext()),n.jsx(s.ActionIcon,{variant:"subtle",onMouseDown:l.getResizeHandler(),onTouchStart:l.getResizeHandler(),className:`resizer ${l.column.getIsResizing()?"isResizing":""}`,children:n.jsx(S.IconArrowBarToRight,{})})]},l.id))},a.id))}),n.jsx(s.Table.Tbody,{children:r.getRowModel().rows.map(a=>n.jsx(s.Table.Tr,{children:a.getVisibleCells().map(l=>n.jsx(s.Table.Td,{children:n.jsx(te,{children:typeof l.getValue()=="object"?n.jsx("pre",{children:JSON.stringify(l.getValue(),null,2)}):ge.flexRender(l.column.columnDef.cell,l.getContext())})},l.id))},a.id))})]})})}const wD=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],mD={root:{width:"150px"},section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px",paddingRight:0}},CD=({data:e,page:t,setPage:r,limit:a,setLimit:l})=>{const{t:o}=x.useTranslation(),i=e.length,c=Math.ceil(i/a),d=p=>{p&&(r(1),l(Number(p)))};if(i===0)return null;const u=c===1&&i<=10;return n.jsxs(s.Group,{pt:10,px:10,justify:"space-between",children:[n.jsxs(s.Group,{justify:"flex-start",children:[!u&&n.jsx(s.Select,{leftSection:n.jsx(s.Text,{ta:"center",c:"dimmed",size:"xs",children:o("common.pagination.page_size")}),size:"xs",styles:mD,data:wD,value:String(a),onChange:d}),c>1&&n.jsx(s.Pagination,{size:"sm",value:t,onChange:r,total:c,withEdges:c>7,styles:{control:{height:"30px"}},color:"red"})]}),n.jsx(s.Group,{justify:"flex-end",children:n.jsx(s.Text,{c:"dimmed",my:0,size:"14px",children:o("common.pagination.total_rows",{total:i})})})]})},SD=il(({data:e,loading:t})=>{const[r,a]=h.useState(1),[l,o]=h.useState(20),i=h.useMemo(()=>{const c=(r-1)*l,d=c+l;return e.slice(c,d)},[e,r,l]);return n.jsx(te,{children:n.jsxs(s.Stack,{gap:10,styles:{root:{height:"100%",overflow:"hidden"}},children:[n.jsx(CD,{data:e,page:r,setPage:a,limit:l,setLimit:o}),n.jsxs(s.Box,{sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n.jsx(s.LoadingOverlay,{visible:t,overlayProps:{blur:2}}),n.jsx(xD,{data:i})]})]})})}),TD=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),{state:r,error:a,metricQueryPayloadErrorString:l,stateMessage:o}=e;return r==="loading"?null:a?n.jsx(s.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:a}):l?n.jsx(s.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:l}):o?n.jsx(s.Text,{size:"sm",mt:10,c:"gray",ta:"center",children:t(o)}):null}),kD=T.observer(({queryModel:e})=>{x.useTranslation();const{data:t,state:r}=e,a=r==="loading",l=h.useCallback(()=>{e.fetchData(!0)},[e.fetchData]),o=()=>{wi(e.name,e.data)};h.useEffect(()=>{l()},[l]);const i=!Array.isArray(t)||t.length===0;return n.jsxs(s.Stack,{gap:0,sx:{maxHeight:"calc(50vh - 48px)",flexGrow:1,flexShrink:0,background:"#F9F9FA"},children:[n.jsxs(s.Group,{justify:"space-between",py:7,px:8,children:[n.jsx(s.Text,{size:"sm",fw:500,children:"查询结果"}),n.jsx(s.Button,{size:"xs",variant:"transparent",color:"gray",leftSection:n.jsx(S.IconDownload,{size:16}),disabled:a||i,onClick:o,children:"下载查询结果"})]}),n.jsxs(s.Box,{sx:{position:"relative",flexGrow:1,overflow:"hidden"},children:[n.jsx(TD,{queryModel:e}),n.jsx(SD,{data:t,loading:a})]})]})}),zD=T.observer(({queryModel:e})=>{const t=W();return n.jsxs(s.Tabs,{defaultValue:"看板变量预览",w:"40%",maw:"600px",styles:{root:{borderRadius:4,backgroundColor:"#F9F9FA",height:"100%",minHeight:"350px",maxHeight:"50vh",overflow:"hidden"},panel:{height:"calc(100% - 36px)"}},color:"red",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"看板变量预览",children:"看板变量预览"}),n.jsx(s.Tabs.Tab,{value:"查询预览",children:"查询预览"})]}),n.jsx(s.Tabs.Panel,{value:"查询预览",children:n.jsx(Le.CodeHighlight,{language:"json",sx:{width:"100%",height:"100%",minHeight:"400px",overflowY:"auto"},withCopyButton:!1,code:e.metricQueryPayloadString})}),n.jsx(s.Tabs.Panel,{value:"看板变量预览",children:n.jsx(Le.CodeHighlight,{language:"json",sx:{width:"100%",height:"100%",minHeight:"400px",overflowY:"auto"},withCopyButton:!1,code:t.queryVariablesString})})]})}),DD=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.24335 1.62305C7.50108 1.62305 7.71001 1.83198 7.71001 2.08971L7.71001 11.423C7.71001 11.6808 7.50108 11.8897 7.24335 11.8897C6.98561 11.8897 6.77668 11.6808 6.77668 11.423L6.77668 2.08971C6.77668 1.83198 6.98561 1.62305 7.24335 1.62305Z",fill:"#3D3E45"}),n.jsx("path",{d:"M9.93845 9.4786C9.80779 9.4786 9.70045 9.43893 9.61645 9.3596C9.53712 9.2756 9.49745 9.17293 9.49745 9.0516L9.49745 5.0056C9.49745 4.88427 9.53712 4.78393 9.61645 4.7046C9.70045 4.6206 9.80312 4.5786 9.92445 4.5786L12.1995 4.5786C12.3208 4.5786 12.4211 4.61827 12.5005 4.6976C12.5845 4.77227 12.6265 4.87027 12.6265 4.9916C12.6265 5.09427 12.5845 5.18527 12.5005 5.2646C12.4211 5.34393 12.3208 5.3836 12.1995 5.3836L10.3725 5.3836V6.6156H11.8845C12.0058 6.6156 12.1061 6.65527 12.1855 6.7346C12.2695 6.80927 12.3115 6.90727 12.3115 7.0286C12.3115 7.13127 12.2695 7.22227 12.1855 7.3016C12.1061 7.38093 12.0058 7.4206 11.8845 7.4206H10.3725L10.3725 9.0516C10.3725 9.17293 10.3281 9.2756 10.2395 9.3596C10.1555 9.43893 10.0551 9.4786 9.93845 9.4786Z",fill:"#3D3E45"}),n.jsx("path",{d:"M3.34754 9.4786C3.21687 9.4786 3.10954 9.43893 3.02554 9.3596C2.94154 9.2756 2.89954 9.17293 2.89954 9.0516L2.89954 5.3836H1.80054C1.6792 5.3836 1.57654 5.34627 1.49254 5.2716C1.4132 5.19693 1.37354 5.09893 1.37354 4.9776C1.37354 4.85627 1.4132 4.7606 1.49254 4.6906C1.57654 4.61593 1.6792 4.5786 1.80054 4.5786H4.90854C5.02987 4.5786 5.1302 4.61593 5.20954 4.6906C5.29354 4.76527 5.33554 4.86327 5.33554 4.9846C5.33554 5.10593 5.29354 5.20393 5.20954 5.2786C5.1302 5.3486 5.02987 5.3836 4.90854 5.3836H3.80954L3.80954 9.0516C3.80954 9.17293 3.7652 9.2756 3.67654 9.3596C3.59254 9.43893 3.48287 9.4786 3.34754 9.4786Z",fill:"#3D3E45"})]}),ID=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("g",{clipPath:"url(#clip0_245_10828)",children:n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M9.91663 1.16634C9.91663 0.844175 9.65546 0.583008 9.33329 0.583008C9.01113 0.583008 8.74996 0.844175 8.74996 1.16634V1.74967L5.24996 1.74967V1.16634C5.24996 0.844175 4.98879 0.583008 4.66663 0.583008C4.34446 0.583008 4.08329 0.844175 4.08329 1.16634V1.74967H2.91663C1.95013 1.74967 1.16663 2.53318 1.16663 3.49967L1.16663 11.6663C1.16663 12.6328 1.95013 13.4163 2.91663 13.4163L11.0833 13.4163C12.0498 13.4163 12.8333 12.6328 12.8333 11.6663L12.8333 3.49967C12.8333 2.53318 12.0498 1.74967 11.0833 1.74967H9.91663V1.16634ZM11.6666 5.24967V3.49967C11.6666 3.17751 11.4055 2.91634 11.0833 2.91634H9.91663V3.49967C9.91663 3.82184 9.65546 4.08301 9.33329 4.08301C9.01113 4.08301 8.74996 3.82184 8.74996 3.49967V2.91634L5.24996 2.91634V3.49967C5.24996 3.82184 4.98879 4.08301 4.66663 4.08301C4.34446 4.08301 4.08329 3.82184 4.08329 3.49967V2.91634L2.91663 2.91634C2.59446 2.91634 2.33329 3.17751 2.33329 3.49967L2.33329 5.24967L11.6666 5.24967ZM2.33329 6.41634L11.6666 6.41634L11.6666 11.6663C11.6666 11.9885 11.4055 12.2497 11.0833 12.2497L2.91663 12.2497C2.59446 12.2497 2.33329 11.9885 2.33329 11.6663V6.41634Z",fill:"#3D3E45"})}),n.jsx("defs",{children:n.jsx("clipPath",{id:"clip0_245_10828",children:n.jsx("rect",{width:"14",height:"14",fill:"white"})})})]}),MD=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M3.11108 2.13932C2.78892 2.13932 2.52775 2.40049 2.52775 2.72266V10.8893C2.52775 11.2115 2.78892 11.4727 3.11108 11.4727H11.2778C11.5999 11.4727 11.8611 11.2115 11.8611 10.8893V2.72266C11.8611 2.40049 11.5999 2.13932 11.2778 2.13932H3.11108ZM1.36108 2.72266C1.36108 1.75616 2.14459 0.972656 3.11108 0.972656H11.2778C12.2442 0.972656 13.0278 1.75616 13.0278 2.72266V10.8893C13.0278 11.8558 12.2442 12.6393 11.2778 12.6393H3.11108C2.14459 12.6393 1.36108 11.8558 1.36108 10.8893V2.72266Z",fill:"#3D3E45"}),n.jsx("path",{d:"M9.84418 8.37166C9.94816 8.37166 10.0348 8.40631 10.1041 8.47563C10.1734 8.54494 10.2081 8.63159 10.2081 8.73556C10.2081 8.8352 10.1734 8.91968 10.1041 8.989C10.0348 9.05398 9.94816 9.08647 9.84418 9.08647H7.63475C7.52211 9.08647 7.4333 9.05182 7.36832 8.9825C7.30334 8.91318 7.27084 8.82437 7.27084 8.71607C7.27084 8.60776 7.30983 8.51245 7.38781 8.43014L8.80445 6.91603C8.96474 6.74274 9.09038 6.56512 9.18135 6.38317C9.27666 6.20121 9.32432 6.04309 9.32432 5.90879C9.32432 5.69218 9.2615 5.51889 9.13587 5.38892C9.01023 5.25462 8.84344 5.18747 8.63549 5.18747C8.55318 5.18747 8.4687 5.20697 8.38206 5.24596C8.29541 5.28495 8.21094 5.3391 8.12862 5.40842C8.05064 5.47773 7.977 5.55788 7.90768 5.64885C7.85569 5.71817 7.80371 5.76149 7.75172 5.77882C7.69973 5.79615 7.65208 5.80481 7.60876 5.80481C7.51345 5.80481 7.42464 5.77016 7.34233 5.70084C7.26435 5.62719 7.22536 5.54271 7.22536 5.44741C7.22536 5.37376 7.24918 5.30228 7.29684 5.23296C7.34882 5.16365 7.41164 5.09216 7.48529 5.01852C7.59359 4.91021 7.7149 4.8149 7.8492 4.73259C7.98349 4.65028 8.12213 4.58746 8.26509 4.54414C8.40805 4.49648 8.54668 4.47266 8.68098 4.47266C8.97124 4.47266 9.22251 4.53114 9.43479 4.64811C9.6514 4.76075 9.81819 4.92321 9.93516 5.13549C10.0521 5.34343 10.1106 5.59037 10.1106 5.8763C10.1106 6.11457 10.0391 6.381 9.89617 6.67559C9.75754 6.96585 9.56909 7.23878 9.33081 7.49438L8.50837 8.37166H9.84418Z",fill:"#3D3E45"}),n.jsx("path",{d:"M5.49994 9.08647C5.37864 9.08647 5.279 9.04965 5.20102 8.976C5.12304 8.89802 5.08405 8.80271 5.08405 8.69007V5.62518L4.70065 5.90879C4.64 5.95644 4.56418 5.98027 4.47321 5.98027C4.36923 5.98027 4.27826 5.94128 4.20028 5.8633C4.1223 5.78532 4.08331 5.69218 4.08331 5.58387C4.08331 5.44524 4.15046 5.3326 4.28475 5.24596L5.22051 4.62212C5.26384 4.59179 5.31149 4.57013 5.36348 4.55713C5.4198 4.54414 5.47178 4.53764 5.51944 4.53764C5.64507 4.53764 5.74471 4.57663 5.81836 4.65461C5.89201 4.72826 5.92883 4.8214 5.92883 4.93404V8.69007C5.92883 8.80271 5.88768 8.89802 5.80536 8.976C5.72738 9.04965 5.62558 9.08647 5.49994 9.08647Z",fill:"#3D3E45"})]}),VD=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{d:"M12.0334 5.64833C12.3099 5.64833 12.55 5.67744 12.7537 5.73565C12.9623 5.79386 13.1224 5.87632 13.2339 5.98303C13.3504 6.0849 13.4086 6.20859 13.4086 6.35412C13.4086 6.45113 13.3795 6.5433 13.3213 6.63061C13.263 6.71307 13.1782 6.7543 13.0666 6.7543C12.989 6.7543 12.9235 6.7446 12.8701 6.7252C12.8216 6.70094 12.778 6.67184 12.7392 6.63788C12.7004 6.60393 12.6543 6.5724 12.6009 6.54329C12.5524 6.51419 12.4772 6.49236 12.3754 6.47781C12.2783 6.45841 12.2056 6.44871 12.1571 6.44871C11.9097 6.44871 11.6987 6.50206 11.5241 6.60878C11.3543 6.7155 11.2233 6.86102 11.1311 7.04535C11.039 7.22482 10.9929 7.43341 10.9929 7.67109C10.9929 7.90393 11.039 8.11251 11.1311 8.29684C11.2282 8.47631 11.3591 8.61941 11.5241 8.72613C11.6938 8.83284 11.8879 8.8862 12.1061 8.8862C12.2274 8.8862 12.3317 8.87893 12.419 8.86437C12.5063 8.84982 12.5791 8.82799 12.6373 8.79889C12.7052 8.76008 12.7658 8.71885 12.8192 8.6752C12.8726 8.63154 12.9526 8.60971 13.0593 8.60971C13.1854 8.60971 13.2824 8.65094 13.3504 8.7334C13.4183 8.81102 13.4522 8.90803 13.4522 9.02445C13.4522 9.14572 13.3843 9.25728 13.2485 9.35915C13.1127 9.45616 12.9332 9.5362 12.7101 9.59926C12.4918 9.65747 12.2541 9.68657 11.997 9.68657C11.6138 9.68657 11.2815 9.59926 11.0002 9.42463C10.7188 9.24516 10.5005 9.00262 10.3453 8.69702C10.1949 8.39143 10.1198 8.04945 10.1198 7.67109C10.1198 7.27333 10.1998 6.92408 10.3599 6.62333C10.5248 6.31774 10.7504 6.08005 11.0366 5.91027C11.3276 5.73565 11.6599 5.64833 12.0334 5.64833Z",fill:"#3D3E45"}),n.jsx("path",{d:"M7.74826 5.64833C8.08781 5.64833 8.39099 5.73565 8.65778 5.91027C8.92942 6.08005 9.14285 6.31531 9.29807 6.61606C9.45815 6.9168 9.53819 7.26606 9.53819 7.66382C9.53819 8.06158 9.45815 8.41326 9.29807 8.71885C9.14285 9.0196 8.93184 9.25728 8.66505 9.43191C8.40311 9.60169 8.10722 9.68657 7.77737 9.68657C7.58334 9.68657 7.40143 9.65505 7.23166 9.59199C7.06188 9.52893 6.91151 9.44889 6.78054 9.35187C6.65442 9.25486 6.55498 9.15784 6.48222 9.06083C6.41431 8.95896 6.38035 8.87408 6.38035 8.80617L6.60591 8.71158V9.24273C6.60591 9.36885 6.56468 9.47557 6.48222 9.56288C6.39976 9.64534 6.29547 9.68657 6.16935 9.68657C6.04323 9.68657 5.93894 9.64534 5.85647 9.56288C5.77401 9.48042 5.73278 9.3737 5.73278 9.24273V4.67333C5.73278 4.54722 5.77401 4.44292 5.85647 4.36046C5.93894 4.27315 6.04323 4.22949 6.16935 4.22949C6.29547 4.22949 6.39976 4.27315 6.48222 4.36046C6.56468 4.44292 6.60591 4.54722 6.60591 4.67333V6.52147L6.48222 6.45598C6.48222 6.39292 6.51617 6.31774 6.58408 6.23042C6.652 6.13826 6.74416 6.04852 6.86058 5.96121C6.97699 5.86904 7.11039 5.79386 7.26076 5.73565C7.41599 5.67744 7.57849 5.64833 7.74826 5.64833ZM7.63912 6.44871C7.42569 6.44871 7.23893 6.50206 7.07886 6.60878C6.91879 6.7155 6.79267 6.86102 6.7005 7.04535C6.61319 7.22482 6.56953 7.43098 6.56953 7.66382C6.56953 7.8918 6.61319 8.10038 6.7005 8.28956C6.79267 8.47389 6.91879 8.61941 7.07886 8.72613C7.23893 8.83285 7.42569 8.8862 7.63912 8.8862C7.85255 8.8862 8.03688 8.83285 8.19211 8.72613C8.35218 8.61941 8.47587 8.47389 8.56319 8.28956C8.65535 8.10038 8.70143 7.8918 8.70143 7.66382C8.70143 7.43098 8.65535 7.22482 8.56319 7.04535C8.47587 6.86102 8.35218 6.7155 8.19211 6.60878C8.03688 6.50206 7.85255 6.44871 7.63912 6.44871Z",fill:"#3D3E45"}),n.jsx("path",{d:"M3.02845 5.66289L1.45681 9.35915C1.42286 9.45131 1.3695 9.52408 1.29674 9.57743C1.22883 9.62594 1.15364 9.65019 1.07118 9.65019C0.940211 9.65019 0.843196 9.61381 0.780136 9.54105C0.717077 9.46829 0.685547 9.37855 0.685547 9.27184C0.685547 9.22818 0.692823 9.1821 0.707375 9.13359L2.51913 4.78248C2.55793 4.68546 2.61614 4.61028 2.69375 4.55692C2.77622 4.50356 2.86353 4.48173 2.95569 4.49143C3.04301 4.49143 3.12304 4.51811 3.19581 4.57147C3.27342 4.61998 3.3292 4.69031 3.36316 4.78248L5.15308 9.04628C5.17733 9.10934 5.18946 9.16755 5.18946 9.2209C5.18946 9.35187 5.1458 9.45616 5.05849 9.53378C4.97603 9.61139 4.88386 9.65019 4.782 9.65019C4.69468 9.65019 4.61465 9.62352 4.54189 9.57016C4.47398 9.5168 4.42062 9.44404 4.38181 9.35187L2.81745 5.70654L3.02845 5.66289ZM1.68237 8.47146L2.08256 7.63471H4.04711L4.18536 8.47146H1.68237Z",fill:"#3D3E45"})]}),PD=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("g",{clipPath:"url(#clip0_567_6919)",children:n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.00001 1.02051C7.29533 1.02051 7.53473 1.25991 7.53473 1.55523V2.99492L11.3486 5.17429C11.5152 5.2695 11.6181 5.44667 11.6181 5.63856V9.97475L13.0725 10.702C13.3366 10.834 13.4437 11.1552 13.3116 11.4194C13.1795 11.6835 12.8583 11.7906 12.5942 11.6585L11.1002 10.9115L7.26531 13.1028C7.10091 13.1968 6.8991 13.1968 6.73471 13.1028L2.89985 10.9115L1.40581 11.6585C1.14167 11.7906 0.820476 11.6835 0.688405 11.4194C0.556335 11.1552 0.663399 10.834 0.92754 10.702L2.38195 9.97475V5.63856C2.38195 5.44667 2.48477 5.2695 2.65138 5.17429L6.46529 2.99492V1.55523C6.46529 1.25991 6.70469 1.02051 7.00001 1.02051ZM7.00001 3.9211L3.99444 5.63856L7.00001 7.35603L10.0056 5.63856L7.00001 3.9211ZM10.5486 6.55999L7.53473 8.28221V11.7171L10.5486 9.99492V6.55999ZM6.46529 11.7171V8.28221L3.4514 6.55999V9.99492L6.46529 11.7171Z",fill:"#3D3E45"})}),n.jsx("defs",{children:n.jsx("clipPath",{id:"clip0_567_6919",children:n.jsx("rect",{width:"14",height:"14",fill:"white"})})})]}),Ua=({type:e})=>{switch(e){case"boolean":return n.jsx(DD,{});case"date":return n.jsx(ID,{});case"number":return n.jsx(MD,{});case"string":return n.jsx(VD,{});case"dimension":return n.jsx(PD,{});default:return null}},AD={option:{fontFamily:"monospace","&.sub-option":{position:"relative",marginLeft:"22px"},"&.sub-option::before":{content:'""',width:"1px",height:"100%",position:"absolute",left:"-6px",borderLeft:"1px solid #E7E7E9"}},groupLabel:{cursor:"default",fontWeight:"normal","&::before":{content:'""',flex:1,insetInline:0,height:"calc(0.0625rem* var(--mantine-scale))",marginInlineEnd:"var(--mantine-spacing-xs)",borderBottom:"1px dashed var(--mantine-color-gray-2)"},"&::after":{borderBottom:"1px dashed var(--mantine-color-gray-2)",background:"none"}},group:{"&.dimension-group":{paddingBottom:"4px",".mantine-Combobox-groupLabel":{color:"#000"},".mantine-Combobox-groupLabel::before":{display:"none"},".mantine-Combobox-groupLabel::after":{display:"none"}}}},$D={root:{maxWidth:"unset"},option:{fontFamily:"monospace"},input:{paddingInlineStart:"var(--input-padding-inline-start)",height:"auto",color:"black",fontFamily:"monospace"}},Zc=(e,t,r)=>{const a=[];return t&&a.push("sub-option"),r&&a.push("disabled"),n.jsx(s.Combobox.Option,{value:e.value,className:a.join(" "),disabled:r,children:n.jsxs(s.Stack,{gap:1,children:[n.jsxs(s.Group,{gap:4,children:[!!e.dataType&&n.jsx(Ua,{type:e.dataType}),n.jsx(s.Text,{size:"xs",children:e.label})]}),n.jsx(s.Text,{size:"xs",c:"dimmed",pl:18,children:e.description})]})},e.value)},Jc=T.observer(({mmInfo:e,value:t,onChange:r,usedKeys:a})=>{const l=e.metricDetail,o=e.metrics.loading||l.loading,i=l.error,c=l.filterColOptions,d=s.useCombobox({onDropdownClose:()=>d.resetSelectedOption()}),u=h.useMemo(()=>o?n.jsx(s.Loader,{size:"xs"}):t?n.jsx(s.CloseButton,{size:"xs",onClick:()=>r(null)}):n.jsx(s.Combobox.Chevron,{size:"xs"}),[o,t]),p=n.jsx(s.InputBase,{component:"button",type:"button",variant:"unstyled",size:"xs",pointer:!0,rightSection:u,rightSectionPointerEvents:!o&&t?"all":"none",onClick:()=>d.toggleDropdown(),disabled:o||c.length===0,styles:$D,error:!!i,children:t||n.jsx(s.Input.Placeholder,{children:"选择维度"})});return n.jsxs(s.Combobox,{store:d,onOptionSubmit:f=>{r(f),d.closeDropdown()},styles:AD,children:[n.jsx(s.Combobox.Target,{children:i?n.jsx(s.Tooltip,{label:i,children:p}):p}),n.jsx(s.Combobox.Dropdown,{miw:300,children:n.jsx(s.Combobox.Options,{mah:500,style:{overflowY:"auto"},children:c.map(({group:f,items:v})=>n.jsx(s.Combobox.Group,{label:f,children:v.map(_=>{var w;return"group"in _?n.jsx(s.Combobox.Group,{className:"dimension-group",label:n.jsxs(s.Group,{gap:4,children:[n.jsx(Ua,{type:"dimension"}),n.jsx(s.Text,{size:"sm",children:_.group}),n.jsx(s.Text,{size:"xs",c:"dimmed",children:_.description})]}),children:(w=_.items)==null?void 0:w.map(m=>Zc(m,!0,a.has(m.value)))},_.group):Zc(_,!1,a.has(_.value))})},f))})})]})}),Hc={tbody:{td:{fontFamily:"monospace"}}},ED={root:{maxWidth:"unset"},option:{fontFamily:"monospace","&[data-checked=true][data-combobox-disabled]":{opacity:1}},input:{fontFamily:"monospace"},groupLabel:{"&::before":{content:'""',flex:1,insetInline:0,height:"calc(0.0625rem* var(--mantine-scale))",marginInlineEnd:"var(--mantine-spacing-xs)",backgroundColor:"var(--mantine-color-gray-2)"}}},BD=({option:e,...t})=>{const{t:r}=x.useTranslation(),a=e,l=a.type==="filter";return n.jsxs(s.Stack,{gap:0,py:4,styles:{root:{flexGrow:1,'&[data-selected="true"]':{".mantine-Text-root":{color:"white"},svg:{stroke:"white"}}}},...t,children:[n.jsx(s.Group,{flex:"1",gap:4,children:n.jsx(s.Text,{size:"xs",children:e.value})}),l&&n.jsxs(s.Group,{justify:"space-between",wrap:"nowrap",children:[n.jsx(s.Text,{size:"xs",c:t.checked?"rgba(255,255,255,.8)":"dimmed",style:{flexShrink:1,flexGrow:1},children:a.widget_label}),n.jsx(s.Text,{size:"xs",c:t.checked?"rgba(255,255,255,.8)":"dimmed",style:{flexShrink:0,flexGrow:0},children:r(st[a.widget])})]})]})},An=T.observer(({queryModel:e,value:t,onChange:r,usedKeys:a})=>{const{t:l}=x.useTranslation();e.config;const o=h.useMemo(()=>e.getConditionOptionsWithInvalidValue(t).optionGroups.map(d=>{const u=d.items.length;return{group:`${l(d.group)}(${u})`,items:d.items.map(f=>({...f,label:f.value,widget_label:f.label,disabled:a==null?void 0:a.has(f.value)}))}}),[e.getConditionOptionsWithInvalidValue,l,t,a]),i=h.useCallback((c,d)=>{r(c,d)},[r]);return n.jsx(s.Select,{size:"xs",variant:"unstyled",placeholder:"选择变量",styles:ED,data:o,renderOption:BD,maxDropdownHeight:600,value:t,onChange:i,clearable:!0})}),Ka=T.observer(({variable:e})=>{const t=W();if(!e)return null;const r=y.has(t.queryVariables,e);return n.jsx(s.ThemeIcon,{variant:"white",size:"xs",color:r?"#88CE98":"#F15050",styles:{root:{flexGrow:0,flexShrink:0}},children:n.jsx(S.IconPointFilled,{})})}),LD=T.observer(({queryModel:e})=>{const t=e.config,a=e.datasource.mericoMetricInfo;return h.useEffect(()=>{a.selectMetric(t.id)},[t.id,a]),n.jsxs(s.Stack,{gap:7,children:[n.jsxs(s.Group,{justify:"flex-start",gap:8,children:[n.jsx(s.Text,{size:"sm",children:"看板变量与指标维度关联"}),n.jsx(s.Tooltip,{label:"将看板的筛选器参数与指标的查询维度关联上,使指标可以按照看板的筛选条件和背景变量进行关联展示。",children:n.jsx(s.ActionIcon,{size:"xs",variant:"subtle",color:"gray",children:n.jsx(S.IconInfoCircle,{})})})]}),n.jsxs(s.Table,{withTableBorder:!0,withColumnBorders:!0,layout:"fixed",styles:Hc,children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:"49%"}}),n.jsx("col",{}),n.jsx("col",{style:{width:130}}),n.jsx("col",{style:{width:40}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:"指标筛选维度"}),n.jsx(s.Table.Td,{children:"看板变量"}),n.jsx(s.Table.Td,{colSpan:2,children:"变量值为真时运行查询"})]})}),n.jsxs(s.Table.Tbody,{children:[t.filters.map(l=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{pr:0,children:n.jsx(Jc,{mmInfo:a,value:l.dimension,onChange:l.setDimension,usedKeys:t.usedFilterDimensionKeys})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsxs(s.Group,{justify:"flex-start",grow:!0,gap:0,w:"100%",children:[n.jsx(Ka,{variable:l.variable}),n.jsx(An,{queryModel:e,value:l.variable,onChange:l.setVariable})]})}),n.jsx(s.Table.Td,{children:n.jsx(s.Checkbox,{size:"xs",checked:e.keyInRunBy(l.variable),onChange:o=>e.changeRunByRecord(l.variable,o.currentTarget.checked),color:"red"})})]},l.dimension)),n.jsxs(s.Table.Tr,{className:"add-a-row",children:[n.jsx(s.Table.Td,{pr:0,children:n.jsx(Jc,{mmInfo:a,value:null,onChange:l=>l&&t.addFilter(l,""),usedKeys:t.usedFilterDimensionKeys})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsx(An,{queryModel:e,value:null,onChange:l=>l&&t.addFilter("",l)})}),n.jsx(s.Table.Td,{})]})]})]})]})}),qD=T.observer(({queryModel:e,variable:t})=>{const r=e.keyInRunBy(t),a=l=>{e.changeRunByRecord(t,l.currentTarget.checked)};return n.jsx(s.Checkbox,{size:"xs",checked:r,onChange:a,color:"red"})}),Rc=({queryModel:e,variable:t})=>t?n.jsx(qD,{queryModel:e,variable:t}):null,OD=T.observer(({queryModel:e})=>{const t=e.config,l=e.datasource.mericoMetricInfo.metricDetail,o=l.trendingDateCol,i=t.timeQuery.enabled;return h.useEffect(()=>{if(!i&&l.requireTrendingReason){t.setTimeQueryEnabled(!0);return}},[l.requireTrendingReason,i]),l.supportTrending?l.requireTrendingReason?n.jsx(s.Tooltip,{label:l.requireTrendingReason,children:n.jsx(s.Box,{children:n.jsx(s.Switch,{size:"xs",color:"red",checked:!0,readOnly:!0,styles:{track:{cursor:"not-allowed"}}})})}):n.jsx(s.Switch,{size:"xs",color:"red",checked:i,onChange:c=>t.setTimeQueryEnabled(c.currentTarget.checked),styles:{track:{cursor:"pointer"}}}):n.jsx(s.Tooltip,{label:"由于指标未设定时序维度,所以不具备时间序列展示功能。",children:n.jsx(s.Box,{children:n.jsx(s.Switch,{size:"xs",color:"red",disabled:!o})})})}),ND=T.observer(({queryModel:e})=>{const t=e.config,l=e.datasource.mericoMetricInfo.metricDetail,o=l.trendingDateCol;return!t.timeQuery.enabled||!l.supportTrending?null:n.jsxs(s.Table,{withTableBorder:!0,withColumnBorders:!0,layout:"fixed",styles:Hc,children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:250}}),n.jsx("col",{}),n.jsx("col",{style:{width:130}}),n.jsx("col",{style:{width:40}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{}),n.jsx(s.Table.Td,{children:"看板变量"}),n.jsx(s.Table.Td,{colSpan:2,children:"变量值为真时运行查询"})]})}),n.jsxs(s.Table.Tbody,{children:[n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{pr:0,children:n.jsxs(s.Group,{gap:4,children:[n.jsx(s.Text,{size:"xs",children:"时间维度"}),n.jsx(s.Text,{size:"xs",c:"dimmed",ff:"monospace",children:(o==null?void 0:o.name)??null})]})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsxs(s.Group,{justify:"flex-start",gap:0,grow:!0,children:[n.jsx(Ka,{variable:t.timeQuery.range_variable}),n.jsx(An,{queryModel:e,value:t.timeQuery.range_variable,onChange:t.setRangeVariable,usedKeys:t.usedTimeQueryVariableSet})]})}),n.jsx(s.Table.Td,{children:n.jsx(Rc,{queryModel:e,variable:t.timeQuery.range_variable})})]},"dimension.time"),n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:n.jsx(s.Text,{size:"xs",children:"步长"})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsxs(s.Group,{justify:"flex-start",gap:0,grow:!0,children:[n.jsx(Ka,{variable:t.timeQuery.unit_variable}),n.jsx(An,{queryModel:e,value:t.timeQuery.unit_variable,onChange:t.setUnitVariable,usedKeys:t.usedTimeQueryVariableSet})]})}),n.jsx(s.Table.Td,{children:n.jsx(Rc,{queryModel:e,variable:t.timeQuery.unit_variable})})]},"dimension.step")]})]})}),GD=T.observer(({queryModel:e})=>n.jsxs(s.Stack,{gap:7,children:[n.jsxs(s.Group,{justify:"flex-start",gap:8,children:[n.jsx(s.Text,{size:"sm",children:"按时间序列展示"}),n.jsx(s.Tooltip,{label:"将看板的时间&步长筛选器与相应的查询维度关联上。",children:n.jsx(s.ActionIcon,{size:"xs",variant:"subtle",color:"gray",children:n.jsx(S.IconInfoCircle,{})})}),n.jsx(OD,{queryModel:e})]}),n.jsx(ND,{queryModel:e})]})),FD={label:{fontWeight:"normal"},input:{fontSize:"12px"},groupLabel:{cursor:"default",fontWeight:"normal","&::before":{content:'""',flex:1,insetInline:0,height:"calc(0.0625rem* var(--mantine-scale))",marginInlineEnd:"var(--mantine-spacing-xs)",borderBottom:"1px dashed var(--mantine-color-gray-2)"},"&::after":{borderBottom:"1px dashed var(--mantine-color-gray-2)",background:"none"}},option:{fontFamily:"monospace"}},jD=e=>{const t=e.option;return n.jsxs(s.Stack,{gap:1,styles:{root:{flexGrow:1}},children:[n.jsxs(s.Group,{gap:4,children:[n.jsx(Ua,{type:t.dataType}),n.jsx(s.Text,{size:"xs",children:t.label})]}),n.jsx(s.Text,{size:"xs",c:"dimmed",pl:18,children:t.description})]})},QD=T.observer(({queryModel:e})=>{const t=e.config,a=e.datasource.mericoMetricInfo,l=a.metricDetail,o=a.metrics.loading||l.loading,i=l.groupByColOptions,c=d=>{const u=l.getGroupByOptions(d),p=[];u.forEach(f=>{f.dimension?f.dimension.fields.forEach(v=>{typeof v=="string"?p.push(`${f.value} -> ${v}`):p.push(`${f.value} -> ${v.field}`)}):p.push(f.value)}),t.setGroupBys(p)};return n.jsxs(n.Fragment,{children:[n.jsx(s.MultiSelect,{size:"sm",label:"分组聚合维度",description:"指标在查询时按照哪些维度进行聚合计算。最多支持两个维度的聚合计算。若选择按时间序列展示,则仅可选择一个聚合维度。",data:i,searchable:!0,styles:FD,renderOption:jD,rightSection:o?n.jsx(s.Loader,{size:"xs"}):null,value:[...t.groupByValues],onChange:c,maxValues:t.timeQuery.enabled?1:2,placeholder:t.timeQuery.enabled?"仅可选一个维度":"最多选两个维度",disabled:o}),n.jsx(s.Switch,{labelPosition:"left",label:"聚合维度为空时,自动补零",size:"sm",color:"red",checked:t.useDefaultValues,onChange:d=>t.setUseDefaultValues(d.currentTarget.checked),disabled:i.length===0})]})}),WD=T.observer(({queryModel:e})=>{const t=e.config,r=t.id;return h.useEffect(()=>{if(e.run_by.length===0)return;const a=[],l=t.usedFilterVariableSet,o=t.usedTimeQueryVariableSet;e.run_by.forEach(i=>{(l.has(i)||o.has(i))&&a.push(i)}),e.setRunBy(a)},[t.usedFilterVariableSet,t.usedTimeQueryVariableSet,e.run_by]),n.jsxs(s.Stack,{gap:16,pos:"relative",children:[!r&&n.jsx(s.Overlay,{color:"#fff",backgroundOpacity:.5,blur:3,children:n.jsx(s.Center,{h:"100%",children:n.jsx(s.Text,{size:"sm",c:"black",children:"请先选择指标"})})}),n.jsx(LD,{queryModel:e}),n.jsx(GD,{queryModel:e}),n.jsx(QD,{queryModel:e})]})}),UD=["function process_result(resp, utils, state) {"," return resp.data","}"].join(`
572
+ `),KD={root:{minHeight:"350px",maxHeight:"50vh",height:"100%",overflow:"hidden"},list:{"&::before":{borderColor:"transparent"}},panel:{height:"calc(100% - 36px)",overflowY:"auto"}},YD=T.observer(({queryModel:e})=>{const[t,r]=h.useState("编辑查询");return n.jsxs(s.Tabs,{color:"red",defaultValue:"编辑查询",styles:KD,value:t,onChange:r,w:"60%",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"编辑查询",size:"xs",children:"编辑查询"}),n.jsx(s.Tabs.Tab,{value:"加工结果",size:"xs",children:"加工结果"}),n.jsx(s.Tabs.Tab,{value:"使用情况",size:"xs",children:"使用情况"})]}),n.jsx(s.Tabs.Panel,{value:"编辑查询",pt:"xs",children:n.jsx(WD,{queryModel:e})}),n.jsx(s.Tabs.Panel,{value:"加工结果",pt:"xs",children:n.jsx(xt,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:UD})}),n.jsx(s.Tabs.Panel,{value:"使用情况",pt:"xs",children:n.jsx(Uc,{queryModel:e})})]})}),XD=T.observer(({queryModel:e})=>{const t=e.metricQueryPayloadError;return t.length>0?n.jsxs(s.HoverCard,{shadow:"md",children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Box,{children:n.jsx(s.Button,{size:"xs",leftSection:n.jsx(Yc,{width:14,height:14,color:"rgb(173, 181, 189)"}),variant:"filled",color:"red",disabled:!0,children:"执行查询"})})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(s.List,{size:"xs",children:t.map(r=>n.jsx(s.List.Item,{children:r},r))})})]}):n.jsx(s.Button,{size:"xs",leftSection:n.jsx(Yc,{width:14,height:14}),variant:"filled",color:"red",onClick:()=>e.fetchData(!0),children:"执行查询"})}),ZD=({option:e,...t})=>{const r=e;return n.jsxs(s.Stack,{gap:0,py:4,styles:{root:{flexGrow:1,'&[data-selected="true"]':{".mantine-Text-root":{color:"white"},svg:{stroke:"white"}}}},...t,children:[n.jsxs(s.Group,{flex:"1",gap:4,children:[n.jsx(S.IconHash,{size:12}),n.jsx(s.Text,{size:"xs",children:r.label})]}),n.jsx(s.Text,{ml:16,size:"xs",c:t.checked?"rgba(255,255,255,.8)":"dimmed",children:r.description})]})},JD=T.observer(({queryModel:e})=>{const t=e.config,a=e.datasource.mericoMetricInfo,l=a.metrics;h.useEffect(()=>{l.load()},[l]),h.useEffect(()=>{!a.metricID&&t.id&&a.selectMetric(t.id)},[t.id]);const o=h.useMemo(()=>l.data.map(p=>({label:p.name,value:p.id,description:p.description,type:p.type})),[l.data]),i=h.useCallback((p,f)=>{p&&(a.selectMetric(p),t.setID(p),t.setType(f.type))},[a,t]),c=h.useMemo(()=>{const p=window.localStorage.getItem("ee_site_url")??"";let f=`${p}/dashboard/admin/metrics/list`;return t.id&&t.type&&(f=`${p}/dashboard/admin/metrics/details/${t.type}/${t.id}`),f.replace("//dashboard","/dashboard")},[t.id,t.type]),{loading:d,error:u}=l;return n.jsx(te,{children:n.jsxs(s.Group,{justify:"flex-end",gap:12,align:"flex-end",children:[u?n.jsx(s.Tooltip,{label:u,children:n.jsx(s.Select,{size:"xs",label:"指标",error:!0,styles:{root:{flexGrow:1}}})}):n.jsx(s.Select,{size:"xs",label:"指标",data:o,renderOption:ZD,styles:{root:{flexGrow:1}},maxDropdownHeight:500,value:t.id,onChange:i,rightSection:d?n.jsx(s.Loader,{size:"xs"}):null}),n.jsx(s.Tooltip,{label:"跳转到指标明细页查看详情。",disabled:d,children:n.jsx(s.Anchor,{size:"md",variant:"subtle",mb:2,href:c,target:"_blank",underline:"never",children:n.jsx(fD,{width:14,height:14})})})]})})}),HD=T.observer(({queryModel:e})=>{const{t}=x.useTranslation();return n.jsxs(s.Stack,{pt:8,pb:16,px:24,gap:8,styles:{root:{height:"100vh",overflow:"hidden"}},children:[n.jsx(s.Group,{styles:{root:{flexGrow:0,flexShrink:0}},children:n.jsx(s.TextInput,{size:"xs",placeholder:t("query.name_description"),label:t("query.name"),value:e.name,onChange:r=>{e.setName(r.currentTarget.value)},styles:{root:{flexGrow:0,width:"calc(50% - 44px)"}}})}),n.jsxs(s.Group,{justify:"space-between",grow:!0,gap:8,align:"flex-end",styles:{root:{flexGrow:0,flexShrink:0}},children:[n.jsxs(s.Group,{justify:"flex-start",grow:!0,gap:24,align:"flex-end",children:[n.jsx(jc,{queryModel:e,size:"xs"}),n.jsx(JD,{queryModel:e})]}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(XD,{queryModel:e}),n.jsx(vD,{queryModel:e})]})]}),n.jsxs(s.Group,{justify:"space-between",grow:!0,gap:12,align:"flex-start",sx:{flexGrow:0,flexShrink:1,overflowY:"hidden"},children:[n.jsx(YD,{queryModel:e}),n.jsx(zD,{queryModel:e})]}),n.jsx(kD,{queryModel:e})]})}),RD=T.observer(({id:e})=>{const r=F().queries.findByID(e);return e===""?null:r?r.isMericoMetricQuery?n.jsx(HD,{queryModel:r}):n.jsx(gD,{queryModel:r}):n.jsx(s.Text,{size:"14px",c:"red",children:"Invalid Query ID"})}),e3=T.observer(({value:e})=>{const r=J().payloadForSQL,a=h.useMemo(()=>ir(e,r),[e,r]);return n.jsx(ar,{height:"100%",value:a})}),t3=T.observer(({item:e,remove:t,onKeyChanged:r})=>{const{t:a}=x.useTranslation(),[l,o]=h.useState("SQL"),[i,c]=h.useState(e.key),d=()=>{e.setKey(i),r(i)},u=i!==e.key,p=e.isADuplicatedKey(i),[f,v]=h.useState(e.value),_=()=>{e.setValue(f)};h.useEffect(()=>{c(e.key),v(e.value)},[e]);const w=f!==e.value,m=Te.useModals(),k=()=>{m.openConfirmModal({title:`${a("sql_snippet.delete")}?`,labels:{confirm:a("common.actions.confirm"),cancel:a("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:t,confirmProps:{color:"red"},zIndex:320})};return n.jsxs(s.Stack,{p:20,sx:{minWidth:"1100px",height:"100vh"},gap:"sm",children:[n.jsxs(s.Group,{sx:{alignItems:"end"},gap:40,children:[n.jsx(s.TextInput,{label:a(p?"sql_snippet.key_occupied":"sql_snippet.key"),value:i,onChange:z=>{c(z.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:n.jsx(s.ActionIcon,{color:"blue",variant:"subtle",onClick:d,disabled:!u||p,children:n.jsx(S.IconDeviceFloppy,{size:16})}),error:p}),n.jsx(s.Button,{leftSection:n.jsx(S.IconTrash,{size:16}),color:"red",variant:"light",onClick:k,children:a("sql_snippet.delete")})]}),n.jsxs(s.Tabs,{value:l,onChange:o,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[n.jsxs(s.Tabs.List,{sx:{position:"relative"},children:[n.jsx(s.Tabs.Tab,{value:"SQL",children:a("sql_snippet.edit_snippet")}),n.jsx(s.Tabs.Tab,{value:"Preview",children:a("sql_snippet.preview_snippet")}),n.jsx(Wa,{}),n.jsx(s.ActionIcon,{color:"blue",variant:"filled",onClick:_,disabled:!w,sx:{position:"absolute",top:0,right:10},children:n.jsx(S.IconDeviceFloppy,{size:18})})]}),n.jsx(s.Tabs.Panel,{value:"SQL",pt:"sm",children:n.jsx(ar,{height:"100%",value:f,onChange:v,defaultLanguage:"sql",theme:"sql-dark"})}),n.jsx(s.Tabs.Panel,{value:"Preview",pt:"sm",children:n.jsx(e3,{value:f})})]})]})}),n3=T.observer(({id:e})=>{const t=W(),r=F(),a=h.useMemo(()=>r.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!a)return n.jsxs(s.Text,{size:"14px",children:["SQL Snippet by key[",e,"] is not found"]});const l=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])},o=()=>{r.sqlSnippets.removeByKey(e),l()},i=c=>{t.editor.setPath(["_SQL_SNIPPETS_",c])};return n.jsx(t3,{item:a,remove:o,onKeyChanged:i})}),r3=T.observer(()=>{const{t:e}=x.useTranslation(),[t,r]=h.useState([]),a=Te.useModals(),l=W(),o=v=>{l.editor.setPath(["_SQL_SNIPPETS_",v])},i=()=>{a.openConfirmModal({title:"Delete ununsed SQL snippets?",children:n.jsx(s.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>l.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},c=()=>{l.content.sqlSnippets.downloadSchema(t)},d=h.useMemo(()=>l.content.sqlSnippets.sortedList.map(v=>v.key),[l.content.sqlSnippets.sortedList]),u=()=>{r(d)},p=()=>{r([])},f=l.content.sqlSnippetsUsage;return n.jsxs(s.Stack,{sx:{height:"100%"},gap:"sm",pb:"59px",children:[n.jsx(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:n.jsx(s.Text,{size:"sm",px:"md",ta:"left",sx:{userSelect:"none",cursor:"default"},children:e("sql_snippet.manage")})}),n.jsxs(s.Flex,{justify:"space-between",align:"center",px:12,children:[n.jsxs(s.Group,{justify:"flex-start",children:[n.jsxs(s.Button.Group,{children:[n.jsx(s.Button,{variant:"default",size:"xs",onClick:u,children:e("common.actions.select_all")}),n.jsx(s.Button,{variant:"default",size:"xs",onClick:p,children:e("common.actions.clear_selection")})]}),n.jsx(s.Button,{size:"xs",color:"blue",leftSection:n.jsx(S.IconCode,{size:14}),disabled:t.length===0,onClick:c,children:e("common.actions.download_schema")})]}),n.jsx(s.Button,{variant:"subtle",size:"xs",color:"red",leftSection:n.jsx(S.IconTrash,{size:14}),disabled:!l.content.hasUnusedSQLSnippets,onClick:i,children:e("sql_snippet.delete_unused")})]}),n.jsx(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:n.jsx(s.Checkbox.Group,{size:"xs",value:t,onChange:r,children:n.jsxs(s.Table,{fz:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"40px"}}),n.jsx(s.Table.Th,{children:e("common.key")}),n.jsx(s.Table.Th,{style:{width:"100px",textAlign:"center"},children:e("sql_snippet.usage.label")}),n.jsx(s.Table.Th,{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),n.jsx(s.Table.Tbody,{children:l.content.sqlSnippets.sortedList.map(v=>{var w;const _=((w=f[v.key])==null?void 0:w.length)??0;return n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:n.jsx(s.Checkbox,{value:v.key,styles:{input:{cursor:"pointer"}}})}),n.jsx(s.Table.Td,{children:v.key}),n.jsx(s.Table.Td,{style:{color:_===0?"#ff0000":"#000",fontWeight:_===0?"bold":"normal",textAlign:"center"},children:_}),n.jsx(s.Table.Td,{children:n.jsx(s.Button,{variant:"subtle",size:"xs",onClick:()=>o(v.key),children:e("common.actions.open")})})]},v.key)})})]})})})]})}),a3=T.observer(({view:e})=>!e||e.type!==$.Division?null:n.jsx(s.Stack,{})),s3=T.observer(({view:e})=>{const{t,i18n:r}=x.useTranslation(),a=h.useMemo(()=>[{value:"default",label:t("common.tabs.variant.default")},{value:"outline",label:t("common.tabs.variant.outline")},{value:"pills",label:t("common.tabs.variant.pills")}],[r.language]),l=h.useMemo(()=>[{value:"horizontal",label:t("common.tabs.orientation.horizontal")},{value:"vertical",label:t("common.tabs.orientation.vertical")}],[r.language]);if(!e||e.type!==$.Tabs)return null;const o=e.config;return n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mt:8,mb:0,label:t("view.component.tabs.tabs_settings"),labelPosition:"center"}),n.jsx(s.Select,{label:t("common.tabs.variant.label"),value:o.variant,onChange:o.setVariant,data:a}),n.jsx(s.Select,{label:t("common.tabs.orientation.label"),value:o.orientation,onChange:o.setOrientation,data:l}),n.jsx(s.Switch,{label:t("common.tabs.grow_tabs"),checked:o.grow,onChange:i=>o.setGrow(i.currentTarget.checked)})]})}),l3=({disabled:e,value:t,onChange:r})=>{const a=l=>{l&&r(l)};return n.jsxs(s.Box,{sx:{position:"relative"},children:[e&&n.jsx(s.Overlay,{backgroundOpacity:.6,color:"#fff",zIndex:5,blur:2}),n.jsx(Ce,{height:"500px",defaultLanguage:"javascript",value:t,onChange:a,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},o3=({value:e,onChange:t})=>{const{t:r}=x.useTranslation(),[a,{setTrue:l,setFalse:o}]=O.useBoolean(),[i,c]=h.useState(e??Tn),d=_=>{c({...i,enabled:_})},u=()=>{o();const{enabled:_,func_content:w}=i,m={enabled:_,func_content:w};c(m),t(m)},p=()=>{o(),c(e)},f=_=>{c(w=>({...w,func_content:_}))},v=()=>{f(Tn.func_content)};return n.jsxs(n.Fragment,{children:[n.jsx(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:l,sx:{flexGrow:0},children:n.jsx(S.IconSettings,{size:14})}),n.jsx(s.Modal,{size:800,title:r("view.component.modal.custom_title"),opened:a,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:a&&n.jsxs(s.Stack,{children:[n.jsx(s.Checkbox,{mt:10,label:r("common.enabled"),checked:i.enabled,onChange:_=>d(_.currentTarget.checked)}),n.jsx(l3,{value:i.func_content,onChange:f,disabled:!i.enabled}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:v,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:r("common.actions.revert")}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:p,variant:"subtle",children:r("common.actions.cancel")}),n.jsx(s.Button,{onClick:u,children:r("common.actions.save")})]})]})]})})]})},i3=T.observer(({view:e})=>{const{t}=x.useTranslation();if(!e||e.type!==$.Modal)return null;const r=e.config,a=r.custom_modal_title.value;return n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mt:8,label:t("view.component.modal.modal_settings"),labelPosition:"center"}),n.jsxs(s.Flex,{gap:10,children:[n.jsx(s.TextInput,{label:t("view.component.modal.title"),value:a,onChange:y.noop,disabled:!0,sx:{flexGrow:1}}),n.jsx(o3,{value:r.custom_modal_title,onChange:r.custom_modal_title.replace})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.TextInput,{label:t("view.component.modal.width"),value:r.width,onChange:l=>r.setWidth(l.currentTarget.value),placeholder:"600px / 50vw"}),n.jsx(s.TextInput,{label:t("view.component.modal.height"),value:r.height,onChange:l=>r.setHeight(l.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),c3=T.observer(({view:e})=>n.jsxs(n.Fragment,{children:[n.jsx(a3,{view:e}),n.jsx(i3,{view:e}),n.jsx(s3,{view:e})]})),d3=T.observer(({view:e})=>{const{t,i18n:r}=x.useTranslation(),a=h.useMemo(()=>[{label:t("view.component.div.label"),value:$.Division},{label:t("view.component.modal.label"),value:$.Modal},{label:t("view.component.tabs.label"),value:$.Tabs}],[r.language]);return e?n.jsxs(s.Stack,{sx:{position:"relative"},children:[n.jsx(s.TextInput,{label:t("common.name"),value:e.name,onChange:l=>{e.setName(l.currentTarget.value)}}),n.jsx(s.Select,{label:t("common.type"),comboboxProps:{withinPortal:!0,zIndex:320},value:e.type,onChange:e.setType,data:a}),n.jsx(c3,{view:e})]}):null}),u3=T.observer(({id:e})=>{const{t}=x.useTranslation(),r=Te.useModals(),a=W(),l=F();if(e==="")return null;const o=l.views.findByID(e);if(!o)return n.jsxs(s.Text,{size:"14px",children:["View by ID[",e,"] is not found"]});const i=()=>{a.editor.setPath(["_VIEWS_",""])},c=()=>{r.openConfirmModal({title:`${t("view.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{l.views.removeByID(e),i()},confirmProps:{color:"red"},zIndex:320})};return n.jsxs(s.Stack,{sx:{maxWidth:"600px",height:"100%"},gap:"sm",children:[n.jsx(s.Group,{justify:"flex-end",pt:10,children:n.jsx(s.Button,{size:"xs",color:"red",leftSection:n.jsx(S.IconTrash,{size:16}),onClick:c,children:t("view.delete")})}),n.jsx(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:n.jsx(d3,{view:o})})]})}),p3=T.observer(()=>n.jsx(s.Stack,{sx:{height:"100%"},p:"sm",children:n.jsx(Qc,{})})),h3=T.observer(()=>{const e=W().editor,t=e.path;return I2(t)?n.jsx(p3,{}):M2(t)?n.jsx(nz,{}):V2(t)?n.jsx(tz,{}):P2(t)?n.jsx(s.Box,{p:"xs",pl:20,children:n.jsx(ez,{id:t[1]})}):A2(t)?n.jsx(r3,{}):$2(t)?n.jsx(n3,{id:t[1]}):B2(t)?n.jsx(Ez,{}):E2(t)?n.jsx(RD,{id:t[1]}):L2(t)?n.jsx(s.Box,{p:"xs",pl:20,children:n.jsx(u3,{id:t[1]})}):Ba(t)?n.jsx($z,{viewID:t[1],panelID:t[3]}):n.jsx(s.Box,{children:e.path})}),g3=T.observer(()=>n.jsx(h3,{})),f3=T.observer(()=>{const{t:e}=x.useTranslation(),t=W(),r=()=>{const a=new Date().getTime().toString(),l={id:a,key:a,label:a,order:t.content.filters.current.length+1,type:A.TextInput,config:oa(),visibleInViewsIDs:["Main"],auto_submit:!1};t.content.filters.append(l),t.editor.setPath(["_FILTERS_",a])};return n.jsx(s.Button,{variant:"subtle",leftSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:r,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("filter.add")})}),b3=T.observer(({parentID:e})=>{const{t}=x.useTranslation(),r=F();if(!e)return null;const a=r.views.findByID(e);return!a||a.type===$.Tabs?null:n.jsx(s.Button,{variant:"subtle",leftSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>r.addANewPanel(a.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:t("panel.add")})}),y3=T.observer(()=>{const{t:e}=x.useTranslation(),t=W(),r=()=>{const a=new Date().getTime().toString(),l={id:a,name:a,type:j.Postgresql,key:"",config:{_type:j.Postgresql,sql:""}};t.content.queries.append(l),t.editor.setPath(["_QUERIES_",a])};return n.jsx(s.Button,{variant:"subtle",leftSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:r,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("query.add")})}),v3=T.observer(()=>{const{t:e}=x.useTranslation(),t=W(),r=()=>{const a=new Date().getTime().toString(),l={key:a,value:""};t.content.sqlSnippets.append(l),t.editor.setPath(["_SQL_SNIPPETS_",a])};return n.jsx(s.Button,{variant:"subtle",leftSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:r,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("sql_snippet.add")})}),_3=T.observer(()=>{const{t:e}=x.useTranslation(),t=F();return n.jsx(s.Button,{variant:"subtle",leftSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("view.add")})}),x3=T.observer(()=>{const{t:e}=x.useTranslation(),t=W();return n.jsx(s.Button,{variant:"subtle",rightSection:n.jsx(S.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_QUERIES_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:e("query.manage")})}),w3=T.observer(()=>{const{t:e}=x.useTranslation(),t=W();return n.jsx(s.Button,{variant:"subtle",rightSection:n.jsx(S.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_SQL_SNIPPETS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:e("sql_snippet.manage")})}),m3=T.observer(()=>{const{t:e}=x.useTranslation(),t=W();return n.jsx(s.Button,{variant:"subtle",rightSection:n.jsx(S.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_FILTERS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:e("filter.manage")})}),C3=T.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?n.jsx(f3,{}):e==="_Add_A_SQL_SNIPPET_"?n.jsx(v3,{}):e==="_Add_A_QUERY_"?n.jsx(y3,{}):e==="_Add_A_VIEW_"?n.jsx(_3,{}):e==="_Add_A_PANEL_"?n.jsx(b3,{parentID:t}):e==="_QUERIES_SETTINGS_"?n.jsx(x3,{}):e==="_SQL_SNIPPETS_SETTINGS_"?n.jsx(w3,{}):e==="_FILTERS_SETTINGS_"?n.jsx(m3,{}):null),ed=T.observer(({option:e})=>{var p;const{t}=x.useTranslation(),r=W().editor,a=r.isOptionActive,l=a(r.path,e),o=r.isOptionOpened,i=r.navigate,c=o(e),[d,u]=h.useState(c);return h.useEffect(()=>{u(c)},[c]),n.jsx(s.NavLink,{active:l,defaultOpened:c,opened:d,onChange:u,label:t(e.label),onClick:()=>i(e),leftSection:e.Icon?n.jsx(e.Icon,{size:18}):null,children:(p=e.children)==null?void 0:p.map(f=>f._type==="ACTION"?n.jsx(C3,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):n.jsx(ed,{option:f},f.value))},e.label)}),S3=T.observer(()=>{const e=W();return n.jsx(s.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>n.jsx(ed,{option:t},t.value))})}),T3=T.observer(()=>{const{t:e}=x.useTranslation(),t=W();return n.jsxs(s.AppShell.Navbar,{p:0,sx:{height:"100vh - 60px - 60px",".mantine-NavLink-body":{wordWrap:"break-word"}},children:[n.jsx(s.AppShell.Section,{sx:{borderBottom:"1px solid #eee",padding:"var(--mantine-spacing-xs) var(--mantine-spacing-md)"},children:n.jsx(s.Text,{size:"sm",ta:"center",sx:{userSelect:"none",cursor:"default"},children:e("common.titles.settings")})}),n.jsx(s.AppShell.Section,{grow:!0,sx:{overflow:"auto"},children:n.jsx(S3,{})}),n.jsx(s.AppShell.Section,{children:n.jsx(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:n.jsx(s.Button,{size:"xs",color:"red",leftSection:n.jsx(S.IconX,{size:18}),onClick:()=>t.editor.close(),children:e("common.actions.close")})})})]})}),k3={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden",minWidth:"calc(var(--app-shell-navbar-width, 0px) + 1200px)"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},z3=T.observer(()=>{const e=W().editor;return n.jsx(s.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"},content:{overflowY:"hidden !important"}},children:n.jsxs(s.AppShell,{padding:0,navbar:{width:{base:220,xs:220,sm:240,md:260,lg:300,xl:320},breakpoint:"xxs"},styles:k3,children:[n.jsx(T3,{}),n.jsx(s.AppShell.Main,{children:n.jsx(g3,{})})]})})}),D3=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function I3(e){h.useEffect(()=>{if(Ce.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const r=D3(e);Ce.loader.config({paths:{vs:r}}),Ce.loader.init().then(a=>console.log("monaco instance:",a))},[])}const M3=e=>{const t=h.useCallback(r=>{const a=r||window.event;return a.preventDefault(),a&&(a.returnValue=""),""},[]);h.useEffect(()=>{if(e)return window.addEventListener("beforeunload",t),()=>{window.removeEventListener("beforeunload",t)}},[e])};Ns(),dl();const V3={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden","--app-shell-header-offset":"calc(3.75rem * var(--mantine-scale))"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},P3=({context:e,dashboard:t,content:r,update:a,className:l="dashboard",config:o,onChange:i,headerSlot:c,filterValues:d,onFilterValuesChange:u,onExit:p,lang:f},v)=>{I3(o.monacoPath),Zr(o);const{data:_=[]}=O.useRequest(Sa),{data:w=[]}=O.useRequest(Di),m=h.useMemo(()=>mc(t,r,_,w,e,d??{}),[t,r]);h.useImperativeHandle(v,()=>m,[m]),Cc(m.content,!0),h.useEffect(()=>{m.context.replace(e)},[e]),h.useEffect(()=>{m.datasources.replace(_)},[_]),h.useEffect(()=>{m.globalSQLSnippets.replace(w)},[w]),h.useEffect(()=>{u==null||u(m.content.filters.values)},[u,m.content.filters.values]),h.useEffect(()=>{d&&m.content.filters.patchValues(d)},[d,m.content.filters.patchValues]),h.useEffect(()=>Q.reaction(()=>Q.toJS(m.json),I=>{i==null||i(I)}),[m]);const k=async()=>{await a(m.json,m.content.json)},z=O.useCreation(Xr,[]),D=Sc(z);return M3(m.content.changed),O.useWhyDidYouUpdate("@devtable/dashboard editor",{context:e,dashboard:t,content:r,update:a,className:l,config:o,onChange:i,headerSlot:c,filterValues:d,onFilterValuesChange:u,onExit:p,lang:f}),n.jsx(dt.MantineEmotionProvider,{children:n.jsx(Vo,{lang:f,children:n.jsx(Te.ModalsProvider,{children:n.jsx(Zn,{children:n.jsx(jn,{value:{renderSearchButton:o.renderSearchButton},children:n.jsx(Fn,{value:m,children:n.jsx(Wn,{value:m.content,children:n.jsxs(Gt.Provider,{value:{inEditMode:!0},children:[n.jsx(dk,{}),n.jsx(rt.Provider,{value:z,children:n.jsxs(ln,{configure:D,children:[n.jsxs(s.AppShell,{padding:0,navbar:{width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},breakpoint:"xxs"},styles:V3,children:[n.jsx(gk,{onExit:p,saveDashboardChanges:k,headerSlot:c}),n.jsx(Gk,{}),n.jsx(s.AppShell.Main,{children:n.jsx(s.Box,{className:`${l} dashboard-root`,sx:{position:"relative"},children:m.content.views.visibleViews.map(I=>n.jsx(sc,{view:I},I.id))})})]}),n.jsx(z3,{})]})})]})})})})})})})})},A3=T.observer(h.forwardRef(P3)),Y5="",Ya=g.types.model({id:g.types.string,name:g.types.string,dashboard_id:g.types.string,create_time:g.types.string,update_time:g.types.string,version:g.types.string,filters:ma,queries:ka,sqlSnippets:Da,views:_a,panels:wa,layouts:za,mock_context:Jr}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,layouts:e.layouts.json,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get contentJSON(){return this.json.content},get payloadForSQL(){const t=g.getParent(e).context.current,r=g.getParent(e).globalSQLSnippets,a={context:{...e.mock_context.current,...t},filters:e.filters.valuesForPayload};return{...a,sql_snippets:Ut(e.sqlSnippets.current,"key","value",a),global_sql_snippets:Ut(r.list,"id","content",a)}},get payloadForViz(){const t=g.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.valuesForPayload}},get dashboardState(){const{context:t,filters:r}=this.payloadForViz,a={context:{},filters:e.filters.keyStateItemMap(r)};return Object.entries(t).forEach(([l,o])=>{a.context[l]={type:"context",key:l,value:o}}),a},get dashboardStateValues(){return lr(this.payloadForSQL)},getAdditionalQueryInfo(t){return{content_id:e.id,query_id:t,params:this.dashboardStateValues}},get data(){return e.queries.current.map(({id:r,data:a})=>({id:r,data:a})).reduce((r,a)=>(r[a.id]=a.data,r),{})},getDataStuffByID(t){const r=e.queries.findByID(t);return r?{data:r.data,len:r.data.length,state:r.state,error:r.error??r.metricQueryPayloadErrorString}:{data:[],len:0,state:"idle",error:void 0}}})).actions(e=>({}));function td({id:e,name:t,dashboard_id:r,create_time:a,update_time:l,content:o},i,c,d){if(!o)throw new Error("unexpected null content when creating a content model");const{version:u,filters:p,views:f,panels:v,layouts:_,definition:{queries:w,sqlSnippets:m,mock_context:k={}}}=o;return Ya.create({id:e,name:t,dashboard_id:r,create_time:a,update_time:l,version:u,filters:Ca(p,i,k,c),queries:Mi(w),sqlSnippets:Ai(m),mock_context:Hr(k),views:_i(f,d),panels:{list:v},layouts:{list:_,currentBreakpoint:_[0].id}})}const nd=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:Ya,content_id:g.types.string,datasources:yi,globalSQLSnippets:ba,context:kn});function rd({id:e,name:t,group:r,content_id:a},l,o,i,c,d,u){return nd.create({id:e,name:t,group:r,content_id:a,content:td(l,c,d,u),datasources:{list:o},globalSQLSnippets:{list:i},context:ya(c)})}Ns(),dl();const $3=({context:e,dashboard:t,content:r,className:a="dashboard",config:l,fullScreenPanelID:o,setFullScreenPanelID:i,filterValues:c,onFilterValuesChange:d,activeTab:u,onActiveTabChange:p,lang:f})=>{Zr(l);const{data:v=[]}=O.useRequest(Sa),{data:_=[]}=O.useRequest(Di),w=h.useMemo(()=>rd(t,r,v,_,e,c??{},u??null),[t,r]);Cc(w.content,!1),h.useEffect(()=>{w.context.replace(e)},[e]),h.useEffect(()=>{w.datasources.replace(v)},[v]),h.useEffect(()=>{w.globalSQLSnippets.replace(_)},[_]),h.useEffect(()=>{console.log("⚪️ calling onFilterValuesChange: ",w.content.filters.values),d==null||d(w.content.filters.values)},[d,w.content.filters.valuesString]),h.useEffect(()=>{c&&w.content.filters.patchValues(c)},[c,w.content.filters.patchValues]),h.useEffect(()=>{p==null||p(w.content.views.firstVisibleTabsViewActiveTab)},[p,w.content.views.firstVisibleTabsViewActiveTabStr]),h.useEffect(()=>{u&&w.content.views.setFirstVisibleTabsViewActiveTab(u)},[u,w.content.views.setFirstVisibleTabsViewActiveTab]);const m=O.useCreation(Xr,[w]),k=Sc(m);return O.useWhyDidYouUpdate("@devtable/dashboard render",{context:e,dashboard:t,content:r,className:a,config:l,fullScreenPanelID:o,setFullScreenPanelID:i,filterValues:c,onFilterValuesChange:d,activeTab:u,onActiveTabChange:p,lang:f}),n.jsx(dt.MantineEmotionProvider,{children:n.jsx(Vo,{lang:f,children:n.jsx(Te.ModalsProvider,{children:n.jsx(Zn,{children:n.jsx(jn,{value:{renderSearchButton:l.renderSearchButton},children:n.jsx(Fn,{value:w,children:n.jsx(Wn,{value:w.content,children:n.jsx(Xn.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:i},children:n.jsx(Gt.Provider,{value:{inEditMode:!1},children:n.jsx(s.Box,{className:`${a} dashboard-root`,children:n.jsx(rt.Provider,{value:m,children:n.jsx(ln,{configure:k,children:w.content.views.visibleViews.map(z=>n.jsx(In,{view:z},z.id))})})})})})})})})})})})})},E3=T.observer($3),B3=()=>Promise.resolve().then(()=>hu).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));C.APIClient=Ve,C.CURRENT_SCHEMA_VERSION=at,C.ClientPanelRender=YT,C.ContentModel=qa,C.ContentModelContext=Qn,C.ContentModelContextProvider=Wn,C.ContentRenderModel=Ya,C.ContextMeta=kn,C.DEFAULT_CUSTOM_MODAL_TITLE=Tn,C.DashboardApiClient=Ao,C.DashboardApiFacadeClient=$o,C.DashboardEditor=A3,C.DashboardFilterType=A,C.DashboardMode=lc,C.DashboardModel=wc,C.DashboardModelContextProvider=Fn,C.DashboardRenderModel=nd,C.DashboardThemeContextProvider=jn,C.DashboardViewEditor=sc,C.DashboardViewRender=In,C.DataSourceMetaModel=fa,C.DataSourceType=j,C.DataSourcesMetaModel=yi,C.DatesProvider=Zn,C.DefaultApiClient=Po,C.DefaultValueModeModelType=ea,C.DescriptionPopover=Ia,C.DraftModel=$i,C.EViewComponentType=$,C.FacadeApiClient=wS,C.FilterCheckboxConfigMeta=ta,C.FilterDateRangeConfigMeta=na,C.FilterMeta=Sn,C.FilterModel=ic,C.FilterMultiSelectConfigMeta=aa,C.FilterSelectConfigMeta=sa,C.FilterTextInputConfigMeta=la,C.FilterTreeSelectConfigMeta=da,C.FilterTreeSingleSelectConfigMeta=ua,C.FiltersModel=cc,C.FiltersRenderModel=ma,C.FullScreenPanel=ec,C.FullScreenPanelContext=Xn,C.GlobalSQLSnippetMeta=vi,C.GlobalSQLSnippetsMeta=ba,C.LayoutItemMeta=Ko,C.LayoutSetMeta=Yo,C.LayoutStateContext=Gt,C.LayoutsRenderModel=za,C.MericoMetricQueryMeta=Rr,C.MockContextMeta=Jr,C.MuteQueryModel=Ii,C.Panel=Ri,C.PanelContextProvider=Kn,C.PanelErrorOrStateMessage=Hi,C.PanelMeta=No,C.PanelModel=yc,C.PanelRender=$a,C.PanelRenderModel=xa,C.PanelStyleMeta=Bo,C.PanelTitleMeta=Lo,C.PanelVizAddons=Ji,C.PanelVizMeta=Oo,C.PanelVizSection=Pa,C.PanelsModel=vc,C.PanelsRenderModel=wa,C.QueriesModel=uc,C.QueriesRenderModel=ka,C.QueryMeta=Uo,C.QueryModel=dc,C.QueryRenderModel=Ta,C.ReadOnlyDashboard=E3,C.SQLSnippetMeta=Xo,C.SQLSnippetRenderModel=Pi,C.SQLSnippetsModel=pc,C.SQLSnippetsRenderModel=Da,C.VariableMeta=qo,C.ViewComponentTypeBackground=oc,C.ViewComponentTypeColor=h2,C.ViewComponentTypeName=p2,C.ViewDivisionConfig=pa,C.ViewMeta=bi,C.ViewModalConfig=ha,C.ViewRenderModel=va,C.ViewTabsConfig=ga,C.ViewsModel=_c,C.ViewsRenderModel=_a,C.Viz=Zi,C.applyPartialDashboard=j2,C.configureAPIClient=Zr,C.createContentModel=xc,C.createContentRenderModel=td,C.createContextMeta=ya,C.createDashboardModel=mc,C.createDashboardRenderModel=rd,C.createDraft=Ei,C.createFilterCheckboxConfig=Zo,C.createFilterDateRangeConfig=ti,C.createFilterMultiSelectConfig=ri,C.createFilterSelectConfig=ai,C.createFilterTextInputConfig=oa,C.createFilterTreeSelectConfig=ui,C.createFilterTreeSingleSelectConfig=pi,C.createMericoMetricQueryMetaConfig=Wo,C.createViewDivisionConfig=hi,C.createViewModalConfig=gi,C.createViewTabsConfig=fi,C.facadeApiClient=Eo,C.formatSQLSnippet=Ut,C.getInitialDashboardViewsModel=La,C.getInitialFiltersConfig=Ca,C.getInitialMockContextMeta=Hr,C.getInitialQueriesRenderModel=Mi,C.getInitialSQLSnippetsRenderModel=Ai,C.getInitialViewsRenderModel=_i,C.getNewPanel=Ci,C.getStaticDateRangeDefaultValue=Ro,C.getVersion=B3,C.initialDashboardContent=KS,C.notifyVizRendered=de,C.onVizRendered=Pp,C.pluginManager=Ct,C.pluginServices=R,C.useContentModelContext=Un,C.useDashboardContext=Nt,C.useDashboardThemeContext=Ms,C.useEditContentModelContext=F,C.useEditDashboardContext=W,C.useEditPanelContext=re,C.useFullScreenPanelContext=Es,C.useIsInEditPanelContext=$s,C.useIsInRenderPanelContext=As,C.usePanelFullScreen=tc,C.useRenderContentModelContext=J,C.useRenderDashboardContext=Ds,C.useRenderPanelContext=fe,C.useServiceLocator=Qt,C.useVisibleFilters=_T,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});