逐步完成前后端服务器

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,166 @@
/*
* 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.
*/
/* global Uint8ClampedArray */
import { platformApi } from 'zrender/lib/core/platform.js';
var GRADIENT_LEVELS = 256;
var HeatmapLayer = /** @class */function () {
function HeatmapLayer() {
this.blurSize = 30;
this.pointSize = 20;
this.maxOpacity = 1;
this.minOpacity = 0;
this._gradientPixels = {
inRange: null,
outOfRange: null
};
var canvas = platformApi.createCanvas();
this.canvas = canvas;
}
/**
* Renders Heatmap and returns the rendered canvas
* @param data array of data, each has x, y, value
* @param width canvas width
* @param height canvas height
*/
HeatmapLayer.prototype.update = function (data, width, height, normalize, colorFunc, isInRange) {
var brush = this._getBrush();
var gradientInRange = this._getGradient(colorFunc, 'inRange');
var gradientOutOfRange = this._getGradient(colorFunc, 'outOfRange');
var r = this.pointSize + this.blurSize;
var canvas = this.canvas;
var ctx = canvas.getContext('2d');
var len = data.length;
canvas.width = width;
canvas.height = height;
for (var i = 0; i < len; ++i) {
var p = data[i];
var x = p[0];
var y = p[1];
var value = p[2];
// calculate alpha using value
var alpha = normalize(value);
// draw with the circle brush with alpha
ctx.globalAlpha = alpha;
ctx.drawImage(brush, x - r, y - r);
}
if (!canvas.width || !canvas.height) {
// Avoid "Uncaught DOMException: Failed to execute 'getImageData' on
// 'CanvasRenderingContext2D': The source height is 0."
return canvas;
}
// colorize the canvas using alpha value and set with gradient
var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
var pixels = imageData.data;
var offset = 0;
var pixelLen = pixels.length;
var minOpacity = this.minOpacity;
var maxOpacity = this.maxOpacity;
var diffOpacity = maxOpacity - minOpacity;
while (offset < pixelLen) {
var alpha = pixels[offset + 3] / 256;
var gradientOffset = Math.floor(alpha * (GRADIENT_LEVELS - 1)) * 4;
// Simple optimize to ignore the empty data
if (alpha > 0) {
var gradient = isInRange(alpha) ? gradientInRange : gradientOutOfRange;
// Any alpha > 0 will be mapped to [minOpacity, maxOpacity]
alpha > 0 && (alpha = alpha * diffOpacity + minOpacity);
pixels[offset++] = gradient[gradientOffset];
pixels[offset++] = gradient[gradientOffset + 1];
pixels[offset++] = gradient[gradientOffset + 2];
pixels[offset++] = gradient[gradientOffset + 3] * alpha * 256;
} else {
offset += 4;
}
}
ctx.putImageData(imageData, 0, 0);
return canvas;
};
/**
* get canvas of a black circle brush used for canvas to draw later
*/
HeatmapLayer.prototype._getBrush = function () {
var brushCanvas = this._brushCanvas || (this._brushCanvas = platformApi.createCanvas());
// set brush size
var r = this.pointSize + this.blurSize;
var d = r * 2;
brushCanvas.width = d;
brushCanvas.height = d;
var ctx = brushCanvas.getContext('2d');
ctx.clearRect(0, 0, d, d);
// in order to render shadow without the distinct circle,
// draw the distinct circle in an invisible place,
// and use shadowOffset to draw shadow in the center of the canvas
ctx.shadowOffsetX = d;
ctx.shadowBlur = this.blurSize;
// draw the shadow in black, and use alpha and shadow blur to generate
// color in color map
ctx.shadowColor = '#000';
// draw circle in the left to the canvas
ctx.beginPath();
ctx.arc(-r, r, this.pointSize, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fill();
return brushCanvas;
};
/**
* get gradient color map
* @private
*/
HeatmapLayer.prototype._getGradient = function (colorFunc, state) {
var gradientPixels = this._gradientPixels;
var pixelsSingleState = gradientPixels[state] || (gradientPixels[state] = new Uint8ClampedArray(256 * 4));
var color = [0, 0, 0, 0];
var off = 0;
for (var i = 0; i < 256; i++) {
colorFunc[state](i / 255, true, color);
pixelsSingleState[off++] = color[0];
pixelsSingleState[off++] = color[1];
pixelsSingleState[off++] = color[2];
pixelsSingleState[off++] = color[3];
}
return pixelsSingleState;
};
return HeatmapLayer;
}();
export default HeatmapLayer;

View File

@ -0,0 +1,89 @@
/*
* 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 SeriesModel from '../../model/Series.js';
import createSeriesData from '../helper/createSeriesData.js';
import CoordinateSystem from '../../core/CoordinateSystem.js';
var HeatmapSeriesModel = /** @class */function (_super) {
__extends(HeatmapSeriesModel, _super);
function HeatmapSeriesModel() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.type = HeatmapSeriesModel.type;
return _this;
}
HeatmapSeriesModel.prototype.getInitialData = function (option, ecModel) {
return createSeriesData(null, this, {
generateCoord: 'value'
});
};
HeatmapSeriesModel.prototype.preventIncremental = function () {
var coordSysCreator = CoordinateSystem.get(this.get('coordinateSystem'));
if (coordSysCreator && coordSysCreator.dimensions) {
return coordSysCreator.dimensions[0] === 'lng' && coordSysCreator.dimensions[1] === 'lat';
}
};
HeatmapSeriesModel.type = 'series.heatmap';
HeatmapSeriesModel.dependencies = ['grid', 'geo', 'calendar'];
HeatmapSeriesModel.defaultOption = {
coordinateSystem: 'cartesian2d',
// zlevel: 0,
z: 2,
// Cartesian coordinate system
// xAxisIndex: 0,
// yAxisIndex: 0,
// Geo coordinate system
geoIndex: 0,
blurSize: 30,
pointSize: 20,
maxOpacity: 1,
minOpacity: 0,
select: {
itemStyle: {
borderColor: '#212121'
}
}
};
return HeatmapSeriesModel;
}(SeriesModel);
export default HeatmapSeriesModel;

View File

@ -0,0 +1,310 @@
/*
* 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 graphic from '../../util/graphic.js';
import { toggleHoverEmphasis } from '../../util/states.js';
import HeatmapLayer from './HeatmapLayer.js';
import * as zrUtil from 'zrender/lib/core/util.js';
import ChartView from '../../view/Chart.js';
import { isCoordinateSystemType } from '../../coord/CoordinateSystem.js';
import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle.js';
function getIsInPiecewiseRange(dataExtent, pieceList, selected) {
var dataSpan = dataExtent[1] - dataExtent[0];
pieceList = zrUtil.map(pieceList, function (piece) {
return {
interval: [(piece.interval[0] - dataExtent[0]) / dataSpan, (piece.interval[1] - dataExtent[0]) / dataSpan]
};
});
var len = pieceList.length;
var lastIndex = 0;
return function (val) {
var i;
// Try to find in the location of the last found
for (i = lastIndex; i < len; i++) {
var interval = pieceList[i].interval;
if (interval[0] <= val && val <= interval[1]) {
lastIndex = i;
break;
}
}
if (i === len) {
// Not found, back interation
for (i = lastIndex - 1; i >= 0; i--) {
var interval = pieceList[i].interval;
if (interval[0] <= val && val <= interval[1]) {
lastIndex = i;
break;
}
}
}
return i >= 0 && i < len && selected[i];
};
}
function getIsInContinuousRange(dataExtent, range) {
var dataSpan = dataExtent[1] - dataExtent[0];
range = [(range[0] - dataExtent[0]) / dataSpan, (range[1] - dataExtent[0]) / dataSpan];
return function (val) {
return val >= range[0] && val <= range[1];
};
}
function isGeoCoordSys(coordSys) {
var dimensions = coordSys.dimensions;
// Not use coordSys.type === 'geo' because coordSys maybe extended
return dimensions[0] === 'lng' && dimensions[1] === 'lat';
}
var HeatmapView = /** @class */function (_super) {
__extends(HeatmapView, _super);
function HeatmapView() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.type = HeatmapView.type;
return _this;
}
HeatmapView.prototype.render = function (seriesModel, ecModel, api) {
var visualMapOfThisSeries;
ecModel.eachComponent('visualMap', function (visualMap) {
visualMap.eachTargetSeries(function (targetSeries) {
if (targetSeries === seriesModel) {
visualMapOfThisSeries = visualMap;
}
});
});
if (process.env.NODE_ENV !== 'production') {
if (!visualMapOfThisSeries) {
throw new Error('Heatmap must use with visualMap');
}
}
// Clear previously rendered progressive elements.
this._progressiveEls = null;
this.group.removeAll();
var coordSys = seriesModel.coordinateSystem;
if (coordSys.type === 'cartesian2d' || coordSys.type === 'calendar') {
this._renderOnCartesianAndCalendar(seriesModel, api, 0, seriesModel.getData().count());
} else if (isGeoCoordSys(coordSys)) {
this._renderOnGeo(coordSys, seriesModel, visualMapOfThisSeries, api);
}
};
HeatmapView.prototype.incrementalPrepareRender = function (seriesModel, ecModel, api) {
this.group.removeAll();
};
HeatmapView.prototype.incrementalRender = function (params, seriesModel, ecModel, api) {
var coordSys = seriesModel.coordinateSystem;
if (coordSys) {
// geo does not support incremental rendering?
if (isGeoCoordSys(coordSys)) {
this.render(seriesModel, ecModel, api);
} else {
this._progressiveEls = [];
this._renderOnCartesianAndCalendar(seriesModel, api, params.start, params.end, true);
}
}
};
HeatmapView.prototype.eachRendered = function (cb) {
graphic.traverseElements(this._progressiveEls || this.group, cb);
};
HeatmapView.prototype._renderOnCartesianAndCalendar = function (seriesModel, api, start, end, incremental) {
var coordSys = seriesModel.coordinateSystem;
var isCartesian2d = isCoordinateSystemType(coordSys, 'cartesian2d');
var width;
var height;
var xAxisExtent;
var yAxisExtent;
if (isCartesian2d) {
var xAxis = coordSys.getAxis('x');
var yAxis = coordSys.getAxis('y');
if (process.env.NODE_ENV !== 'production') {
if (!(xAxis.type === 'category' && yAxis.type === 'category')) {
throw new Error('Heatmap on cartesian must have two category axes');
}
if (!(xAxis.onBand && yAxis.onBand)) {
throw new Error('Heatmap on cartesian must have two axes with boundaryGap true');
}
}
// add 0.5px to avoid the gaps
width = xAxis.getBandWidth() + .5;
height = yAxis.getBandWidth() + .5;
xAxisExtent = xAxis.scale.getExtent();
yAxisExtent = yAxis.scale.getExtent();
}
var group = this.group;
var data = seriesModel.getData();
var emphasisStyle = seriesModel.getModel(['emphasis', 'itemStyle']).getItemStyle();
var blurStyle = seriesModel.getModel(['blur', 'itemStyle']).getItemStyle();
var selectStyle = seriesModel.getModel(['select', 'itemStyle']).getItemStyle();
var borderRadius = seriesModel.get(['itemStyle', 'borderRadius']);
var labelStatesModels = getLabelStatesModels(seriesModel);
var emphasisModel = seriesModel.getModel('emphasis');
var focus = emphasisModel.get('focus');
var blurScope = emphasisModel.get('blurScope');
var emphasisDisabled = emphasisModel.get('disabled');
var dataDims = isCartesian2d ? [data.mapDimension('x'), data.mapDimension('y'), data.mapDimension('value')] : [data.mapDimension('time'), data.mapDimension('value')];
for (var idx = start; idx < end; idx++) {
var rect = void 0;
var style = data.getItemVisual(idx, 'style');
if (isCartesian2d) {
var dataDimX = data.get(dataDims[0], idx);
var dataDimY = data.get(dataDims[1], idx);
// Ignore empty data and out of extent data
if (isNaN(data.get(dataDims[2], idx)) || isNaN(dataDimX) || isNaN(dataDimY) || dataDimX < xAxisExtent[0] || dataDimX > xAxisExtent[1] || dataDimY < yAxisExtent[0] || dataDimY > yAxisExtent[1]) {
continue;
}
var point = coordSys.dataToPoint([dataDimX, dataDimY]);
rect = new graphic.Rect({
shape: {
x: point[0] - width / 2,
y: point[1] - height / 2,
width: width,
height: height
},
style: style
});
} else {
// Ignore empty data
if (isNaN(data.get(dataDims[1], idx))) {
continue;
}
rect = new graphic.Rect({
z2: 1,
shape: coordSys.dataToRect([data.get(dataDims[0], idx)]).contentShape,
style: style
});
}
// Optimization for large dataset
if (data.hasItemOption) {
var itemModel = data.getItemModel(idx);
var emphasisModel_1 = itemModel.getModel('emphasis');
emphasisStyle = emphasisModel_1.getModel('itemStyle').getItemStyle();
blurStyle = itemModel.getModel(['blur', 'itemStyle']).getItemStyle();
selectStyle = itemModel.getModel(['select', 'itemStyle']).getItemStyle();
// Each item value struct in the data would be firstly
// {
// itemStyle: { borderRadius: [30, 30] },
// value: [2022, 02, 22]
// }
borderRadius = itemModel.get(['itemStyle', 'borderRadius']);
focus = emphasisModel_1.get('focus');
blurScope = emphasisModel_1.get('blurScope');
emphasisDisabled = emphasisModel_1.get('disabled');
labelStatesModels = getLabelStatesModels(itemModel);
}
rect.shape.r = borderRadius;
var rawValue = seriesModel.getRawValue(idx);
var defaultText = '-';
if (rawValue && rawValue[2] != null) {
defaultText = rawValue[2] + '';
}
setLabelStyle(rect, labelStatesModels, {
labelFetcher: seriesModel,
labelDataIndex: idx,
defaultOpacity: style.opacity,
defaultText: defaultText
});
rect.ensureState('emphasis').style = emphasisStyle;
rect.ensureState('blur').style = blurStyle;
rect.ensureState('select').style = selectStyle;
toggleHoverEmphasis(rect, focus, blurScope, emphasisDisabled);
rect.incremental = incremental;
// PENDING
if (incremental) {
// Rect must use hover layer if it's incremental.
rect.states.emphasis.hoverLayer = true;
}
group.add(rect);
data.setItemGraphicEl(idx, rect);
if (this._progressiveEls) {
this._progressiveEls.push(rect);
}
}
};
HeatmapView.prototype._renderOnGeo = function (geo, seriesModel, visualMapModel, api) {
var inRangeVisuals = visualMapModel.targetVisuals.inRange;
var outOfRangeVisuals = visualMapModel.targetVisuals.outOfRange;
// if (!visualMapping) {
// throw new Error('Data range must have color visuals');
// }
var data = seriesModel.getData();
var hmLayer = this._hmLayer || this._hmLayer || new HeatmapLayer();
hmLayer.blurSize = seriesModel.get('blurSize');
hmLayer.pointSize = seriesModel.get('pointSize');
hmLayer.minOpacity = seriesModel.get('minOpacity');
hmLayer.maxOpacity = seriesModel.get('maxOpacity');
var rect = geo.getViewRect().clone();
var roamTransform = geo.getRoamTransform();
rect.applyTransform(roamTransform);
// Clamp on viewport
var x = Math.max(rect.x, 0);
var y = Math.max(rect.y, 0);
var x2 = Math.min(rect.width + rect.x, api.getWidth());
var y2 = Math.min(rect.height + rect.y, api.getHeight());
var width = x2 - x;
var height = y2 - y;
var dims = [data.mapDimension('lng'), data.mapDimension('lat'), data.mapDimension('value')];
var points = data.mapArray(dims, function (lng, lat, value) {
var pt = geo.dataToPoint([lng, lat]);
pt[0] -= x;
pt[1] -= y;
pt.push(value);
return pt;
});
var dataExtent = visualMapModel.getExtent();
var isInRange = visualMapModel.type === 'visualMap.continuous' ? getIsInContinuousRange(dataExtent, visualMapModel.option.range) : getIsInPiecewiseRange(dataExtent, visualMapModel.getPieceList(), visualMapModel.option.selected);
hmLayer.update(points, width, height, inRangeVisuals.color.getNormalizer(), {
inRange: inRangeVisuals.color.getColorMapper(),
outOfRange: outOfRangeVisuals.color.getColorMapper()
}, isInRange);
var img = new graphic.Image({
style: {
width: width,
height: height,
x: x,
y: y,
image: hmLayer.canvas
},
silent: true
});
this.group.add(img);
};
HeatmapView.type = 'heatmap';
return HeatmapView;
}(ChartView);
export default HeatmapView;

View File

@ -0,0 +1,49 @@
/*
* 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 HeatmapView from './HeatmapView.js';
import HeatmapSeriesModel from './HeatmapSeries.js';
export function install(registers) {
registers.registerChartView(HeatmapView);
registers.registerSeriesModel(HeatmapSeriesModel);
}