Skip to content

Instantly share code, notes, and snippets.

Rect = require'./rect.coffee'
class Rects
el: 'rect'
constructor: (selection) ->
@dom = selection.selectAll(@el)
@position = (d,i) -> 'translate(0,0)'
@width = (d) =>
@height = (d) =>
@name = (d,i) -> d.name
Visualizer = require './visualizer.coffee'
class Rect extends Visualizer
el: 'rect'
fill: '#000'
stroke: ''
constructor: ->
@setAttr
fill: @fill
# 棒のグループ要素
class Bars extends Visualizer
type: "g"
constructor: ->
@el.attr 'class' : 'bars'
@rects = new Rects @el
render: (data) ->
@rects.render data
class BarChart
setup: ->
@svg = new Svg('')
@bars = new Bars(@svg.dom)
size: (size) ->
@svg.attr(
width: size.width
height: size.height
)
class BarChart
setup: ->
@svg = new Svg('')
@bars = new Bars(@svg.dom)
size: (size) ->
@svg.attr(
width: size.width
height: size.height
)
@valbeat
valbeat / svgTextWrapper.coffee
Created January 20, 2015 06:07
svgTextWrapper.coffee
# テキストを改行させる
textWrapper : (text) ->
text.each(()->
text = d3.select(this)
rect = text.node().previousElementSibling
textArea =
width : rect.getAttribute('width')
height : rect.getAttribute('height')
# テキストを単語で区切った配列に
# x軸を生成 スケールと描画位置を指定する。
@xAxis = d3.svg.axis()
.scale(@xScale)
.orient('bottom')
# .tickFormat(@customFormat)
.tickSize(-@chartHeight)
.tickPadding(10)
.outerTickSize(5)
# y軸を生成 スケールと描画位置を指定する。
@yAxis = d3.svg.axis()
#
# 凡例
#
class Legends
RECT_SIZE = 14
TEXT_MARGIN = 20
LEGEND_MARGIN = 2
LEGEND_WIDTH = 150
LEGEND_HEIGHT = 20
@valbeat
valbeat / file0.txt
Last active February 3, 2016 00:46
都道府県と市町村区を分割し、配列に格納する。 ref: http://qiita.com/kajitack/items/d457fb4a811ddc53952a
'東京都文京区本郷'
.replace(/^(.{2}[都道府県]|.{3}県)(.+)/, "$1 $2")
.split(' ')
// ['東京都','文京区本郷']
@valbeat
valbeat / kaibun.rb
Last active August 29, 2015 14:16
文字列から一番長い回文を求める
# 回文チェック
def check(word)
word = word.to_s
word == word.reverse
end
# 文字列
str = "234567890328927412102352356776"
result = ""