@@ -21,23 +21,51 @@ interface SoloStyles {
21
21
width : number ;
22
22
}
23
23
24
+ type plotlyData = {
25
+ name : string ;
26
+ x : string [ ] ;
27
+ y : string [ ] ;
28
+ type : string ;
29
+ mode : string ;
30
+ marker : { colors : string [ ] } ;
31
+ } ;
32
+
24
33
const 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
26
35
const { serviceName, categoryName, metrics, timeList, sizing, colourGenerator } = props ;
27
36
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 [ ] = [ ] ;
32
41
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
34
47
// 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
+ } ;
41
69
42
70
setInterval ( ( ) => {
43
71
if ( solo !== soloStyle ) {
@@ -46,34 +74,13 @@ const HealthChart: React.FC<HealthChartProps> = React.memo(props => {
46
74
} , 20 ) ;
47
75
48
76
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 ) ;
70
78
const sizeSwitch = sizing === 'all' ? all : solo ;
71
79
72
80
return (
73
81
< 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 } }
77
84
layout = { {
78
85
title : `${ serviceName } | ${ categoryName } ` ,
79
86
...sizeSwitch ,
0 commit comments