Skip to content

Commit d222009

Browse files
committed
fix: fixed coloring for 'Top Categories'
1 parent ec2c385 commit d222009

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/store/modules/activity.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import moment from 'moment';
22
import { unitOfTime } from 'moment';
33
import * as _ from 'lodash';
44
import { map, filter, values, groupBy, sortBy, flow, reverse } from 'lodash/fp';
5+
56
import queries from '~/queries';
7+
import { getColorFromCategory } from '~/util/color';
68
import { loadClassesForQuery } from '~/util/classes';
79
import { get_day_start_with_offset } from '~/util/time';
810

@@ -192,7 +194,7 @@ const actions = {
192194
},
193195

194196
async query_desktop_full(
195-
{ state, commit },
197+
{ state, commit, rootState, rootGetters },
196198
{ timeperiod, filterCategories, filterAFK }: QueryOptions
197199
) {
198200
const periods = [timeperiodToStr(timeperiod)];
@@ -206,8 +208,19 @@ const actions = {
206208
filterCategories
207209
);
208210
const data = await this._vm.$aw.query(periods, q);
209-
commit('query_browser_completed', data[0].browser);
210-
commit('query_window_completed', data[0].window);
211+
212+
const data_window = data[0].window;
213+
const data_browser = data[0].browser;
214+
215+
// Set $color for categories
216+
data_window.cat_events = data[0].window['cat_events'].map(e => {
217+
const cat = rootGetters['categories/get_category'](e.data['$category']);
218+
e.data['$color'] = getColorFromCategory(cat, rootState.categories.classes);
219+
return e;
220+
});
221+
222+
commit('query_window_completed', data_window);
223+
commit('query_browser_completed', data_browser);
211224
},
212225

213226
async query_browser_empty({ commit }) {

src/util/color.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export function getColorFromString(appname) {
6161

6262
// TODO: Move into vuex?
6363
export function getColorFromCategory(c: Category, allCats: Category[]): string {
64+
// Returns the color for a certain category, falling back to parents if none set
6465
if (c && c.data && c.data.color) {
6566
return c.data.color;
6667
} else if (c && c.name.slice(0, -1).length > 0) {

src/visualizations/SunburstCategories.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// We want to use another colorscheme than the default 'schemeAccent',
33
// unfortunately it seems like the color-scheme prop is broken.
44
// See this issue: https://github.com/David-Desmaisons/Vue.D3.sunburst/issues/11
5-
sunburst(:data="data", :colorScale="(s) => colorfunc(s)", :getCategoryForColor="categoryForColor", :colorScheme="null")
5+
sunburst(:data="data", :colorScale="colorfunc", :getCategoryForColor="categoryForColor", :colorScheme="null")
66
// Add behaviors
77
template(slot-scope="{ on, actions }")
88
highlightOnHover(v-bind="{ on, actions }")

0 commit comments

Comments
 (0)