Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
vladminsky committed Jan 14, 2015
1 parent 5293ba6 commit 441aaaf
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 22 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tauCharts",
"version": "0.3.2",
"version": "0.3.3",
"homepage": "https://github.com/TargetProcess/tauCharts",
"description": "Simple charts library based on d3",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion build/development/plugins/tauCharts.legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
});
} else if (typeof module === "object" && module.exports) {
var tauPlugins = require('tauCharts');
module.exports = factory();
module.exports = factory(tauPlugins);
} else {
factory(this.tauCharts);
}
Expand Down
124 changes: 115 additions & 9 deletions build/development/plugins/tauCharts.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
});
} else if (typeof module === "object" && module.exports) {
var tauPlugins = require('tauCharts');
module.exports = factory();
module.exports = factory(tauPlugins);
} else {
factory(this.tauCharts);
}
Expand All @@ -22,6 +22,20 @@
return Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
};

var dfs = function (node, predicate) {
if (predicate(node)) {
return node;
}
var i, children = node.unit || [], child, found;
for (i = 0; i < children.length; i += 1) {
child = children[i];
found = dfs(child, predicate);
if (found) {
return found;
}
}
};

function tooltip(settings) {
settings = settings || {};
return {
Expand Down Expand Up @@ -60,9 +74,8 @@
}.bind(this), false);
},
formatters: {},
_getFormatter: function (field) {
return this.formatters[field] || _.identity;
},
labels: {},

init: function (chart) {
this._chart = chart;
this._dataFields = settings.fields;
Expand All @@ -74,6 +87,23 @@
this._templateItem = _.template(this.itemTemplate);
this._tooltip = chart.addBalloon({spacing: 3, auto: true, effectClass: 'fade'});
this._elementTooltip = this._tooltip.getElement();

var spec = chart.getConfig().spec;

var dimensionGuides = this._findDimensionGuides(spec);

var lastGuides = _.reduce(dimensionGuides, function(memo, guides, key){
memo[key] = _.last(guides);
return memo;
}, {});

var formatters = this._generateDefaultFormatters(lastGuides, spec.dimensions);
_.extend(this.formatters, formatters);

var labels = this._generateDefaultLabels(lastGuides);
_.extend(this.labels, labels);


var elementTooltip = this._elementTooltip;
elementTooltip.addEventListener('mouseover', function () {
clearTimeout(this._timeoutHideId);
Expand All @@ -92,6 +122,7 @@
}
}.bind(this), false);
elementTooltip.insertAdjacentHTML('afterbegin', this.template);

},
onUnitReady: function (chart, unitMeta) {
if (unitMeta.type && unitMeta.type.indexOf('ELEMENT') === 0) {
Expand All @@ -109,10 +140,10 @@
}
},

renderItem: function(field, value, rawValue){
renderItem: function(label, formattedValue, field, rawValue){
return this._templateItem({
label: field,
value: value
label: label,
value: formattedValue
});
},

Expand All @@ -121,8 +152,9 @@
return fields.map(function (field) {
var rawValue = data[field];
var formattedValue = this._getFormatter(field)(rawValue);
var value = (_.isNull(formattedValue) || _.isUndefined(formattedValue)) ? ('No ' + field) : formattedValue;
return this.renderItem(field, value, rawValue);
var label = this._getLabel(field);

return this.renderItem(label, formattedValue, field, rawValue);
}, this).join('');
},
onRender: function (chart) {
Expand All @@ -131,6 +163,80 @@
}
this._hide();
},

_getFormatter: function (field) {
return this.formatters[field] || _.identity;
},
_getLabel: function(field){
return this.labels[field] || field;
},

_generateDefaultLabels: function (lastGuides) {
return _.reduce(lastGuides, function (memo, lastGuide, key) {
memo[key] = lastGuide.label || key;
return memo;
}, {});
},

_generateDefaultFormatters: function (lastGuides, dimensions) {
return _.reduce(lastGuides, function (memo, lastGuide, key) {
var getValue = function (rawValue) {
if (rawValue == null) {
return null;
} else {
var format = lastGuide.tickPeriod || lastGuide.tickFormat;
if (format) {
return tauCharts.api.tickFormat.get(format)(rawValue);
} else if (lastGuide.tickLabel) {
return rawValue[lastGuide.tickLabel];
} else if (dimensions[key].value) {
return rawValue[dimensions[key].value];
} else {
return rawValue;
}
}
};

memo[key] = function (rawValue) {
var value = getValue(rawValue);
return value == null ? 'No ' + lastGuide.label : value;
};

return memo;
}, {});
},

_findDimensionGuides: function(spec){
var dimensionGuideMap = {};

var collect = function(field, unit){
var property = unit[field];
if (property) {
var guide = (unit.guide || {})[field];

if (guide) {
if (!dimensionGuideMap[property]) {
dimensionGuideMap[property] = [];
}

dimensionGuideMap[property].push(guide)
}
}
};

dfs(spec.unit, function(unit){
collect('x', unit);
collect('y', unit);
collect('color', unit);
collect('size', unit);

return false;
});

return dimensionGuideMap;

},

_exclude: function () {
this._chart.addFilter({
tag: 'exclude',
Expand Down
2 changes: 1 addition & 1 deletion build/development/plugins/tauCharts.trendline.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
});
} else if (typeof module === "object" && module.exports) {
var tauPlugins = require('tauCharts');
module.exports = factory();
module.exports = factory(tauPlugins);
} else {
factory(this.tauCharts);
}
Expand Down
8 changes: 5 additions & 3 deletions build/development/tauCharts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! taucharts - v0.3.2 - 2015-01-14
/*! taucharts - v0.3.3 - 2015-01-14
* https://github.com/TargetProcess/tauCharts
* Copyright (c) 2015 Taucraft Limited; Licensed Apache License 2.0 */
(function (root, factory) {
Expand Down Expand Up @@ -3780,7 +3780,8 @@ define('charts/tau.chart',["exports", "./tau.plot", "../utils/utils", "../data-p
y: config.y,
color: config.color,
guide: {
color: config.colorGuide
color: config.colorGuide,
size: config.sizeGuide
},
flip: config.flip,
size: config.size
Expand Down Expand Up @@ -3870,7 +3871,8 @@ define('charts/tau.chart',["exports", "./tau.plot", "../utils/utils", "../data-p
color: config.color,
size: config.size,
flip: config.flip,
colorGuide: currentGuide.color
colorGuide: currentGuide.color,
sizeGuide: currentGuide.size
}));
spec.guide = _.defaults(currentGuide, {
x: { label: currentX },
Expand Down
2 changes: 1 addition & 1 deletion build/production/tauCharts.min.css

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions build/production/tauCharts.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tauCharts",
"version": "0.3.2",
"version": "0.3.3",
"ignore": [
"/*",
"!build/**",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "taucharts",
"version": "0.3.2",
"version": "0.3.3",
"homepage": "https://github.com/TargetProcess/tauCharts",
"description": "Simple charts library based on d3",
"author": {
Expand Down

0 comments on commit 441aaaf

Please sign in to comment.