[chartjs] upgrade chartjs to 2.9.4

fixes CVE-2020-7746
This commit is contained in:
Christopher Lam 2021-05-11 18:43:11 +08:00
parent e57194379e
commit d2a4aef3bb
11 changed files with 9247 additions and 6148 deletions

6744
borrowed/chartjs/Chart.bundle.js Normal file → Executable file

File diff suppressed because it is too large Load Diff

6
borrowed/chartjs/Chart.bundle.min.js vendored Normal file → Executable file

File diff suppressed because one or more lines are too long

0
borrowed/chartjs/Chart.css Normal file → Executable file
View File

6730
borrowed/chartjs/Chart.js vendored Normal file → Executable file

File diff suppressed because it is too large Load Diff

0
borrowed/chartjs/Chart.min.css vendored Normal file → Executable file
View File

6
borrowed/chartjs/Chart.min.js vendored Normal file → Executable file

File diff suppressed because one or more lines are too long

0
borrowed/chartjs/LICENSE.md Normal file → Executable file
View File

32
borrowed/chartjs/README.md Executable file
View File

@ -0,0 +1,32 @@
<p align="center">
<img src="https://www.chartjs.org/media/logo-title.svg"><br/>
Simple yet flexible JavaScript charting for designers & developers
</p>
<p align="center">
<a href="https://www.chartjs.org/docs/latest/getting-started/installation.html"><img src="https://img.shields.io/github/release/chartjs/Chart.js.svg?style=flat-square&maxAge=600" alt="Downloads"></a>
<a href="https://travis-ci.org/chartjs/Chart.js"><img src="https://img.shields.io/travis/chartjs/Chart.js.svg?style=flat-square&maxAge=600" alt="Builds"></a>
<a href="https://coveralls.io/github/chartjs/Chart.js?branch=master"><img src="https://img.shields.io/coveralls/chartjs/Chart.js.svg?style=flat-square&maxAge=600" alt="Coverage"></a>
<a href="https://github.com/chartjs/awesome"><img src="https://awesome.re/badge-flat2.svg" alt="Awesome"></a>
<a href="https://chartjs-slack.herokuapp.com/"><img src="https://img.shields.io/badge/slack-chartjs-blue.svg?style=flat-square&maxAge=3600" alt="Slack"></a>
</p>
## Documentation
- [Introduction](https://www.chartjs.org/docs/latest/)
- [Getting Started](https://www.chartjs.org/docs/latest/getting-started/)
- [General](https://www.chartjs.org/docs/latest/general/)
- [Configuration](https://www.chartjs.org/docs/latest/configuration/)
- [Charts](https://www.chartjs.org/docs/latest/charts/)
- [Axes](https://www.chartjs.org/docs/latest/axes/)
- [Developers](https://www.chartjs.org/docs/latest/developers/)
- [Popular Extensions](https://github.com/chartjs/awesome)
- [Samples](https://www.chartjs.org/samples/)
## Contributing
Instructions on building and testing Chart.js can be found in [the documentation](https://github.com/chartjs/Chart.js/blob/master/docs/developers/contributing.md#building-and-testing). Before submitting an issue or a pull request, please take a moment to look over the [contributing guidelines](https://github.com/chartjs/Chart.js/blob/master/docs/developers/contributing.md) first. For support, please post questions on [Stack Overflow](https://stackoverflow.com/questions/tagged/chartjs) with the `chartjs` tag.
## License
Chart.js is available under the [MIT license](https://opensource.org/licenses/MIT).

View File

@ -17,6 +17,7 @@
<body>
<div style="width:1000px">
<p>This example demonstrates a time series scale by drawing a financial line chart using just the core library. For more specific functionality for financial charts, please see <a href="https://github.com/chartjs/chartjs-chart-financial">chartjs-chart-financial</a></p>
<canvas id="chart1"></canvas>
</div>
<br>
@ -26,8 +27,38 @@
<option value="line">Line</option>
<option value="bar">Bar</option>
</select>
<select id="unit">
<option value="second">Second</option>
<option value="minute">Minute</option>
<option value="hour">Hour</option>
<option value="day" selected>Day</option>
<option value="month">Month</option>
<option value="year">Year</option>
</select>
<button id="update">update</button>
<script>
function generateData() {
var unit = document.getElementById('unit').value;
function unitLessThanDay() {
return unit === 'second' || unit === 'minute' || unit === 'hour';
}
function beforeNineThirty(date) {
return date.hour() < 9 || (date.hour() === 9 && date.minute() < 30);
}
// Returns true if outside 9:30am-4pm on a weekday
function outsideMarketHours(date) {
if (date.isoWeekday() > 5) {
return true;
}
if (unitLessThanDay() && (beforeNineThirty(date) || date.hour() > 16)) {
return true;
}
return false;
}
function randomNumber(min, max) {
return Math.random() * (max - min) + min;
}
@ -41,14 +72,23 @@
};
}
var dateFormat = 'MMMM DD YYYY';
var date = moment('April 01 2017', dateFormat);
var data = [randomBar(date, 30)];
while (data.length < 60) {
date = date.clone().add(1, 'd');
if (date.isoWeekday() <= 5) {
data.push(randomBar(date, data[data.length - 1].y));
var date = moment('Jan 01 1990', 'MMM DD YYYY');
var now = moment();
var data = [];
var lessThanDay = unitLessThanDay();
for (; data.length < 600 && date.isBefore(now); date = date.clone().add(1, unit).startOf(unit)) {
if (outsideMarketHours(date)) {
if (!lessThanDay || !beforeNineThirty(date)) {
date = date.clone().add(date.isoWeekday() >= 5 ? 8 - date.isoWeekday() : 1, 'day');
}
if (lessThanDay) {
date = date.hour(9).minute(30).second(0);
}
}
data.push(randomBar(date, data.length > 0 ? data[data.length - 1].y : 30));
}
return data;
}
var ctx = document.getElementById('chart1').getContext('2d');
@ -57,13 +97,12 @@
var color = Chart.helpers.color;
var cfg = {
type: 'bar',
data: {
datasets: [{
label: 'CHRT - Chart.js Corporation',
backgroundColor: color(window.chartColors.red).alpha(0.5).rgbString(),
borderColor: window.chartColors.red,
data: data,
data: generateData(),
type: 'line',
pointRadius: 0,
fill: false,
@ -72,16 +111,56 @@
}]
},
options: {
animation: {
duration: 0
},
scales: {
xAxes: [{
type: 'time',
distribution: 'series',
offset: true,
ticks: {
major: {
enabled: true,
fontStyle: 'bold'
},
source: 'data',
autoSkip: true
autoSkip: true,
autoSkipPadding: 75,
maxRotation: 0,
sampleSize: 100
},
afterBuildTicks: function(scale, ticks) {
var majorUnit = scale._majorUnit;
var firstTick = ticks[0];
var i, ilen, val, tick, currMajor, lastMajor;
val = moment(ticks[0].value);
if ((majorUnit === 'minute' && val.second() === 0)
|| (majorUnit === 'hour' && val.minute() === 0)
|| (majorUnit === 'day' && val.hour() === 9)
|| (majorUnit === 'month' && val.date() <= 3 && val.isoWeekday() === 1)
|| (majorUnit === 'year' && val.month() === 0)) {
firstTick.major = true;
} else {
firstTick.major = false;
}
lastMajor = val.get(majorUnit);
for (i = 1, ilen = ticks.length; i < ilen; i++) {
tick = ticks[i];
val = moment(tick.value);
currMajor = val.get(majorUnit);
tick.major = currMajor !== lastMajor;
lastMajor = currMajor;
}
return ticks;
}
}],
yAxes: [{
gridLines: {
drawBorder: false
},
scaleLabel: {
display: true,
labelString: 'Closing price ($)'
@ -109,7 +188,9 @@
document.getElementById('update').addEventListener('click', function() {
var type = document.getElementById('type').value;
chart.config.data.datasets[0].type = type;
var dataset = chart.config.data.datasets[0];
dataset.type = type;
dataset.data = generateData();
chart.update();
});

View File

@ -26,14 +26,17 @@
utils.srand(110);
function getLineColor(ctx) {
return utils.color(ctx.datasetIndex);
}
function alternatePointStyles(ctx) {
var index = ctx.dataIndex;
return index % 2 === 0 ? 'circle' : 'rect';
}
function makeHalfAsOpaque(ctx) {
var c = ctx.dataset.backgroundColor;
return utils.transparentize(c);
return utils.transparentize(getLineColor(ctx));
}
function adjustRadiusBasedOnData(ctx) {
@ -56,9 +59,7 @@
var data = {
labels: utils.months({count: DATA_COUNT}),
datasets: [{
data: generateData(),
backgroundColor: '#4dc9f6',
borderColor: '#4dc9f6',
data: generateData()
}]
};
@ -68,8 +69,11 @@
elements: {
line: {
fill: false,
backgroundColor: getLineColor,
borderColor: getLineColor,
},
point: {
backgroundColor: getLineColor,
hoverBackgroundColor: makeHalfAsOpaque,
radius: adjustRadiusBasedOnData,
pointStyle: alternatePointStyles,
@ -87,12 +91,8 @@
// eslint-disable-next-line no-unused-vars
function addDataset() {
var newColor = utils.color(chart.data.datasets.length);
chart.data.datasets.push({
data: generateData(),
backgroundColor: newColor,
borderColor: newColor
data: generateData()
});
chart.update();
}

View File

@ -26,14 +26,21 @@
utils.srand(110);
function getLineColor(ctx) {
return utils.color(ctx.datasetIndex);
}
function alternatePointStyles(ctx) {
var index = ctx.dataIndex;
return index % 2 === 0 ? 'circle' : 'rect';
}
function makeHalfAsOpaque(ctx) {
var c = ctx.dataset.backgroundColor;
return utils.transparentize(c);
return utils.transparentize(getLineColor(ctx));
}
function make20PercentOpaque(ctx) {
return utils.transparentize(getLineColor(ctx), 0.8);
}
function adjustRadiusBasedOnData(ctx) {
@ -56,9 +63,7 @@
var data = {
labels: [['Eating', 'Dinner'], ['Drinking', 'Water'], 'Sleeping', ['Designing', 'Graphics'], 'Coding', 'Cycling', 'Running'],
datasets: [{
data: generateData(),
backgroundColor: Chart.helpers.color('#4dc9f6').alpha(0.2).rgbString(),
borderColor: '#4dc9f6',
data: generateData()
}]
};
@ -66,7 +71,12 @@
legend: false,
tooltips: true,
elements: {
line: {
backgroundColor: make20PercentOpaque,
borderColor: getLineColor,
},
point: {
backgroundColor: getLineColor,
hoverBackgroundColor: makeHalfAsOpaque,
radius: adjustRadiusBasedOnData,
pointStyle: alternatePointStyles,
@ -84,12 +94,8 @@
// eslint-disable-next-line no-unused-vars
function addDataset() {
var newColor = utils.color(chart.data.datasets.length);
chart.data.datasets.push({
data: generateData(),
backgroundColor: Chart.helpers.color(newColor).alpha(0.2).rgbString(),
borderColor: newColor
data: generateData()
});
chart.update();
}