diff --git a/README.md b/README.md index 432b000..b849647 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@
...
- type: 'bar', // Bar Chart specific properties:
- is_navigable: 1, // Navigate across bars; default 0
+ isNavigable: 1, // Navigate across data points; default 0
...
chart.parent.addEventListener('data-select', (e) => {
@@ -214,22 +176,6 @@
-
-
-
- Simple Aggregations
-
-
-
- chart.show_sums(); // and `hide_sums()`
-
- chart.show_averages(); // and `hide_averages()`
-
-
-
@@ -242,23 +188,23 @@
let heatmap = new Chart({
parent: "#heatmap",
type: 'heatmap',
height: 115,
- data: heatmap_data, // object with date/timestamp-value pairs
+ data: heatmapData, // object with date/timestamp-value pairs
- discrete_domains: 1, // default: 0
+ discreteDomains: 1 // default: 0
- start: start_date,
+ start: startDate,
// A Date object;
// default: today's date in past year
// for an annual heatmap
- legend_colors: ['#ebedf0', '#fdf436', '#ffc700', '#ff9100', '#06001c'],
+ legendColors: ['#ebedf0', '#fdf436', '#ffc700', '#ff9100', '#06001c'],
// Set of five incremental colors,
// beginning with a low-saturation color for zero data;
// default: ['#ebedf0', '#c6e48b', '#7bc96f', '#239a3b', '#196127']
@@ -267,13 +213,97 @@
+
+
+ Available options:
+
+ ...
+ {
+ data: {
+ labels: [],
+ datasets: [],
+ yRegions: [],
+ yMarkers: []
+ }
+ title: '',
+ colors: [],
+ height: 200,
+
+ tooltipOptions: {
+ formatTooltipX: d => (d + '').toUpperCase(),
+ formatTooltipY: d => d + ' pts',
+ }
+
+ // Axis charts
+ isNavigable: 1, // default: 0
+ valuesOverPoints: 1, // default: 0
+ barOptions: {
+ stacked: 1 // default: 0
+ }
+
+ lineOptions: {
+ dotSize: 6, // default: 4
+ hideLine: 0, // default: 0
+ hideDots: 1, // default: 0
+ heatline: 1, // default: 0
+ regionFill: 1 // default: 0
+ }
+
+ axisOptions: {
+ yAxisMode: 'span', // Axis lines, default
+ xAxisMode: 'tick', // No axis lines, only short ticks
+ xIsSeries: 1 // Allow skipping x values for space
+ // default: 0
+ },
+
+ // Pie/Percentage charts
+
+ maxLegendPoints: 6, // default: 20
+ maxSlices: 10, // default: 20
+
+ // Heatmap
+
+ discreteDomains: 1, // default: 1
+ start: startDate, // Date object
+ legendColors: []
+ }
+ ...
+
+ // Updating values
+ chart.update(data);
+
+ // Axis charts:
+ chart.addDataPoint(label, valueFromEachDataset, index)
+ chart.removeDataPoint(index)
+ chart.updateDataset(datasetValues, index)
+
+
+
+
+
+
+
+ Install
+ Install via npm
+ npm install frappe-charts
+ And include it in your project
+ import Chart from "frappe-charts/dist/frappe-charts.min.esm"
+ ... or include it directly in your HTML
+ <script src="https://unpkg.com/frappe-charts@0.0.8/dist/frappe-charts.min.iife.js"></script>
+
+
+
+
+
@@ -285,7 +315,7 @@
-
+
Project maintained by Frappe.
Used in ERPNext.
diff --git a/docs/old_index.html b/docs/old_index.html
new file mode 100644
index 0000000..b77f19d
--- /dev/null
+++ b/docs/old_index.html
@@ -0,0 +1,312 @@
+
+
+
+
+ Frappe Charts
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Frappe Charts
+ GitHub-inspired simple and modern charts for the web
+ with zero dependencies.
+
+
+
+
+
+ Click or use arrow keys to navigate data points
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Create a chart
+
+ Install
+ npm install frappe-charts
+ And include it in your project
+ import Chart from "frappe-charts/dist/frappe-charts.min.esm"
+ ... or include it directly in your HTML
+ <script src="https://unpkg.com/frappe-charts@0.0.8/dist/frappe-charts.min.iife.js"></script>
+ Make a new Chart
+ <!--HTML-->
+ <div id="chart"></div>
+ // Javascript
+ let data = {
+ labels: ["12am-3am", "3am-6am", "6am-9am", "9am-12pm",
+ "12pm-3pm", "3pm-6pm", "6pm-9pm", "9pm-12am"],
+
+ datasets: [
+ {
+ label: "Some Data",
+ values: [25, 40, 30, 35, 8, 52, 17, -4]
+ },
+ {
+ label: "Another Set",
+ values: [25, 50, -10, 15, 18, 32, 27, 14]
+ },
+ {
+ label: "Yet Another",
+ values: [15, 20, -3, -15, 58, 12, -17, 37]
+ }
+ ]
+ };
+
+ let chart = new Chart({
+ parent: "#chart", // or a DOM element
+ title: "My Awesome Chart",
+ data: data,
+ type: 'bar', // or 'line', 'scatter', 'pie', 'percentage'
+ height: 250,
+
+ colors: ['#7cd6fd', 'violet', 'blue'],
+ // hex-codes or these preset colors;
+ // defaults (in order):
+ // ['light-blue', 'blue', 'violet', 'red',
+ // 'orange', 'yellow', 'green', 'light-green',
+ // 'purple', 'magenta', 'grey', 'dark-grey']
+
+ format_tooltip_x: d => (d + '').toUpperCase(),
+ format_tooltip_y: d => d + ' pts'
+ });
+
+
+
+ Why Percentage?
+
+
+
+
+
+
+
+ Update Values
+
+ // Update entire datasets
+ chart.updateData(
+ [
+ {values: new_dataset_1_values},
+ {values: new_dataset_2_values}
+ ],
+ new_labels
+ );
+
+ // Add a new data point
+ chart.add_data_point(
+ [new_value_1, new_value_2],
+ new_label,
+ index // defaults to last index
+ );
+
+ // Remove a data point
+ chart.remove_data_point(index);
+
+
+ ...
+ // Include specific Y values in input data to be displayed as lines
+ // (before passing data to a new chart):
+
+ data.specific_values = [
+ {
+ label: "Altitude",
+ line_type: "dashed", // or "solid"
+ value: 38
+ }
+ ]
+ ...
+
+
+
+
+
+
+ Plot Trends
+
+ ...
+ xAxisMode: 'tick', // for short label ticks
+ // or 'span' for long spanning vertical axis lines
+ yAxisMode: 'span', // for long horizontal lines, or 'tick'
+ isSeries: 1, // to allow for skipping of X values
+ ...
+
+
+ ...
+ type: 'line', // Line Chart specific properties:
+
+ hideDots: 1, // Hide data points on the line; default 0
+ heatline: 1, // Show a value-wise line gradient; default 0
+ regionFill: 1, // Fill the area under the graph; default 0
+ ...
+
+
+
+
+
+
+ Listen to state change
+
+
+
+
+
+
+
+
+
+
+
+ Europa
+ Semi-major-axis: 671034 km
+ Mass: 4800000 x 10^16 kg
+ Diameter: 3121.6 km
+
+
+
+
+ ...
+ type: 'bar', // Bar Chart specific properties:
+ isNavigable: 1, // Navigate across bars; default 0
+ ...
+
+ chart.parent.addEventListener('data-select', (e) => {
+ update_moon_data(e.index); // e contains index and value of current datapoint
+ });
+
+
+
+
+
+
+ Simple Aggregations
+
+
+
+ chart.show_sums(); // and `hide_sums()`
+
+ chart.show_averages(); // and `hide_averages()`
+
+
+
+
+
+
+ And a Month-wise Heatmap
+
+
+
+
+ let heatmap = new Chart({
+ parent: "#heatmap",
+ type: 'heatmap',
+ height: 115,
+ data: heatmap_data, // object with date/timestamp-value pairs
+
+ discrete_domains: 1 // default: 0
+
+ start: start_date,
+ // A Date object;
+ // default: today's date in past year
+ // for an annual heatmap
+
+ legend_colors: ['#ebedf0', '#fdf436', '#ffc700', '#ff9100', '#06001c'],
+ // Set of five incremental colors,
+ // beginning with a low-saturation color for zero data;
+ // default: ['#ebedf0', '#c6e48b', '#7bc96f', '#239a3b', '#196127']
+
+ });
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Project maintained by Frappe.
+ Used in ERPNext.
+ Read the blog post.
+
+
+ Data from the American Meteor Society,
+ SILSO and
+ NASA Open APIs
+
+
+
+
+
+
+
+
+
+
+
diff --git a/package.json b/package.json
index 43352ab..3e02b61 100644
--- a/package.json
+++ b/package.json
@@ -52,5 +52,8 @@
"rollup-plugin-uglify": "^2.0.1",
"rollup-plugin-uglify-es": "0.0.1",
"rollup-watch": "^4.3.1"
+ },
+ "dependencies": {
+ "eslint": "^4.18.2"
}
}
diff --git a/rollup.config.js b/rollup.config.js
index 732949f..b4a7678 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -15,17 +15,19 @@ import pkg from './package.json';
export default [
{
- input: 'src/js/charts.js',
+ input: 'src/js/chart.js',
+ sourcemap: true,
output: [
{
- file: pkg.main,
- format: 'cjs',
+ file: 'docs/assets/js/frappe-charts.min.js',
+ format: 'iife',
},
{
- file: pkg.module,
- format: 'es',
+ file: pkg.browser,
+ format: 'iife',
}
],
+ name: 'Chart',
plugins: [
postcss({
preprocessor: (content, id) => new Promise((resolve, reject) => {
@@ -33,7 +35,6 @@ export default [
resolve({ code: result.css.toString() })
}),
extensions: [ '.scss' ],
- // extract: 'dist/frappe-charts.min.css',
plugins: [
nested(),
cssnext({ warnForDuplicates: false }),
@@ -56,10 +57,14 @@ export default [
]
},
{
- input: 'src/js/charts.js',
+ input: 'src/js/chart.js',
output: [
{
- file: pkg.src,
+ file: pkg.main,
+ format: 'cjs',
+ },
+ {
+ file: pkg.module,
format: 'es',
}
],
@@ -70,7 +75,6 @@ export default [
resolve({ code: result.css.toString() })
}),
extensions: [ '.scss' ],
- extract: 'dist/frappe-charts.min.css',
plugins: [
nested(),
cssnext({ warnForDuplicates: false }),
@@ -82,25 +86,24 @@ export default [
'src/scss/**',
]
}),
+ babel({
+ exclude: 'node_modules/**',
+ }),
replace({
exclude: 'node_modules/**',
ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
- })
+ }),
+ uglify()
],
},
{
- input: 'src/js/charts.js',
+ input: 'src/js/chart.js',
output: [
{
- file: 'docs/assets/js/frappe-charts.min.js',
- format: 'iife',
- },
- {
- file: pkg.browser,
- format: 'iife',
+ file: pkg.src,
+ format: 'es',
}
],
- name: 'Chart',
plugins: [
postcss({
preprocessor: (content, id) => new Promise((resolve, reject) => {
@@ -108,6 +111,7 @@ export default [
resolve({ code: result.css.toString() })
}),
extensions: [ '.scss' ],
+ extract: 'dist/frappe-charts.min.css',
plugins: [
nested(),
cssnext({ warnForDuplicates: false }),
@@ -119,14 +123,10 @@ export default [
'src/scss/**',
]
}),
- babel({
- exclude: 'node_modules/**',
- }),
replace({
exclude: 'node_modules/**',
ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
- }),
- uglify()
+ })
],
}
];
diff --git a/src/js/chart.js b/src/js/chart.js
new file mode 100644
index 0000000..f377f39
--- /dev/null
+++ b/src/js/chart.js
@@ -0,0 +1,40 @@
+import '../scss/charts.scss';
+
+// import MultiAxisChart from './charts/MultiAxisChart';
+import PercentageChart from './charts/PercentageChart';
+import PieChart from './charts/PieChart';
+import Heatmap from './charts/Heatmap';
+import AxisChart from './charts/AxisChart';
+
+const chartTypes = {
+ // multiaxis: MultiAxisChart,
+ percentage: PercentageChart,
+ heatmap: Heatmap,
+ pie: PieChart
+};
+
+function getChartByType(chartType = 'line', parent, options) {
+ if(chartType === 'line') {
+ options.type = 'line';
+ return new AxisChart(parent, options);
+ } else if (chartType === 'bar') {
+ options.type = 'bar';
+ return new AxisChart(parent, options);
+ } else if (chartType === 'axis-mixed') {
+ options.type = 'line';
+ return new AxisChart(parent, options);
+ }
+
+ if (!chartTypes[chartType]) {
+ console.error("Undefined chart type: " + chartType);
+ return;
+ }
+
+ return new chartTypes[chartType](parent, options);
+}
+
+export default class Chart {
+ constructor(parent, options) {
+ return getChartByType(options.type, parent, options);
+ }
+}
diff --git a/src/js/charts.js b/src/js/charts.js
deleted file mode 100644
index 5ff073e..0000000
--- a/src/js/charts.js
+++ /dev/null
@@ -1,39 +0,0 @@
-import '../scss/charts.scss';
-
-import BarChart from './charts/BarChart';
-import LineChart from './charts/LineChart';
-import ScatterChart from './charts/ScatterChart';
-import PercentageChart from './charts/PercentageChart';
-import PieChart from './charts/PieChart';
-import Heatmap from './charts/Heatmap';
-
-// if (ENV !== 'production') {
-// // Enable LiveReload
-// document.write(
-// '