'2018/09/20'에 해당되는 글 3건

  1. 2018.09.20 ajax
  2. 2018.09.20 git 상태 다시 읽기
  3. 2018.09.20 polar clock

error / success / complete 세가지에 대해서 처리해주는 것이 좋다.

(귀찮아서 success만 했는데..)


[링크 : http://shovelman.tistory.com/829]

'Programming > javascript & HTML' 카테고리의 다른 글

css 배경 이미지 회전, 크기 등  (0) 2018.09.27
svg.js  (0) 2018.09.21
polar clock  (0) 2018.09.20
visjs  (0) 2018.09.18
자바스크립트 ES6 와 화살표 펑션 (=>)  (2) 2018.09.18
Posted by 구차니

가끔(?) status 하면 새로 추가되거나 수정된 파일이 안뜰때가 있는데

이거 해주면 새로 읽어서 status에 뜨게 해준다.


$ git update-index --again 

[링크 : https://stackoverflow.com/questions/10006462/refresh-staged-files]

'프로그램 사용 > Version Control' 카테고리의 다른 글

git 리비전 이동 후 pull 안되는 문제  (0) 2018.10.22
git 리비전 돌아 다니기  (0) 2018.10.18
git 원격지 주소 변경하기  (0) 2018.09.06
git archive (svn export)  (0) 2018.09.05
git rm 복구하기  (0) 2018.08.22
Posted by 구차니

그래프 만져보는데 나쁘지 않은 듯?

[링크 : http://bl.ocks.org/mbostock/1096355]


원래 공개된 소스에서는 d3.js가 경로가 잘못되었고

하나만 띄울수 있어서 함수로 변형하니 div 여러개에 각각 띄울수 있게 된다.

<script src="https://d3js.org/d3.v3.min.js"></script>

<script>

function clock_instance(element_id)

{

var width = 300,

    height = 300,

    radius = Math.min(width, height) / 1.9,

    spacing = .09;


var formatSecond = d3.time.format("%-S seconds"),

    formatMinute = d3.time.format("%-M minutes"),

    formatHour = d3.time.format("%-H hours"),

    formatDay = d3.time.format("%A"),

    formatDate = function(d) { d = d.getDate(); switch (10 <= d && d <= 19 ? 10 : d % 10) { case 1: d += "st"; break; case 2: d += "nd"; break; case 3: d += "rd"; break; default: d += "th"; break; } return d; },

    formatMonth = d3.time.format("%B");


var color = d3.scale.linear()

    .range(["hsl(-180,60%,50%)", "hsl(180,60%,50%)"])

    .interpolate(function(a, b) { var i = d3.interpolateString(a, b); return function(t) { return d3.hsl(i(t)); }; });


var arcBody = d3.svg.arc()

    .startAngle(0)

    .endAngle(function(d) { return d.value * 2 * Math.PI; })

    .innerRadius(function(d) { return d.index * radius; })

    .outerRadius(function(d) { return (d.index + spacing) * radius; })

    .cornerRadius(6);


var arcCenter = d3.svg.arc()

    .startAngle(0)

    .endAngle(function(d) { return d.value * 2 * Math.PI; })

    .innerRadius(function(d) { return (d.index + spacing / 2) * radius; })

    .outerRadius(function(d) { return (d.index + spacing / 2) * radius; });


var svg = d3.select(element_id).append("svg")

    .attr("width", width)

    .attr("height", height)

  .append("g")

    .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");


var field = svg.selectAll("g")

    .data(fields)

  .enter().append("g");


field.append("path")

    .attr("class", "arc-body");


field.append("path")

    .attr("id", function(d, i) { return "arc-center-" + i; })

    .attr("class", "arc-center");


field.append("text")

    .attr("dy", ".35em")

    .attr("dx", ".75em")

    .style("text-anchor", "start")

  .append("textPath")

    .attr("startOffset", "50%")

    .attr("class", "arc-text")

    .attr("xlink:href", function(d, i) { return "#arc-center-" + i; });


tick();


d3.select(self.frameElement).style("height", height + "px");


function tick() {

  if (!document.hidden) field

      .each(function(d) { this._value = d.value; })

      .data(fields)

      .each(function(d) { d.previousValue = this._value; })

    .transition()

      .ease("elastic")

      .duration(500)

      .each(fieldTransition);


  setTimeout(tick, 1000 - Date.now() % 1000);

}


function fieldTransition() {

  var field = d3.select(this).transition();


  field.select(".arc-body")

      .attrTween("d", arcTween(arcBody))

      .style("fill", function(d) { return color(d.value); });


  field.select(".arc-center")

      .attrTween("d", arcTween(arcCenter));


  field.select(".arc-text")

      .text(function(d) { return d.text; });

}


function arcTween(arc) {

  return function(d) {

    var i = d3.interpolateNumber(d.previousValue, d.value);

    return function(t) {

      d.value = i(t);

      return arc(d);

    };

  };

}


function fields() {

  var now = new Date;

  return [

    {index: .7, text: formatSecond(now), value: now.getSeconds() / 60},

    {index: .6, text: formatMinute(now), value: now.getMinutes() / 60},

    {index: .5, text: formatHour(now),   value: now.getHours() / 24},

    {index: .3, text: formatDay(now),    value: now.getDay() / 7},

    {index: .2, text: formatDate(now),   value: (now.getDate() - 1) / (32 - new Date(now.getYear(), now.getMonth(), 32).getDate())},

    {index: .1, text: formatMonth(now),  value: now.getMonth() / 12}

  ];

}

}

</script>

<body>

<div id="credit">Inspired by <a href="http://blog.pixelbreaker.com/polarclock/">pixelbreaker</a>.</div>

<div>

<div id='id-1' style="float:left"/>

<div id='id-2' style="float:left"/>

<div>

</body>

<script>

 clock_instance("#id-1");

 clock_instance("#id-2");

</script> 

[링크 : https://stackoverflow.com/.../d3-selectelement-not-working-when-code-above-the-html-element]



1. 색상은 hsl 색상으로 칠해짐. 

2. 값의 범위와 값이 같으면 동일한 색

3. 가장 적은 값은 앞의 범위로 부터 시작함,  아래와 같이 설정되면 빨간색에서 cyan 까지 칠해짐

    .range(["hsl(0,60%,50%)", "hsl(180,60%,50%)"]) 

4. 값의 범위는 소수로 한정됨(즉, 0~1 사이의 실수로 정규화 됨)

function fields() {

  var now = new Date;

  return [

    {index: .6, text: formatSecond(now), value: now.getSeconds() / 60},

    {index: .5, text: formatMinute(now), value: now.getMinutes() / 60},

    {index: .4, text: formatHour(now),   value: now.getHours() / 24},

    {index: .3, text: formatDay(now),    value: now.getDay() / 7},

    {index: .2, text: formatDate(now),   value: (now.getDate() - 1) / (32 - new Date(now.getYear(), now.getMonth(), 32).getDate())},

    {index: .1, text: formatMonth(now),  value: now.getMonth() / 12}

  ];


'Programming > javascript & HTML' 카테고리의 다른 글

svg.js  (0) 2018.09.21
ajax  (0) 2018.09.20
visjs  (0) 2018.09.18
자바스크립트 ES6 와 화살표 펑션 (=>)  (2) 2018.09.18
그래프  (0) 2018.09.18
Posted by 구차니