code: def _get_color_encoding(
      df: pd.DataFrame,
      color_value: Color | None,
      color_column: str | None,
      y_column_list: List[str],
      color_from_user: str | Color | List[Color] | None,
  ) -> alt.Color | alt.ColorValue | None:
      import altair as alt
  
      has_color_value = color_value not in [None, [], tuple()]
  
      # If user passed a color value, that should win over colors coming from the
      # color column (be they manual or auto-assigned due to melting)
      if has_color_value:
          # If the color value is color-like, return that.
          if is_color_like(cast(Any, color_value)):
              if len(y_column_list) != 1:
                  raise StreamlitColorLengthError(
                      [color_value], y_column_list
                  )
  
              return alt.ColorValue(
                  to_css_color(cast(Any, color_value))
              )
  
          # If the color value is a list of colors of approriate length, return that.
          elif isinstance(color_value, (list, tuple)):
              color_values = cast(Collection[Color], color_value)
  
              if len(color_values) != len(y_column_list):
                  raise StreamlitColorLengthError(
                      color_values, y_column_list
                  )
  
              if len(color_value) == 1:
                  return alt.ColorValue(
                      to_css_color(cast(Any, color_value[0]))
                  )
              else:
                  return alt.Color(
                      field=color_column,
                      scale=alt.Scale(
                          range=[to_css_color(c) for c in color_values]
                      ),
                      legend=COLOR_LEGEND_SETTINGS,
                      type="nominal",
                      title=" ",
                  )
  
          raise StreamlitInvalidColorError(df, color_from_user)
  
      elif color_column is not None:
          column_type: str | Tuple[str, List[Any]]
  
          if color_column == MELTED_COLOR_COLUMN_NAME:
              column_type = "nominal"
          else:
              column_type = type_util.infer_vegalite_type(
                  df[color_column]
              )
  
          color_enc = alt.Color(
              field=color_column,
              legend=COLOR_LEGEND_SETTINGS,
              type=column_type,
          )
  
          # Fix title if DF was melted
          if color_column == MELTED_COLOR_COLUMN_NAME:
              # This has to contain an empty space, otherwise the
              # full y-axis disappears (maybe a bug in vega-lite)?
              color_enc["title"] = " "
  
          # If the 0th element in the color column looks like a color, we'll use the color column's
          # values as the colors in our chart.
          elif len(df[color_column]) and is_color_like(
              df[color_column][0]
          ):
              color_range = [
                  to_css_color(c) for c in df[color_column].unique()
              ]
              color_enc["scale"] = alt.Scale(range=color_range)
              # Don't show the color legend, because it will just show text with the color values,
              # like #f00, #00f, etc, which are not user-readable.
              color_enc["legend"] = None
  
          # Otherwise, let Vega-Lite auto-assign colors.
          # This codepath is typically reached when the color column contains numbers (in which case
          # Vega-Lite uses a color gradient to represent them) or strings (in which case Vega-Lite
          # assigns one color for each unique value).
          else:
              pass
  
          return color_enc
  
      return None
  
imports: from __future__ import annotations
  from contextlib import nullcontext
  from datetime import date
  from enum import Enum
  from typing import TYPE_CHECKING, Any, Collection, Dict, List, Sequence, Tuple, cast
  import pandas
  from pandas.api.types import infer_dtype, is_integer_dtype
  from typing_extensions import Literal
  import streamlit.elements.arrow_vega_lite
  from streamlit import type_util
  from streamlit.color_util import Color, is_color_like, is_color_tuple_like, is_hex_color_like, to_css_color
  from streamlit.elements.altair_utils import AddRowsMetadata
  from streamlit.elements.arrow import Data
  from streamlit.elements.utils import last_index_for_melted_dataframes
  from streamlit.errors import Error, StreamlitAPIException
  from streamlit.proto.ArrowVegaLiteChart_pb2 import ArrowVegaLiteChart
  from streamlit.runtime.metrics_util import gather_metrics
label_desc: Use image node_id 18 for calling a global function with example usage: _get_color_encoding(df, color_value, color_column, y_column_list, color_from_user) and returns: None, alt, color_enc, alt, alt