Skip to content

Toggle stacked download graph #5010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/components/download-graph.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<canvas
{{did-insert this.createChart}}
{{did-update this.updateChart @data}}
{{did-update this.updateStacked @stacked}}
{{will-destroy this.destroyChart}}
/>
{{else}}
Expand Down
14 changes: 14 additions & 0 deletions app/components/download-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ export default class DownloadGraph extends Component {
}
}

@action updateStacked() {
let { chart, data } = this;

if (chart) {
data.dataset = data.datasets.map(d => {
d.fill = this.args.stacked ? 'origin' : false;
chart.options.scales.y.stacked = this.args.stacked;
return d;
});
chart.data = data;
chart.update();
}
}

@action destroyChart() {
this.chart?.destroy();
}
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/crate/version.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';

import { task } from 'ember-concurrency';
import { alias } from 'macro-decorators';
Expand All @@ -11,6 +13,16 @@ export default class CrateVersionController extends Controller {
return this.requestedVersion ? this.currentVersion : this.crate;
}

@tracked stackedGraph = true;

@action setStackedGraph() {
this.stackedGraph = true;
}

@action setUnstackedGraph() {
this.stackedGraph = false;
}

@alias('downloadsContext.version_downloads.content') downloads;
@alias('model.crate') crate;
@alias('model.requestedVersion') requestedVersion;
Expand Down
28 changes: 28 additions & 0 deletions app/styles/crate/version.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,37 @@

h4 {
color: var(--main-color-light);
float: left;
}

@media only percy {
display: none;
}
}

.graph-data {
clear: both;
}

.toggle-stacked {
float: right;
margin-top: calc(1.33em - 10px);
margin-bottom: calc(1.33em - 10px);

.trigger {
background-color: var(--main-bg-dark);
font-size: 85%;
padding: 10px;
border: none;
border-radius: 5px;

.trigger-label {
min-width: 65px;
}
}

.dropdown-button {
background: none;
border: 0;
}
}
36 changes: 35 additions & 1 deletion app/templates/crate/version.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,41 @@
</div>
<div local-class='graph'>
<h4>Downloads over the last 90 days</h4>
<DownloadGraph @data={{this.downloads}} local-class="graph-data" />
<div local-class="toggle-stacked">
<span local-class="toggle-stacked-label">Display as </span>
<Dropdown as |dd|>
<dd.Trigger local-class="trigger">
<span local-class="trigger-label">
{{#if this.stackedGraph}}
Stacked
{{else}}
Unstacked
{{/if}}
</span>
</dd.Trigger>
<dd.Menu as |menu|>
<menu.Item>
<button
type="button"
local-class="dropdown-button"
{{on "click" this.setStackedGraph}}
>
Stacked
</button>
</menu.Item>
<menu.Item>
<button
type="button"
local-class="dropdown-button"
{{on "click" this.setUnstackedGraph}}
>
Unstacked
</button>
</menu.Item>
</dd.Menu>
</Dropdown>
</div>
<DownloadGraph @data={{this.downloads}} @stacked={{this.stackedGraph}} local-class="graph-data" />
</div>
</div>
{{/if}}