@@ -55,14 +55,23 @@ export default async function convertDashboard(
5555 view : ViewWithInfo ,
5656 options : ConvertViewOptions
5757) : Promise < BrickConf > {
58- const { dataSource, widgets } = properties as {
58+ const {
59+ dataSource,
60+ groupField : _groupField ,
61+ widgets,
62+ } = properties as {
5963 dataSource : string ;
64+ groupField ?: string ;
6065 widgets : Array < Widget > ;
6166 } ;
6267
68+ const groupField = _groupField ? "#showKey" : undefined ;
69+
6370 const { isString, expression, usedContexts } = parseDataSource ( dataSource ) ;
6471
65- const chartData = isString ? `<%= (${ expression } ).list %>` : dataSource ;
72+ const chartData = isString
73+ ? `<%= CTX.__builtin_fn_extractList((${ expression } )) %>`
74+ : dataSource ;
6675
6776 if ( options . expanded ) {
6877 let mergedWidgets = widgets as MergedWidget [ ] ;
@@ -116,7 +125,8 @@ export default async function convertDashboard(
116125 } ,
117126 children : mergedWidgets . map ( ( widget ) => {
118127 const { title, /* type, */ metric, size, precision, min, max } = widget ;
119- const colorCount = widget . relevantMetrics ?. length ?? 1 ;
128+ const colorCount =
129+ widget . relevantMetrics ?. length ?? ( groupField ? 2 : 1 ) ;
120130 const colors = Array . from (
121131 { length : colorCount } ,
122132 ( _ , i ) => COLORS [ ( colorCursor + i ) % COLORS . length ]
@@ -128,7 +138,19 @@ export default async function convertDashboard(
128138 properties : {
129139 data : chartData ,
130140 xField : "time" ,
131- yFields : widget . relevantMetrics ?? [ metric . id ] ,
141+ ...( widget . relevantMetrics
142+ ? {
143+ // yFields: widget.relevantMetrics,
144+ yFields : `<% CTX.__builtin_fn_getMetricDisplayNames((${ expression } ).displayNameList, ${ JSON . stringify (
145+ widget . relevantMetrics
146+ ) } ) %>`,
147+ }
148+ : {
149+ // yField: metric.id,
150+ yField : `<% CTX.__builtin_fn_getMetricDisplayNames((${ expression } ).displayNameList, [${ JSON . stringify (
151+ metric . id
152+ ) } ])[0] %>`,
153+ } ) ,
132154 ...( widget . counterMetric
133155 ? {
134156 forceAbsoluteNumbers : true ,
@@ -141,7 +163,7 @@ export default async function convertDashboard(
141163 : null ) ,
142164 height : size === "large" ? 230 : 200 ,
143165 timeFormat : "HH:mm" ,
144- ...( widget . relevantMetrics
166+ ...( widget . relevantMetrics || groupField
145167 ? null
146168 : {
147169 areaOptions : {
@@ -164,8 +186,9 @@ export default async function convertDashboard(
164186 shape : "smooth" ,
165187 } ,
166188 } ,
189+ groupField,
167190 areaShape : "smooth" ,
168- legends : size === "large" ,
191+ legends : ! ! ( widget . relevantMetrics || groupField ) ,
169192 colors : colors ,
170193 tooltip : {
171194 marker : {
@@ -221,18 +244,82 @@ export default async function convertDashboard(
221244 } ;
222245 }
223246
247+ if ( groupField ) {
248+ return {
249+ brick : "div" ,
250+ properties : {
251+ style : {
252+ display : "flex" ,
253+ flexDirection : "column" ,
254+ gap : "8px" ,
255+ } ,
256+ } ,
257+ children : [
258+ {
259+ brick : ":forEach" ,
260+ dataSource : `<%= CTX.__builtin_fn_groupMetricData(CTX.__builtin_fn_extractList((${ expression } )), ${ JSON . stringify ( groupField ) } ) %>` ,
261+ children : [
262+ {
263+ brick : "div" ,
264+ properties : {
265+ textContent : "<% `${ITEM.group}:` %>" ,
266+ style : {
267+ fontWeight : "500" ,
268+ } ,
269+ } ,
270+ } ,
271+ {
272+ brick : "div" ,
273+ properties : {
274+ style : {
275+ display : "grid" ,
276+ gridTemplateColumns : "repeat(auto-fill, minmax(205px, 1fr))" ,
277+ gap : "10px" ,
278+ marginBottom : "8px" ,
279+ } ,
280+ } ,
281+ children : widgets . map ( ( widget , i ) => {
282+ const { title, type, metric, precision } = widget ;
283+ return {
284+ brick : "ai-portal.stat-with-mini-chart" ,
285+ properties : {
286+ size : "small" ,
287+ label : title || metric . id ,
288+ data : "<% ITEM.list %>" ,
289+ xField : "time" ,
290+ yField : metric . id ,
291+ lineColor : COLORS [ i % COLORS . length ] ,
292+ ...( metric . unit === "percent(1)"
293+ ? { min : 0 , max : 1 , showArea : true }
294+ : metric . unit === "percent(100)" || metric . unit === "%"
295+ ? { min : 0 , max : 100 , showArea : true }
296+ : { showArea : type === "area" } ) ,
297+ value : `<%= CTX.__builtin_fn_getLatestMetricValue(ITEM.list, ${ JSON . stringify (
298+ {
299+ metric,
300+ precision,
301+ }
302+ ) } ) %>`,
303+ } ,
304+ } ;
305+ } ) ,
306+ } ,
307+ ] ,
308+ } ,
309+ ] ,
310+ } ;
311+ }
312+
224313 return {
225314 brick : "div" ,
226315 properties : {
227316 style : {
228317 display : "grid" ,
229318 gridTemplateColumns : "repeat(auto-fill, minmax(205px, 1fr))" ,
230319 gap : "10px" ,
231- // gridTemplateColumns: "repeat(auto-fill, minmax(375px, 1fr))",
232- // gap: "12px",
233320 } ,
234321 } ,
235- children : widgets . map ( ( widget ) => {
322+ children : widgets . map ( ( widget , i ) => {
236323 const { title, type, metric, precision } = widget ;
237324 return {
238325 brick : "ai-portal.stat-with-mini-chart" ,
@@ -242,14 +329,16 @@ export default async function convertDashboard(
242329 data : chartData ,
243330 xField : "time" ,
244331 yField : metric . id ,
245- lineColor : "#295DFF" ,
332+ lineColor : COLORS [ i % COLORS . length ] ,
246333 ...( metric . unit === "percent(1)"
247334 ? { min : 0 , max : 1 , showArea : true }
248335 : metric . unit === "percent(100)" || metric . unit === "%"
249336 ? { min : 0 , max : 100 , showArea : true }
250337 : { showArea : type === "area" } ) ,
251338 value : `<%= CTX.__builtin_fn_getLatestMetricValue((${
252- isString ? expression : JSON . stringify ( dataSource ?? null )
339+ isString
340+ ? `CTX.__builtin_fn_extractList((${ expression } ))`
341+ : JSON . stringify ( dataSource ?? null )
253342 } ), ${ JSON . stringify ( {
254343 metric,
255344 precision,
0 commit comments