1#-----------------------------------------------------------------------------
2# Copyright (c) 2012 - 2021, Anaconda, Inc., and Bokeh Contributors.
3# All rights reserved.
4#
5# The full license is in the file LICENSE.txt, distributed with this software.
6#-----------------------------------------------------------------------------
7""" Provide ``Factor`` and ``FactorSeq`` properties. """
8
9#-----------------------------------------------------------------------------
10# Boilerplate
11#-----------------------------------------------------------------------------
12import logging # isort:skip
13log = logging.getLogger(__name__)
14
15#-----------------------------------------------------------------------------
16# Imports
17#-----------------------------------------------------------------------------
18
19# Bokeh imports
20from .container import Seq, Tuple
21from .either import Either
22from .nullable import NonNullable
23from .primitive import String
24from .singletons import Intrinsic
25
26#-----------------------------------------------------------------------------
27# Globals and constants
28#-----------------------------------------------------------------------------
29
30__all__ = (
31    "Factor",
32    "FactorSeq",
33)
34
35#-----------------------------------------------------------------------------
36# General API
37#-----------------------------------------------------------------------------
38
39L1Factor = String
40L2Factor = Tuple(String, String)
41L3Factor = Tuple(String, String, String)
42
43class Factor(NonNullable):
44    """ Represents a single categorical factor. """
45
46    def __init__(self, default=Intrinsic, *, help=None, serialized=None, readonly=False):
47        type_param = Either(L1Factor, L2Factor, L3Factor)
48        super().__init__(type_param, default=default, help=help, serialized=serialized, readonly=readonly)
49
50class FactorSeq(NonNullable):
51    """ Represents a collection of categorical factors. """
52
53    def __init__(self, default=Intrinsic, *, help=None, serialized=None, readonly=False):
54        type_param = Either(Seq(L1Factor), Seq(L2Factor), Seq(L3Factor))
55        super().__init__(type_param, default=default, help=help, serialized=serialized, readonly=readonly)
56
57#-----------------------------------------------------------------------------
58# Dev API
59#-----------------------------------------------------------------------------
60
61#-----------------------------------------------------------------------------
62# Private API
63#-----------------------------------------------------------------------------
64
65#-----------------------------------------------------------------------------
66# Code
67#-----------------------------------------------------------------------------
68