/ src / evidently / ui / utils.py
utils.py
  1  EVIDENTLY_STYLES_COMMON = """
  2  <style>
  3  .evidently-links.container {{
  4      padding: 10px;
  5      font-family:
  6          -apple-system,
  7          BlinkMacSystemFont,
  8          Segoe UI,
  9          Roboto,
 10          Oxygen,
 11          Ubuntu,
 12          Cantarell,
 13          Fira Sans,
 14          Droid Sans,
 15          Helvetica Neue,
 16          sans-serif;
 17      -webkit-font-smoothing: antialiased;
 18      -moz-osx-font-smoothing: grayscale;
 19  
 20      display: flex;
 21      align-items: flex-start;
 22      flex-direction: column;
 23      gap: 10px;
 24  }}
 25  
 26  .evidently-links.container > p {{
 27      margin: 0;
 28      font-size: 0.85rem;
 29  }}
 30  
 31  .evidently-links.container > a {{
 32      font-size: 1rem;
 33      font-weight: bold;
 34      padding: 10px 15px;
 35      border-radius: 5px;
 36      background-color: #202830;
 37      color: #fff;
 38      border: 0;
 39      text-decoration: none;
 40      cursor: pointer;
 41      transition: all 0.2s;
 42  }}
 43  
 44  .evidently-links.container > a:hover {{
 45      background-color: #455565;
 46      color: #fff;
 47  }}
 48  </style>
 49  """
 50  
 51  HTML_LINK_WITH_ID_TEMPLATE = (
 52      EVIDENTLY_STYLES_COMMON
 53      + """
 54  <div class="evidently-links container">
 55      <a target="_blank" href="{button_url}">{button_title}</a>
 56      <p>
 57          <b>{id_title}:</b> <span>{id}</span>
 58      </p>
 59  </div>
 60  """
 61  )
 62  
 63  
 64  FILE_LINK_WITH_ID_TEMPLATE = (
 65      EVIDENTLY_STYLES_COMMON
 66      + """
 67  <div class="evidently-links container">
 68      <p>
 69          <b>{id_title}:</b> <span>{id}</span>
 70      </p>
 71      <p>
 72          <b>File:</b> <span>{url}</span>
 73      </p>
 74  </div>
 75  """
 76  )
 77  
 78  RUNNING_SERVICE_LINK_TEMPLATE = (
 79      EVIDENTLY_STYLES_COMMON
 80      + """
 81  <div class="evidently-links container">\
 82      <a target="_blank" href="{url_to_service}">{title}</a>
 83      <p>
 84          <b>{service_label}:</b> <a target="_blank" href="{url_to_service}">{url_to_service}</a>
 85      </p>
 86  </div>
 87  """
 88  )
 89  
 90  
 91  def _html_link_to_report_template(*, id: str, button_url: str, button_title: str, id_title: str) -> str:
 92      params = dict(
 93          id=id,
 94          id_title=id_title,
 95          button_title=button_title,
 96          button_url=button_url,
 97      )
 98  
 99      return HTML_LINK_WITH_ID_TEMPLATE.format(**params)
100  
101  
102  def _running_service_link_template(*, url_to_service: str, title: str, service_label: str):
103      params = dict(
104          url_to_service=url_to_service,
105          title=title,
106          service_label=service_label,
107      )
108  
109      return RUNNING_SERVICE_LINK_TEMPLATE.format(**params)
110  
111  
112  def _file_link_to_report_template(*, url_to_report: str, report_id: str):
113      params = dict(
114          id=report_id,
115          id_title="Report ID",
116          url=url_to_report,
117      )
118  
119      return FILE_LINK_WITH_ID_TEMPLATE.format(params)
120  
121  
122  def get_html_link_to_report(*, url_to_report: str, report_id: str):
123      return _html_link_to_report_template(
124          id=report_id,
125          id_title="Report ID",
126          button_title="View report",
127          button_url=url_to_report,
128      )
129  
130  
131  def get_html_link_to_running_service(
132      *, url_to_service: str, title: str = "Go to Service", service_label: str = "Service running on"
133  ):
134      return _running_service_link_template(url_to_service=url_to_service, title=title, service_label=service_label)
135  
136  
137  def get_file_link_to_report(*, url_to_report: str, report_id: str):
138      return _file_link_to_report_template(url_to_report=url_to_report, report_id=report_id)