Skip to content

Commit

Permalink
v2.0.3
Browse files Browse the repository at this point in the history
Developer preview
  • Loading branch information
zibous committed Apr 9, 2021
1 parent ca6a7a5 commit e177792
Show file tree
Hide file tree
Showing 38 changed files with 2,497 additions and 867 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Lovelace - graph-chartjs-card

Chart.js card `Version 2.0.2` for Home Assistant - Visualize your data in 9 different ways; each of them animated and customisable.
This is higly customizable graph card for [Home-Assistant](https://www.home-assistant.io/)'s Lovelace UI.

Graph ChartJS Chart `Version 2.0.2` for Home Assistant - Visualize your data in different ways- `BAR`, `HORIZONTALBAR` ,`SEGMENTEDBAR`, `PIE`, `DOUGHNUT`, `LINE`,`RADAR`,`SCATTR`,`BUBBLE` - ; each of them animated and customisable. Respects the set Homeassistant `locale` for numbers and dates.

It is based on [chart.js](https://chartjs.org) and offers most of the features of the library.

<br>

![charts2.png](docs/img/charts/charts.png)

Expand All @@ -26,9 +32,15 @@ If you find any information on this page useful, feel free to buy me a coffee:
- url: /hacsfiles/chart-card/chart-card-min.js
type: module
```
<br>
<br>
YAML Structure for `custom:chart-card`
You can see all the ways to use `Lovelace - graph-chartjs-card` in the [usage documentation](docs/getting-started/index.md).



<br>

## YAML Structure for `custom:chart-card`

```yaml
## -------------------------------------
Expand Down Expand Up @@ -173,6 +185,7 @@ You can see all the ways to use `Lovelace - graph-chartjs-card` in the [usage do
- [Evert Timberg](https://github.com/etimberg) - Maintainer of @chartjs
- [Jukka Kurkela](https://github.com/kurkle) - Maintainer of @chartjs & Plugins for chartjs


## License

`graph-chartjs-card` is available under the [MIT license](https://opensource.org/licenses/MIT).
2 changes: 1 addition & 1 deletion dist/chart-card/chart-bundle-min.js

Large diffs are not rendered by default.

58 changes: 40 additions & 18 deletions dist/chart-card/chart-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3937,7 +3937,7 @@ class Scale extends Element {
}
init(options) {
const me = this;
me.options = options;
me.options = options.setContext(me.getContext());
me.axis = options.axis;
me._userMin = me.parse(options.min);
me._userMax = me.parse(options.max);
Expand Down Expand Up @@ -8999,29 +8999,33 @@ PointElement: PointElement,
BarElement: BarElement
});

function lttbDecimation(data, availableWidth, options) {
function lttbDecimation(data, start, count, availableWidth, options) {
const samples = options.samples || availableWidth;
if (samples >= count) {
return data.slice(start, start + count);
}
const decimated = [];
const bucketWidth = (data.length - 2) / (samples - 2);
const bucketWidth = (count - 2) / (samples - 2);
let sampledIndex = 0;
let a = 0;
const endIndex = start + count - 1;
let a = start;
let i, maxAreaPoint, maxArea, area, nextA;
decimated[sampledIndex++] = data[a];
for (i = 0; i < samples - 2; i++) {
let avgX = 0;
let avgY = 0;
let j;
const avgRangeStart = Math.floor((i + 1) * bucketWidth) + 1;
const avgRangeEnd = Math.min(Math.floor((i + 2) * bucketWidth) + 1, data.length);
const avgRangeStart = Math.floor((i + 1) * bucketWidth) + 1 + start;
const avgRangeEnd = Math.min(Math.floor((i + 2) * bucketWidth) + 1, count) + start;
const avgRangeLength = avgRangeEnd - avgRangeStart;
for (j = avgRangeStart; j < avgRangeEnd; j++) {
avgX = data[j].x;
avgY = data[j].y;
avgX += data[j].x;
avgY += data[j].y;
}
avgX /= avgRangeLength;
avgY /= avgRangeLength;
const rangeOffs = Math.floor(i * bucketWidth) + 1;
const rangeTo = Math.floor((i + 1) * bucketWidth) + 1;
const rangeOffs = Math.floor(i * bucketWidth) + 1 + start;
const rangeTo = Math.floor((i + 1) * bucketWidth) + 1 + start;
const {x: pointAx, y: pointAy} = data[a];
maxArea = area = -1;
for (j = rangeOffs; j < rangeTo; j++) {
Expand All @@ -9038,18 +9042,19 @@ function lttbDecimation(data, availableWidth, options) {
decimated[sampledIndex++] = maxAreaPoint;
a = nextA;
}
decimated[sampledIndex++] = data[data.length - 1];
decimated[sampledIndex++] = data[endIndex];
return decimated;
}
function minMaxDecimation(data, availableWidth) {
function minMaxDecimation(data, start, count, availableWidth) {
let avgX = 0;
let countX = 0;
let i, point, x, y, prevX, minIndex, maxIndex, startIndex, minY, maxY;
const decimated = [];
const xMin = data[0].x;
const xMax = data[data.length - 1].x;
const endIndex = start + count - 1;
const xMin = data[start].x;
const xMax = data[endIndex].x;
const dx = xMax - xMin;
for (i = 0; i < data.length; ++i) {
for (i = start; i < start + count; ++i) {
point = data[i];
x = (point.x - xMin) / dx * availableWidth;
y = point.y;
Expand Down Expand Up @@ -9103,6 +9108,22 @@ function cleanDecimatedData(chart) {
}
});
}
function getStartAndCountOfVisiblePointsSimplified(meta, points) {
const pointCount = points.length;
let start = 0;
let count;
const {iScale} = meta;
const {min, max, minDefined, maxDefined} = iScale.getUserBounds();
if (minDefined) {
start = _limitValue(_lookupByKey(points, iScale.axis, min).lo, 0, pointCount - 1);
}
if (maxDefined) {
count = _limitValue(_lookupByKey(points, iScale.axis, max).hi + 1, start, pointCount) - start;
} else {
count = pointCount - start;
}
return {start, count};
}
var plugin_decimation = {
id: 'decimation',
defaults: {
Expand Down Expand Up @@ -9132,7 +9153,8 @@ var plugin_decimation = {
if (chart.options.parsing) {
return;
}
if (data.length <= 4 * availableWidth) {
let {start, count} = getStartAndCountOfVisiblePointsSimplified(meta, data);
if (count <= 4 * availableWidth) {
return;
}
if (isNullOrUndef(_data)) {
Expand All @@ -9152,10 +9174,10 @@ var plugin_decimation = {
let decimated;
switch (options.algorithm) {
case 'lttb':
decimated = lttbDecimation(data, availableWidth, options);
decimated = lttbDecimation(data, start, count, availableWidth, options);
break;
case 'min-max':
decimated = minMaxDecimation(data, availableWidth);
decimated = minMaxDecimation(data, start, count, availableWidth);
break;
default:
throw new Error(`Unsupported decimation algorithm '${options.algorithm}'`);
Expand Down
2 changes: 1 addition & 1 deletion dist/chart-card/chart-card-min.js

Large diffs are not rendered by default.

Loading

0 comments on commit e177792

Please sign in to comment.