逐步完成前后端服务器

This commit is contained in:
2025-09-09 15:00:30 +08:00
parent fcb09432e9
commit c7dfa1e9fc
2937 changed files with 1477567 additions and 0 deletions

View File

@ -0,0 +1,94 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { __extends } from "tslib";
import Axis from '../Axis.js';
var Axis2D = /** @class */function (_super) {
__extends(Axis2D, _super);
function Axis2D(dim, scale, coordExtent, axisType, position) {
var _this = _super.call(this, dim, scale, coordExtent) || this;
/**
* Index of axis, can be used as key
* Injected outside.
*/
_this.index = 0;
_this.type = axisType || 'value';
_this.position = position || 'bottom';
return _this;
}
Axis2D.prototype.isHorizontal = function () {
var position = this.position;
return position === 'top' || position === 'bottom';
};
/**
* Each item cooresponds to this.getExtent(), which
* means globalExtent[0] may greater than globalExtent[1],
* unless `asc` is input.
*
* @param {boolean} [asc]
* @return {Array.<number>}
*/
Axis2D.prototype.getGlobalExtent = function (asc) {
var ret = this.getExtent();
ret[0] = this.toGlobalCoord(ret[0]);
ret[1] = this.toGlobalCoord(ret[1]);
asc && ret[0] > ret[1] && ret.reverse();
return ret;
};
Axis2D.prototype.pointToData = function (point, clamp) {
return this.coordToData(this.toLocalCoord(point[this.dim === 'x' ? 0 : 1]), clamp);
};
/**
* Set ordinalSortInfo
* @param info new OrdinalSortInfo
*/
Axis2D.prototype.setCategorySortInfo = function (info) {
if (this.type !== 'category') {
return false;
}
this.model.option.categorySortInfo = info;
this.scale.setSortInfo(info);
};
return Axis2D;
}(Axis);
export default Axis2D;

View File

@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { __extends } from "tslib";
import * as zrUtil from 'zrender/lib/core/util.js';
import ComponentModel from '../../model/Component.js';
import { AxisModelCommonMixin } from '../axisModelCommonMixin.js';
import { SINGLE_REFERRING } from '../../util/model.js';
var CartesianAxisModel = /** @class */function (_super) {
__extends(CartesianAxisModel, _super);
function CartesianAxisModel() {
return _super !== null && _super.apply(this, arguments) || this;
}
CartesianAxisModel.prototype.getCoordSysModel = function () {
return this.getReferringComponents('grid', SINGLE_REFERRING).models[0];
};
CartesianAxisModel.type = 'cartesian2dAxis';
return CartesianAxisModel;
}(ComponentModel);
export { CartesianAxisModel };
zrUtil.mixin(CartesianAxisModel, AxisModelCommonMixin);
export default CartesianAxisModel;

View File

@ -0,0 +1,74 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import * as zrUtil from 'zrender/lib/core/util.js';
var Cartesian = /** @class */function () {
function Cartesian(name) {
this.type = 'cartesian';
this._dimList = [];
this._axes = {};
this.name = name || '';
}
Cartesian.prototype.getAxis = function (dim) {
return this._axes[dim];
};
Cartesian.prototype.getAxes = function () {
return zrUtil.map(this._dimList, function (dim) {
return this._axes[dim];
}, this);
};
Cartesian.prototype.getAxesByScale = function (scaleType) {
scaleType = scaleType.toLowerCase();
return zrUtil.filter(this.getAxes(), function (axis) {
return axis.scale.type === scaleType;
});
};
Cartesian.prototype.addAxis = function (axis) {
var dim = axis.dim;
this._axes[dim] = axis;
this._dimList.push(dim);
};
return Cartesian;
}();
;
export default Cartesian;

View File

@ -0,0 +1,169 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { __extends } from "tslib";
import BoundingRect from 'zrender/lib/core/BoundingRect.js';
import Cartesian from './Cartesian.js';
import { invert } from 'zrender/lib/core/matrix.js';
import { applyTransform } from 'zrender/lib/core/vector.js';
export var cartesian2DDimensions = ['x', 'y'];
function canCalculateAffineTransform(scale) {
return scale.type === 'interval' || scale.type === 'time';
}
var Cartesian2D = /** @class */function (_super) {
__extends(Cartesian2D, _super);
function Cartesian2D() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.type = 'cartesian2d';
_this.dimensions = cartesian2DDimensions;
return _this;
}
/**
* Calculate an affine transform matrix if two axes are time or value.
* It's mainly for accelartion on the large time series data.
*/
Cartesian2D.prototype.calcAffineTransform = function () {
this._transform = this._invTransform = null;
var xAxisScale = this.getAxis('x').scale;
var yAxisScale = this.getAxis('y').scale;
if (!canCalculateAffineTransform(xAxisScale) || !canCalculateAffineTransform(yAxisScale)) {
return;
}
var xScaleExtent = xAxisScale.getExtent();
var yScaleExtent = yAxisScale.getExtent();
var start = this.dataToPoint([xScaleExtent[0], yScaleExtent[0]]);
var end = this.dataToPoint([xScaleExtent[1], yScaleExtent[1]]);
var xScaleSpan = xScaleExtent[1] - xScaleExtent[0];
var yScaleSpan = yScaleExtent[1] - yScaleExtent[0];
if (!xScaleSpan || !yScaleSpan) {
return;
}
// Accelerate data to point calculation on the special large time series data.
var scaleX = (end[0] - start[0]) / xScaleSpan;
var scaleY = (end[1] - start[1]) / yScaleSpan;
var translateX = start[0] - xScaleExtent[0] * scaleX;
var translateY = start[1] - yScaleExtent[0] * scaleY;
var m = this._transform = [scaleX, 0, 0, scaleY, translateX, translateY];
this._invTransform = invert([], m);
};
/**
* Base axis will be used on stacking.
*/
Cartesian2D.prototype.getBaseAxis = function () {
return this.getAxesByScale('ordinal')[0] || this.getAxesByScale('time')[0] || this.getAxis('x');
};
Cartesian2D.prototype.containPoint = function (point) {
var axisX = this.getAxis('x');
var axisY = this.getAxis('y');
return axisX.contain(axisX.toLocalCoord(point[0])) && axisY.contain(axisY.toLocalCoord(point[1]));
};
Cartesian2D.prototype.containData = function (data) {
return this.getAxis('x').containData(data[0]) && this.getAxis('y').containData(data[1]);
};
Cartesian2D.prototype.containZone = function (data1, data2) {
var zoneDiag1 = this.dataToPoint(data1);
var zoneDiag2 = this.dataToPoint(data2);
var area = this.getArea();
var zone = new BoundingRect(zoneDiag1[0], zoneDiag1[1], zoneDiag2[0] - zoneDiag1[0], zoneDiag2[1] - zoneDiag1[1]);
return area.intersect(zone);
};
Cartesian2D.prototype.dataToPoint = function (data, clamp, out) {
out = out || [];
var xVal = data[0];
var yVal = data[1];
// Fast path
if (this._transform
// It's supported that if data is like `[Inifity, 123]`, where only Y pixel calculated.
&& xVal != null && isFinite(xVal) && yVal != null && isFinite(yVal)) {
return applyTransform(out, data, this._transform);
}
var xAxis = this.getAxis('x');
var yAxis = this.getAxis('y');
out[0] = xAxis.toGlobalCoord(xAxis.dataToCoord(xVal, clamp));
out[1] = yAxis.toGlobalCoord(yAxis.dataToCoord(yVal, clamp));
return out;
};
Cartesian2D.prototype.clampData = function (data, out) {
var xScale = this.getAxis('x').scale;
var yScale = this.getAxis('y').scale;
var xAxisExtent = xScale.getExtent();
var yAxisExtent = yScale.getExtent();
var x = xScale.parse(data[0]);
var y = yScale.parse(data[1]);
out = out || [];
out[0] = Math.min(Math.max(Math.min(xAxisExtent[0], xAxisExtent[1]), x), Math.max(xAxisExtent[0], xAxisExtent[1]));
out[1] = Math.min(Math.max(Math.min(yAxisExtent[0], yAxisExtent[1]), y), Math.max(yAxisExtent[0], yAxisExtent[1]));
return out;
};
Cartesian2D.prototype.pointToData = function (point, clamp) {
var out = [];
if (this._invTransform) {
return applyTransform(out, point, this._invTransform);
}
var xAxis = this.getAxis('x');
var yAxis = this.getAxis('y');
out[0] = xAxis.coordToData(xAxis.toLocalCoord(point[0]), clamp);
out[1] = yAxis.coordToData(yAxis.toLocalCoord(point[1]), clamp);
return out;
};
Cartesian2D.prototype.getOtherAxis = function (axis) {
return this.getAxis(axis.dim === 'x' ? 'y' : 'x');
};
/**
* Get rect area of cartesian.
* Area will have a contain function to determine if a point is in the coordinate system.
*/
Cartesian2D.prototype.getArea = function (tolerance) {
tolerance = tolerance || 0;
var xExtent = this.getAxis('x').getGlobalExtent();
var yExtent = this.getAxis('y').getGlobalExtent();
var x = Math.min(xExtent[0], xExtent[1]) - tolerance;
var y = Math.min(yExtent[0], yExtent[1]) - tolerance;
var width = Math.max(xExtent[0], xExtent[1]) - x + tolerance;
var height = Math.max(yExtent[0], yExtent[1]) - y + tolerance;
return new BoundingRect(x, y, width, height);
};
return Cartesian2D;
}(Cartesian);
;
export default Cartesian2D;

View File

@ -0,0 +1,493 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Grid is a region which contains at most 4 cartesian systems
*
* TODO Default cartesian
*/
import { isObject, each, indexOf, retrieve3, keys } from 'zrender/lib/core/util.js';
import { getLayoutRect } from '../../util/layout.js';
import { createScaleByModel, ifAxisCrossZero, niceScaleExtent, estimateLabelUnionRect, getDataDimensionsOnAxis } from '../../coord/axisHelper.js';
import Cartesian2D, { cartesian2DDimensions } from './Cartesian2D.js';
import Axis2D from './Axis2D.js';
import { SINGLE_REFERRING } from '../../util/model.js';
import { isCartesian2DSeries, findAxisModels } from './cartesianAxisHelper.js';
import { isIntervalOrLogScale } from '../../scale/helper.js';
import { alignScaleTicks } from '../axisAlignTicks.js';
var Grid = /** @class */function () {
function Grid(gridModel, ecModel, api) {
// FIXME:TS where used (different from registered type 'cartesian2d')?
this.type = 'grid';
this._coordsMap = {};
this._coordsList = [];
this._axesMap = {};
this._axesList = [];
this.axisPointerEnabled = true;
this.dimensions = cartesian2DDimensions;
this._initCartesian(gridModel, ecModel, api);
this.model = gridModel;
}
Grid.prototype.getRect = function () {
return this._rect;
};
Grid.prototype.update = function (ecModel, api) {
var axesMap = this._axesMap;
this._updateScale(ecModel, this.model);
function updateAxisTicks(axes) {
var alignTo;
// Axis is added in order of axisIndex.
var axesIndices = keys(axes);
var len = axesIndices.length;
if (!len) {
return;
}
var axisNeedsAlign = [];
// Process once and calculate the ticks for those don't use alignTicks.
for (var i = len - 1; i >= 0; i--) {
var idx = +axesIndices[i]; // Convert to number.
var axis = axes[idx];
var model = axis.model;
var scale = axis.scale;
if (
// Only value and log axis without interval support alignTicks.
isIntervalOrLogScale(scale) && model.get('alignTicks') && model.get('interval') == null) {
axisNeedsAlign.push(axis);
} else {
niceScaleExtent(scale, model);
if (isIntervalOrLogScale(scale)) {
// Can only align to interval or log axis.
alignTo = axis;
}
}
}
;
// All axes has set alignTicks. Pick the first one.
// PENDING. Should we find the axis that both set interval, min, max and align to this one?
if (axisNeedsAlign.length) {
if (!alignTo) {
alignTo = axisNeedsAlign.pop();
niceScaleExtent(alignTo.scale, alignTo.model);
}
each(axisNeedsAlign, function (axis) {
alignScaleTicks(axis.scale, axis.model, alignTo.scale);
});
}
}
updateAxisTicks(axesMap.x);
updateAxisTicks(axesMap.y);
// Key: axisDim_axisIndex, value: boolean, whether onZero target.
var onZeroRecords = {};
each(axesMap.x, function (xAxis) {
fixAxisOnZero(axesMap, 'y', xAxis, onZeroRecords);
});
each(axesMap.y, function (yAxis) {
fixAxisOnZero(axesMap, 'x', yAxis, onZeroRecords);
});
// Resize again if containLabel is enabled
// FIXME It may cause getting wrong grid size in data processing stage
this.resize(this.model, api);
};
/**
* Resize the grid
*/
Grid.prototype.resize = function (gridModel, api, ignoreContainLabel) {
var boxLayoutParams = gridModel.getBoxLayoutParams();
var isContainLabel = !ignoreContainLabel && gridModel.get('containLabel');
var gridRect = getLayoutRect(boxLayoutParams, {
width: api.getWidth(),
height: api.getHeight()
});
this._rect = gridRect;
var axesList = this._axesList;
adjustAxes();
// Minus label size
if (isContainLabel) {
each(axesList, function (axis) {
if (!axis.model.get(['axisLabel', 'inside'])) {
var labelUnionRect = estimateLabelUnionRect(axis);
if (labelUnionRect) {
var dim = axis.isHorizontal() ? 'height' : 'width';
var margin = axis.model.get(['axisLabel', 'margin']);
gridRect[dim] -= labelUnionRect[dim] + margin;
if (axis.position === 'top') {
gridRect.y += labelUnionRect.height + margin;
} else if (axis.position === 'left') {
gridRect.x += labelUnionRect.width + margin;
}
}
}
});
adjustAxes();
}
each(this._coordsList, function (coord) {
// Calculate affine matrix to accelerate the data to point transform.
// If all the axes scales are time or value.
coord.calcAffineTransform();
});
function adjustAxes() {
each(axesList, function (axis) {
var isHorizontal = axis.isHorizontal();
var extent = isHorizontal ? [0, gridRect.width] : [0, gridRect.height];
var idx = axis.inverse ? 1 : 0;
axis.setExtent(extent[idx], extent[1 - idx]);
updateAxisTransform(axis, isHorizontal ? gridRect.x : gridRect.y);
});
}
};
Grid.prototype.getAxis = function (dim, axisIndex) {
var axesMapOnDim = this._axesMap[dim];
if (axesMapOnDim != null) {
return axesMapOnDim[axisIndex || 0];
}
};
Grid.prototype.getAxes = function () {
return this._axesList.slice();
};
Grid.prototype.getCartesian = function (xAxisIndex, yAxisIndex) {
if (xAxisIndex != null && yAxisIndex != null) {
var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
return this._coordsMap[key];
}
if (isObject(xAxisIndex)) {
yAxisIndex = xAxisIndex.yAxisIndex;
xAxisIndex = xAxisIndex.xAxisIndex;
}
for (var i = 0, coordList = this._coordsList; i < coordList.length; i++) {
if (coordList[i].getAxis('x').index === xAxisIndex || coordList[i].getAxis('y').index === yAxisIndex) {
return coordList[i];
}
}
};
Grid.prototype.getCartesians = function () {
return this._coordsList.slice();
};
/**
* @implements
*/
Grid.prototype.convertToPixel = function (ecModel, finder, value) {
var target = this._findConvertTarget(finder);
return target.cartesian ? target.cartesian.dataToPoint(value) : target.axis ? target.axis.toGlobalCoord(target.axis.dataToCoord(value)) : null;
};
/**
* @implements
*/
Grid.prototype.convertFromPixel = function (ecModel, finder, value) {
var target = this._findConvertTarget(finder);
return target.cartesian ? target.cartesian.pointToData(value) : target.axis ? target.axis.coordToData(target.axis.toLocalCoord(value)) : null;
};
Grid.prototype._findConvertTarget = function (finder) {
var seriesModel = finder.seriesModel;
var xAxisModel = finder.xAxisModel || seriesModel && seriesModel.getReferringComponents('xAxis', SINGLE_REFERRING).models[0];
var yAxisModel = finder.yAxisModel || seriesModel && seriesModel.getReferringComponents('yAxis', SINGLE_REFERRING).models[0];
var gridModel = finder.gridModel;
var coordsList = this._coordsList;
var cartesian;
var axis;
if (seriesModel) {
cartesian = seriesModel.coordinateSystem;
indexOf(coordsList, cartesian) < 0 && (cartesian = null);
} else if (xAxisModel && yAxisModel) {
cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
} else if (xAxisModel) {
axis = this.getAxis('x', xAxisModel.componentIndex);
} else if (yAxisModel) {
axis = this.getAxis('y', yAxisModel.componentIndex);
}
// Lowest priority.
else if (gridModel) {
var grid = gridModel.coordinateSystem;
if (grid === this) {
cartesian = this._coordsList[0];
}
}
return {
cartesian: cartesian,
axis: axis
};
};
/**
* @implements
*/
Grid.prototype.containPoint = function (point) {
var coord = this._coordsList[0];
if (coord) {
return coord.containPoint(point);
}
};
/**
* Initialize cartesian coordinate systems
*/
Grid.prototype._initCartesian = function (gridModel, ecModel, api) {
var _this = this;
var grid = this;
var axisPositionUsed = {
left: false,
right: false,
top: false,
bottom: false
};
var axesMap = {
x: {},
y: {}
};
var axesCount = {
x: 0,
y: 0
};
// Create axis
ecModel.eachComponent('xAxis', createAxisCreator('x'), this);
ecModel.eachComponent('yAxis', createAxisCreator('y'), this);
if (!axesCount.x || !axesCount.y) {
// Roll back when there no either x or y axis
this._axesMap = {};
this._axesList = [];
return;
}
this._axesMap = axesMap;
// Create cartesian2d
each(axesMap.x, function (xAxis, xAxisIndex) {
each(axesMap.y, function (yAxis, yAxisIndex) {
var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
var cartesian = new Cartesian2D(key);
cartesian.master = _this;
cartesian.model = gridModel;
_this._coordsMap[key] = cartesian;
_this._coordsList.push(cartesian);
cartesian.addAxis(xAxis);
cartesian.addAxis(yAxis);
});
});
function createAxisCreator(dimName) {
return function (axisModel, idx) {
if (!isAxisUsedInTheGrid(axisModel, gridModel)) {
return;
}
var axisPosition = axisModel.get('position');
if (dimName === 'x') {
// Fix position
if (axisPosition !== 'top' && axisPosition !== 'bottom') {
// Default bottom of X
axisPosition = axisPositionUsed.bottom ? 'top' : 'bottom';
}
} else {
// Fix position
if (axisPosition !== 'left' && axisPosition !== 'right') {
// Default left of Y
axisPosition = axisPositionUsed.left ? 'right' : 'left';
}
}
axisPositionUsed[axisPosition] = true;
var axis = new Axis2D(dimName, createScaleByModel(axisModel), [0, 0], axisModel.get('type'), axisPosition);
var isCategory = axis.type === 'category';
axis.onBand = isCategory && axisModel.get('boundaryGap');
axis.inverse = axisModel.get('inverse');
// Inject axis into axisModel
axisModel.axis = axis;
// Inject axisModel into axis
axis.model = axisModel;
// Inject grid info axis
axis.grid = grid;
// Index of axis, can be used as key
axis.index = idx;
grid._axesList.push(axis);
axesMap[dimName][idx] = axis;
axesCount[dimName]++;
};
}
};
/**
* Update cartesian properties from series.
*/
Grid.prototype._updateScale = function (ecModel, gridModel) {
// Reset scale
each(this._axesList, function (axis) {
axis.scale.setExtent(Infinity, -Infinity);
if (axis.type === 'category') {
var categorySortInfo = axis.model.get('categorySortInfo');
axis.scale.setSortInfo(categorySortInfo);
}
});
ecModel.eachSeries(function (seriesModel) {
if (isCartesian2DSeries(seriesModel)) {
var axesModelMap = findAxisModels(seriesModel);
var xAxisModel = axesModelMap.xAxisModel;
var yAxisModel = axesModelMap.yAxisModel;
if (!isAxisUsedInTheGrid(xAxisModel, gridModel) || !isAxisUsedInTheGrid(yAxisModel, gridModel)) {
return;
}
var cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
var data = seriesModel.getData();
var xAxis = cartesian.getAxis('x');
var yAxis = cartesian.getAxis('y');
unionExtent(data, xAxis);
unionExtent(data, yAxis);
}
}, this);
function unionExtent(data, axis) {
each(getDataDimensionsOnAxis(data, axis.dim), function (dim) {
axis.scale.unionExtentFromData(data, dim);
});
}
};
/**
* @param dim 'x' or 'y' or 'auto' or null/undefined
*/
Grid.prototype.getTooltipAxes = function (dim) {
var baseAxes = [];
var otherAxes = [];
each(this.getCartesians(), function (cartesian) {
var baseAxis = dim != null && dim !== 'auto' ? cartesian.getAxis(dim) : cartesian.getBaseAxis();
var otherAxis = cartesian.getOtherAxis(baseAxis);
indexOf(baseAxes, baseAxis) < 0 && baseAxes.push(baseAxis);
indexOf(otherAxes, otherAxis) < 0 && otherAxes.push(otherAxis);
});
return {
baseAxes: baseAxes,
otherAxes: otherAxes
};
};
Grid.create = function (ecModel, api) {
var grids = [];
ecModel.eachComponent('grid', function (gridModel, idx) {
var grid = new Grid(gridModel, ecModel, api);
grid.name = 'grid_' + idx;
// dataSampling requires axis extent, so resize
// should be performed in create stage.
grid.resize(gridModel, api, true);
gridModel.coordinateSystem = grid;
grids.push(grid);
});
// Inject the coordinateSystems into seriesModel
ecModel.eachSeries(function (seriesModel) {
if (!isCartesian2DSeries(seriesModel)) {
return;
}
var axesModelMap = findAxisModels(seriesModel);
var xAxisModel = axesModelMap.xAxisModel;
var yAxisModel = axesModelMap.yAxisModel;
var gridModel = xAxisModel.getCoordSysModel();
if (process.env.NODE_ENV !== 'production') {
if (!gridModel) {
throw new Error('Grid "' + retrieve3(xAxisModel.get('gridIndex'), xAxisModel.get('gridId'), 0) + '" not found');
}
if (xAxisModel.getCoordSysModel() !== yAxisModel.getCoordSysModel()) {
throw new Error('xAxis and yAxis must use the same grid');
}
}
var grid = gridModel.coordinateSystem;
seriesModel.coordinateSystem = grid.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
});
return grids;
};
// For deciding which dimensions to use when creating list data
Grid.dimensions = cartesian2DDimensions;
return Grid;
}();
/**
* Check if the axis is used in the specified grid.
*/
function isAxisUsedInTheGrid(axisModel, gridModel) {
return axisModel.getCoordSysModel() === gridModel;
}
function fixAxisOnZero(axesMap, otherAxisDim, axis,
// Key: see `getOnZeroRecordKey`
onZeroRecords) {
axis.getAxesOnZeroOf = function () {
// TODO: onZero of multiple axes.
return otherAxisOnZeroOf ? [otherAxisOnZeroOf] : [];
};
// onZero can not be enabled in these two situations:
// 1. When any other axis is a category axis.
// 2. When no axis is cross 0 point.
var otherAxes = axesMap[otherAxisDim];
var otherAxisOnZeroOf;
var axisModel = axis.model;
var onZero = axisModel.get(['axisLine', 'onZero']);
var onZeroAxisIndex = axisModel.get(['axisLine', 'onZeroAxisIndex']);
if (!onZero) {
return;
}
// If target axis is specified.
if (onZeroAxisIndex != null) {
if (canOnZeroToAxis(otherAxes[onZeroAxisIndex])) {
otherAxisOnZeroOf = otherAxes[onZeroAxisIndex];
}
} else {
// Find the first available other axis.
for (var idx in otherAxes) {
if (otherAxes.hasOwnProperty(idx) && canOnZeroToAxis(otherAxes[idx])
// Consider that two Y axes on one value axis,
// if both onZero, the two Y axes overlap.
&& !onZeroRecords[getOnZeroRecordKey(otherAxes[idx])]) {
otherAxisOnZeroOf = otherAxes[idx];
break;
}
}
}
if (otherAxisOnZeroOf) {
onZeroRecords[getOnZeroRecordKey(otherAxisOnZeroOf)] = true;
}
function getOnZeroRecordKey(axis) {
return axis.dim + '_' + axis.index;
}
}
function canOnZeroToAxis(axis) {
return axis && axis.type !== 'category' && axis.type !== 'time' && ifAxisCrossZero(axis);
}
function updateAxisTransform(axis, coordBase) {
var axisExtent = axis.getExtent();
var axisExtentSum = axisExtent[0] + axisExtent[1];
// Fast transform
axis.toGlobalCoord = axis.dim === 'x' ? function (coord) {
return coord + coordBase;
} : function (coord) {
return axisExtentSum - coord + coordBase;
};
axis.toLocalCoord = axis.dim === 'x' ? function (coord) {
return coord - coordBase;
} : function (coord) {
return axisExtentSum - coord + coordBase;
};
}
export default Grid;

View File

@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { __extends } from "tslib";
import ComponentModel from '../../model/Component.js';
var GridModel = /** @class */function (_super) {
__extends(GridModel, _super);
function GridModel() {
return _super !== null && _super.apply(this, arguments) || this;
}
GridModel.type = 'grid';
GridModel.dependencies = ['xAxis', 'yAxis'];
GridModel.layoutMode = 'box';
GridModel.defaultOption = {
show: false,
// zlevel: 0,
z: 0,
left: '10%',
top: 60,
right: '10%',
bottom: 70,
// If grid size contain label
containLabel: false,
// width: {totalWidth} - left - right,
// height: {totalHeight} - top - bottom,
backgroundColor: 'rgba(0,0,0,0)',
borderWidth: 1,
borderColor: '#ccc'
};
return GridModel;
}(ComponentModel);
export default GridModel;

View File

@ -0,0 +1,119 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import * as zrUtil from 'zrender/lib/core/util.js';
import { SINGLE_REFERRING } from '../../util/model.js';
/**
* Can only be called after coordinate system creation stage.
* (Can be called before coordinate system update stage).
*/
export function layout(gridModel, axisModel, opt) {
opt = opt || {};
var grid = gridModel.coordinateSystem;
var axis = axisModel.axis;
var layout = {};
var otherAxisOnZeroOf = axis.getAxesOnZeroOf()[0];
var rawAxisPosition = axis.position;
var axisPosition = otherAxisOnZeroOf ? 'onZero' : rawAxisPosition;
var axisDim = axis.dim;
var rect = grid.getRect();
var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
var idx = {
left: 0,
right: 1,
top: 0,
bottom: 1,
onZero: 2
};
var axisOffset = axisModel.get('offset') || 0;
var posBound = axisDim === 'x' ? [rectBound[2] - axisOffset, rectBound[3] + axisOffset] : [rectBound[0] - axisOffset, rectBound[1] + axisOffset];
if (otherAxisOnZeroOf) {
var onZeroCoord = otherAxisOnZeroOf.toGlobalCoord(otherAxisOnZeroOf.dataToCoord(0));
posBound[idx.onZero] = Math.max(Math.min(onZeroCoord, posBound[1]), posBound[0]);
}
// Axis position
layout.position = [axisDim === 'y' ? posBound[idx[axisPosition]] : rectBound[0], axisDim === 'x' ? posBound[idx[axisPosition]] : rectBound[3]];
// Axis rotation
layout.rotation = Math.PI / 2 * (axisDim === 'x' ? 0 : 1);
// Tick and label direction, x y is axisDim
var dirMap = {
top: -1,
bottom: 1,
left: -1,
right: 1
};
layout.labelDirection = layout.tickDirection = layout.nameDirection = dirMap[rawAxisPosition];
layout.labelOffset = otherAxisOnZeroOf ? posBound[idx[rawAxisPosition]] - posBound[idx.onZero] : 0;
if (axisModel.get(['axisTick', 'inside'])) {
layout.tickDirection = -layout.tickDirection;
}
if (zrUtil.retrieve(opt.labelInside, axisModel.get(['axisLabel', 'inside']))) {
layout.labelDirection = -layout.labelDirection;
}
// Special label rotation
var labelRotate = axisModel.get(['axisLabel', 'rotate']);
layout.labelRotate = axisPosition === 'top' ? -labelRotate : labelRotate;
// Over splitLine and splitArea
layout.z2 = 1;
return layout;
}
export function isCartesian2DSeries(seriesModel) {
return seriesModel.get('coordinateSystem') === 'cartesian2d';
}
export function findAxisModels(seriesModel) {
var axisModelMap = {
xAxisModel: null,
yAxisModel: null
};
zrUtil.each(axisModelMap, function (v, key) {
var axisType = key.replace(/Model$/, '');
var axisModel = seriesModel.getReferringComponents(axisType, SINGLE_REFERRING).models[0];
if (process.env.NODE_ENV !== 'production') {
if (!axisModel) {
throw new Error(axisType + ' "' + zrUtil.retrieve3(seriesModel.get(axisType + 'Index'), seriesModel.get(axisType + 'Id'), 0) + '" not found');
}
}
axisModelMap[key] = axisModel;
});
return axisModelMap;
}

View File

@ -0,0 +1,223 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import * as echarts from '../../core/echarts.js';
import { createHashMap, each, hasOwn, keys, map } from 'zrender/lib/core/util.js';
import { isCartesian2DSeries, findAxisModels } from './cartesianAxisHelper.js';
import { getDataDimensionsOnAxis, unionAxisExtentFromData } from '../axisHelper.js';
import { ensureScaleRawExtentInfo } from '../scaleRawExtentInfo.js';
// A tricky: the priority is just after dataZoom processor.
// If dataZoom has fixed the min/max, this processor do not need to work.
// TODO: SELF REGISTERED.
echarts.registerProcessor(echarts.PRIORITY.PROCESSOR.FILTER + 10, {
getTargetSeries: function (ecModel) {
var seriesModelMap = createHashMap();
ecModel.eachSeries(function (seriesModel) {
isCartesian2DSeries(seriesModel) && seriesModelMap.set(seriesModel.uid, seriesModel);
});
return seriesModelMap;
},
overallReset: function (ecModel, api) {
var seriesRecords = [];
var axisRecordMap = createHashMap();
prepareDataExtentOnAxis(ecModel, axisRecordMap, seriesRecords);
calculateFilteredExtent(axisRecordMap, seriesRecords);
shrinkAxisExtent(axisRecordMap);
}
});
function prepareDataExtentOnAxis(ecModel, axisRecordMap, seriesRecords) {
ecModel.eachSeries(function (seriesModel) {
if (!isCartesian2DSeries(seriesModel)) {
return;
}
var axesModelMap = findAxisModels(seriesModel);
var xAxisModel = axesModelMap.xAxisModel;
var yAxisModel = axesModelMap.yAxisModel;
var xAxis = xAxisModel.axis;
var yAxis = yAxisModel.axis;
var xRawExtentInfo = xAxis.scale.rawExtentInfo;
var yRawExtentInfo = yAxis.scale.rawExtentInfo;
var data = seriesModel.getData();
// If either axis controlled by other filter like "dataZoom",
// use the rule of dataZoom rather than adopting the rules here.
if (xRawExtentInfo && xRawExtentInfo.frozen || yRawExtentInfo && yRawExtentInfo.frozen) {
return;
}
seriesRecords.push({
seriesModel: seriesModel,
xAxisModel: xAxisModel,
yAxisModel: yAxisModel
});
// FIXME: this logic needs to be consistent with
// `coord/cartesian/Grid.ts#_updateScale`.
// It's not good to implement one logic in multiple places.
unionAxisExtentFromData(prepareAxisRecord(axisRecordMap, xAxisModel).condExtent, data, xAxis.dim);
unionAxisExtentFromData(prepareAxisRecord(axisRecordMap, yAxisModel).condExtent, data, yAxis.dim);
});
}
function calculateFilteredExtent(axisRecordMap, seriesRecords) {
each(seriesRecords, function (seriesRecord) {
var xAxisModel = seriesRecord.xAxisModel;
var yAxisModel = seriesRecord.yAxisModel;
var xAxis = xAxisModel.axis;
var yAxis = yAxisModel.axis;
var xAxisRecord = prepareAxisRecord(axisRecordMap, xAxisModel);
var yAxisRecord = prepareAxisRecord(axisRecordMap, yAxisModel);
xAxisRecord.rawExtentInfo = ensureScaleRawExtentInfo(xAxis.scale, xAxisModel, xAxisRecord.condExtent);
yAxisRecord.rawExtentInfo = ensureScaleRawExtentInfo(yAxis.scale, yAxisModel, yAxisRecord.condExtent);
xAxisRecord.rawExtentResult = xAxisRecord.rawExtentInfo.calculate();
yAxisRecord.rawExtentResult = yAxisRecord.rawExtentInfo.calculate();
// If the "xAxis" is set `min`/`max`, some data items might be out of the cartesian.
// then the "yAxis" may needs to calculate extent only based on the data items inside
// the cartesian (similar to what "dataZoom" did).
// A typical case is bar-racing, where bars ara sort dynamically and may only need to
// displayed part of the whole bars.
var data = seriesRecord.seriesModel.getData();
// For duplication removal.
var condDimMap = {};
var tarDimMap = {};
var condAxis;
var tarAxisRecord;
function addCondition(axis, axisRecord) {
// But for simplicity and safety and performance, we only adopt this
// feature on category axis at present.
var condExtent = axisRecord.condExtent;
var rawExtentResult = axisRecord.rawExtentResult;
if (axis.type === 'category' && (condExtent[0] < rawExtentResult.min || rawExtentResult.max < condExtent[1])) {
each(getDataDimensionsOnAxis(data, axis.dim), function (dataDim) {
if (!hasOwn(condDimMap, dataDim)) {
condDimMap[dataDim] = true;
condAxis = axis;
}
});
}
}
function addTarget(axis, axisRecord) {
var rawExtentResult = axisRecord.rawExtentResult;
if (axis.type !== 'category' && (!rawExtentResult.minFixed || !rawExtentResult.maxFixed)) {
each(getDataDimensionsOnAxis(data, axis.dim), function (dataDim) {
if (!hasOwn(condDimMap, dataDim) && !hasOwn(tarDimMap, dataDim)) {
tarDimMap[dataDim] = true;
tarAxisRecord = axisRecord;
}
});
}
}
addCondition(xAxis, xAxisRecord);
addCondition(yAxis, yAxisRecord);
addTarget(xAxis, xAxisRecord);
addTarget(yAxis, yAxisRecord);
var condDims = keys(condDimMap);
var tarDims = keys(tarDimMap);
var tarDimExtents = map(tarDims, function () {
return initExtent();
});
var condDimsLen = condDims.length;
var tarDimsLen = tarDims.length;
if (!condDimsLen || !tarDimsLen) {
return;
}
var singleCondDim = condDimsLen === 1 ? condDims[0] : null;
var singleTarDim = tarDimsLen === 1 ? tarDims[0] : null;
var dataLen = data.count();
// Time consuming, because this is a "block task".
// Simple optimization for the vast majority of cases.
if (singleCondDim && singleTarDim) {
for (var dataIdx = 0; dataIdx < dataLen; dataIdx++) {
var condVal = data.get(singleCondDim, dataIdx);
if (condAxis.scale.isInExtentRange(condVal)) {
unionExtent(tarDimExtents[0], data.get(singleTarDim, dataIdx));
}
}
} else {
for (var dataIdx = 0; dataIdx < dataLen; dataIdx++) {
for (var j = 0; j < condDimsLen; j++) {
var condVal = data.get(condDims[j], dataIdx);
if (condAxis.scale.isInExtentRange(condVal)) {
for (var k = 0; k < tarDimsLen; k++) {
unionExtent(tarDimExtents[k], data.get(tarDims[k], dataIdx));
}
// Any one dim is in range means satisfied.
break;
}
}
}
}
each(tarDimExtents, function (tarDimExtent, i) {
var dim = tarDims[i];
// FIXME: if there has been approximateExtent set?
data.setApproximateExtent(tarDimExtent, dim);
var tarAxisExtent = tarAxisRecord.tarExtent = tarAxisRecord.tarExtent || initExtent();
unionExtent(tarAxisExtent, tarDimExtent[0]);
unionExtent(tarAxisExtent, tarDimExtent[1]);
});
});
}
function shrinkAxisExtent(axisRecordMap) {
axisRecordMap.each(function (axisRecord) {
var tarAxisExtent = axisRecord.tarExtent;
if (tarAxisExtent) {
var rawExtentResult = axisRecord.rawExtentResult;
var rawExtentInfo = axisRecord.rawExtentInfo;
// Shink the original extent.
if (!rawExtentResult.minFixed && tarAxisExtent[0] > rawExtentResult.min) {
rawExtentInfo.modifyDataMinMax('min', tarAxisExtent[0]);
}
if (!rawExtentResult.maxFixed && tarAxisExtent[1] < rawExtentResult.max) {
rawExtentInfo.modifyDataMinMax('max', tarAxisExtent[1]);
}
}
});
}
function prepareAxisRecord(axisRecordMap, axisModel) {
return axisRecordMap.get(axisModel.uid) || axisRecordMap.set(axisModel.uid, {
condExtent: initExtent()
});
}
function initExtent() {
return [Infinity, -Infinity];
}
function unionExtent(extent, val) {
val < extent[0] && (extent[0] = val);
val > extent[1] && (extent[1] = val);
}

View File

@ -0,0 +1,74 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import * as zrUtil from 'zrender/lib/core/util.js';
function dataToCoordSize(dataSize, dataItem) {
// dataItem is necessary in log axis.
dataItem = dataItem || [0, 0];
return zrUtil.map(['x', 'y'], function (dim, dimIdx) {
var axis = this.getAxis(dim);
var val = dataItem[dimIdx];
var halfSize = dataSize[dimIdx] / 2;
return axis.type === 'category' ? axis.getBandWidth() : Math.abs(axis.dataToCoord(val - halfSize) - axis.dataToCoord(val + halfSize));
}, this);
}
export default function cartesianPrepareCustom(coordSys) {
var rect = coordSys.master.getRect();
return {
coordSys: {
// The name exposed to user is always 'cartesian2d' but not 'grid'.
type: 'cartesian2d',
x: rect.x,
y: rect.y,
width: rect.width,
height: rect.height
},
api: {
coord: function (data) {
// do not provide "out" param
return coordSys.dataToPoint(data);
},
size: zrUtil.bind(dataToCoordSize, coordSys)
}
};
}