Move clustering logic to metadata.

Close #1297.
Out of scope of this pr, but we should change this function name
maybe to generatePlotMetadataForDataset?  Concise is better