• 티스토리 홈
  • 프로필사진
    루루개발자
  • 방명록
  • 공지사항
  • 태그
  • 블로그 관리
  • 글 작성
루루개발자
  • 프로필사진
    루루개발자
    • 분류 전체보기 (212)
      • react & next.js (12)
      • Node.js & Javascript & Type.. (24)
        • d3.js (10)
      • 차트 만들기 (1)
      • 티스토리 스킨 개발 (7)
      • 내가 만든 패키지 (3)
      • 내가 만든 CSS (1)
      • CSS (7)
      • 도커 & 쿠버네티스 (3)
      • 개인 프로젝트 (7)
      • 리뷰 & 추천 (2)
      • 알고리즘 (1)
      • IT 기타 (18)
      • 잡동사니 (1)
      • Spring Boot (5)
      • 취미로 그리는 그림들 (120)
      • 개인적인 생각들 (0)
  • 반응형
  • 방문자 수
    • 전체:
    • 오늘:
    • 어제:
  • 최근 댓글
      등록된 댓글이 없습니다.
    • 최근 공지
        등록된 공지가 없습니다.
      # Home
      # 공지사항
      #
      # 태그
      # 검색결과
      # 방명록
      • [008] d3.active
        2022년 07월 08일
        • 루루개발자
        • 작성자
        • 2022.07.08.:56
        반응형

         

        d3.active


        d3.active 는 현재 transition이 활성화된 노드를 반환하는 함수입니다. 연속적으로 연결된 transition 을 구현할 때 유용하게 사용됩니다.

         

         

        예제


        다음과 같이 typescript 코드를 작성합니다. (js 로의 빌드는 esbuild 등으로 진행 하신 후, 브라우저에서 script 태그로 불러오시면 됩니다.)

        import * as d3 from 'd3';
        
        // https://github.com/d3/d3-transition#active
        // https://www.geeksforgeeks.org/d3-js-interpolatergb-function/
        // https://runebook.dev/en/docs/d3/d3-transition?page=2#transition_tween
        
        window.addEventListener('load', function() {
          const n = 10;
        
          const whiteblue = d3.interpolateRgb("#eee", "steelblue");
          const blueorange = d3.interpolateRgb("steelblue", "orange");
          const orangewhite = d3.interpolateRgb("orange", "#eee");
        
          d3
            .select("body")
            .selectAll("div")
            .data(d3.range(n))
            .enter()
            .append("div")
            .transition()
            .delay(function(d, i) { 
              const delayValue = (i + Math.random() * n / 4) * 1000; 
              console.log('delayValue', delayValue);
              return delayValue; 
            })
            .ease(d3.easeLinear)
            .on("start", function repeat() {
              console.log('repeat', d3.active(this));
        
              d3
                .active(this)
                ?.styleTween("background-color", function() { 
                  console.log('styleTween : 회색 -> 파랑색'); // 회색 -> 파랑색
                  return whiteblue; 
                })
                .transition()
                .delay(1000) // 1초 딜레이 적용
                .styleTween("background-color", function() { 
                  console.log('styleTween : 파랑색 -> 주황색'); // 파랑색 -> 주황색
                  return blueorange; 
                })
                .transition()
                .delay(1000) // 1초 딜레이 적용
                .styleTween("background-color", function() { 
                  console.log('styleTween : 주황색 -> 회색'); // 주황색 -> 회색
                  return orangewhite; 
                })
                .transition()
                .delay(1000) // 1초 딜레이 적용
                .on("start", repeat);
              });
        });

         

         

        결과는 다음과 같습니다.

        참고


        https://github.com/d3/d3-transition#active

         

        GitHub - d3/d3-transition: Animated transitions for D3 selections.

        Animated transitions for D3 selections. Contribute to d3/d3-transition development by creating an account on GitHub.

        github.com

        https://www.geeksforgeeks.org/d3-js-interpolatergb-function/

         

        D3.js interpolateRgb() Function - GeeksforGeeks

        A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

        www.geeksforgeeks.org

        https://runebook.dev/en/docs/d3/d3-transition?page=2#transition_tween 

         

        D3.js - d3-transition - Modifying Elements - After selecting elements and creating a transition with selection.transition, use

        After selecting elements and creating a transition with selection.transition, use the transition’s transformation methods to affect document content. For each selected element, assigns the attribute tween for the attribute with the specified name to the

        runebook.dev

         

        반응형

        'Node.js & Javascript & Typescript > d3.js' 카테고리의 다른 글

        [010] d3.area  (0) 2022.07.13
        [009] d3.arc  (0) 2022.07.12
        [007] d3.ZoomTransform  (0) 2022.06.30
        [006] d3.Voronoi  (0) 2022.06.29
        [005] d3.InternSet  (0) 2022.06.28
        다음글
        다음 글이 없습니다.
        이전글
        이전 글이 없습니다.
        댓글
      조회된 결과가 없습니다.
      스킨 업데이트 안내
      현재 이용하고 계신 스킨의 버전보다 더 높은 최신 버전이 감지 되었습니다. 최신버전 스킨 파일을 다운로드 받을 수 있는 페이지로 이동하시겠습니까?
      ("아니오" 를 선택할 시 30일 동안 최신 버전이 감지되어도 모달 창이 표시되지 않습니다.)
      목차
      표시할 목차가 없습니다.
        • 안녕하세요
        • 감사해요
        • 잘있어요

        티스토리툴바