altairjp.js 988 B

12345678910111213141516171819202122232425262728293031323334
  1. // {* raw *}
  2. // Uses https://github.com/vega/vega-embed
  3. Vue.component('altairjp', {
  4. template:
  5. `<div v-bind:id="jp_props.id" :class="jp_props.classes" :style="jp_props.style" >
  6. <div v-bind:id="'altair' + jp_props.id" :class="jp_props.classes" :style="jp_props.style" ></div>
  7. </div>`,
  8. data: function () {
  9. return {
  10. vega_source: {}
  11. }
  12. },
  13. methods: {
  14. chart_create() {
  15. this.vega_source = this.$props.jp_props.vega_source;
  16. el = document.getElementById('altair' + this.$props.jp_props.id.toString());
  17. vegaEmbed(el, JSON.parse(this.$props.jp_props.vega_source), this.$props.jp_props.options).then(function (result) {
  18. }).catch(console.error);
  19. }
  20. },
  21. mounted() {
  22. this.chart_create();
  23. },
  24. updated() {
  25. if (this.vega_source != this.$props.jp_props.vega_source) this.chart_create();
  26. },
  27. props: {
  28. jp_props: Object
  29. }
  30. });
  31. // {* endraw *}