utils.srand(110);
+ function channelValue(x, y, values) {
+ return x < 0 && y < 0 ? values[0] : x < 0 ? values[1] : y < 0 ? values[2] : values[3];
+ }
+
function colorize(opaque, context) {
var value = context.dataset.data[context.dataIndex];
var x = value.x / 100;
var y = value.y / 100;
- var r = x < 0 && y < 0 ? 250 : x < 0 ? 150 : y < 0 ? 50 : 0;
- var g = x < 0 && y < 0 ? 0 : x < 0 ? 50 : y < 0 ? 150 : 250;
- var b = x < 0 && y < 0 ? 0 : x > 0 && y > 0 ? 250 : 150;
+ var r = channelValue(x, y, [250, 150, 50, 0]);
+ var g = channelValue(x, y, [0, 50, 150, 250]);
+ var b = channelValue(x, y, [0, 150, 150, 250]);
var a = opaque ? 1 : 0.5 * value.v / 1000;
return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
<script>
Chart.defaults.pointHitDetectionRadius = 1;
- var customTooltips = function(tooltip) {
- // Tooltip Element
+ var getOrCreateTooltip = function() {
var tooltipEl = document.getElementById('chartjs-tooltip');
if (!tooltipEl) {
this._chart.canvas.parentNode.appendChild(tooltipEl);
}
+ return tooltipEl;
+ };
+
+ var customTooltips = function(tooltip) {
+ // Tooltip Element
+ var tooltipEl = getOrCreateTooltip();
+
// Hide if no tooltip
if (tooltip.opacity === 0) {
tooltipEl.style.opacity = 0;
var Samples = global.Samples || (global.Samples = {});
var Color = Chart.helpers.color;
+ function applyDefaultNumbers(config) {
+ var cfg = config || {};
+ cfg.min = cfg.min || 0;
+ cfg.max = cfg.max || 1;
+ cfg.from = cfg.from || [];
+ cfg.count = cfg.count || 8;
+ cfg.decimals = cfg.decimals || 8;
+ cfg.continuity = cfg.continuity || 1;
+
+ return cfg;
+ }
+
Samples.utils = {
// Adapted from http://indiegamr.com/generate-repeatable-random-numbers-in-js/
srand: function(seed) {
},
numbers: function(config) {
- var cfg = config || {};
- var min = cfg.min || 0;
- var max = cfg.max || 1;
- var from = cfg.from || [];
- var count = cfg.count || 8;
- var decimals = cfg.decimals || 8;
- var continuity = cfg.continuity || 1;
- var dfactor = Math.pow(10, decimals) || 0;
+ var cfg = applyDefaultNumbers(config);
+ var dfactor = Math.pow(10, cfg.decimals) || 0;
var data = [];
var i, value;
- for (i = 0; i < count; ++i) {
- value = (from[i] || 0) + this.rand(min, max);
- if (this.rand() <= continuity) {
+ for (i = 0; i < cfg.count; ++i) {
+ value = (cfg.from[i] || 0) + this.rand(cfg.min, cfg.max);
+ if (this.rand() <= cfg.continuity) {
data.push(Math.round(dfactor * value) / dfactor);
} else {
data.push(null);