File tree Expand file tree Collapse file tree 5 files changed +90
-1
lines changed Expand file tree Collapse file tree 5 files changed +90
-1
lines changed Original file line number Diff line number Diff line change 1010 <canvas
1111 {{ did-insert this.createChart }}
1212 {{ did-update this.updateChart @data }}
13+ {{ did-update this.updateStacked @stacked }}
1314 {{ will-destroy this.destroyChart }}
1415 />
1516 {{ else }}
Original file line number Diff line number Diff line change @@ -59,6 +59,20 @@ export default class DownloadGraph extends Component {
5959 }
6060 }
6161
62+ @action updateStacked ( ) {
63+ let { chart, data } = this ;
64+
65+ if ( chart ) {
66+ data . dataset = data . datasets . map ( d => {
67+ d . fill = this . args . stacked ? 'origin' : false ;
68+ chart . options . scales . y . stacked = this . args . stacked ;
69+ return d ;
70+ } ) ;
71+ chart . data = data ;
72+ chart . update ( ) ;
73+ }
74+ }
75+
6276 @action destroyChart ( ) {
6377 this . chart ?. destroy ( ) ;
6478 }
Original file line number Diff line number Diff line change 11import Controller from '@ember/controller' ;
2+ import { action } from '@ember/object' ;
23import { inject as service } from '@ember/service' ;
4+ import { tracked } from '@glimmer/tracking' ;
35
46import { task } from 'ember-concurrency' ;
57import { alias } from 'macro-decorators' ;
@@ -11,6 +13,16 @@ export default class CrateVersionController extends Controller {
1113 return this . requestedVersion ? this . currentVersion : this . crate ;
1214 }
1315
16+ @tracked stackedGraph = true ;
17+
18+ @action setStackedGraph ( ) {
19+ this . stackedGraph = true ;
20+ }
21+
22+ @action setUnstackedGraph ( ) {
23+ this . stackedGraph = false ;
24+ }
25+
1426 @alias ( 'downloadsContext.version_downloads.content' ) downloads ;
1527 @alias ( 'model.crate' ) crate ;
1628 @alias ( 'model.requestedVersion' ) requestedVersion ;
Original file line number Diff line number Diff line change 125125
126126 h4 {
127127 color : var (--main-color-light );
128+ float : left;
128129 }
129130
130131 @media only percy {
131132 display : none;
132133 }
133134}
135+
136+ .graph-data {
137+ clear : both;
138+ }
139+
140+ .toggle-stacked {
141+ float : right;
142+ margin-top : calc (1.33em - 10px );
143+ margin-bottom : calc (1.33em - 10px );
144+
145+ .trigger {
146+ background-color : var (--main-bg-dark );
147+ font-size : 85% ;
148+ padding : 10px ;
149+ border : none;
150+ border-radius : 5px ;
151+
152+ .trigger-label {
153+ min-width : 65px ;
154+ }
155+ }
156+
157+ .dropdown-button {
158+ background : none;
159+ border : 0 ;
160+ }
161+ }
Original file line number Diff line number Diff line change 7979 </div >
8080 <div local-class =' graph' >
8181 <h4 >Downloads over the last 90 days</h4 >
82- <DownloadGraph @data ={{ this.downloads }} local-class =" graph-data" />
82+ <div local-class =" toggle-stacked" >
83+ <span local-class =" toggle-stacked-label" >Display as </span >
84+ <Dropdown as |dd|>
85+ <dd .Trigger local-class =" trigger" >
86+ <span local-class =" trigger-label" >
87+ {{ #if this.stackedGraph }}
88+ Stacked
89+ {{ else }}
90+ Unstacked
91+ {{ /if }}
92+ </span >
93+ </dd .Trigger>
94+ <dd .Menu as |menu|>
95+ <menu .Item>
96+ <button
97+ type =" button"
98+ local-class =" dropdown-button"
99+ {{ on " click" this.setStackedGraph }}
100+ >
101+ Stacked
102+ </button >
103+ </menu .Item>
104+ <menu .Item>
105+ <button
106+ type =" button"
107+ local-class =" dropdown-button"
108+ {{ on " click" this.setUnstackedGraph }}
109+ >
110+ Unstacked
111+ </button >
112+ </menu .Item>
113+ </dd .Menu>
114+ </Dropdown >
115+ </div >
116+ <DownloadGraph @data ={{ this.downloads }} @stacked ={{ this.stackedGraph }} local-class =" graph-data" />
83117 </div >
84118 </div >
85119{{ /if }}
You can’t perform that action at this time.
0 commit comments