Browse Source

Make size column configurable graph

This commit makes the size column configurable to graphs by
configuration file. And this commit adds color styles by thresholds
which are configurable.

Change-Id: Ifdc6961efbb178cc314c0fbd4d948a1ba19dcdd6
Masayuki Igawa 2 years ago
parent
commit
a34fdef1ed
4 changed files with 113 additions and 3 deletions
  1. 9
    0
      examples/openstack-gertty.yaml
  2. 15
    0
      gertty/config.py
  3. 16
    0
      gertty/palette.py
  4. 73
    3
      gertty/view/change_list.py

+ 9
- 0
examples/openstack-gertty.yaml View File

@@ -143,3 +143,12 @@ reviewkeys:
143 143
   - key: 'meta 4'
144 144
     approvals: []
145 145
     message: "recheck"
146
+
147
+# 'size-column' is a set of customize parameters for the 'Size' column
148
+# on your dashboard.
149
+# 'type' must be 'graph' or 'number'. Default is 'graph'.
150
+# 'thresholds' is for bar graphs width (when graph) or color styles
151
+# (when number).
152
+size-column:
153
+  type: 'graph'
154
+  thresholds: [1, 10, 100, 1000]

+ 15
- 0
gertty/config.py View File

@@ -111,6 +111,11 @@ class ConfigSchema(object):
111 111
 
112 112
     keymaps = [keymap]
113 113
 
114
+    thresholds = [int, int, int, int, int, int, int, int]
115
+    size_column = {v.Required('type'): v.Any('graph', 'splitGraph', 'number',
116
+                                             'disabled', None),
117
+                   v.Optional('thresholds'): thresholds}
118
+
114 119
     def getSchema(self, data):
115 120
         schema = v.Schema({v.Required('servers'): self.servers,
116 121
                            'palettes': self.palettes,
@@ -129,6 +134,7 @@ class ConfigSchema(object):
129 134
                            'breadcrumbs': bool,
130 135
                            'change-list-options': self.change_list_options,
131 136
                            'expire-age': str,
137
+                           'size-column': self.size_column,
132 138
                            })
133 139
         return schema
134 140
 
@@ -250,6 +256,15 @@ class Config(object):
250 256
 
251 257
         self.expire_age = self.config.get('expire-age', '2 months')
252 258
 
259
+        self.size_column = self.config.get('size-column', {})
260
+        self.size_column['type'] = self.size_column.get('type', 'graph')
261
+        if self.size_column['type'] == 'graph':
262
+            self.size_column['thresholds'] = self.size_column.get('thresholds',
263
+                [1, 10, 100, 1000])
264
+        else:
265
+            self.size_column['thresholds'] = self.size_column.get('thresholds',
266
+                [1, 10, 100, 200, 400, 600, 800, 1000])
267
+
253 268
     def getServer(self, name=None):
254 269
         for server in self.config['servers']:
255 270
             if name is None or name == server['name']:

+ 16
- 0
gertty/palette.py View File

@@ -98,6 +98,22 @@ DEFAULT_PALETTE={
98 98
     'added-removed-graph': ['dark green', 'dark red'],
99 99
     'focused-added-graph': ['default,standout', 'dark green'],
100 100
     'focused-removed-graph': ['default,standout', 'dark red'],
101
+    'line-count-threshold-1': ['light green', ''],
102
+    'focused-line-count-threshold-1': ['light green,standout', ''],
103
+    'line-count-threshold-2': ['light cyan', ''],
104
+    'focused-line-count-threshold-2': ['light cyan,standout', ''],
105
+    'line-count-threshold-3': ['light blue', ''],
106
+    'focused-line-count-threshold-3': ['light blue,standout', ''],
107
+    'line-count-threshold-4': ['yellow', ''],
108
+    'focused-line-count-threshold-4': ['yellow,standout', ''],
109
+    'line-count-threshold-5': ['dark magenta', ''],
110
+    'focused-line-count-threshold-5': ['dark magenta,standout', ''],
111
+    'line-count-threshold-6': ['light magenta', ''],
112
+    'focused-line-count-threshold-6': ['light magenta,standout', ''],
113
+    'line-count-threshold-7': ['dark red', ''],
114
+    'focused-line-count-threshold-7': ['dark red,standout', ''],
115
+    'line-count-threshold-8': ['light red', ''],
116
+    'focused-line-count-threshold-8': ['light red,standout', ''],
101 117
     }
102 118
 
103 119
 # A delta from the default palette

+ 73
- 3
gertty/view/change_list.py View File

@@ -104,6 +104,15 @@ class ChangeRow(urwid.Button, ChangeListColumns):
104 104
 
105 105
                         'added-graph': 'focused-added-graph',
106 106
                         'removed-graph': 'focused-removed-graph',
107
+
108
+                        'line-count-threshold-1': 'focused-line-count-threshold-1',
109
+                        'line-count-threshold-2': 'focused-line-count-threshold-2',
110
+                        'line-count-threshold-3': 'focused-line-count-threshold-3',
111
+                        'line-count-threshold-4': 'focused-line-count-threshold-4',
112
+                        'line-count-threshold-5': 'focused-line-count-threshold-5',
113
+                        'line-count-threshold-6': 'focused-line-count-threshold-6',
114
+                        'line-count-threshold-7': 'focused-line-count-threshold-7',
115
+                        'line-count-threshold-8': 'focused-line-count-threshold-8',
107 116
                         }
108 117
 
109 118
     def selectable(self):
@@ -148,7 +157,7 @@ class ChangeRow(urwid.Button, ChangeListColumns):
148 157
             return True
149 158
         return False
150 159
 
151
-    def _makeSize(self, added, removed):
160
+    def _makeSizeGraph(self, added, removed):
152 161
         # Removed is a red graph on top, added is a green graph on bottom.
153 162
         #
154 163
         # The graph is 4 cells wide.  If both the red and green graphs
@@ -165,7 +174,9 @@ class ChangeRow(urwid.Button, ChangeListColumns):
165 174
         ret = []
166 175
         # The graph is logarithmic -- one cell for each order of
167 176
         # magnitude.
168
-        for threshold in [1, 10, 100, 1000]:
177
+        conf_thresholds = self.app.config.size_column['thresholds']
178
+        # for threshold in [1, 10, 100, 1000]:
179
+        for threshold in conf_thresholds:
169 180
             color = []
170 181
             if (added > threshold and removed > threshold):
171 182
                 ret.append(('added-removed-graph', lower_box))
@@ -177,6 +188,36 @@ class ChangeRow(urwid.Button, ChangeListColumns):
177 188
                 ret.append(' ')
178 189
         return ret
179 190
 
191
+    def _makeSizeSplitGraph(self, added, removed):
192
+        # Removed is a red graph on right, added is a green graph on left.
193
+        # conf_thresholds[7]: Full block,
194
+        # conf_thresholds[6]: Left seven eighths block,
195
+        # ...., conf_thresholds[0]: Left one eighth block.
196
+        # You can see the character table at the wikipedia[1] or somewhere.
197
+        # [1] https://en.wikipedia.org/wiki/Block_Elements#Character_table
198
+        conf_thresholds = self.app.config.size_column['thresholds']
199
+        thresholds = [(conf_thresholds[7], u'\u2588'),
200
+                      (conf_thresholds[6], u'\u2589'),
201
+                      (conf_thresholds[5], u'\u258a'),
202
+                      (conf_thresholds[4], u'\u258b'),
203
+                      (conf_thresholds[3], u'\u258c'),
204
+                      (conf_thresholds[2], u'\u258d'),
205
+                      (conf_thresholds[1], u'\u258e'),
206
+                      (conf_thresholds[0], u'\u258f')]
207
+        ret = []
208
+        # The graph is logarithmic -- one cell for each order of
209
+        # magnitude.
210
+        for diff in [[added, 'added-graph'], [removed, 'removed-graph']]:
211
+            for threshold in thresholds:
212
+                if (diff[0] == 0):
213
+                    ret.append(' ')
214
+                    break
215
+                if (diff[0] >= threshold[0]):
216
+                    ret.append((diff[1], threshold[1]))
217
+                    break
218
+            ret.append(' ')
219
+        return ret
220
+
180 221
     def update(self, change, categories):
181 222
         if change.reviewed or change.hidden:
182 223
             style = 'reviewed-change'
@@ -217,7 +258,32 @@ class ChangeRow(urwid.Button, ChangeListColumns):
217 258
                 continue
218 259
             total_added += rfile.inserted or 0
219 260
             total_removed += rfile.deleted or 0
220
-        self.size.set_text(self._makeSize(total_added, total_removed))
261
+        if self.app.config.size_column['type'] == 'number':
262
+            total_added_removed = total_added + total_removed
263
+            thresholds = self.app.config.size_column['thresholds']
264
+            size_style = 'line-count-threshold-1'
265
+            if (total_added_removed >= thresholds[7]):
266
+                size_style = 'line-count-threshold-8'
267
+            elif (total_added_removed >= thresholds[6]):
268
+                size_style = 'line-count-threshold-7'
269
+            elif (total_added_removed >= thresholds[5]):
270
+                size_style = 'line-count-threshold-6'
271
+            elif (total_added_removed >= thresholds[4]):
272
+                size_style = 'line-count-threshold-5'
273
+            elif (total_added_removed >= thresholds[3]):
274
+                size_style = 'line-count-threshold-4'
275
+            elif (total_added_removed >= thresholds[2]):
276
+                size_style = 'line-count-threshold-3'
277
+            elif (total_added_removed >= thresholds[1]):
278
+                size_style = 'line-count-threshold-2'
279
+            elif (total_added_removed >= thresholds[0]):
280
+                size_style = 'line-count-threshold-1'
281
+            self.size.set_text((size_style, str(total_added_removed)))
282
+        elif self.app.config.size_column['type'] == 'splitGraph':
283
+            self.size.set_text(self._makeSizeSplitGraph(total_added,
284
+                                                          total_removed))
285
+        else:
286
+            self.size.set_text(self._makeSizeGraph(total_added, total_removed))
221 287
 
222 288
         self.category_columns = []
223 289
         for category in categories:
@@ -267,6 +333,7 @@ class ChangeListHeader(urwid.WidgetWrap, ChangeListColumns):
267 333
 @mouse_scroll_decorator.ScrollByWheel
268 334
 class ChangeListView(urwid.WidgetWrap, mywid.Searchable):
269 335
     required_columns = set(['Number', 'Subject', 'Updated'])
336
+    # FIXME(masayukig): Disable 'Size' column when configured
270 337
     optional_columns = set(['Topic', 'Branch', 'Size'])
271 338
 
272 339
     def getCommands(self):
@@ -344,6 +411,9 @@ class ChangeListView(urwid.WidgetWrap, mywid.Searchable):
344 411
             # not.
345 412
             self.enabled_columns.discard('Owner')
346 413
             self.disabled_columns.add('Owner')
414
+        if app.config.size_column['type'] == 'disabled':
415
+            self.enabled_columns.discard('Size')
416
+            self.disabled_columns.add('Size')
347 417
         self.sort_by = sort_by or app.config.change_list_options['sort-by']
348 418
         if reverse is not None:
349 419
             self.reverse = reverse

Loading…
Cancel
Save