Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
topydo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
topydo
Commits
30f5bb1a
Commit
30f5bb1a
authored
Dec 03, 2015
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Color blocks can also be requested as HTML color codes
The Dot output now uses these colors for the nodes.
parent
306d7497
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
46 deletions
+71
-46
topydo/lib/Colorblock.py
topydo/lib/Colorblock.py
+65
-45
topydo/lib/DotPrinter.py
topydo/lib/DotPrinter.py
+6
-1
No files found.
topydo/lib/Colorblock.py
View file @
30f5bb1a
...
...
@@ -20,52 +20,67 @@ from topydo.lib.Colors import int_to_ansi, Colors
from
topydo.lib.Recurrence
import
relative_date_to_date
COLOR16_RANGE
=
[
10
,
# light green
2
,
# green
3
,
# yellow
1
,
# red
(
10
,
'#00ff00'
,
'#000000'
),
# light green
(
2
,
'#008700'
,
'#ffffff'
),
# green
(
3
,
'#ffff00'
,
'#000000'
),
# yellow
(
1
,
'#ff0000'
,
'#ffffff'
),
# red
]
# https://upload.wikimedia.org/wikipedia/en/1/15/Xterm_256color_chart.svg
# a gradient from green to yellow to red
COLOR256_RANGE
=
\
[
22
,
28
,
34
,
40
,
46
,
82
,
118
,
154
,
190
,
226
,
220
,
214
,
208
,
202
,
196
]
COLOR256_RANGE
=
[
(
22
,
'#005f00'
,
'#ffffff'
),
(
28
,
'#008700'
,
'#ffffff'
),
(
34
,
'#00af00'
,
'#ffffff'
),
(
40
,
'#00d700'
,
'#000000'
),
(
46
,
'#00ff00'
,
'#000000'
),
(
82
,
'#5fff00'
,
'#000000'
),
(
118
,
'#87ff00'
,
'#000000'
),
(
154
,
'#afff00'
,
'#000000'
),
(
190
,
'#dfff00'
,
'#000000'
),
(
226
,
'#ffff00'
,
'#000000'
),
(
220
,
'#ffd700'
,
'#000000'
),
(
214
,
'#ffaf00'
,
'#000000'
),
(
208
,
'#ff8700'
,
'#000000'
),
(
202
,
'#ff5f00'
,
'#ffffff'
),
(
196
,
'#ff0000'
,
'#ffffff'
),
]
def
progress_color_code
(
p_todo
,
p_safe
=
True
):
def
get_
length
():
def
_progress_to_color
(
p_todo
,
p_safe
=
True
):
def
get_
progress
():
"""
Returns
the length of the p_todo item in days, based on the recurrence
period + due date, or the start/due dat
e.
Returns
a value from 0 to 1 where we are today in a date range. Returns
a value >1 when a todo item is overdu
e.
"""
result
=
0
def
diff_days
(
p_start
,
p_end
):
if
p_start
<
p_end
:
diff
=
p_end
-
p_start
return
diff
.
days
def
get_length
():
"""
Returns the length of the p_todo item in days, based on the recurrence
period + due date, or the start/due date.
"""
result
=
0
return
0
def
diff_days
(
p_start
,
p_end
):
if
p_start
<
p_end
:
diff
=
p_end
-
p_start
return
diff
.
days
if
p_todo
.
has_tag
(
'rec'
)
and
p_todo
.
due_date
():
# add negation, offset is based on due date
recurrence_pattern
=
p_todo
.
tag_value
(
'rec'
)
neg_recurrence_pattern
=
re
.
sub
(
'^
\
+?
'
, '
-
', recurrence_pattern)
return
0
start = relative_date_to_date(
neg_recurrence_pattern, p_todo.due_date())
due = p_todo.due_date()
if
p_todo
.
has_tag
(
'rec'
)
and
p_todo
.
due_date
():
# add negation, offset is based on due date
recurrence_pattern
=
p_todo
.
tag_value
(
'rec'
)
neg_recurrence_pattern
=
re
.
sub
(
'^
\
+?
'
, '
-
', recurrence_pattern)
result = diff_days(start, due)
else:
result = p_todo.length
()
start = relative_date_to_date(
neg_recurrence_pattern, p_todo.due_date())
due = p_todo.due_date
()
return result
result = diff_days(start, due)
else:
result = p_todo.length()
def get_progress():
"""
Returns a value from 0 to 1 where we are today in a date range. Returns
a value >1 when a todo item is overdue.
"""
return result
if p_todo.is_overdue():
return 1.1
...
...
@@ -76,21 +91,26 @@ def progress_color_code(p_todo, p_safe=True):
else:
return 0
def progress_to_color():
color_range = COLOR16_RANGE if p_safe else COLOR256_RANGE
progress = get_progress()
color_range = COLOR16_RANGE if p_safe else COLOR256_RANGE
progress = get_progress()
# TODO: remove linear scale to exponential scale
if progress > 1:
# overdue, return the last color
return color_range[-1]
else:
# not overdue, calculate position over color range excl. due date
# color
pos = round(progress * (len(color_range) - 2))
return color_range[pos]
# TODO: remove linear scale to exponential scale
if progress > 1:
# overdue, return the last color
return color_range[-1]
else:
# not overdue, calculate position over color range excl. due date
# color
pos = round(progress * (len(color_range) - 2))
return color_range[pos]
def progress_color_code(p_todo, p_safe=True):
return _progress_to_color(p_todo, p_safe)[0]
return progress_to_color()
def progress_html_color(p_todo):
""" Returns a tuple (foreground, background) color """
_, background, foreground = _progress_to_color(p_todo, p_safe=False)
return (foreground, background)
def color_block(p_todo, p_safe=True):
color_code = progress_color_code(p_todo, p_safe)
...
...
topydo/lib/DotPrinter.py
View file @
30f5bb1a
...
...
@@ -21,6 +21,7 @@ notation. Useful for displaying dependencies.
from
textwrap
import
wrap
from
topydo.lib.Colorblock
import
progress_html_color
from
topydo.lib.PrettyPrinter
import
Printer
from
topydo.lib.Utils
import
humanize_date
...
...
@@ -85,9 +86,13 @@ class DotPrinter(Printer):
# print todos
for
todo
in
p_todos
:
result
+=
' {} [label={}]
\
n
'
.
format
(
foreground
,
background
=
progress_html_color
(
todo
)
result
+=
' {} [label={} style=filled fillcolor="{}" fontcolor="{}"]
\
n
'
.
format
(
node_name
(
todo
),
node_label
(
todo
),
background
,
foreground
,
)
# print edges
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment