D3.js 系列 (二) Observable -- D3 在线开发编辑工具 -- 导出篇

Observable 的语法官网的文档写的很好,请参见 用户手册

 

原文

完成在线开发后,点击右上角的 「 ... 」

点击 Download code 会打开新页面,复制 URL,例:

https://api.observablehq.com/@jashkenas/my-neat-notebook.js?v=3

这样的路径指向的是封装好的代码模块,结构如下:

 

// https://observablehq.com/@observablehq/downloading-and-embedding-notebooks@971
export default function define(runtime, observer) {
  const main = runtime.module();
  ......
  return main;
}

引用方式如下:

 

<!DOCTYPE html>
<body>
<script type="module">

// Load the Observable runtime and inspector.
import {Runtime, Inspector} from "https://cdn.jsdelivr.net/npm/@observablehq/runtime@4/dist/runtime.js";

// Your notebook, compiled as an ES module.
import notebook from "https://api.observablehq.com/@jashkenas/my-neat-notebook.js?v=3";

// Load the notebook, observing its cells with a default Inspector
// that simply renders the value of each cell into the provided DOM node.
new Runtime().module(notebook, Inspector.into(document.body));

</script>

如果是框架中引入,http 这种引入方式会报错,可以将相关 js 文件下载到本地,然后这样引入:

 

<template>
  <div id="notebook"></div>
</template>

<script>
import { Runtime, Inspector } from '@/utils/observable/Observable.js'
import notebook from '@/utils/observable/bubble-chart.js'

export default {
  components: {},

  data() {
    return {
      runtime: null
    }
  },

  computed: {},

  mounted() {
  },
  beforeDestroy() {
  },
  methods: {
    startRender() {
      this.runtime = new Runtime().module(
        notebook,
        Inspector.into(document.getElementById('notebook'))
      )
      console.log('runtime', this.runtime)
    }
  }
}
</script>
<style scoped>
#notebook {
  padding: 62px;
}
</style>



作者:MercuryWang
链接:https://www.jianshu.com/p/57e893a06bd2
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值