You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@echarts.apache.org by GitBox <gi...@apache.org> on 2019/04/09 03:26:03 UTC

[GitHub] [incubator-echarts] keertipAltair edited a comment on issue #9797: Stacked bars not drawn properly.

keertipAltair edited a comment on issue #9797: Stacked bars not drawn properly. 
URL: https://github.com/apache/incubator-echarts/issues/9797#issuecomment-481087126
 
 
   Yes. I currently made a fix in my local code base by changing barGrid.js. My changes are in **Bold**
   
   _**function getValue(data, valueDim, idx, stacked){
   	var values = data.getValues(data.dimensions, idx);
   
   	return stacked ? values[2] : values[data.dimensions.indexOf(valueDim)];
   }**_
   
   /**
    * @param {string} seriesType
    * @param {module:echarts/model/Global} ecModel
    */
   export function layout(seriesType, ecModel) {
   
   	var seriesModels = prepareLayoutBarSeries(seriesType, ecModel);
   	var barWidthAndOffset = makeColumnLayout(seriesModels);
   
   	var lastStackCoords = {};
   	var lastStackCoordsOrigin = {};
   
   	zrUtil.each(seriesModels, function (seriesModel) {
   
   		var data = seriesModel.getData();
   		var cartesian = seriesModel.coordinateSystem;
   		var baseAxis = cartesian.getBaseAxis();
   
   		var stackId = getSeriesStackId(seriesModel);
   		var columnLayoutInfo = barWidthAndOffset[getAxisKey(baseAxis)][stackId];
   		var columnOffset = columnLayoutInfo.offset;
   		var columnWidth = columnLayoutInfo.width;
   		var valueAxis = cartesian.getOtherAxis(baseAxis);
   
   		var barMinHeight = seriesModel.get('barMinHeight') || 0;
   
   		lastStackCoords[stackId] = lastStackCoords[stackId] || [];
   		lastStackCoordsOrigin[stackId] = lastStackCoordsOrigin[stackId] || []; // Fix #4243
   
   		data.setLayout({
   			offset: columnOffset,
   			size: columnWidth
   		});
   
   		var valueDim = data.mapDimension(valueAxis.dim);
   		var baseDim = data.mapDimension(baseAxis.dim);
   		var stacked = isDimensionStacked(data, valueDim /*, baseDim*/);
   		var isValueAxisH = valueAxis.isHorizontal();
   
   		var valueAxisStart = getValueAxisStart(baseAxis, valueAxis, stacked);
   
   		for (var idx = 0, len = data.count(); idx < len; idx++) {
   			**var value = getValue(data, valueDim, idx, stacked);**
   			var baseValue = data.get(baseDim, idx);
   
   			if (isNaN(value)) {
   				continue;
   			}
   
   			var sign = value >= 0 ? 'p' : 'n';
   			var baseCoord = valueAxisStart;
   
   			// Because of the barMinHeight, we can not use the value in
   			// stackResultDimension directly.
   			if (stacked) {
   				// Only ordinal axis can be stacked.
   				if (!lastStackCoords[stackId][baseValue]) {
   					lastStackCoords[stackId][baseValue] = {
   						p: valueAxisStart, // Positive stack
   						n: valueAxisStart // Negative stack
   					};
   				}
   				// Should also consider #4243
   				baseCoord = lastStackCoords[stackId][baseValue][sign];
   			}
   
   			var x;
   			var y;
   			var width;
   			var height;
   
   			if (isValueAxisH) {
   				var coord = cartesian.dataToPoint([value,
   					baseValue]);
   				x = baseCoord;
   				y = coord[1] + columnOffset;
   				**width = coord[0] - baseCoord;**
   				height = columnWidth;
   
   				if (Math.abs(width) < barMinHeight) {
   					width = (width < 0 ? -1 : 1) * barMinHeight;
   				}
   				stacked && (lastStackCoords[stackId][baseValue][sign] += width);
   			}
   			else {
   				var coord = cartesian.dataToPoint([baseValue,
   					value]);
   				x = coord[0] + columnOffset;
   				y = baseCoord;
   				width = columnWidth;
   				**height = coord[1] - baseCoord;**
   
   				if (Math.abs(height) < barMinHeight) {
   					// Include zero to has a positive bar
   					height = (height <= 0 ? -1 : 1) * barMinHeight;
   				}
   
   				stacked && (lastStackCoords[stackId][baseValue][sign] += height);
   			}
   
   			data.setItemLayout(idx, {
   				x: x,
   				y: y,
   				width: width,
   				height: height
   			});
   		}
   
   	}, this);
   }

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@echarts.apache.org
For additional commands, e-mail: dev-help@echarts.apache.org