How to incorporate keys or dataframe column names in plotly express custom hover text? - plotly-python

Lost as I can be on how to control hover text with embedded data.
Non-dataframe scenario
In one case, I am passing a list of dicts to a plotly express (scatter) plot, having the shape:
list[dict[str, float]]
and I would like the hover text for each point to include its key from the dict inside my own domain-specific phrasing for the hover text.
When not tampering with the hover text, the default hover text showing up includes the key following the string "variable", and the x and y values being called "index" and "value" accordingly there in the default hover text. Obviously the x value is just the index of the dict from the list for input shaped as in my input type.
But incorporating these values with names bearing the semantics of the data seems to pose a challenge, as including something like follows does not really plug in (by substitution) anything but the x and y values in the percent prefix bracelets:
fig.update(data=[{'hovertemplate': 'distance: %{y} (class %{variable})'}])
For example, %{variable} will show as just the string as is, it will not substitute this string with the value of what the default hover text calls "variable".
How would I incorporate the "variable" value, as called in the default hover text, in my own hover text specification?
I went through numerous documentation pages where this is accomplished via plotly's non-express api or other ways which didn't seem to work for me. It's in general elusive to adapt any of the dataframe based solutions to my dataframe-sidestepping case. I wonder if there's an idiomatic way.
DataFrame based scenario
In another case, switching to dataframe input, I still battle to get the desired column name be recognized as, I wander in the plurality of ways to handle hover text and data for plotly:
fig = px.scatter(df, x='x', y='distance', color='class')
fig.update(data=[{'hovertemplate': 'distance: %{y} class %{class}'}])
fig.show()
― %{class} in the above dataframe oriented approach, is obviously not the proper way to select the class column's value for the hover data. How would I bring in the value of the desired dataframe column name into the hover text?

Related

Graphics from arrays in LabVIEW

I have attached a picture of what I have tried.
Starting from an array with values to graph and another array with the names of these values, I would want to graph them all. For later, from the front panel, I want to be able to choose which ones I want to visualize and which not. In the attached image is what I have tried and it does not work only know how to graph the 1 value with the first name but not the others.
The property you need for setting the names is "Active Plot".
The key to writing multiple plots is the "Bundle" node (or "Bundle By Name").
Result:

qwt: how to add extra text in legend

I have a QwtPlot with a couple of lines in it. It also has a legend.
Now apart from the description of the lines themself, I would like to add extra text describing the graph in general.
E.g. "line a: length of frog, line b: weight of frog" and then as an extra "outside temperature is 12C" (the temperature is then not drawn).
The description of QwtPlot shown in legend is QwtLegendData. Further in the QwtPlotItem doc (which is a superclass of all QwtPlots):
QwtLegendData is basically a list of QVariants that makes it possible to overload and reimplement legendData() to return almost any type of information, that is understood by the receiver that acts as the legend.
So everything that you need is to pull the existing "automated" legend from the plot and add one more QwtLegendData to it. It also needs a QVariant as a "key" to distinguish between Datas for each plot, but it can be really anything expectably different from the keys of real plots. Even default (empty) QVariant() will do, if you don't plan to add any more such extra texts.
QwtLegendData data;
data.setValue(QwtLegendData::Role::TitleRole, QVariant("Outside temperature is 12C"));
QList<QwtLegendData> list;
list << data;
QwtAbstractLegend* existingLegend = frogPlot.legend();
// "update" with a new key really means "insert"
existingLegend->updateLegend(QVariant("Temperature comment extra text"), list);

Displaying dynamic kanban colors according to record state in OpenERP 7

could someone tell me in what way I can display the items in a view kanban with a specific color according to the state that is the record.
I'm trying something like this
<div t-attf-class="#{record.state=='scheduled' ? oe_kanban_color_#{kanban_getcolor(1)} : oe_kanban_color_#{kanban_getcolor(0)}">
but I looked ALL elements and not only those who are in the "scheduled".
Thanks :)
If you have copy/pasted exactly what you typed in the view definition, then your t-attf- class attribute is malformed, and all record will have the following class:
class="#{record.state=='scheduled' ? oe_kanban_color_1 : oe_kanban_color_0"
which, due to CSS class precedence, will cause them all to have the oe_kanban_color_1 style.
A few hints:
To avoid coloring some records, you can omit the oe_kanban_color_X entirely in some cases
You can use a t-att-class attribute to allow arbitrary Javascript expressions, depending on what you want to do. In contrast, t-attf-class only allows replacing placeholders.
When comparing field values with Javascript operators you normally want to use the value or raw_value of the field, rather that the Field object itself. value will only differ from raw_value when the value needs specific rendering, such as dates, numbers, etc.
The kanban_getcolor() function accepts any integer or string and returns one of the 10 default kanban color indexes.
Based on the above, the following might be closer to what you tried to do (note the t-att-class attribute:
<div t-att-class="record.state.value == 'scheduled' ?
'oe_kanban_color_1' :
'oe_kanban_color_0' ">
Alternatively, you could use t-attf-class and let kanban_getcolor() pick a color based on the state string:
<div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.state.value)}">
That last example is similar to what is done in many default kanban views in the official OpenERP distribution.

How to use a single NSValueTransformer subclass to toggle the titles of multiple menu items

I would like to make some bindings that toggle item titles in a popup menu based on a single numerical value in a text field. Let me explain:
This is my UI:
I want my menu items to automatically adjust to singular or plural based on the number in the text field. For example, when I type "1" in the box, I want the menu items to be labeled "minute", "hour" and "day". When I type "4", I want the menu items to be labeled "minutes", "hours" and "days".
What I did to date:
I bound the three menu item's labels to the same key path as the text field's value.
I created an NSValueTransformer subclass to interpret the value in the text field and return singular or plural to be used as item titles.
I applied this value transformer to the three bindings.
The issue:
My value transformer can either return singular or plural but it can't set the appropriate string based on the menu item it's applied to.
It looks to me like a value transformer is generic and can't return different values for different destinations. That would mean that to have the three titles change automatically, I would need to have three different value transformers that return the appropriate string for each menu item. That doesn't seem optimal at all.
Ideally I would be able to combine a string stored in the destination menu item (let's say in the item's tag property) with an "s" in the value transformer when the text field's value is larger than one, or something similar that would enable me to use a single value transformer for all the menu items.
Is there something I missed? What would be an ideal solution?
Okay, this is probably not an ideal solution, but something you could consider: if you set your value transformers from your code (and not in IB), you could instantiate 3 different transformers of the same class. You could give your value transformer an ivar NSString *unit (and add something like [[MyValueTransformer alloc] initWithUnit:]) to allow each to return their own string, but you still have to write the value transformer's code only once.
(Also, if you're ever going to consider making your application localizable, simply appending an "s" to create the plurals is not going to work. You could of course add ivars for both NSString *singular and NSString *plural to do that.)
Edit: Wait, I just realized you can register value transformers! If you register them as MyValueTransformerHours and MyValueTransformerMinutes (by manually allocating and initializing them in your code), you can use them from Interface Builder. See also https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ValueTransformers/Concepts/Registration.html#//apple_ref/doc/uid/20002166-BAJEAIEE.

Displaying/Formatting Tabular Data (web)

In my example I have a table where each row is a user for example. Columns could include their name, address, email address, etc. I now need to add a column for (hypothetical example) their cat's names. While most people will have no cats and some people will have 1- 2 cats there will be the occasional person with 20 cats that create one very long row in the table. This is giving me an issue in presentation and for filtering/searching for cat names. Is there a good solution to displaying this type of data?
Have the first 50 (or whatever) characters of the field displayed as normal then put the rest in a block with its visibility set to hidden through CSS. Include a link / button / icon that will allow the user to toggle the visibility so they can see the entire value.
Several options:
Set a maximum width for the cell and allow the data to wrap
Place the content inside a wrapper tag (such as a div) and set the div with a fixed width/height and style of overflow:hidden to ensure that a particularly long word doesn't force out the width of the cell.
Truncate the output text on the server side
For cases #2 and #3, set the Title attribute of the TD tag to contain the full non-truncated text. This will present itself as a tooltip when hovering over the cell.
I would mention other CSS-based solutions but they're very sparsely supported right now, so not worth mentioning.
You might want to try doing something like what SO does. Namely, once someone reaches a certain point in their Rep, it suffixes the number and appromixates it. Ex. 10k instead of 10,236.
That way the numbers don't get out of hand.