Skip to content

Commit

Permalink
chore: generate dist
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstanbury committed Mar 7, 2017
1 parent e792c8d commit d0cea66
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 24 deletions.
63 changes: 41 additions & 22 deletions dist/chartist-plugin-axistitle.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], function () {
return (root.returnExportsGlobal = factory());
define(["chartist"], function (Chartist) {
return (root.returnExportsGlobal = factory(Chartist));
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory();
module.exports = factory(require("chartist"));
} else {
root['Chartist.plugins.ctAxisTitle'] = factory();
root['Chartist.plugins.ctAxisTitle'] = factory(Chartist);
}
}(this, function () {
}(this, function (Chartist) {

/**
* Chartist.js plugin to display a title for 1 or 2 axises.
*
* Chartist.js plugin to display a title for 1 or 2 axes.
* version 0.0.3
* author: alex stanbury
*/
/* global Chartist */
(function (window, document, Chartist) {
Expand All @@ -32,24 +33,43 @@
textAnchor: 'middle',
flipText: false
};

var defaultOptions = {
xAxis: axisDefaults,
yAxis: axisDefaults
};

var getTitle = function (title) {
if (title instanceof Function) {
return title();
}
return title;
};

var getClasses = function (classes) {
if (classes instanceof Function) {
return classes();
}
return classes;
};

Chartist.plugins = Chartist.plugins || {};
Chartist.plugins.ctAxisTitle = function (options) {
Chartist.plugins.ctAxisTitle = function(options) {

options = Chartist.extend({}, defaultOptions, options);

return function ctAxisTitle(chart) {

chart.on('created', function (data) {
chart.on('created', function(data) {

if (!options.axisX.axisTitle && !options.axisY.axisTitle) {
throw new Error('ctAxisTitle plugin - You must provide at least one axis title');
throw new Error(
'ctAxisTitle plugin - You must provide at least one axis title'
);
} else if (!data.axisX && !data.axisY) {
throw new Error('ctAxisTitle plugin can only be used on charts that have at least one axis');
throw new Error(
'ctAxisTitle plugin can only be used on charts that have at least one axis'
);
}

var xPos;
Expand All @@ -59,7 +79,8 @@
//position axis X title
if (options.axisX.axisTitle && data.axisX) {

xPos = (data.axisX.axisLength / 2) + data.options.axisY.offset + data.options.chartPadding.left;
xPos = (data.axisX.axisLength / 2) + data.options.axisY.offset +
data.options.chartPadding.left;

yPos = data.options.chartPadding.top;

Expand All @@ -72,8 +93,8 @@
}

title = new Chartist.Svg("text");
title.addClass(options.axisX.axisClass);
title.text(options.axisX.axisTitle);
title.addClass(getClasses(options.axisX.axisClass));
title.text(getTitle(options.axisX.axisTitle));
title.attr({
x: xPos + options.axisX.offset.x,
y: yPos + options.axisX.offset.y,
Expand All @@ -89,7 +110,8 @@
xPos = 0;


yPos = (data.axisY.axisLength / 2) + data.options.chartPadding.top;
yPos = (data.axisY.axisLength / 2) + data.options.chartPadding
.top;

if (data.options.axisX.position === 'start') {
yPos += data.options.axisX.offset;
Expand All @@ -99,26 +121,23 @@
xPos = data.axisX.axisLength;
}

var transform = 'rotate(' + (options.axisY.flipTitle ? -90 : 90) + ', ' + xPos + ', ' + yPos + ')';
var transform = 'rotate(' + (options.axisY.flipTitle ? -
90 : 90) + ', ' + xPos + ', ' + yPos + ')';

title = new Chartist.Svg("text");
title.addClass(options.axisY.axisClass);
title.text(options.axisY.axisTitle);
title.addClass(getClasses(options.axisY.axisClass));
title.text(getTitle(options.axisY.axisTitle));
title.attr({
x: xPos + options.axisY.offset.x,
y: yPos + options.axisY.offset.y,
transform: transform,
"text-anchor": options.axisY.textAnchor
});

data.svg.append(title, true);

}

});
};
};

}(window, document, Chartist));

return Chartist.plugins.ctAxisTitle;
Expand Down
2 changes: 1 addition & 1 deletion dist/chartist-plugin-axistitle.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d0cea66

Please sign in to comment.