Skip to content

Commit dcc73f6

Browse files
committed
- fix column label issue (#1)
1 parent 285149b commit dcc73f6

File tree

8 files changed

+92
-47
lines changed

8 files changed

+92
-47
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Logs
22

3+
## v0.0.9
4+
5+
- fix column label issue (plotdb/sheet#1)
6+
7+
38
## v0.0.8
49

510
- fix bug: cell overflow should be hidden so content won't overflow and cover following cells if size is fixed.

dist/index.js

Lines changed: 30 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "@plotdb/sheet",
44
"license": "MIT",
55
"description": "spreadsheet",
6-
"version": "0.0.8",
6+
"version": "0.0.9",
77
"main": "dist/index.js",
88
"homepage": "https://github.com/plotdb/sheet",
99
"files": [

src/index.ls

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,29 @@ parent = (n, s, e) ->
1212
if n == e and (!e.matches or !e.matches(s)) => return null
1313
return n
1414

15-
num-to-idx = (v) ->
16-
if v < 0 => return ""
15+
idx-to-label = (val) ->
16+
radix = Math.floor(Math.log( (val + 1) * 25 + 1 ) / Math.log(26)) - 1
17+
base = ((Math.pow(26, (radix + 1)) - 1) / 25) - 1
18+
v = val - base
19+
map = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1720
ret = ""
18-
u = v % 26
19-
ret = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(u)) + ret
20-
v = (v - u) / 26
21-
while v > 0
22-
u = v % 26
23-
ret = (" ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(u)) + ret
24-
v = (v - u) / 26
25-
21+
for i from 0 to radix
22+
c = map.charAt(v % 26)
23+
ret = c + ret
24+
v = (v - (v % 26)) / 26
2625
return ret
2726

27+
label-to-idx = (label) ->
28+
radix = label.length - 1
29+
base = ((Math.pow(26, (radix + 1)) - 1) / 25) - 1
30+
map = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
31+
val = 0
32+
for i from 0 to radix =>
33+
idx = map.indexOf(label[i])
34+
if idx < 0 => throw new Error("incorrect label")
35+
val = val * 26 + idx
36+
return val + base
37+
2838
sheet = (opt={}) ->
2939
@root = if typeof(opt.root) == \string => document.querySelector(opt.root) else opt.root
3040
@evt-handler = {}
@@ -192,8 +202,8 @@ sheet.prototype = Object.create(Object.prototype) <<< do
192202
[v,"cell idx"]
193203
else if y < @xif.row.0 =>
194204
v = if x < @xif.col.1 => " "
195-
else if x < @xif.col.2 => num-to-idx(x - @xif.col.1)
196-
else num-to-idx(x - @xif.col.1 + @pos.col)
205+
else if x < @xif.col.2 => idx-to-label(x - @xif.col.1)
206+
else idx-to-label(x - @xif.col.1 + @pos.col)
197207
[v,"cell idx"]
198208
else if x < @xif.col.1 => [null, "cell fixed"]
199209
else if y < @xif.row.1 => [null, "cell fixed"]

web/static/assets/lib/@plotdb/sheet/dev/index.js

Lines changed: 30 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/static/assets/lib/@plotdb/sheet/dev/index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)