MediaWiki:Gadget-ec-make-pie.js
Ir a la navegación
Ir a la búsqueda
Nota: tras guardar, quizás necesites actualizar la caché de tu navegador para ver los cambios.
- Firefox/Safari: Mantén presionada la tecla Mayús mientras pulsas el botón Actualizar, o presiona Ctrl+F5 o Ctrl+R (⌘+R en Mac)
- Google Chrome: presiona Ctrl+Shift+R (⌘+Mayús+R en Mac)
- Internet Explorer: mantén presionada Ctrl mientras pulsas Actualizar, o presiona Ctrl+F5
- Opera: dirígete a Menú → Configuración (Opera → Preferencias en Mac) y luego a Privacidad y seguridad → Borrar datos de navegación → Imágenes y archivos en caché.
///# show graphs on editors corner mw.hook( 'wikipage.content' ).add(function () { if (mw.config.get('wgPageName') != "Coppermind:Editor's_Corner") return console.warn('gadget:', 'ec-make-pie') const radius = 200 const font_size = 10 const graph_data = { version: 2, width: radius * 2, height: radius * 2, data: [ { name: 'X', values: [ /*{ label: '', count: 0, color: '', }*/ ], transform: [ { type: 'pie', field: 'count', }, ], } ], marks: [ { type: 'arc', from: { data: 'X', }, properties: { enter: { x: { field: { group: 'width', }, mult: .5, }, y: { field: { group: 'height',}, mult: .5, }, startAngle: { field: 'layout_start', }, endAngle: { field: 'layout_end', }, innerRadius: { value: 0, }, outerRadius: { value: radius, }, fill: { field: 'color', }, stroke: { value: 'white', }, }, }, }, { type: 'text', from: { data: 'X', }, properties: { enter: { x: { field: { group: 'width', }, mult: .5, }, y: { field: { group: 'height',}, mult: .5, }, radius: { value: radius * 2/3, }, theta: { field: 'layout_mid', }, fill: { value: 'white', }, align: { value: 'center', }, baseline: { value: 'middle', }, text: { field: 'label', }, fontWeight: { value: 'bold', }, fontSize: { value: font_size, }, }, }, }, ], } // FIXME: get json from /wiki/MediaWiki:Gadget-ec-make-pie-status.json' // fill it with article counts graph_data.data[0].values.push({ label: 'Complete', count: +document.querySelector('[title="Category:Complete articles"]').textContent, color: 'green', }) graph_data.data[0].values.push({ label: 'Pending', count: +document.querySelector('[title="Category:Articles nearing completion"]').textContent, color: 'blue', }) graph_data.data[0].values.push({ label: 'Partial', count: +document.querySelector('[title="Category:Partially complete articles"]').textContent, color: 'yellow', }) graph_data.data[0].values.push({ label: 'Stub', count: +document.querySelector('[title="Category:Stubs"]').textContent, color: 'grey', }) // find render spot const render_spot = document.createElement('div') const stats_table = document.querySelector('.infobox') stats_table.parentElement.insertBefore(render_spot, stats_table) // load renderer mw.loader.using('ext.graph.vega2').then(function () { console.debug('gadget:', 'make-pie', 'start-render', arguments) console.debug('gadget:', 'make-pie', 'data:', graph_data.data[0].values, graph_data) // attempt to render mw.drawVegaGraph( render_spot, graph_data, function () { console.warn('gadget:', 'make-pie', 'done', arguments) }); }); // done });