@@ -1816,43 +1816,41 @@ def infer_config(args, constructor, trace_patch, layout_patch):
1816
1816
1817
1817
def get_orderings (args , grouper , grouped ):
1818
1818
"""
1819
- `orders` is the user-supplied ordering (with the remaining data-frame-supplied
1820
- ordering appended if the column is used for grouping). It includes anything the user
1821
- gave, for any variable, including values not present in the dataset. It is used
1822
- downstream to set e.g. `categoryarray` for cartesian axes
1823
-
1824
- `group_names` is the set of groups, ordered by the order above
1825
-
1826
- `group_values` is a subset of `orders` in both keys and values. It contains a key
1827
- for every grouped mapping and its values are the sorted *data* values for these
1828
- mappings.
1819
+ `orders` is the user-supplied ordering with the remaining data-frame-supplied
1820
+ ordering appended if the column is used for grouping. It includes anything the user
1821
+ gave, for any variable, including values not present in the dataset. It's a dict
1822
+ where the keys are e.g. "x" or "color"
1823
+
1824
+ `sorted_group_names` is the set of groups, ordered by the order above. It's a list
1825
+ of tuples like [("value1", ""), ("value2", "")] where each tuple contains the name
1826
+ of a single dimension-group
1829
1827
"""
1828
+
1830
1829
orders = {} if "category_orders" not in args else args ["category_orders" ].copy ()
1831
- group_names = []
1832
- group_values = {}
1830
+ for col in grouper :
1831
+ if col != one_group :
1832
+ uniques = args ["data_frame" ][col ].unique ()
1833
+ if col not in orders :
1834
+ orders [col ] = list (uniques )
1835
+ else :
1836
+ orders [col ] = list (orders [col ])
1837
+ for val in uniques :
1838
+ if val not in orders [col ]:
1839
+ orders [col ].append (val )
1840
+
1841
+ sorted_group_names = []
1833
1842
for group_name in grouped .groups :
1834
1843
if len (grouper ) == 1 :
1835
1844
group_name = (group_name ,)
1836
- group_names .append (group_name )
1837
- for col in grouper :
1838
- if col != one_group :
1839
- uniques = args ["data_frame" ][col ].unique ()
1840
- if col not in orders :
1841
- orders [col ] = list (uniques )
1842
- else :
1843
- orders [col ] = list (orders [col ])
1844
- for val in uniques :
1845
- if val not in orders [col ]:
1846
- orders [col ].append (val )
1847
- group_values [col ] = sorted (uniques , key = orders [col ].index )
1845
+ sorted_group_names .append (group_name )
1848
1846
1849
1847
for i , col in reversed (list (enumerate (grouper ))):
1850
1848
if col != one_group :
1851
- group_names = sorted (
1852
- group_names ,
1849
+ sorted_group_names = sorted (
1850
+ sorted_group_names ,
1853
1851
key = lambda g : orders [col ].index (g [i ]) if g [i ] in orders [col ] else - 1 ,
1854
1852
)
1855
- return orders , group_names , group_values
1853
+ return orders , sorted_group_names
1856
1854
1857
1855
1858
1856
def make_figure (args , constructor , trace_patch = None , layout_patch = None ):
@@ -1873,15 +1871,13 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
1873
1871
grouper = [x .grouper or one_group for x in grouped_mappings ] or [one_group ]
1874
1872
grouped = args ["data_frame" ].groupby (grouper , sort = False )
1875
1873
1876
- orders , sorted_group_names , sorted_group_values = get_orderings (
1877
- args , grouper , grouped
1878
- )
1874
+ orders , sorted_group_names = get_orderings (args , grouper , grouped )
1879
1875
1880
1876
col_labels = []
1881
1877
row_labels = []
1882
1878
nrows = ncols = 1
1883
1879
for m in grouped_mappings :
1884
- if m .grouper not in sorted_group_values :
1880
+ if m .grouper not in orders :
1885
1881
m .val_map ["" ] = m .sequence [0 ]
1886
1882
else :
1887
1883
sorted_values = orders [m .grouper ]
0 commit comments