@@ -21,23 +21,51 @@ interface SoloStyles {
2121 width : number ;
2222}
2323
24+ type plotlyData = {
25+ name : string ;
26+ x : string [ ] ;
27+ y : string [ ] ;
28+ type : string ;
29+ mode : string ;
30+ marker : { colors : string [ ] } ;
31+ } ;
32+
2433const HealthChart : React . FC < HealthChartProps > = React . memo ( props => {
25- // const { renderService, metric, timeList, valueList, sizing, colourGenerator } = props;
34+ // 'metrics' is an array of the user-specified metrics as objects
2635 const { serviceName, categoryName, metrics, timeList, sizing, colourGenerator } = props ;
2736 const [ solo , setSolo ] = useState < SoloStyles | null > ( null ) ;
28- // metrics = specific metrics in categories
29- // temporary y-axis values for testing purposes
30- const valueList = metrics [ 0 ] . books [ 0 ] . activememory_in_bytes
31- // filter through metrics to desired metrics and then plot them
37+ const timeArr = timeList . map ( ( el : any ) => moment ( el ) . format ( 'kk:mm:ss' ) ) ;
38+ const reverseTimeArr = timeArr . reverse ( ) ;
39+ const re = / _ / g ;
40+ const plotlyDataObjectArray : plotlyData [ ] = [ ] ;
3241
33- function generatePlotlyDataObjects ( metricsArray ) {
42+ // generates an array plotly data objects to add to be passed into our plotly chart's data prop
43+ const generatePlotlyDataObjects = ( metricsArray , timeArray ) => {
44+ console . log ( 'metricsArray: ' , metricsArray ) ;
45+ console . log ( 'timeArray: ' , timeArray ) ;
46+ // initalize an array of objects for output
3447 // iterate through the metricsArray
35- // each element is an array of num data (y-axis)
36- // generate a plotly data object to add to an array that will be passed into our plotly chart's data prop
37-
38- }
39-
40-
48+ // each element is an array of num data (y-axis)
49+ metricsArray . forEach ( el => {
50+ const originalMetricName = Object . keys ( el ) [ 0 ] ;
51+ const prettyMetricName = originalMetricName . replace ( re , ' ' ) ;
52+ const newColor = colourGenerator ( serviceName ) ;
53+ console . log ( 'prettyMetricName ' , prettyMetricName ) ;
54+ // plotly's data prop takes an array of objects that each have x, y, type, mode, marker
55+ const dataObject : plotlyData = {
56+ name : prettyMetricName ,
57+ x : timeArray ,
58+ y : el [ originalMetricName ] ,
59+ type : 'scattergl' ,
60+ mode : 'lines' ,
61+ marker : {
62+ colors : [ '#fc4039' , '#4b54ea' , '#32b44f' , '#3788fc' , '#9c27b0' , '#febc2c' ] ,
63+ } ,
64+ } ;
65+ plotlyDataObjectArray . push ( dataObject ) ;
66+ } ) ;
67+ console . log ( 'plotlydataObjectarray: ' , plotlyDataObjectArray ) ;
68+ } ;
4169
4270 setInterval ( ( ) => {
4371 if ( solo !== soloStyle ) {
@@ -46,34 +74,13 @@ const HealthChart: React.FC<HealthChartProps> = React.memo(props => {
4674 } , 20 ) ;
4775
4876 const createChart = ( ) => {
49- //
50- const timeArr = timeList . map ( ( el : any ) => moment ( el ) . format ( 'kk:mm:ss' ) ) ;
51- const reverseTimeArr = timeArr . reverse ( ) ;
52- const hashedColour = colourGenerator ( serviceName ) ;
53- const re = / _ / g;
54- type plotlyData = {
55- name : any ;
56- x : any ;
57- y : any ;
58- type : any ;
59- mode : any ;
60- marker : { color : string } ;
61- } ;
62- // const plotlyData = {
63- // name: metric.replace(re, ' '),
64- // x: reverseTimeArr, //reversed for better UX
65- // y: valueList,
66- // type: 'scattergl',
67- // mode: 'lines',
68- // marker: { color: hashedColour },
69- // };
77+ generatePlotlyDataObjects ( metrics , reverseTimeArr ) ;
7078 const sizeSwitch = sizing === 'all' ? all : solo ;
7179
7280 return (
7381 < Plot
74- // data takes an array of objects that each have x, y, type, mode, marker
75- data = { [ plotlyData ] }
76- config = { { displayModeBar : false } }
82+ data = { plotlyDataObjectArray }
83+ config = { { displayModeBar : true } }
7784 layout = { {
7885 title : `${ serviceName } | ${ categoryName } ` ,
7986 ...sizeSwitch ,
0 commit comments