Skip to content

Commit 906b005

Browse files
authored
feat: enhance colorisation for Top Window Titles (#654)
* feat: enhance colorisation for Top Window Titles * Use `useCategoryStore().get_category_color` * Update type definitions
1 parent 691c57b commit 906b005

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/components/SelectableVisualization.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ div
3131
div(v-if="type == 'top_titles'")
3232
aw-summary(:fields="activityStore.window.top_titles",
3333
:namefunc="e => e.data.title",
34-
:colorfunc="e => e.data.title",
34+
:colorfunc="e => e.data['$category']",
3535
with_limit)
3636
div(v-if="type == 'top_domains'")
3737
aw-summary(:fields="activityStore.browser.top_domains",
@@ -68,7 +68,7 @@ div
6868
div(v-if="type == 'top_categories'")
6969
aw-summary(:fields="activityStore.category.top",
7070
:namefunc="e => e.data['$category'].join(' > ')",
71-
:colorfunc="e => e.data['$category'].join(' > ')",
71+
:colorfunc="e => e.data['$category']",
7272
:linkfunc="e => '#' + $route.path + '?category=' + encodeURIComponent(e.data['$category'].join('>'))",
7373
with_limit)
7474
div(v-if="type == 'category_tree'")

src/visualizations/summary.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as d3 from 'd3';
44
import Color from 'color';
55
import _ from 'lodash';
66

7+
import { useCategoryStore } from '~/stores/categories';
78
import { getCategoryColorFromString } from '~/util/color';
89
import { seconds_to_duration } from '~/util/time';
910
import { IEvent } from '~/util/interfaces';
@@ -40,8 +41,9 @@ interface Entry {
4041
hovertext: string;
4142
duration: number;
4243
color?: string;
43-
colorKey?: string;
44+
colorKey?: string | string[];
4445
link?: string;
46+
category?: string;
4547
}
4648

4749
function update(container: HTMLElement, apps: Entry[]) {
@@ -69,7 +71,15 @@ function update(container: HTMLElement, apps: Entry[]) {
6971
const width = (app.duration / longest_duration) * 100 + '%';
7072
const barHeight = 46;
7173
const textSize = 14;
72-
const appcolor = app.color || getCategoryColorFromString(app.colorKey || app.name);
74+
75+
let appcolor: string;
76+
if (Array.isArray(app.colorKey)) {
77+
const categoryStore = useCategoryStore();
78+
appcolor = categoryStore.get_category_color(app.colorKey);
79+
} else {
80+
appcolor = app.color || getCategoryColorFromString(app.colorKey || app.name);
81+
}
82+
7383
const hovercolor = Color(appcolor).darken(0.1).hex();
7484

7585
// Add a parent <a> element if link is set
@@ -143,6 +153,7 @@ function updateSummedEvents(
143153
color: e.data['$color'],
144154
colorKey: colorKeyFunc(e),
145155
link: linkKeyFunc(e),
156+
category: e.data['$category'],
146157
} as Entry;
147158
});
148159
update(container, apps);

0 commit comments

Comments
 (0)