In D3plus, all methods support passing a function that will handle the logic of fetching a given attribute. By passing .color( ) a function, the returned color can be determined based off special conditions that the data may meet.
Featured on D3plus.org