My problem started with realizing the preprocess completely ignores the show legend settings being passed and forces it to true but upon further inspection it would seem there are multiple issues with how the preprocess handles legend settings. I'm guessing that ultimately you're wanting to make sure that $options->legend has values set for show and position and that settings passed through $variables['legend'] can override settings passed through $variables['options'] but while checking to see if $variables['legend'] exists it completely ignores anything it passes.
if (isset($variables['legend']) && $variables['legend']) {
if (!isset($options->legend)) {
// Default position bottom
$options->legend->show = TRUE;
$options->legend->position = 'bottom';
}
else {
$options->legend->show = TRUE;
if (!isset($options->legend->position)) {
$options->legend->position = 'bottom';
}
}
}
I'm guessing what should happen here is something like this.
if(!isset($options->legend)) {
$options->legend = new stdClass();
$options->legend->show = TRUE;
$options->legend->position = 'bottom';
}
else {
if(!isset($options->legend->show)) {
$options->legend->show = TRUE;
}
if(!isset($options->legend->position)) {
$options->legend->position = 'bottom';
}
}
if (isset($variables['legend']) && $variables['legend']) {
if(isset($variables['legend']->show)) {
$options->legend->show = $variables['legend']->show;
}
if (!isset($options->legend->position)) {
$options->legend->position = $variables['legend']->position;
}
}
It ensures that $options->legend exists and has show and legend property values then checks to see if $variables['legend'] exists and if so overwrites show and/or position if provided. If this is the intention of this section of code I can provide a patch.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | flot-7.x-1.0.patch | 1.15 KB | RunningThot |
Comments
Comment #1
attiks commentedYou're right, a patch would be appreciated.
Comment #2
RunningThot commentedI was also going to attach a patch for the 7.x dev version as well but it looks like you changed it slightly to not show the legend if $variables['legend'] doesn't exist and I wasn't sure how you would want to reconcile that with the legend being passed in through $variables['options']. Was it possibly your thought that the legend would be disabled unless explicitly defined either by $variables['legend'] or in $variables['options']->legend?
Comment #3
attiks commentedComment #4
jelle_sYour patch assumes $variables['legend'] is an object. It is actually just a boolean indicating whether or not we should show a legend. The actual legend object should be in $variables['options']->legend.
(Emphasis mine.)
So (1) -> Yes, we do want to make sure that $options->legend has values set for show and position and
(2) No we don't want settings passed through $variables['legend'] to overwrite settings passed through $variables['options']->legend. $variables['legend'] is just a switch do enable or disable the legend, and we want to make sure that if and when the legend is enabled, we provide some sensible defaults for it.
Marking this as 'works as designed'. Feel free to ask anything if something isn't clear.