prepareCustom.js 934 B

1234567891011121314151617181920212223242526272829303132
  1. var zrUtil = require("zrender/lib/core/util");
  2. function dataToCoordSize(dataSize, dataItem) {
  3. // dataItem is necessary in log axis.
  4. dataItem = dataItem || [0, 0];
  5. return zrUtil.map(['x', 'y'], function (dim, dimIdx) {
  6. var axis = this.getAxis(dim);
  7. var val = dataItem[dimIdx];
  8. var halfSize = dataSize[dimIdx] / 2;
  9. return axis.type === 'category' ? axis.getBandWidth() : Math.abs(axis.dataToCoord(val - halfSize) - axis.dataToCoord(val + halfSize));
  10. }, this);
  11. }
  12. function _default(coordSys) {
  13. var rect = coordSys.grid.getRect();
  14. return {
  15. coordSys: {
  16. // The name exposed to user is always 'cartesian2d' but not 'grid'.
  17. type: 'cartesian2d',
  18. x: rect.x,
  19. y: rect.y,
  20. width: rect.width,
  21. height: rect.height
  22. },
  23. api: {
  24. coord: zrUtil.bind(coordSys.dataToPoint, coordSys),
  25. size: zrUtil.bind(dataToCoordSize, coordSys)
  26. }
  27. };
  28. }
  29. module.exports = _default;