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 10
10
<canvas
11
11
{{ did-insert this.createChart }}
12
12
{{ did-update this.updateChart @data }}
13
+ {{ did-update this.updateStacked @stacked }}
13
14
{{ will-destroy this.destroyChart }}
14
15
/>
15
16
{{ else }}
Original file line number Diff line number Diff line change @@ -59,6 +59,20 @@ export default class DownloadGraph extends Component {
59
59
}
60
60
}
61
61
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
+
62
76
@action destroyChart ( ) {
63
77
this . chart ?. destroy ( ) ;
64
78
}
Original file line number Diff line number Diff line change 1
1
import Controller from '@ember/controller' ;
2
+ import { action } from '@ember/object' ;
2
3
import { inject as service } from '@ember/service' ;
4
+ import { tracked } from '@glimmer/tracking' ;
3
5
4
6
import { task } from 'ember-concurrency' ;
5
7
import { alias } from 'macro-decorators' ;
@@ -11,6 +13,16 @@ export default class CrateVersionController extends Controller {
11
13
return this . requestedVersion ? this . currentVersion : this . crate ;
12
14
}
13
15
16
+ @tracked stackedGraph = true ;
17
+
18
+ @action setStackedGraph ( ) {
19
+ this . stackedGraph = true ;
20
+ }
21
+
22
+ @action setUnstackedGraph ( ) {
23
+ this . stackedGraph = false ;
24
+ }
25
+
14
26
@alias ( 'downloadsContext.version_downloads.content' ) downloads ;
15
27
@alias ( 'model.crate' ) crate ;
16
28
@alias ( 'model.requestedVersion' ) requestedVersion ;
Original file line number Diff line number Diff line change 125
125
126
126
h4 {
127
127
color : var (--main-color-light );
128
+ float : left;
128
129
}
129
130
130
131
@media only percy {
131
132
display : none;
132
133
}
133
134
}
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 79
79
</div >
80
80
<div local-class =' graph' >
81
81
<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" />
83
117
</div >
84
118
</div >
85
119
{{ /if }}
You can’t perform that action at this time.
0 commit comments