Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
marcondiro
Partner - Contributor
Partner - Contributor

Use master items COLORS in QSense Extension

Hi all,

Is there an API to get the colors of a master item in a QS extension?

I've noticed that layout.qHyperCube.qDimensionInfo[0].coloring.colorMapRef contains an ID of a ColorMap in case of master items.

How can I get this ColorMap?

Thanks

Labels (6)
1 Solution

Accepted Solutions
mek
Employee
Employee

Hi,

The master dimension colors are stored in a separate generic object called ColorMapModel_<colorMapRef>, to get those values you would need to get the object and then its layout:

 

app.getObject('ColorMapModel_abcdef').then(model => model.getLayout().then(layout => console.log(layout)));

View solution in original post

11 Replies
mek
Employee
Employee

Hi,

The master dimension colors are stored in a separate generic object called ColorMapModel_<colorMapRef>, to get those values you would need to get the object and then its layout:

 

app.getObject('ColorMapModel_abcdef').then(model => model.getLayout().then(layout => console.log(layout)));
IVAN-FELIPE
Employee
Employee

Dear colleagues

This is a very interesting topic, as i¡m trying to get this info too from the colorMapRef object.

Your proposal just don't show anything.

And if I just get and print in the console this info 

app.getObject('ColorMapModel_abcdef')

it always show an error message, Object Not Found. 

What I'm missing here?

Thanks!

 

marcondiro
Partner - Contributor
Partner - Contributor
Author

Hi Ife,

Maybe you have not  inizialized correctly the "app" variable.

For example with var app = qlik.currApp()

Hope this will help.

Regards,

Marco

IVAN-FELIPE
Employee
Employee

Hi marco

Thanks for the answer,

No it's not like that, the variable app is correctly initialized.

It seems Qlik does not expose in the extensions API any way to get this info from the colorMapRef.

Marco, have you tested it? have you been able to get info from the colorMapRef object?

Regards

mek
Employee
Employee

@IVAN-FELIPE 

The abcdef part of the object id in my example is just a placeholder, it needs to be replaced with the actual id of the dimension you want the colors for 😉

master_t
Partner - Creator II
Partner - Creator II

I've tried this, but it seems to only return the colors that I specifically change from the default ones, as seen in the attached screenshot.

Do you happen to know how to retrieve the colors for the other values?

 

mek
Employee
Employee

Correct, only the changed colors are stored - the other colors are populated from the currently applied theme. There is currently no straight way to figure out exactly which colors other dimension values will have as that varies depending on other variables like the number of dimension values, persistence etc. The colors themselves are stored in the theme api.

master_t
Partner - Creator II
Partner - Creator II

Thanks... what I'm actually trying to do is to replicate the "persistent colors" feature of the native Qlik Sense charts... where you flag "persistent colors" and all charts throughout the app will have the same color for the same dimension, regardless of the type of chart or the filter. Is that possible at all? I checked out the theme API, but while that lists a series of colors, I don't see any method that I can use to obtain the color for a certain value...

mek
Employee
Employee

It's possible, the first step is to get the colors from the theme properties. You can then use the remainder operator on  qElemNumber and array length to get the correct color value from the palette, something like

const palette = theme.properties.palettes.data[0].scale;
const color = palette[cell.qElemNumber % palette.length];