2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
8 from datetime import datetime
9 from arvados._internal.report_template import ReportTemplate
14 .sortable thead th:not(.no-sort) {
17 .sortable thead th:not(.no-sort)::after, .sortable thead th:not(.no-sort)::before {
18 transition: color 0.1s ease-in-out;
22 .sortable thead th:not(.no-sort)::after {
26 .sortable thead th:not(.no-sort):hover::after {
29 .sortable thead th:not(.no-sort)[aria-sort=descending]::after {
33 .sortable thead th:not(.no-sort)[aria-sort=ascending]::after {
37 .sortable thead th:not(.no-sort).indicator-left::after {
40 .sortable thead th:not(.no-sort).indicator-left::before {
44 .sortable thead th:not(.no-sort).indicator-left:hover::before {
47 .sortable thead th:not(.no-sort).indicator-left[aria-sort=descending]::before {
51 .sortable thead th:not(.no-sort).indicator-left[aria-sort=ascending]::before {
56 table.aggtable td:nth-child(2) {
60 table.active-projects td:nth-child(4),
61 table.active-projects td:nth-child(5) {
66 table.single-project td:nth-child(3),
67 table.single-project td:nth-child(4) {
72 table.active-projects th:nth-child(4),
73 table.active-projects th:nth-child(5) {
77 table.project td:nth-child(3),
78 table.project td:nth-child(4),
79 table.project td:nth-child(5),
80 table.project td:nth-child(6),
81 table.project td:nth-child(7) {
86 table.project th:nth-child(3),
87 table.project th:nth-child(4),
88 table.project th:nth-child(5),
89 table.project th:nth-child(6),
90 table.project th:nth-child(7) {
96 def date_export(item):
97 if isinstance(item, datetime):
98 return """@new Date("{}")@""".format(item.strftime("%Y-%m-%dT%H:%M:%SZ"))
100 class ReportChart(ReportTemplate):
101 CSS = 'https://cdnjs.cloudflare.com/ajax/libs/dygraph/2.0.0/dygraph.min.css'
102 JSLIB = 'https://cdnjs.cloudflare.com/ajax/libs/dygraph/2.0.0/dygraph.min.js'
103 JSASSETS = ['synchronizer.js', 'dygraphs.js', 'sortable.js']
105 def __init__(self, label, cards, graphs):
106 super(ReportChart, self).__init__(label)
114 'charts': [self.chartdata(k, v)]
116 for k,v in self.graphs.items()]
118 def chartdata(self, label, stats):
123 'connectSeparatedPoints': True,
124 'labels': ['date', label[1]],
132 <script type="text/javascript" src="{jslib}"></script>
133 <script type="text/javascript">
134 var chartdata = {chartdata};\n{jsassets}
137 chartdata=json.dumps(self.sections(), default=date_export).replace('"@', '').replace('@"', '').replace('\\"', '"'),
138 jsassets='\n'.join([pkg_resources.resource_string('arvados_cluster_activity', jsa).decode('utf-8') for jsa in self.JSASSETS]))
141 return '\n'.join((super().style(),
143 '<link rel="stylesheet" href="{}">\n'.format(self.CSS)))