Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mrspence committed Mar 22, 2021
2 parents 7424b6b + fe7ebb6 commit 80c9a20
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/vue-charts-css.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions example/dist/example.js

Large diffs are not rendered by default.

63 changes: 59 additions & 4 deletions example/src/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<div>
<h1>Chart Examples</h1>

<button @click="addDataset">Add Dataset</button>
<button @click="removeDataset">Remove Dataset</button>

<h2>Column</h2>
<charts-css
type="column"
Expand All @@ -20,10 +23,11 @@

<h2>Bar</h2>
<charts-css
v-if="datasets.length"
type="bar"
heading="Bens coffee count"
:heading="datasets[0].name + '\'s coffee count'"
:labels="labels"
:datasets="[{values: datasets[1].values }]"
:datasets="[ datasets[0], ]"
:height="300"
:data-spacing="20"
:formatDataValue="(value) => value + ' coffee' + ( value > 1 ? 's':'' )"
Expand All @@ -39,7 +43,7 @@
<h2>Area</h2>
<charts-css
type="area"
heading="Bens coffee count"
heading="Team's coffee count"
:labels="labels"
:datasets="datasets"
:height="300"
Expand All @@ -54,7 +58,7 @@
<h2>Line</h2>
<charts-css
type="line"
heading="Bens coffee count"
heading="Team's coffee count"
:labels="labels"
:datasets="datasets"
:height="300"
Expand Down Expand Up @@ -92,5 +96,56 @@
],
};
},
methods: {
addDataset()
{
this.datasets.push({
name: this.generateName(),
values: [this.generateNumber(), this.generateNumber(), this.generateNumber(), this.generateNumber(),],
});
},
removeDataset()
{
this.datasets = this.datasets.slice(1);
},
generateName()
{
const randomNames = [
"Genaro",
"Zandra",
"Nancey",
"Jeannette",
"Michel",
"Kacey",
"Essie",
"Kristi",
"Manuel",
"Cherrie",
"Dollie",
"Jordon",
"Cathie",
"Latoyia",
"Herlinda",
];
return randomNames[Math.floor(Math.random() * randomNames.length)];
},
generateNumber()
{
return Math.round(Math.random() * 100);
},
animate()
{
this.removeDataset();
this.addDataset();
setTimeout(this.animate, 2000);
}
},
mounted()
{
this.animate();
}
}
</script>
2 changes: 1 addition & 1 deletion src/chart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<slot name="legend" v-if="( $slots.legend || showLegend ) && this.datasets.length > 1">
<ul :class="legendClasses">
<li v-for="(dataset, index) in datasets" :key="dataset.name">
<li v-for="(dataset, index) in datasets" :key="index + '' + datasets.length">
{{ dataset.name }}
</li>
</ul>
Expand Down
4 changes: 2 additions & 2 deletions src/charts/area.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
<tbody>
<tr
v-for="(row, rowIndex) in rows"
:key="row.name"
:key="rowIndex + '-' + row.length"
>
<th scope="row">{{ labels[rowIndex] }}</th>

<td
v-for="(value, colIndex) in row"
:key="rowIndex + '-' + colIndex + '-' + value.valueRaw"
:key="colIndex + '-' + row.length"
:style="resolveDataStyle(value, rowIndex, colIndex)"
>
<span class="data">
Expand Down
4 changes: 2 additions & 2 deletions src/charts/bar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
<tbody>
<tr
v-for="(row, rowIndex) in rows"
:key="row.name"
:key="rowIndex + '-' + row.length"
>
<th scope="row">{{ labels[rowIndex] }}</th>

<td
v-for="(value, colIndex) in row"
:key="rowIndex + '-' + colIndex + '-' + value.valueRaw"
:key="colIndex + '-' + row.length"
:style="resolveDataStyle(value, rowIndex, colIndex)"
>
<span class="data">{{ formatDataValue(value.valueRaw) }}</span>
Expand Down
4 changes: 2 additions & 2 deletions src/charts/column.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
<tbody>
<tr
v-for="(row, rowIndex) in rows"
:key="row.name"
:key="rowIndex + '-' + row.length"
>
<th scope="row">{{ labels[rowIndex] }}</th>

<td
v-for="(value, colIndex) in row"
:key="rowIndex + '-' + colIndex + '-' + value.valueRaw"
:key="colIndex + '-' + row.length"
:style="resolveDataStyle(value, rowIndex, colIndex)"
>
<span class="data">
Expand Down
4 changes: 2 additions & 2 deletions src/charts/line.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
<tbody>
<tr
v-for="(row, rowIndex) in rows"
:key="row.name"
:key="rowIndex + '-' + row.length"
>
<th scope="row">{{ labels[rowIndex] }}</th>

<td
v-for="(value, colIndex) in row"
:key="rowIndex + '-' + colIndex + '-' + value.valueRaw"
:key="colIndex + '-' + row.length"
:style="resolveDataStyle(value, rowIndex, colIndex)"
>
<span class="data">
Expand Down

0 comments on commit 80c9a20

Please sign in to comment.