Skip to content

Commit

Permalink
Merge pull request #98 from phibr0/revert-90-sankey-chart
Browse files Browse the repository at this point in the history
Revert "add sankey chart type"
  • Loading branch information
phibr0 authored Oct 30, 2023
2 parents 6519b0a + ae3737e commit d05a2b6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 110 deletions.
45 changes: 0 additions & 45 deletions docusaurus/docs/Chart Types/Sankey.mdx

This file was deleted.

Binary file removed images/sankey.png
Binary file not shown.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
55 changes: 8 additions & 47 deletions src/chartRenderer.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
});
}
}

Expand Down Expand Up @@ -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: {
Expand Down
27 changes: 11 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit d05a2b6

Please sign in to comment.