Skip to content

Commit

Permalink
fix: fixed coloring for 'Top Categories'
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Feb 22, 2021
1 parent ec2c385 commit d222009
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/store/modules/activity.ts
Expand Up @@ -2,7 +2,9 @@ import moment from 'moment';
import { unitOfTime } from 'moment';
import * as _ from 'lodash';
import { map, filter, values, groupBy, sortBy, flow, reverse } from 'lodash/fp';

import queries from '~/queries';
import { getColorFromCategory } from '~/util/color';
import { loadClassesForQuery } from '~/util/classes';
import { get_day_start_with_offset } from '~/util/time';

Expand Down Expand Up @@ -192,7 +194,7 @@ const actions = {
},

async query_desktop_full(
{ state, commit },
{ state, commit, rootState, rootGetters },
{ timeperiod, filterCategories, filterAFK }: QueryOptions
) {
const periods = [timeperiodToStr(timeperiod)];
Expand All @@ -206,8 +208,19 @@ const actions = {
filterCategories
);
const data = await this._vm.$aw.query(periods, q);
commit('query_browser_completed', data[0].browser);
commit('query_window_completed', data[0].window);

const data_window = data[0].window;
const data_browser = data[0].browser;

// Set $color for categories
data_window.cat_events = data[0].window['cat_events'].map(e => {
const cat = rootGetters['categories/get_category'](e.data['$category']);
e.data['$color'] = getColorFromCategory(cat, rootState.categories.classes);
return e;
});

commit('query_window_completed', data_window);
commit('query_browser_completed', data_browser);
},

async query_browser_empty({ commit }) {
Expand Down
1 change: 1 addition & 0 deletions src/util/color.ts
Expand Up @@ -61,6 +61,7 @@ export function getColorFromString(appname) {

// TODO: Move into vuex?
export function getColorFromCategory(c: Category, allCats: Category[]): string {
// Returns the color for a certain category, falling back to parents if none set
if (c && c.data && c.data.color) {
return c.data.color;
} else if (c && c.name.slice(0, -1).length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/visualizations/SunburstCategories.vue
Expand Up @@ -2,7 +2,7 @@
// We want to use another colorscheme than the default 'schemeAccent',
// unfortunately it seems like the color-scheme prop is broken.
// See this issue: https://github.com/David-Desmaisons/Vue.D3.sunburst/issues/11
sunburst(:data="data", :colorScale="(s) => colorfunc(s)", :getCategoryForColor="categoryForColor", :colorScheme="null")
sunburst(:data="data", :colorScale="colorfunc", :getCategoryForColor="categoryForColor", :colorScheme="null")
// Add behaviors
template(slot-scope="{ on, actions }")
highlightOnHover(v-bind="{ on, actions }")
Expand Down

0 comments on commit d222009

Please sign in to comment.