first commit

This commit is contained in:
jefferyzhao
2025-07-31 17:44:12 +08:00
commit b9bdc8598b
42390 changed files with 4467935 additions and 0 deletions

308
node_modules/echarts/lib/scale/Interval.js generated vendored Normal file
View File

@ -0,0 +1,308 @@
/*
* 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.
*/
var numberUtil = require("../util/number");
var formatUtil = require("../util/format");
var Scale = require("./Scale");
var helper = require("./helper");
/*
* 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.
*/
/**
* Interval scale
* @module echarts/scale/Interval
*/
var roundNumber = numberUtil.round;
/**
* @alias module:echarts/coord/scale/Interval
* @constructor
*/
var IntervalScale = Scale.extend({
type: 'interval',
_interval: 0,
_intervalPrecision: 2,
setExtent: function (start, end) {
var thisExtent = this._extent; //start,end may be a Number like '25',so...
if (!isNaN(start)) {
thisExtent[0] = parseFloat(start);
}
if (!isNaN(end)) {
thisExtent[1] = parseFloat(end);
}
},
unionExtent: function (other) {
var extent = this._extent;
other[0] < extent[0] && (extent[0] = other[0]);
other[1] > extent[1] && (extent[1] = other[1]); // unionExtent may called by it's sub classes
IntervalScale.prototype.setExtent.call(this, extent[0], extent[1]);
},
/**
* Get interval
*/
getInterval: function () {
return this._interval;
},
/**
* Set interval
*/
setInterval: function (interval) {
this._interval = interval; // Dropped auto calculated niceExtent and use user setted extent
// We assume user wan't to set both interval, min, max to get a better result
this._niceExtent = this._extent.slice();
this._intervalPrecision = helper.getIntervalPrecision(interval);
},
/**
* @param {boolean} [expandToNicedExtent=false] If expand the ticks to niced extent.
* @return {Array.<number>}
*/
getTicks: function (expandToNicedExtent) {
var interval = this._interval;
var extent = this._extent;
var niceTickExtent = this._niceExtent;
var intervalPrecision = this._intervalPrecision;
var ticks = []; // If interval is 0, return [];
if (!interval) {
return ticks;
} // Consider this case: using dataZoom toolbox, zoom and zoom.
var safeLimit = 10000;
if (extent[0] < niceTickExtent[0]) {
if (expandToNicedExtent) {
ticks.push(roundNumber(niceTickExtent[0] - interval, intervalPrecision));
} else {
ticks.push(extent[0]);
}
}
var tick = niceTickExtent[0];
while (tick <= niceTickExtent[1]) {
ticks.push(tick); // Avoid rounding error
tick = roundNumber(tick + interval, intervalPrecision);
if (tick === ticks[ticks.length - 1]) {
// Consider out of safe float point, e.g.,
// -3711126.9907707 + 2e-10 === -3711126.9907707
break;
}
if (ticks.length > safeLimit) {
return [];
}
} // Consider this case: the last item of ticks is smaller
// than niceTickExtent[1] and niceTickExtent[1] === extent[1].
var lastNiceTick = ticks.length ? ticks[ticks.length - 1] : niceTickExtent[1];
if (extent[1] > lastNiceTick) {
if (expandToNicedExtent) {
ticks.push(roundNumber(lastNiceTick + interval, intervalPrecision));
} else {
ticks.push(extent[1]);
}
}
return ticks;
},
/**
* @param {number} [splitNumber=5]
* @return {Array.<Array.<number>>}
*/
getMinorTicks: function (splitNumber) {
var ticks = this.getTicks(true);
var minorTicks = [];
var extent = this.getExtent();
for (var i = 1; i < ticks.length; i++) {
var nextTick = ticks[i];
var prevTick = ticks[i - 1];
var count = 0;
var minorTicksGroup = [];
var interval = nextTick - prevTick;
var minorInterval = interval / splitNumber;
while (count < splitNumber - 1) {
var minorTick = numberUtil.round(prevTick + (count + 1) * minorInterval); // For the first and last interval. The count may be less than splitNumber.
if (minorTick > extent[0] && minorTick < extent[1]) {
minorTicksGroup.push(minorTick);
}
count++;
}
minorTicks.push(minorTicksGroup);
}
return minorTicks;
},
/**
* @param {number} data
* @param {Object} [opt]
* @param {number|string} [opt.precision] If 'auto', use nice presision.
* @param {boolean} [opt.pad] returns 1.50 but not 1.5 if precision is 2.
* @return {string}
*/
getLabel: function (data, opt) {
if (data == null) {
return '';
}
var precision = opt && opt.precision;
if (precision == null) {
precision = numberUtil.getPrecisionSafe(data) || 0;
} else if (precision === 'auto') {
// Should be more precise then tick.
precision = this._intervalPrecision;
} // (1) If `precision` is set, 12.005 should be display as '12.00500'.
// (2) Use roundNumber (toFixed) to avoid scientific notation like '3.5e-7'.
data = roundNumber(data, precision, true);
return formatUtil.addCommas(data);
},
/**
* Update interval and extent of intervals for nice ticks
*
* @param {number} [splitNumber = 5] Desired number of ticks
* @param {number} [minInterval]
* @param {number} [maxInterval]
*/
niceTicks: function (splitNumber, minInterval, maxInterval) {
splitNumber = splitNumber || 5;
var extent = this._extent;
var span = extent[1] - extent[0];
if (!isFinite(span)) {
return;
} // User may set axis min 0 and data are all negative
// FIXME If it needs to reverse ?
if (span < 0) {
span = -span;
extent.reverse();
}
var result = helper.intervalScaleNiceTicks(extent, splitNumber, minInterval, maxInterval);
this._intervalPrecision = result.intervalPrecision;
this._interval = result.interval;
this._niceExtent = result.niceTickExtent;
},
/**
* Nice extent.
* @param {Object} opt
* @param {number} [opt.splitNumber = 5] Given approx tick number
* @param {boolean} [opt.fixMin=false]
* @param {boolean} [opt.fixMax=false]
* @param {boolean} [opt.minInterval]
* @param {boolean} [opt.maxInterval]
*/
niceExtent: function (opt) {
var extent = this._extent; // If extent start and end are same, expand them
if (extent[0] === extent[1]) {
if (extent[0] !== 0) {
// Expand extent
var expandSize = extent[0]; // In the fowllowing case
// Axis has been fixed max 100
// Plus data are all 100 and axis extent are [100, 100].
// Extend to the both side will cause expanded max is larger than fixed max.
// So only expand to the smaller side.
if (!opt.fixMax) {
extent[1] += expandSize / 2;
extent[0] -= expandSize / 2;
} else {
extent[0] -= expandSize / 2;
}
} else {
extent[1] = 1;
}
}
var span = extent[1] - extent[0]; // If there are no data and extent are [Infinity, -Infinity]
if (!isFinite(span)) {
extent[0] = 0;
extent[1] = 1;
}
this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval); // var extent = this._extent;
var interval = this._interval;
if (!opt.fixMin) {
extent[0] = roundNumber(Math.floor(extent[0] / interval) * interval);
}
if (!opt.fixMax) {
extent[1] = roundNumber(Math.ceil(extent[1] / interval) * interval);
}
}
});
/**
* @return {module:echarts/scale/Time}
*/
IntervalScale.create = function () {
return new IntervalScale();
};
var _default = IntervalScale;
module.exports = _default;

212
node_modules/echarts/lib/scale/Log.js generated vendored Normal file
View File

@ -0,0 +1,212 @@
/*
* 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.
*/
var zrUtil = require("zrender/lib/core/util");
var Scale = require("./Scale");
var numberUtil = require("../util/number");
var IntervalScale = require("./Interval");
/*
* 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.
*/
/**
* Log scale
* @module echarts/scale/Log
*/
// Use some method of IntervalScale
var scaleProto = Scale.prototype;
var intervalScaleProto = IntervalScale.prototype;
var getPrecisionSafe = numberUtil.getPrecisionSafe;
var roundingErrorFix = numberUtil.round;
var mathFloor = Math.floor;
var mathCeil = Math.ceil;
var mathPow = Math.pow;
var mathLog = Math.log;
var LogScale = Scale.extend({
type: 'log',
base: 10,
$constructor: function () {
Scale.apply(this, arguments);
this._originalScale = new IntervalScale();
},
/**
* @param {boolean} [expandToNicedExtent=false] If expand the ticks to niced extent.
* @return {Array.<number>}
*/
getTicks: function (expandToNicedExtent) {
var originalScale = this._originalScale;
var extent = this._extent;
var originalExtent = originalScale.getExtent();
return zrUtil.map(intervalScaleProto.getTicks.call(this, expandToNicedExtent), function (val) {
var powVal = numberUtil.round(mathPow(this.base, val)); // Fix #4158
powVal = val === extent[0] && originalScale.__fixMin ? fixRoundingError(powVal, originalExtent[0]) : powVal;
powVal = val === extent[1] && originalScale.__fixMax ? fixRoundingError(powVal, originalExtent[1]) : powVal;
return powVal;
}, this);
},
/**
* @param {number} splitNumber
* @return {Array.<Array.<number>>}
*/
getMinorTicks: intervalScaleProto.getMinorTicks,
/**
* @param {number} val
* @return {string}
*/
getLabel: intervalScaleProto.getLabel,
/**
* @param {number} val
* @return {number}
*/
scale: function (val) {
val = scaleProto.scale.call(this, val);
return mathPow(this.base, val);
},
/**
* @param {number} start
* @param {number} end
*/
setExtent: function (start, end) {
var base = this.base;
start = mathLog(start) / mathLog(base);
end = mathLog(end) / mathLog(base);
intervalScaleProto.setExtent.call(this, start, end);
},
/**
* @return {number} end
*/
getExtent: function () {
var base = this.base;
var extent = scaleProto.getExtent.call(this);
extent[0] = mathPow(base, extent[0]);
extent[1] = mathPow(base, extent[1]); // Fix #4158
var originalScale = this._originalScale;
var originalExtent = originalScale.getExtent();
originalScale.__fixMin && (extent[0] = fixRoundingError(extent[0], originalExtent[0]));
originalScale.__fixMax && (extent[1] = fixRoundingError(extent[1], originalExtent[1]));
return extent;
},
/**
* @param {Array.<number>} extent
*/
unionExtent: function (extent) {
this._originalScale.unionExtent(extent);
var base = this.base;
extent[0] = mathLog(extent[0]) / mathLog(base);
extent[1] = mathLog(extent[1]) / mathLog(base);
scaleProto.unionExtent.call(this, extent);
},
/**
* @override
*/
unionExtentFromData: function (data, dim) {
// TODO
// filter value that <= 0
this.unionExtent(data.getApproximateExtent(dim));
},
/**
* Update interval and extent of intervals for nice ticks
* @param {number} [approxTickNum = 10] Given approx tick number
*/
niceTicks: function (approxTickNum) {
approxTickNum = approxTickNum || 10;
var extent = this._extent;
var span = extent[1] - extent[0];
if (span === Infinity || span <= 0) {
return;
}
var interval = numberUtil.quantity(span);
var err = approxTickNum / span * interval; // Filter ticks to get closer to the desired count.
if (err <= 0.5) {
interval *= 10;
} // Interval should be integer
while (!isNaN(interval) && Math.abs(interval) < 1 && Math.abs(interval) > 0) {
interval *= 10;
}
var niceExtent = [numberUtil.round(mathCeil(extent[0] / interval) * interval), numberUtil.round(mathFloor(extent[1] / interval) * interval)];
this._interval = interval;
this._niceExtent = niceExtent;
},
/**
* Nice extent.
* @override
*/
niceExtent: function (opt) {
intervalScaleProto.niceExtent.call(this, opt);
var originalScale = this._originalScale;
originalScale.__fixMin = opt.fixMin;
originalScale.__fixMax = opt.fixMax;
}
});
zrUtil.each(['contain', 'normalize'], function (methodName) {
LogScale.prototype[methodName] = function (val) {
val = mathLog(val) / mathLog(this.base);
return scaleProto[methodName].call(this, val);
};
});
LogScale.create = function () {
return new LogScale();
};
function fixRoundingError(val, originalVal) {
return roundingErrorFix(val, getPrecisionSafe(originalVal));
}
var _default = LogScale;
module.exports = _default;

149
node_modules/echarts/lib/scale/Ordinal.js generated vendored Normal file
View File

@ -0,0 +1,149 @@
/*
* 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.
*/
var zrUtil = require("zrender/lib/core/util");
var Scale = require("./Scale");
var OrdinalMeta = require("../data/OrdinalMeta");
/*
* 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.
*/
/**
* Linear continuous scale
* @module echarts/coord/scale/Ordinal
*
* http://en.wikipedia.org/wiki/Level_of_measurement
*/
// FIXME only one data
var scaleProto = Scale.prototype;
var OrdinalScale = Scale.extend({
type: 'ordinal',
/**
* @param {module:echarts/data/OrdianlMeta|Array.<string>} ordinalMeta
*/
init: function (ordinalMeta, extent) {
// Caution: Should not use instanceof, consider ec-extensions using
// import approach to get OrdinalMeta class.
if (!ordinalMeta || zrUtil.isArray(ordinalMeta)) {
ordinalMeta = new OrdinalMeta({
categories: ordinalMeta
});
}
this._ordinalMeta = ordinalMeta;
this._extent = extent || [0, ordinalMeta.categories.length - 1];
},
parse: function (val) {
return typeof val === 'string' ? this._ordinalMeta.getOrdinal(val) // val might be float.
: Math.round(val);
},
contain: function (rank) {
rank = this.parse(rank);
return scaleProto.contain.call(this, rank) && this._ordinalMeta.categories[rank] != null;
},
/**
* Normalize given rank or name to linear [0, 1]
* @param {number|string} [val]
* @return {number}
*/
normalize: function (val) {
return scaleProto.normalize.call(this, this.parse(val));
},
scale: function (val) {
return Math.round(scaleProto.scale.call(this, val));
},
/**
* @return {Array}
*/
getTicks: function () {
var ticks = [];
var extent = this._extent;
var rank = extent[0];
while (rank <= extent[1]) {
ticks.push(rank);
rank++;
}
return ticks;
},
/**
* Get item on rank n
* @param {number} n
* @return {string}
*/
getLabel: function (n) {
if (!this.isBlank()) {
// Note that if no data, ordinalMeta.categories is an empty array.
return this._ordinalMeta.categories[n];
}
},
/**
* @return {number}
*/
count: function () {
return this._extent[1] - this._extent[0] + 1;
},
/**
* @override
*/
unionExtentFromData: function (data, dim) {
this.unionExtent(data.getApproximateExtent(dim));
},
getOrdinalMeta: function () {
return this._ordinalMeta;
},
niceTicks: zrUtil.noop,
niceExtent: zrUtil.noop
});
/**
* @return {module:echarts/scale/Time}
*/
OrdinalScale.create = function () {
return new OrdinalScale();
};
var _default = OrdinalScale;
module.exports = _default;

195
node_modules/echarts/lib/scale/Scale.js generated vendored Normal file
View File

@ -0,0 +1,195 @@
/*
* 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.
*/
var clazzUtil = require("../util/clazz");
/*
* 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.
*/
/**
* // Scale class management
* @module echarts/scale/Scale
*/
/**
* @param {Object} [setting]
*/
function Scale(setting) {
this._setting = setting || {};
/**
* Extent
* @type {Array.<number>}
* @protected
*/
this._extent = [Infinity, -Infinity];
/**
* Step is calculated in adjustExtent
* @type {Array.<number>}
* @protected
*/
this._interval = 0;
this.init && this.init.apply(this, arguments);
}
/**
* Parse input val to valid inner number.
* @param {*} val
* @return {number}
*/
Scale.prototype.parse = function (val) {
// Notice: This would be a trap here, If the implementation
// of this method depends on extent, and this method is used
// before extent set (like in dataZoom), it would be wrong.
// Nevertheless, parse does not depend on extent generally.
return val;
};
Scale.prototype.getSetting = function (name) {
return this._setting[name];
};
Scale.prototype.contain = function (val) {
var extent = this._extent;
return val >= extent[0] && val <= extent[1];
};
/**
* Normalize value to linear [0, 1], return 0.5 if extent span is 0
* @param {number} val
* @return {number}
*/
Scale.prototype.normalize = function (val) {
var extent = this._extent;
if (extent[1] === extent[0]) {
return 0.5;
}
return (val - extent[0]) / (extent[1] - extent[0]);
};
/**
* Scale normalized value
* @param {number} val
* @return {number}
*/
Scale.prototype.scale = function (val) {
var extent = this._extent;
return val * (extent[1] - extent[0]) + extent[0];
};
/**
* Set extent from data
* @param {Array.<number>} other
*/
Scale.prototype.unionExtent = function (other) {
var extent = this._extent;
other[0] < extent[0] && (extent[0] = other[0]);
other[1] > extent[1] && (extent[1] = other[1]); // not setExtent because in log axis it may transformed to power
// this.setExtent(extent[0], extent[1]);
};
/**
* Set extent from data
* @param {module:echarts/data/List} data
* @param {string} dim
*/
Scale.prototype.unionExtentFromData = function (data, dim) {
this.unionExtent(data.getApproximateExtent(dim));
};
/**
* Get extent
* @return {Array.<number>}
*/
Scale.prototype.getExtent = function () {
return this._extent.slice();
};
/**
* Set extent
* @param {number} start
* @param {number} end
*/
Scale.prototype.setExtent = function (start, end) {
var thisExtent = this._extent;
if (!isNaN(start)) {
thisExtent[0] = start;
}
if (!isNaN(end)) {
thisExtent[1] = end;
}
};
/**
* When axis extent depends on data and no data exists,
* axis ticks should not be drawn, which is named 'blank'.
*/
Scale.prototype.isBlank = function () {
return this._isBlank;
},
/**
* When axis extent depends on data and no data exists,
* axis ticks should not be drawn, which is named 'blank'.
*/
Scale.prototype.setBlank = function (isBlank) {
this._isBlank = isBlank;
};
/**
* @abstract
* @param {*} tick
* @return {string} label of the tick.
*/
Scale.prototype.getLabel = null;
clazzUtil.enableClassExtend(Scale);
clazzUtil.enableClassManagement(Scale, {
registerWhenExtend: true
});
var _default = Scale;
module.exports = _default;

243
node_modules/echarts/lib/scale/Time.js generated vendored Normal file
View File

@ -0,0 +1,243 @@
/*
* 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.
*/
var zrUtil = require("zrender/lib/core/util");
var numberUtil = require("../util/number");
var formatUtil = require("../util/format");
var scaleHelper = require("./helper");
var IntervalScale = require("./Interval");
/*
* 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.
*/
/*
* A third-party license is embeded for some of the code in this file:
* The "scaleLevels" was originally copied from "d3.js" with some
* modifications made for this project.
* (See more details in the comment on the definition of "scaleLevels" below.)
* The use of the source code of this file is also subject to the terms
* and consitions of the license of "d3.js" (BSD-3Clause, see
* </licenses/LICENSE-d3>).
*/
// [About UTC and local time zone]:
// In most cases, `number.parseDate` will treat input data string as local time
// (except time zone is specified in time string). And `format.formateTime` returns
// local time by default. option.useUTC is false by default. This design have
// concidered these common case:
// (1) Time that is persistent in server is in UTC, but it is needed to be diplayed
// in local time by default.
// (2) By default, the input data string (e.g., '2011-01-02') should be displayed
// as its original time, without any time difference.
var intervalScaleProto = IntervalScale.prototype;
var mathCeil = Math.ceil;
var mathFloor = Math.floor;
var ONE_SECOND = 1000;
var ONE_MINUTE = ONE_SECOND * 60;
var ONE_HOUR = ONE_MINUTE * 60;
var ONE_DAY = ONE_HOUR * 24; // FIXME 公用?
var bisect = function (a, x, lo, hi) {
while (lo < hi) {
var mid = lo + hi >>> 1;
if (a[mid][1] < x) {
lo = mid + 1;
} else {
hi = mid;
}
}
return lo;
};
/**
* @alias module:echarts/coord/scale/Time
* @constructor
*/
var TimeScale = IntervalScale.extend({
type: 'time',
/**
* @override
*/
getLabel: function (val) {
var stepLvl = this._stepLvl;
var date = new Date(val);
return formatUtil.formatTime(stepLvl[0], date, this.getSetting('useUTC'));
},
/**
* @override
*/
niceExtent: function (opt) {
var extent = this._extent; // If extent start and end are same, expand them
if (extent[0] === extent[1]) {
// Expand extent
extent[0] -= ONE_DAY;
extent[1] += ONE_DAY;
} // If there are no data and extent are [Infinity, -Infinity]
if (extent[1] === -Infinity && extent[0] === Infinity) {
var d = new Date();
extent[1] = +new Date(d.getFullYear(), d.getMonth(), d.getDate());
extent[0] = extent[1] - ONE_DAY;
}
this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval); // var extent = this._extent;
var interval = this._interval;
if (!opt.fixMin) {
extent[0] = numberUtil.round(mathFloor(extent[0] / interval) * interval);
}
if (!opt.fixMax) {
extent[1] = numberUtil.round(mathCeil(extent[1] / interval) * interval);
}
},
/**
* @override
*/
niceTicks: function (approxTickNum, minInterval, maxInterval) {
approxTickNum = approxTickNum || 10;
var extent = this._extent;
var span = extent[1] - extent[0];
var approxInterval = span / approxTickNum;
if (minInterval != null && approxInterval < minInterval) {
approxInterval = minInterval;
}
if (maxInterval != null && approxInterval > maxInterval) {
approxInterval = maxInterval;
}
var scaleLevelsLen = scaleLevels.length;
var idx = bisect(scaleLevels, approxInterval, 0, scaleLevelsLen);
var level = scaleLevels[Math.min(idx, scaleLevelsLen - 1)];
var interval = level[1]; // Same with interval scale if span is much larger than 1 year
if (level[0] === 'year') {
var yearSpan = span / interval; // From "Nice Numbers for Graph Labels" of Graphic Gems
// var niceYearSpan = numberUtil.nice(yearSpan, false);
var yearStep = numberUtil.nice(yearSpan / approxTickNum, true);
interval *= yearStep;
}
var timezoneOffset = this.getSetting('useUTC') ? 0 : new Date(+extent[0] || +extent[1]).getTimezoneOffset() * 60 * 1000;
var niceExtent = [Math.round(mathCeil((extent[0] - timezoneOffset) / interval) * interval + timezoneOffset), Math.round(mathFloor((extent[1] - timezoneOffset) / interval) * interval + timezoneOffset)];
scaleHelper.fixExtent(niceExtent, extent);
this._stepLvl = level; // Interval will be used in getTicks
this._interval = interval;
this._niceExtent = niceExtent;
},
parse: function (val) {
// val might be float.
return +numberUtil.parseDate(val);
}
});
zrUtil.each(['contain', 'normalize'], function (methodName) {
TimeScale.prototype[methodName] = function (val) {
return intervalScaleProto[methodName].call(this, this.parse(val));
};
});
/**
* This implementation was originally copied from "d3.js"
* <https://github.com/d3/d3/blob/b516d77fb8566b576088e73410437494717ada26/src/time/scale.js>
* with some modifications made for this program.
* See the license statement at the head of this file.
*/
var scaleLevels = [// Format interval
['hh:mm:ss', ONE_SECOND], // 1s
['hh:mm:ss', ONE_SECOND * 5], // 5s
['hh:mm:ss', ONE_SECOND * 10], // 10s
['hh:mm:ss', ONE_SECOND * 15], // 15s
['hh:mm:ss', ONE_SECOND * 30], // 30s
['hh:mm\nMM-dd', ONE_MINUTE], // 1m
['hh:mm\nMM-dd', ONE_MINUTE * 5], // 5m
['hh:mm\nMM-dd', ONE_MINUTE * 10], // 10m
['hh:mm\nMM-dd', ONE_MINUTE * 15], // 15m
['hh:mm\nMM-dd', ONE_MINUTE * 30], // 30m
['hh:mm\nMM-dd', ONE_HOUR], // 1h
['hh:mm\nMM-dd', ONE_HOUR * 2], // 2h
['hh:mm\nMM-dd', ONE_HOUR * 6], // 6h
['hh:mm\nMM-dd', ONE_HOUR * 12], // 12h
['MM-dd\nyyyy', ONE_DAY], // 1d
['MM-dd\nyyyy', ONE_DAY * 2], // 2d
['MM-dd\nyyyy', ONE_DAY * 3], // 3d
['MM-dd\nyyyy', ONE_DAY * 4], // 4d
['MM-dd\nyyyy', ONE_DAY * 5], // 5d
['MM-dd\nyyyy', ONE_DAY * 6], // 6d
['week', ONE_DAY * 7], // 7d
['MM-dd\nyyyy', ONE_DAY * 10], // 10d
['week', ONE_DAY * 14], // 2w
['week', ONE_DAY * 21], // 3w
['month', ONE_DAY * 31], // 1M
['week', ONE_DAY * 42], // 6w
['month', ONE_DAY * 62], // 2M
['week', ONE_DAY * 70], // 10w
['quarter', ONE_DAY * 95], // 3M
['month', ONE_DAY * 31 * 4], // 4M
['month', ONE_DAY * 31 * 5], // 5M
['half-year', ONE_DAY * 380 / 2], // 6M
['month', ONE_DAY * 31 * 8], // 8M
['month', ONE_DAY * 31 * 10], // 10M
['year', ONE_DAY * 380] // 1Y
];
/**
* @param {module:echarts/model/Model}
* @return {module:echarts/scale/Time}
*/
TimeScale.create = function (model) {
return new TimeScale({
useUTC: model.ecModel.get('useUTC')
});
};
var _default = TimeScale;
module.exports = _default;

104
node_modules/echarts/lib/scale/helper.js generated vendored Normal file
View File

@ -0,0 +1,104 @@
/*
* 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.
*/
var numberUtil = require("../util/number");
/*
* 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.
*/
/**
* For testable.
*/
var roundNumber = numberUtil.round;
/**
* @param {Array.<number>} extent Both extent[0] and extent[1] should be valid number.
* Should be extent[0] < extent[1].
* @param {number} splitNumber splitNumber should be >= 1.
* @param {number} [minInterval]
* @param {number} [maxInterval]
* @return {Object} {interval, intervalPrecision, niceTickExtent}
*/
function intervalScaleNiceTicks(extent, splitNumber, minInterval, maxInterval) {
var result = {};
var span = extent[1] - extent[0];
var interval = result.interval = numberUtil.nice(span / splitNumber, true);
if (minInterval != null && interval < minInterval) {
interval = result.interval = minInterval;
}
if (maxInterval != null && interval > maxInterval) {
interval = result.interval = maxInterval;
} // Tow more digital for tick.
var precision = result.intervalPrecision = getIntervalPrecision(interval); // Niced extent inside original extent
var niceTickExtent = result.niceTickExtent = [roundNumber(Math.ceil(extent[0] / interval) * interval, precision), roundNumber(Math.floor(extent[1] / interval) * interval, precision)];
fixExtent(niceTickExtent, extent);
return result;
}
/**
* @param {number} interval
* @return {number} interval precision
*/
function getIntervalPrecision(interval) {
// Tow more digital for tick.
return numberUtil.getPrecisionSafe(interval) + 2;
}
function clamp(niceTickExtent, idx, extent) {
niceTickExtent[idx] = Math.max(Math.min(niceTickExtent[idx], extent[1]), extent[0]);
} // In some cases (e.g., splitNumber is 1), niceTickExtent may be out of extent.
function fixExtent(niceTickExtent, extent) {
!isFinite(niceTickExtent[0]) && (niceTickExtent[0] = extent[0]);
!isFinite(niceTickExtent[1]) && (niceTickExtent[1] = extent[1]);
clamp(niceTickExtent, 0, extent);
clamp(niceTickExtent, 1, extent);
if (niceTickExtent[0] > niceTickExtent[1]) {
niceTickExtent[0] = niceTickExtent[1];
}
}
exports.intervalScaleNiceTicks = intervalScaleNiceTicks;
exports.getIntervalPrecision = getIntervalPrecision;
exports.fixExtent = fixExtent;