mirror of
https://gitlab.com/JKANetwork/CheckServer.git
synced 2026-04-05 18:22:01 +02:00
Start again
This commit is contained in:
71
vendors/echarts/src/component/toolbox/ToolboxModel.js
vendored
Normal file
71
vendors/echarts/src/component/toolbox/ToolboxModel.js
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
define(function (require) {
|
||||
|
||||
var featureManager = require('./featureManager');
|
||||
var zrUtil = require('zrender/core/util');
|
||||
|
||||
var ToolboxModel = require('../../echarts').extendComponentModel({
|
||||
|
||||
type: 'toolbox',
|
||||
|
||||
layoutMode: {
|
||||
type: 'box',
|
||||
ignoreSize: true
|
||||
},
|
||||
|
||||
mergeDefaultAndTheme: function (option) {
|
||||
ToolboxModel.superApply(this, 'mergeDefaultAndTheme', arguments);
|
||||
|
||||
zrUtil.each(this.option.feature, function (featureOpt, featureName) {
|
||||
var Feature = featureManager.get(featureName);
|
||||
Feature && zrUtil.merge(featureOpt, Feature.defaultOption);
|
||||
});
|
||||
},
|
||||
|
||||
defaultOption: {
|
||||
|
||||
show: true,
|
||||
|
||||
z: 6,
|
||||
|
||||
zlevel: 0,
|
||||
|
||||
orient: 'horizontal',
|
||||
|
||||
left: 'right',
|
||||
|
||||
top: 'top',
|
||||
|
||||
// right
|
||||
// bottom
|
||||
|
||||
backgroundColor: 'transparent',
|
||||
|
||||
borderColor: '#ccc',
|
||||
|
||||
borderWidth: 0,
|
||||
|
||||
padding: 5,
|
||||
|
||||
itemSize: 15,
|
||||
|
||||
itemGap: 8,
|
||||
|
||||
showTitle: true,
|
||||
|
||||
iconStyle: {
|
||||
normal: {
|
||||
borderColor: '#666',
|
||||
color: 'none'
|
||||
},
|
||||
emphasis: {
|
||||
borderColor: '#3E98C5'
|
||||
}
|
||||
}
|
||||
// textStyle: {},
|
||||
|
||||
// feature
|
||||
}
|
||||
});
|
||||
|
||||
return ToolboxModel;
|
||||
});
|
||||
233
vendors/echarts/src/component/toolbox/ToolboxView.js
vendored
Normal file
233
vendors/echarts/src/component/toolbox/ToolboxView.js
vendored
Normal file
@@ -0,0 +1,233 @@
|
||||
define(function (require) {
|
||||
|
||||
var featureManager = require('./featureManager');
|
||||
var zrUtil = require('zrender/core/util');
|
||||
var graphic = require('../../util/graphic');
|
||||
var Model = require('../../model/Model');
|
||||
var DataDiffer = require('../../data/DataDiffer');
|
||||
var listComponentHelper = require('../helper/listComponent');
|
||||
var textContain = require('zrender/contain/text');
|
||||
|
||||
return require('../../echarts').extendComponentView({
|
||||
|
||||
type: 'toolbox',
|
||||
|
||||
render: function (toolboxModel, ecModel, api) {
|
||||
var group = this.group;
|
||||
group.removeAll();
|
||||
|
||||
if (!toolboxModel.get('show')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var itemSize = +toolboxModel.get('itemSize');
|
||||
var featureOpts = toolboxModel.get('feature') || {};
|
||||
var features = this._features || (this._features = {});
|
||||
|
||||
var featureNames = [];
|
||||
zrUtil.each(featureOpts, function (opt, name) {
|
||||
featureNames.push(name);
|
||||
});
|
||||
|
||||
(new DataDiffer(this._featureNames || [], featureNames))
|
||||
.add(process)
|
||||
.update(process)
|
||||
.remove(zrUtil.curry(process, null))
|
||||
.execute();
|
||||
|
||||
// Keep for diff.
|
||||
this._featureNames = featureNames;
|
||||
|
||||
function process(newIndex, oldIndex) {
|
||||
var featureName = featureNames[newIndex];
|
||||
var oldName = featureNames[oldIndex];
|
||||
var featureOpt = featureOpts[featureName];
|
||||
var featureModel = new Model(featureOpt, toolboxModel, toolboxModel.ecModel);
|
||||
var feature;
|
||||
|
||||
if (featureName && !oldName) { // Create
|
||||
if (isUserFeatureName(featureName)) {
|
||||
feature = {
|
||||
model: featureModel,
|
||||
onclick: featureModel.option.onclick,
|
||||
featureName: featureName
|
||||
};
|
||||
}
|
||||
else {
|
||||
var Feature = featureManager.get(featureName);
|
||||
if (!Feature) {
|
||||
return;
|
||||
}
|
||||
feature = new Feature(featureModel);
|
||||
}
|
||||
features[featureName] = feature;
|
||||
}
|
||||
else {
|
||||
feature = features[oldName];
|
||||
// If feature does not exsit.
|
||||
if (!feature) {
|
||||
return;
|
||||
}
|
||||
feature.model = featureModel;
|
||||
}
|
||||
|
||||
if (!featureName && oldName) {
|
||||
feature.dispose && feature.dispose(ecModel, api);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!featureModel.get('show') || feature.unusable) {
|
||||
feature.remove && feature.remove(ecModel, api);
|
||||
return;
|
||||
}
|
||||
|
||||
createIconPaths(featureModel, feature, featureName);
|
||||
|
||||
featureModel.setIconStatus = function (iconName, status) {
|
||||
var option = this.option;
|
||||
var iconPaths = this.iconPaths;
|
||||
option.iconStatus = option.iconStatus || {};
|
||||
option.iconStatus[iconName] = status;
|
||||
// FIXME
|
||||
iconPaths[iconName] && iconPaths[iconName].trigger(status);
|
||||
};
|
||||
|
||||
if (feature.render) {
|
||||
feature.render(featureModel, ecModel, api);
|
||||
}
|
||||
}
|
||||
|
||||
function createIconPaths(featureModel, feature, featureName) {
|
||||
var iconStyleModel = featureModel.getModel('iconStyle');
|
||||
|
||||
// If one feature has mutiple icon. they are orginaized as
|
||||
// {
|
||||
// icon: {
|
||||
// foo: '',
|
||||
// bar: ''
|
||||
// },
|
||||
// title: {
|
||||
// foo: '',
|
||||
// bar: ''
|
||||
// }
|
||||
// }
|
||||
var icons = feature.getIcons ? feature.getIcons() : featureModel.get('icon');
|
||||
var titles = featureModel.get('title') || {};
|
||||
if (typeof icons === 'string') {
|
||||
var icon = icons;
|
||||
var title = titles;
|
||||
icons = {};
|
||||
titles = {};
|
||||
icons[featureName] = icon;
|
||||
titles[featureName] = title;
|
||||
}
|
||||
var iconPaths = featureModel.iconPaths = {};
|
||||
zrUtil.each(icons, function (icon, iconName) {
|
||||
var normalStyle = iconStyleModel.getModel('normal').getItemStyle();
|
||||
var hoverStyle = iconStyleModel.getModel('emphasis').getItemStyle();
|
||||
|
||||
var style = {
|
||||
x: -itemSize / 2,
|
||||
y: -itemSize / 2,
|
||||
width: itemSize,
|
||||
height: itemSize
|
||||
};
|
||||
var path = icon.indexOf('image://') === 0
|
||||
? (
|
||||
style.image = icon.slice(8),
|
||||
new graphic.Image({style: style})
|
||||
)
|
||||
: graphic.makePath(
|
||||
icon.replace('path://', ''),
|
||||
{
|
||||
style: normalStyle,
|
||||
hoverStyle: hoverStyle,
|
||||
rectHover: true
|
||||
},
|
||||
style,
|
||||
'center'
|
||||
);
|
||||
|
||||
graphic.setHoverStyle(path);
|
||||
|
||||
if (toolboxModel.get('showTitle')) {
|
||||
path.__title = titles[iconName];
|
||||
path.on('mouseover', function () {
|
||||
path.setStyle({
|
||||
text: titles[iconName],
|
||||
textPosition: hoverStyle.textPosition || 'bottom',
|
||||
textFill: hoverStyle.fill || hoverStyle.stroke || '#000',
|
||||
textAlign: hoverStyle.textAlign || 'center'
|
||||
});
|
||||
})
|
||||
.on('mouseout', function () {
|
||||
path.setStyle({
|
||||
textFill: null
|
||||
});
|
||||
});
|
||||
}
|
||||
path.trigger(featureModel.get('iconStatus.' + iconName) || 'normal');
|
||||
|
||||
group.add(path);
|
||||
path.on('click', zrUtil.bind(
|
||||
feature.onclick, feature, ecModel, api, iconName
|
||||
));
|
||||
|
||||
iconPaths[iconName] = path;
|
||||
});
|
||||
}
|
||||
|
||||
listComponentHelper.layout(group, toolboxModel, api);
|
||||
// Render background after group is layout
|
||||
// FIXME
|
||||
listComponentHelper.addBackground(group, toolboxModel);
|
||||
|
||||
// Adjust icon title positions to avoid them out of screen
|
||||
group.eachChild(function (icon) {
|
||||
var titleText = icon.__title;
|
||||
var hoverStyle = icon.hoverStyle;
|
||||
// May be background element
|
||||
if (hoverStyle && titleText) {
|
||||
var rect = textContain.getBoundingRect(
|
||||
titleText, hoverStyle.font
|
||||
);
|
||||
var offsetX = icon.position[0] + group.position[0];
|
||||
var offsetY = icon.position[1] + group.position[1] + itemSize;
|
||||
|
||||
var needPutOnTop = false;
|
||||
if (offsetY + rect.height > api.getHeight()) {
|
||||
hoverStyle.textPosition = 'top';
|
||||
needPutOnTop = true;
|
||||
}
|
||||
var topOffset = needPutOnTop ? (-5 - rect.height) : (itemSize + 8);
|
||||
if (offsetX + rect.width / 2 > api.getWidth()) {
|
||||
hoverStyle.textPosition = ['100%', topOffset];
|
||||
hoverStyle.textAlign = 'right';
|
||||
}
|
||||
else if (offsetX - rect.width / 2 < 0) {
|
||||
hoverStyle.textPosition = [0, topOffset];
|
||||
hoverStyle.textAlign = 'left';
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
remove: function (ecModel, api) {
|
||||
zrUtil.each(this._features, function (feature) {
|
||||
feature.remove && feature.remove(ecModel, api);
|
||||
});
|
||||
this.group.removeAll();
|
||||
},
|
||||
|
||||
dispose: function (ecModel, api) {
|
||||
zrUtil.each(this._features, function (feature) {
|
||||
feature.dispose && feature.dispose(ecModel, api);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function isUserFeatureName(featureName) {
|
||||
return featureName.indexOf('my') === 0;
|
||||
}
|
||||
|
||||
});
|
||||
478
vendors/echarts/src/component/toolbox/feature/DataView.js
vendored
Normal file
478
vendors/echarts/src/component/toolbox/feature/DataView.js
vendored
Normal file
@@ -0,0 +1,478 @@
|
||||
/**
|
||||
* @module echarts/component/toolbox/feature/DataView
|
||||
*/
|
||||
|
||||
define(function (require) {
|
||||
|
||||
var zrUtil = require('zrender/core/util');
|
||||
var eventTool = require('zrender/core/event');
|
||||
|
||||
|
||||
var BLOCK_SPLITER = new Array(60).join('-');
|
||||
var ITEM_SPLITER = '\t';
|
||||
/**
|
||||
* Group series into two types
|
||||
* 1. on category axis, like line, bar
|
||||
* 2. others, like scatter, pie
|
||||
* @param {module:echarts/model/Global} ecModel
|
||||
* @return {Object}
|
||||
* @inner
|
||||
*/
|
||||
function groupSeries(ecModel) {
|
||||
var seriesGroupByCategoryAxis = {};
|
||||
var otherSeries = [];
|
||||
var meta = [];
|
||||
ecModel.eachRawSeries(function (seriesModel) {
|
||||
var coordSys = seriesModel.coordinateSystem;
|
||||
|
||||
if (coordSys && (coordSys.type === 'cartesian2d' || coordSys.type === 'polar')) {
|
||||
var baseAxis = coordSys.getBaseAxis();
|
||||
if (baseAxis.type === 'category') {
|
||||
var key = baseAxis.dim + '_' + baseAxis.index;
|
||||
if (!seriesGroupByCategoryAxis[key]) {
|
||||
seriesGroupByCategoryAxis[key] = {
|
||||
categoryAxis: baseAxis,
|
||||
valueAxis: coordSys.getOtherAxis(baseAxis),
|
||||
series: []
|
||||
};
|
||||
meta.push({
|
||||
axisDim: baseAxis.dim,
|
||||
axisIndex: baseAxis.index
|
||||
});
|
||||
}
|
||||
seriesGroupByCategoryAxis[key].series.push(seriesModel);
|
||||
}
|
||||
else {
|
||||
otherSeries.push(seriesModel);
|
||||
}
|
||||
}
|
||||
else {
|
||||
otherSeries.push(seriesModel);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
seriesGroupByCategoryAxis: seriesGroupByCategoryAxis,
|
||||
other: otherSeries,
|
||||
meta: meta
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Assemble content of series on cateogory axis
|
||||
* @param {Array.<module:echarts/model/Series>} series
|
||||
* @return {string}
|
||||
* @inner
|
||||
*/
|
||||
function assembleSeriesWithCategoryAxis(series) {
|
||||
var tables = [];
|
||||
zrUtil.each(series, function (group, key) {
|
||||
var categoryAxis = group.categoryAxis;
|
||||
var valueAxis = group.valueAxis;
|
||||
var valueAxisDim = valueAxis.dim;
|
||||
|
||||
var headers = [' '].concat(zrUtil.map(group.series, function (series) {
|
||||
return series.name;
|
||||
}));
|
||||
var columns = [categoryAxis.model.getCategories()];
|
||||
zrUtil.each(group.series, function (series) {
|
||||
columns.push(series.getRawData().mapArray(valueAxisDim, function (val) {
|
||||
return val;
|
||||
}));
|
||||
});
|
||||
// Assemble table content
|
||||
var lines = [headers.join(ITEM_SPLITER)];
|
||||
for (var i = 0; i < columns[0].length; i++) {
|
||||
var items = [];
|
||||
for (var j = 0; j < columns.length; j++) {
|
||||
items.push(columns[j][i]);
|
||||
}
|
||||
lines.push(items.join(ITEM_SPLITER));
|
||||
}
|
||||
tables.push(lines.join('\n'));
|
||||
});
|
||||
return tables.join('\n\n' + BLOCK_SPLITER + '\n\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Assemble content of other series
|
||||
* @param {Array.<module:echarts/model/Series>} series
|
||||
* @return {string}
|
||||
* @inner
|
||||
*/
|
||||
function assembleOtherSeries(series) {
|
||||
return zrUtil.map(series, function (series) {
|
||||
var data = series.getRawData();
|
||||
var lines = [series.name];
|
||||
var vals = [];
|
||||
data.each(data.dimensions, function () {
|
||||
var argLen = arguments.length;
|
||||
var dataIndex = arguments[argLen - 1];
|
||||
var name = data.getName(dataIndex);
|
||||
for (var i = 0; i < argLen - 1; i++) {
|
||||
vals[i] = arguments[i];
|
||||
}
|
||||
lines.push((name ? (name + ITEM_SPLITER) : '') + vals.join(ITEM_SPLITER));
|
||||
});
|
||||
return lines.join('\n');
|
||||
}).join('\n\n' + BLOCK_SPLITER + '\n\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:echarts/model/Global}
|
||||
* @return {string}
|
||||
* @inner
|
||||
*/
|
||||
function getContentFromModel(ecModel) {
|
||||
|
||||
var result = groupSeries(ecModel);
|
||||
|
||||
return {
|
||||
value: zrUtil.filter([
|
||||
assembleSeriesWithCategoryAxis(result.seriesGroupByCategoryAxis),
|
||||
assembleOtherSeries(result.other)
|
||||
], function (str) {
|
||||
return str.replace(/[\n\t\s]/g, '');
|
||||
}).join('\n\n' + BLOCK_SPLITER + '\n\n'),
|
||||
|
||||
meta: result.meta
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function trim(str) {
|
||||
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
|
||||
}
|
||||
/**
|
||||
* If a block is tsv format
|
||||
*/
|
||||
function isTSVFormat(block) {
|
||||
// Simple method to find out if a block is tsv format
|
||||
var firstLine = block.slice(0, block.indexOf('\n'));
|
||||
if (firstLine.indexOf(ITEM_SPLITER) >= 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
var itemSplitRegex = new RegExp('[' + ITEM_SPLITER + ']+', 'g');
|
||||
/**
|
||||
* @param {string} tsv
|
||||
* @return {Array.<Object>}
|
||||
*/
|
||||
function parseTSVContents(tsv) {
|
||||
var tsvLines = tsv.split(/\n+/g);
|
||||
var headers = trim(tsvLines.shift()).split(itemSplitRegex);
|
||||
|
||||
var categories = [];
|
||||
var series = zrUtil.map(headers, function (header) {
|
||||
return {
|
||||
name: header,
|
||||
data: []
|
||||
};
|
||||
});
|
||||
for (var i = 0; i < tsvLines.length; i++) {
|
||||
var items = trim(tsvLines[i]).split(itemSplitRegex);
|
||||
categories.push(items.shift());
|
||||
for (var j = 0; j < items.length; j++) {
|
||||
series[j] && (series[j].data[i] = items[j]);
|
||||
}
|
||||
}
|
||||
return {
|
||||
series: series,
|
||||
categories: categories
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} str
|
||||
* @return {Array.<Object>}
|
||||
* @inner
|
||||
*/
|
||||
function parseListContents(str) {
|
||||
var lines = str.split(/\n+/g);
|
||||
var seriesName = trim(lines.shift());
|
||||
|
||||
var data = [];
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var items = trim(lines[i]).split(itemSplitRegex);
|
||||
var name = '';
|
||||
var value;
|
||||
var hasName = false;
|
||||
if (isNaN(items[0])) { // First item is name
|
||||
hasName = true;
|
||||
name = items[0];
|
||||
items = items.slice(1);
|
||||
data[i] = {
|
||||
name: name,
|
||||
value: []
|
||||
};
|
||||
value = data[i].value;
|
||||
}
|
||||
else {
|
||||
value = data[i] = [];
|
||||
}
|
||||
for (var j = 0; j < items.length; j++) {
|
||||
value.push(+items[j]);
|
||||
}
|
||||
if (value.length === 1) {
|
||||
hasName ? (data[i].value = value[0]) : (data[i] = value[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
name: seriesName,
|
||||
data: data
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} str
|
||||
* @param {Array.<Object>} blockMetaList
|
||||
* @return {Object}
|
||||
* @inner
|
||||
*/
|
||||
function parseContents(str, blockMetaList) {
|
||||
var blocks = str.split(new RegExp('\n*' + BLOCK_SPLITER + '\n*', 'g'));
|
||||
var newOption = {
|
||||
series: []
|
||||
};
|
||||
zrUtil.each(blocks, function (block, idx) {
|
||||
if (isTSVFormat(block)) {
|
||||
var result = parseTSVContents(block);
|
||||
var blockMeta = blockMetaList[idx];
|
||||
var axisKey = blockMeta.axisDim + 'Axis';
|
||||
|
||||
if (blockMeta) {
|
||||
newOption[axisKey] = newOption[axisKey] || [];
|
||||
newOption[axisKey][blockMeta.axisIndex] = {
|
||||
data: result.categories
|
||||
};
|
||||
newOption.series = newOption.series.concat(result.series);
|
||||
}
|
||||
}
|
||||
else {
|
||||
var result = parseListContents(block);
|
||||
newOption.series.push(result);
|
||||
}
|
||||
});
|
||||
return newOption;
|
||||
}
|
||||
|
||||
/**
|
||||
* @alias {module:echarts/component/toolbox/feature/DataView}
|
||||
* @constructor
|
||||
* @param {module:echarts/model/Model} model
|
||||
*/
|
||||
function DataView(model) {
|
||||
|
||||
this._dom = null;
|
||||
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
DataView.defaultOption = {
|
||||
show: true,
|
||||
readOnly: false,
|
||||
optionToContent: null,
|
||||
contentToOption: null,
|
||||
|
||||
icon: 'M17.5,17.3H33 M17.5,17.3H33 M45.4,29.5h-28 M11.5,2v56H51V14.8L38.4,2H11.5z M38.4,2.2v12.7H51 M45.4,41.7h-28',
|
||||
title: '数据视图',
|
||||
lang: ['数据视图', '关闭', '刷新'],
|
||||
backgroundColor: '#fff',
|
||||
textColor: '#000',
|
||||
textareaColor: '#fff',
|
||||
textareaBorderColor: '#333',
|
||||
buttonColor: '#c23531',
|
||||
buttonTextColor: '#fff'
|
||||
};
|
||||
|
||||
DataView.prototype.onclick = function (ecModel, api) {
|
||||
var container = api.getDom();
|
||||
var model = this.model;
|
||||
if (this._dom) {
|
||||
container.removeChild(this._dom);
|
||||
}
|
||||
var root = document.createElement('div');
|
||||
root.style.cssText = 'position:absolute;left:5px;top:5px;bottom:5px;right:5px;';
|
||||
root.style.backgroundColor = model.get('backgroundColor') || '#fff';
|
||||
|
||||
// Create elements
|
||||
var header = document.createElement('h4');
|
||||
var lang = model.get('lang') || [];
|
||||
header.innerHTML = lang[0] || model.get('title');
|
||||
header.style.cssText = 'margin: 10px 20px;';
|
||||
header.style.color = model.get('textColor');
|
||||
|
||||
var viewMain = document.createElement('div');
|
||||
var textarea = document.createElement('textarea');
|
||||
viewMain.style.cssText = 'display:block;width:100%;overflow:hidden;';
|
||||
|
||||
var optionToContent = model.get('optionToContent');
|
||||
var contentToOption = model.get('contentToOption');
|
||||
var result = getContentFromModel(ecModel);
|
||||
if (typeof optionToContent === 'function') {
|
||||
var htmlOrDom = optionToContent(api.getOption());
|
||||
if (typeof htmlOrDom === 'string') {
|
||||
viewMain.innerHTML = htmlOrDom;
|
||||
}
|
||||
else if (zrUtil.isDom(htmlOrDom)) {
|
||||
viewMain.appendChild(htmlOrDom);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Use default textarea
|
||||
viewMain.appendChild(textarea);
|
||||
textarea.readOnly = model.get('readOnly');
|
||||
textarea.style.cssText = 'width:100%;height:100%;font-family:monospace;font-size:14px;line-height:1.6rem;';
|
||||
textarea.style.color = model.get('textColor');
|
||||
textarea.style.borderColor = model.get('textareaBorderColor');
|
||||
textarea.style.backgroundColor = model.get('textareaColor');
|
||||
textarea.value = result.value;
|
||||
}
|
||||
|
||||
var blockMetaList = result.meta;
|
||||
|
||||
var buttonContainer = document.createElement('div');
|
||||
buttonContainer.style.cssText = 'position:absolute;bottom:0;left:0;right:0;';
|
||||
|
||||
var buttonStyle = 'float:right;margin-right:20px;border:none;'
|
||||
+ 'cursor:pointer;padding:2px 5px;font-size:12px;border-radius:3px';
|
||||
var closeButton = document.createElement('div');
|
||||
var refreshButton = document.createElement('div');
|
||||
|
||||
buttonStyle += ';background-color:' + model.get('buttonColor');
|
||||
buttonStyle += ';color:' + model.get('buttonTextColor');
|
||||
|
||||
var self = this;
|
||||
|
||||
function close() {
|
||||
container.removeChild(root);
|
||||
self._dom = null;
|
||||
}
|
||||
eventTool.addEventListener(closeButton, 'click', close);
|
||||
|
||||
eventTool.addEventListener(refreshButton, 'click', function () {
|
||||
var newOption;
|
||||
try {
|
||||
if (typeof contentToOption === 'function') {
|
||||
newOption = contentToOption(viewMain, api.getOption());
|
||||
}
|
||||
else {
|
||||
newOption = parseContents(textarea.value, blockMetaList);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
close();
|
||||
throw new Error('Data view format error ' + e);
|
||||
}
|
||||
if (newOption) {
|
||||
api.dispatchAction({
|
||||
type: 'changeDataView',
|
||||
newOption: newOption
|
||||
});
|
||||
}
|
||||
|
||||
close();
|
||||
});
|
||||
|
||||
closeButton.innerHTML = lang[1];
|
||||
refreshButton.innerHTML = lang[2];
|
||||
refreshButton.style.cssText = buttonStyle;
|
||||
closeButton.style.cssText = buttonStyle;
|
||||
|
||||
!model.get('readOnly') && buttonContainer.appendChild(refreshButton);
|
||||
buttonContainer.appendChild(closeButton);
|
||||
|
||||
// http://stackoverflow.com/questions/6637341/use-tab-to-indent-in-textarea
|
||||
eventTool.addEventListener(textarea, 'keydown', function (e) {
|
||||
if ((e.keyCode || e.which) === 9) {
|
||||
// get caret position/selection
|
||||
var val = this.value;
|
||||
var start = this.selectionStart;
|
||||
var end = this.selectionEnd;
|
||||
|
||||
// set textarea value to: text before caret + tab + text after caret
|
||||
this.value = val.substring(0, start) + ITEM_SPLITER + val.substring(end);
|
||||
|
||||
// put caret at right position again
|
||||
this.selectionStart = this.selectionEnd = start + 1;
|
||||
|
||||
// prevent the focus lose
|
||||
eventTool.stop(e);
|
||||
}
|
||||
});
|
||||
|
||||
root.appendChild(header);
|
||||
root.appendChild(viewMain);
|
||||
root.appendChild(buttonContainer);
|
||||
|
||||
viewMain.style.height = (container.clientHeight - 80) + 'px';
|
||||
|
||||
container.appendChild(root);
|
||||
this._dom = root;
|
||||
};
|
||||
|
||||
DataView.prototype.remove = function (ecModel, api) {
|
||||
this._dom && api.getDom().removeChild(this._dom);
|
||||
};
|
||||
|
||||
DataView.prototype.dispose = function (ecModel, api) {
|
||||
this.remove(ecModel, api);
|
||||
};
|
||||
|
||||
/**
|
||||
* @inner
|
||||
*/
|
||||
function tryMergeDataOption(newData, originalData) {
|
||||
return zrUtil.map(newData, function (newVal, idx) {
|
||||
var original = originalData && originalData[idx];
|
||||
if (zrUtil.isObject(original) && !zrUtil.isArray(original)) {
|
||||
if (zrUtil.isObject(newVal) && !zrUtil.isArray(newVal)) {
|
||||
newVal = newVal.value;
|
||||
}
|
||||
// Original data has option
|
||||
return zrUtil.defaults({
|
||||
value: newVal
|
||||
}, original);
|
||||
}
|
||||
else {
|
||||
return newVal;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
require('../featureManager').register('dataView', DataView);
|
||||
|
||||
require('../../../echarts').registerAction({
|
||||
type: 'changeDataView',
|
||||
event: 'dataViewChanged',
|
||||
update: 'prepareAndUpdate'
|
||||
}, function (payload, ecModel) {
|
||||
var newSeriesOptList = [];
|
||||
zrUtil.each(payload.newOption.series, function (seriesOpt) {
|
||||
var seriesModel = ecModel.getSeriesByName(seriesOpt.name)[0];
|
||||
if (!seriesModel) {
|
||||
// New created series
|
||||
// Geuss the series type
|
||||
newSeriesOptList.push(zrUtil.extend({
|
||||
// Default is scatter
|
||||
type: 'scatter'
|
||||
}, seriesOpt));
|
||||
}
|
||||
else {
|
||||
var originalData = seriesModel.get('data');
|
||||
newSeriesOptList.push({
|
||||
name: seriesOpt.name,
|
||||
data: tryMergeDataOption(seriesOpt.data, originalData)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
ecModel.mergeOption(zrUtil.defaults({
|
||||
series: newSeriesOptList
|
||||
}, payload.newOption));
|
||||
});
|
||||
|
||||
return DataView;
|
||||
});
|
||||
343
vendors/echarts/src/component/toolbox/feature/DataZoom.js
vendored
Normal file
343
vendors/echarts/src/component/toolbox/feature/DataZoom.js
vendored
Normal file
@@ -0,0 +1,343 @@
|
||||
define(function(require) {
|
||||
'use strict';
|
||||
|
||||
var zrUtil = require('zrender/core/util');
|
||||
var numberUtil = require('../../../util/number');
|
||||
var SelectController = require('../../helper/SelectController');
|
||||
var BoundingRect = require('zrender/core/BoundingRect');
|
||||
var Group = require('zrender/container/Group');
|
||||
var history = require('../../dataZoom/history');
|
||||
var interactionMutex = require('../../helper/interactionMutex');
|
||||
|
||||
var each = zrUtil.each;
|
||||
var asc = numberUtil.asc;
|
||||
|
||||
// Use dataZoomSelect
|
||||
require('../../dataZoomSelect');
|
||||
|
||||
// Spectial component id start with \0ec\0, see echarts/model/Global.js~hasInnerId
|
||||
var DATA_ZOOM_ID_BASE = '\0_ec_\0toolbox-dataZoom_';
|
||||
|
||||
function DataZoom(model) {
|
||||
this.model = model;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:zrender/container/Group}
|
||||
*/
|
||||
this._controllerGroup;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:echarts/component/helper/SelectController}
|
||||
*/
|
||||
this._controller;
|
||||
|
||||
/**
|
||||
* Is zoom active.
|
||||
* @private
|
||||
* @type {Object}
|
||||
*/
|
||||
this._isZoomActive;
|
||||
}
|
||||
|
||||
DataZoom.defaultOption = {
|
||||
show: true,
|
||||
// Icon group
|
||||
icon: {
|
||||
zoom: 'M0,13.5h26.9 M13.5,26.9V0 M32.1,13.5H58V58H13.5 V32.1',
|
||||
back: 'M22,1.4L9.9,13.5l12.3,12.3 M10.3,13.5H54.9v44.6 H10.3v-26'
|
||||
},
|
||||
title: {
|
||||
zoom: '区域缩放',
|
||||
back: '区域缩放还原'
|
||||
}
|
||||
};
|
||||
|
||||
var proto = DataZoom.prototype;
|
||||
|
||||
proto.render = function (featureModel, ecModel, api) {
|
||||
updateBackBtnStatus(featureModel, ecModel);
|
||||
};
|
||||
|
||||
proto.onclick = function (ecModel, api, type) {
|
||||
var controllerGroup = this._controllerGroup;
|
||||
if (!this._controllerGroup) {
|
||||
controllerGroup = this._controllerGroup = new Group();
|
||||
api.getZr().add(controllerGroup);
|
||||
}
|
||||
|
||||
handlers[type].call(this, controllerGroup, this.model, ecModel, api);
|
||||
};
|
||||
|
||||
proto.remove = function (ecModel, api) {
|
||||
this._disposeController();
|
||||
interactionMutex.release('globalPan', api.getZr());
|
||||
};
|
||||
|
||||
proto.dispose = function (ecModel, api) {
|
||||
var zr = api.getZr();
|
||||
interactionMutex.release('globalPan', zr);
|
||||
this._disposeController();
|
||||
this._controllerGroup && zr.remove(this._controllerGroup);
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
var handlers = {
|
||||
|
||||
zoom: function (controllerGroup, featureModel, ecModel, api) {
|
||||
var isZoomActive = this._isZoomActive = !this._isZoomActive;
|
||||
var zr = api.getZr();
|
||||
|
||||
interactionMutex[isZoomActive ? 'take' : 'release']('globalPan', zr);
|
||||
|
||||
featureModel.setIconStatus('zoom', isZoomActive ? 'emphasis' : 'normal');
|
||||
|
||||
if (isZoomActive) {
|
||||
zr.setDefaultCursorStyle('crosshair');
|
||||
|
||||
this._createController(
|
||||
controllerGroup, featureModel, ecModel, api
|
||||
);
|
||||
}
|
||||
else {
|
||||
zr.setDefaultCursorStyle('default');
|
||||
this._disposeController();
|
||||
}
|
||||
},
|
||||
|
||||
back: function (controllerGroup, featureModel, ecModel, api) {
|
||||
this._dispatchAction(history.pop(ecModel), api);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
proto._createController = function (
|
||||
controllerGroup, featureModel, ecModel, api
|
||||
) {
|
||||
var controller = this._controller = new SelectController(
|
||||
'rect',
|
||||
api.getZr(),
|
||||
{
|
||||
// FIXME
|
||||
lineWidth: 3,
|
||||
stroke: '#333',
|
||||
fill: 'rgba(0,0,0,0.2)'
|
||||
}
|
||||
);
|
||||
controller.on(
|
||||
'selectEnd',
|
||||
zrUtil.bind(
|
||||
this._onSelected, this, controller,
|
||||
featureModel, ecModel, api
|
||||
)
|
||||
);
|
||||
controller.enable(controllerGroup, false);
|
||||
};
|
||||
|
||||
proto._disposeController = function () {
|
||||
var controller = this._controller;
|
||||
if (controller) {
|
||||
controller.off('selected');
|
||||
controller.dispose();
|
||||
}
|
||||
};
|
||||
|
||||
function prepareCoordInfo(grid, ecModel) {
|
||||
// Default use the first axis.
|
||||
// FIXME
|
||||
var coordInfo = [
|
||||
{axisModel: grid.getAxis('x').model, axisIndex: 0}, // x
|
||||
{axisModel: grid.getAxis('y').model, axisIndex: 0} // y
|
||||
];
|
||||
coordInfo.grid = grid;
|
||||
|
||||
ecModel.eachComponent(
|
||||
{mainType: 'dataZoom', subType: 'select'},
|
||||
function (dzModel, dataZoomIndex) {
|
||||
if (isTheAxis('xAxis', coordInfo[0].axisModel, dzModel, ecModel)) {
|
||||
coordInfo[0].dataZoomModel = dzModel;
|
||||
}
|
||||
if (isTheAxis('yAxis', coordInfo[1].axisModel, dzModel, ecModel)) {
|
||||
coordInfo[1].dataZoomModel = dzModel;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return coordInfo;
|
||||
}
|
||||
|
||||
function isTheAxis(axisName, axisModel, dataZoomModel, ecModel) {
|
||||
var axisIndex = dataZoomModel.get(axisName + 'Index');
|
||||
return axisIndex != null
|
||||
&& ecModel.getComponent(axisName, axisIndex) === axisModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
proto._onSelected = function (controller, featureModel, ecModel, api, selRanges) {
|
||||
if (!selRanges.length) {
|
||||
return;
|
||||
}
|
||||
var selRange = selRanges[0];
|
||||
|
||||
controller.update(); // remove cover
|
||||
|
||||
var snapshot = {};
|
||||
|
||||
// FIXME
|
||||
// polar
|
||||
|
||||
ecModel.eachComponent('grid', function (gridModel, gridIndex) {
|
||||
var grid = gridModel.coordinateSystem;
|
||||
var coordInfo = prepareCoordInfo(grid, ecModel);
|
||||
var selDataRange = pointToDataInCartesian(selRange, coordInfo);
|
||||
|
||||
if (selDataRange) {
|
||||
var xBatchItem = scaleCartesianAxis(selDataRange, coordInfo, 0, 'x');
|
||||
var yBatchItem = scaleCartesianAxis(selDataRange, coordInfo, 1, 'y');
|
||||
|
||||
xBatchItem && (snapshot[xBatchItem.dataZoomId] = xBatchItem);
|
||||
yBatchItem && (snapshot[yBatchItem.dataZoomId] = yBatchItem);
|
||||
}
|
||||
}, this);
|
||||
|
||||
history.push(ecModel, snapshot);
|
||||
|
||||
this._dispatchAction(snapshot, api);
|
||||
};
|
||||
|
||||
function pointToDataInCartesian(selRange, coordInfo) {
|
||||
var grid = coordInfo.grid;
|
||||
|
||||
var selRect = new BoundingRect(
|
||||
selRange[0][0],
|
||||
selRange[1][0],
|
||||
selRange[0][1] - selRange[0][0],
|
||||
selRange[1][1] - selRange[1][0]
|
||||
);
|
||||
if (!selRect.intersect(grid.getRect())) {
|
||||
return;
|
||||
}
|
||||
var cartesian = grid.getCartesian(coordInfo[0].axisIndex, coordInfo[1].axisIndex);
|
||||
var dataLeftTop = cartesian.pointToData([selRange[0][0], selRange[1][0]], true);
|
||||
var dataRightBottom = cartesian.pointToData([selRange[0][1], selRange[1][1]], true);
|
||||
|
||||
return [
|
||||
asc([dataLeftTop[0], dataRightBottom[0]]), // x, using asc to handle inverse
|
||||
asc([dataLeftTop[1], dataRightBottom[1]]) // y, using asc to handle inverse
|
||||
];
|
||||
}
|
||||
|
||||
function scaleCartesianAxis(selDataRange, coordInfo, dimIdx, dimName) {
|
||||
var dimCoordInfo = coordInfo[dimIdx];
|
||||
var dataZoomModel = dimCoordInfo.dataZoomModel;
|
||||
|
||||
if (dataZoomModel) {
|
||||
return {
|
||||
dataZoomId: dataZoomModel.id,
|
||||
startValue: selDataRange[dimIdx][0],
|
||||
endValue: selDataRange[dimIdx][1]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
proto._dispatchAction = function (snapshot, api) {
|
||||
var batch = [];
|
||||
|
||||
each(snapshot, function (batchItem) {
|
||||
batch.push(batchItem);
|
||||
});
|
||||
|
||||
batch.length && api.dispatchAction({
|
||||
type: 'dataZoom',
|
||||
from: this.uid,
|
||||
batch: zrUtil.clone(batch, true)
|
||||
});
|
||||
};
|
||||
|
||||
function updateBackBtnStatus(featureModel, ecModel) {
|
||||
featureModel.setIconStatus(
|
||||
'back',
|
||||
history.count(ecModel) > 1 ? 'emphasis' : 'normal'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
require('../featureManager').register('dataZoom', DataZoom);
|
||||
|
||||
|
||||
// Create special dataZoom option for select
|
||||
require('../../../echarts').registerPreprocessor(function (option) {
|
||||
if (!option) {
|
||||
return;
|
||||
}
|
||||
|
||||
var dataZoomOpts = option.dataZoom || (option.dataZoom = []);
|
||||
if (!zrUtil.isArray(dataZoomOpts)) {
|
||||
option.dataZoom = dataZoomOpts = [dataZoomOpts];
|
||||
}
|
||||
|
||||
var toolboxOpt = option.toolbox;
|
||||
if (toolboxOpt) {
|
||||
// Assume there is only one toolbox
|
||||
if (zrUtil.isArray(toolboxOpt)) {
|
||||
toolboxOpt = toolboxOpt[0];
|
||||
}
|
||||
|
||||
if (toolboxOpt && toolboxOpt.feature) {
|
||||
var dataZoomOpt = toolboxOpt.feature.dataZoom;
|
||||
addForAxis('xAxis', dataZoomOpt);
|
||||
addForAxis('yAxis', dataZoomOpt);
|
||||
}
|
||||
}
|
||||
|
||||
function addForAxis(axisName, dataZoomOpt) {
|
||||
if (!dataZoomOpt) {
|
||||
return;
|
||||
}
|
||||
|
||||
var axisIndicesName = axisName + 'Index';
|
||||
var givenAxisIndices = dataZoomOpt[axisIndicesName];
|
||||
if (givenAxisIndices != null && !zrUtil.isArray(givenAxisIndices)) {
|
||||
givenAxisIndices = givenAxisIndices === false ? [] : [givenAxisIndices];
|
||||
}
|
||||
|
||||
forEachComponent(axisName, function (axisOpt, axisIndex) {
|
||||
if (givenAxisIndices != null
|
||||
&& zrUtil.indexOf(givenAxisIndices, axisIndex) === -1
|
||||
) {
|
||||
return;
|
||||
}
|
||||
var newOpt = {
|
||||
type: 'select',
|
||||
$fromToolbox: true,
|
||||
// Id for merge mapping.
|
||||
id: DATA_ZOOM_ID_BASE + axisName + axisIndex
|
||||
};
|
||||
// FIXME
|
||||
// Only support one axis now.
|
||||
newOpt[axisIndicesName] = axisIndex;
|
||||
dataZoomOpts.push(newOpt);
|
||||
});
|
||||
}
|
||||
|
||||
function forEachComponent(mainType, cb) {
|
||||
var opts = option[mainType];
|
||||
if (!zrUtil.isArray(opts)) {
|
||||
opts = opts ? [opts] : [];
|
||||
}
|
||||
each(opts, cb);
|
||||
}
|
||||
});
|
||||
|
||||
return DataZoom;
|
||||
});
|
||||
169
vendors/echarts/src/component/toolbox/feature/MagicType.js
vendored
Normal file
169
vendors/echarts/src/component/toolbox/feature/MagicType.js
vendored
Normal file
@@ -0,0 +1,169 @@
|
||||
define(function(require) {
|
||||
'use strict';
|
||||
|
||||
var zrUtil = require('zrender/core/util');
|
||||
|
||||
function MagicType(model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
MagicType.defaultOption = {
|
||||
show: true,
|
||||
type: [],
|
||||
// Icon group
|
||||
icon: {
|
||||
line: 'M4.1,28.9h7.1l9.3-22l7.4,38l9.7-19.7l3,12.8h14.9M4.1,58h51.4',
|
||||
bar: 'M6.7,22.9h10V48h-10V22.9zM24.9,13h10v35h-10V13zM43.2,2h10v46h-10V2zM3.1,58h53.7',
|
||||
stack: 'M8.2,38.4l-8.4,4.1l30.6,15.3L60,42.5l-8.1-4.1l-21.5,11L8.2,38.4z M51.9,30l-8.1,4.2l-13.4,6.9l-13.9-6.9L8.2,30l-8.4,4.2l8.4,4.2l22.2,11l21.5-11l8.1-4.2L51.9,30z M51.9,21.7l-8.1,4.2L35.7,30l-5.3,2.8L24.9,30l-8.4-4.1l-8.3-4.2l-8.4,4.2L8.2,30l8.3,4.2l13.9,6.9l13.4-6.9l8.1-4.2l8.1-4.1L51.9,21.7zM30.4,2.2L-0.2,17.5l8.4,4.1l8.3,4.2l8.4,4.2l5.5,2.7l5.3-2.7l8.1-4.2l8.1-4.2l8.1-4.1L30.4,2.2z', // jshint ignore:line
|
||||
tiled: 'M2.3,2.2h22.8V25H2.3V2.2z M35,2.2h22.8V25H35V2.2zM2.3,35h22.8v22.8H2.3V35z M35,35h22.8v22.8H35V35z'
|
||||
},
|
||||
title: {
|
||||
line: '切换为折线图',
|
||||
bar: '切换为柱状图',
|
||||
stack: '切换为堆叠',
|
||||
tiled: '切换为平铺'
|
||||
},
|
||||
option: {},
|
||||
seriesIndex: {}
|
||||
};
|
||||
|
||||
var proto = MagicType.prototype;
|
||||
|
||||
proto.getIcons = function () {
|
||||
var model = this.model;
|
||||
var availableIcons = model.get('icon');
|
||||
var icons = {};
|
||||
zrUtil.each(model.get('type'), function (type) {
|
||||
if (availableIcons[type]) {
|
||||
icons[type] = availableIcons[type];
|
||||
}
|
||||
});
|
||||
return icons;
|
||||
};
|
||||
|
||||
var seriesOptGenreator = {
|
||||
'line': function (seriesType, seriesId, seriesModel, model) {
|
||||
if (seriesType === 'bar') {
|
||||
return zrUtil.merge({
|
||||
id: seriesId,
|
||||
type: 'line',
|
||||
// Preserve data related option
|
||||
data: seriesModel.get('data'),
|
||||
stack: seriesModel.get('stack'),
|
||||
markPoint: seriesModel.get('markPoint'),
|
||||
markLine: seriesModel.get('markLine')
|
||||
}, model.get('option.line') || {}, true);
|
||||
}
|
||||
},
|
||||
'bar': function (seriesType, seriesId, seriesModel, model) {
|
||||
if (seriesType === 'line') {
|
||||
return zrUtil.merge({
|
||||
id: seriesId,
|
||||
type: 'bar',
|
||||
// Preserve data related option
|
||||
data: seriesModel.get('data'),
|
||||
stack: seriesModel.get('stack'),
|
||||
markPoint: seriesModel.get('markPoint'),
|
||||
markLine: seriesModel.get('markLine')
|
||||
}, model.get('option.bar') || {}, true);
|
||||
}
|
||||
},
|
||||
'stack': function (seriesType, seriesId, seriesModel, model) {
|
||||
if (seriesType === 'line' || seriesType === 'bar') {
|
||||
return zrUtil.merge({
|
||||
id: seriesId,
|
||||
stack: '__ec_magicType_stack__'
|
||||
}, model.get('option.stack') || {}, true);
|
||||
}
|
||||
},
|
||||
'tiled': function (seriesType, seriesId, seriesModel, model) {
|
||||
if (seriesType === 'line' || seriesType === 'bar') {
|
||||
return zrUtil.merge({
|
||||
id: seriesId,
|
||||
stack: ''
|
||||
}, model.get('option.tiled') || {}, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var radioTypes = [
|
||||
['line', 'bar'],
|
||||
['stack', 'tiled']
|
||||
];
|
||||
|
||||
proto.onclick = function (ecModel, api, type) {
|
||||
var model = this.model;
|
||||
var seriesIndex = model.get('seriesIndex.' + type);
|
||||
// Not supported magicType
|
||||
if (!seriesOptGenreator[type]) {
|
||||
return;
|
||||
}
|
||||
var newOption = {
|
||||
series: []
|
||||
};
|
||||
var generateNewSeriesTypes = function (seriesModel) {
|
||||
var seriesType = seriesModel.subType;
|
||||
var seriesId = seriesModel.id;
|
||||
var newSeriesOpt = seriesOptGenreator[type](
|
||||
seriesType, seriesId, seriesModel, model
|
||||
);
|
||||
if (newSeriesOpt) {
|
||||
// PENDING If merge original option?
|
||||
zrUtil.defaults(newSeriesOpt, seriesModel.option);
|
||||
newOption.series.push(newSeriesOpt);
|
||||
}
|
||||
// Modify boundaryGap
|
||||
var coordSys = seriesModel.coordinateSystem;
|
||||
if (coordSys && coordSys.type === 'cartesian2d' && (type === 'line' || type === 'bar')) {
|
||||
var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
|
||||
if (categoryAxis) {
|
||||
var axisDim = categoryAxis.dim;
|
||||
var axisIndex = seriesModel.get(axisDim + 'AxisIndex');
|
||||
var axisKey = axisDim + 'Axis';
|
||||
newOption[axisKey] = newOption[axisKey] || [];
|
||||
for (var i = 0; i <= axisIndex; i++) {
|
||||
newOption[axisKey][axisIndex] = newOption[axisKey][axisIndex] || {};
|
||||
}
|
||||
newOption[axisKey][axisIndex].boundaryGap = type === 'bar' ? true : false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
zrUtil.each(radioTypes, function (radio) {
|
||||
if (zrUtil.indexOf(radio, type) >= 0) {
|
||||
zrUtil.each(radio, function (item) {
|
||||
model.setIconStatus(item, 'normal');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
model.setIconStatus(type, 'emphasis');
|
||||
|
||||
ecModel.eachComponent(
|
||||
{
|
||||
mainType: 'series',
|
||||
query: seriesIndex == null ? null : {
|
||||
seriesIndex: seriesIndex
|
||||
}
|
||||
}, generateNewSeriesTypes
|
||||
);
|
||||
api.dispatchAction({
|
||||
type: 'changeMagicType',
|
||||
currentType: type,
|
||||
newOption: newOption
|
||||
});
|
||||
};
|
||||
|
||||
var echarts = require('../../../echarts');
|
||||
echarts.registerAction({
|
||||
type: 'changeMagicType',
|
||||
event: 'magicTypeChanged',
|
||||
update: 'prepareAndUpdate'
|
||||
}, function (payload, ecModel) {
|
||||
ecModel.mergeOption(payload.newOption);
|
||||
});
|
||||
|
||||
require('../featureManager').register('magicType', MagicType);
|
||||
|
||||
return MagicType;
|
||||
});
|
||||
39
vendors/echarts/src/component/toolbox/feature/Restore.js
vendored
Normal file
39
vendors/echarts/src/component/toolbox/feature/Restore.js
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
define(function(require) {
|
||||
'use strict';
|
||||
|
||||
var history = require('../../dataZoom/history');
|
||||
|
||||
function Restore(model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
Restore.defaultOption = {
|
||||
show: true,
|
||||
icon: 'M3.8,33.4 M47,18.9h9.8V8.7 M56.3,20.1 C52.1,9,40.5,0.6,26.8,2.1C12.6,3.7,1.6,16.2,2.1,30.6 M13,41.1H3.1v10.2 M3.7,39.9c4.2,11.1,15.8,19.5,29.5,18 c14.2-1.6,25.2-14.1,24.7-28.5',
|
||||
title: '还原'
|
||||
};
|
||||
|
||||
var proto = Restore.prototype;
|
||||
|
||||
proto.onclick = function (ecModel, api, type) {
|
||||
history.clear(ecModel);
|
||||
|
||||
api.dispatchAction({
|
||||
type: 'restore',
|
||||
from: this.uid
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
require('../featureManager').register('restore', Restore);
|
||||
|
||||
|
||||
require('../../../echarts').registerAction(
|
||||
{type: 'restore', event: 'restore', update: 'prepareAndUpdate'},
|
||||
function (payload, ecModel) {
|
||||
ecModel.resetOption('recreate');
|
||||
}
|
||||
);
|
||||
|
||||
return Restore;
|
||||
});
|
||||
67
vendors/echarts/src/component/toolbox/feature/SaveAsImage.js
vendored
Normal file
67
vendors/echarts/src/component/toolbox/feature/SaveAsImage.js
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
define(function (require) {
|
||||
|
||||
var env = require('zrender/core/env');
|
||||
|
||||
function SaveAsImage (model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
SaveAsImage.defaultOption = {
|
||||
show: true,
|
||||
icon: 'M4.7,22.9L29.3,45.5L54.7,23.4M4.6,43.6L4.6,58L53.8,58L53.8,43.6M29.2,45.1L29.2,0',
|
||||
title: '保存为图片',
|
||||
type: 'png',
|
||||
// Default use option.backgroundColor
|
||||
// backgroundColor: '#fff',
|
||||
name: '',
|
||||
excludeComponents: ['toolbox'],
|
||||
pixelRatio: 1,
|
||||
lang: ['右键另存为图片']
|
||||
};
|
||||
|
||||
SaveAsImage.prototype.unusable = !env.canvasSupported;
|
||||
|
||||
var proto = SaveAsImage.prototype;
|
||||
|
||||
proto.onclick = function (ecModel, api) {
|
||||
var model = this.model;
|
||||
var title = model.get('name') || ecModel.get('title.0.text') || 'echarts';
|
||||
var $a = document.createElement('a');
|
||||
var type = model.get('type', true) || 'png';
|
||||
$a.download = title + '.' + type;
|
||||
$a.target = '_blank';
|
||||
var url = api.getConnectedDataURL({
|
||||
type: type,
|
||||
backgroundColor: model.get('backgroundColor', true)
|
||||
|| ecModel.get('backgroundColor') || '#fff',
|
||||
excludeComponents: model.get('excludeComponents'),
|
||||
pixelRatio: model.get('pixelRatio')
|
||||
});
|
||||
$a.href = url;
|
||||
// Chrome and Firefox
|
||||
if (typeof MouseEvent === 'function') {
|
||||
var evt = new MouseEvent('click', {
|
||||
view: window,
|
||||
bubbles: true,
|
||||
cancelable: false
|
||||
});
|
||||
$a.dispatchEvent(evt);
|
||||
}
|
||||
// IE
|
||||
else {
|
||||
var lang = model.get('lang');
|
||||
var html = ''
|
||||
+ '<body style="margin:0;">'
|
||||
+ '<img src="' + url + '" style="max-width:100%;" title="' + ((lang && lang[0]) || '') + '" />'
|
||||
+ '</body>';
|
||||
var tab = window.open();
|
||||
tab.document.write(html);
|
||||
}
|
||||
};
|
||||
|
||||
require('../featureManager').register(
|
||||
'saveAsImage', SaveAsImage
|
||||
);
|
||||
|
||||
return SaveAsImage;
|
||||
});
|
||||
15
vendors/echarts/src/component/toolbox/featureManager.js
vendored
Normal file
15
vendors/echarts/src/component/toolbox/featureManager.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
define(function(require) {
|
||||
'use strict';
|
||||
|
||||
var features = {};
|
||||
|
||||
return {
|
||||
register: function (name, ctor) {
|
||||
features[name] = ctor;
|
||||
},
|
||||
|
||||
get: function (name) {
|
||||
return features[name];
|
||||
}
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user