Skip to content

Commit

Permalink
Some modification to ease extending chart types
Browse files Browse the repository at this point in the history
  • Loading branch information
highslide-software committed Dec 22, 2010
1 parent f44ccf9 commit 517f0ea
Show file tree
Hide file tree
Showing 3 changed files with 552 additions and 454 deletions.
50 changes: 30 additions & 20 deletions js/highcharts.src.js
Expand Up @@ -5414,10 +5414,7 @@ function Chart (options, callback) {

// build the values
each(points, function(point) {
series = point.series;
s.push('<span style="color:'+ series.color +'">', (point.name || series.name), '</span>: ',
(!useHeader ? ('<b>x = '+ (point.name || point.x) + ',</b> ') : ''),
'<b>', (!useHeader ? 'y = ' : '' ), point.y, '</b><br/>');
s.push(point.tooltipFormatter(useHeader));
});
return s.join('');
}
Expand Down Expand Up @@ -7880,6 +7877,23 @@ Point.prototype = {
point.series.chart.hoverPoint = null;
},

/**
* Extendable method for formatting each point's tooltip line
*
* @param {Boolean} useHeader Whether a common header is used for multiple series in the tooltip
*
* @return {String} A string to be concatenated in to the common tooltip text
*/
tooltipFormatter: function(useHeader) {
var point = this,
series = point.series;

return ['<span style="color:'+ series.color +'">', (point.name || series.name), '</span>: ',
(!useHeader ? ('<b>x = '+ (point.name || point.x) + ',</b> ') : ''),
'<b>', (!useHeader ? 'y = ' : '' ), point.y, '</b><br/>'].join('');

},

/**
* Update the point with new options (typically x/y data) and optionally redraw the series.
*
Expand Down Expand Up @@ -8371,15 +8385,15 @@ Series.prototype = {
stacking = series.options.stacking,
categories = series.xAxis.categories,
yAxis = series.yAxis,
data = series.data,
data = series.data,
i = data.length;

// do the translation
while (i--) {
var point = data[i],
xValue = point.x,
yValue = point.y,
yBottom,
yBottom = point.low,
stack = yAxis.stacks[(yValue < 0 ? '-' : '') + series.stackKey],
pointStack,
pointStackTotal;
Expand All @@ -8399,7 +8413,10 @@ Series.prototype = {

point.percentage = pointStackTotal ? point.y * 100 / pointStackTotal : 0;
point.stackTotal = pointStackTotal;
point.yBottom = yAxis.translate(yBottom, 0, 1);
}

if (defined(yBottom)) {
point.yBottom = yAxis.translate(yBottom, 0, 1);
}

// set the y value
Expand Down Expand Up @@ -8657,8 +8674,11 @@ Series.prototype = {
stateOptions = normalOptions.states,
stateOptionsHover = stateOptions[HOVER_STATE],
pointStateOptionsHover,
normalDefaults = {},
seriesColor = series.color,
normalDefaults = {
stroke: seriesColor,
fill: seriesColor
},
data = series.data,
i,
point,
Expand All @@ -8670,23 +8690,12 @@ Series.prototype = {
// series type specific modifications
if (series.options.marker) { // line, spline, area, areaspline, scatter

// if no color is given for the point, use the general series color
normalDefaults = {
stroke: seriesColor,
fill: seriesColor
};

// if no hover radius is given, default to normal radius + 2
stateOptionsHover.radius = stateOptionsHover.radius || normalOptions.radius + 2;
stateOptionsHover.lineWidth = stateOptionsHover.lineWidth || normalOptions.lineWidth + 1;

} else { // column, bar, pie

// if no color is given for the point, use the general series color
normalDefaults = {
fill: seriesColor
};

// if no hover color is given, brighten the normal color
stateOptionsHover.color = stateOptionsHover.color ||
Color(stateOptionsHover.color || seriesColor)
Expand Down Expand Up @@ -9601,7 +9610,7 @@ var ColumnSeries = extendClass(Series, {
(reversedXAxis ? -1 : 1),
threshold = options.threshold || 0,
translatedThreshold = series.yAxis.getThreshold(threshold),
minPointLength = pick(options.minPointLength, 5);
minPointLength = pick(options.minPointLength, 5);

// record the new values
each(data, function(point) {
Expand Down Expand Up @@ -10416,6 +10425,7 @@ win.Highcharts = {
getOptions: getOptions,
numberFormat: numberFormat,
Point: Point,
Color: Color,
Renderer: Renderer,
seriesTypes: seriesTypes,
setOptions: setOptions,
Expand Down

0 comments on commit 517f0ea

Please sign in to comment.