refactor all curve drawing into a generic function