Get radicals and characters sorted by strokes

This commit is contained in:
Shaunak Kishore
2015-09-14 01:19:48 -04:00
parent 884db12af8
commit 3a21845226
3 changed files with 50 additions and 14 deletions

View File

@ -4,8 +4,8 @@ var COLORS = ['#0074D9', '#2ECC40', '#FFDC00', '#FF4136', '#7FDBFF',
var subscription = undefined; var subscription = undefined;
function comparison(glyph1, glyph2) { function comparison(glyph1, glyph2) {
if (glyph1.index.strokes !== glyph2.index.strokes) { if (glyph1.derived.strokes.length !== glyph2.derived.strokes.length) {
return glyph1.index.strokes - glyph2.index.strokes; return glyph1.derived.strokes.length - glyph2.derived.strokes.length;
} else if (glyph1.index.radical !== glyph2.index.radical) { } else if (glyph1.index.radical !== glyph2.index.radical) {
return glyph1.index.radical - glyph2.index.radical; return glyph1.index.radical - glyph2.index.radical;
} }
@ -19,12 +19,13 @@ Template.gallery.events({
}); });
Template.gallery.helpers({ Template.gallery.helpers({
glyphs: function() { blocks: function() {
if (!Session.get('gallery.ready')) { if (!Session.get('gallery.ready')) {
return []; return [];
} }
var glyphs = Glyphs.find().fetch().sort(comparison); var glyphs = Glyphs.find().fetch().sort(comparison);
var on_radicals_page = Session.get('gallery.radical') === undefined; var on_radicals_page = Session.get('gallery.radical') === undefined;
var last_num_strokes = -1;
var result = []; var result = [];
for (var i = 0; i < glyphs.length; i++) { for (var i = 0; i < glyphs.length; i++) {
var glyph = glyphs[i]; var glyph = glyphs[i];
@ -39,13 +40,20 @@ Template.gallery.helpers({
strokes.push({color: COLORS[j % COLORS.length], stroke: stroke}); strokes.push({color: COLORS[j % COLORS.length], stroke: stroke});
} }
} }
result.push({ var data = {
class: (on_radicals_page ? 'radical' : 'character'), class: (on_radicals_page ? 'radical' : 'character'),
d: Glyphs.get_svg_path(glyph), d: Glyphs.get_svg_path(glyph),
name: glyph.name, name: glyph.name,
radical: glyph.index.radical, radical: glyph.index.radical,
strokes: strokes strokes: strokes
}); };
var num_strokes =
on_radicals_page ? glyph.derived.strokes.length : glyph.index.strokes;
if (num_strokes != last_num_strokes) {
result.push({glyphs: [], count: num_strokes});
last_num_strokes = num_strokes;
}
result[result.length - 1].glyphs.push(data);
} }
return result; return result;
}, },

View File

@ -96,8 +96,13 @@
<template name="gallery"> <template name="gallery">
<div id="gallery"> <div id="gallery">
{{#each blocks}}
<div class="gallery-block">
<div class="block-header">{{count}}</div>
<div class="block-values">
{{#each glyphs}} {{#each glyphs}}
<svg viewbox="0 0 1024 1024" class="{{class}}" data-name="{{name}}"> <svg viewbox="0 0 1024 1024"
class="{{class}}" data-name="{{name}}">
<g transform="scale(1, -1) translate(0, -900)"> <g transform="scale(1, -1) translate(0, -900)">
<path d="{{d}}"></path> <path d="{{d}}"></path>
{{#each strokes}} {{#each strokes}}
@ -108,6 +113,9 @@
</svg> </svg>
{{/each}} {{/each}}
</div> </div>
</div>
{{/each}}
</div>
{{#if loading}} {{#if loading}}
<div id="gallery-loader"> <div id="gallery-loader">
<div class="whirly-loader"></div> <div class="whirly-loader"></div>

View File

@ -104,6 +104,26 @@
width: 200px; width: 200px;
} }
#gallery .gallery-block {
display: inline-block;
margin: 60px auto;
text-align: left;
}
#gallery .gallery-block .block-header {
float: left;
font-size: 60px;
line-height: 200px;
margin-right: 80px;
text-align: right;
width: 80px;
}
#gallery .gallery-block .block-values {
float: left;
width: 1020px;
}
#gallery svg.radical { #gallery svg.radical {
cursor: pointer; cursor: pointer;
} }