Moved some plot-specific code into the directive.