You could do it like this:
- find the largest square place in the board
- place a square of the largest colour left to place in there, subtract this Pi by the appropriate amount
Your question, however, is far from complete and unambiguous
If you want to only have one rectangle per colour, things can get a bit more complicated.
(brute force, not very elegant)
- Factor all the areas for the colours into their prime factors, and get all possible two-element factorizations that will fit within the board. For most numbers up to reasonable amounts, this will be relatively manageable (if not, you could just scale down a factor ten, the visual result won't differ much).
- for each possible combination of these two-element factorizations, try to fit them into the board (most will not succeed)
- find the one with best ratios, weighted however you want
I can imagine a lot better approaches exist, but these might do the trick if your board is not too large, and the amount of colours is reasonable