Format the value of data point in overview page card header - formatting

A service returns 0.05 to indicate 5%. Is there any UI annotation to format this value so that the card header will show 5% ?
The datapoint has the ValueFormat but that doesn't really solve my issue.
Thanks.

Just use a formatter function like this:
function formatPercent(nPercentage) {
return (nPercentage*100).toString() + '%';
}
// Input 0.05
// Output '5%'
(Add type checks, truncating, etc)

Related

How to set custom colors for Odoo 12 calendar view events?

There is a good tutorial on how to achieve this in Odoo-8 here:
Tutorial , but it doesn't work on Odoo-12.
Odoo natively allows you to set a field of your model as a basis for color differentiation in calendar view.
<calendar ... color="your_model_field">
The problem is that he will decide automagically what color to assign to every value.
I need to be able to decide what color mapping to use.
Doing some diving in the web module js files, more specifically on
web/static/src/js/views/calendar/calendar_renderer.js on line 266
I found a promising function which appears to be the one responsible for deciding which color to set.
getColor: function (key) {
if (!key) {
return;
}
if (this.color_map[key]) {
return this.color_map[key];
}
// check if the key is a css color
if (typeof key === 'string' && key.match(/^((#[A-F0-9]{3})|(#[A-F0-9]{6})|((hsl|rgb)a?\(\s*(?:(\s*\d{1,3}%?\s*),?){3}(\s*,[0-9.]{1,4})?\))|)$/i)) {
return this.color_map[key] = key;
}
var index = (((_.keys(this.color_map).length + 1) * 5) % 24) + 1;
this.color_map[key] = index;
return index;
},
This function is fed the value of your field (for every calendar event) and returns the color to be used "supposedly" as background for the calendar event square.
According to the second if statement, if you manage to instantiate the CalendarRenderer class with a color_map object which has the possible values of your field as keys and color codes as values you should be ok.
According the the third if statement, if the values of your field are strings with color codes (#FFF, rgb(x, y, z) , etc) they will be set in the color_map object and returned to be used as background colors.
The last part I guess is how odoo decides on a color when no mapping is provided.
I tried both approaches with the same efect:
Image displaying the calendar view
Namely, all the calendar events are rendered with the default color taken from the fullcalendar.css stylesheet (line 529), but the color reference displays correctly on the sidebar to the right.
I would appreciate any light shed on this matter, It has to be possible to make this work!.
Thanks.

Slider filtering edges by property (e.g., strength [0-1])

I am a newbie in Cytoscape js, is there an example of how to filter down all edges that has an attribute lower than a certain threshold (using a slider)?
Thank you!
The code bellow shows how to filter edges by an attribute, in this example weight using a variable named threshold. The elements variable will have the filtered edges.
var elements = cy.filter('edges[weight > ' + threshold + ']')
The slider callback method could be used to trigger this function, resulting in a filter controlled by a slider.
If you wish to remove those elements from the graph, the restore function could be useful to return them back before filtering the graph again. An snippet of a possible callback method is given bellow:
var filteredEdges = [];
sliderCalback(threshold) {
// putting back the previously removed edges
cy.recover(filteredEdges);
// filtering edges
filteredEdges = cy.filter('edges[weight> ' + threshold + ']');
// Removing filteredEdges from graph
cy.remove(filteredEdges);
}
More details on Cytoscape.js filter method can be found here, and selectors can be found here.

How to limit the textarea size

I need to limit the textarea to 4 characters...
my current javascript
{
name : "pin",
title : "PIN",
align:"center",
textArea:"isc.TextArea.setCharacterWidth(4)"
}
Can anyone tell me how can I do that please?
You can use following methods both on TextAreaItem and TextItem:
text.setEnforceLength(true);
text.setLength(4);
You can use TextAreaItem field of smartgwt to create multi-line text area.
To restrict the number of characters for this field, setLength can be used.
For example:
private TextAreaItem text = new TextAreaItem("pin", "PIN");
text.setLength(4);
text.setAlign(Alignment.CENTER);

Titanium: click on element(View, Label e.t.c.) should increase its top by 1

I've binded the same function to all elements that I want(let's say View and Label).
In this onClick handler function I want to get the element which was clicked and increase its 'top' by 1.
Please tell me if you know how to do that, I can't find an answer yet.
My global click handler function:
function increaseElementTop(e) {
// Here we should increase element's top position.
Ti.API.info(JSON.stringify(e));
}
Thanks, any help is appreciated.
Get the e.source attribute from the Event e. Then use the setTop() method.
if (e.source == $.yourLabel) {
$.yourLabel.setTop($.yourLabel.getTop() + 1)
}
UPDATE: Regarding your comment: I thought it would only be used for two elements. A universal approach would be something like this:
e.source.setTop(e.source.getTop() + 1);
Unfortunately I have no machine available to test the code but I will do so later (Tuesday I guess). Just try it and let your programm print the e.source variable. If this does not work you can also try to use e.source.getId().
function increaseElementTop(e) {
var theUIElement = e.source;
theUIElement.top = theUIElement.top + 1;
}
Add the event listener to each of your UIElements, and this will get the element you click on & modify the top.

Highcharts Bubble Chart - How to get the size of the point

I want to format the tooltip of my bubble chart but I need to know what property gets me the size of the bubble.
If you are using a formatter function you would do something like this:
tooltip :
formatter: function() {
return "My bubble size is : " + this.point.z;
}
}
this.point also has the following properties in the bubble chart tooltip formatter: series, x, and y
For more see: http://api.highcharts.com/highcharts#tooltip.formatter
you can get the radius by accecssing this.point.shapeArgs.r in formatter function. just like the solution by #scott-gearhart