Repository: roboflow/supervision
File: supervision/detection/line_zone.py (Python)

Code before:
        self,
        frame: np.ndarray,
        line_zones: List[LineZone],
        line_zone_labels: Optional[List[str]] = None,
    ) -> np.ndarray:
        """
        Draw a table on the frame, showing how many items of each class
        crossed each line.

        Args:
            frame (np.ndarray): The image on which the table will be drawn.
            line_zones (List[LineZone]): The line zones used to count
                the objects.
            line_zone_labels (Optional[List[str]]): The labels for each line
                zone. If not specified, the labels will be `Line 1:`,
                `Line 2:`, etc.

        Returns:
            (np.ndarray): The image with the table drawn on it.
        """
        if line_zone_labels is None:
            line_zone_labels = [f"Line {i + 1}:" for i in range(len(line_zones))]
        if len(line_zones) != len(line_zone_labels):
            raise ValueError("The number of line zones and their labels must match.")

        text = "Line Crossings:\n"
        for line_zone, line_zone_label in zip(line_zones, line_zone_labels):
            text += f"{line_zone_label}\n"
            class_id_to_name = line_zone.class_id_to_name

            if len(line_zone.in_count_per_class) > 0:
                text += " In:\n"
                for class_id, count in line_zone.in_count_per_class.items():
                    if not self.force_draw_class_ids and class_id in class_id_to_name:
                        class_name = class_id_to_name[class_id]
                    else:
                        class_name = str(class_id)
                    text += f"  {class_name}: {count}\n"

            if len(line_zone.out_count_per_class) > 0:
                text += " Out:\n"
                for class_id, count in line_zone.out_count_per_class.items():
                    if class_id in class_id_to_name and not self.force_draw_class_ids:
                        class_name = class_id_to_name[class_id]
                    else:
                        class_name = str(class_id)
                    text += f"  {class_name}: {count}\n"

        table_width = 0
        table_height = 0
        text_lines = text.split("\n")

Review comment (suggestion):
```suggestion
        text_lines = ["Line Crossings:"]
```

Code after:
        frame: np.ndarray,
        line_zones: List[LineZone],
        line_zone_labels: Optional[List[str]] = None,
    ) -> np.ndarray:
        if line_zone_labels is None:
            line_zone_labels = [f"Line {i + 1}:" for i in range(len(line_zones))]
        if len(line_zones) != len(line_zone_labels):
            raise ValueError("The number of line zones and their labels must match.")

        text_lines = ["Line Crossings:"]
        for line_zone, line_zone_label in zip(line_zones, line_zone_labels):
            text_lines.append(line_zone_label)
            class_id_to_name = line_zone.class_id_to_name

            for direction, count_per_class in [
                ("In", line_zone.in_count_per_class),
                ("Out", line_zone.out_count_per_class),
            ]:
                if not count_per_class:
                    continue

                text_lines.append(f" {direction}:")
                for class_id, count in count_per_class.items():
                    class_name = (
                        class_id_to_name.get(class_id, str(class_id))
                        if not self.force_draw_class_ids
                        else str(class_id)
                    )
                    text_lines.append(f"  {class_name}: {count}")

        table_width, table_height = 0, 0
        for line in text_lines:
            text_width, text_height = cv2.getTextSize(
                line, cv2.FONT_HERSHEY_SIMPLEX, self.text_scale, self.text_thickness
            )[0]
            text_height += TEXT_MARGIN
            table_width = max(table_width, text_width)
            table_height += text_height

        table_width += 2 * self.table_padding
        table_height += 2 * self.table_padding
        table_max_height = frame.shape[0] - 2 * self.table_margin
        table_height = min(table_height, table_max_height)
        table_width = min(table_width, self.table_max_width)

        position_map = {
            Position.TOP_LEFT: (self.table_margin, self.table_margin),
            Position.TOP_RIGHT: (
                frame.shape[1] - table_width - self.table_margin,
                self.table_margin,
            ),