BoxChartComponent constructor

BoxChartComponent(
  1. RenderComponent parent,
  2. String id, {
  3. Map<String, List<BoxDataPoint>> points = const {},
  4. LinkedHashSet<String>? labelsX,
  5. Set<String>? graphKeys,
  6. Map<String, String>? graphAliases,
  7. int? labelCountY,
  8. double? labelMinY,
  9. double? labelMaxY,
  10. double maxLabelWidthX = 50,
  11. double maxLabelWidthY = 20,
  12. double textMargin = 15,
  13. String labelFormatX(
    1. double
    )?,
  14. String labelFormatY(
    1. double
    )?,
  15. double aspectRatio = 1.5,
  16. double gridLineWidth = 1,
  17. String gridLineStrokeStyle = '#d7d7d7',
  18. String labelFillStyle = '#aaaaaa',
  19. String labelFontStyle = '14px sans-serif',
  20. String captionBgColor = '#2d2d2d',
  21. String captionFgColor = 'white',
  22. String captionFontFamily = 'sans-serif',
  23. bool drawGridY = false,
  24. Map<String, String> barFillStyle = const {keyAllGraph : '#aaaaaa'},
  25. double minWidth = 500,
  26. bool minWidthOverride = false,
  27. double singleBarWidth = 15,
  28. double barMargin = 5,
  29. double barSetMargin = 45,
  30. dynamic onHover(
    1. String x,
    2. BoxDataPoint y
    )?,
  31. dynamic onHoverOut()?,
  32. dynamic onClick(
    1. String x,
    2. BoxDataPoint y
    )?,
})

Implementation

BoxChartComponent(super.parent, super.id, {
  Map<String, List<BoxDataPoint>> points = const {},
  LinkedHashSet<String>? labelsX,
  Set<String>? graphKeys,
  Map<String, String>? graphAliases,
  int? labelCountY,
  double? labelMinY,
  double? labelMaxY,
  super.maxLabelWidthX,
  super.maxLabelWidthY,
  super.textMargin,
  String Function(double)? labelFormatX,
  String Function(double)? labelFormatY,
  super.aspectRatio,
  super.gridLineWidth,
  super.gridLineStrokeStyle,
  super.labelFillStyle,
  super.labelFontStyle,
  super.captionBgColor,
  super.captionFgColor,
  super.captionFontFamily,
  super.drawGridY,
  this.barFillStyle = const {keyAllGraph: '#aaaaaa'},
  this.minWidth = 500,
  this.minWidthOverride = false,
  this.singleBarWidth = 15,
  this.barMargin = 5,
  this.barSetMargin = 45,
  this.onHover,
  this.onHoverOut,
  this.onClick,
}) : super(labelFormatX: labelFormatX ?? _defaultLabelFormat,
  labelFormatY: labelFormatY ?? _defaultLabelFormat,
) {
  if (!barFillStyle.containsKey(keyAllGraph)) barFillStyle[keyAllGraph] = '#aaaaaa';
  _initialLabelCountY = labelCountY;
  _initialLabelMinY = labelMinY;
  _initialLabelMaxY = labelMaxY;
  _userGraphKeys = graphKeys ?? {};
  this.graphAliases = graphAliases ?? {};

  if (labelsX != null) this.labelsX = labelsX;

  var labelsXSet = labelsX != null && labelsX.isNotEmpty;

  // Add empty data point in some X point that is defined in labels, but
  // do not have any points.
  labelsX?.forEach((element) {
    if (_dataPoints[element] == null) {
      _dataPoints[element] = points.map((key, value) => MapEntry(key, BoxDataPoint()));
    }
  });

  _graphKeys.addAll(_userGraphKeys);

  points.forEach((key, value) {
    if (_userGraphKeys.isNotEmpty && !_userGraphKeys.contains(key)) return;

    _graphKeys.add(key);
    for (var dp in value) {
      // If the labelsX has predefined X labels, ignore those points that are outside of defined labels.
      if (labelsXSet && labelsX.contains(this.labelFormatX(dp.x))) continue;

      if (_dataPoints[this.labelFormatX(dp.x)] == null) {
        _dataPoints[this.labelFormatX(dp.x)] = {};
      }

      _dataPoints[this.labelFormatX(dp.x)]![key] = dp;
    }
  });
  _setMinMaxY();
}