示例#1
0
    def style_container(self, attrs, important=True, page=None):
        """
    Description:
    ------------
    Set the CSS style for the container page in a Jupyter Notebook.

    Usage::

      page = pk.Page()
      pk.jupyter.Notebook.display.full_width(page)

    Attributes:
    ----------
    :param attrs: Dictionary. Optional. The key, value pairs with the CSS attributes,
    :param important: Boolean. Optional. Set all the CSS attributes are important.
    :param page: Report. Optional. The web page or cell in the Jupyter notebook.
    """
        self.page = page or self.page
        if self.page is not None:
            self.page.properties.css.add_text(
                ".container {%s}" % Defaults_css.inline(attrs, important))
            return self

        else:
            return self.css(".container {%s}" %
                            Defaults_css.inline(attrs, important))
示例#2
0
    def __str__(self):
        header = [
            "<th style='width:%s%%;%s'>%s</th>" %
            (100 / len(self.labels), Defaults.inline(self.options.header), d)
            for d in self.labels
        ]
        body, row = [], []
        for i, day in enumerate(self.val):
            if 'number' in day:
                total_capacity, tooltip = 0, ["<b>%s</b>" % day['date']]
                for t in day.get("tasks", []):
                    c = t.get("capacity", 0)
                    total_capacity += c
                    tooltip.append("<div>%s: %s%%</div>" % (t['name'], c))
                if total_capacity > 100:
                    day["total_capacity"] = total_capacity
                    day["style"] = Defaults.inline(self.options.overload)
                    numer_day = "<div style='%(style)s' data-html='true' data-toggle='tooltip' title='overload: %(total_capacity)s%%'>%(number)s</div>" % day
                else:
                    day["style"] = Defaults.inline(self.options.number)
                    numer_day = "<div style='%(style)s'>%(number)s</div>" % day
                tasks = "<div>%s</div>" % "".join([
                    "<div style='width:100%%;height:20px;display:block;vertical-align:middle'><div style='background:%(color)s;width:100%%;height:%(capacity)s%%;display:inline-block' title='%(name)s: %(capacity)s%%'></div></div>"
                    % t for t in day.get("tasks", [])
                ])
                cell_style = Defaults.inline(self.options.today)
                if day.get("today", False):
                    row.append(
                        "<td data-placement='right' data-toggle='tooltip' data-html='true' title='<div>%s</div>' style='%s;background:%s'>%s%s</td>"
                        % ("".join(tooltip), cell_style,
                           self._report.theme.success[0], numer_day, tasks))
                else:
                    row.append(
                        "<td data-placement='right' data-toggle='tooltip' data-html='true' title='<div>%s</div>' style='%s'>%s%s</td>"
                        % ("".join(tooltip), cell_style, numer_day, tasks))
            else:
                row.append("<td style='padding:0'></td>")
            if i % len(self.labels) == 0:
                body.append("<tr>%s</tr>" % "".join(row))
                row = []
        if row:
            for i in range(7 - len(row)):
                row.append("<td style='padding:0'></td>")
            body.append("<tr>%s</tr>" % "".join(row))

        self._report._props['js']['onReady'].add(
            "%s.tooltip()" %
            JsQuery.decorate_var("'[data-toggle=tooltip]'", convert_var=False))
        return '<table %(strAttr)s><caption style="text-align:right">%(caption)s</caption><tr>%(header)s</tr>%(content)s</table>' % {
            'strAttr': self.get_attrs(pyClassNames=self.style.get_classes()),
            'caption': self.caption,
            'header': "".join(header),
            'content': "".join(body)
        }
示例#3
0
 def __str__(self):
   divs = []
   css_inline = Defaults.inline(self.options.style)
   for val in self.val:
     val["css_inline"] = css_inline
     divs.append("<div><div style='background:%(color)s;%(css_inline)s'></div>%(name)s</div>" % val)
   return '<div %s>%s</div>' % (self.get_attrs(css_class_names=self.style.get_classes()), "".join(divs))
示例#4
0
    def style_prompt(self, attrs, important=True, page=None):
        """
    Description:
    ------------

    :param attrs:
    :param important:
    :param page:
    :return:
    """
        self.page = page or self.page
        if self.page is not None:
            self.page.properties.css.add_text(
                ".prompt {%s}" % Defaults_css.inline(attrs, important))
            return self

        else:
            return self.css(".prompt {%s}" %
                            Defaults_css.inline(attrs, important))