逐步完成前后端服务器
This commit is contained in:
260
frontend/node_modules/echarts/lib/chart/themeRiver/ThemeRiverSeries.js
generated
vendored
Normal file
260
frontend/node_modules/echarts/lib/chart/themeRiver/ThemeRiverSeries.js
generated
vendored
Normal file
@ -0,0 +1,260 @@
|
||||
|
||||
/*
|
||||
* 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 prepareSeriesDataSchema from '../../data/helper/createDimensions.js';
|
||||
import { getDimensionTypeByAxis } from '../../data/helper/dimensionHelper.js';
|
||||
import SeriesData from '../../data/SeriesData.js';
|
||||
import * as zrUtil from 'zrender/lib/core/util.js';
|
||||
import { groupData, SINGLE_REFERRING } from '../../util/model.js';
|
||||
import LegendVisualProvider from '../../visual/LegendVisualProvider.js';
|
||||
import { createTooltipMarkup } from '../../component/tooltip/tooltipMarkup.js';
|
||||
var DATA_NAME_INDEX = 2;
|
||||
var ThemeRiverSeriesModel = /** @class */function (_super) {
|
||||
__extends(ThemeRiverSeriesModel, _super);
|
||||
function ThemeRiverSeriesModel() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.type = ThemeRiverSeriesModel.type;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
ThemeRiverSeriesModel.prototype.init = function (option) {
|
||||
// eslint-disable-next-line
|
||||
_super.prototype.init.apply(this, arguments);
|
||||
// Put this function here is for the sake of consistency of code style.
|
||||
// Enable legend selection for each data item
|
||||
// Use a function instead of direct access because data reference may changed
|
||||
this.legendVisualProvider = new LegendVisualProvider(zrUtil.bind(this.getData, this), zrUtil.bind(this.getRawData, this));
|
||||
};
|
||||
/**
|
||||
* If there is no value of a certain point in the time for some event,set it value to 0.
|
||||
*
|
||||
* @param {Array} data initial data in the option
|
||||
* @return {Array}
|
||||
*/
|
||||
ThemeRiverSeriesModel.prototype.fixData = function (data) {
|
||||
var rawDataLength = data.length;
|
||||
/**
|
||||
* Make sure every layer data get the same keys.
|
||||
* The value index tells which layer has visited.
|
||||
* {
|
||||
* 2014/01/01: -1
|
||||
* }
|
||||
*/
|
||||
var timeValueKeys = {};
|
||||
// grouped data by name
|
||||
var groupResult = groupData(data, function (item) {
|
||||
if (!timeValueKeys.hasOwnProperty(item[0] + '')) {
|
||||
timeValueKeys[item[0] + ''] = -1;
|
||||
}
|
||||
return item[2];
|
||||
});
|
||||
var layerData = [];
|
||||
groupResult.buckets.each(function (items, key) {
|
||||
layerData.push({
|
||||
name: key,
|
||||
dataList: items
|
||||
});
|
||||
});
|
||||
var layerNum = layerData.length;
|
||||
for (var k = 0; k < layerNum; ++k) {
|
||||
var name_1 = layerData[k].name;
|
||||
for (var j = 0; j < layerData[k].dataList.length; ++j) {
|
||||
var timeValue = layerData[k].dataList[j][0] + '';
|
||||
timeValueKeys[timeValue] = k;
|
||||
}
|
||||
for (var timeValue in timeValueKeys) {
|
||||
if (timeValueKeys.hasOwnProperty(timeValue) && timeValueKeys[timeValue] !== k) {
|
||||
timeValueKeys[timeValue] = k;
|
||||
data[rawDataLength] = [timeValue, 0, name_1];
|
||||
rawDataLength++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
};
|
||||
/**
|
||||
* @override
|
||||
* @param option the initial option that user gave
|
||||
* @param ecModel the model object for themeRiver option
|
||||
*/
|
||||
ThemeRiverSeriesModel.prototype.getInitialData = function (option, ecModel) {
|
||||
var singleAxisModel = this.getReferringComponents('singleAxis', SINGLE_REFERRING).models[0];
|
||||
var axisType = singleAxisModel.get('type');
|
||||
// filter the data item with the value of label is undefined
|
||||
var filterData = zrUtil.filter(option.data, function (dataItem) {
|
||||
return dataItem[2] !== undefined;
|
||||
});
|
||||
// ??? TODO design a stage to transfer data for themeRiver and lines?
|
||||
var data = this.fixData(filterData || []);
|
||||
var nameList = [];
|
||||
var nameMap = this.nameMap = zrUtil.createHashMap();
|
||||
var count = 0;
|
||||
for (var i = 0; i < data.length; ++i) {
|
||||
nameList.push(data[i][DATA_NAME_INDEX]);
|
||||
if (!nameMap.get(data[i][DATA_NAME_INDEX])) {
|
||||
nameMap.set(data[i][DATA_NAME_INDEX], count);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
var dimensions = prepareSeriesDataSchema(data, {
|
||||
coordDimensions: ['single'],
|
||||
dimensionsDefine: [{
|
||||
name: 'time',
|
||||
type: getDimensionTypeByAxis(axisType)
|
||||
}, {
|
||||
name: 'value',
|
||||
type: 'float'
|
||||
}, {
|
||||
name: 'name',
|
||||
type: 'ordinal'
|
||||
}],
|
||||
encodeDefine: {
|
||||
single: 0,
|
||||
value: 1,
|
||||
itemName: 2
|
||||
}
|
||||
}).dimensions;
|
||||
var list = new SeriesData(dimensions, this);
|
||||
list.initData(data);
|
||||
return list;
|
||||
};
|
||||
/**
|
||||
* The raw data is divided into multiple layers and each layer
|
||||
* has same name.
|
||||
*/
|
||||
ThemeRiverSeriesModel.prototype.getLayerSeries = function () {
|
||||
var data = this.getData();
|
||||
var lenCount = data.count();
|
||||
var indexArr = [];
|
||||
for (var i = 0; i < lenCount; ++i) {
|
||||
indexArr[i] = i;
|
||||
}
|
||||
var timeDim = data.mapDimension('single');
|
||||
// data group by name
|
||||
var groupResult = groupData(indexArr, function (index) {
|
||||
return data.get('name', index);
|
||||
});
|
||||
var layerSeries = [];
|
||||
groupResult.buckets.each(function (items, key) {
|
||||
items.sort(function (index1, index2) {
|
||||
return data.get(timeDim, index1) - data.get(timeDim, index2);
|
||||
});
|
||||
layerSeries.push({
|
||||
name: key,
|
||||
indices: items
|
||||
});
|
||||
});
|
||||
return layerSeries;
|
||||
};
|
||||
/**
|
||||
* Get data indices for show tooltip content
|
||||
*/
|
||||
ThemeRiverSeriesModel.prototype.getAxisTooltipData = function (dim, value, baseAxis) {
|
||||
if (!zrUtil.isArray(dim)) {
|
||||
dim = dim ? [dim] : [];
|
||||
}
|
||||
var data = this.getData();
|
||||
var layerSeries = this.getLayerSeries();
|
||||
var indices = [];
|
||||
var layerNum = layerSeries.length;
|
||||
var nestestValue;
|
||||
for (var i = 0; i < layerNum; ++i) {
|
||||
var minDist = Number.MAX_VALUE;
|
||||
var nearestIdx = -1;
|
||||
var pointNum = layerSeries[i].indices.length;
|
||||
for (var j = 0; j < pointNum; ++j) {
|
||||
var theValue = data.get(dim[0], layerSeries[i].indices[j]);
|
||||
var dist = Math.abs(theValue - value);
|
||||
if (dist <= minDist) {
|
||||
nestestValue = theValue;
|
||||
minDist = dist;
|
||||
nearestIdx = layerSeries[i].indices[j];
|
||||
}
|
||||
}
|
||||
indices.push(nearestIdx);
|
||||
}
|
||||
return {
|
||||
dataIndices: indices,
|
||||
nestestValue: nestestValue
|
||||
};
|
||||
};
|
||||
ThemeRiverSeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
|
||||
var data = this.getData();
|
||||
var name = data.getName(dataIndex);
|
||||
var value = data.get(data.mapDimension('value'), dataIndex);
|
||||
return createTooltipMarkup('nameValue', {
|
||||
name: name,
|
||||
value: value
|
||||
});
|
||||
};
|
||||
ThemeRiverSeriesModel.type = 'series.themeRiver';
|
||||
ThemeRiverSeriesModel.dependencies = ['singleAxis'];
|
||||
ThemeRiverSeriesModel.defaultOption = {
|
||||
// zlevel: 0,
|
||||
z: 2,
|
||||
colorBy: 'data',
|
||||
coordinateSystem: 'singleAxis',
|
||||
// gap in axis's orthogonal orientation
|
||||
boundaryGap: ['10%', '10%'],
|
||||
// legendHoverLink: true,
|
||||
singleAxisIndex: 0,
|
||||
animationEasing: 'linear',
|
||||
label: {
|
||||
margin: 4,
|
||||
show: true,
|
||||
position: 'left',
|
||||
fontSize: 11
|
||||
},
|
||||
emphasis: {
|
||||
label: {
|
||||
show: true
|
||||
}
|
||||
}
|
||||
};
|
||||
return ThemeRiverSeriesModel;
|
||||
}(SeriesModel);
|
||||
export default ThemeRiverSeriesModel;
|
185
frontend/node_modules/echarts/lib/chart/themeRiver/ThemeRiverView.js
generated
vendored
Normal file
185
frontend/node_modules/echarts/lib/chart/themeRiver/ThemeRiverView.js
generated
vendored
Normal file
@ -0,0 +1,185 @@
|
||||
|
||||
/*
|
||||
* 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 { ECPolygon } from '../line/poly.js';
|
||||
import * as graphic from '../../util/graphic.js';
|
||||
import { setStatesStylesFromModel, toggleHoverEmphasis } from '../../util/states.js';
|
||||
import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle.js';
|
||||
import { bind } from 'zrender/lib/core/util.js';
|
||||
import DataDiffer from '../../data/DataDiffer.js';
|
||||
import ChartView from '../../view/Chart.js';
|
||||
import { saveOldStyle } from '../../animation/basicTransition.js';
|
||||
var ThemeRiverView = /** @class */function (_super) {
|
||||
__extends(ThemeRiverView, _super);
|
||||
function ThemeRiverView() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.type = ThemeRiverView.type;
|
||||
_this._layers = [];
|
||||
return _this;
|
||||
}
|
||||
ThemeRiverView.prototype.render = function (seriesModel, ecModel, api) {
|
||||
var data = seriesModel.getData();
|
||||
var self = this;
|
||||
var group = this.group;
|
||||
var layersSeries = seriesModel.getLayerSeries();
|
||||
var layoutInfo = data.getLayout('layoutInfo');
|
||||
var rect = layoutInfo.rect;
|
||||
var boundaryGap = layoutInfo.boundaryGap;
|
||||
group.x = 0;
|
||||
group.y = rect.y + boundaryGap[0];
|
||||
function keyGetter(item) {
|
||||
return item.name;
|
||||
}
|
||||
var dataDiffer = new DataDiffer(this._layersSeries || [], layersSeries, keyGetter, keyGetter);
|
||||
var newLayersGroups = [];
|
||||
dataDiffer.add(bind(process, this, 'add')).update(bind(process, this, 'update')).remove(bind(process, this, 'remove')).execute();
|
||||
function process(status, idx, oldIdx) {
|
||||
var oldLayersGroups = self._layers;
|
||||
if (status === 'remove') {
|
||||
group.remove(oldLayersGroups[idx]);
|
||||
return;
|
||||
}
|
||||
var points0 = [];
|
||||
var points1 = [];
|
||||
var style;
|
||||
var indices = layersSeries[idx].indices;
|
||||
var j = 0;
|
||||
for (; j < indices.length; j++) {
|
||||
var layout = data.getItemLayout(indices[j]);
|
||||
var x = layout.x;
|
||||
var y0 = layout.y0;
|
||||
var y = layout.y;
|
||||
points0.push(x, y0);
|
||||
points1.push(x, y0 + y);
|
||||
style = data.getItemVisual(indices[j], 'style');
|
||||
}
|
||||
var polygon;
|
||||
var textLayout = data.getItemLayout(indices[0]);
|
||||
var labelModel = seriesModel.getModel('label');
|
||||
var margin = labelModel.get('margin');
|
||||
var emphasisModel = seriesModel.getModel('emphasis');
|
||||
if (status === 'add') {
|
||||
var layerGroup = newLayersGroups[idx] = new graphic.Group();
|
||||
polygon = new ECPolygon({
|
||||
shape: {
|
||||
points: points0,
|
||||
stackedOnPoints: points1,
|
||||
smooth: 0.4,
|
||||
stackedOnSmooth: 0.4,
|
||||
smoothConstraint: false
|
||||
},
|
||||
z2: 0
|
||||
});
|
||||
layerGroup.add(polygon);
|
||||
group.add(layerGroup);
|
||||
if (seriesModel.isAnimationEnabled()) {
|
||||
polygon.setClipPath(createGridClipShape(polygon.getBoundingRect(), seriesModel, function () {
|
||||
polygon.removeClipPath();
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
var layerGroup = oldLayersGroups[oldIdx];
|
||||
polygon = layerGroup.childAt(0);
|
||||
group.add(layerGroup);
|
||||
newLayersGroups[idx] = layerGroup;
|
||||
graphic.updateProps(polygon, {
|
||||
shape: {
|
||||
points: points0,
|
||||
stackedOnPoints: points1
|
||||
}
|
||||
}, seriesModel);
|
||||
saveOldStyle(polygon);
|
||||
}
|
||||
setLabelStyle(polygon, getLabelStatesModels(seriesModel), {
|
||||
labelDataIndex: indices[j - 1],
|
||||
defaultText: data.getName(indices[j - 1]),
|
||||
inheritColor: style.fill
|
||||
}, {
|
||||
normal: {
|
||||
verticalAlign: 'middle'
|
||||
// align: 'right'
|
||||
}
|
||||
});
|
||||
polygon.setTextConfig({
|
||||
position: null,
|
||||
local: true
|
||||
});
|
||||
var labelEl = polygon.getTextContent();
|
||||
// TODO More label position options.
|
||||
if (labelEl) {
|
||||
labelEl.x = textLayout.x - margin;
|
||||
labelEl.y = textLayout.y0 + textLayout.y / 2;
|
||||
}
|
||||
polygon.useStyle(style);
|
||||
data.setItemGraphicEl(idx, polygon);
|
||||
setStatesStylesFromModel(polygon, seriesModel);
|
||||
toggleHoverEmphasis(polygon, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
|
||||
}
|
||||
this._layersSeries = layersSeries;
|
||||
this._layers = newLayersGroups;
|
||||
};
|
||||
ThemeRiverView.type = 'themeRiver';
|
||||
return ThemeRiverView;
|
||||
}(ChartView);
|
||||
;
|
||||
// add animation to the view
|
||||
function createGridClipShape(rect, seriesModel, cb) {
|
||||
var rectEl = new graphic.Rect({
|
||||
shape: {
|
||||
x: rect.x - 10,
|
||||
y: rect.y - 10,
|
||||
width: 0,
|
||||
height: rect.height + 20
|
||||
}
|
||||
});
|
||||
graphic.initProps(rectEl, {
|
||||
shape: {
|
||||
x: rect.x - 50,
|
||||
width: rect.width + 100,
|
||||
height: rect.height + 20
|
||||
}
|
||||
}, seriesModel, cb);
|
||||
return rectEl;
|
||||
}
|
||||
export default ThemeRiverView;
|
35
frontend/node_modules/echarts/lib/chart/themeRiver/install.js
generated
vendored
Normal file
35
frontend/node_modules/echarts/lib/chart/themeRiver/install.js
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import ThemeRiverView from './ThemeRiverView.js';
|
||||
import ThemeRiverSeriesModel from './ThemeRiverSeries.js';
|
||||
import themeRiverLayout from './themeRiverLayout.js';
|
||||
import dataFilter from '../../processor/dataFilter.js';
|
||||
export function install(registers) {
|
||||
registers.registerChartView(ThemeRiverView);
|
||||
registers.registerSeriesModel(ThemeRiverSeriesModel);
|
||||
registers.registerLayout(themeRiverLayout);
|
||||
registers.registerProcessor(dataFilter('themeRiver'));
|
||||
}
|
157
frontend/node_modules/echarts/lib/chart/themeRiver/themeRiverLayout.js
generated
vendored
Normal file
157
frontend/node_modules/echarts/lib/chart/themeRiver/themeRiverLayout.js
generated
vendored
Normal file
@ -0,0 +1,157 @@
|
||||
|
||||
/*
|
||||
* 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 * as numberUtil from '../../util/number.js';
|
||||
export default function themeRiverLayout(ecModel, api) {
|
||||
ecModel.eachSeriesByType('themeRiver', function (seriesModel) {
|
||||
var data = seriesModel.getData();
|
||||
var single = seriesModel.coordinateSystem;
|
||||
var layoutInfo = {};
|
||||
// use the axis boundingRect for view
|
||||
var rect = single.getRect();
|
||||
layoutInfo.rect = rect;
|
||||
var boundaryGap = seriesModel.get('boundaryGap');
|
||||
var axis = single.getAxis();
|
||||
layoutInfo.boundaryGap = boundaryGap;
|
||||
if (axis.orient === 'horizontal') {
|
||||
boundaryGap[0] = numberUtil.parsePercent(boundaryGap[0], rect.height);
|
||||
boundaryGap[1] = numberUtil.parsePercent(boundaryGap[1], rect.height);
|
||||
var height = rect.height - boundaryGap[0] - boundaryGap[1];
|
||||
doThemeRiverLayout(data, seriesModel, height);
|
||||
} else {
|
||||
boundaryGap[0] = numberUtil.parsePercent(boundaryGap[0], rect.width);
|
||||
boundaryGap[1] = numberUtil.parsePercent(boundaryGap[1], rect.width);
|
||||
var width = rect.width - boundaryGap[0] - boundaryGap[1];
|
||||
doThemeRiverLayout(data, seriesModel, width);
|
||||
}
|
||||
data.setLayout('layoutInfo', layoutInfo);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* The layout information about themeriver
|
||||
*
|
||||
* @param data data in the series
|
||||
* @param seriesModel the model object of themeRiver series
|
||||
* @param height value used to compute every series height
|
||||
*/
|
||||
function doThemeRiverLayout(data, seriesModel, height) {
|
||||
if (!data.count()) {
|
||||
return;
|
||||
}
|
||||
var coordSys = seriesModel.coordinateSystem;
|
||||
// the data in each layer are organized into a series.
|
||||
var layerSeries = seriesModel.getLayerSeries();
|
||||
// the points in each layer.
|
||||
var timeDim = data.mapDimension('single');
|
||||
var valueDim = data.mapDimension('value');
|
||||
var layerPoints = zrUtil.map(layerSeries, function (singleLayer) {
|
||||
return zrUtil.map(singleLayer.indices, function (idx) {
|
||||
var pt = coordSys.dataToPoint(data.get(timeDim, idx));
|
||||
pt[1] = data.get(valueDim, idx);
|
||||
return pt;
|
||||
});
|
||||
});
|
||||
var base = computeBaseline(layerPoints);
|
||||
var baseLine = base.y0;
|
||||
var ky = height / base.max;
|
||||
// set layout information for each item.
|
||||
var n = layerSeries.length;
|
||||
var m = layerSeries[0].indices.length;
|
||||
var baseY0;
|
||||
for (var j = 0; j < m; ++j) {
|
||||
baseY0 = baseLine[j] * ky;
|
||||
data.setItemLayout(layerSeries[0].indices[j], {
|
||||
layerIndex: 0,
|
||||
x: layerPoints[0][j][0],
|
||||
y0: baseY0,
|
||||
y: layerPoints[0][j][1] * ky
|
||||
});
|
||||
for (var i = 1; i < n; ++i) {
|
||||
baseY0 += layerPoints[i - 1][j][1] * ky;
|
||||
data.setItemLayout(layerSeries[i].indices[j], {
|
||||
layerIndex: i,
|
||||
x: layerPoints[i][j][0],
|
||||
y0: baseY0,
|
||||
y: layerPoints[i][j][1] * ky
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Compute the baseLine of the rawdata
|
||||
* Inspired by Lee Byron's paper Stacked Graphs - Geometry & Aesthetics
|
||||
*
|
||||
* @param data the points in each layer
|
||||
*/
|
||||
function computeBaseline(data) {
|
||||
var layerNum = data.length;
|
||||
var pointNum = data[0].length;
|
||||
var sums = [];
|
||||
var y0 = [];
|
||||
var max = 0;
|
||||
for (var i = 0; i < pointNum; ++i) {
|
||||
var temp = 0;
|
||||
for (var j = 0; j < layerNum; ++j) {
|
||||
temp += data[j][i][1];
|
||||
}
|
||||
if (temp > max) {
|
||||
max = temp;
|
||||
}
|
||||
sums.push(temp);
|
||||
}
|
||||
for (var k = 0; k < pointNum; ++k) {
|
||||
y0[k] = (max - sums[k]) / 2;
|
||||
}
|
||||
max = 0;
|
||||
for (var l = 0; l < pointNum; ++l) {
|
||||
var sum = sums[l] + y0[l];
|
||||
if (sum > max) {
|
||||
max = sum;
|
||||
}
|
||||
}
|
||||
return {
|
||||
y0: y0,
|
||||
max: max
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user