Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ssr): add server-side rendering #15880

Merged
merged 17 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions build/dev-fast.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@

const path = require('path');
const {build} = require('esbuild');

const commander = require('commander');
const outFilePath = path.resolve(__dirname, '../dist/echarts.js');

const umdMark = '// ------------- WRAPPED UMD --------------- //';
const umdWrapperHead = `
${umdMark}
(function (root, factory) {
window.__DEV__ = true;
const umdWrapperHead = `(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['exports'], factory);
Expand All @@ -52,15 +48,20 @@ build({
bundle: true,
banner: umdWrapperHead,
footer: umdWrapperTail,
define: {
'process.env.NODE_ENV': '"development"',
'__DEV__': 'true'
},
watch: {
async onRebuild(error) {
if (error) {
console.error('watch build failed:', error)
} else {
console.log('build done')
}
else {
console.log('Bundled with esbuild')
}
},
},
}).then(async () => {
console.log('build done')
console.log('Bundled with esbuild')
}).catch(e => console.error(e.toString()))
6 changes: 3 additions & 3 deletions build/source-release/template/announce-release.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ The Apache ECharts team is proud to announce Apache ECharts {{ECHARTS_RELEASE_VE

Apache ECharts is a powerful, interactive charting and data visualization library for browser.

Download Links: https://dist.apache.org/repos/dist/release/echarts/{{ECHARTS_RELEASE_VERSION}}/
Download Links: https://echarts.apache.org/download.html

Release Notes: http:https://www.apache.org/dist/echarts/{{ECHARTS_RELEASE_VERSION}}/RELEASE_NOTE.txt
Release Notes: https:https://echarts.apache.org/changelog.html

Website: http:https://echarts.apache.org/
Website: https:https://echarts.apache.org/


ECharts Resources:
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
},
"dependencies": {
"tslib": "2.3.0",
"zrender": "5.2.1"
"zrender": "npm:zrender-nightly@^5.3.0-dev.20211015"
},
"devDependencies": {
"@babel/code-frame": "7.10.4",
Expand Down Expand Up @@ -106,6 +106,6 @@
"socket.io": "2.2.0",
"terser": "^5.3.8",
"ts-jest": "^26.4.3",
"typescript": "4.3.5"
"typescript": "4.4.3"
}
}
6 changes: 3 additions & 3 deletions src/chart/heatmap/HeatmapLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/* global Uint8ClampedArray */

import * as zrUtil from 'zrender/src/core/util';
import { platformApi } from 'zrender/src/core/platform';

const GRADIENT_LEVELS = 256;

Expand All @@ -43,7 +43,7 @@ class HeatmapLayer {
};

constructor() {
const canvas = zrUtil.createCanvas();
const canvas = platformApi.createCanvas();
this.canvas = canvas;
}

Expand Down Expand Up @@ -127,7 +127,7 @@ class HeatmapLayer {
* get canvas of a black circle brush used for canvas to draw later
*/
_getBrush() {
const brushCanvas = this._brushCanvas || (this._brushCanvas = zrUtil.createCanvas());
const brushCanvas = this._brushCanvas || (this._brushCanvas = platformApi.createCanvas());
// set brush size
const r = this.pointSize + this.blurSize;
const d = r * 2;
Expand Down
12 changes: 11 additions & 1 deletion src/chart/pie/PieView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,17 @@ class PiePiece extends graphic.Sector {
sector.setShape(sectorShape);

const animationType = seriesModel.getShallow('animationType');
if (animationType === 'scale') {
if (seriesModel.ecModel.ssr) {
// Use scale animation in SSR mode(opacity?)
// Because CSS SVG animation doesn't support very customized shape animation.
graphic.initProps(sector, {
scaleX: 0,
scaleY: 0
}, seriesModel, { dataIndex: idx, isFrom: true});
sector.originX = sectorShape.cx;
sector.originY = sectorShape.cy;
}
else if (animationType === 'scale') {
sector.shape.r = layout.r0;
graphic.initProps(sector, {
shape: {
Expand Down
4 changes: 0 additions & 4 deletions src/component/dataZoom/DataZoomModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,6 @@ class DataZoomModel<Opts extends DataZoomOption = DataZoomOption> extends Compon
private _doInit(inputRawOption: Opts): void {
const thisOption = this.option;

// if (!env.canvasSupported) {
// thisOption.realtime = false;
// }

this._setDefaultThrottle(inputRawOption);

this._updateRangeUse(inputRawOption);
Expand Down
6 changes: 3 additions & 3 deletions src/component/toolbox/feature/SaveAsImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class SaveAsImage extends ToolboxFeature<ToolboxSaveAsImageFeatureOption> {
}
// IE or old Edge
else {
// @ts-ignore
if (window.navigator.msSaveOrOpenBlob || isSvg) {
const parts = url.split(',');
// data:[<mime type>][;charset=<charset>][;base64],<encoded data>
Expand All @@ -88,13 +89,14 @@ class SaveAsImage extends ToolboxFeature<ToolboxSaveAsImageFeatureOption> {
// (just a url-encoded string through `encodeURIComponent`)
base64Encoded && (bstr = window.atob(bstr));
const filename = title + '.' + type;
// @ts-ignore
if (window.navigator.msSaveOrOpenBlob) {
let n = bstr.length;
const u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
const blob = new Blob([u8arr]);
const blob = new Blob([u8arr]);// @ts-ignore
window.navigator.msSaveOrOpenBlob(blob, filename);
}
else {
Expand Down Expand Up @@ -143,6 +145,4 @@ class SaveAsImage extends ToolboxFeature<ToolboxSaveAsImageFeatureOption> {
}
}

SaveAsImage.prototype.unusable = !env.canvasSupported;

export default SaveAsImage;
11 changes: 1 addition & 10 deletions src/component/tooltip/TooltipHTMLContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,7 @@ function assembleCssText(tooltipModel: Model<TooltipOption>, enableTransition?:
enableTransition && transitionDuration && cssText.push(assembleTransition(transitionDuration, onlyFade));

if (backgroundColor) {
if (env.canvasSupported) {
cssText.push('background-color:' + backgroundColor);
}
else {
// for ie
cssText.push(
'background-color:#' + toHex(backgroundColor)
);
cssText.push('filter:alpha(opacity=70)');
}
cssText.push('background-color:' + backgroundColor);
}

// Border style
Expand Down
8 changes: 4 additions & 4 deletions src/component/tooltip/TooltipView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class TooltipView extends ComponentView {
private _updatePosition: ReturnType<typeof throttle> | TooltipView['_doUpdatePosition'];

init(ecModel: GlobalModel, api: ExtensionAPI) {
if (env.node) {
if (env.node || !api.getDom()) {
return;
}

Expand All @@ -191,7 +191,7 @@ class TooltipView extends ComponentView {
ecModel: GlobalModel,
api: ExtensionAPI
) {
if (env.node) {
if (env.node || !api.getDom()) {
return;
}

Expand Down Expand Up @@ -301,7 +301,7 @@ class TooltipView extends ComponentView {
api: ExtensionAPI,
payload: ShowTipPayload
) {
if (payload.from === this.uid || env.node) {
if (payload.from === this.uid || env.node || !api.getDom()) {
return;
}

Expand Down Expand Up @@ -1013,7 +1013,7 @@ class TooltipView extends ComponentView {
}

dispose(ecModel: GlobalModel, api: ExtensionAPI) {
if (env.node) {
if (env.node || !api.getDom()) {
return;
}
this._tooltipContent.dispose();
Expand Down
7 changes: 0 additions & 7 deletions src/component/visualMap/VisualMapModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,6 @@ class VisualMapModel<Opts extends VisualMapOption = VisualMapOption> extends Com
optionUpdated(newOption: Opts, isInit?: boolean) {
const thisOption = this.option;

// FIXME
// necessary?
// Disable realtime view update if canvas is not supported.
if (!env.canvasSupported) {
thisOption.realtime = false;
}

!isInit && visualSolution.replaceVisualOption(
thisOption, newOption, this.replacableOptionKeys
);
Expand Down
1 change: 1 addition & 0 deletions src/core/ExtensionAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const availableMethods: (keyof EChartsType)[] = [
'getHeight',
'getDevicePixelRatio',
'dispatchAction',
'isSSR',
'isDisposed',
'on',
'off',
Expand Down
Loading