@@ -9,6 +9,7 @@ import { Fragment } from 'react/jsx-runtime';
99import { Accordion } from './ui/accordion' ;
1010import { useTranslation } from 'react-i18next' ;
1111import HeatMapChart from './graphs/HeatMap' ;
12+ import DistributionBarChart from './graphs/DistributionBarChart' ;
1213
1314const createArrayFromPythonDictionary = ( dict : Record < string , number > ) => {
1415 const resultArray = [ ] ;
@@ -23,6 +24,50 @@ const createArrayFromPythonDictionary = (dict: Record<string, number>) => {
2324 return resultArray ;
2425} ;
2526
27+ function createHeatmapdata ( resultItem : unknown ) {
28+ const columns : string [ ] = [ ] ;
29+ const heatmapList =
30+ typeof resultItem === 'string'
31+ ? JSON . parse ( resultItem as string )
32+ : ( resultItem as Record < string , unknown > ) ;
33+ const convertedData : number [ ] [ ] = [ ] ;
34+ let createdColumns = false ;
35+ if ( heatmapList ) {
36+ heatmapList . forEach (
37+ ( heatmapRow : number [ ] | object , rowIndex : number ) => {
38+ if ( Array . isArray ( heatmapRow ) ) {
39+ columns . push ( `${ rowIndex + 1 } ` ) ;
40+ convertedData . push ( heatmapRow ) ;
41+ } else {
42+ if ( typeof heatmapRow === 'object' ) {
43+ const temp = [ ] ;
44+ for ( const key in heatmapRow ) {
45+ temp . push (
46+ (
47+ heatmapRow as unknown as Record <
48+ string ,
49+ number
50+ >
51+ ) [ key ]
52+ ) ;
53+ if ( ! createdColumns ) {
54+ columns . push ( key ) ;
55+ }
56+ }
57+ createdColumns = true ;
58+ convertedData . push ( temp ) ;
59+ }
60+ }
61+ }
62+ ) ;
63+ }
64+
65+ return {
66+ columns,
67+ data : convertedData ,
68+ } ;
69+ }
70+
2671export default function ComponentMapper ( {
2772 items,
2873 data,
@@ -128,23 +173,108 @@ export default function ComponentMapper({
128173 </ ErrorBoundary >
129174 ) ;
130175 }
176+ case 'distribution' : {
177+ const realData = JSON . parse ( resultItem . real ) ;
178+ const syntheticData = JSON . parse ( resultItem . synthetic ) ;
179+ return (
180+ < div key = { `distribution-${ index } ` } >
181+ { realData . length === 0 ||
182+ syntheticData . length === 0
183+ ? null
184+ : Object . keys ( realData [ 0 ] ) . map (
185+ (
186+ columnName : string ,
187+ columnIndex : number
188+ ) => {
189+ const realDataColumn =
190+ realData . map (
191+ (
192+ row : Record <
193+ string ,
194+ number
195+ >
196+ ) => row [ columnName ]
197+ ) ;
198+ const syntheticDataColumn =
199+ syntheticData . map (
200+ (
201+ row : Record <
202+ string ,
203+ number
204+ >
205+ ) => row [ columnName ]
206+ ) ;
207+ return (
208+ < ErrorBoundary
209+ key = { columnIndex }
210+ >
211+ < DistributionBarChart
212+ realData = {
213+ realDataColumn
214+ }
215+ syntheticData = {
216+ syntheticDataColumn
217+ }
218+ column = { columnName }
219+ />
220+ </ ErrorBoundary >
221+ ) ;
222+ }
223+ ) }
224+ </ div >
225+ ) ;
226+ }
131227 case 'heatmap' : {
132- console . log ( 'heatmap data' , resultItem . data ) ;
133228 /*
229+ resultItem.real
230+ resultItem.synthetic
231+
134232 Array in Array
135233
136234 [
137235 [1,2,3],
138236 [4,5,6],
139237 [7,8,9]
140238 ]
239+
240+ of
241+
242+ Object in Array
243+
244+ [
245+ {a: 1, b: 2, c: 3},
246+ {a: 4, b: 5, c: 6},
247+ {a: 7, b: 8, c: 9}
248+ ]
141249 */
250+ const { columns : realColumns , data : convertedData } =
251+ createHeatmapdata ( resultItem . real ) ;
252+ const {
253+ columns : synthticColumns ,
254+ data : syntheticData ,
255+ } = createHeatmapdata ( resultItem . synthetic ) ;
142256 return (
143- < HeatMapChart
144- key = { index }
145- data = { resultItem . data }
146- title = { resultItem . title ?? '' }
147- />
257+ < div
258+ key = { `heatmap-${ index } ` }
259+ className = "grid lg:grid-cols-[50%_50%] grid-cols-[100%]"
260+ >
261+ < div className = "col-[1]" >
262+ < HeatMapChart
263+ columns = { realColumns }
264+ key = { index }
265+ data = { convertedData }
266+ title = { t ( 'heatmap.realdata' ) }
267+ />
268+ </ div >
269+ < div className = "col-[1] lg:col-[2]" >
270+ < HeatMapChart
271+ columns = { synthticColumns }
272+ key = { index }
273+ data = { syntheticData }
274+ title = { t ( 'heatmap.syntheticdata' ) }
275+ />
276+ </ div >
277+ </ div >
148278 ) ;
149279 }
150280 case 'barchart' : {
0 commit comments