Skip to content

Commit

Permalink
Fix #8149 (candlestick default tooltip fix.)
Browse files Browse the repository at this point in the history
  • Loading branch information
100pah committed Apr 16, 2018
1 parent ddab25f commit 3d5b8b1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 deletions.
8 changes: 7 additions & 1 deletion src/chart/boxplot/BoxplotSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ var BoxplotSeries = SeriesModel.extend({
* and echarts do not need to know it.
* @readOnly
*/
defaultValueDimensions: ['min', 'Q1', 'median', 'Q3', 'max'],
defaultValueDimensions: [
{name: 'min', defaultTooltip: true},
{name: 'Q1', defaultTooltip: true},
{name: 'median', defaultTooltip: true},
{name: 'Q3', defaultTooltip: true},
{name: 'max', defaultTooltip: true}
],

/**
* @type {Array.<string>}
Expand Down
11 changes: 8 additions & 3 deletions src/chart/candlestick/CandlestickSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ var CandlestickSeries = SeriesModel.extend({
/**
* @readOnly
*/
defaultValueDimensions: ['open', 'close', 'lowest', 'highest'],
defaultValueDimensions: [
{name: 'open', defaultTooltip: true},
{name: 'close', defaultTooltip: true},
{name: 'lowest', defaultTooltip: true},
{name: 'highest', defaultTooltip: true}
],

/**
* @type {Array.<string>}
Expand All @@ -23,8 +28,8 @@ var CandlestickSeries = SeriesModel.extend({
* @override
*/
defaultOption: {
zlevel: 0, // 一级层叠
z: 2, // 二级层叠
zlevel: 0,
z: 2,
coordinateSystem: 'cartesian2d',
legendHoverLink: true,

Expand Down
7 changes: 5 additions & 2 deletions src/data/helper/completeDimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {OTHER_DIMENSIONS} from './dimensionHelper';
* provides not only dim template, but also default order.
* properties: 'name', 'type', 'displayName'.
* `name` of each item provides default coord name.
* [{dimsDef: [string...]}, ...] dimsDef of sysDim item provides default dim name, and
* [{dimsDef: [string|Object, ...]}, ...] dimsDef of sysDim item provides default dim name, and
* provide dims count that the sysDim required.
* [{ordinalMeta}] can be specified.
* @param {module:echarts/data/Source|Array|Object} source or data (for compatibal with pervious)
Expand Down Expand Up @@ -145,7 +145,10 @@ function completeDimensions(sysDims, source, opt) {
var resultItem = result[resultDimIdx];
applyDim(defaults(resultItem, sysDimItem), coordDim, coordDimIndex);
if (resultItem.name == null && sysDimItemDimsDef) {
resultItem.name = resultItem.displayName = sysDimItemDimsDef[coordDimIndex];
var sysDimItemDimsDefItem = sysDimItemDimsDef[coordDimIndex];
!isObject(sysDimItemDimsDefItem) && (sysDimItemDimsDefItem = {name: sysDimItemDimsDefItem});
resultItem.name = resultItem.displayName = sysDimItemDimsDefItem.name;
resultItem.defaultTooltip = sysDimItemDimsDefItem.defaultTooltip;
}
// FIXME refactor, currently only used in case: {otherDims: {tooltip: false}}
sysDimItemOtherDims && defaults(resultItem.otherDims, sysDimItemOtherDims);
Expand Down
8 changes: 7 additions & 1 deletion src/data/helper/dimensionHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function summarizeDimensions(data) {
var encode = summary.encode = {};
var notExtraCoordDimMap = createHashMap();
var defaultedLabel = [];
var defaultedTooltip = [];

each(data.dimensions, function (dimName) {
var dimItem = data.getDimensionInfo(dimName);
Expand All @@ -36,6 +37,9 @@ export function summarizeDimensions(data) {
defaultedLabel[0] = dimName;
}
}
if (dimItem.defaultTooltip) {
defaultedTooltip.push(dimName);
}
}

OTHER_DIMENSIONS.each(function (v, otherDim) {
Expand Down Expand Up @@ -75,11 +79,13 @@ export function summarizeDimensions(data) {
defaultedLabel = encodeLabel.slice();
}

var defaultedTooltip = defaultedLabel.slice();
var encodeTooltip = encode.tooltip;
if (encodeTooltip && encodeTooltip.length) {
defaultedTooltip = encodeTooltip.slice();
}
else if (!defaultedTooltip.length) {
defaultedTooltip = defaultedLabel.slice();
}

encode.defaultedLabel = defaultedLabel;
encode.defaultedTooltip = defaultedTooltip;
Expand Down
28 changes: 16 additions & 12 deletions test/candlestick.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
height: 100%;
}
</style>
Check tooltip.
<div id="info"></div>
<div id="main"></div>
<script>
Expand Down Expand Up @@ -155,18 +156,21 @@
// borderColor0: '#998',
// borderWidth: 2
// },
tooltip: {
formatter: function (param) {
var param = param[0];
return [
'日期:' + param.name + '<hr size=1 style="margin: 3px 0">',
'开盘:' + param.data[0] + '<br/>',
'收盘:' + param.data[1] + '<br/>',
'日最低:' + param.data[2] + '<br/>',
'日最高:' + param.data[3] + '<br/>'
].join('')
}
},
// encode: {
// tooltip: [0, 1, 2, 3]
// },
// tooltip: {
// formatter: function (param) {
// var param = param[0];
// return [
// '日期:' + param.name + '<hr size=1 style="margin: 3px 0">',
// '开盘:' + param.data[0] + '<br/>',
// '收盘:' + param.data[1] + '<br/>',
// '日最低:' + param.data[2] + '<br/>',
// '日最高:' + param.data[3] + '<br/>'
// ].join('')
// }
// },
markPoint: {
data: [
{
Expand Down

0 comments on commit 3d5b8b1

Please sign in to comment.