Diferencia entre revisiones de «MediaWiki:Gadget-ec-make-pie.js»

De La Coppermind
Ir a la navegación Ir a la búsqueda
m (oops)
m (tweak size)
 
(No se muestran 29 ediciones intermedias del mismo usuario)
Línea 1: Línea 1:
///# show graphs on editors corner
///# show graphs on editors corner


mw.hook( 'wikipage.content' ).add(function () {
mw.hook( 'wikipage.content' ).add(function make_pie() {
if (mw.config.get('wgPageName') != "Coppermind:Editor's_Corner") return
if (mw.config.get('wgPageName') != "Coppermind:Editor's_Corner") return
console.warn('gadget:', 'ec-make-pie')
console.warn('gadget:', 'ec-make-pie')

const cats = {
stub: 'Stubs',
part: 'Partially complete articles',
good: 'Articles nearing completion',
done: 'Complete articles',
}

// PIE CHART:
mw.loader.using('ext.gadget.make-pie').then(function make_pie(require) {
// find a place for it
const place = document.querySelector('.infobox td').parentElement.insertCell(0)
place.rowSpan = 2
place.setAttribute('style', 'max-width: 50mm; min-width: 50mm; vertical-align: middle;')
document.querySelector('.infobox th').colSpan += 1
// make the pie
const make = require('ext.gadget.make-pie');
const pie = make('test', 75)// TODO: what radius?
place.append(pie)
// fill in the data
function add_wedge(name, icon, fill) {
const count = +document.querySelector('[title="Category:'+ cats[name] +'"]').textContent
if(!count) return
pie.add_data_entry(count, name, icon, fill)
}
add_wedge('done', '⬤', '#DFD')
add_wedge('good', '◕', '#FEB')
add_wedge('part', '◒', 'white')
add_wedge('stub', '◔', '#DDD')
pie.render()
}) // END: PIE CHART


// done
});
});

Revisión actual - 14:09 15 abr 2020

///# show graphs on editors corner

mw.hook( 'wikipage.content' ).add(function make_pie() {
  if (mw.config.get('wgPageName') != "Coppermind:Editor's_Corner") return
  console.warn('gadget:', 'ec-make-pie')

const cats = {
  stub: 'Stubs',
  part: 'Partially complete articles',
  good: 'Articles nearing completion',
  done: 'Complete articles',
}

// PIE CHART:
mw.loader.using('ext.gadget.make-pie').then(function make_pie(require) {
// find a place for it
const place = document.querySelector('.infobox td').parentElement.insertCell(0)
place.rowSpan = 2
place.setAttribute('style', 'max-width: 50mm; min-width: 50mm; vertical-align: middle;')
document.querySelector('.infobox th').colSpan += 1
// make the pie
const make = require('ext.gadget.make-pie');
const pie = make('test', 75)// TODO: what radius?
place.append(pie)
// fill in the data
function add_wedge(name, icon, fill) {
  const count = +document.querySelector('[title="Category:'+ cats[name] +'"]').textContent
  if(!count) return
  pie.add_data_entry(count, name, icon, fill)
}
add_wedge('done', '⬤', '#DFD')
add_wedge('good', '◕', '#FEB')
add_wedge('part', '◒', 'white')
add_wedge('stub', '◔', '#DDD')
pie.render()
}) // END: PIE CHART


// done
});