Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Fix issues in getMinPixels and getMaxPixels #457

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions charts_common/lib/src/chart/layout/layout_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import 'dart:math' show min;

/// Collection of configurations that apply to the [LayoutManager].
class LayoutConfig {
final MarginSpec leftSpec;
Expand Down Expand Up @@ -97,25 +99,41 @@ class MarginSpec {

/// Get the min pixels, given the [totalPixels].
int getMinPixels(int totalPixels) {
int result;

if (totalPixels == null) {
totalPixels = 0;
}

// All paths must set result
if (_minPixel != null) {
assert(_minPixel < totalPixels);
return _minPixel;
result = min(_minPixel, totalPixels);
} else if (_minPercent != null) {
return (totalPixels * (_minPercent / 100)).round();
result = (totalPixels * (_minPercent / 100)).round();
} else {
return 0;
result = 0;
}

return result >= 0 ? result : 0;
}

/// Get the max pixels, given the [totalPixels].
int getMaxPixels(int totalPixels) {
int result;

if (totalPixels == null) {
totalPixels = 0;
}

// All paths must set result
if (_maxPixel != null) {
assert(_maxPixel < totalPixels);
return _maxPixel;
result = min(_maxPixel, totalPixels);
} else if (_maxPercent != null) {
return (totalPixels * (_maxPercent / 100)).round();
result = (totalPixels * (_maxPercent / 100)).round();
} else {
return totalPixels;
result = totalPixels;
}

return result >= 0 ? result : 0;
}
}
Loading