You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by wa...@apache.org on 2021/04/07 02:20:28 UTC
[echarts] branch fix-linear-gradient created (now 10c9f79)
This is an automated email from the ASF dual-hosted git repository.
wangzx pushed a change to branch fix-linear-gradient
in repository https://gitbox.apache.org/repos/asf/echarts.git.
at 10c9f79 fix(linear-gradient): avoid the Infinite value in `linearMap` util, fix #7293, #14534, #14601.
This branch includes the following new commits:
new 10c9f79 fix(linear-gradient): avoid the Infinite value in `linearMap` util, fix #7293, #14534, #14601.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[echarts] 01/01: fix(linear-gradient): avoid the Infinite value in
`linearMap` util, fix #7293, #14534, #14601.
Posted by wa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
wangzx pushed a commit to branch fix-linear-gradient
in repository https://gitbox.apache.org/repos/asf/echarts.git
commit 10c9f7997040bc651d82ee69ac26385b46c6a9b8
Author: plainheart <yh...@all-my-life.cn>
AuthorDate: Wed Apr 7 10:18:19 2021 +0800
fix(linear-gradient): avoid the Infinite value in `linearMap` util, fix #7293, #14534, #14601.
---
src/util/number.ts | 42 +++++----
test/linear-gradient.html | 229 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 254 insertions(+), 17 deletions(-)
diff --git a/src/util/number.ts b/src/util/number.ts
index 735c5be..d9e3815 100644
--- a/src/util/number.ts
+++ b/src/util/number.ts
@@ -47,13 +47,21 @@ export function linearMap(
range: number[],
clamp?: boolean
): number {
- const subDomain = domain[1] - domain[0];
- const subRange = range[1] - range[0];
+ const d0 = domain[0];
+ const d1 = domain[1];
+ const r0 = range[0];
+ const r1 = range[1];
+
+ const subDomain = d1 - d0;
+ const subRange = r1 - r0;
+
+ // avoid the infinite number
+ isFinite(val) || (val = val > 0 ? r1 : r0);
if (subDomain === 0) {
return subRange === 0
- ? range[0]
- : (range[0] + range[1]) / 2;
+ ? r0
+ : (r0 + r1) / 2;
}
// Avoid accuracy problem in edge, such as
@@ -63,32 +71,32 @@ export function linearMap(
// is a hotspot.
if (clamp) {
if (subDomain > 0) {
- if (val <= domain[0]) {
- return range[0];
+ if (val <= d0) {
+ return r0;
}
- else if (val >= domain[1]) {
- return range[1];
+ else if (val >= d1) {
+ return r1;
}
}
else {
- if (val >= domain[0]) {
- return range[0];
+ if (val >= d0) {
+ return r0;
}
- else if (val <= domain[1]) {
- return range[1];
+ else if (val <= d1) {
+ return r1;
}
}
}
else {
- if (val === domain[0]) {
- return range[0];
+ if (val === d0) {
+ return r0;
}
- if (val === domain[1]) {
- return range[1];
+ if (val === d1) {
+ return r1;
}
}
- return (val - domain[0]) / subDomain * subRange + range[0];
+ return (val - d0) / subDomain * subRange + r0;
}
/**
diff --git a/test/linear-gradient.html b/test/linear-gradient.html
new file mode 100644
index 0000000..e8a79e7
--- /dev/null
+++ b/test/linear-gradient.html
@@ -0,0 +1,229 @@
+
+<!--
+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.
+-->
+
+<html>
+ <head>
+ <meta charset="utf-8">
+ <script src="lib/esl.js"></script>
+ <script src="lib/config.js"></script>
+ <script src="lib/jquery.min.js"></script>
+ <script src="lib/facePrint.js"></script>
+ <script src="lib/testHelper.js"></script>
+ <link rel="stylesheet" href="lib/reset.css" />
+ <meta name="viewport" content="user-scalable=no,width=device-width,height=device-height">
+ </head>
+ <body>
+ <style>
+ .test-title {
+ background: #146402;
+ color: #fff;
+ }
+ </style>
+
+ <div id="main0"></div>
+ <div id="main1"></div>
+
+
+
+
+
+
+ <script>
+
+ require([
+ 'echarts'
+ ], function (echarts) {
+
+ var option = {
+ tooltip: {
+ trigger: 'axis'
+ },
+ legend: {
+ data: ['pm0.5', 'pm2.5']
+ },
+ grid: {
+ top: '18%',
+ left: '3%',
+ right: '8%',
+ bottom: '3%',
+ containLabel: true
+ },
+ xAxis: {
+ type: 'category',
+ boundaryGap: false,
+ data: ['4-1', '4-2', '4-3', '4-4', '4-5', '4-6']
+ },
+ yAxis: {
+ type: 'log',
+ axisLabel: {
+ formatter: function(value) {
+ return value === 0.1 ? 0 : value
+ }
+ }
+ },
+ series: [{
+ name: 'pm0.5',
+ type: 'line',
+ areaStyle: {
+ //color: 'cyan'
+ },
+ emphasis: {
+ focus: 'series'
+ },
+ lineStyle: {
+ color: '#FEC171'
+ },
+ data: [15, 200, 3000, 50000, 1200000],
+ markLine: {
+ data: [{
+ name: `Y 轴值为 150 的水平线`,
+ yAxis: 150
+ }],
+ lineStyle: {
+ color: '#30B08F'
+ }
+ }
+ },
+ {
+ name: 'pm2.5',
+ type: 'line',
+ areaStyle: {
+ // color: 'blue'
+ },
+ emphasis: {
+ focus: 'series'
+ },
+ lineStyle: {
+ color: '#409EFF'
+ },
+ data: [1200000, 50000, 3000, 200, 15],
+ markLine: {
+ data: [{
+ name: `Y 轴值为 150 的水平线`,
+ yAxis: 150
+ }],
+ lineStyle: {
+ color: '#30B08F'
+ }
+ }
+ }
+ ],
+ visualMap: {
+ show: false,
+ pieces: [{
+ gt: 0,
+ lte: 150,
+ color: '#30B08F'
+ }, {
+ gt: 150,
+ color: '#C03639'
+ }],
+ left: '55%',
+ top: -2,
+ orient: 'horizontal'
+ }
+ };
+
+ testHelper.create(echarts, 'main0', {
+ title: [
+ 'Should be rendered without errors in console',
+ 'https://github.com/apache/echarts/issues/14601'
+ ],
+ option: option,
+ height: 600
+ });
+
+ })
+
+ </script>
+
+
+
+
+
+
+
+
+
+
+ <script>
+
+ require([
+ 'echarts'
+ ], function (echarts) {
+
+ var option = {
+ xAxis: {
+ data: [0, 1]
+ },
+ yAxis: {
+ type: 'value'
+ },
+ series: [
+ {
+ name: '会员数-周同比',
+ type: 'line',
+ data: [
+ {
+ value: null
+ },
+ {
+ value: null
+ }
+ ],
+ areaStyle: {
+ color: {
+ type: 'linear',
+ x: 0,
+ y: 0,
+ x2: 0,
+ y2: 1,
+ index: 6,
+ colorStops: [
+ {
+ offset: 0,
+ color: 'rgba(235, 83, 46, 0.30)'
+ },
+ {
+ offset: 1,
+ color: 'rgba(235, 83, 6, 0.05)'
+ }
+ ]
+ }
+ }
+ }
+ ]
+ };
+
+ testHelper.create(echarts, 'main1', {
+ title: [
+ 'Should be rendered without errors in console',
+ 'https://github.com/apache/echarts/issues/14534'
+ ],
+ option: option
+ });
+ });
+
+ </script>
+
+
+
+ </body>
+</html>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org