提交 2a2af15d 编写于 作者: P pah100

datarange fix. and remove api from model. and rename...

datarange  fix.             and  remove api from  model.       and rename 'event' to 'payload' in action
上级 146ab530
...@@ -121,8 +121,14 @@ define(function(require) { ...@@ -121,8 +121,14 @@ define(function(require) {
*/ */
getValueState: function (value) { getValueState: function (value) {
var range = this.option.range; var range = this.option.range;
return (range[0] <= value && value <= range[1]) var dataExtent = this.getExtent();
? 'inRange' : 'outOfRange';
// When range[0] === dataExtent[0], any value larger than dataExtent[0] maps to 'inRange'.
// range[1] is processed likewise.
return (
(range[0] <= dataExtent[0] || range[0] <= value)
&& (range[1] >= dataExtent[1] || value <= range[1])
) ? 'inRange' : 'outOfRange';
} }
}); });
......
...@@ -58,8 +58,8 @@ define(function(require) { ...@@ -58,8 +58,8 @@ define(function(require) {
* @protected * @protected
* @override * @override
*/ */
doRender: function (dataRangeModel, ecModel, api, event) { doRender: function (dataRangeModel, ecModel, api, payload) {
if (!event || event.type !== 'dataRangeSelected' || event.from !== this.uid) { if (!payload || payload.type !== 'selectDataRange' || payload.from !== this.uid) {
this._buildView(); this._buildView();
} }
else { else {
...@@ -84,15 +84,19 @@ define(function(require) { ...@@ -84,15 +84,19 @@ define(function(require) {
this._renderBar(thisGroup); this._renderBar(thisGroup);
var dataRangeText = dataRangeModel.get('text'); var dataRangeText = dataRangeModel.get('text');
dataRangeText && this._renderEndsText(thisGroup, dataRangeText, 0); this._renderEndsText(thisGroup, dataRangeText, 0);
dataRangeText && this._renderEndsText(thisGroup, dataRangeText, 1); this._renderEndsText(thisGroup, dataRangeText, 1);
// Do this for background size calculation.
this._updateView(true);
// After updating view, inner shapes is built completely, // After updating view, inner shapes is built completely,
// and then background can be rendered. // and then background can be rendered.
this._updateView();
this.renderBackground(thisGroup); this.renderBackground(thisGroup);
// Real update view
this._updateView();
this.positionGroup(thisGroup); this.positionGroup(thisGroup);
}, },
...@@ -100,7 +104,12 @@ define(function(require) { ...@@ -100,7 +104,12 @@ define(function(require) {
* @private * @private
*/ */
_renderEndsText: function (group, dataRangeText, endsIndex) { _renderEndsText: function (group, dataRangeText, endsIndex) {
var text = dataRangeText[endsIndex]; if (!dataRangeText) {
return;
}
// Compatible with ec2, text[0] map to high value, text[1] map low value.
var text = dataRangeText[1 - endsIndex];
text = text != null ? text + '' : ''; text = text != null ? text + '' : '';
var dataRangeModel = this.dataRangeModel; var dataRangeModel = this.dataRangeModel;
...@@ -164,8 +173,6 @@ define(function(require) { ...@@ -164,8 +173,6 @@ define(function(require) {
// Handle // Handle
if (useHandle) { if (useHandle) {
var handleEndsMax = [0, itemSize[1]];
shapes.handleGroups = []; shapes.handleGroups = [];
shapes.handleThumbs = []; shapes.handleThumbs = [];
shapes.handleLabels = []; shapes.handleLabels = [];
...@@ -173,9 +180,6 @@ define(function(require) { ...@@ -173,9 +180,6 @@ define(function(require) {
this._createHandle(barGroup, 0, itemSize, textSize, orient, itemAlign); this._createHandle(barGroup, 0, itemSize, textSize, orient, itemAlign);
this._createHandle(barGroup, 1, itemSize, textSize, orient, itemAlign); this._createHandle(barGroup, 1, itemSize, textSize, orient, itemAlign);
// Do this for background size calculation.
this._updateHandlePosition(handleEndsMax);
} }
// Indicator // Indicator
...@@ -313,14 +317,21 @@ define(function(require) { ...@@ -313,14 +317,21 @@ define(function(require) {
/** /**
* @private * @private
*/ */
_updateView: function () { _updateView: function (forSketch) {
var dataRangeModel = this.dataRangeModel; var dataRangeModel = this.dataRangeModel;
var dataExtent = dataRangeModel.getExtent(); var dataExtent = dataRangeModel.getExtent();
var shapes = this._shapes; var shapes = this._shapes;
var dataInterval = this._dataInterval; var dataInterval = this._dataInterval;
var visualInRange = this._createBarVisual(dataInterval, dataExtent); var outOfRangeHandleEnds = [0, dataRangeModel.itemSize[1]];
var visualOutOfRange = this._createBarVisual(dataExtent, dataExtent, 'outOfRange'); var inRangeHandleEnds = forSketch ? outOfRangeHandleEnds : this._handleEnds;
var visualInRange = this._createBarVisual(
dataInterval, dataExtent, inRangeHandleEnds, 'inRange'
);
var visualOutOfRange = this._createBarVisual(
dataExtent, dataExtent, outOfRangeHandleEnds, 'outOfRange'
);
shapes.inRange shapes.inRange
.setStyle('fill', visualInRange.barColor) .setStyle('fill', visualInRange.barColor)
...@@ -347,52 +358,42 @@ define(function(require) { ...@@ -347,52 +358,42 @@ define(function(require) {
}, this); }, this);
this._updateHandlePosition(visualInRange.handleEnds); this._updateHandlePosition(inRangeHandleEnds);
}, },
/** /**
* @private * @private
*/ */
_createBarVisual: function (dataInterval, dataExtent, forceState) { _createBarVisual: function (dataInterval, dataExtent, handleEnds, forceState) {
var handleEnds = forceState var colorStops = this.getControllerVisual(dataInterval, forceState, 'color').color;
? [0, this.dataRangeModel.itemSize[1]]
: this._handleEnds;
var visuals = [
this.getControllerVisual(dataInterval[0], forceState),
this.getControllerVisual(dataInterval[1], forceState)
];
var colorStops = [];
var handles = [];
each(dataInterval, function (value, index) {
colorStops.push({offset: index, color: visuals[index].color});
handles.push(visuals[index].color);
});
var barPoints = this._createBarPoints(handleEnds, visuals); var symbolSizes = [
this.getControllerVisual(dataInterval[0], forceState, 'symbolSize').symbolSize,
this.getControllerVisual(dataInterval[1], forceState, 'symbolSize').symbolSize
];
var barPoints = this._createBarPoints(handleEnds, symbolSizes);
return { return {
barColor: new LinearGradient(0, 0, 1, 1, colorStops), barColor: new LinearGradient(0, 0, 1, 1, colorStops),
barPoints: barPoints, barPoints: barPoints,
handlesColor: handles, handlesColor: [
handleEnds: handleEnds colorStops[0].color,
colorStops[colorStops.length - 1].color
]
}; };
}, },
/** /**
* @private * @private
*/ */
_createBarPoints: function (handleEnds, visuals) { _createBarPoints: function (handleEnds, symbolSizes) {
var itemSize = this.dataRangeModel.itemSize; var itemSize = this.dataRangeModel.itemSize;
var widths0 = visuals[0].symbolSize;
var widths1 = visuals[1].symbolSize;
return [ return [
[itemSize[0] - widths0, handleEnds[0]], [itemSize[0] - symbolSizes[0], handleEnds[0]],
[itemSize[0], handleEnds[0]], [itemSize[0], handleEnds[0]],
[itemSize[0], handleEnds[1]], [itemSize[0], handleEnds[1]],
[itemSize[0] - widths1, handleEnds[1]] [itemSize[0] - symbolSizes[1], handleEnds[1]]
]; ];
}, },
...@@ -428,7 +429,7 @@ define(function(require) { ...@@ -428,7 +429,7 @@ define(function(require) {
var handleGroup = shapes.handleGroups[handleIndex]; var handleGroup = shapes.handleGroups[handleIndex];
handleGroup.position[1] = handleEnds[handleIndex]; handleGroup.position[1] = handleEnds[handleIndex];
// Update handle label location // Update handle label position.
var labelPoint = shapes.handleLabelPoints[handleIndex]; var labelPoint = shapes.handleLabelPoints[handleIndex];
var textPoint = modelUtil.applyTransform( var textPoint = modelUtil.applyTransform(
[labelPoint.x, labelPoint.y], [labelPoint.x, labelPoint.y],
......
...@@ -74,9 +74,9 @@ define(function(require) { ...@@ -74,9 +74,9 @@ define(function(require) {
itemWidth: null, // 值域图形宽度 itemWidth: null, // 值域图形宽度
itemHeight: null, // 值域图形高度 itemHeight: null, // 值域图形高度
precision: 0, // 小数精度,默认为0,无小数点 precision: 0, // 小数精度,默认为0,无小数点
color: ['#e0ffff', '#006edd'],//颜色(deprecated,兼容ec2 color: ['#e0ffff', '#006edd'], //颜色(deprecated,兼容ec2,对应数值由高到低
// formatter: null, // formatter: null,
// text:['高','低'], // 文本,默认为数值文本 text: null, // 文本,如['高', '低'],兼容ec2,text[0]对应高值,text[1]对应低值
textStyle: { textStyle: {
color: '#333' // 值域文字颜色 color: '#333' // 值域文字颜色
} }
...@@ -320,12 +320,14 @@ define(function(require) { ...@@ -320,12 +320,14 @@ define(function(require) {
function completeSingle(base) { function completeSingle(base) {
// Compatible with ec2 dataRange.color. // Compatible with ec2 dataRange.color.
// The mapping order of dataRange.color is: [high value, ..., low value]
// whereas inRange.color and outOfRange.color is [low value, ..., high value]
if (zrUtil.isArray(thisOption.color) if (zrUtil.isArray(thisOption.color)
// If there has been inRange: {symbol: ...}, adding color is a mistake. // If there has been inRange: {symbol: ...}, adding color is a mistake.
// So adding color only when no inRange defined. // So adding color only when no inRange defined.
&& !base.inRange && !base.inRange
) { ) {
base.inRange = {color: thisOption.color.slice()}; base.inRange = {color: thisOption.color.slice().reverse()};
} }
// If using shortcut like: {inRange: 'symbol'}, complete default value. // If using shortcut like: {inRange: 'symbol'}, complete default value.
...@@ -420,11 +422,7 @@ define(function(require) { ...@@ -420,11 +422,7 @@ define(function(require) {
* @protected * @protected
*/ */
resetItemSize: function () { resetItemSize: function () {
var api = this.api; this.itemSize = [+this.get('itemWidth'), +this.get('itemHeight')];
this.itemSize = [
parsePercent(this.get('itemWidth'), api.getWidth()),
parsePercent(this.get('itemHeight'), api.getHeight())
];
}, },
/** /**
......
...@@ -46,7 +46,7 @@ define(function (require) { ...@@ -46,7 +46,7 @@ define(function (require) {
/** /**
* @protected * @protected
*/ */
render: function (dataRangeModel, ecModel, api, event) { render: function (dataRangeModel, ecModel, api, payload) {
this.dataRangeModel = dataRangeModel; this.dataRangeModel = dataRangeModel;
if (dataRangeModel.get('show') === false) { if (dataRangeModel.get('show') === false) {
...@@ -84,15 +84,29 @@ define(function (require) { ...@@ -84,15 +84,29 @@ define(function (require) {
/** /**
* @protected * @protected
* @param {(number|Array)} targetValue
* @param {string=} forceState Specify state, instead of using getValueState method.
* @param {string=} visualType Specify visual type, defualt all available visualTypes.
*/ */
getControllerVisual: function (representValue, forceState) { getControllerVisual: function (targetValue, forceState, visualType) {
var dataRangeModel = this.dataRangeModel; var dataRangeModel = this.dataRangeModel;
var targetIsArray = zrUtil.isArray(targetValue);
// targetValue is array when caculate gradient color,
// where forceState is required.
if (targetIsArray && (!forceState || visualType !== 'color')) {
throw new Error(targetValue);
}
var mappings = dataRangeModel.controllerVisuals[ var mappings = dataRangeModel.controllerVisuals[
forceState || dataRangeModel.getValueState(representValue) forceState || dataRangeModel.getValueState(targetValue)
]; ];
var defaultColor = dataRangeModel.get('contentColor');
var visualObj = { var visualObj = {
symbol: dataRangeModel.get('itemSymbol'), symbol: dataRangeModel.get('itemSymbol'),
color: dataRangeModel.get('contentColor') color: targetIsArray
? [{color: defaultColor, offset: 0}, {color: defaultColor, offset: 1}]
: defaultColor
}; };
function getter(key) { function getter(key) {
...@@ -105,10 +119,12 @@ define(function (require) { ...@@ -105,10 +119,12 @@ define(function (require) {
: (visualObj[key] = value); : (visualObj[key] = value);
} }
zrUtil.each(mappings, function (visualMapping) { zrUtil.each(mappings, function (visualMapping, type) {
visualMapping && visualMapping.applyVisual( (!visualType || type === visualType)
representValue, getter, setter && visualMapping
); && visualMapping.applyVisual(
targetValue, getter, setter
);
}); });
return visualObj; return visualObj;
......
...@@ -19,7 +19,7 @@ define(function(require) { ...@@ -19,7 +19,7 @@ define(function(require) {
itemWidth: 20, // 值域图形宽度,线性渐变水平布局宽度为该值 * 10 itemWidth: 20, // 值域图形宽度,线性渐变水平布局宽度为该值 * 10
itemHeight: 14, // 值域图形高度,线性渐变垂直布局高度为该值 * 10 itemHeight: 14, // 值域图形高度,线性渐变垂直布局高度为该值 * 10
itemSymbol: 'roundRect', itemSymbol: 'roundRect',
splitList: null, splitList: null, // 值顺序:由高到低
selectedMode: 'multiple', selectedMode: 'multiple',
itemGap: 10 // 各个item之间的间隔,单位px,默认为10, itemGap: 10 // 各个item之间的间隔,单位px,默认为10,
// 横向布局时为水平间隔,纵向布局时为纵向间隔 // 横向布局时为水平间隔,纵向布局时为纵向间隔
...@@ -32,6 +32,7 @@ define(function(require) { ...@@ -32,6 +32,7 @@ define(function(require) {
this.baseMergeOption(newOption); this.baseMergeOption(newOption);
/** /**
* Compatible with ec2, value order is [high, ..., low]
* [{text: string, interval: Array.<number>}, ...] * [{text: string, interval: Array.<number>}, ...]
* *
* @private * @private
......
...@@ -23,18 +23,19 @@ define(function(require) { ...@@ -23,18 +23,19 @@ define(function(require) {
var api = this.api; var api = this.api;
var ecWidth = api.getWidth(); var ecWidth = api.getWidth();
var textGap = dataRangeModel.get('textGap'); var textGap = dataRangeModel.get('textGap');
var dataRangeText = dataRangeModel.get('text');
var font = dataRangeModel.textStyleModel.getFont(); var font = dataRangeModel.textStyleModel.getFont();
var showLabel = !dataRangeText;
var showEndsText = !showLabel;
var itemAlign = this.getItemAlignByOrient('horizontal', ecWidth); var itemAlign = this.getItemAlignByOrient('horizontal', ecWidth);
var itemSize = dataRangeModel.itemSize; var itemSize = dataRangeModel.itemSize;
showEndsText && this._renderEndsText(thisGroup, dataRangeText[0], itemSize); var viewData = this._getViewData();
var showLabel = !viewData.endsText;
var showEndsText = !showLabel;
showEndsText && this._renderEndsText(thisGroup, viewData.endsText[1], itemSize);
zrUtil.each(this._getViewPieceList(), renderItem, this); zrUtil.each(viewData.pieceList, renderItem, this);
showEndsText && this._renderEndsText(thisGroup, dataRangeText[1], itemSize); showEndsText && this._renderEndsText(thisGroup, viewData.endsText[0], itemSize);
layout.box( layout.box(
dataRangeModel.get('orient'), thisGroup, dataRangeModel.get('itemGap') dataRangeModel.get('orient'), thisGroup, dataRangeModel.get('itemGap')
...@@ -91,20 +92,30 @@ define(function(require) { ...@@ -91,20 +92,30 @@ define(function(require) {
/** /**
* @private * @private
* @return {Object} {peiceList, endsText} value order is [low, ..., high]
*/ */
_getViewPieceList: function () { _getViewData: function () {
var dataRangeModel = this.dataRangeModel; var dataRangeModel = this.dataRangeModel;
var list = zrUtil.map(dataRangeModel.getPieceList(), function (piece, index) {
var pieceList = zrUtil.map(dataRangeModel.getPieceList(), function (piece, index) {
return {piece: piece, index: index}; return {piece: piece, index: index};
}); });
var endsText = dataRangeModel.get('text');
// Consider orient and inverse.
var orient = dataRangeModel.get('orient'); var orient = dataRangeModel.get('orient');
var inverse = dataRangeModel.get('inverse'); var inverse = dataRangeModel.get('inverse');
if (orient === 'horizontal' ? inverse : !inverse) { if (orient === 'horizontal' ? inverse : !inverse) {
list.reverse(); // Value order of pieceList is [high, ..., low]
pieceList.reverse();
// Value order of endsText is [high, low]
if (endsText) {
endsText = endsText.slice().reverse();
}
} }
return list; return {pieceList: pieceList, endsText: endsText};
}, },
/** /**
......
...@@ -86,7 +86,7 @@ define(function (require) { ...@@ -86,7 +86,7 @@ define(function (require) {
this.api = api; this.api = api;
}, },
render: function (dataZoomModel, ecModel, api, event) { render: function (dataZoomModel, ecModel, api, payload) {
this.dataZoomModel = dataZoomModel; this.dataZoomModel = dataZoomModel;
this.ecModel = ecModel; this.ecModel = ecModel;
this._orient = dataZoomModel.get('orient'); this._orient = dataZoomModel.get('orient');
...@@ -97,7 +97,7 @@ define(function (require) { ...@@ -97,7 +97,7 @@ define(function (require) {
return; return;
} }
if (!event || event.type !== 'dataZoom' || event.from !== this.uid) { if (!payload || payload.type !== 'dataZoom' || payload.from !== this.uid) {
this._buildView(); this._buildView();
} }
......
...@@ -124,9 +124,7 @@ define(function (require) { ...@@ -124,9 +124,7 @@ define(function (require) {
var ecModel = this._model; var ecModel = this._model;
if (!ecModel || notMerge) { if (!ecModel || notMerge) {
ecModel = new GlobalModel( ecModel = new GlobalModel(option, null, this._theme);
option, null, this._theme, this._extensionAPI
);
this._model = ecModel; this._model = ecModel;
} }
else { else {
...@@ -210,15 +208,15 @@ define(function (require) { ...@@ -210,15 +208,15 @@ define(function (require) {
/** /**
* @pubilc * @pubilc
* @param {Object} event * @param {Object} payload
* @param {string} [event.type] Event type * @param {string} [payload.type] Event type
* @param {number} [event.from] From uid * @param {number} [payload.from] From uid
*/ */
dispatch: function (event) { dispatch: function (payload) {
var action = actions[event.type]; var action = actions[payload.type];
if (action) { if (action) {
action(event, this._model); action(payload, this._model);
this.updateImmediately(event); this.updateImmediately(payload);
} }
}, },
......
...@@ -47,11 +47,6 @@ define(function(require) { ...@@ -47,11 +47,6 @@ define(function(require) {
*/ */
uid: null, uid: null,
/**
* @readOnly
*/
api: null,
init: function () { init: function () {
this.mergeDefaultAndTheme(this.option, this.ecModel); this.mergeDefaultAndTheme(this.option, this.ecModel);
}, },
...@@ -85,11 +80,10 @@ define(function(require) { ...@@ -85,11 +80,10 @@ define(function(require) {
// Reset ComponentModel.extend, add preConstruct. // Reset ComponentModel.extend, add preConstruct.
componentUtil.enableClassExtend( componentUtil.enableClassExtend(
ComponentModel, ComponentModel,
function (option, parentModel, ecModel, dependentModels, index, api) { function (option, parentModel, ecModel, dependentModels) {
this.ecModel = ecModel; this.ecModel = ecModel;
this.dependentModels = dependentModels; this.dependentModels = dependentModels;
this.uid = componentUtil.getUID('componentModel'); this.uid = componentUtil.getUID('componentModel');
this.api = api;
} }
); );
......
...@@ -27,12 +27,11 @@ define(function (require) { ...@@ -27,12 +27,11 @@ define(function (require) {
constructor: GlobalModel, constructor: GlobalModel,
init: function (option, parentModel, theme, api) { init: function (option, parentModel, theme) {
theme = theme || {}; theme = theme || {};
this.option = {}; this.option = {};
this.api = api;
/** /**
* @type {Array.<module:echarts/model/Model} * @type {Array.<module:echarts/model/Model}
...@@ -152,7 +151,7 @@ define(function (require) { ...@@ -152,7 +151,7 @@ define(function (require) {
// PENDING Global as parent ? // PENDING Global as parent ?
componentModel = new ComponentModelClass( componentModel = new ComponentModelClass(
newCptOptionList[i], this, this, newCptOptionList[i], this, this,
this._getComponentsByTypes(dependencies), i, this.api this._getComponentsByTypes(dependencies), i
); );
componentsMap[componentType][i] = componentModel; componentsMap[componentType][i] = componentModel;
......
...@@ -71,12 +71,24 @@ define(function (require) { ...@@ -71,12 +71,24 @@ define(function (require) {
}, },
mapValueToVisual: function (value) { mapValueToVisual: function (value) {
var normalized = this._normalizeData(value); var optionData = this.option.data;
var specifiedVisual = this._getIntervalVisual(normalized);
if (zrUtil.isArray(value)) {
value = [
this._normalizeData(value[0]),
this._normalizeData(value[1])
];
// For creating graduate color list.
return zrColor.mapIntervalToColor(value, optionData);
}
else {
var normalized = this._normalizeData(value);
var specifiedVisual = this._getIntervalVisual(normalized);
return specifiedVisual != null return specifiedVisual != null
? specifiedVisual ? specifiedVisual
: zrColor.mapToColor(normalized, this.option.data); : zrColor.mapToColor(normalized, optionData);
}
} }
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册