-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make bar styling options scriptable (#5780)
The bar `backgroundColor`, `borderColor`, `borderWidth` and `borderSkipped` options are now scriptable (unit tests, docs and a basic sample). Also fix the gulp task that generates the documentation on Windows.
- Loading branch information
1 parent
637c217
commit ae80e14
Showing
31 changed files
with
828 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<!DOCTYPE html> | ||
<html lang="en-US"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=Edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Scriptable > Bar | Chart.js sample</title> | ||
<link rel="stylesheet" type="text/css" href="../style.css"> | ||
<script src="../../dist/Chart.js"></script> | ||
<script src="../utils.js"></script> | ||
</head> | ||
<body> | ||
<div class="content"> | ||
<div class="wrapper"><canvas id="chart-0"></canvas></div> | ||
<div class="toolbar"> | ||
<button onclick="randomize(this)">Randomize</button> | ||
<button onclick="addDataset(this)">Add Dataset</button> | ||
<button onclick="removeDataset(this)">Remove Dataset</button> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
var DATA_COUNT = 16; | ||
|
||
var utils = Samples.utils; | ||
|
||
utils.srand(110); | ||
|
||
function colorize(opaque, ctx) { | ||
var v = ctx.dataset.data[ctx.dataIndex]; | ||
var c = v < -50 ? '#D60000' | ||
: v < 0 ? '#F46300' | ||
: v < 50 ? '#0358B6' | ||
: '#44DE28'; | ||
|
||
return opaque ? c : utils.transparentize(c, 1 - Math.abs(v / 150)); | ||
} | ||
|
||
function generateData() { | ||
return utils.numbers({ | ||
count: DATA_COUNT, | ||
min: -100, | ||
max: 100 | ||
}); | ||
} | ||
|
||
var data = { | ||
labels: utils.months({count: DATA_COUNT}), | ||
datasets: [{ | ||
data: generateData() | ||
}] | ||
}; | ||
|
||
var options = { | ||
legend: false, | ||
tooltips: false, | ||
elements: { | ||
rectangle: { | ||
backgroundColor: colorize.bind(null, false), | ||
borderColor: colorize.bind(null, true), | ||
borderWidth: 2 | ||
} | ||
} | ||
}; | ||
|
||
var chart = new Chart('chart-0', { | ||
type: 'bar', | ||
data: data, | ||
options: options | ||
}); | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
function randomize() { | ||
chart.data.datasets.forEach(function(dataset) { | ||
dataset.data = generateData(); | ||
}); | ||
chart.update(); | ||
} | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
function addDataset() { | ||
chart.data.datasets.push({ | ||
data: generateData() | ||
}); | ||
chart.update(); | ||
} | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
function removeDataset() { | ||
chart.data.datasets.shift(); | ||
chart.update(); | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.