Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
半栈学徒
incubator-echarts
提交
2ff07072
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,体验更适合开发者的 AI 搜索 >>
提交
2ff07072
编写于
2月 25, 2016
作者:
L
lang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add List#downSample
上级
b01ccf9e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
74 addition
and
31 deletion
+74
-31
src/data/List.js
src/data/List.js
+74
-31
未找到文件。
src/data/List.js
浏览文件 @
2ff07072
...
...
@@ -663,49 +663,53 @@ define(function (require) {
return
result
;
};
/**
* Data mapping to a new List with given dimensions
* @param {string|Array.<string>} dimensions
* @param {Function} cb
* @param {boolean} [stack=false]
* @param {*} [context=this]
* @return {Array}
*/
listProto
.
map
=
function
(
dimensions
,
cb
,
stack
,
context
)
{
dimensions
=
zrUtil
.
map
(
normalizeDimensions
(
dimensions
),
this
.
getDimension
,
this
);
function
cloneListForMapAndSample
(
original
,
excludeDimensions
)
{
var
allDimensions
=
this
.
dimensions
;
var
list
=
new
List
(
zrUtil
.
map
(
allDimensions
,
this
.
getDimensionInfo
,
this
),
this
.
hostModel
);
// Following properties are all immutable.
// So we can reference to the same value
var
indices
=
list
.
indices
=
this
.
indices
;
// FIXME If needs stackedOn, value may already been stacked
transferImmuProperties
(
list
,
this
,
this
.
_wrappedMethods
);
transferImmuProperties
(
list
,
original
,
original
.
_wrappedMethods
);
var
storage
=
list
.
_storage
=
{};
var
thisStorage
=
this
.
_storage
;
var
originalStorage
=
original
.
_storage
;
// Init storage
for
(
var
i
=
0
;
i
<
allDimensions
.
length
;
i
++
)
{
var
dim
=
allDimensions
[
i
];
var
dimStore
=
this
Storage
[
dim
];
if
(
zrUtil
.
indexOf
(
d
imensions
,
dim
)
>=
0
)
{
var
dimStore
=
original
Storage
[
dim
];
if
(
zrUtil
.
indexOf
(
excludeD
imensions
,
dim
)
>=
0
)
{
storage
[
dim
]
=
new
dimStore
.
constructor
(
this
Storage
[
dim
].
length
original
Storage
[
dim
].
length
);
}
else
{
// Direct
copy
for other dimensions
storage
[
dim
]
=
this
Storage
[
dim
];
// Direct
reference
for other dimensions
storage
[
dim
]
=
original
Storage
[
dim
];
}
}
return
list
;
}
/**
* Data mapping to a new List with given dimensions
* @param {string|Array.<string>} dimensions
* @param {Function} cb
* @param {boolean} [stack=false]
* @param {*} [context=this]
* @return {Array}
*/
listProto
.
map
=
function
(
dimensions
,
cb
,
stack
,
context
)
{
dimensions
=
zrUtil
.
map
(
normalizeDimensions
(
dimensions
),
this
.
getDimension
,
this
);
var
list
=
cloneListForMapAndSample
(
this
,
dimensions
);
// Following properties are all immutable.
// So we can reference to the same value
var
indices
=
list
.
indices
=
this
.
indices
;
var
storage
=
list
.
_storage
;
var
tmpRetValue
=
[];
this
.
each
(
dimensions
,
function
()
{
...
...
@@ -731,11 +735,50 @@ define(function (require) {
return
list
;
};
// Since temporate model is shared by all data items. So we must make sure it can't be write.
// PENDING may cause any performance problem?
// if (Object.freeze) {
// Object.freeze(temporaryModel);
// }
/**
* Large data down sampling on given dimension
* @param {string} dimension
* @param {number} rate
* @param {Function} sampleValue
* @param {Function} sampleIndex Sample index for name and id
*/
listProto
.
downSample
=
function
(
dimension
,
rate
,
sampleValue
,
sampleIndex
)
{
var
list
=
cloneListForMapAndSample
(
this
,
[
dimension
]);
var
storage
=
this
.
_storage
;
var
targetStorage
=
list
.
_storage
;
var
originalIndices
=
this
.
indices
;
var
indices
=
list
.
indices
=
[];
var
frameValues
=
[];
var
frameIndices
=
[];
var
frameSize
=
Math
.
floor
(
1
/
rate
);
var
dimStore
=
targetStorage
[
dimension
];
var
len
=
this
.
count
();
// Copy data from original data
for
(
var
i
=
0
;
i
<
storage
[
dimension
].
length
;
i
++
)
{
targetStorage
[
dimension
][
i
]
=
storage
[
dimension
][
i
];
}
for
(
var
i
=
0
;
i
<
len
;
i
+=
frameSize
)
{
// Last frame
if
(
frameSize
>
len
-
i
)
{
frameSize
=
len
-
i
;
frameValues
.
length
=
frameSize
;
}
for
(
var
k
=
0
;
k
<
frameSize
;
k
++
)
{
frameValues
[
k
]
=
dimStore
[
i
+
k
];
frameIndices
[
k
]
=
originalIndices
[
i
+
k
];
}
var
value
=
sampleValue
(
frameValues
);
var
idx
=
frameIndices
[
sampleIndex
(
frameValues
,
value
)
||
0
];
// Only write value on the filtered data
dimStore
[
idx
]
=
value
;
indices
.
push
(
idx
);
}
return
list
;
};
/**
* Get model of one data item.
*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录