@inb/oeb_visualizations 0.0.7 → 0.0.8-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,8 +4,13 @@
4
4
  var script$1 = {
5
5
  name: 'accessibilityPlot',
6
6
  data: () => ({
7
- divId: randstr('acc_plot'),
8
- max_access_time: 0
7
+ divId: randstr('acc_plot_'),
8
+ max_access_time: 0,
9
+ config: {
10
+ displaylogo: false,
11
+ responsive: true,
12
+ modeBarButtonsToRemove: ['lasso']
13
+ }
9
14
  }),
10
15
  props: {
11
16
  dtick: {
@@ -76,6 +81,15 @@ var script$1 = {
76
81
  required: false,
77
82
  default: false
78
83
  },
84
+ sixMonths: {
85
+ /*
86
+ whether the plot is used to show data of six months
87
+ If true, months are shown on the x axis
88
+ */
89
+ type: Boolean,
90
+ required: false,
91
+ default: false
92
+ },
79
93
  dataItems: {
80
94
  /*
81
95
  dataItems is an array of objects with keys "access_time", "date" and "code".
@@ -138,12 +152,13 @@ var script$1 = {
138
152
  margin: {
139
153
  l: 50,
140
154
  r: 50,
141
- b: 70,
142
- t: 70,
155
+ b: 50,
156
+ t: 20,
143
157
  pad: 4
144
158
  },
145
159
  xaxis: {
146
160
  type: 'date',
161
+ ticklabelmode: this.xaxisMode(),
147
162
  title: this.xaxisTitle,
148
163
  font: {
149
164
  size: 10
@@ -151,16 +166,17 @@ var script$1 = {
151
166
  tickfont: {
152
167
  size: 10
153
168
  },
154
- showgrid: this.week ? true : false,
169
+ showgrid: this.sixMonths ? true : false,
155
170
  griddash: "dot",
156
171
  gridwidth: 1,
172
+ gridcolor: "#d9d7d7",
157
173
  showspikes: true,
158
174
  spikedash: "4px",
159
175
  spikethickness: 1,
160
- tick0: this.dataItems[0].date,
161
- dtick: this.dtick,
162
- tickangle: this.xaxesTickAngle(),
163
- tickformat: this.xaxesTickFormat()
176
+ tick0: this.xaxisTickZero(),
177
+ dtick: this.xaxisTickD(),
178
+ tickangle: this.xaxisTickAngle(),
179
+ tickformat: this.xaxisTickFormat()
164
180
  },
165
181
  yaxis: {
166
182
  title: this.yaxisTitle,
@@ -175,9 +191,9 @@ var script$1 = {
175
191
  legend: {
176
192
  orientation: 'h',
177
193
  yanchor: 'bottom',
178
- y: 1.02,
179
- xanchor: 'right',
180
- x: 1,
194
+ y: -0.5,
195
+ xanchor: 'left',
196
+ x: 0.05,
181
197
  font: {
182
198
  size: 8
183
199
  }
@@ -187,7 +203,8 @@ var script$1 = {
187
203
  },
188
204
  hovermode: 'closest'
189
205
  };
190
- Plotly__default["default"].newPlot(this.divId, traces, layout);
206
+ console.log(this.divId);
207
+ Plotly__default["default"].newPlot(this.divId, traces, layout, this.config);
191
208
  },
192
209
  methods: {
193
210
  generateColor(values, transparency) {
@@ -315,7 +332,7 @@ var script$1 = {
315
332
  // set start and end dates so that the line spands the whole plot
316
333
  const firstDate = new Date(this.dataItems[0].date);
317
334
  if (this.week) {
318
- firstDate.setDate(firstDate.getDate() - 0.1); // one day before the first date in data
335
+ firstDate.setDate(firstDate.getDate() - 0.3); // one day before the first date in data
319
336
  } else {
320
337
  firstDate.setDate(firstDate.getDate() - 1); // one month before the first date in data
321
338
  }
@@ -461,7 +478,7 @@ var script$1 = {
461
478
  }
462
479
  return traces;
463
480
  },
464
- xaxesTickFormat() {
481
+ xaxisTickFormat() {
465
482
  /*
466
483
  This function returns the tickformat of the x axis.
467
484
  If the plot is used to show data of one week, it returns the day of the week and the day.
@@ -470,11 +487,14 @@ var script$1 = {
470
487
 
471
488
  if (this.week) {
472
489
  return "%A<br>%d %b";
490
+ }
491
+ if (this.sixMonths) {
492
+ return "%b";
473
493
  } else {
474
494
  return "%d %b";
475
495
  }
476
496
  },
477
- xaxesTickAngle() {
497
+ xaxisTickAngle() {
478
498
  /*
479
499
  This function returns the tickangle of the x axis.
480
500
  If the plot is used to show data of one week, it returns 0.
@@ -482,9 +502,38 @@ var script$1 = {
482
502
  */
483
503
  if (this.week) {
484
504
  return 0;
505
+ }
506
+ if (this.sixMonths) {
507
+ return 0;
485
508
  } else {
486
509
  return 45;
487
510
  }
511
+ },
512
+ xaxisTickD() {
513
+ if (this.sixMonths === true) {
514
+ return "M1";
515
+ } else {
516
+ return this.dtick;
517
+ }
518
+ },
519
+ xaxisTickZero() {
520
+ if (this.sixMonths === true) {
521
+ console.log('zero six months ago');
522
+ const lastDate = new Date(this.dataItems[this.dataItems.length - 1].date);
523
+ //return lastDate minus six months
524
+ console.log(lastDate);
525
+ console.log('six months ago: ' + new Date(lastDate.setMonth(lastDate.getMonth() - 6)));
526
+ return new Date(lastDate.setMonth(lastDate.getMonth() - 6));
527
+ } else {
528
+ return this.dataItems[0];
529
+ }
530
+ },
531
+ xaxisMode() {
532
+ if (this.sixMonths === true) {
533
+ return "period";
534
+ } else {
535
+ return "instant";
536
+ }
488
537
  }
489
538
  }
490
539
  };function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier
@@ -591,7 +640,7 @@ const __vue_inject_styles__$1 = undefined;
591
640
  /* scoped */
592
641
  const __vue_scope_id__$1 = undefined;
593
642
  /* module identifier */
594
- const __vue_module_identifier__$1 = "data-v-5ead469f";
643
+ const __vue_module_identifier__$1 = "data-v-77c84891";
595
644
  /* functional template */
596
645
  const __vue_is_functional_template__$1 = false;
597
646
  /* style inject */
@@ -605,7 +654,7 @@ var accessibilityPlot = normalizeComponent_1({
605
654
  var script = {
606
655
  name: 'citationsPlot',
607
656
  data: () => ({
608
- divId: randstr('cit_plot')
657
+ divId: randstr('cit_plot_')
609
658
  }),
610
659
  props: {
611
660
  dataTraces: {
@@ -777,7 +826,7 @@ const __vue_inject_styles__ = undefined;
777
826
  /* scoped */
778
827
  const __vue_scope_id__ = undefined;
779
828
  /* module identifier */
780
- const __vue_module_identifier__ = "data-v-64c53c55";
829
+ const __vue_module_identifier__ = "data-v-4ac5e814";
781
830
  /* functional template */
782
831
  const __vue_is_functional_template__ = false;
783
832
  /* style inject */
@@ -8,8 +8,13 @@ function randstr(prefix) {
8
8
  var script$1 = {
9
9
  name: 'accessibilityPlot',
10
10
  data: () => ({
11
- divId: randstr('acc_plot'),
12
- max_access_time: 0
11
+ divId: randstr('acc_plot_'),
12
+ max_access_time: 0,
13
+ config: {
14
+ displaylogo: false,
15
+ responsive: true,
16
+ modeBarButtonsToRemove: ['lasso']
17
+ }
13
18
  }),
14
19
  props: {
15
20
  dtick: {
@@ -80,6 +85,15 @@ var script$1 = {
80
85
  required: false,
81
86
  default: false
82
87
  },
88
+ sixMonths: {
89
+ /*
90
+ whether the plot is used to show data of six months
91
+ If true, months are shown on the x axis
92
+ */
93
+ type: Boolean,
94
+ required: false,
95
+ default: false
96
+ },
83
97
  dataItems: {
84
98
  /*
85
99
  dataItems is an array of objects with keys "access_time", "date" and "code".
@@ -142,12 +156,13 @@ var script$1 = {
142
156
  margin: {
143
157
  l: 50,
144
158
  r: 50,
145
- b: 70,
146
- t: 70,
159
+ b: 50,
160
+ t: 20,
147
161
  pad: 4
148
162
  },
149
163
  xaxis: {
150
164
  type: 'date',
165
+ ticklabelmode: this.xaxisMode(),
151
166
  title: this.xaxisTitle,
152
167
  font: {
153
168
  size: 10
@@ -155,16 +170,17 @@ var script$1 = {
155
170
  tickfont: {
156
171
  size: 10
157
172
  },
158
- showgrid: this.week ? true : false,
173
+ showgrid: this.sixMonths ? true : false,
159
174
  griddash: "dot",
160
175
  gridwidth: 1,
176
+ gridcolor: "#d9d7d7",
161
177
  showspikes: true,
162
178
  spikedash: "4px",
163
179
  spikethickness: 1,
164
- tick0: this.dataItems[0].date,
165
- dtick: this.dtick,
166
- tickangle: this.xaxesTickAngle(),
167
- tickformat: this.xaxesTickFormat()
180
+ tick0: this.xaxisTickZero(),
181
+ dtick: this.xaxisTickD(),
182
+ tickangle: this.xaxisTickAngle(),
183
+ tickformat: this.xaxisTickFormat()
168
184
  },
169
185
  yaxis: {
170
186
  title: this.yaxisTitle,
@@ -179,9 +195,9 @@ var script$1 = {
179
195
  legend: {
180
196
  orientation: 'h',
181
197
  yanchor: 'bottom',
182
- y: 1.02,
183
- xanchor: 'right',
184
- x: 1,
198
+ y: -0.5,
199
+ xanchor: 'left',
200
+ x: 0.05,
185
201
  font: {
186
202
  size: 8
187
203
  }
@@ -191,7 +207,8 @@ var script$1 = {
191
207
  },
192
208
  hovermode: 'closest'
193
209
  };
194
- Plotly.newPlot(this.divId, traces, layout);
210
+ console.log(this.divId);
211
+ Plotly.newPlot(this.divId, traces, layout, this.config);
195
212
  },
196
213
  methods: {
197
214
  generateColor(values, transparency) {
@@ -319,7 +336,7 @@ var script$1 = {
319
336
  // set start and end dates so that the line spands the whole plot
320
337
  const firstDate = new Date(this.dataItems[0].date);
321
338
  if (this.week) {
322
- firstDate.setDate(firstDate.getDate() - 0.1); // one day before the first date in data
339
+ firstDate.setDate(firstDate.getDate() - 0.3); // one day before the first date in data
323
340
  } else {
324
341
  firstDate.setDate(firstDate.getDate() - 1); // one month before the first date in data
325
342
  }
@@ -465,7 +482,7 @@ var script$1 = {
465
482
  }
466
483
  return traces;
467
484
  },
468
- xaxesTickFormat() {
485
+ xaxisTickFormat() {
469
486
  /*
470
487
  This function returns the tickformat of the x axis.
471
488
  If the plot is used to show data of one week, it returns the day of the week and the day.
@@ -474,11 +491,14 @@ var script$1 = {
474
491
 
475
492
  if (this.week) {
476
493
  return "%A<br>%d %b";
494
+ }
495
+ if (this.sixMonths) {
496
+ return "%b";
477
497
  } else {
478
498
  return "%d %b";
479
499
  }
480
500
  },
481
- xaxesTickAngle() {
501
+ xaxisTickAngle() {
482
502
  /*
483
503
  This function returns the tickangle of the x axis.
484
504
  If the plot is used to show data of one week, it returns 0.
@@ -486,9 +506,38 @@ var script$1 = {
486
506
  */
487
507
  if (this.week) {
488
508
  return 0;
509
+ }
510
+ if (this.sixMonths) {
511
+ return 0;
489
512
  } else {
490
513
  return 45;
491
514
  }
515
+ },
516
+ xaxisTickD() {
517
+ if (this.sixMonths === true) {
518
+ return "M1";
519
+ } else {
520
+ return this.dtick;
521
+ }
522
+ },
523
+ xaxisTickZero() {
524
+ if (this.sixMonths === true) {
525
+ console.log('zero six months ago');
526
+ const lastDate = new Date(this.dataItems[this.dataItems.length - 1].date);
527
+ //return lastDate minus six months
528
+ console.log(lastDate);
529
+ console.log('six months ago: ' + new Date(lastDate.setMonth(lastDate.getMonth() - 6)));
530
+ return new Date(lastDate.setMonth(lastDate.getMonth() - 6));
531
+ } else {
532
+ return this.dataItems[0];
533
+ }
534
+ },
535
+ xaxisMode() {
536
+ if (this.sixMonths === true) {
537
+ return "period";
538
+ } else {
539
+ return "instant";
540
+ }
492
541
  }
493
542
  }
494
543
  };
@@ -615,7 +664,7 @@ var accessibilityPlot = normalizeComponent_1({
615
664
  var script = {
616
665
  name: 'citationsPlot',
617
666
  data: () => ({
618
- divId: randstr('cit_plot')
667
+ divId: randstr('cit_plot_')
619
668
  }),
620
669
  props: {
621
670
  dataTraces: {
@@ -1 +1 @@
1
- var oeb_visualizations=function(e,t){"use strict";function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=i(t);function s(e){return Math.random().toString(36).replace("0.",e||"")}var r=function(e,t,i,a,s,r,o,n,l,c){"boolean"!=typeof o&&(l=n,n=o,o=!1);var d,h="function"==typeof i?i.options:i;if(e&&e.render&&(h.render=e.render,h.staticRenderFns=e.staticRenderFns,h._compiled=!0,s&&(h.functional=!0)),a&&(h._scopeId=a),r?(d=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),t&&t.call(this,l(e)),e&&e._registeredComponents&&e._registeredComponents.add(r)},h._ssrRegister=d):t&&(d=o?function(){t.call(this,c(this.$root.$options.shadowRoot))}:function(e){t.call(this,n(e))}),d)if(h.functional){var u=h.render;h.render=function(e,t){return d.call(t),u(e,t)}}else{var m=h.beforeCreate;h.beforeCreate=m?[].concat(m,d):[d]}return i};var o=r({render:function(){var e=this,t=e.$createElement;return(e._self._c||t)("div",{attrs:{id:e.divId}})},staticRenderFns:[]},undefined,{name:"accessibilityPlot",data:()=>({divId:s("acc_plot"),max_access_time:0}),props:{dtick:{type:Number,required:!1,default:864e5},xaxisTitle:{type:String,required:!1,default:"Date"},yaxisTitle:{type:String,required:!1,default:"Access time (ms)"},colorOnline:{type:String,required:!1,default:"111, 176, 129"},colorOffline:{type:String,required:!1,default:"255, 153, 145"},colorNA:{type:String,required:!1,default:"204,204,204"},height:{type:Number,required:!1,default:350},week:{type:Boolean,required:!1,default:!1},dataItems:{type:Array,required:!0,validator:function(e){for(let t=0;t<e.length;t++)e[t].hasOwnProperty("access_time")?e[t].hasOwnProperty("date")?e[t].hasOwnProperty("code")||console.error(`[oeb-visualizations warn] code key is missing in dataItems prop item (at position ${t})`):console.error(`[oeb-visualizations warn] date key is missing in dataItems prop item (at position ${t})`):console.error(`[oeb-visualizations warn] access_time key is missing in dataItems prop item (at position ${t})`),null!==e[t].access_time&&"number"!=typeof e[t].access_time&&console.error(`[oeb-visualizations warn] access_time must be null or a number in dataItems prop item (at position ${t})`),null!==e[t].code&&"number"!=typeof e[t].code&&console.error(`[oeb-visualizations warn] code must be null or a number in dataItems prop item (at position ${t})`),("string"!=typeof e[t].date||isNaN(Date.parse(e[t].date)))&&console.error(`[oeb-visualizations warn] date must be a string containing a date in dataItems prop item (at position ${t})`),null===e[t].date&&console.error(`[oeb-visualizations warn] date cannot be null in dataItems prop item (at position ${t})`);return!0}}},mounted(){this.max_access_time=Math.max(...this.dataItems.map((e=>e.access_time)));var e=this.buildOnlineTraces(this.dataItems);e=e.concat(this.buildOfflineNATraces(this.dataItems));const t={bargap:0,barmode:"stack",showlegend:!0,autosize:!0,height:this.height,margin:{l:50,r:50,b:70,t:70,pad:4},xaxis:{type:"date",title:this.xaxisTitle,font:{size:10},tickfont:{size:10},showgrid:!!this.week,griddash:"dot",gridwidth:1,showspikes:!0,spikedash:"4px",spikethickness:1,tick0:this.dataItems[0].date,dtick:this.dtick,tickangle:this.xaxesTickAngle(),tickformat:this.xaxesTickFormat()},yaxis:{title:this.yaxisTitle,titlefont:{size:10},tickfont:{size:10}},template:"plotly_white",legend:{orientation:"h",yanchor:"bottom",y:1.02,xanchor:"right",x:1,font:{size:8}},hoverlabel:{bgcolor:"#FFF"},hovermode:"closest"};a.default.newPlot(this.divId,e,t)},methods:{generateColor(e,t){let i=[];for(let a=0;a<30;a++)switch(e[a]){case"up":i.push(`rgba(${this.colorOnline},0)`);break;case"down":i.push(`rgba(${this.colorOffline},${t})`);break;case"NA":i.push(`rgba(${this.colorNA},${t})`)}return i},extractSubarraysBetweenNullValues(e){var t={access_time:[],date:[],average_access_time:0},i=[],a=[],s=0,r=0;for(let o=0;o<e.length;o++)null!==e[o].access_time?(i.push(e[o].access_time),a.push(e[o].date),s+=e[o].access_time,r+=1):i.length>0&&(t.access_time.push(i),t.date.push(a),i=[],a=[]);return t.access_time.push(i),t.date.push(a),t.average_access_time=s/r,t},buildAccessTimeTraces(e){var t=[];for(let i=0;i<e.access_time.length;i++){const a=e.access_time[i],s={x:e.date[i],y:a,name:"Online",legendgroup:"up",showlegend:0===i,mode:"markers+lines",type:"scatter",fill:"tozeroy",fillcolor:`rgba(${this.colorOnline},.2)`,connectgaps:!1,line:{color:`rgba(${this.colorOnline},.8)`,width:1.5},marker:{size:5},hovertemplate:"<b>Online</b><br>%{x|%d %b %Y}<br>%{y} ms <extra></extra>",hoveron:"points+fills"};t.push(s)}return t},buildAvgAccessTimeTrace(e){const t=new Date(this.dataItems[0].date);this.week?t.setDate(t.getDate()-.1):t.setDate(t.getDate()-1);const i=new Date(this.dataItems[this.dataItems.length-1].date);this.week?i.setDate(i.getDate()+.3):i.setDate(i.getDate()+1);return{x:[t,i],y:[e,e],name:"Average access time",showlegend:!0,mode:"lines",type:"scatter",line:{color:`rgba(${this.colorOnline},.6)`,width:1.5,dash:"4px"},marker:{size:5},hovertemplate:"<b>Average access time</b><br>%{y:.2f} ms <extra></extra>"}},buildOnlineTraces(e){const t=this.extractSubarraysBetweenNullValues(e);var i=this.buildAccessTimeTraces(t);return i.push(this.buildAvgAccessTimeTrace(t.average_access_time)),i},extractOfflineNADates(e){const t=[],i=[];for(let a=0;a<e.length;a++)null===e[a].access_time&&null===e[a].code?t.push(e[a].date):null===e[a].access_time&&i.push(e[a].date);return{NA:t,down:i}},barTrace(e,t,i,a,s,r){const o={x:e.dates,y:e.access_times,marker:{color:e.colors},name:t,type:"bar",legendgroup:r,showlegend:i,hoverinfo:a,hovertemplate:s,width:864e5};return console.log(o),o},buildBarTraces(e,t,i,a){const s=`rgba(${t},.8)`,r=`rgba(${t},.2)`,o={dates:e,access_times:Array(e.length).fill(2),colors:Array(e.length).fill(s)},n={dates:e,access_times:Array(e.length).fill(1.1*this.max_access_time),colors:Array(e.length).fill(r)},l=`<b>${i}</b><br>%{x|%d %b %Y}<br>%{y} ms <extra></extra>`;return[this.barTrace(o,i,!1,"skip","",a),this.barTrace(n,i,!0,"all",l,a)]},buildOfflineNATraces(e){var t=[];const i=this.extractOfflineNADates(e);return i.down.length>0&&(t=t.concat(this.buildBarTraces(i.down,this.colorOffline,"Offline","down")),console.log(i.down)),i.NA.length>0&&(t=t.concat(this.buildBarTraces(i.NA,this.colorNA,"No information available","na")),console.log(i.NA)),t},xaxesTickFormat(){return this.week?"%A<br>%d %b":"%d %b"},xaxesTickAngle(){return this.week?0:45}}},undefined,!1,undefined,void 0,void 0);var n=r({render:function(){var e=this,t=e.$createElement;return(e._self._c||t)("div",{attrs:{id:e.divId}})},staticRenderFns:[]},undefined,{name:"citationsPlot",data:()=>({divId:s("cit_plot")}),props:{dataTraces:{type:Array,required:!0},stack:{type:Boolean,required:!1,default:!1},colors:{type:Array,required:!1,default:()=>["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd"]},height:{type:Number,required:!1,default:400},showlegend:{type:Boolean,required:!1,default:!0},title:{type:String,required:!1,default:""},xaxisTitle:{type:String,required:!1,default:"Year"},yaxisTitle:{type:String,required:!1,default:"Number of citations"},darkMode:{type:Boolean,required:!1,default:!1}},mounted(){const e=this.buildTraces(),t={showlegend:this.showlegend,autosize:!0,height:this.height,margin:{l:50,r:50,b:70,t:50,pad:4},xaxis:{title:this.xaxisTitle,font:{size:10},tickfont:{size:10},tickmode:"linear",color:this.darkMode?"white":"black"},yaxis:{title:this.yaxisTitle,titlefont:{size:10},tickfont:{size:10},font:{size:10},color:this.darkMode?"white":"black"},legend:{orientation:"h",yanchor:"bottom",y:1.02,xanchor:"right",x:1,font:{size:8,color:this.darkMode?"white":"black"}},hoverlabel:{color:this.darkMode?"white":"black"},hovermode:this.stack?"x unified":"closest",hoverdistance:70,plot_bgcolor:this.darkMode?"rgb(38, 50, 56)":"white",paper_bgcolor:this.darkMode?"rgb(38, 50, 56)":"white"};a.default.newPlot(this.divId,e,t)},methods:{buildTraces(){const e=[];for(let t=0;t<this.dataTraces.length;t++){const i={x:this.dataTraces[t].data.map((e=>e.year)),y:this.dataTraces[t].data.map((e=>e.citations)),mode:"lines+markers",name:this.dataTraces[t].label,hovertemplate:this.hoverTemplate(),marker:{size:5},line:{color:this.colors[t],width:1.8},stackgroup:this.stack?"one":null};e.push(i)}return e},hoverTemplate(){return this.stack?"%{y} citations <extra></extra>":"%{y} citations in %{x} <extra></extra>"}}},undefined,!1,undefined,void 0,void 0),l=Object.freeze({__proto__:null,accessibilityPlot:o,citationsPlot:n});const c=function(e){c.installed||(c.installed=!0,Object.entries(l).forEach((([t,i])=>{e.component(t,i)})))},d={install:c};{let e=null;"undefined"!=typeof window?e=window.Vue:"undefined"!=typeof global&&(e=global.Vue),e&&e.use(d)}return e.accessibilityPlot=o,e.citationsPlot=n,e.default=d,Object.defineProperty(e,"__esModule",{value:!0}),e}({},Plotly);
1
+ var oeb_visualizations=function(e,t){"use strict";function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=i(t);function a(e){return Math.random().toString(36).replace("0.",e||"")}var r=function(e,t,i,s,a,r,o,n,l,c){"boolean"!=typeof o&&(l=n,n=o,o=!1);var d,h="function"==typeof i?i.options:i;if(e&&e.render&&(h.render=e.render,h.staticRenderFns=e.staticRenderFns,h._compiled=!0,a&&(h.functional=!0)),s&&(h._scopeId=s),r?(d=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),t&&t.call(this,l(e)),e&&e._registeredComponents&&e._registeredComponents.add(r)},h._ssrRegister=d):t&&(d=o?function(){t.call(this,c(this.$root.$options.shadowRoot))}:function(e){t.call(this,n(e))}),d)if(h.functional){var u=h.render;h.render=function(e,t){return d.call(t),u(e,t)}}else{var m=h.beforeCreate;h.beforeCreate=m?[].concat(m,d):[d]}return i};var o=r({render:function(){var e=this,t=e.$createElement;return(e._self._c||t)("div",{attrs:{id:e.divId}})},staticRenderFns:[]},undefined,{name:"accessibilityPlot",data:()=>({divId:a("acc_plot_"),max_access_time:0,config:{displaylogo:!1,responsive:!0,modeBarButtonsToRemove:["lasso"]}}),props:{dtick:{type:Number,required:!1,default:864e5},xaxisTitle:{type:String,required:!1,default:"Date"},yaxisTitle:{type:String,required:!1,default:"Access time (ms)"},colorOnline:{type:String,required:!1,default:"111, 176, 129"},colorOffline:{type:String,required:!1,default:"255, 153, 145"},colorNA:{type:String,required:!1,default:"204,204,204"},height:{type:Number,required:!1,default:350},week:{type:Boolean,required:!1,default:!1},sixMonths:{type:Boolean,required:!1,default:!1},dataItems:{type:Array,required:!0,validator:function(e){for(let t=0;t<e.length;t++)e[t].hasOwnProperty("access_time")?e[t].hasOwnProperty("date")?e[t].hasOwnProperty("code")||console.error(`[oeb-visualizations warn] code key is missing in dataItems prop item (at position ${t})`):console.error(`[oeb-visualizations warn] date key is missing in dataItems prop item (at position ${t})`):console.error(`[oeb-visualizations warn] access_time key is missing in dataItems prop item (at position ${t})`),null!==e[t].access_time&&"number"!=typeof e[t].access_time&&console.error(`[oeb-visualizations warn] access_time must be null or a number in dataItems prop item (at position ${t})`),null!==e[t].code&&"number"!=typeof e[t].code&&console.error(`[oeb-visualizations warn] code must be null or a number in dataItems prop item (at position ${t})`),("string"!=typeof e[t].date||isNaN(Date.parse(e[t].date)))&&console.error(`[oeb-visualizations warn] date must be a string containing a date in dataItems prop item (at position ${t})`),null===e[t].date&&console.error(`[oeb-visualizations warn] date cannot be null in dataItems prop item (at position ${t})`);return!0}}},mounted(){this.max_access_time=Math.max(...this.dataItems.map((e=>e.access_time)));var e=this.buildOnlineTraces(this.dataItems);e=e.concat(this.buildOfflineNATraces(this.dataItems));const t={bargap:0,barmode:"stack",showlegend:!0,autosize:!0,height:this.height,margin:{l:50,r:50,b:50,t:20,pad:4},xaxis:{type:"date",ticklabelmode:this.xaxisMode(),title:this.xaxisTitle,font:{size:10},tickfont:{size:10},showgrid:!!this.sixMonths,griddash:"dot",gridwidth:1,gridcolor:"#d9d7d7",showspikes:!0,spikedash:"4px",spikethickness:1,tick0:this.xaxisTickZero(),dtick:this.xaxisTickD(),tickangle:this.xaxisTickAngle(),tickformat:this.xaxisTickFormat()},yaxis:{title:this.yaxisTitle,titlefont:{size:10},tickfont:{size:10}},template:"plotly_white",legend:{orientation:"h",yanchor:"bottom",y:-.5,xanchor:"left",x:.05,font:{size:8}},hoverlabel:{bgcolor:"#FFF"},hovermode:"closest"};console.log(this.divId),s.default.newPlot(this.divId,e,t,this.config)},methods:{generateColor(e,t){let i=[];for(let s=0;s<30;s++)switch(e[s]){case"up":i.push(`rgba(${this.colorOnline},0)`);break;case"down":i.push(`rgba(${this.colorOffline},${t})`);break;case"NA":i.push(`rgba(${this.colorNA},${t})`)}return i},extractSubarraysBetweenNullValues(e){var t={access_time:[],date:[],average_access_time:0},i=[],s=[],a=0,r=0;for(let o=0;o<e.length;o++)null!==e[o].access_time?(i.push(e[o].access_time),s.push(e[o].date),a+=e[o].access_time,r+=1):i.length>0&&(t.access_time.push(i),t.date.push(s),i=[],s=[]);return t.access_time.push(i),t.date.push(s),t.average_access_time=a/r,t},buildAccessTimeTraces(e){var t=[];for(let i=0;i<e.access_time.length;i++){const s=e.access_time[i],a={x:e.date[i],y:s,name:"Online",legendgroup:"up",showlegend:0===i,mode:"markers+lines",type:"scatter",fill:"tozeroy",fillcolor:`rgba(${this.colorOnline},.2)`,connectgaps:!1,line:{color:`rgba(${this.colorOnline},.8)`,width:1.5},marker:{size:5},hovertemplate:"<b>Online</b><br>%{x|%d %b %Y}<br>%{y} ms <extra></extra>",hoveron:"points+fills"};t.push(a)}return t},buildAvgAccessTimeTrace(e){const t=new Date(this.dataItems[0].date);this.week?t.setDate(t.getDate()-.3):t.setDate(t.getDate()-1);const i=new Date(this.dataItems[this.dataItems.length-1].date);this.week?i.setDate(i.getDate()+.3):i.setDate(i.getDate()+1);return{x:[t,i],y:[e,e],name:"Average access time",showlegend:!0,mode:"lines",type:"scatter",line:{color:`rgba(${this.colorOnline},.6)`,width:1.5,dash:"4px"},marker:{size:5},hovertemplate:"<b>Average access time</b><br>%{y:.2f} ms <extra></extra>"}},buildOnlineTraces(e){const t=this.extractSubarraysBetweenNullValues(e);var i=this.buildAccessTimeTraces(t);return i.push(this.buildAvgAccessTimeTrace(t.average_access_time)),i},extractOfflineNADates(e){const t=[],i=[];for(let s=0;s<e.length;s++)null===e[s].access_time&&null===e[s].code?t.push(e[s].date):null===e[s].access_time&&i.push(e[s].date);return{NA:t,down:i}},barTrace(e,t,i,s,a,r){const o={x:e.dates,y:e.access_times,marker:{color:e.colors},name:t,type:"bar",legendgroup:r,showlegend:i,hoverinfo:s,hovertemplate:a,width:864e5};return console.log(o),o},buildBarTraces(e,t,i,s){const a=`rgba(${t},.8)`,r=`rgba(${t},.2)`,o={dates:e,access_times:Array(e.length).fill(2),colors:Array(e.length).fill(a)},n={dates:e,access_times:Array(e.length).fill(1.1*this.max_access_time),colors:Array(e.length).fill(r)},l=`<b>${i}</b><br>%{x|%d %b %Y}<br>%{y} ms <extra></extra>`;return[this.barTrace(o,i,!1,"skip","",s),this.barTrace(n,i,!0,"all",l,s)]},buildOfflineNATraces(e){var t=[];const i=this.extractOfflineNADates(e);return i.down.length>0&&(t=t.concat(this.buildBarTraces(i.down,this.colorOffline,"Offline","down")),console.log(i.down)),i.NA.length>0&&(t=t.concat(this.buildBarTraces(i.NA,this.colorNA,"No information available","na")),console.log(i.NA)),t},xaxisTickFormat(){return this.week?"%A<br>%d %b":this.sixMonths?"%b":"%d %b"},xaxisTickAngle(){return this.week||this.sixMonths?0:45},xaxisTickD(){return!0===this.sixMonths?"M1":this.dtick},xaxisTickZero(){if(!0===this.sixMonths){console.log("zero six months ago");const e=new Date(this.dataItems[this.dataItems.length-1].date);return console.log(e),console.log("six months ago: "+new Date(e.setMonth(e.getMonth()-6))),new Date(e.setMonth(e.getMonth()-6))}return this.dataItems[0]},xaxisMode(){return!0===this.sixMonths?"period":"instant"}}},undefined,!1,undefined,void 0,void 0);var n=r({render:function(){var e=this,t=e.$createElement;return(e._self._c||t)("div",{attrs:{id:e.divId}})},staticRenderFns:[]},undefined,{name:"citationsPlot",data:()=>({divId:a("cit_plot_")}),props:{dataTraces:{type:Array,required:!0},stack:{type:Boolean,required:!1,default:!1},colors:{type:Array,required:!1,default:()=>["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd"]},height:{type:Number,required:!1,default:400},showlegend:{type:Boolean,required:!1,default:!0},title:{type:String,required:!1,default:""},xaxisTitle:{type:String,required:!1,default:"Year"},yaxisTitle:{type:String,required:!1,default:"Number of citations"},darkMode:{type:Boolean,required:!1,default:!1}},mounted(){const e=this.buildTraces(),t={showlegend:this.showlegend,autosize:!0,height:this.height,margin:{l:50,r:50,b:70,t:50,pad:4},xaxis:{title:this.xaxisTitle,font:{size:10},tickfont:{size:10},tickmode:"linear",color:this.darkMode?"white":"black"},yaxis:{title:this.yaxisTitle,titlefont:{size:10},tickfont:{size:10},font:{size:10},color:this.darkMode?"white":"black"},legend:{orientation:"h",yanchor:"bottom",y:1.02,xanchor:"right",x:1,font:{size:8,color:this.darkMode?"white":"black"}},hoverlabel:{color:this.darkMode?"white":"black"},hovermode:this.stack?"x unified":"closest",hoverdistance:70,plot_bgcolor:this.darkMode?"rgb(38, 50, 56)":"white",paper_bgcolor:this.darkMode?"rgb(38, 50, 56)":"white"};s.default.newPlot(this.divId,e,t)},methods:{buildTraces(){const e=[];for(let t=0;t<this.dataTraces.length;t++){const i={x:this.dataTraces[t].data.map((e=>e.year)),y:this.dataTraces[t].data.map((e=>e.citations)),mode:"lines+markers",name:this.dataTraces[t].label,hovertemplate:this.hoverTemplate(),marker:{size:5},line:{color:this.colors[t],width:1.8},stackgroup:this.stack?"one":null};e.push(i)}return e},hoverTemplate(){return this.stack?"%{y} citations <extra></extra>":"%{y} citations in %{x} <extra></extra>"}}},undefined,!1,undefined,void 0,void 0),l=Object.freeze({__proto__:null,accessibilityPlot:o,citationsPlot:n});const c=function(e){c.installed||(c.installed=!0,Object.entries(l).forEach((([t,i])=>{e.component(t,i)})))},d={install:c};{let e=null;"undefined"!=typeof window?e=window.Vue:"undefined"!=typeof global&&(e=global.Vue),e&&e.use(d)}return e.accessibilityPlot=o,e.citationsPlot=n,e.default=d,Object.defineProperty(e,"__esModule",{value:!0}),e}({},Plotly);
@@ -4,8 +4,13 @@
4
4
  var script$1 = {
5
5
  name: 'accessibilityPlot',
6
6
  data: () => ({
7
- divId: randstr('acc_plot'),
8
- max_access_time: 0
7
+ divId: randstr('acc_plot_'),
8
+ max_access_time: 0,
9
+ config: {
10
+ displaylogo: false,
11
+ responsive: true,
12
+ modeBarButtonsToRemove: ['lasso']
13
+ }
9
14
  }),
10
15
  props: {
11
16
  dtick: {
@@ -76,6 +81,15 @@ var script$1 = {
76
81
  required: false,
77
82
  default: false
78
83
  },
84
+ sixMonths: {
85
+ /*
86
+ whether the plot is used to show data of six months
87
+ If true, months are shown on the x axis
88
+ */
89
+ type: Boolean,
90
+ required: false,
91
+ default: false
92
+ },
79
93
  dataItems: {
80
94
  /*
81
95
  dataItems is an array of objects with keys "access_time", "date" and "code".
@@ -138,12 +152,13 @@ var script$1 = {
138
152
  margin: {
139
153
  l: 50,
140
154
  r: 50,
141
- b: 70,
142
- t: 70,
155
+ b: 50,
156
+ t: 20,
143
157
  pad: 4
144
158
  },
145
159
  xaxis: {
146
160
  type: 'date',
161
+ ticklabelmode: this.xaxisMode(),
147
162
  title: this.xaxisTitle,
148
163
  font: {
149
164
  size: 10
@@ -151,16 +166,17 @@ var script$1 = {
151
166
  tickfont: {
152
167
  size: 10
153
168
  },
154
- showgrid: this.week ? true : false,
169
+ showgrid: this.sixMonths ? true : false,
155
170
  griddash: "dot",
156
171
  gridwidth: 1,
172
+ gridcolor: "#d9d7d7",
157
173
  showspikes: true,
158
174
  spikedash: "4px",
159
175
  spikethickness: 1,
160
- tick0: this.dataItems[0].date,
161
- dtick: this.dtick,
162
- tickangle: this.xaxesTickAngle(),
163
- tickformat: this.xaxesTickFormat()
176
+ tick0: this.xaxisTickZero(),
177
+ dtick: this.xaxisTickD(),
178
+ tickangle: this.xaxisTickAngle(),
179
+ tickformat: this.xaxisTickFormat()
164
180
  },
165
181
  yaxis: {
166
182
  title: this.yaxisTitle,
@@ -175,9 +191,9 @@ var script$1 = {
175
191
  legend: {
176
192
  orientation: 'h',
177
193
  yanchor: 'bottom',
178
- y: 1.02,
179
- xanchor: 'right',
180
- x: 1,
194
+ y: -0.5,
195
+ xanchor: 'left',
196
+ x: 0.05,
181
197
  font: {
182
198
  size: 8
183
199
  }
@@ -187,7 +203,8 @@ var script$1 = {
187
203
  },
188
204
  hovermode: 'closest'
189
205
  };
190
- Plotly__default["default"].newPlot(this.divId, traces, layout);
206
+ console.log(this.divId);
207
+ Plotly__default["default"].newPlot(this.divId, traces, layout, this.config);
191
208
  },
192
209
  methods: {
193
210
  generateColor(values, transparency) {
@@ -315,7 +332,7 @@ var script$1 = {
315
332
  // set start and end dates so that the line spands the whole plot
316
333
  const firstDate = new Date(this.dataItems[0].date);
317
334
  if (this.week) {
318
- firstDate.setDate(firstDate.getDate() - 0.1); // one day before the first date in data
335
+ firstDate.setDate(firstDate.getDate() - 0.3); // one day before the first date in data
319
336
  } else {
320
337
  firstDate.setDate(firstDate.getDate() - 1); // one month before the first date in data
321
338
  }
@@ -461,7 +478,7 @@ var script$1 = {
461
478
  }
462
479
  return traces;
463
480
  },
464
- xaxesTickFormat() {
481
+ xaxisTickFormat() {
465
482
  /*
466
483
  This function returns the tickformat of the x axis.
467
484
  If the plot is used to show data of one week, it returns the day of the week and the day.
@@ -470,11 +487,14 @@ var script$1 = {
470
487
 
471
488
  if (this.week) {
472
489
  return "%A<br>%d %b";
490
+ }
491
+ if (this.sixMonths) {
492
+ return "%b";
473
493
  } else {
474
494
  return "%d %b";
475
495
  }
476
496
  },
477
- xaxesTickAngle() {
497
+ xaxisTickAngle() {
478
498
  /*
479
499
  This function returns the tickangle of the x axis.
480
500
  If the plot is used to show data of one week, it returns 0.
@@ -482,9 +502,38 @@ var script$1 = {
482
502
  */
483
503
  if (this.week) {
484
504
  return 0;
505
+ }
506
+ if (this.sixMonths) {
507
+ return 0;
485
508
  } else {
486
509
  return 45;
487
510
  }
511
+ },
512
+ xaxisTickD() {
513
+ if (this.sixMonths === true) {
514
+ return "M1";
515
+ } else {
516
+ return this.dtick;
517
+ }
518
+ },
519
+ xaxisTickZero() {
520
+ if (this.sixMonths === true) {
521
+ console.log('zero six months ago');
522
+ const lastDate = new Date(this.dataItems[this.dataItems.length - 1].date);
523
+ //return lastDate minus six months
524
+ console.log(lastDate);
525
+ console.log('six months ago: ' + new Date(lastDate.setMonth(lastDate.getMonth() - 6)));
526
+ return new Date(lastDate.setMonth(lastDate.getMonth() - 6));
527
+ } else {
528
+ return this.dataItems[0];
529
+ }
530
+ },
531
+ xaxisMode() {
532
+ if (this.sixMonths === true) {
533
+ return "period";
534
+ } else {
535
+ return "instant";
536
+ }
488
537
  }
489
538
  }
490
539
  };function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier
@@ -591,7 +640,7 @@ const __vue_inject_styles__$1 = undefined;
591
640
  /* scoped */
592
641
  const __vue_scope_id__$1 = undefined;
593
642
  /* module identifier */
594
- const __vue_module_identifier__$1 = "data-v-5ead469f";
643
+ const __vue_module_identifier__$1 = "data-v-77c84891";
595
644
  /* functional template */
596
645
  const __vue_is_functional_template__$1 = false;
597
646
  /* style inject */
@@ -605,7 +654,7 @@ var accessibilityPlot = normalizeComponent_1({
605
654
  var script = {
606
655
  name: 'citationsPlot',
607
656
  data: () => ({
608
- divId: randstr('cit_plot')
657
+ divId: randstr('cit_plot_')
609
658
  }),
610
659
  props: {
611
660
  dataTraces: {
@@ -777,7 +826,7 @@ const __vue_inject_styles__ = undefined;
777
826
  /* scoped */
778
827
  const __vue_scope_id__ = undefined;
779
828
  /* module identifier */
780
- const __vue_module_identifier__ = "data-v-64c53c55";
829
+ const __vue_module_identifier__ = "data-v-4ac5e814";
781
830
  /* functional template */
782
831
  const __vue_is_functional_template__ = false;
783
832
  /* style inject */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inb/oeb_visualizations",
3
- "version": "0.0.7",
3
+ "version": "0.0.8-beta",
4
4
  "description": "Collection of Vue components for data visualization in OpenEBench.",
5
5
  "author": "evamart",
6
6
  "license": "MIT",