diff --git a/docusaurus/docs/Chart Types/Sankey.mdx b/docusaurus/docs/Chart Types/Sankey.mdx deleted file mode 100644 index 1dd4c9c..0000000 --- a/docusaurus/docs/Chart Types/Sankey.mdx +++ /dev/null @@ -1,45 +0,0 @@ -# Sankey Chart - -## Example - -````yaml -```chart -type: sankey -labels: [Oil, "Natural Gas", Coal, "Fossil Fuel", Electricity, Energy] -series: - - data: - - [Oil, 15, "Fossil Fuels"] - - ["Natural Gas", 20, "Fossil Fuels"] - - ["Coal", 25, "Fossil Fuels"] - - ["Coal", 25, "Electricity"] - - ["Fossil Fuels", 60, "Energy"] - - ["Electricity", 25, "Energy"] - priority: - Oil: 1 - Natural Gas: 2 - Coal: 3 - Fossil Fuels: 1 - Electricity: 2 - Energy: 1 - colorFrom: - Oil: "black" - Coal: "gray" - "Fossil Fuels": "slategray" - Electricity: "blue" - Energy: "orange" - colorTo: - Oil: "black" - Coal: "gray" - "Fossil Fuels": "slategray" - Electricity: "blue" - Energy: "orange" -``` -```` - -The above example Code will render a _Sankey Chart_. - -![Radar Chart Example Image](../../../images/sankey.png) - -## Advanced - -*See [Modifiers](/Modifiers) for advanced configuration.* \ No newline at end of file diff --git a/images/sankey.png b/images/sankey.png deleted file mode 100644 index f027cc5..0000000 Binary files a/images/sankey.png and /dev/null differ diff --git a/manifest.json b/manifest.json index 26ab959..159f3ca 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-charts", "name": "Obsidian Charts", - "version": "3.8.0", + "version": "3.8.1", "minAppVersion": "0.12.7", "description": "This Plugin lets you create Charts within Obsidian", "author": "phibr0", diff --git a/package.json b/package.json index c896058..86b4f0d 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ }, "dependencies": { "chart.js": "^3.9.1", - "chartjs-chart-sankey": "^0.12.0", "chroma-js": "^2.1.2", "markdown-tables-to-json": "^0.1.7", "svelte": "^3.35.0", diff --git a/src/chartRenderer.ts b/src/chartRenderer.ts index 13fd33c..1501a16 100644 --- a/src/chartRenderer.ts +++ b/src/chartRenderer.ts @@ -1,14 +1,13 @@ -import { Chart, ChartConfiguration, SankeyControllerDatasetOptions, registerables } from 'chart.js'; -import { SankeyController, Flow } from 'chartjs-chart-sankey'; +import { Chart, ChartConfiguration, RadarControllerChartOptions, registerables } from 'chart.js'; import './date-adapter/chartjs-adapter-moment.esm.js'; import { MarkdownPostProcessorContext, MarkdownRenderChild, parseYaml, TFile } from 'obsidian'; import { generateInnerColors, renderError } from 'src/util'; -import type { ImageOptions } from './constants/settingsConstants'; +import type { ChartPluginSettings, ImageOptions } from './constants/settingsConstants'; import type ChartPlugin from 'src/main'; import { generateTableData } from 'src/chartFromTable'; import annotationPlugin from 'chartjs-plugin-annotation' -Chart.register(...registerables, annotationPlugin, SankeyController, Flow); +Chart.register(...registerables, annotationPlugin); // I need to refactor this // Or just rewrite it completely @@ -38,26 +37,15 @@ export default class Renderer { } } for (let i = 0; yaml.series.length > i; i++) { - const {title, ...rest} = yaml.series[i]; - const dataset = { - label: title ?? "", + datasets.push({ + label: yaml.series[i].title ?? "", + data: yaml.series[i].data, backgroundColor: yaml.labelColors ? colors.length ? generateInnerColors(colors, yaml.transparency) : generateInnerColors(this.plugin.settings.colors, yaml.transparency) : colors.length ? generateInnerColors(colors, yaml.transparency)[i] : generateInnerColors(this.plugin.settings.colors, yaml.transparency)[i], borderColor: yaml.labelColors ? colors.length ? colors : this.plugin.settings.colors : colors.length ? colors[i] : this.plugin.settings.colors[i], borderWidth: 1, fill: yaml.fill ? yaml.stacked ? i == 0 ? 'origin' : '-1' : true : false, //See https://github.com/phibr0/obsidian-charts/issues/53#issuecomment-1084869550 tension: yaml.tension ?? 0, - ...rest, - }; - if (yaml.type === 'sankey') { - // colorFrom, colorTo is accepted as object in yaml, but should be function for sankey. - if (dataset.colorFrom) - (dataset as SankeyControllerDatasetOptions).colorFrom = (c) => yaml.series[i].colorFrom[c.dataset.data[c.dataIndex].from] ?? colors[i] ?? 'green' - - if (dataset.colorTo) - (dataset as SankeyControllerDatasetOptions).colorTo = (c) => yaml.series[i].colorTo[c.dataset.data[c.dataIndex].to] ?? colors[i] ?? 'green' - - } - datasets.push(dataset); + }); } } @@ -159,34 +147,7 @@ export default class Renderer { }, } }; - } else if (yaml.type === 'sankey') { - datasets = datasets.map(dataset => { - return { - ...dataset, - data: dataset.data.map((item: object | any[]) => - Array.isArray(item) && item.length === 3 ? - { - from: item[0], - flow: item[1], - to: item[2], - } : item - ) - } - }) as ChartConfiguration<'sankey'>['data']['datasets']; - - (chartOptions as ChartConfiguration<'sankey'>) = { - type: yaml.type, - data: { - labels, - datasets, - }, - options: { - animation: { - duration: 0 - }, - } - } - }else { + } else { (chartOptions as ChartConfiguration<"pie" | "doughnut" | "bubble" | "scatter">) = { type: yaml.type, data: { diff --git a/yarn.lock b/yarn.lock index 50ce702..8e58bb5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -177,20 +177,15 @@ chart.js@^3.9.1: resolved "https://registry.npmjs.org/chart.js/-/chart.js-3.9.1.tgz" integrity sha512-Ro2JbLmvg83gXF5F4sniaQ+lTbSv18E+TIf2cOeiH1Iqd2PGFOtem+DUufMZsCJwFE7ywPOpfXFBwRTGq7dh6w== -chartjs-chart-sankey@^0.12.0: - version "0.12.0" - resolved "https://registry.yarnpkg.com/chartjs-chart-sankey/-/chartjs-chart-sankey-0.12.0.tgz#eef091d84dd57a1953606b46e021d60099fe46ce" - integrity sha512-2f0YfDWNTTDqztVALlD2YMdSbpmjxdxHpcpKgBi9cUq3IPWBvHb58h4gIa7GjsYVjMLwX6gusDXgxlh9PMKkkA== +chartjs-plugin-annotation@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/chartjs-plugin-annotation/-/chartjs-plugin-annotation-2.2.1.tgz#b7c359e46814b27632d9648584435d64c183427c" + integrity sha512-RL9UtrFr2SXd7C47zD0MZqn6ZLgrcRt3ySC6cYal2amBdANcYB1QcwFXcpKWAYnO4SGJYRok7P5rKDDNgJMA/w== -"chartjs-plugin-annotation@^2.2.1": - "integrity" "sha512-RL9UtrFr2SXd7C47zD0MZqn6ZLgrcRt3ySC6cYal2amBdANcYB1QcwFXcpKWAYnO4SGJYRok7P5rKDDNgJMA/w==" - "resolved" "https://registry.yarnpkg.com/chartjs-plugin-annotation/-/chartjs-plugin-annotation-2.2.1.tgz#b7c359e46814b27632d9648584435d64c183427c" - "version" "2.2.1" - -"chokidar@^3.4.1": - "integrity" "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==" - "resolved" "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz" - "version" "3.5.3" +chokidar@^3.4.1: + version "3.5.3" + resolved "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz" + integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw== dependencies: anymatch "~3.1.2" braces "~3.0.2" @@ -284,9 +279,9 @@ fs.realpath@^1.0.0: integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== fsevents@~2.3.2: - version "2.3.2" - resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a" - integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== + version "2.3.3" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6" + integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== function-bind@^1.1.1: version "1.1.1"