Comparing version 1.0.4 to 1.1.0
@@ -8,4 +8,9 @@ const Chart = require('chart.js') | ||
function main() { | ||
const context = global.$$context | ||
if (context.showValueLabels) { | ||
labelPlugin() | ||
} | ||
const chartData = { | ||
@@ -129,2 +134,43 @@ datasets: [], | ||
return patternNames[patternIndex++] | ||
} | ||
function labelPlugin() { | ||
Chart.plugins.register({ | ||
afterDatasetsDraw | ||
}) | ||
function afterDatasetsDraw(chart, easing) { | ||
// To only draw at the end of animation, check for easing === 1 | ||
var ctx = chart.ctx | ||
for (let i = 0; i < chart.data.datasets.length; i++) { | ||
let dataset = chart.data.datasets[i] | ||
var meta = chart.getDatasetMeta(i) | ||
if (!meta.hidden) { | ||
for (let j = 0; j < meta.data.length; j++) { | ||
let element = meta.data[j] | ||
// Draw the text in black, with the specified font | ||
ctx.fillStyle = 'rgb(0, 0, 0)' | ||
var fontSize = 16 | ||
var fontStyle = 'normal' | ||
var fontFamily = 'Helvetica Neue' | ||
ctx.font = Chart.helpers.fontString(fontSize, fontStyle, fontFamily) | ||
// Just naively convert to string for now | ||
var dataString = dataset.data[j].toString() | ||
// Make sure alignment settings are correct | ||
ctx.textAlign = 'center' | ||
ctx.textBaseline = 'middle' | ||
var padding = 5 | ||
var position = element.tooltipPosition() | ||
ctx.fillText(dataString, position.x, position.y - (fontSize / 2) - padding) | ||
} | ||
} | ||
} | ||
} | ||
} |
const rc = require('rc') | ||
// TODO unify these comments with program.js | ||
module.exports = rc('catchart', { | ||
@@ -28,2 +29,5 @@ rowSeparator: '\n', | ||
// show labels on values in the chart | ||
showValueLabels: false, | ||
// do not fill the area under chart lines with color | ||
@@ -30,0 +34,0 @@ noFill: false, |
@@ -154,3 +154,4 @@ const hcat = require('hcat') | ||
title: config.title, | ||
fieldCount: config.fieldCount | ||
fieldCount: config.fieldCount, | ||
showValueLabels: config.showValueLabels | ||
} | ||
@@ -157,0 +158,0 @@ |
{ | ||
"name": "catchart", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "Pipe something from command line to a browser chart", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -21,2 +21,3 @@ const program = require('commander') | ||
value in each row will be considered the label`, 'auto') | ||
.option('--showValueLabels', 'show labels on values in the chart', config.showValueLabels) | ||
.option('--noFill', 'Do not fill the area under the chart line with color', config.noFill) | ||
@@ -23,0 +24,0 @@ .option('--usePatterns', 'Fill the area under the chart line with a pattern, this is meant for individuals who suffer from color blindness', config.usePatterns) |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
593233
1547