There's no simple answer to this question. Generally, the succession follows from father to eldest son. In this case that would be Joffrey, but since Joffrey wasn't biologically Robert's son (he was Jaime's), technically he wasn't the rightful air. Therefore, Stannis, as Robert's eldest living sibling, had a legitimate claim. However, Robert had plenty of bastard sons (such as Gendry) who also could've potentially had a claim, if they were able to be legitimised. But the likelihood of that was slim since those young men would likely not know their true parentage, have no knowledge of politics or what it takes to rule and probably wouldn't be very favourable amongst the people or the key players in Kings Landing. So overall, I suppose Stannis comes out as having the most rightful claim.