Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
半栈学徒
incubator-echarts
提交
6fb4079a
I
incubator-echarts
项目概览
半栈学徒
/
incubator-echarts
与 Fork 源项目一致
从无法访问的项目Fork
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
incubator-echarts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6fb4079a
编写于
1月 09, 2018
作者:
S
sushuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support auto label and some refactor about label.
上级
8840e95b
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
108 addition
and
69 deletion
+108
-69
src/chart/bar/helper.js
src/chart/bar/helper.js
+2
-1
src/chart/custom.js
src/chart/custom.js
+3
-5
src/chart/helper/Symbol.js
src/chart/helper/Symbol.js
+3
-4
src/chart/helper/createListFromArray.js
src/chart/helper/createListFromArray.js
+3
-2
src/chart/helper/labelHelper.js
src/chart/helper/labelHelper.js
+21
-22
src/data/List.js
src/data/List.js
+8
-0
src/data/helper/completeDimensions.js
src/data/helper/completeDimensions.js
+2
-5
src/data/helper/dimensionHelper.js
src/data/helper/dimensionHelper.js
+63
-0
src/data/helper/sourceHelper.js
src/data/helper/sourceHelper.js
+0
-8
src/model/Series.js
src/model/Series.js
+3
-2
src/util/model.js
src/util/model.js
+0
-20
未找到文件。
src/chart/bar/helper.js
浏览文件 @
6fb4079a
import
*
as
graphic
from
'
../../util/graphic
'
;
import
{
getDefaultLabel
}
from
'
../helper/labelHelper
'
;
export
function
setLabel
(
normalStyle
,
hoverStyle
,
itemModel
,
color
,
seriesModel
,
dataIndex
,
labelPositionOutside
...
...
@@ -11,7 +12,7 @@ export function setLabel(
{
labelFetcher
:
seriesModel
,
labelDataIndex
:
dataIndex
,
defaultText
:
seriesModel
.
getRawValue
(
dataIndex
),
defaultText
:
getDefaultLabel
(
seriesModel
.
getData
(),
dataIndex
),
isRectText
:
true
,
autoColor
:
color
}
...
...
src/chart/custom.js
浏览文件 @
6fb4079a
...
...
@@ -2,7 +2,7 @@ import {__DEV__} from '../config';
import
*
as
echarts
from
'
../echarts
'
;
import
*
as
zrUtil
from
'
zrender/src/core/util
'
;
import
*
as
graphicUtil
from
'
../util/graphic
'
;
import
{
findLabelValueDim
}
from
'
./helper/labelHelper
'
;
import
{
getDefaultLabel
}
from
'
./helper/labelHelper
'
;
import
createListFromArray
from
'
./helper/createListFromArray
'
;
import
{
getLayoutOnAxis
}
from
'
../layout/barGrid
'
;
import
DataDiffer
from
'
../data/DataDiffer
'
;
...
...
@@ -309,7 +309,6 @@ function makeRenderItem(customSeries, data, ecModel, api) {
var
currItemModel
;
var
currLabelNormalModel
;
var
currLabelEmphasisModel
;
var
currLabelValueDim
;
var
currVisualColor
;
return
function
(
dataIndexInside
)
{
...
...
@@ -331,7 +330,6 @@ function makeRenderItem(customSeries, data, ecModel, api) {
currItemModel
=
data
.
getItemModel
(
dataIndexInside
);
currLabelNormalModel
=
currItemModel
.
getModel
(
LABEL_NORMAL
);
currLabelEmphasisModel
=
currItemModel
.
getModel
(
LABEL_EMPHASIS
);
currLabelValueDim
=
findLabelValueDim
(
data
);
currVisualColor
=
data
.
getItemVisual
(
dataIndexInside
,
'
color
'
);
currDirty
=
false
;
...
...
@@ -368,7 +366,7 @@ function makeRenderItem(customSeries, data, ecModel, api) {
var
opacity
=
data
.
getItemVisual
(
dataIndexInside
,
'
opacity
'
);
opacity
!=
null
&&
(
itemStyle
.
opacity
=
opacity
);
if
(
currLabelValueDim
!=
nul
l
)
{
if
(
!
data
.
dimensionsSummary
.
noDefaultLabe
l
)
{
graphicUtil
.
setTextStyle
(
itemStyle
,
currLabelNormalModel
,
null
,
{
autoColor
:
currVisualColor
,
isRectText
:
true
...
...
@@ -377,7 +375,7 @@ function makeRenderItem(customSeries, data, ecModel, api) {
itemStyle
.
text
=
currLabelNormalModel
.
getShallow
(
'
show
'
)
?
zrUtil
.
retrieve2
(
customSeries
.
getFormattedLabel
(
dataIndexInside
,
'
normal
'
),
data
.
get
(
currLabelValueDim
,
dataIndexInside
)
getDefaultLabel
(
data
,
dataIndexInside
)
)
:
null
;
}
...
...
src/chart/helper/Symbol.js
浏览文件 @
6fb4079a
...
...
@@ -6,7 +6,7 @@ import * as zrUtil from 'zrender/src/core/util';
import
{
createSymbol
}
from
'
../../util/symbol
'
;
import
*
as
graphic
from
'
../../util/graphic
'
;
import
{
parsePercent
}
from
'
../../util/number
'
;
import
{
findLabelValueDim
}
from
'
./labelHelper
'
;
import
{
getDefaultLabel
}
from
'
./labelHelper
'
;
function
getSymbolSize
(
data
,
idx
)
{
...
...
@@ -259,15 +259,14 @@ symbolProto._updateCommon = function (data, idx, symbolSize, seriesScope) {
}
var
useNameLabel
=
seriesScope
&&
seriesScope
.
useNameLabel
;
var
valueDim
=
!
useNameLabel
&&
findLabelValueDim
(
data
);
if
(
useNameLabel
||
valueDim
!=
nul
l
)
{
if
(
useNameLabel
||
!
data
.
dimensionsSummary
.
noDefaultLabe
l
)
{
graphic
.
setLabelStyle
(
elStyle
,
hoverItemStyle
,
labelModel
,
hoverLabelModel
,
{
labelFetcher
:
seriesModel
,
labelDataIndex
:
idx
,
defaultText
:
useNameLabel
?
data
.
getName
(
idx
)
:
data
.
get
(
valueDim
,
idx
),
defaultText
:
useNameLabel
?
data
.
getName
(
idx
)
:
getDefaultLabel
(
data
,
idx
),
isRectText
:
true
,
autoColor
:
color
}
...
...
src/chart/helper/createListFromArray.js
浏览文件 @
6fb4079a
import
*
as
zrUtil
from
'
zrender/src/core/util
'
;
import
List
from
'
../../data/List
'
;
import
createDimensions
from
'
../../data/helper/createDimensions
'
;
import
{
getDimTypeByAxis
,
SOURCE_FORMAT_ORIGINAL
}
from
'
../../data/helper/sourceHelper
'
;
import
{
SOURCE_FORMAT_ORIGINAL
}
from
'
../../data/helper/sourceHelper
'
;
import
{
getValueTypeByAxis
}
from
'
../../data/helper/dimensionHelper
'
;
import
{
getDataItemValue
}
from
'
../../util/model
'
;
import
CoordinateSystem
from
'
../../CoordinateSystem
'
;
import
{
getCoordSysDefineBySeries
}
from
'
../../model/referHelper
'
;
...
...
@@ -24,7 +25,7 @@ function createListFromArray(source, seriesModel) {
var
axisModel
=
coordSysDefine
.
axisMap
.
get
(
dim
);
if
(
axisModel
)
{
var
axisType
=
axisModel
.
get
(
'
type
'
);
dimInfo
.
type
=
get
Dim
TypeByAxis
(
axisType
);
dimInfo
.
type
=
get
Value
TypeByAxis
(
axisType
);
dimInfo
.
stackable
=
isStackable
(
axisType
);
}
return
dimInfo
;
...
...
src/chart/helper/labelHelper.js
浏览文件 @
6fb4079a
/**
* @module echarts/chart/helper/Symbol
*/
import
{
otherDimToDataDim
}
from
'
../../util/model
'
;
import
{
SOURCE_FORMAT_ORIGINAL
}
from
'
../../data/helper/sourceHelper
'
;
export
function
findLabelValueDim
(
data
)
{
var
valueDim
;
var
labelDims
=
otherDimToDataDim
(
data
,
'
label
'
);
// Get concrete dim.
function
getLabelValueDim
(
data
)
{
var
dimensionsSummary
=
data
.
dimensionsSummary
;
var
labelDims
=
dimensionsSummary
.
label
;
if
(
labelDims
.
length
)
{
valueDim
=
labelDims
[
0
];
}
else
{
// Get last value dim
var
dimensions
=
data
.
dimensions
.
slice
();
var
dataType
;
while
(
dimensions
.
length
&&
(
valueDim
=
dimensions
.
pop
(),
dataType
=
data
.
getDimensionInfo
(
valueDim
).
type
,
dataType
===
'
ordinal
'
||
dataType
===
'
time
'
))
{}
// jshint ignore:line
}
return
labelDims
[
0
]
?
labelDims
[
0
]
// Only if the source is own to a series, we can use the last.
// If the source is from dataset, it probably be shared by
// different series.
:
data
.
getProvider
().
getSource
().
sourceFormat
===
SOURCE_FORMAT_ORIGINAL
?
dimensionsSummary
.
lastValueDimension
:
null
;
}
return
valueDim
;
/**
* @param {module:echarts/data/List} data
* @param {number} dataIndex
*/
export
function
getDefaultLabel
(
data
,
dataIndex
)
{
var
val
=
data
.
get
(
getLabelValueDim
(
data
),
dataIndex
);
return
(
val
==
null
||
isNaN
(
val
))
?
''
:
val
;
}
src/data/List.js
浏览文件 @
6fb4079a
...
...
@@ -9,6 +9,7 @@ import Model from '../model/Model';
import
DataDiffer
from
'
./DataDiffer
'
;
import
Source
from
'
./Source
'
;
import
{
defaultDimValueGetters
,
DefaultDataProvider
}
from
'
./helper/dataProvider
'
;
import
{
summarizeDimensions
}
from
'
./helper/dimensionHelper
'
;
var
isObject
=
zrUtil
.
isObject
;
...
...
@@ -250,6 +251,13 @@ var List = function (dimensions, hostModel) {
* @private
*/
this
.
_approximateExtent
=
{};
/**
* Cache summary info for fast visit. See "dimensionHelper".
* @readOnly
* @type {Object}
*/
this
.
dimensionsSummary
=
summarizeDimensions
(
this
);
};
var
listProto
=
List
.
prototype
;
...
...
src/data/helper/completeDimensions.js
浏览文件 @
6fb4079a
...
...
@@ -8,15 +8,12 @@ import * as zrUtil from 'zrender/src/core/util';
import
{
normalizeToArray
}
from
'
../../util/model
'
;
import
{
guessOrdinal
}
from
'
./sourceHelper
'
;
import
Source
from
'
../Source
'
;
import
{
SPECIAL_DIMENSIONS
}
from
'
./dimensionHelper
'
;
var
each
=
zrUtil
.
each
;
var
isString
=
zrUtil
.
isString
;
var
defaults
=
zrUtil
.
defaults
;
var
OTHER_DIMS
=
zrUtil
.
createHashMap
({
tooltip
:
1
,
label
:
1
,
itemName
:
1
,
seriesName
:
1
});
/**
* @see {module:echarts/test/ut/spec/data/completeDimensions}
*
...
...
@@ -146,7 +143,7 @@ function completeDimensions(sysDims, source, opt) {
});
function
applyDim
(
resultItem
,
coordDim
,
coordDimIndex
)
{
if
(
OTHER_DIMS
.
get
(
coordDim
)
)
{
if
(
SPECIAL_DIMENSIONS
.
get
(
coordDim
)
!=
null
)
{
resultItem
.
otherDims
[
coordDim
]
=
coordDimIndex
;
}
else
{
...
...
src/data/helper/dimensionHelper.js
0 → 100644
浏览文件 @
6fb4079a
import
{
each
,
createHashMap
}
from
'
zrender/src/core/util
'
;
export
var
SPECIAL_DIMENSIONS
=
createHashMap
([
'
tooltip
'
,
'
label
'
,
'
itemName
'
,
'
seriesName
'
]);
/**
* Summarize and cache for avoiding repeat calculation while travel data.
* @return {Object}
* {
* each of SPECIAL_DIMENSIONS in concrete dim. Array not null/undefined.
* lastValueDimension: a set of DIMENSION_TYPES in concrete dim. Array not null/undefined.
* }
*/
export
function
summarizeDimensions
(
data
)
{
var
summary
=
{};
SPECIAL_DIMENSIONS
.
each
(
function
(
v
,
dimType
)
{
summary
[
dimType
]
=
otherDimToDataDim
(
data
,
dimType
);
});
summary
.
lastValueDimension
=
findTheLastValueDimensions
(
data
);
summary
.
noDefaultLabel
=
!
(
summary
.
label
[
0
]
||
summary
.
lastValueDimension
);
return
summary
;
}
/**
* @see {module:echarts/data/helper/createDimensions}
* @param {module:echarts/data/List} data
* @param {string} otherDim See OTHER_DIMS
* @return {Array.<string>} data dimensions on the otherDim.
*/
export
function
otherDimToDataDim
(
data
,
otherDim
)
{
var
dataDim
=
[];
each
(
data
.
dimensions
,
function
(
dimName
)
{
var
dimItem
=
data
.
getDimensionInfo
(
dimName
);
var
otherDims
=
dimItem
.
otherDims
;
var
dimIndex
=
otherDims
[
otherDim
];
if
(
dimIndex
!=
null
&&
dimIndex
!==
false
)
{
dataDim
[
dimIndex
]
=
dimItem
.
name
;
}
});
return
dataDim
;
}
export
function
getValueTypeByAxis
(
axisType
)
{
return
axisType
===
'
category
'
?
'
ordinal
'
:
axisType
===
'
time
'
?
'
time
'
:
'
float
'
;
}
function
findTheLastValueDimensions
(
data
)
{
// Get last value dim
var
dimensions
=
data
.
dimensions
.
slice
();
var
valueType
;
var
valueDim
;
while
(
dimensions
.
length
&&
(
valueDim
=
dimensions
.
pop
(),
valueType
=
data
.
getDimensionInfo
(
valueDim
).
type
,
valueType
===
'
ordinal
'
||
valueType
===
'
time
'
))
{}
// jshint ignore:line
return
valueDim
;
}
src/data/helper/sourceHelper.js
浏览文件 @
6fb4079a
...
...
@@ -416,11 +416,3 @@ export function guessOrdinal(source, dimIndex, dimName) {
return
false
;
}
export
function
getDimTypeByAxis
(
axisType
)
{
return
axisType
===
'
category
'
?
'
ordinal
'
:
axisType
===
'
time
'
?
'
time
'
:
'
float
'
;
}
src/model/Series.js
浏览文件 @
6fb4079a
...
...
@@ -19,6 +19,7 @@ import {
prepareSource
,
getSource
}
from
'
../data/helper/sourceHelper
'
;
import
{
otherDimToDataDim
}
from
'
../data/helper/dimensionHelper
'
;
var
inner
=
modelUtil
.
makeInner
();
...
...
@@ -280,7 +281,7 @@ var SeriesModel = ComponentModel.extend({
},
0
);
var
result
=
[];
var
tooltipDims
=
modelUtil
.
otherDimToDataDim
(
data
,
'
tooltip
'
);
var
tooltipDims
=
otherDimToDataDim
(
data
,
'
tooltip
'
);
tooltipDims
.
length
?
zrUtil
.
each
(
tooltipDims
,
function
(
dimIdx
)
{
...
...
@@ -431,7 +432,7 @@ function autoSeriesName(seriesModel) {
function
getSeriesAutoName
(
seriesModel
)
{
var
data
=
seriesModel
.
getRawData
();
var
dataDims
=
modelUtil
.
otherDimToDataDim
(
data
,
'
seriesName
'
);
var
dataDims
=
otherDimToDataDim
(
data
,
'
seriesName
'
);
var
nameArr
=
[];
zrUtil
.
each
(
dataDims
,
function
(
dataDim
)
{
var
dimInfo
=
data
.
getDimensionInfo
(
dataDim
);
...
...
src/util/model.js
浏览文件 @
6fb4079a
...
...
@@ -636,26 +636,6 @@ export function coordDimToDataDim(data, coordDim) {
return
dataDim
;
}
/**
* @see {module:echarts/data/helper/createDimensions}
* @param {module:echarts/data/List} data
* @param {string} otherDim Can be `otherDims`
* like 'label' or 'tooltip'.
* @return {Array.<string>} data dimensions on the otherDim.
*/
export
function
otherDimToDataDim
(
data
,
otherDim
)
{
var
dataDim
=
[];
each
(
data
.
dimensions
,
function
(
dimName
)
{
var
dimItem
=
data
.
getDimensionInfo
(
dimName
);
var
otherDims
=
dimItem
.
otherDims
;
var
dimIndex
=
otherDims
[
otherDim
];
if
(
dimIndex
!=
null
&&
dimIndex
!==
false
)
{
dataDim
[
dimIndex
]
=
dimItem
.
name
;
}
});
return
dataDim
;
}
function
has
(
obj
,
prop
)
{
return
obj
&&
obj
.
hasOwnProperty
(
prop
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录