def create_timeline_chart()

in visualize/generate.py [0:0]


def create_timeline_chart(epoch_data):
    def process_items(items):
        timeline_comp = []
        timeline_comm = []
        x_data = []
        current_time = 0 
        len_data = len(items) + 1
        x_data.append(f"{current_time:.3f}")
        for i,item in enumerate(items):
            if item.comm_type != CommType.epoch_end:
                # y = [None] * len_data
                start_time = current_time
                end_time = current_time + item._elapsed_time
                if i < len_data - 1 and item.comm_type == CommType.computation:  
                    y = [None] * (i + 2)
                    y[i] = 1
                    y[i+1] = 1
                    timeline_comp.append({
                        'value': y,
                        'stage': item.stage,
                        'elapsed_time': item._elapsed_time,
                        'comm_type':item.comm_type
                    })
                elif i < len_data - 1:
                    y = [None] * (i + 2)
                    y[i] = 2
                    y[i+1] = 2
                    timeline_comm.append({
                        'value': y,
                        'stage': item.stage,
                        'elapsed_time': item._elapsed_time,
                        'comm_type':item.comm_type
                    })
                x_data.append(f"{end_time:.3f}")
                current_time = end_time
        return timeline_comp,timeline_comm,x_data
    
    computation_timeline = []
    communication_timeline = []
    computation_timeline,communication_timeline,x_data = process_items(epoch_data)
    # Calculate computation time and communication time
    total_computation_time = sum(item['elapsed_time'] for item in computation_timeline)
    total_communication_time = sum(item['elapsed_time'] for item in communication_timeline)

    line = Line()
    line.add_xaxis(x_data)

    for comp_y in computation_timeline:
        line.add_yaxis(
            "Computation",
            comp_y['value'],
            is_connect_nones=False,
            label_opts=opts.LabelOpts(is_show=False),
            linestyle_opts=opts.LineStyleOpts(width=5),  
            tooltip_opts=opts.TooltipOpts(
                    formatter=f"stage: {comp_y['stage']}<br>elapsed_time: {comp_y['elapsed_time']}<br>comm_type: {comp_y['comm_type']}"  
                ),
        )
    

    for comm_y in communication_timeline:
        
        line.add_yaxis(
            "communication",
            comm_y['value'],
            is_connect_nones=False,
            label_opts=opts.LabelOpts(is_show=False),
            linestyle_opts=opts.LineStyleOpts(width=5),  
            tooltip_opts=opts.TooltipOpts(
                    formatter=f"stage: {comm_y['stage']}<br>elapsed_time: {comm_y['elapsed_time']}<br>comm_type: {comm_y['comm_type']}"  
                ),
        )


    line.set_global_opts(
        title_opts=opts.TitleOpts(title="Computation and Communication Timeline"),
        xaxis_opts=opts.AxisOpts(name="Time (ms)",type_ = "value"),#type_ = "value"
        yaxis_opts=opts.AxisOpts(name="Type", max_=3,axislabel_opts=opts.LabelOpts(is_show=False),axistick_opts=opts.AxisTickOpts(is_show=False)  
                                 ),
        tooltip_opts=opts.TooltipOpts(trigger="axis"),

        datazoom_opts=[
            opts.DataZoomOpts(type_="slider", range_start=0, range_end=100),
            opts.DataZoomOpts(type_="inside", range_start=0, range_end=100),
        ],
        legend_opts=opts.LegendOpts(
            type_="scroll",
            pos_left="right",
            orient="vertical",
        ),
        
    )
    #comp—comm Pie
    pie = Pie()
    pie.add(
        "",
        [
            ("Computation", total_computation_time),
            ("Communication", total_communication_time)
        ],
        radius=["40%", "75%"],
    )
    pie.set_global_opts(
        title_opts=opts.TitleOpts(title="Computation vs Communication time Ratio"),
        legend_opts=opts.LegendOpts(type_="scroll", pos_left="80%", orient="vertical")
    )
    pie.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{d}%"))
    return line,pie