In each different view (be it month/week/day) the colours of stripes vary depending on which particular types are there. I think that there should be more consistency between the different views and stripes should remain the same colour for a particular node type. This means people will not need to keep refering to the key, and can remember for example that red events are ones they are interested in.
I have achieved this by simply setting the stripe id to that of the node type. This then require you to add to the css a style for each type id eg stripe-## for node type ##. This requires simpler code than that which is currently there, but does have a disadvantage that there will be no colours by default.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

KarenS’s picture

I agree that it would be nice to have a way to set this up so that you can control what things are displayed in what colors. A related issue is the one that requested that the stripe be based on taxonomy instead of node type.

I'm not sure yet how to accomplish this, so it's still outstanding, just wanted to confirm that it's something I'd like to see, too.

skor’s picture

Status: Active » Needs work
FileSize
3.28 KB

Here's a patch against calendar 5.x-1.4 that does two things.

  1. changes the legend to be taxonomy based (assumes only one single-select vocab)
  2. makes the colors consistent

Sorry it blows away the current node-type capability, but it's a decent starting place.

htxt’s picture

This is just what I needed, thanks :)

Will this patch go into the dev branch?

skor’s picture

I doubt this will be incorporated as is. It's a custom solution that works well on our site, but it should really be generalized before it would be included, possibly made an option.

m1mic’s picture

subscribing

gmak’s picture

I've been trying a different approach to this, via PHPTemplate theme functions.

I have this:

/**
 * Format node stripes
 */
function phptemplate_calendar_stripe_stripe($node) {

//define the vocabulary for use in getting stripe values
$vocabulary = 2;

//get the terms for the node from a given vocabulary
$label_terms = taxonomy_node_get_terms_by_vocabulary($node->nid, $vocabulary, $key = 'tid');

//count the terms
$term_count = count($label_terms);


if($term_count==1){ //if only one term is defined for the node...
  $label = $label_terms[0]->tid;
}else{
  $label = 4;
}

$output .= '<div class="stripe-'.$label.'" title="Key: '.$label.'">
<span class="stripe">Key '.$label.'</span></div>'."\n";

return $output;
}

Which should work, but I'm having one problem. If there is only one taxonomy term (from the given vocabulary) then I can't seem to get a value for $label. If there is more than one taxonomy term, it gets the $label value.

Can anyone suggest the problem as to why I can't get the 'tid' value if there is only one taxonomy term?

Thanks.

gmak’s picture

I found the problem. For anyone interested, this is the working code.

/**
* Format node stripes
*/
function phptemplate_calendar_stripe_stripe($node) {

//define the vocabulary for use in getting stripe values
$vocabulary = 2;

//get the terms for the node from a given vocabulary
$label_terms = taxonomy_node_get_terms_by_vocabulary($node->nid, $vocabulary, $key = 'tid');

//count the terms
$term_count = count($label_terms);

if($term_count==1){ //if only one term is defined for the node...
  foreach($label_terms as $term){
   	$label = $term->tid;
   	}
}else{
  $label = 4;
}

$output .= '<div class="stripe-'.$label.'" title="Key: '.$label.'">
<span class="stripe">Key '.$label.'</span></div>'."\n";

return $output;
}

If anyone can improve/streamline this, I'd appreciate your input.

This solution does not require any changes to the CSS (unless you want to change it). Next, I'm going to work on the Legend.

rubenk’s picture

subscribing. I too am one of those that would like a taxonomy (and simultaneous node if possible?) based legend.

jiangxijay’s picture

Subscribe

scottrigby’s picture

Could this work for the Event calendar, or only the Calendar module?

I would like to use the event calendar because Calendar module has been presenting problems for me (for instance, if you click on the day, it shows a blank table, even if there's an event on that day - whereas this is fine in Event). This isn't exactly the place to compare Event with Calendar.

My main question is if this could be used for the Event Calendar, and if not - is it possible to modify so it could?

Thanks!

gmak’s picture

The answer to your question is yes and no.

Yes, you can modify the output from the Event module in the same way. Just find the relevant function in the module and modify it in your template.php file (assuming you're using a phptemplate type template). It is fairly trivial, and you can find lots of theming help on the Drupal site.

And, the 'no', is that this code is from the Calendar module and cannot be used directly.

Mike Sances’s picture

to #7, isn't this a problem if you have a term id greater than 10 (or whatever the max stripe number is). In my case I have term id's above 50 so this results in blank colors. I'll try to work around this; otherwise your code is just what I need, thanks!

jjohnsonBLC’s picture

I thought I'd post my solution to this problem, in case it might help anyone.

I changed my theme_calendar_stripe_stripe function in calendar.theme. I deleted everything in it and replaced it with the following:

switch($node->stripe){
  case "case1":
	$label = 1;
	break;
  case "case2":
    $label = 2;
	break;
  case "case3":
    $label = 3;
	break;
  case "case4":
    $label = 4;
	break;
  case "case5":
    $label = 5;
	break;
  default:
    $label = 6;
	}

$output .= '<div class="stripe-'.$label.'" title="Key: '.$label.'">
<span class="stripe">Key '.$label.'</span></div>'."\n";

return $output;

This works for me because I only need the color stripe/legend on only one page. I can think of two ways to attempt to make this flexible enough to not mess up other calendars: do a check on the page (if this page, then do this switch statement, else...) or, assuming you don't overlap taxonomy terms, have each case cover two options like:

case "case1.a" or "case1.b":
   $label = 1;
   break;
jefff-1’s picture

Status: Needs work » Needs review
FileSize
2.6 KB

That is what I was looking for. Thanks.
I just edited your patch to work on calendar module version 5.x-1.7

KarenS’s picture

Version: 7.x-1.x-dev » 5.x-1.7
Status: Needs review » Closed (won't fix)

None of this will work in Calendar version 5.2 or 6.2 and I'm not adding new features to 5.1. For the new versions I've added the farbtastic color picker to the settings where you can select a color for each item which will give you consistency and an unlimited number of colors. I'm starting it out with only the option to set a color for each content type, but plan to adapt it later so you can set colors for taxonomy terms.

Obviously anyone who wants to can patch the 5.1 code themselves.

KarenS’s picture

I mean patch their own copies of the 5.1 code.

petertj’s picture

Thank you for adding this! It perfectly solved one of the few remaining client complaints on the calendar.

however, is the legend still being worked on? It doesn't display anything... or is that a separate issue?

(PS - I'm running 6.x-2.0-rc1, not the 5.x shown in this topic.)

KarenS’s picture

The legend is working for me, you have to add the legend block to your theme and it will only appear on the main calendar page. If there are problems with it, start a separate issue.

agerson’s picture

Is the color by node type a working feature yet? Would love to see this work for Taxonomy colorizing too. Thanks for your hard work.

Adam