Added a dark-mode
This commit is contained in:
parent
5fc161fcc0
commit
f27d89e43d
39
caliGraph.py
39
caliGraph.py
@ -437,7 +437,7 @@ def loadBooksFromDB():
|
||||
return json.loads(os.popen("calibredb list --for-machine -f all").read())
|
||||
|
||||
|
||||
def buildBookGraph(books):
|
||||
def buildBookGraph(books, darkMode=False):
|
||||
G = nx.Graph()
|
||||
|
||||
# Books
|
||||
@ -462,7 +462,7 @@ def buildBookGraph(books):
|
||||
return G
|
||||
|
||||
|
||||
def graphAddAuthors(G, books):
|
||||
def graphAddAuthors(G, books, darkMode=False):
|
||||
for author in getAllAuthors(books):
|
||||
G.add_node('a/'+author, color='green', t='author', label=author)
|
||||
for book in books:
|
||||
@ -471,7 +471,7 @@ def graphAddAuthors(G, books):
|
||||
return G
|
||||
|
||||
|
||||
def graphAddRecommenders(G, books):
|
||||
def graphAddRecommenders(G, books, darkMode=False):
|
||||
for rec in getAllRecommenders(books):
|
||||
G.add_node('r/'+rec, color='orange', t='recommender', label=rec)
|
||||
for book in books:
|
||||
@ -480,7 +480,7 @@ def graphAddRecommenders(G, books):
|
||||
return G
|
||||
|
||||
|
||||
def graphAddTopLists(G, books):
|
||||
def graphAddTopLists(G, books, darkMode=False):
|
||||
for tl in getAllTopLists(books):
|
||||
G.add_node('t/'+tl, color='yellow', t='topList', label=tl)
|
||||
for book in books:
|
||||
@ -490,7 +490,7 @@ def graphAddTopLists(G, books):
|
||||
return G
|
||||
|
||||
|
||||
def graphAddSeries(G, books):
|
||||
def graphAddSeries(G, books, darkMode=False):
|
||||
for series in getAllSeries(books):
|
||||
G.add_node('s/'+series, color='red', t='series', label=series, shape='triangle')
|
||||
for book in books:
|
||||
@ -499,9 +499,9 @@ def graphAddSeries(G, books):
|
||||
return G
|
||||
|
||||
|
||||
def graphAddTags(G, books):
|
||||
def graphAddTags(G, books, darkMode=False):
|
||||
for tag in getAllTags(books):
|
||||
G.add_node('t/'+tag, color='lightGray', t='tag', label=tag, shape='box')
|
||||
G.add_node('t/'+tag, color=['lightGray','darkgray'][darkMode], t='tag', label=tag, shape='box')
|
||||
for book in books:
|
||||
for tag in getTags(book):
|
||||
G.add_edge('t/'+tag, book['id'], color=readColor(book))
|
||||
@ -552,8 +552,10 @@ def addScoreToLabels(G):
|
||||
node['label'] += " (~0±∞)"
|
||||
|
||||
|
||||
def genAndShowHTML(G, showButtons=False):
|
||||
net = Network('1080px', '1920px')
|
||||
def genAndShowHTML(G, showButtons=False, darkMode=False, arrows=False):
|
||||
net = Network('1080px', '1920px',
|
||||
directed=arrows,
|
||||
bgcolor=['#FFFFFF','#181818'][darkMode])
|
||||
if showButtons:
|
||||
net.show_buttons(filter_=['configure', 'layout',
|
||||
'interaction', 'physics', 'edges'])
|
||||
@ -561,15 +563,15 @@ def genAndShowHTML(G, showButtons=False):
|
||||
net.show('nx.html')
|
||||
|
||||
|
||||
def buildFullGraph():
|
||||
def buildFullGraph(darkMode=False):
|
||||
books = loadBooksFromDB()
|
||||
G = buildBookGraph(books)
|
||||
G = buildBookGraph(books, darkMode=darkMode)
|
||||
|
||||
graphAddAuthors(G, books)
|
||||
graphAddRecommenders(G, books)
|
||||
graphAddTopLists(G, books)
|
||||
graphAddSeries(G, books)
|
||||
graphAddTags(G, books)
|
||||
graphAddAuthors(G, books, darkMode=darkMode)
|
||||
graphAddRecommenders(G, books, darkMode=darkMode)
|
||||
graphAddTopLists(G, books, darkMode=darkMode)
|
||||
graphAddSeries(G, books, darkMode=darkMode)
|
||||
graphAddTags(G, books, darkMode=darkMode)
|
||||
return G, books
|
||||
|
||||
|
||||
@ -889,6 +891,7 @@ def cliInterface():
|
||||
parser.add_argument('--remove-edge', action="store_true")
|
||||
parser.add_argument('--keep-top-lists', action="store_true")
|
||||
parser.add_argument('--keep-useless-recommenders', action="store_true")
|
||||
parser.add_argument('--dark-mode', action="store_true")
|
||||
cmds = parser.add_subparsers(required=True, dest='cmd')
|
||||
|
||||
p_rec = cmds.add_parser('recommend', description="TODO", aliases=['rec'])
|
||||
@ -918,7 +921,7 @@ def cliInterface():
|
||||
train(args.g, args.full)
|
||||
exit()
|
||||
|
||||
G, books = buildFullGraph()
|
||||
G, books = buildFullGraph(darkMode=args.dark_mode)
|
||||
mu, std = genScores(G, books)
|
||||
|
||||
if args.cmd=="recommend":
|
||||
@ -954,7 +957,7 @@ def cliInterface():
|
||||
if not args.no_list:
|
||||
printBestList(G)
|
||||
if not args.no_web:
|
||||
genAndShowHTML(G)
|
||||
genAndShowHTML(G, darkMode=args.dark_mode)
|
||||
|
||||
|
||||
weights = loadWeights()
|
||||
|
Loading…
Reference in New Issue
Block a user