The New York Times has a good article about gerrymandering and efforts to rein it in. It focuses on something called the "efficiency standard" as a measure of whether too much bias has been used in districting.
As the article notes, the geographical distribution of adherents of both parties confounds some efforts at fair districting. People will choose (or be forced) to live near others with similar views.
To the extent that districts are at all compact, this ideological sorting process causes them to lean heavily one way or the other. It turns out that complicates efforts to legislate, or judicially rule against districting bias.