goog.provide('anychart.core.drawers.RangeColumn');
goog.require('anychart.core.drawers');
goog.require('anychart.core.drawers.Base');
goog.require('anychart.enums');



/**
 * RangeColumn drawer.
 * @param {anychart.core.series.Base} series
 * @constructor
 * @extends {anychart.core.drawers.Base}
 */
anychart.core.drawers.RangeColumn = function(series) {
  anychart.core.drawers.RangeColumn.base(this, 'constructor', series);
};
goog.inherits(anychart.core.drawers.RangeColumn, anychart.core.drawers.Base);
anychart.core.drawers.AvailableDrawers[anychart.enums.SeriesDrawerTypes.RANGE_COLUMN] = anychart.core.drawers.RangeColumn;


/** @inheritDoc */
anychart.core.drawers.RangeColumn.prototype.type = anychart.enums.SeriesDrawerTypes.RANGE_COLUMN;


/** @inheritDoc */
anychart.core.drawers.RangeColumn.prototype.flags = (
    // anychart.core.drawers.Capabilities.NEEDS_ZERO |
    // anychart.core.drawers.Capabilities.NEEDS_SIZE_SCALE |
    // anychart.core.drawers.Capabilities.USES_CONTAINER_AS_ROOT |
    // anychart.core.drawers.Capabilities.USES_STROKE_AS_FILL |
    // anychart.core.drawers.Capabilities.SUPPORTS_CONNECTING_MISSING |
    // anychart.core.drawers.Capabilities.SUPPORTS_STACK |
    // anychart.core.drawers.Capabilities.SUPPORTS_COMPARISON |
    // anychart.core.drawers.Capabilities.SUPPORTS_ERROR |
    // anychart.core.drawers.Capabilities.SUPPORTS_OUTLIERS |
    anychart.core.drawers.Capabilities.IS_DISCRETE_BASED |
    anychart.core.drawers.Capabilities.IS_WIDTH_BASED |
    // anychart.core.drawers.Capabilities.IS_3D_BASED |
    // anychart.core.drawers.Capabilities.IS_VERTICAL |
    // anychart.core.drawers.Capabilities.IS_MARKER_BASED |
    // anychart.core.drawers.Capabilities.IS_OHLC_BASED |
    // anychart.core.drawers.Capabilities.IS_LINE_BASED |
    anychart.core.drawers.Capabilities.IS_RANGE_BASED |
    // anychart.core.drawers.Capabilities.SUPPORTS_STEP_DIRECTION |
    anychart.core.drawers.Capabilities.SUPPORTS_DISTRIBUTION |
    0);


/** @inheritDoc */
anychart.core.drawers.RangeColumn.prototype.requiredShapes = (function() {
  var res = {};
  res['path'] = anychart.enums.ShapeType.PATH;
  res['hatchFill'] = anychart.enums.ShapeType.PATH;
  return res;
})();


/** @inheritDoc */
anychart.core.drawers.RangeColumn.prototype.yValueNames = (function () { return ['low', 'high']; })();


/** @inheritDoc */
anychart.core.drawers.RangeColumn.prototype.valueFieldName = 'high';


/** @inheritDoc */
anychart.core.drawers.RangeColumn.prototype.drawSubsequentPoint = function(point, state) {
  if (!point.meta('skipDrawing')) { //fixes DVF-3048
    var valueNames = this.series.getYValueNames();

    var highValue = point.get(valueNames[1]);
    var lowValue = point.get(valueNames[0]);

    var names = this.getShapeNames(highValue, lowValue);

    var shapeNames = {};
    shapeNames[names.path] = true;
    shapeNames[names.hatchFill] = true;

    point.meta('name', names.path);

    var shapes = this.shapesManager.getShapesGroup(state, shapeNames);

    var x = /** @type {number} */(point.meta('x'));
    var high = /** @type {number} */(point.meta('high'));
    var low = /** @type {number} */(point.meta('low'));

    var leftX = x - this.pointWidth / 2;
    var rightX = leftX + this.pointWidth;

    var thickness = acgraph.vector.getThickness(/** @type {acgraph.vector.Stroke} */(shapes[names.path].stroke()));
    if (this.crispEdges) {
      leftX = anychart.utils.applyPixelShift(leftX, thickness);
      rightX = anychart.utils.applyPixelShift(rightX, thickness);
    }
    high = anychart.utils.applyPixelShift(high, thickness);
    low = anychart.utils.applyPixelShift(low, thickness);

    var path = /** @type {acgraph.vector.Path} */(shapes[names.path]);
    anychart.core.drawers.move(path, this.isVertical, leftX, low);
    anychart.core.drawers.line(path, this.isVertical, rightX, low);
    anychart.core.drawers.line(path, this.isVertical, rightX, high);
    anychart.core.drawers.line(path, this.isVertical, leftX, high);
    path.close();
    path = /** @type {acgraph.vector.Path} */(shapes[names.hatchFill]);
    anychart.core.drawers.move(path, this.isVertical, leftX, low);
    anychart.core.drawers.line(path, this.isVertical, rightX, low);
    anychart.core.drawers.line(path, this.isVertical, rightX, high);
    anychart.core.drawers.line(path, this.isVertical, leftX, high);
    path.close();
  }
};
