|
19 | 19 | Sequence,
|
20 | 20 | Tuple,
|
21 | 21 | Union,
|
| 22 | + cast, |
22 | 23 | )
|
23 | 24 | from uuid import uuid4
|
24 | 25 |
|
|
55 | 56 | CSSPair = Tuple[str, Union[str, int, float]]
|
56 | 57 | CSSList = List[CSSPair]
|
57 | 58 | CSSProperties = Union[str, CSSList]
|
58 |
| -CSSStyles = List[Dict[str, CSSProperties]] |
| 59 | +CSSStyles = List[Dict[str, CSSProperties]] # = List[CSSDict] |
| 60 | +# class CSSDict(TypedDict): # available when TypedDict is valid in pandas |
| 61 | +# selector: str |
| 62 | +# props: CSSProperties |
59 | 63 |
|
60 | 64 | try:
|
61 | 65 | from matplotlib import colors
|
@@ -566,7 +570,7 @@ def _translate(self):
|
566 | 570 | "body": body,
|
567 | 571 | "uuid": uuid,
|
568 | 572 | "precision": precision,
|
569 |
| - "table_styles": table_styles, |
| 573 | + "table_styles": _format_table_styles(table_styles), |
570 | 574 | "caption": caption,
|
571 | 575 | "table_attributes": table_attr,
|
572 | 576 | }
|
@@ -1904,25 +1908,14 @@ def _pseudo_css(self, uuid: str, name: str, row: int, col: int, text: str):
|
1904 | 1908 | -------
|
1905 | 1909 | pseudo_css : List
|
1906 | 1910 | """
|
| 1911 | + selector_id = "#T_" + uuid + "row" + str(row) + "_col" + str(col) |
1907 | 1912 | return [
|
1908 | 1913 | {
|
1909 |
| - "selector": "#T_" |
1910 |
| - + uuid |
1911 |
| - + "row" |
1912 |
| - + str(row) |
1913 |
| - + "_col" |
1914 |
| - + str(col) |
1915 |
| - + f":hover .{name}", |
| 1914 | + "selector": selector_id + f":hover .{name}", |
1916 | 1915 | "props": [("visibility", "visible")],
|
1917 | 1916 | },
|
1918 | 1917 | {
|
1919 |
| - "selector": "#T_" |
1920 |
| - + uuid |
1921 |
| - + "row" |
1922 |
| - + str(row) |
1923 |
| - + "_col" |
1924 |
| - + str(col) |
1925 |
| - + f" .{name}::after", |
| 1918 | + "selector": selector_id + f" .{name}::after", |
1926 | 1919 | "props": [("content", f'"{text}"')],
|
1927 | 1920 | },
|
1928 | 1921 | ]
|
@@ -2077,6 +2070,26 @@ def _maybe_convert_css_to_tuples(style: CSSProperties) -> CSSList:
|
2077 | 2070 | return style
|
2078 | 2071 |
|
2079 | 2072 |
|
| 2073 | +def _format_table_styles(styles: CSSStyles) -> CSSStyles: |
| 2074 | + """ |
| 2075 | + looks for multiple CSS selectors and separates them: |
| 2076 | + [{'selector': 'td, th', 'props': 'a:v;'}] |
| 2077 | + ---> [{'selector': 'td', 'props': 'a:v;'}, |
| 2078 | + {'selector': 'th', 'props': 'a:v;'}] |
| 2079 | + """ |
| 2080 | + return [ |
| 2081 | + item |
| 2082 | + for sublist in [ |
| 2083 | + [ # this is a CSSDict when TypedDict is available to avoid cast. |
| 2084 | + {"selector": x, "props": style["props"]} |
| 2085 | + for x in cast(str, style["selector"]).split(",") |
| 2086 | + ] |
| 2087 | + for style in styles |
| 2088 | + ] |
| 2089 | + for item in sublist |
| 2090 | + ] |
| 2091 | + |
| 2092 | + |
2080 | 2093 | def _non_reducing_slice(slice_):
|
2081 | 2094 | """
|
2082 | 2095 | Ensure that a slice doesn't reduce to a Series or Scalar.
|
|
0 commit comments