I have several functions/constants defined in the schema. An example is:
_latestPeriodWithData() which returns a date.
Goal: I want to use this value in the Reporting to set a Guide in a chart, using the demo example 'On Widget Options':
This is what I tried so far:
I have assigned this function as 'MDX / Value' for a Report Constant _lastDate and obtained the value for this constant using the java script function: context.eventValue('_lastDate'); but that just gives me the caption. The function context.eventObject("_lastDate").options.asMdx gives me _latestPeriodWithData(), but not its value.
On Widget Options
/**
* Result will be used while rendering.
*/
function(context, options, $box) {
// for debugging purpose
console.log(context.eventObject("_lastDate").options.asMdx);
options.guides[0].value = context.eventObject("_lastDate").options.asMdx; // <-- gives me _latestPeriodeWith data
// but not its value
options.guides[0].toValue = context.eventObject("_lastDate").options.asMdx;
options.guides[0].lineAlpha = 1;
options.guides[0].lineColor = "#c44";
return options;
}
I'm pulling my hair out trying to get some very basic iteration working using non-execution set variables (ie setting things at Global with potential to override at lower scope).
Setting a $variable to some value works fine but I need to do something like...
foreach $DeployConfigKey in #MapKeys(%DeployConfigs)
{
...
}
So far I'm getting nowhere fast with execution errors saying "Invalid value for property Map; expected map."
Further doing something like set %executionvar = %DeployConfigs complains that a map cannot be set to a scaler value.
The variable, DeployConfigs looks like ...
%{"Web.config": ["Web.Beta.config", "Web.Release.config"]}
and is defined at Global scope.
What am I doing wrong?
I'm using buildmaster 5.7.3
Maps are specified as %(key: value), here is an example plan that should help:
set %map = %(Web.config: #("Web.Beta.config", "Web.Release.config"));
foreach $key in #MapKeys(%map)
{
set #values = %map[$key];
Log-Information `$key = $key;
Log-Information `#values = $Join(", ", #values);
}
Sleep 3;
Imagine I have the following set of defined variables:
$sportmenu_1: #23765c;
$sportmenu_3: #5e6b34;
$sportmenu_4: #7d7e6c;
$sportmenu_6: #786857;
$sportmenu_8: #487a91;
I also have a list containing the "id" or the last digit of each variable as:
$list: 1 3 4 6 8;
I then want to the $sportmenu_ variables to both name the css selectors and populate the properties, I'm using a list and a foreach as follows:
#each $id in $list_id_sports {
#sportmenu_#{$id} { //this works fine
.menu-sport-item {
background-color: #{$sportmenu_}#{$id}; //here's the issue!
}
}
}
The problem is that I cannot find a way to combine a string and the $id from the foreach to generate a variable that the Sass compiler will understand. Basically, I want the foreach to create a new variable by combining $sportmenu_ and the value of $id. Not sure if this is possible.
My solution doesn't work, since $sportmenu_ doesn't exist. I've tried combining a string and the $id as: "$sportmenu_"#{$id} but this just creates a string followed by the value of $id.
Thanks!
Why can't you do something like this? Using maps
$list: (1: #23765c, 3: #5e6b34, 4: #7d7e6c, 6: #786857, 8: #487a91);
//$id grabs your map index, and $val grabs your hex color values
#each $id, $val in $list {
#sportmenu_#{$id} {
.menu-sport-item {
background-color: #{$val};
}
}
}
You can try it out on SassMeister. Which outputs :
#sportmenu_1 .menu-sport-item {
background-color: #23765c;
}
.....
All I am doing over here is nothing but using maps(kind of hash), looping over, and printing colors accordingly.
Also, what you were trying won't work. You are trying to interpolate two variables and trying to create a dynamic variable name on compile.
#{$sportmenu_}#{$id}; //will throw undefined $sprotsmenu_ error
I have converted the following OpenVx Sobel immediate code to Graph based . But the results done match.
Immediate code works fine, it gives proper result. Whereas Graph code takes "longer" than the immediate code for a single image and produces wrong results too.
So is my conversion correct ?
Immediate Code :
/* Intermediate images. */
vx_image dx = vxCreateImage(context, width, height, VX_DF_IMAGE_S16);
vx_image dy = vxCreateImage(context, width, height, VX_DF_IMAGE_S16);
vx_image mag = vxCreateImage(context, width, height, VX_DF_IMAGE_S16);
/* Perform Sobel convolution. */
if (vxuSobel3x3(context,image,dx, dy)!=VX_SUCCESS)
{
printf("ERROR: failed to do sobel!\n");
}
/* Calculate magnitude from gradients. */
if (vxuMagnitude(context,dx,dy,mag)!=VX_SUCCESS)
{
printf("ERROR: failed to do magnitude!\n");
}
//Convert result back to U8 image.
if (vxuConvertDepth(context,mag,image,VX_CONVERT_POLICY_WRAP,0)!=VX_SUCCESS)
{
printf("ERROR: failed to do color convert!\n");
}
Graph based code of the above immediate code
vx_graph graph = vxCreateGraph( context );
vx_image intermediate1 = vxCreateVirtualImage( graph, width, height, VX_DF_IMAGE_S16 );
vx_image intermediate2 = vxCreateVirtualImage( graph, width, height, VX_DF_IMAGE_S16 );
vx_image intermediate3 = vxCreateVirtualImage( graph, width, height, VX_DF_IMAGE_S16 );
if(vxSobel3x3Node(graph,image,intermediate1,intermediate2) == 0)
{
printf("FAILED TO Create 1 graph node");
}
if(vxMagnitudeNode(graph,intermediate1,intermediate2,intermediate3) == 0)
{
printf("ERROR: failed to do magnitude!\n");
}
if(vxConvertDepthNode(graph,intermediate3,image,VX_CONVERT_POLICY_WRAP,0) == 0)
{
printf("ERROR failed to do color convert");
}
vxVerifyGraph( graph );
vxProcessGraph( graph ); // run in a loop
At first, you should inspect the result of the vxVerifyGraph. Like this:
vx_status stat = vxVerifyGraph(graph);
if (stat != VX_SUCCESS)
printf("Graph failed (%d)\n", stat);
else
vxProcessGraph(graph);
For your example it returns "-4" for the vxConvertDepthNode function.
vx_types.h says:
VX_ERROR_NOT_SUFFICIENT = -4, /*!< \brief Indicates that the given graph has failed verification due to an insufficient
number of required parameters, which cannot be automatically created.
Typically this indicates required atomic parameters. \see
vxVerifyGraph. */
The proper use is (I don't remember where we got it):
vx_int32 shift = 0;
vx_scalar sshift = vxCreateScalar(context, VX_TYPE_INT32, &shift);
if(vxConvertDepthNode(graph,intermediate3,image,VX_CONVERT_POLICY_WRAP,sshift) == 0) {
printf("ERROR failed to do color convert");
}
Now vxVerifyGraph returns "-18".
VX_ERROR_INVALID_GRAPH = -18, /*!< \brief Indicates that the supplied graph has invalid connections (cycles). */
That's what about #jet47 says. You should use another image for output:
if(vxConvertDepthNode(graph,intermediate3,imageOut,VX_CONVERT_POLICY_WRAP,sshift ) == 0) {
printf("ERROR failed to do color convert");
}
Now it works fine.
Please check return code of vxVerifyGraph. You graph contains a loop (image object), which is forbidden, so it should fail on verification stage. To fix this use another image for vxConvertDepthNode output.
I am using a module that builds a price table for Drupal Commerce items. There is a function that formats the table headers:
/**
* Helper function that takes care of the quantity displayed in the headers of
* the price table.
*/
function commerce_price_table_display_quantity_headers($item) {
// Set the quantity text to unlimited if it's -1.
$max_qty = $item['max_qty'] == -1 ? t('Unlimited') : $item['max_qty'];
// If max and min qtys are the same, only show one.
if ($item['min_qty'] == $max_qty) {
$quantity_text = $item['min_qty'];
}
else {
$quantity_text = $item['min_qty'] . ' - ' . $max_qty;
}
return $quantity_text;
}
As you can see, this is not a theme function where I can override it in template.php but I can to tweak some of the output.
How can I redefine this function so I can chop and change a few things?
My work so far...
So far, I have tried to create it as a seperate module with a few subtle changes to show if it's working or not, but it's not overriding any of the output.
Info file
; $id$
name = Price Table: Tweaked Display
description = A different layout for the price table as shown on the product display nodes
package = Commerce (contrib)
core = 7.x
dependencies[] = commerce_product
dependencies[] = commerce_price
dependencies[] = commerce_price_table
Module File
/**
* Override of the helper function that takes care of the quantity displayed in the headers of
* the price table.
*/
function commerce_table_tweak_display_quantity_headers($item) {
// Set the quantity text to unlimited if it's -1.
$max_qty = $item['max_qty'] == -1 ? t('Unlimited gnhh') : $item['max_qty'];
// If max and min qtys are the same, only show one.
if ($item['min_qty'] == $max_qty) {
$quantity_text = $item['min_qty'];
}
else {
$quantity_text = $item['min_qty'] . ' - this is working - ' . $max_qty;
}
return $quantity_text;
}
Most drupal modules I believe have a hook_function (or at least ones that are hookable) I don't do this much so I would search the drupal api for how to hook functions and if your module will support it.